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