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 
23 #include <ndn-cxx/security/key-chain.hpp>
24 #include <ndn-cxx/security/security-common.hpp>
25 #include <ndn-cxx/security/pib/pib-impl.hpp>
26 #include <ndn-cxx/security/tpm/back-end.hpp>
27 #include <ndn-cxx/security/transform/private-key.hpp>
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 
151  doDecrypt(const uint8_t* cipherText, size_t cipherTextLen) const final;
152 
154  doDerivePublicKey() const final;
155 };
156 
157 } // namespace tpm
158 
161 
162 class DummyTpm : public BackEnd
163 {
164 public:
165  class Error : public BackEnd::Error
166  {
167  public:
168  explicit
169  Error(const std::string& what)
170  : BackEnd::Error(what)
171  {
172  }
173  };
174 
175 public:
176  explicit DummyTpm(const std::string& locator);
177 
178  bool
179  isTerminalMode() const override;
180 
181  void
182  setTerminalMode(bool isTerminal) const override;
183 
184  bool
185  isTpmLocked() const override;
186 
188  sign(const uint8_t* buf, size_t size, const Name& keyName, DigestAlgorithm digestAlgorithm) const;
189 
190  static std::string
191  getScheme();
192 
193 private:
194  bool
195  doHasKey(const Name& keyName) const final;
196 
197  unique_ptr<tpm::KeyHandle>
198  doGetKeyHandle(const Name& keyName) const final;
199 
200  unique_ptr<tpm::KeyHandle>
201  doCreateKey(const Name& identity, const KeyParams& params) final;
202 
203  void
204  doDeleteKey(const Name& keyName) final;
205 
207  doExportKey(const Name& keyName, const char* pw, size_t pwLen) final;
208 
209  void
210  doImportKey(const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Len, const char* pw, size_t pwLen) final;
211 
212 public:
213  static const std::string SCHEME;
214 };
215 
216 } // namespace security
217 } // namespace ndn
218 
219 #endif // NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP
represents a non-semantic error
Definition: pib-impl.hpp:48
static const std::string SCHEME
bool hasKey(const Name &keyName) const override
Check the existence of a key with keyName.
Copyright (c) 2011-2015 Regents of the University of California.
The certificate following the certificate format naming convention.
Definition: certificate.hpp:81
void setTpmLocator(const std::string &tpmLocator) override
Set the corresponding TPM information to tpmLocator.
void removeKey(const Name &keyName) override
Remove a key with keyName and related certificates.
bool isTerminalMode() const override
Check if TPM is in terminal mode.
void addKey(const Name &identity, const Name &keyName, const uint8_t *key, size_t keyLen) override
Add a key.
std::set< Name > getIdentities() const override
Get the name of all the identities.
Buffer getKeyBits(const Name &keyName) const override
Get the key bits of a key with name keyName.
Name getDefaultKeyOfIdentity(const Name &identity) const override
std::set< Name > getCertificatesOfKey(const Name &keyName) const override
Get a list of certificate names of a key with id keyName.
Abstraction of TPM key handle.
Definition: key-handle.hpp:38
void setDefaultKeyOfIdentity(const Name &identity, const Name &keyName) override
Set an key with keyName as the default key of an identity with name identity.
Error(const std::string &what)
bool isTpmLocked() const override
DummyPib(const std::string &locator)
void clearIdentities() override
Erasing all certificates, keys, and identities.
Abstraction of Tpm back-end.
Definition: back-end.hpp:41
static std::string getScheme()
void removeCertificate(const Name &certName) override
Remove a certificate with name certName.
void addCertificate(const v2::Certificate &certificate) override
Add a certificate.
std::set< Name > getKeysOfIdentity(const Name &identity) const override
Get all the key names of an identity with name identity.
v2::Certificate getCertificate(const Name &certificateName) const override
Get a certificate with name certName.
static const std::string SCHEME
bool hasCertificate(const Name &certName) const override
Check the existence of a certificate with name certName.
static std::string getScheme()
bool hasIdentity(const Name &identityName) const override
Check the existence of an identity.
void addIdentity(const Name &identityName) override
Add an identity.
Represents an absolute name.
Definition: name.hpp:42
void setTerminalMode(bool isTerminal) const override
Set the terminal mode of TPM.
Name getDefaultIdentity() const override
Get the default identity.
void setDefaultCertificateOfKey(const Name &keyName, const Name &certName) override
Set a cert with name certName as the default of a key with keyName.
Error(const std::string &what)
std::string getTpmLocator() const override
Get TPM Locator.
DummyTpm(const std::string &locator)
Base class of key parameters.
Definition: key-params.hpp:35
void setDefaultIdentity(const Name &identityName) override
Set an identity with name identityName as the default identity.
DummyKeyHandle(shared_ptr< transform::PrivateKey > key)
General-purpose automatically managed/resized buffer.
Definition: buffer.hpp:40
void removeIdentity(const Name &identity) override
Remove an identity and related keys and certificates.
Abstract class of PIB implementation.
Definition: pib-impl.hpp:39
ConstBufferPtr sign(const uint8_t *buf, size_t size, const Name &keyName, DigestAlgorithm digestAlgorithm) const
v2::Certificate getDefaultCertificateOfKey(const Name &keyName) const override
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:89