NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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
static const std::string SCHEME
bool hasKey(const Name &keyName) const override
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
void removeKey(const Name &keyName) override
void addKey(const Name &identity, const Name &keyName, const uint8_t *key, size_t keyLen) override
std::set< Name > getIdentities() const override
Buffer getKeyBits(const Name &keyName) const override
Name getDefaultKeyOfIdentity(const Name &identity) const override
std::set< Name > getCertificatesOfKey(const Name &keyName) const override
Abstraction of TPM key handle.
Definition: key-handle.hpp:38
void setDefaultKeyOfIdentity(const Name &identity, const Name &keyName) override
Error(const std::string &what)
DummyPib(const std::string &locator)
void clearIdentities() override
Catch-all error for security policy errors that don&#39;t fit in other categories.
Definition: base.hpp:79
static std::string getScheme()
void removeCertificate(const Name &certName) override
void addCertificate(const v2::Certificate &certificate) override
std::set< Name > getKeysOfIdentity(const Name &identity) const override
v2::Certificate getCertificate(const Name &certificateName) const override
static const std::string SCHEME
bool hasCertificate(const Name &certName) const override
bool hasIdentity(const Name &identityName) const override
void addIdentity(const Name &identityName) override
Represents an absolute name.
Definition: name.hpp:42
Name getDefaultIdentity() const override
void setDefaultCertificateOfKey(const Name &keyName, const Name &certName) override
Error(const std::string &what)
std::string getTpmLocator() const override
Base class of key parameters.
Definition: key-params.hpp:35
void setDefaultIdentity(const Name &identityName) override
General-purpose automatically managed/resized buffer.
Definition: buffer.hpp:40
void removeIdentity(const Name &identity) override
v2::Certificate getDefaultCertificateOfKey(const Name &keyName) const override
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:89