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