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