Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 8 | #ifndef NDN_SEC_TPM_OSX_HPP |
| 9 | #define NDN_SEC_TPM_OSX_HPP |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 10 | |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 11 | #include "../common.hpp" |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 12 | #include "sec-tpm.hpp" |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 13 | |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 14 | namespace ndn |
| 15 | { |
| 16 | |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 17 | class SecTpmOsx : public SecTpm { |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 18 | public: |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 19 | struct Error : public SecTpm::Error { Error(const std::string &what) : SecTpm::Error(what) {} }; |
| 20 | |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 21 | /** |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 22 | * constructor of OSXKeyChainTpm |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 23 | * @param keychainName the name of keychain |
| 24 | */ |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 25 | SecTpmOsx(const std::string & keychainName = ""); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 28 | * destructor of OSXKeyChainTpm |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 29 | */ |
| 30 | virtual |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 31 | ~SecTpmOsx(); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 33 | |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 34 | // From TrustedPlatformModule |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 35 | virtual void |
Yingdi Yu | 3c5887c | 2014-01-21 18:19:49 -0800 | [diff] [blame] | 36 | generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 37 | |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 38 | virtual ptr_lib::shared_ptr<PublicKey> |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 39 | getPublicKeyFromTpm(const Name& keyName); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 40 | |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 41 | virtual Block |
Yingdi Yu | b4bb85a | 2014-01-16 10:11:04 -0800 | [diff] [blame] | 42 | signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm); |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 43 | |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Decrypt data. |
| 46 | * @param keyName The name of the decrypting key. |
| 47 | * @param data The byte to be decrypted. |
| 48 | * @param dataLength the length of data. |
| 49 | * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used. |
| 50 | * @return The decrypted data. |
| 51 | */ |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 52 | virtual ConstBufferPtr |
Yingdi Yu | b4bb85a | 2014-01-16 10:11:04 -0800 | [diff] [blame] | 53 | decryptInTpm(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Encrypt data. |
| 57 | * @param keyName The name of the encrypting key. |
| 58 | * @param data The byte to be encrypted. |
| 59 | * @param dataLength the length of data. |
| 60 | * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used. |
| 61 | * @return The encrypted data. |
| 62 | */ |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 63 | virtual ConstBufferPtr |
Yingdi Yu | b4bb85a | 2014-01-16 10:11:04 -0800 | [diff] [blame] | 64 | encryptInTpm(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Generate a symmetric key. |
| 68 | * @param keyName The name of the key. |
| 69 | * @param keyType The type of the key, e.g. KEY_TYPE_AES. |
| 70 | * @param keySize The size of the key. |
| 71 | */ |
| 72 | virtual void |
Yingdi Yu | b4bb85a | 2014-01-16 10:11:04 -0800 | [diff] [blame] | 73 | generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Check if a particular key exists. |
| 77 | * @param keyName The name of the key. |
| 78 | * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC. |
| 79 | * @return True if the key exists, otherwise false. |
| 80 | */ |
| 81 | virtual bool |
Yingdi Yu | b4bb85a | 2014-01-16 10:11:04 -0800 | [diff] [blame] | 82 | doesKeyExistInTpm(const Name& keyName, KeyClass keyClass); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 83 | |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 84 | |
| 85 | //////////////////////////////////////////////////////////////////////////////////// |
| 86 | // OSX-specifics |
| 87 | //////////////////////////////////////////////////////////////////////////////////// |
| 88 | |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 89 | /** |
| 90 | * configure ACL of a particular key |
| 91 | * @param keyName the name of key |
| 92 | * @param keyClass the class of key, e.g. Private Key |
| 93 | * @param acl the new acl of the key |
| 94 | * @param appPath the absolute path to the application |
| 95 | * @returns true if setting succeeds |
| 96 | */ |
| 97 | bool |
| 98 | setACL(const Name & keyName, KeyClass keyClass, int acl, const std::string & appPath); |
| 99 | |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 100 | // /** |
| 101 | // * verify data (test only) |
| 102 | // * @param keyName the name of key |
| 103 | // * @param pData the data to be verified |
| 104 | // * @param pSig the signature associated with the data |
| 105 | // * @param digestAlgo digest algorithm |
| 106 | // * @return true if signature can be verified, otherwise false |
| 107 | // */ |
| 108 | // bool |
| 109 | // verifyData(const Name & keyName, const Blob & pData, const Blob & pSig, DigestAlgorithm digestAlgo = DIGEST_ALGORITHM_SHA256); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 110 | |
| 111 | private: |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 112 | class Impl; |
| 113 | std::auto_ptr<Impl> impl_; |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
Alexander Afanasyev | 1950885 | 2014-01-29 01:01:51 -0800 | [diff] [blame] | 116 | } // namespace ndn |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 117 | |
Alexander Afanasyev | 1950885 | 2014-01-29 01:01:51 -0800 | [diff] [blame] | 118 | #endif // NDN_SEC_TPM_OSX_HPP |