blob: 2ed729d119b96eb501466b15df1da6b649956dc3 [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
awlaneaf975e52023-10-06 16:23:25 -050016index 00000000..9421fb24
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050017--- /dev/null
18+++ b/ndn-cxx/util/dummy-keychain.cpp
awlaneaf975e52023-10-06 16:23:25 -050019@@ -0,0 +1,348 @@
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+{
awlaneaf975e52023-10-06 16:23:25 -0500167+ static auto cert = [] {
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500168+ typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
awlaneaf975e52023-10-06 16:23:25 -0500169+ arrayStream is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
170+ return io::loadTlv<Certificate>(is, io::BASE64);
171+ }();
172+ return Buffer(cert.getContent().value(), cert.getContent().value_size());
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500173+}
174+
175+std::set<Name>
176+DummyPib::getKeysOfIdentity(const Name& identity) const
177+{
178+ std::set<Name> keys;
179+ keys.insert("/dummy/KEY/-%9C%28r%B8%AA%3B%60");
180+ return keys;
181+}
182+
183+void
184+DummyPib::setDefaultKeyOfIdentity(const Name& identity, const Name& keyName)
185+{
186+}
187+
188+Name
189+DummyPib::getDefaultKeyOfIdentity(const Name& identity) const
190+{
191+ return "/dummy/KEY/-%9C%28r%B8%AA%3B%60";
192+}
193+
194+bool
195+DummyPib::hasCertificate(const Name& certName) const
196+{
197+ return true;
198+}
199+
200+void
awlane2e7b5842023-06-27 08:02:20 -0500201+DummyPib::addCertificate(const Certificate& certificate)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500202+{
203+}
204+
205+void
206+DummyPib::removeCertificate(const Name& certName)
207+{
208+}
209+
awlane2e7b5842023-06-27 08:02:20 -0500210+Certificate
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500211+DummyPib::getCertificate(const Name& certificateName) const
212+{
awlaneaf975e52023-10-06 16:23:25 -0500213+ static auto cert = [] {
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500214+ typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
awlaneaf975e52023-10-06 16:23:25 -0500215+ arrayStream is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
216+ return io::loadTlv<Certificate>(is, io::BASE64);
217+ }();
218+ return cert;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500219+}
220+
221+std::set<Name>
222+DummyPib::getCertificatesOfKey(const Name& keyName) const
223+{
224+ std::set<Name> certs;
225+ certs.insert("/dummy/KEY/-%9C%28r%B8%AA%3B%60/self/%FD%00%00%01%5E%DF%3Bv%01");
226+ return certs;
227+}
228+
229+void
230+DummyPib::setDefaultCertificateOfKey(const Name& keyName, const Name& certName)
231+{
232+}
233+
awlane2e7b5842023-06-27 08:02:20 -0500234+Certificate
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500235+DummyPib::getDefaultCertificateOfKey(const Name& keyName) const
236+{
awlaneaf975e52023-10-06 16:23:25 -0500237+ static auto cert = [] {
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500238+ typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
awlaneaf975e52023-10-06 16:23:25 -0500239+ arrayStream is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
240+ return io::loadTlv<Certificate>(is, io::BASE64);
241+ }();
242+ return cert;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500243+}
244+
245+std::string
246+DummyPib::getScheme()
247+{
248+ return DummyPib::SCHEME;
249+}
250+
251+//////////////////////////////////////////////////////////////////////////////////////////
252+//////////////////////////////////////////////////////////////////////////////////////////
253+//////////////////////////////////////////////////////////////////////////////////////////
254+//////////////////////////////////////////////////////////////////////////////////////////
255+
256+namespace tpm {
257+
258+DummyKeyHandle::DummyKeyHandle(shared_ptr<transform::PrivateKey> key)
259+{
260+}
261+
262+ConstBufferPtr
Alex Lane722dcd52020-06-30 17:37:54 -0500263+DummyKeyHandle::doSign(DigestAlgorithm digestAlgorithm, const InputBuffers& bufs) const
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500264+{
awlaneaf975e52023-10-06 16:23:25 -0500265+ thread_local auto buff = make_shared<Buffer>(DUMMY_SIGNATURE, sizeof(DUMMY_SIGNATURE));
266+ return buff;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500267+}
268+
269+bool
Alex Lane722dcd52020-06-30 17:37:54 -0500270+DummyKeyHandle::doVerify(DigestAlgorithm digestAlgorithm, const InputBuffers& bufs,
awlane49e43c32022-03-22 16:44:40 -0500271+ span<const uint8_t> sig) const
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500272+{
273+ return true;
274+}
275+
276+ConstBufferPtr
awlane49e43c32022-03-22 16:44:40 -0500277+DummyKeyHandle::doDecrypt(span<const uint8_t> cipherText) const
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500278+{
279+ throw Error("Not supported");
280+}
281+
282+ConstBufferPtr
283+DummyKeyHandle::doDerivePublicKey() const
284+{
285+ throw Error("Not supported");
286+}
287+
288+} // namespace tpm
289+
290+//////////////////////////////////////////////////////////////////////////////////////////
291+//////////////////////////////////////////////////////////////////////////////////////////
292+//////////////////////////////////////////////////////////////////////////////////////////
293+//////////////////////////////////////////////////////////////////////////////////////////
294+
295+DummyTpm::DummyTpm(const std::string& locator)
296+{
297+}
298+
299+bool
300+DummyTpm::isTerminalMode() const
301+{
302+ return false;
303+}
304+
305+void
306+DummyTpm::setTerminalMode(bool isTerminal) const
307+{
308+}
309+
310+bool
311+DummyTpm::isTpmLocked() const
312+{
313+ return false;
314+}
315+
316+bool
317+DummyTpm::doHasKey(const Name& keyName) const
318+{
319+ return false;
320+}
321+
322+unique_ptr<tpm::KeyHandle>
323+DummyTpm::doGetKeyHandle(const Name& keyName) const
324+{
325+ unique_ptr<tpm::KeyHandle> m_dummyKeyHandle = make_unique<tpm::DummyKeyHandle>(nullptr);
326+ return m_dummyKeyHandle;
327+}
328+
329+unique_ptr<tpm::KeyHandle>
330+DummyTpm::doCreateKey(const Name& identity, const KeyParams& params)
331+{
332+ unique_ptr<tpm::KeyHandle> m_dummyKeyHandle = make_unique<tpm::DummyKeyHandle>(nullptr);
333+ return m_dummyKeyHandle;
334+}
335+
336+void
337+DummyTpm::doDeleteKey(const Name& keyName)
338+{
339+ throw Error("Not supported");
340+}
341+
342+ConstBufferPtr
343+DummyTpm::doExportKey(const Name& keyName, const char* pw, size_t pwLen)
344+{
345+ throw Error("Not supported");
346+}
347+
348+void
awlane49e43c32022-03-22 16:44:40 -0500349+DummyTpm::doImportKey(const Name& keyName, span<const uint8_t> pkcs8, const char* pw, size_t pwLen)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500350+{
351+ throw Error("Not supported");
352+}
353+
Ashlesh Gawandef48424a2020-04-04 16:58:41 -0700354+void
355+DummyTpm::doImportKey(const Name& keyName, shared_ptr<transform::PrivateKey> key)
356+{
357+ throw Error("Not supported");
358+}
359+
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500360+std::string
361+DummyTpm::getScheme()
362+{
363+ return DummyTpm::SCHEME;
364+}
365+
366+} // namespace security
367+} // namespace ndn
368diff --git a/ndn-cxx/util/dummy-keychain.hpp b/ndn-cxx/util/dummy-keychain.hpp
369new file mode 100644
awlane2e7b5842023-06-27 08:02:20 -0500370index 00000000..bdaea8a2
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500371--- /dev/null
372+++ b/ndn-cxx/util/dummy-keychain.hpp
Ashlesh Gawandef48424a2020-04-04 16:58:41 -0700373@@ -0,0 +1,226 @@
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500374+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
375+/**
376+ * Copyright (c) 2011-2015 Regents of the University of California.
377+ *
378+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
379+ * contributors.
380+ *
381+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
382+ * of the GNU General Public License as published by the Free Software Foundation,
383+ * either version 3 of the License, or (at your option) any later version.
384+ *
385+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
386+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
387+ * PURPOSE. See the GNU General Public License for more details.
388+ *
389+ * You should have received a copy of the GNU General Public License along with
390+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
391+ **/
392+
393+#ifndef NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP
394+#define NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP
395+
396+#include <ndn-cxx/security/key-chain.hpp>
397+#include <ndn-cxx/security/security-common.hpp>
398+#include <ndn-cxx/security/pib/pib-impl.hpp>
399+#include <ndn-cxx/security/tpm/back-end.hpp>
400+#include <ndn-cxx/security/transform/private-key.hpp>
401+
402+namespace ndn {
403+namespace security {
404+
405+using pib::PibImpl;
406+using tpm::BackEnd;
407+using tpm::KeyHandle;
408+
409+class DummyPib : public PibImpl
410+{
411+public:
412+ class Error : public PibImpl::Error
413+ {
414+ public:
415+ explicit
416+ Error(const std::string& what)
417+ : PibImpl::Error(what)
418+ {
419+ }
420+ };
421+
422+public:
423+ explicit DummyPib(const std::string& locator);
424+
425+ // TPM management
426+ void
427+ setTpmLocator(const std::string& tpmLocator) override;
428+
429+ std::string
430+ getTpmLocator() const override;
431+
432+ // Identity manangement
433+ bool
434+ hasIdentity(const Name& identityName) const override;
435+
436+ void
437+ addIdentity(const Name& identityName) override;
438+
439+ void
440+ removeIdentity(const Name& identity) override;
441+
442+ void
443+ clearIdentities() override;
444+
445+ std::set<Name>
446+ getIdentities() const override;
447+
448+ void
449+ setDefaultIdentity(const Name& identityName) override;
450+
451+ Name
452+ getDefaultIdentity() const override;
453+
454+ // Key management
455+ bool
456+ hasKey(const Name& keyName) const override;
457+
458+ void
awlane49e43c32022-03-22 16:44:40 -0500459+ addKey(const Name& identity, const Name& keyName,
460+ span<const uint8_t> key) override;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500461+
462+ void
463+ removeKey(const Name& keyName) override;
464+
465+ Buffer
466+ getKeyBits(const Name& keyName) const override;
467+
468+ std::set<Name>
469+ getKeysOfIdentity(const Name& identity) const override;
470+
471+ void
472+ setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) override;
473+
474+ Name
475+ getDefaultKeyOfIdentity(const Name& identity) const override;
476+
477+ // certificate management
478+ bool
479+ hasCertificate(const Name& certName) const override;
480+
481+ void
awlane2e7b5842023-06-27 08:02:20 -0500482+ addCertificate(const Certificate& certificate) override;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500483+
484+ void
485+ removeCertificate(const Name& certName) override;
486+
awlane2e7b5842023-06-27 08:02:20 -0500487+ Certificate
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500488+ getCertificate(const Name& certificateName) const override;
489+
490+ std::set<Name>
491+ getCertificatesOfKey(const Name& keyName) const override;
492+
493+ void
494+ setDefaultCertificateOfKey(const Name& keyName, const Name& certName) override;
495+
awlane2e7b5842023-06-27 08:02:20 -0500496+ Certificate
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500497+ getDefaultCertificateOfKey(const Name& keyName) const override;
498+
499+ static std::string
500+ getScheme();
501+
502+ static const std::string SCHEME;
503+
504+private:
505+ std::string m_tpmLocator;
506+};
507+
508+//////////////////////////////////////////////////////////////////////////////////////////
509+//////////////////////////////////////////////////////////////////////////////////////////
510+
511+namespace tpm {
512+
513+class DummyKeyHandle : public KeyHandle
514+{
515+public:
516+ explicit
517+ DummyKeyHandle(shared_ptr<transform::PrivateKey> key);
518+
519+private:
520+ ConstBufferPtr
Alex Lane722dcd52020-06-30 17:37:54 -0500521+ doSign(DigestAlgorithm digestAlgorithm, const InputBuffers& bufs) const final;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500522+
523+ bool
Alex Lane722dcd52020-06-30 17:37:54 -0500524+ doVerify(DigestAlgorithm digestAlgorithm, const InputBuffers& bufs,
awlane49e43c32022-03-22 16:44:40 -0500525+ span<const uint8_t> sig) const final;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500526+
527+ ConstBufferPtr
awlane49e43c32022-03-22 16:44:40 -0500528+ doDecrypt(span<const uint8_t> cipherText) const final;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500529+
530+ ConstBufferPtr
531+ doDerivePublicKey() const final;
532+};
533+
534+} // namespace tpm
535+
536+//////////////////////////////////////////////////////////////////////////////////////////
537+//////////////////////////////////////////////////////////////////////////////////////////
538+
539+class DummyTpm : public BackEnd
540+{
541+public:
542+ class Error : public BackEnd::Error
543+ {
544+ public:
545+ explicit
546+ Error(const std::string& what)
547+ : BackEnd::Error(what)
548+ {
549+ }
550+ };
551+
552+public:
553+ explicit DummyTpm(const std::string& locator);
554+
555+ bool
556+ isTerminalMode() const override;
557+
558+ void
559+ setTerminalMode(bool isTerminal) const override;
560+
561+ bool
562+ isTpmLocked() const override;
563+
564+ ConstBufferPtr
565+ sign(const uint8_t* buf, size_t size, const Name& keyName, DigestAlgorithm digestAlgorithm) const;
566+
567+ static std::string
568+ getScheme();
569+
570+private:
571+ bool
572+ doHasKey(const Name& keyName) const final;
573+
574+ unique_ptr<tpm::KeyHandle>
575+ doGetKeyHandle(const Name& keyName) const final;
576+
577+ unique_ptr<tpm::KeyHandle>
578+ doCreateKey(const Name& identity, const KeyParams& params) final;
579+
580+ void
581+ doDeleteKey(const Name& keyName) final;
582+
583+ ConstBufferPtr
584+ doExportKey(const Name& keyName, const char* pw, size_t pwLen) final;
585+
586+ void
awlane49e43c32022-03-22 16:44:40 -0500587+ doImportKey(const Name& keyName, span<const uint8_t> pkcs8, const char* pw, size_t pwLen) final;
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500588+
Ashlesh Gawandef48424a2020-04-04 16:58:41 -0700589+ void
Alex Lane722dcd52020-06-30 17:37:54 -0500590+ doImportKey(const Name& keyName, shared_ptr<transform::PrivateKey> key) final;
Ashlesh Gawandef48424a2020-04-04 16:58:41 -0700591+
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500592+public:
593+ static const std::string SCHEME;
594+};
595+
596+} // namespace security
597+} // namespace ndn
598+
599+#endif // NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP