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