blob: 5c95edf930fdbcd120dfd30524df2c1bc3c1faa3 [file] [log] [blame]
Alexander Afanasyev07113802015-01-15 19:14:36 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2015 Regents of the University of California.
4 *
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#ifndef NDN_TESTS_SECURITY_DUMMY_KEYCHAIN_HPP
23#define NDN_TESTS_SECURITY_DUMMY_KEYCHAIN_HPP
24
25#include "security/key-chain.hpp"
26
27namespace ndn {
28namespace security {
29
30class DummyPublicInfo : public SecPublicInfo
31{
32public:
33 explicit
34 DummyPublicInfo(const std::string& locator);
35
36 virtual bool
37 doesIdentityExist(const Name& identityName);
38
39 virtual void
40 addIdentity(const Name& identityName);
41
42 virtual bool
43 revokeIdentity();
44
45 virtual bool
46 doesPublicKeyExist(const Name& keyName);
47
48 virtual void
49 addKey(const Name& keyName, const PublicKey& publicKey);
50
51 virtual shared_ptr<PublicKey>
52 getPublicKey(const Name& keyName);
53
54 virtual KeyType
55 getPublicKeyType(const Name& keyName);
56
57 virtual bool
58 doesCertificateExist(const Name& certificateName);
59
60 virtual void
61 addCertificate(const IdentityCertificate& certificate);
62
63 virtual shared_ptr<IdentityCertificate>
64 getCertificate(const Name& certificateName);
65
66 virtual Name
67 getDefaultIdentity();
68
69 virtual Name
70 getDefaultKeyNameForIdentity(const Name& identityName);
71
72 virtual Name
73 getDefaultCertificateNameForKey(const Name& keyName);
74
75 virtual void
76 getAllIdentities(std::vector<Name>& nameList, bool isDefault);
77
78 virtual void
79 getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
80
81 virtual void
82 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
83
84 virtual void
85 getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
86
87 virtual void
88 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
89
90 virtual void
91 deleteCertificateInfo(const Name& certificateName);
92
93 virtual void
94 deletePublicKeyInfo(const Name& keyName);
95
96 virtual void
97 deleteIdentityInfo(const Name& identity);
98
99 virtual void
100 setTpmLocator(const std::string& tpmLocator);
101
102 virtual std::string
103 getTpmLocator();
104
105protected:
106 virtual void
107 setDefaultIdentityInternal(const Name& identityName);
108
109 virtual void
110 setDefaultKeyNameForIdentityInternal(const Name& keyName);
111
112 virtual void
113 setDefaultCertificateNameForKeyInternal(const Name& certificateName);
114
115 virtual std::string
116 getScheme();
117
118public:
119 static const std::string SCHEME;
120
121private:
122 std::string m_tpmLocator;
123};
124
125//////////////////////////////////////////////////////////////////////////////////////////
126//////////////////////////////////////////////////////////////////////////////////////////
127
128class DummyTpm : public SecTpm
129{
130public:
131 explicit
132 DummyTpm(const std::string& locator);
133
134 virtual void
135 setTpmPassword(const uint8_t* password, size_t passwordLength);
136
137 virtual void
138 resetTpmPassword();
139
140 virtual void
141 setInTerminal(bool inTerminal);
142
143 virtual bool
144 getInTerminal() const;
145
146 virtual bool
147 isLocked();
148
149 virtual bool
150 unlockTpm(const char* password, size_t passwordLength, bool usePassword);
151
152 virtual void
153 generateKeyPairInTpm(const Name& keyName, const KeyParams& params);
154
155 virtual void
156 deleteKeyPairInTpm(const Name& keyName);
157
158 virtual shared_ptr<PublicKey>
159 getPublicKeyFromTpm(const Name& keyName);
160
161 virtual Block
162 signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName,
163 DigestAlgorithm digestAlgorithm);
164
165 virtual ConstBufferPtr
166 decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
167
168 virtual ConstBufferPtr
169 encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
170
171 virtual void
172 generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params);
173
174 virtual bool
175 doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
176
177 virtual bool
178 generateRandomBlock(uint8_t* res, size_t size);
179
180 virtual void
181 addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl);
182
183 virtual std::string
184 getScheme();
185
186protected:
187 virtual ConstBufferPtr
188 exportPrivateKeyPkcs8FromTpm(const Name& keyName);
189
190 virtual bool
191 importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize);
192
193 virtual bool
194 importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize);
195
196public:
197 static const std::string SCHEME;
198};
199
200} // namespace security
201} // namespace ndn
202
203#endif // NDN_TESTS_SECURITY_DUMMY_KEYCHAIN_HPP