NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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>
24 #include <boost/iostreams/device/array.hpp>
25 #include <boost/iostreams/stream.hpp>
26 
27 namespace ndn {
28 namespace security {
29 
30 static const uint8_t DUMMY_CERT[] =
31  "Bv0CqQclCAVkdW1teQgDS0VZCAgtnChyuKo7YAgCTkEICf0AAAFe3zzGfBQJGAEC"
32  "GQQANu6AFf0BJjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOJSa1j6"
33  "JAzobrmtlUdJi38EWQZOigLykf9psImvIu7pa29Q3apBXENcV1E9687FmfY85Ec3"
34  "/onMtN7WG/wiuKiu/9eOr5WslD3VGDgxhesx80ygP0GNsN8FzsMl0lRKduXx3wG4"
35  "MCT8CX7uA4n4JbHY+0QaKUEEMRCiXcRAtF+yKfr+GaVeSemg+i/LR+6CSgpOyH0K"
36  "ogH9nlNhBn1Hxyc8X+B/nEu6P6NNEKkSnhT1jAbWtT1eL3BPGK/HNY19w9k2Ln6/"
37  "OYlhaHfB4m0oR/ePcUguQBwTgYS+40YQYUPivBsSQv3X2/7+gGLhIzA4YppwOooK"
38  "RGhbmL8zF2evmJ8CAwEAARZHGwEBHBgHFggFZHVtbXkIA0tFWQgILZwocriqO2D9"
39  "AP0m/QD+DzIwMTcxMDAyVDIyMzczNv0A/w8yMDE4MTAwMlQyMjM3MzUX/QEAMBUV"
40  "O51BEQwxp646i7IuHkuc1C/LISnOP2+wBFF2Ea1ht9MKjKkyJdmB1/GAOiR3njKd"
41  "UgRjBlownL11EwYDxkPY39RR05TmhF6PkpP81Ro/Vzv7rtSi/dxFIZXCiyuKPRUx"
42  "E0pZelPWVs3zMfqQ+8rWG89Kqs1vM0dglLBzlX9Lbim71TyLmaJaMmmBKv8+eQ22"
43  "CN71sRZOovl1kKcTHpOm61nD3C1n9GRflFtaMAXE/XU4zMJVzBv6XwQl6PCIc9H2"
44  "vjLa28ruVjhMGxqCGhziTC2eR56SUixrnEcbOKT0R+8+0AFnZIjdYglOZPcVwTVB"
45  "G6OxECJOuSoREcd1Ww==;";
46 
47 static const uint8_t DUMMY_SIGNATURE[] =
48  {0x17, 0xfd, 0x01, 0x00, 0x93, 0x15, 0x09, 0x49, 0x79, 0x9e, 0xb7, 0x9c, 0xd3, 0xc1, 0xbf, 0x61,
49  0x89, 0xd5, 0xd9, 0xca, 0xf2, 0xb0, 0x14, 0xae, 0x72, 0x7c, 0x1f, 0x8f, 0xf5, 0xb1, 0x70, 0xd6,
50  0x9b, 0x8f, 0xf8, 0xd7, 0x2d, 0xbc, 0x92, 0x6f, 0x7d, 0x77, 0x96, 0x46, 0xea, 0xd4, 0x7d, 0x90,
51  0xbc, 0x7a, 0xeb, 0xe2, 0x03, 0x93, 0xb1, 0xd2, 0x62, 0xec, 0x9d, 0xff, 0x9c, 0x9c, 0x2a, 0x14,
52  0x7d, 0x23, 0xca, 0x29, 0x3d, 0x15, 0x1a, 0x40, 0x42, 0x2c, 0x59, 0x33, 0x8a, 0xf7, 0xc0, 0x6b,
53  0xc4, 0x9c, 0xf3, 0xc4, 0x99, 0xa4, 0x1a, 0x60, 0xf5, 0x28, 0x7d, 0x4c, 0xef, 0x43, 0x7d, 0xbd,
54  0x7d, 0x00, 0x51, 0xee, 0x41, 0xf5, 0x25, 0x80, 0xce, 0xe6, 0x64, 0x4f, 0x75, 0x54, 0xf3, 0xb2,
55  0x99, 0x9a, 0x0f, 0x93, 0x9a, 0x28, 0x1d, 0xfe, 0x12, 0x8a, 0xe0, 0xc1, 0x02, 0xeb, 0xa4, 0x35,
56  0x52, 0x88, 0xac, 0x44, 0x1a, 0x44, 0x82, 0x97, 0x4f, 0x5f, 0xa8, 0xd8, 0x9f, 0x67, 0x38, 0xa8,
57  0x64, 0xb6, 0x62, 0x99, 0xbd, 0x96, 0x3c, 0xf5, 0x86, 0x09, 0x5c, 0x97, 0x6b, 0x8f, 0xae, 0xe0,
58  0x60, 0xe7, 0x23, 0x98, 0x6a, 0xee, 0xc1, 0xb0, 0x14, 0xbe, 0x46, 0x2c, 0xfb, 0xa7, 0x27, 0x73,
59  0xe4, 0xf3, 0x26, 0x33, 0xba, 0x99, 0xd4, 0x01, 0x38, 0xa8, 0xf2, 0x9e, 0x87, 0xe0, 0x71, 0x0b,
60  0x25, 0x44, 0x07, 0x35, 0x88, 0xab, 0x67, 0x27, 0x56, 0x0e, 0xb5, 0xb5, 0xe8, 0x27, 0xb4, 0x49,
61  0xdc, 0xb8, 0x48, 0x31, 0xff, 0x99, 0x48, 0xab, 0x11, 0xb4, 0xa0, 0xdf, 0x8a, 0x6d, 0xff, 0x43,
62  0x69, 0x32, 0xa7, 0xbc, 0x63, 0x9d, 0x0f, 0xe0, 0x95, 0x34, 0x36, 0x25, 0x4b, 0x3e, 0x36, 0xbd,
63  0x81, 0x91, 0x0b, 0x91, 0x9f, 0x3a, 0x04, 0xa2, 0x44, 0x28, 0x19, 0xa1, 0x38, 0x21, 0x4f, 0x25,
64  0x59, 0x8a, 0x48, 0xc2};
65 
66 const std::string DummyPib::SCHEME = "pib-dummy";
67 const std::string DummyTpm::SCHEME = "tpm-dummy";
68 
71 
72 DummyPib::DummyPib(const std::string& locator)
73 {
74 }
75 
76 void
77 DummyPib::setTpmLocator(const std::string& tpmLocator)
78 {
79  m_tpmLocator = tpmLocator;
80 }
81 
82 std::string
84 {
85  return m_tpmLocator;
86 }
87 
88 bool
89 DummyPib::hasIdentity(const Name& identityName) const
90 {
91  return true;
92 }
93 
94 void
95 DummyPib::addIdentity(const Name& identityName)
96 {
97 }
98 
99 void
101 {
102 }
103 
104 void
106 {
107 }
108 
109 std::set<Name>
111 {
112  std::set<Name> identities;
113  identities.insert("/dummy");
114  return identities;
115 }
116 
117 void
118 DummyPib::setDefaultIdentity(const Name& identityName)
119 {
120 }
121 
122 Name
124 {
125  return "/dummy";
126 }
127 
128 bool
129 DummyPib::hasKey(const Name& keyName) const
130 {
131  return true;
132 }
133 
134 void
135 DummyPib::addKey(const Name& identity, const Name& keyName,
136  const uint8_t* key, size_t keyLen)
137 {
138 }
139 
140 void
141 DummyPib::removeKey(const Name& keyName)
142 {
143 }
144 
145 Buffer
146 DummyPib::getKeyBits(const Name& keyName) const
147 {
148  typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
149  arrayStream
150  is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
151  auto cert = io::load<v2::Certificate>(is, io::BASE64);
152  return cert->getPublicKey();
153 }
154 
155 std::set<Name>
156 DummyPib::getKeysOfIdentity(const Name& identity) const
157 {
158  std::set<Name> keys;
159  keys.insert("/dummy/KEY/-%9C%28r%B8%AA%3B%60");
160  return keys;
161 }
162 
163 void
164 DummyPib::setDefaultKeyOfIdentity(const Name& identity, const Name& keyName)
165 {
166 }
167 
168 Name
170 {
171  return "/dummy/KEY/-%9C%28r%B8%AA%3B%60";
172 }
173 
174 bool
175 DummyPib::hasCertificate(const Name& certName) const
176 {
177  return true;
178 }
179 
180 void
182 {
183 }
184 
185 void
187 {
188 }
189 
191 DummyPib::getCertificate(const Name& certificateName) const
192 {
193  static shared_ptr<v2::Certificate> cert = nullptr;
194  if (cert == nullptr) {
195  typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
196  arrayStream
197  is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
198  cert = io::load<v2::Certificate>(is, io::BASE64);
199  }
200 
201  return *cert;
202 }
203 
204 std::set<Name>
206 {
207  std::set<Name> certs;
208  certs.insert("/dummy/KEY/-%9C%28r%B8%AA%3B%60/self/%FD%00%00%01%5E%DF%3Bv%01");
209  return certs;
210 }
211 
212 void
213 DummyPib::setDefaultCertificateOfKey(const Name& keyName, const Name& certName)
214 {
215 }
216 
219 {
220  static shared_ptr<v2::Certificate> cert = nullptr;
221  if (cert == nullptr) {
222  typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
223  arrayStream
224  is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
225  cert = io::load<v2::Certificate>(is, io::BASE64);
226  }
227 
228  return *cert;
229 }
230 
231 std::string
233 {
234  return DummyPib::SCHEME;
235 }
236 
241 
242 namespace tpm {
243 
244 DummyKeyHandle::DummyKeyHandle(shared_ptr<transform::PrivateKey> key)
245 {
246 }
247 
249 DummyKeyHandle::doSign(DigestAlgorithm digestAlgorithm, const uint8_t* buf, size_t size) const
250 {
251  return make_shared<Buffer>(DUMMY_SIGNATURE, sizeof(DUMMY_SIGNATURE));
252 }
253 
254 bool
255 DummyKeyHandle::doVerify(DigestAlgorithm digestAlgorithm, const uint8_t* buf, size_t bufLen,
256  const uint8_t* sig, size_t sigLen) const
257 {
258  throw Error("Not supported");
259 }
260 
262 DummyKeyHandle::doDecrypt(const uint8_t* cipherText, size_t cipherTextLen) const
263 {
264  throw Error("Not supported");
265 }
266 
268 DummyKeyHandle::doDerivePublicKey() const
269 {
270  throw Error("Not supported");
271 }
272 
273 } // namespace tpm
274 
279 
280 DummyTpm::DummyTpm(const std::string& locator)
281 {
282 }
283 
284 bool
286 {
287  return false;
288 }
289 
290 void
291 DummyTpm::setTerminalMode(bool isTerminal) const
292 {
293 }
294 
295 bool
297 {
298  return false;
299 }
300 
301 bool
302 DummyTpm::doHasKey(const Name& keyName) const
303 {
304  return false;
305 }
306 
307 unique_ptr<tpm::KeyHandle>
308 DummyTpm::doGetKeyHandle(const Name& keyName) const
309 {
310  unique_ptr<tpm::KeyHandle> m_dummyKeyHandle = make_unique<tpm::DummyKeyHandle>(nullptr);
311  return m_dummyKeyHandle;
312 }
313 
314 unique_ptr<tpm::KeyHandle>
315 DummyTpm::doCreateKey(const Name& identity, const KeyParams& params)
316 {
317  unique_ptr<tpm::KeyHandle> m_dummyKeyHandle = make_unique<tpm::DummyKeyHandle>(nullptr);
318  return m_dummyKeyHandle;
319 }
320 
321 void
322 DummyTpm::doDeleteKey(const Name& keyName)
323 {
324  throw Error("Not supported");
325 }
326 
328 DummyTpm::doExportKey(const Name& keyName, const char* pw, size_t pwLen)
329 {
330  throw Error("Not supported");
331 }
332 
333 void
334 DummyTpm::doImportKey(const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Len, const char* pw, size_t pwLen)
335 {
336  throw Error("Not supported");
337 }
338 
339 void
340 DummyTpm::doImportKey(const Name& keyName, shared_ptr<transform::PrivateKey> key)
341 {
342  throw Error("Not supported");
343 }
344 
345 std::string
347 {
348  return DummyTpm::SCHEME;
349 }
350 
351 } // namespace security
352 } // namespace ndn
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
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
dummy-keychain.hpp
ndn::Buffer
General-purpose automatically managed/resized buffer.
Definition: buffer.hpp:41
ndn::security::tpm::BackEnd::Error
Tpm::Error Error
Definition: back-end.hpp:39
ndn::security::DummyPib::addCertificate
void addCertificate(const v2::Certificate &certificate) override
Add a certificate.
Definition: dummy-keychain.cpp:181
ndn::security::DUMMY_CERT
static const uint8_t DUMMY_CERT[]
Definition: dummy-keychain.cpp:30
ndn::security::DummyTpm::setTerminalMode
void setTerminalMode(bool isTerminal) const override
Set the terminal mode of the TPM.
Definition: dummy-keychain.cpp:291
public-key.hpp
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::io::BASE64
@ BASE64
Base64 encoding.
Definition: io.hpp:51
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::DummyTpm::isTpmLocked
bool isTpmLocked() const override
Check if the TPM is locked.
Definition: dummy-keychain.cpp:296
ndn::security::DummyPib::removeIdentity
void removeIdentity(const Name &identity) override
Remove an identity and related keys and certificates.
Definition: dummy-keychain.cpp:100
ndn::security::DUMMY_SIGNATURE
static const uint8_t DUMMY_SIGNATURE[]
Definition: dummy-keychain.cpp:47
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
io.hpp
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
ns3::ndn::Name
Name
Definition: ndn-common.cpp:25
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
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::NDN_CXX_V2_KEYCHAIN_REGISTER_TPM_BACKEND
NDN_CXX_V2_KEYCHAIN_REGISTER_TPM_BACKEND(DummyTpm)
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
ndn::security::NDN_CXX_V2_KEYCHAIN_REGISTER_PIB_BACKEND
NDN_CXX_V2_KEYCHAIN_REGISTER_PIB_BACKEND(DummyPib)
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::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
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::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