blob: 6091d619ba55f73912884d8b79b2a21b03bc048b [file] [log] [blame]
Alex Lane722dcd52020-06-30 17:37:54 -05001diff --git a/ndn-cxx/security/key-chain.cpp b/ndn-cxx/security/key-chain.cpp
awlane2e7b5842023-06-27 08:02:20 -05002index 16f6c421..d01696e9 100644
Alex Lane722dcd52020-06-30 17:37:54 -05003--- a/ndn-cxx/security/key-chain.cpp
4+++ b/ndn-cxx/security/key-chain.cpp
awlane2e7b5842023-06-27 08:02:20 -05005@@ -140,7 +140,7 @@ KeyChain::Locator KeyChain::s_defaultTpmLocator;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -05006 //
7
8 KeyChain::KeyChain()
9- : KeyChain(getDefaultPibLocator(), getDefaultTpmLocator(), true)
10+ : KeyChain("pib-dummy", "tpm-dummy", true)
11 {
12 }
13
14diff --git a/ndn-cxx/util/dummy-keychain.cpp b/ndn-cxx/util/dummy-keychain.cpp
15new file mode 100644
awlane2e7b5842023-06-27 08:02:20 -050016index 00000000..dbf399dc
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050017--- /dev/null
18+++ b/ndn-cxx/util/dummy-keychain.cpp
Ashlesh Gawandef48424a2020-04-04 16:58:41 -070019@@ -0,0 +1,352 @@
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050020+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
21+/**
22+ * Copyright (c) 2011-2015 Regents of the University of California.
23+ *
24+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
25+ * contributors.
26+ *
27+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
28+ * of the GNU General Public License as published by the Free Software Foundation,
29+ * either version 3 of the License, or (at your option) any later version.
30+ *
31+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
32+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
33+ * PURPOSE. See the GNU General Public License for more details.
34+ *
35+ * You should have received a copy of the GNU General Public License along with
36+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
37+ **/
38+
39+#include "dummy-keychain.hpp"
40+
41+#include <ndn-cxx/util/io.hpp>
42+#include <ndn-cxx/security/transform/public-key.hpp>
43+#include <boost/iostreams/device/array.hpp>
44+#include <boost/iostreams/stream.hpp>
45+
46+namespace ndn {
47+namespace security {
48+
49+static const uint8_t DUMMY_CERT[] =
50+ "Bv0CqQclCAVkdW1teQgDS0VZCAgtnChyuKo7YAgCTkEICf0AAAFe3zzGfBQJGAEC"
51+ "GQQANu6AFf0BJjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOJSa1j6"
52+ "JAzobrmtlUdJi38EWQZOigLykf9psImvIu7pa29Q3apBXENcV1E9687FmfY85Ec3"
53+ "/onMtN7WG/wiuKiu/9eOr5WslD3VGDgxhesx80ygP0GNsN8FzsMl0lRKduXx3wG4"
54+ "MCT8CX7uA4n4JbHY+0QaKUEEMRCiXcRAtF+yKfr+GaVeSemg+i/LR+6CSgpOyH0K"
55+ "ogH9nlNhBn1Hxyc8X+B/nEu6P6NNEKkSnhT1jAbWtT1eL3BPGK/HNY19w9k2Ln6/"
56+ "OYlhaHfB4m0oR/ePcUguQBwTgYS+40YQYUPivBsSQv3X2/7+gGLhIzA4YppwOooK"
57+ "RGhbmL8zF2evmJ8CAwEAARZHGwEBHBgHFggFZHVtbXkIA0tFWQgILZwocriqO2D9"
58+ "AP0m/QD+DzIwMTcxMDAyVDIyMzczNv0A/w8yMDE4MTAwMlQyMjM3MzUX/QEAMBUV"
59+ "O51BEQwxp646i7IuHkuc1C/LISnOP2+wBFF2Ea1ht9MKjKkyJdmB1/GAOiR3njKd"
60+ "UgRjBlownL11EwYDxkPY39RR05TmhF6PkpP81Ro/Vzv7rtSi/dxFIZXCiyuKPRUx"
61+ "E0pZelPWVs3zMfqQ+8rWG89Kqs1vM0dglLBzlX9Lbim71TyLmaJaMmmBKv8+eQ22"
62+ "CN71sRZOovl1kKcTHpOm61nD3C1n9GRflFtaMAXE/XU4zMJVzBv6XwQl6PCIc9H2"
63+ "vjLa28ruVjhMGxqCGhziTC2eR56SUixrnEcbOKT0R+8+0AFnZIjdYglOZPcVwTVB"
64+ "G6OxECJOuSoREcd1Ww==;";
65+
66+static const uint8_t DUMMY_SIGNATURE[] =
67+ {0x17, 0xfd, 0x01, 0x00, 0x93, 0x15, 0x09, 0x49, 0x79, 0x9e, 0xb7, 0x9c, 0xd3, 0xc1, 0xbf, 0x61,
68+ 0x89, 0xd5, 0xd9, 0xca, 0xf2, 0xb0, 0x14, 0xae, 0x72, 0x7c, 0x1f, 0x8f, 0xf5, 0xb1, 0x70, 0xd6,
69+ 0x9b, 0x8f, 0xf8, 0xd7, 0x2d, 0xbc, 0x92, 0x6f, 0x7d, 0x77, 0x96, 0x46, 0xea, 0xd4, 0x7d, 0x90,
70+ 0xbc, 0x7a, 0xeb, 0xe2, 0x03, 0x93, 0xb1, 0xd2, 0x62, 0xec, 0x9d, 0xff, 0x9c, 0x9c, 0x2a, 0x14,
71+ 0x7d, 0x23, 0xca, 0x29, 0x3d, 0x15, 0x1a, 0x40, 0x42, 0x2c, 0x59, 0x33, 0x8a, 0xf7, 0xc0, 0x6b,
72+ 0xc4, 0x9c, 0xf3, 0xc4, 0x99, 0xa4, 0x1a, 0x60, 0xf5, 0x28, 0x7d, 0x4c, 0xef, 0x43, 0x7d, 0xbd,
73+ 0x7d, 0x00, 0x51, 0xee, 0x41, 0xf5, 0x25, 0x80, 0xce, 0xe6, 0x64, 0x4f, 0x75, 0x54, 0xf3, 0xb2,
74+ 0x99, 0x9a, 0x0f, 0x93, 0x9a, 0x28, 0x1d, 0xfe, 0x12, 0x8a, 0xe0, 0xc1, 0x02, 0xeb, 0xa4, 0x35,
75+ 0x52, 0x88, 0xac, 0x44, 0x1a, 0x44, 0x82, 0x97, 0x4f, 0x5f, 0xa8, 0xd8, 0x9f, 0x67, 0x38, 0xa8,
76+ 0x64, 0xb6, 0x62, 0x99, 0xbd, 0x96, 0x3c, 0xf5, 0x86, 0x09, 0x5c, 0x97, 0x6b, 0x8f, 0xae, 0xe0,
77+ 0x60, 0xe7, 0x23, 0x98, 0x6a, 0xee, 0xc1, 0xb0, 0x14, 0xbe, 0x46, 0x2c, 0xfb, 0xa7, 0x27, 0x73,
78+ 0xe4, 0xf3, 0x26, 0x33, 0xba, 0x99, 0xd4, 0x01, 0x38, 0xa8, 0xf2, 0x9e, 0x87, 0xe0, 0x71, 0x0b,
79+ 0x25, 0x44, 0x07, 0x35, 0x88, 0xab, 0x67, 0x27, 0x56, 0x0e, 0xb5, 0xb5, 0xe8, 0x27, 0xb4, 0x49,
80+ 0xdc, 0xb8, 0x48, 0x31, 0xff, 0x99, 0x48, 0xab, 0x11, 0xb4, 0xa0, 0xdf, 0x8a, 0x6d, 0xff, 0x43,
81+ 0x69, 0x32, 0xa7, 0xbc, 0x63, 0x9d, 0x0f, 0xe0, 0x95, 0x34, 0x36, 0x25, 0x4b, 0x3e, 0x36, 0xbd,
82+ 0x81, 0x91, 0x0b, 0x91, 0x9f, 0x3a, 0x04, 0xa2, 0x44, 0x28, 0x19, 0xa1, 0x38, 0x21, 0x4f, 0x25,
83+ 0x59, 0x8a, 0x48, 0xc2};
84+
85+const std::string DummyPib::SCHEME = "pib-dummy";
86+const std::string DummyTpm::SCHEME = "tpm-dummy";
87+
Alex Lane722dcd52020-06-30 17:37:54 -050088+NDN_CXX_KEYCHAIN_REGISTER_PIB_BACKEND(DummyPib);
89+NDN_CXX_KEYCHAIN_REGISTER_TPM_BACKEND(DummyTpm);
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050090+
91+DummyPib::DummyPib(const std::string& locator)
92+{
93+}
94+
95+void
96+DummyPib::setTpmLocator(const std::string& tpmLocator)
97+{
98+ m_tpmLocator = tpmLocator;
99+}
100+
101+std::string
102+DummyPib::getTpmLocator() const
103+{
104+ return m_tpmLocator;
105+}
106+
107+bool
108+DummyPib::hasIdentity(const Name& identityName) const
109+{
110+ return true;
111+}
112+
113+void
114+DummyPib::addIdentity(const Name& identityName)
115+{
116+}
117+
118+void
119+DummyPib::removeIdentity(const Name& identity)
120+{
121+}
122+
123+void
124+DummyPib::clearIdentities()
125+{
126+}
127+
128+std::set<Name>
129+DummyPib::getIdentities() const
130+{
131+ std::set<Name> identities;
132+ identities.insert("/dummy");
133+ return identities;
134+}
135+
136+void
137+DummyPib::setDefaultIdentity(const Name& identityName)
138+{
139+}
140+
141+Name
142+DummyPib::getDefaultIdentity() const
143+{
144+ return "/dummy";
145+}
146+
147+bool
148+DummyPib::hasKey(const Name& keyName) const
149+{
150+ return true;
151+}
152+
153+void
154+DummyPib::addKey(const Name& identity, const Name& keyName,
awlane49e43c32022-03-22 16:44:40 -0500155+ span<const uint8_t> key)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500156+{
157+}
158+
159+void
160+DummyPib::removeKey(const Name& keyName)
161+{
162+}
163+
164+Buffer
165+DummyPib::getKeyBits(const Name& keyName) const
166+{
167+ typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
168+ arrayStream
169+ is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
awlane2e7b5842023-06-27 08:02:20 -0500170+ auto cert = io::load<Certificate>(is, io::BASE64);
awlane3e95ee82022-05-23 16:24:26 -0500171+ return Buffer(cert->getContent().value(), cert->getContent().value_size());
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500172+}
173+
174+std::set<Name>
175+DummyPib::getKeysOfIdentity(const Name& identity) const
176+{
177+ std::set<Name> keys;
178+ keys.insert("/dummy/KEY/-%9C%28r%B8%AA%3B%60");
179+ return keys;
180+}
181+
182+void
183+DummyPib::setDefaultKeyOfIdentity(const Name& identity, const Name& keyName)
184+{
185+}
186+
187+Name
188+DummyPib::getDefaultKeyOfIdentity(const Name& identity) const
189+{
190+ return "/dummy/KEY/-%9C%28r%B8%AA%3B%60";
191+}
192+
193+bool
194+DummyPib::hasCertificate(const Name& certName) const
195+{
196+ return true;
197+}
198+
199+void
awlane2e7b5842023-06-27 08:02:20 -0500200+DummyPib::addCertificate(const Certificate& certificate)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500201+{
202+}
203+
204+void
205+DummyPib::removeCertificate(const Name& certName)
206+{
207+}
208+
awlane2e7b5842023-06-27 08:02:20 -0500209+Certificate
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500210+DummyPib::getCertificate(const Name& certificateName) const
211+{
awlane2e7b5842023-06-27 08:02:20 -0500212+ static shared_ptr<Certificate> cert = nullptr;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500213+ if (cert == nullptr) {
214+ typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
215+ arrayStream
216+ is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
awlane2e7b5842023-06-27 08:02:20 -0500217+ cert = io::load<Certificate>(is, io::BASE64);
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500218+ }
219+
220+ return *cert;
221+}
222+
223+std::set<Name>
224+DummyPib::getCertificatesOfKey(const Name& keyName) const
225+{
226+ std::set<Name> certs;
227+ certs.insert("/dummy/KEY/-%9C%28r%B8%AA%3B%60/self/%FD%00%00%01%5E%DF%3Bv%01");
228+ return certs;
229+}
230+
231+void
232+DummyPib::setDefaultCertificateOfKey(const Name& keyName, const Name& certName)
233+{
234+}
235+
awlane2e7b5842023-06-27 08:02:20 -0500236+Certificate
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500237+DummyPib::getDefaultCertificateOfKey(const Name& keyName) const
238+{
awlane2e7b5842023-06-27 08:02:20 -0500239+ static shared_ptr<Certificate> cert = nullptr;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500240+ if (cert == nullptr) {
241+ typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
242+ arrayStream
243+ is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
awlane2e7b5842023-06-27 08:02:20 -0500244+ cert = io::load<Certificate>(is, io::BASE64);
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500245+ }
246+
247+ return *cert;
248+}
249+
250+std::string
251+DummyPib::getScheme()
252+{
253+ return DummyPib::SCHEME;
254+}
255+
256+//////////////////////////////////////////////////////////////////////////////////////////
257+//////////////////////////////////////////////////////////////////////////////////////////
258+//////////////////////////////////////////////////////////////////////////////////////////
259+//////////////////////////////////////////////////////////////////////////////////////////
260+
261+namespace tpm {
262+
263+DummyKeyHandle::DummyKeyHandle(shared_ptr<transform::PrivateKey> key)
264+{
265+}
266+
267+ConstBufferPtr
Alex Lane722dcd52020-06-30 17:37:54 -0500268+DummyKeyHandle::doSign(DigestAlgorithm digestAlgorithm, const InputBuffers& bufs) const
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500269+{
270+ return make_shared<Buffer>(DUMMY_SIGNATURE, sizeof(DUMMY_SIGNATURE));
271+}
272+
273+bool
Alex Lane722dcd52020-06-30 17:37:54 -0500274+DummyKeyHandle::doVerify(DigestAlgorithm digestAlgorithm, const InputBuffers& bufs,
awlane49e43c32022-03-22 16:44:40 -0500275+ span<const uint8_t> sig) const
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500276+{
277+ return true;
278+}
279+
280+ConstBufferPtr
awlane49e43c32022-03-22 16:44:40 -0500281+DummyKeyHandle::doDecrypt(span<const uint8_t> cipherText) const
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500282+{
283+ throw Error("Not supported");
284+}
285+
286+ConstBufferPtr
287+DummyKeyHandle::doDerivePublicKey() const
288+{
289+ throw Error("Not supported");
290+}
291+
292+} // namespace tpm
293+
294+//////////////////////////////////////////////////////////////////////////////////////////
295+//////////////////////////////////////////////////////////////////////////////////////////
296+//////////////////////////////////////////////////////////////////////////////////////////
297+//////////////////////////////////////////////////////////////////////////////////////////
298+
299+DummyTpm::DummyTpm(const std::string& locator)
300+{
301+}
302+
303+bool
304+DummyTpm::isTerminalMode() const
305+{
306+ return false;
307+}
308+
309+void
310+DummyTpm::setTerminalMode(bool isTerminal) const
311+{
312+}
313+
314+bool
315+DummyTpm::isTpmLocked() const
316+{
317+ return false;
318+}
319+
320+bool
321+DummyTpm::doHasKey(const Name& keyName) const
322+{
323+ return false;
324+}
325+
326+unique_ptr<tpm::KeyHandle>
327+DummyTpm::doGetKeyHandle(const Name& keyName) const
328+{
329+ unique_ptr<tpm::KeyHandle> m_dummyKeyHandle = make_unique<tpm::DummyKeyHandle>(nullptr);
330+ return m_dummyKeyHandle;
331+}
332+
333+unique_ptr<tpm::KeyHandle>
334+DummyTpm::doCreateKey(const Name& identity, const KeyParams& params)
335+{
336+ unique_ptr<tpm::KeyHandle> m_dummyKeyHandle = make_unique<tpm::DummyKeyHandle>(nullptr);
337+ return m_dummyKeyHandle;
338+}
339+
340+void
341+DummyTpm::doDeleteKey(const Name& keyName)
342+{
343+ throw Error("Not supported");
344+}
345+
346+ConstBufferPtr
347+DummyTpm::doExportKey(const Name& keyName, const char* pw, size_t pwLen)
348+{
349+ throw Error("Not supported");
350+}
351+
352+void
awlane49e43c32022-03-22 16:44:40 -0500353+DummyTpm::doImportKey(const Name& keyName, span<const uint8_t> pkcs8, const char* pw, size_t pwLen)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500354+{
355+ throw Error("Not supported");
356+}
357+
Ashlesh Gawandef48424a2020-04-04 16:58:41 -0700358+void
359+DummyTpm::doImportKey(const Name& keyName, shared_ptr<transform::PrivateKey> key)
360+{
361+ throw Error("Not supported");
362+}
363+
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500364+std::string
365+DummyTpm::getScheme()
366+{
367+ return DummyTpm::SCHEME;
368+}
369+
370+} // namespace security
371+} // namespace ndn
372diff --git a/ndn-cxx/util/dummy-keychain.hpp b/ndn-cxx/util/dummy-keychain.hpp
373new file mode 100644
awlane2e7b5842023-06-27 08:02:20 -0500374index 00000000..bdaea8a2
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500375--- /dev/null
376+++ b/ndn-cxx/util/dummy-keychain.hpp
Ashlesh Gawandef48424a2020-04-04 16:58:41 -0700377@@ -0,0 +1,226 @@
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500378+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
379+/**
380+ * Copyright (c) 2011-2015 Regents of the University of California.
381+ *
382+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
383+ * contributors.
384+ *
385+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
386+ * of the GNU General Public License as published by the Free Software Foundation,
387+ * either version 3 of the License, or (at your option) any later version.
388+ *
389+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
390+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
391+ * PURPOSE. See the GNU General Public License for more details.
392+ *
393+ * You should have received a copy of the GNU General Public License along with
394+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
395+ **/
396+
397+#ifndef NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP
398+#define NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP
399+
400+#include <ndn-cxx/security/key-chain.hpp>
401+#include <ndn-cxx/security/security-common.hpp>
402+#include <ndn-cxx/security/pib/pib-impl.hpp>
403+#include <ndn-cxx/security/tpm/back-end.hpp>
404+#include <ndn-cxx/security/transform/private-key.hpp>
405+
406+namespace ndn {
407+namespace security {
408+
409+using pib::PibImpl;
410+using tpm::BackEnd;
411+using tpm::KeyHandle;
412+
413+class DummyPib : public PibImpl
414+{
415+public:
416+ class Error : public PibImpl::Error
417+ {
418+ public:
419+ explicit
420+ Error(const std::string& what)
421+ : PibImpl::Error(what)
422+ {
423+ }
424+ };
425+
426+public:
427+ explicit DummyPib(const std::string& locator);
428+
429+ // TPM management
430+ void
431+ setTpmLocator(const std::string& tpmLocator) override;
432+
433+ std::string
434+ getTpmLocator() const override;
435+
436+ // Identity manangement
437+ bool
438+ hasIdentity(const Name& identityName) const override;
439+
440+ void
441+ addIdentity(const Name& identityName) override;
442+
443+ void
444+ removeIdentity(const Name& identity) override;
445+
446+ void
447+ clearIdentities() override;
448+
449+ std::set<Name>
450+ getIdentities() const override;
451+
452+ void
453+ setDefaultIdentity(const Name& identityName) override;
454+
455+ Name
456+ getDefaultIdentity() const override;
457+
458+ // Key management
459+ bool
460+ hasKey(const Name& keyName) const override;
461+
462+ void
awlane49e43c32022-03-22 16:44:40 -0500463+ addKey(const Name& identity, const Name& keyName,
464+ span<const uint8_t> key) override;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500465+
466+ void
467+ removeKey(const Name& keyName) override;
468+
469+ Buffer
470+ getKeyBits(const Name& keyName) const override;
471+
472+ std::set<Name>
473+ getKeysOfIdentity(const Name& identity) const override;
474+
475+ void
476+ setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) override;
477+
478+ Name
479+ getDefaultKeyOfIdentity(const Name& identity) const override;
480+
481+ // certificate management
482+ bool
483+ hasCertificate(const Name& certName) const override;
484+
485+ void
awlane2e7b5842023-06-27 08:02:20 -0500486+ addCertificate(const Certificate& certificate) override;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500487+
488+ void
489+ removeCertificate(const Name& certName) override;
490+
awlane2e7b5842023-06-27 08:02:20 -0500491+ Certificate
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500492+ getCertificate(const Name& certificateName) const override;
493+
494+ std::set<Name>
495+ getCertificatesOfKey(const Name& keyName) const override;
496+
497+ void
498+ setDefaultCertificateOfKey(const Name& keyName, const Name& certName) override;
499+
awlane2e7b5842023-06-27 08:02:20 -0500500+ Certificate
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500501+ getDefaultCertificateOfKey(const Name& keyName) const override;
502+
503+ static std::string
504+ getScheme();
505+
506+ static const std::string SCHEME;
507+
508+private:
509+ std::string m_tpmLocator;
510+};
511+
512+//////////////////////////////////////////////////////////////////////////////////////////
513+//////////////////////////////////////////////////////////////////////////////////////////
514+
515+namespace tpm {
516+
517+class DummyKeyHandle : public KeyHandle
518+{
519+public:
520+ explicit
521+ DummyKeyHandle(shared_ptr<transform::PrivateKey> key);
522+
523+private:
524+ ConstBufferPtr
Alex Lane722dcd52020-06-30 17:37:54 -0500525+ doSign(DigestAlgorithm digestAlgorithm, const InputBuffers& bufs) const final;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500526+
527+ bool
Alex Lane722dcd52020-06-30 17:37:54 -0500528+ doVerify(DigestAlgorithm digestAlgorithm, const InputBuffers& bufs,
awlane49e43c32022-03-22 16:44:40 -0500529+ span<const uint8_t> sig) const final;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500530+
531+ ConstBufferPtr
awlane49e43c32022-03-22 16:44:40 -0500532+ doDecrypt(span<const uint8_t> cipherText) const final;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500533+
534+ ConstBufferPtr
535+ doDerivePublicKey() const final;
536+};
537+
538+} // namespace tpm
539+
540+//////////////////////////////////////////////////////////////////////////////////////////
541+//////////////////////////////////////////////////////////////////////////////////////////
542+
543+class DummyTpm : public BackEnd
544+{
545+public:
546+ class Error : public BackEnd::Error
547+ {
548+ public:
549+ explicit
550+ Error(const std::string& what)
551+ : BackEnd::Error(what)
552+ {
553+ }
554+ };
555+
556+public:
557+ explicit DummyTpm(const std::string& locator);
558+
559+ bool
560+ isTerminalMode() const override;
561+
562+ void
563+ setTerminalMode(bool isTerminal) const override;
564+
565+ bool
566+ isTpmLocked() const override;
567+
568+ ConstBufferPtr
569+ sign(const uint8_t* buf, size_t size, const Name& keyName, DigestAlgorithm digestAlgorithm) const;
570+
571+ static std::string
572+ getScheme();
573+
574+private:
575+ bool
576+ doHasKey(const Name& keyName) const final;
577+
578+ unique_ptr<tpm::KeyHandle>
579+ doGetKeyHandle(const Name& keyName) const final;
580+
581+ unique_ptr<tpm::KeyHandle>
582+ doCreateKey(const Name& identity, const KeyParams& params) final;
583+
584+ void
585+ doDeleteKey(const Name& keyName) final;
586+
587+ ConstBufferPtr
588+ doExportKey(const Name& keyName, const char* pw, size_t pwLen) final;
589+
590+ void
awlane49e43c32022-03-22 16:44:40 -0500591+ doImportKey(const Name& keyName, span<const uint8_t> pkcs8, const char* pw, size_t pwLen) final;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500592+
Ashlesh Gawandef48424a2020-04-04 16:58:41 -0700593+ void
Alex Lane722dcd52020-06-30 17:37:54 -0500594+ doImportKey(const Name& keyName, shared_ptr<transform::PrivateKey> key) final;
Ashlesh Gawandef48424a2020-04-04 16:58:41 -0700595+
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500596+public:
597+ static const std::string SCHEME;
598+};
599+
600+} // namespace security
601+} // namespace ndn
602+
603+#endif // NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP