Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * 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 Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * 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 Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * 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 Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 19 | |
| 20 | #ifndef NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP |
| 21 | #define NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP |
| 22 | |
| 23 | #include <ndn-cxx/security/key-chain.hpp> |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame^] | 24 | #include <ndn-cxx/security/security-common.hpp> |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace security { |
| 28 | |
| 29 | class DummyPublicInfo : public SecPublicInfo { |
| 30 | public: |
Alexander Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 31 | DummyPublicInfo(const std::string& locator); |
| 32 | |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 33 | 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 Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 96 | virtual void |
| 97 | setTpmLocator(const std::string& tpmLocator); |
| 98 | |
| 99 | virtual std::string |
| 100 | getTpmLocator(); |
| 101 | |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 102 | protected: |
| 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 Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 111 | |
| 112 | virtual std::string |
| 113 | getScheme(); |
| 114 | |
| 115 | public: |
| 116 | static const std::string SCHEME; |
| 117 | |
| 118 | private: |
| 119 | std::string m_tpmLocator; |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 123 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 124 | |
| 125 | class DummyTpm : public SecTpm { |
| 126 | public: |
Alexander Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 127 | DummyTpm(const std::string& locator); |
| 128 | |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 129 | 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 Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 178 | virtual std::string |
| 179 | getScheme(); |
| 180 | |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 181 | protected: |
| 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 Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 190 | |
Alexander Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 191 | public: |
| 192 | static const std::string SCHEME; |
| 193 | }; |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 194 | |
| 195 | } // namespace security |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 196 | } // namespace ndn |
| 197 | |
| 198 | #endif // NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP |