NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
dummy-keychain.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #include "dummy-keychain.hpp"
21 
22 #include <ndn-cxx/util/io.hpp>
23 #include <boost/iostreams/device/array.hpp>
24 
25 namespace ndn {
26 namespace security {
27 
28 static const uint8_t DUMMY_CERT[] =
29  "Bv0C8Ac4CAVkdW1teQgDa2V5CANLRVkIEWtzay0xNDE4NjAwMzkxMDUwCAdJRC1D"
30  "RVJUCAn9AAABSkssIl4UAxgBAhX9AXMwggFvMCIYDzIwMTQxMjE0MjMzOTUxWhgP"
31  "MjAzNDEyMDkyMzM5NTFaMCUwIwYDVQQpExwvZHVtbXkva2V5L2tzay0xNDE4NjAw"
32  "MzkxMDUwMIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAxUfhv54Jdgeq"
33  "0wmQ/ru9ew/ByCKcQawaZT9Xm9o/sMahwQ9IbNx2Dz4Jkelaxra7+DI0QP3pYctv"
34  "Ykn/jwq5y3cO0LJQB+kf/7FtSKG9qBEv8aqq5hDVteBUKiyUXqDmQzbe+mTcJ9Yd"
35  "D7siF1dhrjnM3KL1xpcXu3QaV5m/I6cKVwYrJxp3JKr6k5pHhxJlPIyUu7oU3kFW"
36  "7bHq2uq4ec9gBXCKwA64IVYVQm1GVDk+V0wr7pw9qD6QNa7eMzrCME6vfM0deSiU"
37  "a4TovUJDQFDsM287kYm3tZu7iuJzmOC63tl4YZdyqyOgnqSrUGE1soNHfLokI13H"
38  "hSwxok7nuQIBERY0GwEBHC8HLQgFZHVtbXkIA2tleQgDS0VZCBFrc2stMTQxODYw"
39  "MDM5MTA1MAgHSUQtQ0VSVBf9AQBLLJoQt9HE93NI3Mv1JCb3ezBCWMwTDnZA+XQV"
40  "UgVSvISJfU/lo2sne0SfGp4KsUhj206CDpuh3q0Th5gKSJeysy/bv66V2m2G8aDn"
41  "OkJ7Ut+2o/QnFpIMJz+oZf2f9Z0Pchocmkv8y4Fj02t8HCuFO1ekEvOcocZvWbKy"
42  "HX+P0OdefPzSC535/rsNHXTzgPsoV+yb13vrm4wPeqPPBs+scQYneIFKkRkGE5PU"
43  "pkncAMBN6iWgmSA2RcjcbmT6utCjJTqWviX1XPQtHoF/hBGC0D/TtQDgwVGGibXB"
44  "zb+klRHvCC/uUIfjU2HrE705kaw8btPhTP5/PMe8YKkk+hjh";
45 
46 static const uint8_t DUMMY_SIGNATURE[] =
47  {0x17, 0xfd, 0x01, 0x00, 0x93, 0x15, 0x09, 0x49, 0x79, 0x9e, 0xb7, 0x9c, 0xd3, 0xc1, 0xbf, 0x61,
48  0x89, 0xd5, 0xd9, 0xca, 0xf2, 0xb0, 0x14, 0xae, 0x72, 0x7c, 0x1f, 0x8f, 0xf5, 0xb1, 0x70, 0xd6,
49  0x9b, 0x8f, 0xf8, 0xd7, 0x2d, 0xbc, 0x92, 0x6f, 0x7d, 0x77, 0x96, 0x46, 0xea, 0xd4, 0x7d, 0x90,
50  0xbc, 0x7a, 0xeb, 0xe2, 0x03, 0x93, 0xb1, 0xd2, 0x62, 0xec, 0x9d, 0xff, 0x9c, 0x9c, 0x2a, 0x14,
51  0x7d, 0x23, 0xca, 0x29, 0x3d, 0x15, 0x1a, 0x40, 0x42, 0x2c, 0x59, 0x33, 0x8a, 0xf7, 0xc0, 0x6b,
52  0xc4, 0x9c, 0xf3, 0xc4, 0x99, 0xa4, 0x1a, 0x60, 0xf5, 0x28, 0x7d, 0x4c, 0xef, 0x43, 0x7d, 0xbd,
53  0x7d, 0x00, 0x51, 0xee, 0x41, 0xf5, 0x25, 0x80, 0xce, 0xe6, 0x64, 0x4f, 0x75, 0x54, 0xf3, 0xb2,
54  0x99, 0x9a, 0x0f, 0x93, 0x9a, 0x28, 0x1d, 0xfe, 0x12, 0x8a, 0xe0, 0xc1, 0x02, 0xeb, 0xa4, 0x35,
55  0x52, 0x88, 0xac, 0x44, 0x1a, 0x44, 0x82, 0x97, 0x4f, 0x5f, 0xa8, 0xd8, 0x9f, 0x67, 0x38, 0xa8,
56  0x64, 0xb6, 0x62, 0x99, 0xbd, 0x96, 0x3c, 0xf5, 0x86, 0x09, 0x5c, 0x97, 0x6b, 0x8f, 0xae, 0xe0,
57  0x60, 0xe7, 0x23, 0x98, 0x6a, 0xee, 0xc1, 0xb0, 0x14, 0xbe, 0x46, 0x2c, 0xfb, 0xa7, 0x27, 0x73,
58  0xe4, 0xf3, 0x26, 0x33, 0xba, 0x99, 0xd4, 0x01, 0x38, 0xa8, 0xf2, 0x9e, 0x87, 0xe0, 0x71, 0x0b,
59  0x25, 0x44, 0x07, 0x35, 0x88, 0xab, 0x67, 0x27, 0x56, 0x0e, 0xb5, 0xb5, 0xe8, 0x27, 0xb4, 0x49,
60  0xdc, 0xb8, 0x48, 0x31, 0xff, 0x99, 0x48, 0xab, 0x11, 0xb4, 0xa0, 0xdf, 0x8a, 0x6d, 0xff, 0x43,
61  0x69, 0x32, 0xa7, 0xbc, 0x63, 0x9d, 0x0f, 0xe0, 0x95, 0x34, 0x36, 0x25, 0x4b, 0x3e, 0x36, 0xbd,
62  0x81, 0x91, 0x0b, 0x91, 0x9f, 0x3a, 0x04, 0xa2, 0x44, 0x28, 0x19, 0xa1, 0x38, 0x21, 0x4f, 0x25,
63  0x59, 0x8a, 0x48, 0xc2};
64 
65 const std::string DummyPublicInfo::SCHEME = "pib-dummy";
66 const std::string DummyTpm::SCHEME = "tpm-dummy";
67 
69 NDN_CXX_KEYCHAIN_REGISTER_TPM(DummyTpm, "tpm-dummy", "dummy");
70 
71 DummyPublicInfo::DummyPublicInfo(const std::string& locator)
72  : SecPublicInfo(locator)
73 {
74 }
75 
76 bool
78 {
79  return true;
80 }
81 
82 void
83 DummyPublicInfo::addIdentity(const Name& identityName)
84 {
85 }
86 
87 bool
89 {
90  return true;
91 }
92 
93 bool
95 {
96  return true;
97 }
98 
99 void
100 DummyPublicInfo::addKey(const Name& keyName, const PublicKey& publicKey)
101 {
102 }
103 
104 shared_ptr<PublicKey>
106 {
107  static shared_ptr<PublicKey> publicKey = nullptr;
108  if (publicKey == nullptr) {
109  typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
110  arrayStream
111  is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
112  auto cert = io::load<IdentityCertificate>(is, io::NO_ENCODING);
113  publicKey = make_shared<PublicKey>(cert->getPublicKeyInfo());
114  }
115 
116  return publicKey;
117 }
118 
119 KeyType
121 {
122  return KEY_TYPE_RSA;
123 }
124 
125 bool
127 {
128  return true;
129 }
130 
131 void
133 {
134 }
135 
136 shared_ptr<IdentityCertificate>
137 DummyPublicInfo::getCertificate(const Name& certificateName)
138 {
139  static shared_ptr<IdentityCertificate> cert = nullptr;
140  if (cert == nullptr) {
141  typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
142  arrayStream
143  is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
144  cert = io::load<IdentityCertificate>(is, io::BASE_64);
145  }
146 
147  return cert;
148 }
149 
150 Name
152 {
153  return "/dummy/key";
154 }
155 
156 Name
158 {
159  return "/dummy/key/ksk-1418600391050";
160 }
161 
162 Name
164 {
165  return "/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E";
166 }
167 
168 void
169 DummyPublicInfo::getAllIdentities(std::vector<Name>& nameList, bool isDefault)
170 {
171  if (isDefault) {
172  nameList.push_back("/dummy");
173  }
174 }
175 
176 void
177 DummyPublicInfo::getAllKeyNames(std::vector<Name>& nameList, bool isDefault)
178 {
179  if (isDefault) {
180  nameList.push_back("/dummy/key/ksk-1418600391050");
181  }
182 }
183 
184 void
185 DummyPublicInfo::getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList,
186  bool isDefault)
187 {
188  if (isDefault) {
189  nameList.push_back("/dummy/key/ksk-1418600391050");
190  }
191 }
192 
193 void
194 DummyPublicInfo::getAllCertificateNames(std::vector<Name>& nameList, bool isDefault)
195 {
196  if (isDefault) {
197  nameList.push_back("/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E");
198  }
199 }
200 
201 void
202 DummyPublicInfo::getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList,
203  bool isDefault)
204 {
205  if (isDefault) {
206  nameList.push_back("/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E");
207  }
208 }
209 
210 void
212 {
213 }
214 
215 void
217 {
218 }
219 
220 void
222 {
223 }
224 
225 void
227 {
228 }
229 
230 void
232 {
233 }
234 
235 void
237 {
238 }
239 
240 void
241 DummyPublicInfo::setTpmLocator(const std::string& tpmLocator)
242 {
243  m_tpmLocator = tpmLocator;
244 }
245 
246 std::string
248 {
249  return m_tpmLocator;
250 }
251 
252 std::string
254 {
256 }
257 
262 
263 DummyTpm::DummyTpm(const std::string& locator)
264  : SecTpm(locator)
265 {
266 }
267 
268 void
269 DummyTpm::setTpmPassword(const uint8_t* password, size_t passwordLength)
270 {
271 }
272 
273 void
275 {
276 }
277 
278 void
279 DummyTpm::setInTerminal(bool inTerminal)
280 {
281 }
282 
283 bool
285 {
286  return false;
287 }
288 
289 bool
291 {
292  return false;
293 }
294 
295 bool
296 DummyTpm::unlockTpm(const char* password, size_t passwordLength, bool usePassword)
297 {
298  return true;
299 }
300 
301 void
302 DummyTpm::generateKeyPairInTpm(const Name& keyName, const KeyParams& params)
303 {
304 }
305 
306 void
308 {
309 }
310 
311 shared_ptr<PublicKey>
313 {
314  return nullptr;
315 }
316 
317 Block
318 DummyTpm::signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName,
319  DigestAlgorithm digestAlgorithm)
320 {
321  return Block(DUMMY_SIGNATURE, sizeof(DUMMY_SIGNATURE));
322 }
323 
325 DummyTpm::decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName,
326  bool isSymmetric)
327 {
328  throw Error("Not supported");
329 }
330 
332 DummyTpm::encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName,
333  bool isSymmetric)
334 {
335  throw Error("Not supported");
336 }
337 
338 void
339 DummyTpm::generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params)
340 {
341 }
342 
343 bool
344 DummyTpm::doesKeyExistInTpm(const Name& keyName, KeyClass keyClass)
345 {
346  return true;
347 }
348 
349 bool
350 DummyTpm::generateRandomBlock(uint8_t* res, size_t size)
351 {
352  return false;
353 }
354 
355 void
356 DummyTpm::addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath,
357  AclType acl)
358 {
359 }
360 
363 {
364  throw Error("Not supported");
365 }
366 
367 bool
368 DummyTpm::importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buffer,
369  size_t bufferSize)
370 {
371  return false;
372 }
373 
374 bool
375 DummyTpm::importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize)
376 {
377  return false;
378 }
379 
380 std::string
382 {
383  return DummyTpm::SCHEME;
384 }
385 
386 } // namespace security
387 } // namespace ndn
virtual shared_ptr< PublicKey > getPublicKey(const Name &keyName)
Get shared pointer to PublicKey object from the identity storage.
virtual bool generateRandomBlock(uint8_t *res, size_t size)
Generate a random block.
virtual Name getDefaultCertificateNameForKey(const Name &keyName)
Get name of the default certificate name for the specified key.
Copyright (c) 2011-2015 Regents of the University of California.
virtual void deleteKeyPairInTpm(const Name &keyName)
Delete a key pair of asymmetric keys.
virtual void deleteCertificateInfo(const Name &certificateName)
Delete a certificate.
static const std::string SCHEME
virtual bool unlockTpm(const char *password, size_t passwordLength, bool usePassword)
Unlock the TPM.
virtual ConstBufferPtr exportPrivateKeyPkcs8FromTpm(const Name &keyName)
Export a private key in PKCS#8 format.
virtual void deleteIdentityInfo(const Name &identity)
Delete an identity and related public keys and certificates.
virtual bool doesKeyExistInTpm(const Name &keyName, KeyClass keyClass)
Check if a particular key exists.
virtual KeyType getPublicKeyType(const Name &keyName)
Get the type of the queried public key.
virtual shared_ptr< IdentityCertificate > getCertificate(const Name &certificateName)
Get a shared pointer to identity certificate object from the identity storage.
virtual void getAllKeyNames(std::vector< Name > &nameList, bool isDefault)
Get all the key names from public info.
virtual void setTpmLocator(const std::string &tpmLocator)
Set the corresponding TPM information to tpmLocator.
virtual bool getInTerminal() const
Get value of inTerminal flag.
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
virtual void resetTpmPassword()
reset password of TPM
virtual bool isLocked()
Check if TPM is locked.
DummyPublicInfo(const std::string &locator)
virtual bool revokeIdentity()
Revoke the identity.
virtual void getAllKeyNamesOfIdentity(const Name &identity, std::vector< Name > &nameList, bool isDefault)
Get all the key names of a particular identity.
virtual std::string getScheme()
return the scheme of the PibLocator
static const uint8_t DUMMY_CERT[]
virtual shared_ptr< PublicKey > getPublicKeyFromTpm(const Name &keyName)
Get a public key.
virtual bool doesPublicKeyExist(const Name &keyName)
Check if the specified key already exists.
SecTpm is the base class of the TPM classes.
Definition: sec-tpm.hpp:41
virtual ConstBufferPtr encryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Encrypt data.
virtual void getAllIdentities(std::vector< Name > &nameList, bool isDefault)
Get all the identities from public info.
static const std::string SCHEME
virtual Name getDefaultIdentity()
Get name of the default identity.
virtual std::string getScheme()
virtual ConstBufferPtr decryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Decrypt data.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
virtual void setDefaultKeyNameForIdentityInternal(const Name &keyName)
Set the default key name for the corresponding identity.
virtual void addKey(const Name &keyName, const PublicKey &publicKey)
Add a public key to the identity storage.
virtual bool doesCertificateExist(const Name &certificateName)
Check if the specified certificate already exists.
static const uint8_t DUMMY_SIGNATURE[]
virtual void getAllCertificateNamesOfKey(const Name &keyName, std::vector< Name > &nameList, bool isDefault)
Get all the certificate name of a particular key name.
virtual Block signInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm)
Sign data.
virtual void deletePublicKeyInfo(const Name &keyName)
Delete a public key and related certificates.
virtual void addAppToAcl(const Name &keyName, KeyClass keyClass, const std::string &appPath, AclType acl)
Add the application into the ACL of a particular key.
virtual void setInTerminal(bool inTerminal)
Set inTerminal flag to.
virtual void addIdentity(const Name &identityName)
Add a new identity.
DummyTpm(const std::string &locator)
virtual void setDefaultCertificateNameForKeyInternal(const Name &certificateName)
Set the default certificate name for the corresponding key.
virtual void generateKeyPairInTpm(const Name &keyName, const KeyParams &params)
Generate a pair of asymmetric keys.
virtual bool importPublicKeyPkcs1IntoTpm(const Name &keyName, const uint8_t *buffer, size_t bufferSize)
Import a public key in PKCS#1 formatted.
Base class of key parameters.
Definition: key-params.hpp:35
#define NDN_CXX_KEYCHAIN_REGISTER_TPM(TpmType,...)
Register SecTpm class in ndn-cxx KeyChain.
Definition: key-chain.hpp:950
virtual bool doesIdentityExist(const Name &identityName)
Check if the specified identity already exists.
virtual void getAllCertificateNames(std::vector< Name > &nameList, bool isDefault)
Get all the certificate name in public info.
virtual bool importPrivateKeyPkcs8IntoTpm(const Name &keyName, const uint8_t *buffer, size_t bufferSize)
Import a private key from PKCS#8 formatted.
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
virtual void setTpmPassword(const uint8_t *password, size_t passwordLength)
set password of TPM
virtual Name getDefaultKeyNameForIdentity(const Name &identityName)
Get name of the default key name for the specified identity.
#define NDN_CXX_KEYCHAIN_REGISTER_PIB(PibType,...)
Register SecPib class in ndn-cxx KeyChain.
Definition: key-chain.hpp:934
virtual std::string getTpmLocator()
Get TPM Locator.
SecPublicInfo is a base class for the storage of public information.
virtual void generateSymmetricKeyInTpm(const Name &keyName, const KeyParams &params)
Generate a symmetric key.
virtual void addCertificate(const IdentityCertificate &certificate)
Add a certificate to the identity storage.
virtual void setDefaultIdentityInternal(const Name &identityName)
Set the default identity.