Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 2 | /** |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/> |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 24 | #ifndef NDN_SECURITY_SEC_TPM_HPP |
| 25 | #define NDN_SECURITY_SEC_TPM_HPP |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 27 | #include "../common.hpp" |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 28 | #include "security-common.hpp" |
| 29 | #include "../name.hpp" |
| 30 | #include "../data.hpp" |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 31 | #include "key-params.hpp" |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame^] | 32 | #include "v1/public-key.hpp" |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 33 | |
| 34 | namespace ndn { |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame^] | 35 | namespace security { |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 36 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 37 | /** |
| 38 | * @brief SecTpm is the base class of the TPM classes. |
| 39 | * |
| 40 | * It specifies the interfaces of private/secret key related operations. |
| 41 | */ |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 42 | class SecTpm : noncopyable |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 43 | { |
Jeff Thompson | a50703f | 2013-09-17 14:24:15 -0700 | [diff] [blame] | 44 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 45 | class Error : public std::runtime_error |
| 46 | { |
| 47 | public: |
| 48 | explicit |
| 49 | Error(const std::string& what) |
| 50 | : std::runtime_error(what) |
| 51 | { |
| 52 | } |
| 53 | }; |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 54 | |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 55 | explicit |
| 56 | SecTpm(const std::string& location); |
| 57 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 58 | virtual |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 59 | ~SecTpm(); |
| 60 | |
| 61 | std::string |
| 62 | getTpmLocator(); |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 63 | |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 64 | /** |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 65 | * @brief set password of TPM |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 66 | * |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 67 | * Password is used to unlock TPM when it is locked. |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 68 | * You should be cautious when using this method, because remembering password is kind of |
| 69 | * dangerous. |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 70 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 71 | * @param password The password |
| 72 | * @param passwordLength The length of password |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 73 | */ |
| 74 | virtual void |
| 75 | setTpmPassword(const uint8_t* password, size_t passwordLength) = 0; |
| 76 | |
| 77 | /** |
| 78 | * @brief reset password of TPM |
| 79 | */ |
| 80 | virtual void |
| 81 | resetTpmPassword() = 0; |
| 82 | |
| 83 | /** |
Davide Pesavento | 18cf81b | 2015-09-12 23:36:43 +0200 | [diff] [blame] | 84 | * @brief Set inTerminal flag to @p inTerminal |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 85 | * |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 86 | * If the inTerminal flag is set, and password is not set, TPM may ask for password via terminal. |
| 87 | * inTerminal flag is set by default. |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 88 | */ |
| 89 | virtual void |
| 90 | setInTerminal(bool inTerminal) = 0; |
| 91 | |
| 92 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 93 | * @brief Get value of inTerminal flag |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 94 | */ |
| 95 | virtual bool |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 96 | getInTerminal() const = 0; |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 97 | |
| 98 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 99 | * @brief Check if TPM is locked |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 100 | */ |
| 101 | virtual bool |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 102 | isLocked() = 0; |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 103 | |
| 104 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 105 | * @brief Unlock the TPM |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 106 | * |
| 107 | * @param password The password. |
| 108 | * @param passwordLength The password size. 0 indicates no password. |
| 109 | * @param usePassword True if we want to use the supplied password to unlock the TPM. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 110 | * @return true if TPM is unlocked, otherwise false. |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 111 | */ |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 112 | virtual bool |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 113 | unlockTpm(const char* password, size_t passwordLength, bool usePassword) = 0; |
| 114 | |
| 115 | /** |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 116 | * @brief Generate a pair of asymmetric keys. |
| 117 | * |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 118 | * @param keyName The name of the key pair. |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 119 | * @param params The parameters of key. |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 120 | * @throws SecTpm::Error if fails. |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 121 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 122 | virtual void |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 123 | generateKeyPairInTpm(const Name& keyName, const KeyParams& params) = 0; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 124 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 125 | /** |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 126 | * @brief Delete a key pair of asymmetric keys. |
| 127 | * |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 128 | * @param keyName The name of the key pair. |
| 129 | */ |
| 130 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 131 | deleteKeyPairInTpm(const Name& keyName) = 0; |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 132 | |
| 133 | /** |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 134 | * @brief Get a public key. |
| 135 | * |
| 136 | * @param keyName The public key name. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 137 | * @return The public key. |
| 138 | * @throws SecTpm::Error if public key does not exist in TPM. |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 139 | */ |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame^] | 140 | virtual shared_ptr<v1::PublicKey> |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 141 | getPublicKeyFromTpm(const Name& keyName) = 0; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 142 | |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 143 | /** |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 144 | * @brief Sign data. |
| 145 | * |
| 146 | * @param data Pointer to the byte array to be signed. |
Jeff Thompson | 4c11b9f | 2013-09-13 11:05:28 -0700 | [diff] [blame] | 147 | * @param dataLength The length of data. |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 148 | * @param keyName The name of the signing key. |
| 149 | * @param digestAlgorithm the digest algorithm. |
Yingdi Yu | 3c5887c | 2014-01-21 18:19:49 -0800 | [diff] [blame] | 150 | * @return The signature block. |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 151 | * @throws SecTpm::Error if signing fails. |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 152 | */ |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 153 | virtual Block |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 154 | signInTpm(const uint8_t* data, size_t dataLength, |
| 155 | const Name& keyName, |
| 156 | DigestAlgorithm digestAlgorithm) = 0; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 157 | |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 158 | /** |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 159 | * @brief Decrypt data. |
| 160 | * |
| 161 | * @param data Pointer to the byte arry to be decrypted. |
| 162 | * @param dataLength The length of data. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 163 | * @param keyName The name of the decrypting key. |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 164 | * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric encryption. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 165 | * @return The decrypted data. |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 166 | * @throws SecTpm::Error if decryption fails. |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 167 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 168 | virtual ConstBufferPtr |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 169 | decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric) = 0; |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 170 | |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 171 | /** |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 172 | * @brief Encrypt data. |
| 173 | * |
| 174 | * @param data Pointer to the byte arry to be decrypted. |
| 175 | * @param dataLength The length of data. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 176 | * @param keyName The name of the encrypting key. |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 177 | * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric encryption. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 178 | * @return The encrypted data. |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 179 | * @throws SecTpm::Error if encryption fails. |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 180 | */ |
Alexander Afanasyev | 64a3d81 | 2014-01-05 23:35:05 -0800 | [diff] [blame] | 181 | virtual ConstBufferPtr |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 182 | encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric) = 0; |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 183 | |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 184 | /** |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 185 | * @brief Generate a symmetric key. |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 186 | * |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 187 | * @param keyName The name of the key. |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 188 | * @param params The parameter of the key. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 189 | * @throws SecTpm::Error if key generating fails. |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 190 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 191 | virtual void |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 192 | generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params) = 0; |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 193 | |
| 194 | /** |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 195 | * @brief Check if a particular key exists. |
| 196 | * |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 197 | * @param keyName The name of the key. |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 198 | * @param keyClass The class of the key, e.g. KeyClass::PUBLIC, KeyClass::PRIVATE. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 199 | * @return True if the key exists, otherwise false. |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 200 | */ |
| 201 | virtual bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 202 | doesKeyExistInTpm(const Name& keyName, KeyClass keyClass) = 0; |
Yingdi Yu | 4b75275 | 2014-02-18 12:24:03 -0800 | [diff] [blame] | 203 | |
| 204 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 205 | * @brief Generate a random block |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 206 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 207 | * @param res The pointer to the generated block |
| 208 | * @param size The random block size |
| 209 | * @return true for success, otherwise false |
Yingdi Yu | 4b75275 | 2014-02-18 12:24:03 -0800 | [diff] [blame] | 210 | */ |
| 211 | virtual bool |
| 212 | generateRandomBlock(uint8_t* res, size_t size) = 0; |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 213 | |
| 214 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 215 | * @brief Add the application into the ACL of a particular key |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 216 | * |
| 217 | * @param keyName the name of key |
| 218 | * @param keyClass the class of key, e.g. Private Key |
| 219 | * @param appPath the absolute path to the application |
| 220 | * @param acl the new acl of the key |
| 221 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 222 | virtual void |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 223 | addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl) = 0; |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 224 | |
| 225 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 226 | * @brief Export a private key in PKCS#5 format |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 227 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 228 | * @param keyName The private key name |
| 229 | * @param password The password to encrypt the private key |
| 230 | * @return The private key info (in PKCS8 format) if exist |
| 231 | * @throws SecTpm::Error if private key cannot be exported |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 232 | */ |
| 233 | ConstBufferPtr |
Yingdi Yu | 5e96e00 | 2014-04-23 18:32:15 -0700 | [diff] [blame] | 234 | exportPrivateKeyPkcs5FromTpm(const Name& keyName, const std::string& password); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 235 | |
| 236 | /** |
Davide Pesavento | 18cf81b | 2015-09-12 23:36:43 +0200 | [diff] [blame] | 237 | * @brief Import a private key in PKCS#5 formatted buffer of size @p bufferSize |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 238 | * |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 239 | * Also recover the public key and installed it in TPM. |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 240 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 241 | * @param keyName The private key name |
| 242 | * @param buffer Pointer to the first byte of the buffer containing PKCS#5-encoded |
| 243 | * private key info |
| 244 | * @param bufferSize Size of the buffer |
| 245 | * @param password The password to encrypt the private key |
| 246 | * @return false if import fails |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 247 | */ |
| 248 | bool |
Yingdi Yu | 5e96e00 | 2014-04-23 18:32:15 -0700 | [diff] [blame] | 249 | importPrivateKeyPkcs5IntoTpm(const Name& keyName, |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 250 | const uint8_t* buffer, size_t bufferSize, |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 251 | const std::string& password); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 252 | |
| 253 | protected: |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 254 | virtual std::string |
| 255 | getScheme() = 0; |
| 256 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 257 | /** |
Yingdi Yu | 5e96e00 | 2014-04-23 18:32:15 -0700 | [diff] [blame] | 258 | * @brief Export a private key in PKCS#8 format. |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 259 | * |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 260 | * @param keyName The private key name. |
Yingdi Yu | 5e96e00 | 2014-04-23 18:32:15 -0700 | [diff] [blame] | 261 | * @return The private key info (in PKCS#8 format) if exist, otherwise a NULL pointer. |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 262 | */ |
| 263 | virtual ConstBufferPtr |
Yingdi Yu | 5e96e00 | 2014-04-23 18:32:15 -0700 | [diff] [blame] | 264 | exportPrivateKeyPkcs8FromTpm(const Name& keyName) = 0; |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 265 | |
| 266 | /** |
Davide Pesavento | 18cf81b | 2015-09-12 23:36:43 +0200 | [diff] [blame] | 267 | * @brief Import a private key from PKCS#8 formatted buffer of size @p bufferSize |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 268 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 269 | * @param keyName The private key name. |
| 270 | * @param buffer Pointer to the first byte of the buffer containing PKCS#8-encoded |
| 271 | * private key info |
| 272 | * @param bufferSize Size of the buffer |
| 273 | * @return false if import fails |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 274 | */ |
| 275 | virtual bool |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 276 | importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize) = 0; |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 277 | |
| 278 | /** |
Davide Pesavento | 18cf81b | 2015-09-12 23:36:43 +0200 | [diff] [blame] | 279 | * @brief Import a public key in PKCS#1 formatted buffer of size @p bufferSize |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 280 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 281 | * @param keyName The public key name |
| 282 | * @param buffer Pointer to the first byte of the buffer containing PKCS#1-encoded |
| 283 | * private key info |
| 284 | * @param bufferSize Size of the buffer |
| 285 | * @return false if import fails |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 286 | */ |
| 287 | virtual bool |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 288 | importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize) = 0; |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 289 | |
| 290 | /** |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 291 | * @brief Get import/export password. |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 292 | * |
| 293 | * @param password On return, the password. |
| 294 | * @param prompt Prompt for password, i.e., "Password for key:" |
| 295 | * @return true if password has been obtained. |
| 296 | */ |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 297 | virtual bool |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 298 | getImpExpPassWord(std::string& password, const std::string& prompt); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 299 | |
| 300 | protected: |
| 301 | std::string m_location; |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame^] | 304 | } // namespace security |
| 305 | |
| 306 | using security::SecTpm; |
| 307 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 308 | } // namespace ndn |
Jeff Thompson | 7b79eb6 | 2013-09-12 18:48:29 -0700 | [diff] [blame] | 309 | |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 310 | #endif // NDN_SECURITY_SEC_TPM_HPP |