Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 22 | #ifndef NDN_TESTS_SECURITY_V1_DUMMY_KEYCHAIN_HPP |
| 23 | #define NDN_TESTS_SECURITY_V1_DUMMY_KEYCHAIN_HPP |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 24 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 25 | #include "security/v1/key-chain.hpp" |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace security { |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 29 | namespace v1 { |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 30 | |
| 31 | class DummyPublicInfo : public SecPublicInfo |
| 32 | { |
| 33 | public: |
| 34 | explicit |
| 35 | DummyPublicInfo(const std::string& locator); |
| 36 | |
| 37 | virtual bool |
| 38 | doesIdentityExist(const Name& identityName); |
| 39 | |
| 40 | virtual void |
| 41 | addIdentity(const Name& identityName); |
| 42 | |
| 43 | virtual bool |
| 44 | revokeIdentity(); |
| 45 | |
| 46 | virtual bool |
| 47 | doesPublicKeyExist(const Name& keyName); |
| 48 | |
| 49 | virtual void |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 50 | addKey(const Name& keyName, const v1::PublicKey& publicKey); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 51 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 52 | virtual shared_ptr<v1::PublicKey> |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 53 | getPublicKey(const Name& keyName); |
| 54 | |
| 55 | virtual KeyType |
| 56 | getPublicKeyType(const Name& keyName); |
| 57 | |
| 58 | virtual bool |
| 59 | doesCertificateExist(const Name& certificateName); |
| 60 | |
| 61 | virtual void |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 62 | addCertificate(const v1::IdentityCertificate& certificate); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 63 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 64 | virtual shared_ptr<v1::IdentityCertificate> |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 65 | getCertificate(const Name& certificateName); |
| 66 | |
| 67 | virtual Name |
| 68 | getDefaultIdentity(); |
| 69 | |
| 70 | virtual Name |
| 71 | getDefaultKeyNameForIdentity(const Name& identityName); |
| 72 | |
| 73 | virtual Name |
| 74 | getDefaultCertificateNameForKey(const Name& keyName); |
| 75 | |
| 76 | virtual void |
| 77 | getAllIdentities(std::vector<Name>& nameList, bool isDefault); |
| 78 | |
| 79 | virtual void |
| 80 | getAllKeyNames(std::vector<Name>& nameList, bool isDefault); |
| 81 | |
| 82 | virtual void |
| 83 | getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault); |
| 84 | |
| 85 | virtual void |
| 86 | getAllCertificateNames(std::vector<Name>& nameList, bool isDefault); |
| 87 | |
| 88 | virtual void |
| 89 | getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault); |
| 90 | |
| 91 | virtual void |
| 92 | deleteCertificateInfo(const Name& certificateName); |
| 93 | |
| 94 | virtual void |
| 95 | deletePublicKeyInfo(const Name& keyName); |
| 96 | |
| 97 | virtual void |
| 98 | deleteIdentityInfo(const Name& identity); |
| 99 | |
| 100 | virtual void |
| 101 | setTpmLocator(const std::string& tpmLocator); |
| 102 | |
| 103 | virtual std::string |
| 104 | getTpmLocator(); |
| 105 | |
| 106 | protected: |
| 107 | virtual void |
| 108 | setDefaultIdentityInternal(const Name& identityName); |
| 109 | |
| 110 | virtual void |
| 111 | setDefaultKeyNameForIdentityInternal(const Name& keyName); |
| 112 | |
| 113 | virtual void |
| 114 | setDefaultCertificateNameForKeyInternal(const Name& certificateName); |
| 115 | |
| 116 | virtual std::string |
| 117 | getScheme(); |
| 118 | |
| 119 | public: |
| 120 | static const std::string SCHEME; |
| 121 | |
| 122 | private: |
| 123 | std::string m_tpmLocator; |
| 124 | }; |
| 125 | |
| 126 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 127 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 128 | |
| 129 | class DummyTpm : public SecTpm |
| 130 | { |
| 131 | public: |
| 132 | explicit |
| 133 | DummyTpm(const std::string& locator); |
| 134 | |
| 135 | virtual void |
| 136 | setTpmPassword(const uint8_t* password, size_t passwordLength); |
| 137 | |
| 138 | virtual void |
| 139 | resetTpmPassword(); |
| 140 | |
| 141 | virtual void |
| 142 | setInTerminal(bool inTerminal); |
| 143 | |
| 144 | virtual bool |
| 145 | getInTerminal() const; |
| 146 | |
| 147 | virtual bool |
| 148 | isLocked(); |
| 149 | |
| 150 | virtual bool |
| 151 | unlockTpm(const char* password, size_t passwordLength, bool usePassword); |
| 152 | |
| 153 | virtual void |
| 154 | generateKeyPairInTpm(const Name& keyName, const KeyParams& params); |
| 155 | |
| 156 | virtual void |
| 157 | deleteKeyPairInTpm(const Name& keyName); |
| 158 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 159 | virtual shared_ptr<v1::PublicKey> |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 160 | getPublicKeyFromTpm(const Name& keyName); |
| 161 | |
| 162 | virtual Block |
| 163 | signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, |
| 164 | DigestAlgorithm digestAlgorithm); |
| 165 | |
| 166 | virtual ConstBufferPtr |
| 167 | decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric); |
| 168 | |
| 169 | virtual ConstBufferPtr |
| 170 | encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric); |
| 171 | |
| 172 | virtual void |
| 173 | generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params); |
| 174 | |
| 175 | virtual bool |
| 176 | doesKeyExistInTpm(const Name& keyName, KeyClass keyClass); |
| 177 | |
| 178 | virtual bool |
| 179 | generateRandomBlock(uint8_t* res, size_t size); |
| 180 | |
| 181 | virtual void |
| 182 | addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl); |
| 183 | |
| 184 | virtual std::string |
| 185 | getScheme(); |
| 186 | |
| 187 | protected: |
| 188 | virtual ConstBufferPtr |
| 189 | exportPrivateKeyPkcs8FromTpm(const Name& keyName); |
| 190 | |
| 191 | virtual bool |
| 192 | importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize); |
| 193 | |
| 194 | virtual bool |
| 195 | importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize); |
| 196 | |
| 197 | public: |
| 198 | static const std::string SCHEME; |
| 199 | }; |
| 200 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 201 | } // namespace v1 |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 202 | } // namespace security |
| 203 | } // namespace ndn |
| 204 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 205 | #endif // NDN_TESTS_SECURITY_V1_DUMMY_KEYCHAIN_HPP |