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