blob: 84d79eee6aec5cc877fb09ab2fa25463ca24f5b9 [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev34e13f32014-12-14 15:13:28 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev34e13f32014-12-14 15:13:28 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyev34e13f32014-12-14 15:13:28 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyev34e13f32014-12-14 15:13:28 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyev34e13f32014-12-14 15:13:28 -080019
20#include "dummy-keychain.hpp"
21
22#include <ndn-cxx/util/io.hpp>
23#include <boost/iostreams/device/array.hpp>
24
25namespace ndn {
26namespace security {
27
28static const uint8_t DUMMY_CERT[] =
29 "Bv0C8Ac4CAVkdW1teQgDa2V5CANLRVkIEWtzay0xNDE4NjAwMzkxMDUwCAdJRC1D"
30 "RVJUCAn9AAABSkssIl4UAxgBAhX9AXMwggFvMCIYDzIwMTQxMjE0MjMzOTUxWhgP"
31 "MjAzNDEyMDkyMzM5NTFaMCUwIwYDVQQpExwvZHVtbXkva2V5L2tzay0xND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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
65bool
66DummyPublicInfo::doesIdentityExist(const Name& identityName)
67{
68 return true;
69}
70
71void
72DummyPublicInfo::addIdentity(const Name& identityName)
73{
74}
75
76bool
77DummyPublicInfo::revokeIdentity()
78{
79 return true;
80}
81
82bool
83DummyPublicInfo::doesPublicKeyExist(const Name& keyName)
84{
85 return true;
86}
87
88void
89DummyPublicInfo::addKey(const Name& keyName, const PublicKey& publicKey)
90{
91}
92
93shared_ptr<PublicKey>
94DummyPublicInfo::getPublicKey(const Name& keyName)
95{
96 static shared_ptr<PublicKey> publicKey = nullptr;
97 if (publicKey == nullptr) {
98 typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
99 arrayStream
100 is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
101 auto cert = io::load<IdentityCertificate>(is, io::NO_ENCODING);
102 publicKey = make_shared<PublicKey>(cert->getPublicKeyInfo());
103 }
104
105 return publicKey;
106}
107
108KeyType
109DummyPublicInfo::getPublicKeyType(const Name& keyName)
110{
111 return KEY_TYPE_RSA;
112}
113
114bool
115DummyPublicInfo::doesCertificateExist(const Name& certificateName)
116{
117 return true;
118}
119
120void
121DummyPublicInfo::addCertificate(const IdentityCertificate& certificate)
122{
123}
124
125shared_ptr<IdentityCertificate>
126DummyPublicInfo::getCertificate(const Name& certificateName)
127{
128 static shared_ptr<IdentityCertificate> cert = nullptr;
129 if (cert == nullptr) {
130 typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
131 arrayStream
132 is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
133 cert = io::load<IdentityCertificate>(is, io::BASE_64);
134 }
135
136 return cert;
137}
138
139Name
140DummyPublicInfo::getDefaultIdentity()
141{
142 return "/dummy/key";
143}
144
145Name
146DummyPublicInfo::getDefaultKeyNameForIdentity(const Name& identityName)
147{
148 return "/dummy/key/ksk-1418600391050";
149}
150
151Name
152DummyPublicInfo::getDefaultCertificateNameForKey(const Name& keyName)
153{
154 return "/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E";
155}
156
157void
158DummyPublicInfo::getAllIdentities(std::vector<Name>& nameList, bool isDefault)
159{
160 if (isDefault) {
161 nameList.push_back("/dummy");
162 }
163}
164
165void
166DummyPublicInfo::getAllKeyNames(std::vector<Name>& nameList, bool isDefault)
167{
168 if (isDefault) {
169 nameList.push_back("/dummy/key/ksk-1418600391050");
170 }
171}
172
173void
174DummyPublicInfo::getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList,
175 bool isDefault)
176{
177 if (isDefault) {
178 nameList.push_back("/dummy/key/ksk-1418600391050");
179 }
180}
181
182void
183DummyPublicInfo::getAllCertificateNames(std::vector<Name>& nameList, bool isDefault)
184{
185 if (isDefault) {
186 nameList.push_back("/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E");
187 }
188}
189
190void
191DummyPublicInfo::getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList,
192 bool isDefault)
193{
194 if (isDefault) {
195 nameList.push_back("/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E");
196 }
197}
198
199void
200DummyPublicInfo::deleteCertificateInfo(const Name& certificateName)
201{
202}
203
204void
205DummyPublicInfo::deletePublicKeyInfo(const Name& keyName)
206{
207}
208
209void
210DummyPublicInfo::deleteIdentityInfo(const Name& identity)
211{
212}
213
214void
215DummyPublicInfo::setDefaultIdentityInternal(const Name& identityName)
216{
217}
218
219void
220DummyPublicInfo::setDefaultKeyNameForIdentityInternal(const Name& keyName)
221{
222}
223
224void
225DummyPublicInfo::setDefaultCertificateNameForKeyInternal(const Name& certificateName)
226{
227}
228
229//////////////////////////////////////////////////////////////////////////////////////////
230//////////////////////////////////////////////////////////////////////////////////////////
231//////////////////////////////////////////////////////////////////////////////////////////
232//////////////////////////////////////////////////////////////////////////////////////////
233
234void
235DummyTpm::setTpmPassword(const uint8_t* password, size_t passwordLength)
236{
237}
238
239void
240DummyTpm::resetTpmPassword()
241{
242}
243
244void
245DummyTpm::setInTerminal(bool inTerminal)
246{
247}
248
249bool
250DummyTpm::getInTerminal() const
251{
252 return false;
253}
254
255bool
256DummyTpm::isLocked()
257{
258 return false;
259}
260
261bool
262DummyTpm::unlockTpm(const char* password, size_t passwordLength, bool usePassword)
263{
264 return true;
265}
266
267void
268DummyTpm::generateKeyPairInTpm(const Name& keyName, const KeyParams& params)
269{
270}
271
272void
273DummyTpm::deleteKeyPairInTpm(const Name& keyName)
274{
275}
276
277shared_ptr<PublicKey>
278DummyTpm::getPublicKeyFromTpm(const Name& keyName)
279{
280 return nullptr;
281}
282
283Block
284DummyTpm::signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName,
285 DigestAlgorithm digestAlgorithm)
286{
287 return Block(DUMMY_SIGNATURE, sizeof(DUMMY_SIGNATURE));
288}
289
290ConstBufferPtr
291DummyTpm::decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName,
292 bool isSymmetric)
293{
294 throw Error("Not supported");
295}
296
297ConstBufferPtr
298DummyTpm::encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName,
299 bool isSymmetric)
300{
301 throw Error("Not supported");
302}
303
304void
305DummyTpm::generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params)
306{
307}
308
309bool
310DummyTpm::doesKeyExistInTpm(const Name& keyName, KeyClass keyClass)
311{
312 return true;
313}
314
315bool
316DummyTpm::generateRandomBlock(uint8_t* res, size_t size)
317{
318 return false;
319}
320
321void
322DummyTpm::addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath,
323 AclType acl)
324{
325}
326
327ConstBufferPtr
328DummyTpm::exportPrivateKeyPkcs8FromTpm(const Name& keyName)
329{
330 throw Error("Not supported");
331}
332
333bool
334DummyTpm::importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buffer,
335 size_t bufferSize)
336{
337 return false;
338}
339
340bool
341DummyTpm::importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize)
342{
343 return false;
344}
345
346} // namespace security
347} // namespace ndn