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> |
| 24 | |
| 25 | namespace ndn { |
| 26 | namespace security { |
| 27 | |
| 28 | class DummyPublicInfo : public SecPublicInfo { |
| 29 | public: |
Alexander Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 30 | DummyPublicInfo(const std::string& locator); |
| 31 | |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 32 | 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 Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 95 | virtual void |
| 96 | setTpmLocator(const std::string& tpmLocator); |
| 97 | |
| 98 | virtual std::string |
| 99 | getTpmLocator(); |
| 100 | |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 101 | protected: |
| 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 Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 110 | |
| 111 | virtual std::string |
| 112 | getScheme(); |
| 113 | |
| 114 | public: |
| 115 | static const std::string SCHEME; |
| 116 | |
| 117 | private: |
| 118 | std::string m_tpmLocator; |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 122 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 123 | |
| 124 | class DummyTpm : public SecTpm { |
| 125 | public: |
Alexander Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 126 | DummyTpm(const std::string& locator); |
| 127 | |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 128 | 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 Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 177 | virtual std::string |
| 178 | getScheme(); |
| 179 | |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 180 | protected: |
| 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 Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 189 | |
Alexander Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 190 | public: |
| 191 | static const std::string SCHEME; |
| 192 | }; |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 193 | |
| 194 | } // namespace security |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 195 | } // namespace ndn |
| 196 | |
| 197 | #endif // NDNSIM_UTILS_DUMMY_KEYCHAIN_HPP |