blob: c173117600251ccc9a6d346b0250ca10b6e7cbc5 [file] [log] [blame]
Alexander Afanasyev07113802015-01-15 19:14:36 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu99b2a002015-08-12 12:47:44 -07003 * Copyright (c) 2013-2016 Regents of the University of California.
Alexander Afanasyev07113802015-01-15 19:14:36 -08004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#include "dummy-keychain.hpp"
Junxiao Shi160701a2016-08-30 11:35:25 +000023#include "encoding/buffer-stream.hpp"
Alexander Afanasyev07113802015-01-15 19:14:36 -080024#include "util/io.hpp"
25#include <boost/iostreams/device/array.hpp>
26
27namespace ndn {
28namespace security {
29
30static const uint8_t DUMMY_CERT[] =
31 "Bv0C8Ac4CAVkdW1teQgDa2V5CANLRVkIEWtzay0xNDE4NjAwMzkxMDUwCAdJRC1D"
32 "RVJUCAn9AAABSkssIl4UAxgBAhX9AXMwggFvMCIYDzIwMTQxMjE0MjMzOTUxWhgP"
33 "MjAzNDEyMDkyMzM5NTFaMCUwIwYDVQQpExwvZHVtbXkva2V5L2tzay0xNDE4NjAw"
34 "MzkxMDUwMIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAxUfhv54Jdgeq"
35 "0wmQ/ru9ew/By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d, 0x77, 0x96, 0x46, 0xea, 0xd4, 0x7d, 0x90,
52 0xbc, 0x7a, 0xeb, 0xe2, 0x03, 0x93, 0xb1, 0xd2, 0x62, 0xec, 0x9d, 0xff, 0x9c, 0x9c, 0x2a, 0x14,
53 0x7d, 0x23, 0xca, 0x29, 0x3d, 0x15, 0x1a, 0x40, 0x42, 0x2c, 0x59, 0x33, 0x8a, 0xf7, 0xc0, 0x6b,
54 0xc4, 0x9c, 0xf3, 0xc4, 0x99, 0xa4, 0x1a, 0x60, 0xf5, 0x28, 0x7d, 0x4c, 0xef, 0x43, 0x7d, 0xbd,
55 0x7d, 0x00, 0x51, 0xee, 0x41, 0xf5, 0x25, 0x80, 0xce, 0xe6, 0x64, 0x4f, 0x75, 0x54, 0xf3, 0xb2,
56 0x99, 0x9a, 0x0f, 0x93, 0x9a, 0x28, 0x1d, 0xfe, 0x12, 0x8a, 0xe0, 0xc1, 0x02, 0xeb, 0xa4, 0x35,
57 0x52, 0x88, 0xac, 0x44, 0x1a, 0x44, 0x82, 0x97, 0x4f, 0x5f, 0xa8, 0xd8, 0x9f, 0x67, 0x38, 0xa8,
58 0x64, 0xb6, 0x62, 0x99, 0xbd, 0x96, 0x3c, 0xf5, 0x86, 0x09, 0x5c, 0x97, 0x6b, 0x8f, 0xae, 0xe0,
59 0x60, 0xe7, 0x23, 0x98, 0x6a, 0xee, 0xc1, 0xb0, 0x14, 0xbe, 0x46, 0x2c, 0xfb, 0xa7, 0x27, 0x73,
60 0xe4, 0xf3, 0x26, 0x33, 0xba, 0x99, 0xd4, 0x01, 0x38, 0xa8, 0xf2, 0x9e, 0x87, 0xe0, 0x71, 0x0b,
61 0x25, 0x44, 0x07, 0x35, 0x88, 0xab, 0x67, 0x27, 0x56, 0x0e, 0xb5, 0xb5, 0xe8, 0x27, 0xb4, 0x49,
62 0xdc, 0xb8, 0x48, 0x31, 0xff, 0x99, 0x48, 0xab, 0x11, 0xb4, 0xa0, 0xdf, 0x8a, 0x6d, 0xff, 0x43,
63 0x69, 0x32, 0xa7, 0xbc, 0x63, 0x9d, 0x0f, 0xe0, 0x95, 0x34, 0x36, 0x25, 0x4b, 0x3e, 0x36, 0xbd,
64 0x81, 0x91, 0x0b, 0x91, 0x9f, 0x3a, 0x04, 0xa2, 0x44, 0x28, 0x19, 0xa1, 0x38, 0x21, 0x4f, 0x25,
65 0x59, 0x8a, 0x48, 0xc2};
66
67const std::string DummyPublicInfo::SCHEME = "pib-dummy";
68const std::string DummyTpm::SCHEME = "tpm-dummy";
69
70NDN_CXX_KEYCHAIN_REGISTER_PIB(DummyPublicInfo, "pib-dummy", "dummy");
71NDN_CXX_KEYCHAIN_REGISTER_TPM(DummyTpm, "tpm-dummy", "dummy");
72
Alexander Afanasyev34a37632015-01-16 17:37:36 -080073typedef DummyPublicInfo DummyPublicInfo2;
74typedef DummyTpm DummyTpm2;
75
76NDN_CXX_KEYCHAIN_REGISTER_PIB(DummyPublicInfo2, "pib-dummy2");
77NDN_CXX_KEYCHAIN_REGISTER_TPM(DummyTpm2, "tpm-dummy2");
78
Alexander Afanasyev07113802015-01-15 19:14:36 -080079DummyPublicInfo::DummyPublicInfo(const std::string& locator)
80 : SecPublicInfo(locator)
81{
82}
83
84bool
85DummyPublicInfo::doesIdentityExist(const Name& identityName)
86{
87 return true;
88}
89
90void
91DummyPublicInfo::addIdentity(const Name& identityName)
92{
93}
94
95bool
96DummyPublicInfo::revokeIdentity()
97{
98 return true;
99}
100
101bool
102DummyPublicInfo::doesPublicKeyExist(const Name& keyName)
103{
104 return true;
105}
106
107void
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700108DummyPublicInfo::addKey(const Name& keyName, const v1::PublicKey& publicKey)
Alexander Afanasyev07113802015-01-15 19:14:36 -0800109{
110}
111
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700112shared_ptr<v1::PublicKey>
Alexander Afanasyev07113802015-01-15 19:14:36 -0800113DummyPublicInfo::getPublicKey(const Name& keyName)
114{
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700115 static shared_ptr<v1::PublicKey> publicKey = nullptr;
Alexander Afanasyev07113802015-01-15 19:14:36 -0800116 if (publicKey == nullptr) {
Junxiao Shi4ce0bcf2016-09-03 07:09:03 +0000117 typedef boost::iostreams::stream<boost::iostreams::array_source> ArrayStream;
118 ArrayStream is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700119 auto cert = io::load<v1::IdentityCertificate>(is, io::NO_ENCODING);
120 publicKey = make_shared<v1::PublicKey>(cert->getPublicKeyInfo());
Alexander Afanasyev07113802015-01-15 19:14:36 -0800121 }
122
123 return publicKey;
124}
125
126KeyType
127DummyPublicInfo::getPublicKeyType(const Name& keyName)
128{
Yingdi Yu99b2a002015-08-12 12:47:44 -0700129 return KeyType::RSA;
Alexander Afanasyev07113802015-01-15 19:14:36 -0800130}
131
132bool
133DummyPublicInfo::doesCertificateExist(const Name& certificateName)
134{
135 return true;
136}
137
138void
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700139DummyPublicInfo::addCertificate(const v1::IdentityCertificate& certificate)
Alexander Afanasyev07113802015-01-15 19:14:36 -0800140{
141}
142
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700143shared_ptr<v1::IdentityCertificate>
Alexander Afanasyev07113802015-01-15 19:14:36 -0800144DummyPublicInfo::getCertificate(const Name& certificateName)
145{
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700146 static shared_ptr<v1::IdentityCertificate> cert = nullptr;
Alexander Afanasyev07113802015-01-15 19:14:36 -0800147 if (cert == nullptr) {
Junxiao Shi4ce0bcf2016-09-03 07:09:03 +0000148 typedef boost::iostreams::stream<boost::iostreams::array_source> ArrayStream;
149 ArrayStream is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
150 cert = io::load<v1::IdentityCertificate>(is);
Alexander Afanasyev07113802015-01-15 19:14:36 -0800151 }
152
153 return cert;
154}
155
156Name
157DummyPublicInfo::getDefaultIdentity()
158{
159 return "/dummy/key";
160}
161
162Name
163DummyPublicInfo::getDefaultKeyNameForIdentity(const Name& identityName)
164{
165 return "/dummy/key/ksk-1418600391050";
166}
167
168Name
169DummyPublicInfo::getDefaultCertificateNameForKey(const Name& keyName)
170{
171 return "/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E";
172}
173
174void
175DummyPublicInfo::getAllIdentities(std::vector<Name>& nameList, bool isDefault)
176{
177 if (isDefault) {
178 nameList.push_back("/dummy");
179 }
180}
181
182void
183DummyPublicInfo::getAllKeyNames(std::vector<Name>& nameList, bool isDefault)
184{
185 if (isDefault) {
186 nameList.push_back("/dummy/key/ksk-1418600391050");
187 }
188}
189
190void
191DummyPublicInfo::getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList,
192 bool isDefault)
193{
194 if (isDefault) {
195 nameList.push_back("/dummy/key/ksk-1418600391050");
196 }
197}
198
199void
200DummyPublicInfo::getAllCertificateNames(std::vector<Name>& nameList, bool isDefault)
201{
202 if (isDefault) {
203 nameList.push_back("/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E");
204 }
205}
206
207void
208DummyPublicInfo::getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList,
209 bool isDefault)
210{
211 if (isDefault) {
212 nameList.push_back("/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E");
213 }
214}
215
216void
217DummyPublicInfo::deleteCertificateInfo(const Name& certificateName)
218{
219}
220
221void
222DummyPublicInfo::deletePublicKeyInfo(const Name& keyName)
223{
224}
225
226void
227DummyPublicInfo::deleteIdentityInfo(const Name& identity)
228{
229}
230
231void
232DummyPublicInfo::setDefaultIdentityInternal(const Name& identityName)
233{
234}
235
236void
237DummyPublicInfo::setDefaultKeyNameForIdentityInternal(const Name& keyName)
238{
239}
240
241void
242DummyPublicInfo::setDefaultCertificateNameForKeyInternal(const Name& certificateName)
243{
244}
245
246void
247DummyPublicInfo::setTpmLocator(const std::string& tpmLocator)
248{
249 m_tpmLocator = tpmLocator;
250}
251
252std::string
253DummyPublicInfo::getTpmLocator()
254{
255 return m_tpmLocator;
256}
257
258std::string
259DummyPublicInfo::getScheme()
260{
261 return DummyPublicInfo::SCHEME;
262}
263
264//////////////////////////////////////////////////////////////////////////////////////////
265//////////////////////////////////////////////////////////////////////////////////////////
266//////////////////////////////////////////////////////////////////////////////////////////
267//////////////////////////////////////////////////////////////////////////////////////////
268
269DummyTpm::DummyTpm(const std::string& locator)
270 : SecTpm(locator)
271{
272}
273
274void
275DummyTpm::setTpmPassword(const uint8_t* password, size_t passwordLength)
276{
277}
278
279void
280DummyTpm::resetTpmPassword()
281{
282}
283
284void
285DummyTpm::setInTerminal(bool inTerminal)
286{
287}
288
289bool
290DummyTpm::getInTerminal() const
291{
292 return false;
293}
294
295bool
296DummyTpm::isLocked()
297{
298 return false;
299}
300
301bool
302DummyTpm::unlockTpm(const char* password, size_t passwordLength, bool usePassword)
303{
304 return true;
305}
306
307void
308DummyTpm::generateKeyPairInTpm(const Name& keyName, const KeyParams& params)
309{
310}
311
312void
313DummyTpm::deleteKeyPairInTpm(const Name& keyName)
314{
315}
316
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700317shared_ptr<v1::PublicKey>
Alexander Afanasyev07113802015-01-15 19:14:36 -0800318DummyTpm::getPublicKeyFromTpm(const Name& keyName)
319{
320 return nullptr;
321}
322
323Block
324DummyTpm::signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName,
325 DigestAlgorithm digestAlgorithm)
326{
327 return Block(DUMMY_SIGNATURE, sizeof(DUMMY_SIGNATURE));
328}
329
330ConstBufferPtr
331DummyTpm::decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName,
332 bool isSymmetric)
333{
Spyridon Mastorakis0d2ed2e2015-07-27 19:09:12 -0700334 BOOST_THROW_EXCEPTION(Error("Not supported"));
Alexander Afanasyev07113802015-01-15 19:14:36 -0800335}
336
337ConstBufferPtr
338DummyTpm::encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName,
339 bool isSymmetric)
340{
Spyridon Mastorakis0d2ed2e2015-07-27 19:09:12 -0700341 BOOST_THROW_EXCEPTION(Error("Not supported"));
Alexander Afanasyev07113802015-01-15 19:14:36 -0800342}
343
344void
345DummyTpm::generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params)
346{
347}
348
349bool
350DummyTpm::doesKeyExistInTpm(const Name& keyName, KeyClass keyClass)
351{
352 return true;
353}
354
355bool
356DummyTpm::generateRandomBlock(uint8_t* res, size_t size)
357{
358 return false;
359}
360
361void
362DummyTpm::addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath,
363 AclType acl)
364{
365}
366
367ConstBufferPtr
368DummyTpm::exportPrivateKeyPkcs8FromTpm(const Name& keyName)
369{
Spyridon Mastorakis0d2ed2e2015-07-27 19:09:12 -0700370 BOOST_THROW_EXCEPTION(Error("Not supported"));
Alexander Afanasyev07113802015-01-15 19:14:36 -0800371}
372
373bool
374DummyTpm::importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buffer,
375 size_t bufferSize)
376{
377 return false;
378}
379
380bool
381DummyTpm::importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize)
382{
383 return false;
384}
385
386std::string
387DummyTpm::getScheme()
388{
389 return DummyTpm::SCHEME;
390}
391
392} // namespace security
393} // namespace ndn