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, span<const uint8_t> key) override;
87 
88  void
89  removeKey(const Name& keyName) override;
90 
91  Buffer
92  getKeyBits(const Name& keyName) const override;
93 
94  std::set<Name>
95  getKeysOfIdentity(const Name& identity) const override;
96 
97  void
98  setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) override;
99 
100  Name
101  getDefaultKeyOfIdentity(const Name& identity) const override;
102 
103  // certificate management
104  bool
105  hasCertificate(const Name& certName) const override;
106 
107  void
108  addCertificate(const Certificate& certificate) override;
109 
110  void
111  removeCertificate(const Name& certName) override;
112 
113  Certificate
114  getCertificate(const Name& certificateName) const override;
115 
116  std::set<Name>
117  getCertificatesOfKey(const Name& keyName) const override;
118 
119  void
120  setDefaultCertificateOfKey(const Name& keyName, const Name& certName) override;
121 
122  Certificate
123  getDefaultCertificateOfKey(const Name& keyName) const override;
124 
125  static std::string
126  getScheme();
127 
128  static const std::string SCHEME;
129 
130 private:
131  std::string m_tpmLocator;
132 };
133 
136 
137 namespace tpm {
138 
139 class DummyKeyHandle : public KeyHandle
140 {
141 public:
142  explicit
143  DummyKeyHandle(shared_ptr<transform::PrivateKey> key);
144 
145 private:
147  doSign(DigestAlgorithm digestAlgorithm, const InputBuffers& bufs) const final;
148 
149  bool
150  doVerify(DigestAlgorithm digestAlgorithm, const InputBuffers& bufs, span<const uint8_t> sig) const final;
151 
153  doDecrypt(span<const uint8_t> cipherText) const final;
154 
156  doDerivePublicKey() const final;
157 };
158 
159 } // namespace tpm
160 
163 
164 class DummyTpm : public BackEnd
165 {
166 public:
167  class Error : public BackEnd::Error
168  {
169  public:
170  explicit
171  Error(const std::string& what)
172  : BackEnd::Error(what)
173  {
174  }
175  };
176 
177 public:
178  explicit DummyTpm(const std::string& locator);
179 
180  bool
181  isTerminalMode() const override;
182 
183  void
184  setTerminalMode(bool isTerminal) const override;
185 
186  bool
187  isTpmLocked() const override;
188 
190  sign(const uint8_t* buf, size_t size, const Name& keyName, DigestAlgorithm digestAlgorithm) const;
191 
192  static std::string
193  getScheme();
194 
195 private:
196  bool
197  doHasKey(const Name& keyName) const final;
198 
199  unique_ptr<tpm::KeyHandle>
200  doGetKeyHandle(const Name& keyName) const final;
201 
202  unique_ptr<tpm::KeyHandle>
203  doCreateKey(const Name& identity, const KeyParams& params) final;
204 
205  void
206  doDeleteKey(const Name& keyName) final;
207 
209  doExportKey(const Name& keyName, const char* pw, size_t pwLen) final;
210 
211  void
212  doImportKey(const Name& keyName, span<const uint8_t> pkcs8, const char* pw, size_t pwLen) final;
213 
214  void
215  doImportKey(const Name& keyName, shared_ptr<transform::PrivateKey> key) final;
216 
217 public:
218  static const std::string SCHEME;
219 };
220 
221 } // namespace security
222 } // namespace ndn
223 
224 #endif // NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP
represents a non-semantic error
Definition: pib-impl.hpp:49
static const std::string SCHEME
bool hasKey(const Name &keyName) const override
Check the existence of a key with keyName.
Certificate getDefaultCertificateOfKey(const Name &keyName) const override
Copyright (c) 2011-2015 Regents of the University of California.
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.
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:37
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)
DummyPib(const std::string &locator)
void clearIdentities() override
Erasing all certificates, keys, and identities.
Abstract interface for a TPM backend implementation.
Definition: back-end.hpp:36
static std::string getScheme()
void removeCertificate(const Name &certName) override
Remove a certificate with name certName.
Certificate getCertificate(const Name &certificateName) const override
Get a certificate with name certName.
void addCertificate(const 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.
static const std::string SCHEME
bool hasCertificate(const Name &certName) const override
Check the existence of a certificate with name certName.
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:41
void addKey(const Name &identity, const Name &keyName, span< const uint8_t > key) override
Add a key.
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.
Base class for key parameters.
Definition: key-params.hpp:35
void setDefaultIdentity(const Name &identityName) override
Set an identity with name identityName as the default identity.
span_constexpr std::size_t size(span< T, Extent > const &spn)
Definition: span-lite.hpp:1535
InputBuffers bufs
General-purpose automatically managed/resized buffer.
Definition: buffer.hpp:41
void removeIdentity(const Name &identity) override
Remove an identity and related keys and certificates.
Abstract class of PIB implementation.
Definition: pib-impl.hpp:40
span< const uint8_t > sig
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:139