NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
dummy-keychain.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #ifndef NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP
21 #define NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP
22 
28 
29 namespace ndn {
30 namespace security {
31 
32 using pib::PibImpl;
33 using tpm::BackEnd;
34 using tpm::KeyHandle;
35 
36 class DummyPib : public PibImpl
37 {
38 public:
39  class Error : public PibImpl::Error
40  {
41  public:
42  explicit
43  Error(const std::string& what)
44  : PibImpl::Error(what)
45  {
46  }
47  };
48 
49 public:
50  explicit DummyPib(const std::string& locator);
51 
52  // TPM management
53  void
54  setTpmLocator(const std::string& tpmLocator) override;
55 
56  std::string
57  getTpmLocator() const override;
58 
59  // Identity manangement
60  bool
61  hasIdentity(const Name& identityName) const override;
62 
63  void
64  addIdentity(const Name& identityName) override;
65 
66  void
67  removeIdentity(const Name& identity) override;
68 
69  void
70  clearIdentities() override;
71 
72  std::set<Name>
73  getIdentities() const override;
74 
75  void
76  setDefaultIdentity(const Name& identityName) override;
77 
78  Name
79  getDefaultIdentity() const override;
80 
81  // Key management
82  bool
83  hasKey(const Name& keyName) const override;
84 
85  void
86  addKey(const Name& identity, const Name& keyName, const uint8_t* key,
87  size_t keyLen) override;
88 
89  void
90  removeKey(const Name& keyName) override;
91 
92  Buffer
93  getKeyBits(const Name& keyName) const override;
94 
95  std::set<Name>
96  getKeysOfIdentity(const Name& identity) const override;
97 
98  void
99  setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) override;
100 
101  Name
102  getDefaultKeyOfIdentity(const Name& identity) const override;
103 
104  // certificate management
105  bool
106  hasCertificate(const Name& certName) const override;
107 
108  void
109  addCertificate(const v2::Certificate& certificate) override;
110 
111  void
112  removeCertificate(const Name& certName) override;
113 
115  getCertificate(const Name& certificateName) const override;
116 
117  std::set<Name>
118  getCertificatesOfKey(const Name& keyName) const override;
119 
120  void
121  setDefaultCertificateOfKey(const Name& keyName, const Name& certName) override;
122 
124  getDefaultCertificateOfKey(const Name& keyName) const override;
125 
126  static std::string
127  getScheme();
128 
129  static const std::string SCHEME;
130 
131 private:
132  std::string m_tpmLocator;
133 };
134 
137 
138 namespace tpm {
139 
140 class DummyKeyHandle : public KeyHandle
141 {
142 public:
143  explicit
144  DummyKeyHandle(shared_ptr<transform::PrivateKey> key);
145 
146 private:
148  doSign(DigestAlgorithm digestAlgorithm, const uint8_t* buf, size_t size) const final;
149 
150  bool
151  doVerify(DigestAlgorithm digestAlgorithm, const uint8_t* buf, size_t bufLen,
152  const uint8_t* sig, size_t sigLen) const final;
153 
155  doDecrypt(const uint8_t* cipherText, size_t cipherTextLen) const final;
156 
158  doDerivePublicKey() const final;
159 };
160 
161 } // namespace tpm
162 
165 
166 class DummyTpm : public BackEnd
167 {
168 public:
169  class Error : public BackEnd::Error
170  {
171  public:
172  explicit
173  Error(const std::string& what)
174  : BackEnd::Error(what)
175  {
176  }
177  };
178 
179 public:
180  explicit DummyTpm(const std::string& locator);
181 
182  bool
183  isTerminalMode() const override;
184 
185  void
186  setTerminalMode(bool isTerminal) const override;
187 
188  bool
189  isTpmLocked() const override;
190 
192  sign(const uint8_t* buf, size_t size, const Name& keyName, DigestAlgorithm digestAlgorithm) const;
193 
194  static std::string
195  getScheme();
196 
197 private:
198  bool
199  doHasKey(const Name& keyName) const final;
200 
201  unique_ptr<tpm::KeyHandle>
202  doGetKeyHandle(const Name& keyName) const final;
203 
204  unique_ptr<tpm::KeyHandle>
205  doCreateKey(const Name& identity, const KeyParams& params) final;
206 
207  void
208  doDeleteKey(const Name& keyName) final;
209 
211  doExportKey(const Name& keyName, const char* pw, size_t pwLen) final;
212 
213  void
214  doImportKey(const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Len, const char* pw, size_t pwLen) final;
215 
216  void
217  doImportKey(const Name& keyName, shared_ptr<transform::PrivateKey> key) final;
218 
219 public:
220  static const std::string SCHEME;
221 };
222 
223 } // namespace security
224 } // namespace ndn
225 
226 #endif // NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP
buf
const uint8_t * buf
Definition: verification-helpers.cpp:47
ndn::security::DummyPib::addKey
void addKey(const Name &identity, const Name &keyName, const uint8_t *key, size_t keyLen) override
Add a key.
Definition: dummy-keychain.cpp:135
ndn::security::DummyPib::hasIdentity
bool hasIdentity(const Name &identityName) const override
Check the existence of an identity.
Definition: dummy-keychain.cpp:89
ndn::security::tpm::Tpm::Error
Definition: tpm.hpp:69
ndn::KeyParams
Base class for key parameters.
Definition: key-params.hpp:36
ndn::security::DummyTpm::sign
ConstBufferPtr sign(const uint8_t *buf, size_t size, const Name &keyName, DigestAlgorithm digestAlgorithm) const
bufLen
size_t bufLen
Definition: verification-helpers.cpp:48
ndn::security::DummyPib::removeCertificate
void removeCertificate(const Name &certName) override
Remove a certificate with name certName.
Definition: dummy-keychain.cpp:186
sigLen
size_t sigLen
Definition: verification-helpers.cpp:50
ndn::security::DummyTpm::getScheme
static std::string getScheme()
Definition: dummy-keychain.cpp:346
security-common.hpp
ndn::security::tpm::DummyKeyHandle
Definition: dummy-keychain.hpp:141
key-chain.hpp
ndn::security::pib::PibImpl::Error
represents a non-semantic error
Definition: pib-impl.hpp:50
ndn::Buffer
General-purpose automatically managed/resized buffer.
Definition: buffer.hpp:41
ndn::security::DummyPib::addCertificate
void addCertificate(const v2::Certificate &certificate) override
Add a certificate.
Definition: dummy-keychain.cpp:181
ndn::security::DummyTpm::setTerminalMode
void setTerminalMode(bool isTerminal) const override
Set the terminal mode of the TPM.
Definition: dummy-keychain.cpp:291
ndn::security::tpm::BackEnd
Abstract interface for a TPM backend implementation.
Definition: back-end.hpp:37
ndn::security::DummyPib::setDefaultIdentity
void setDefaultIdentity(const Name &identityName) override
Set an identity with name identityName as the default identity.
Definition: dummy-keychain.cpp:118
ndn::security::DummyPib::Error
Definition: dummy-keychain.hpp:40
ndn::security::DummyTpm::Error::Error
Error(const std::string &what)
Definition: dummy-keychain.hpp:173
ndn::security::DummyTpm::DummyTpm
DummyTpm(const std::string &locator)
Definition: dummy-keychain.cpp:280
ndn::security::DummyPib::getDefaultCertificateOfKey
v2::Certificate getDefaultCertificateOfKey(const Name &keyName) const override
Definition: dummy-keychain.cpp:218
ndn::DigestAlgorithm
DigestAlgorithm
Definition: security-common.hpp:96
ndn::security::DummyPib::Error::Error
Error(const std::string &what)
Definition: dummy-keychain.hpp:43
ndn::security::DummyTpm::isTpmLocked
bool isTpmLocked() const override
Check if the TPM is locked.
Definition: dummy-keychain.cpp:296
ndn::security::tpm::KeyHandle
Abstraction of TPM key handle.
Definition: key-handle.hpp:38
ndn::security::DummyPib::removeIdentity
void removeIdentity(const Name &identity) override
Remove an identity and related keys and certificates.
Definition: dummy-keychain.cpp:100
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
ndn::security::DummyPib::setDefaultCertificateOfKey
void setDefaultCertificateOfKey(const Name &keyName, const Name &certName) override
Set a cert with name certName as the default of a key with keyName.
Definition: dummy-keychain.cpp:213
ndn::security::v2::Certificate
The certificate following the certificate format naming convention.
Definition: certificate.hpp:82
ndn::security::tpm::DummyKeyHandle::DummyKeyHandle
DummyKeyHandle(shared_ptr< transform::PrivateKey > key)
Definition: dummy-keychain.cpp:244
ndn::security::DummyPib::setDefaultKeyOfIdentity
void setDefaultKeyOfIdentity(const Name &identity, const Name &keyName) override
Set an key with keyName as the default key of an identity with name identity.
Definition: dummy-keychain.cpp:164
ndn::security::DummyPib::getCertificatesOfKey
std::set< Name > getCertificatesOfKey(const Name &keyName) const override
Get a list of certificate names of a key with id keyName.
Definition: dummy-keychain.cpp:205
ndn::security::DummyPib::DummyPib
DummyPib(const std::string &locator)
Definition: dummy-keychain.cpp:72
private-key.hpp
ndn::security::DummyPib::SCHEME
static const std::string SCHEME
Definition: dummy-keychain.hpp:129
ndn::security::DummyPib::getScheme
static std::string getScheme()
Definition: dummy-keychain.cpp:232
ndn::security::DummyPib::setTpmLocator
void setTpmLocator(const std::string &tpmLocator) override
Set the corresponding TPM information to tpmLocator.
Definition: dummy-keychain.cpp:77
ndn::security::DummyPib::getIdentities
std::set< Name > getIdentities() const override
Get the name of all the identities.
Definition: dummy-keychain.cpp:110
sig
const uint8_t * sig
Definition: verification-helpers.cpp:49
ndn::security::DummyTpm::isTerminalMode
bool isTerminalMode() const override
Check if the TPM is in terminal mode.
Definition: dummy-keychain.cpp:285
ndn::security::DummyTpm
Definition: dummy-keychain.hpp:167
ndn::security::DummyPib::getDefaultKeyOfIdentity
Name getDefaultKeyOfIdentity(const Name &identity) const override
Definition: dummy-keychain.cpp:169
back-end.hpp
ndn::security::DummyPib::getKeysOfIdentity
std::set< Name > getKeysOfIdentity(const Name &identity) const override
Get all the key names of an identity with name identity.
Definition: dummy-keychain.cpp:156
ndn::security::DummyPib::getKeyBits
Buffer getKeyBits(const Name &keyName) const override
Get the key bits of a key with name keyName.
Definition: dummy-keychain.cpp:146
ndn::security::DummyPib::clearIdentities
void clearIdentities() override
Erasing all certificates, keys, and identities.
Definition: dummy-keychain.cpp:105
ndn::security::DummyPib::getCertificate
v2::Certificate getCertificate(const Name &certificateName) const override
Get a certificate with name certName.
Definition: dummy-keychain.cpp:191
ndn::security::DummyTpm::Error
Definition: dummy-keychain.hpp:170
ndn::security::DummyPib::hasKey
bool hasKey(const Name &keyName) const override
Check the existence of a key with keyName.
Definition: dummy-keychain.cpp:129
ndn::security::DummyPib::getDefaultIdentity
Name getDefaultIdentity() const override
Get the default identity.
Definition: dummy-keychain.cpp:123
ndn::security::DummyTpm::SCHEME
static const std::string SCHEME
Definition: dummy-keychain.hpp:220
ndn::security::DummyPib::removeKey
void removeKey(const Name &keyName) override
Remove a key with keyName and related certificates.
Definition: dummy-keychain.cpp:141
ndn::security::DummyPib
Definition: dummy-keychain.hpp:37
pib-impl.hpp
ndn::ConstBufferPtr
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:126
ndn::security::DummyPib::hasCertificate
bool hasCertificate(const Name &certName) const override
Check the existence of a certificate with name certName.
Definition: dummy-keychain.cpp:175
ndn::security::pib::PibImpl
Abstract class of PIB implementation.
Definition: pib-impl.hpp:41
ndn::security::DummyPib::addIdentity
void addIdentity(const Name &identityName) override
Add an identity.
Definition: dummy-keychain.cpp:95
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::security::DummyPib::getTpmLocator
std::string getTpmLocator() const override
Get TPM Locator.
Definition: dummy-keychain.cpp:83