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 | |
Jeff Thompson | f21e224 | 2013-10-09 19:01:49 -0700 | [diff] [blame] | 11 | // Only compile if ndn-cpp-config.h defines NDN_CPP_HAVE_OSX_SECURITY 1. |
Jeff Thompson | 6e22904 | 2013-10-10 11:09:49 -0700 | [diff] [blame] | 12 | #include <ndn-cpp/ndn-cpp-config.h> |
Jeff Thompson | f21e224 | 2013-10-09 19:01:49 -0700 | [diff] [blame] | 13 | #if NDN_CPP_HAVE_OSX_SECURITY |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 14 | |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame^] | 15 | #include "../common.hpp" |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 16 | #include "sec-tpm.hpp" |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 17 | |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 18 | namespace ndn |
| 19 | { |
| 20 | |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 21 | class SecTpmOsx : public SecTpm { |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 22 | public: |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 23 | struct Error : public SecTpm::Error { Error(const std::string &what) : SecTpm::Error(what) {} }; |
| 24 | |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 25 | /** |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 26 | * constructor of OSXKeyChainTpm |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 27 | * @param keychainName the name of keychain |
| 28 | */ |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 29 | SecTpmOsx(const std::string & keychainName = ""); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 32 | * destructor of OSXKeyChainTpm |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 33 | */ |
| 34 | virtual |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 35 | ~SecTpmOsx(); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 37 | |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 38 | // From TrustedPlatformModule |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 39 | virtual void |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 40 | generateKeyPairInTpm(const Name& keyName, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 41 | |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 42 | virtual ptr_lib::shared_ptr<PublicKey> |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 43 | getPublicKeyFromTpm(const Name& keyName); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 45 | virtual Block |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 46 | sign(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm); |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 47 | |
| 48 | virtual void |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 49 | sign(Data &data, const Name& keyName, DigestAlgorithm digestAlgorithm); |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 50 | |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Decrypt data. |
| 53 | * @param keyName The name of the decrypting key. |
| 54 | * @param data The byte to be decrypted. |
| 55 | * @param dataLength the length of data. |
| 56 | * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used. |
| 57 | * @return The decrypted data. |
| 58 | */ |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 59 | virtual ConstBufferPtr |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 60 | decrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Encrypt data. |
| 64 | * @param keyName The name of the encrypting key. |
| 65 | * @param data The byte to be encrypted. |
| 66 | * @param dataLength the length of data. |
| 67 | * @param isSymmetric If true symmetric encryption is used, otherwise asymmetric decryption is used. |
| 68 | * @return The encrypted data. |
| 69 | */ |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 70 | virtual ConstBufferPtr |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 71 | encrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Generate a symmetric key. |
| 75 | * @param keyName The name of the key. |
| 76 | * @param keyType The type of the key, e.g. KEY_TYPE_AES. |
| 77 | * @param keySize The size of the key. |
| 78 | */ |
| 79 | virtual void |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 80 | generateSymmetricKey(const Name& keyName, KeyType keyType, int keySize); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Check if a particular key exists. |
| 84 | * @param keyName The name of the key. |
| 85 | * @param keyClass The class of the key, e.g. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE, or KEY_CLASS_SYMMETRIC. |
| 86 | * @return True if the key exists, otherwise false. |
| 87 | */ |
| 88 | virtual bool |
| 89 | doesKeyExist(const Name& keyName, KeyClass keyClass); |
| 90 | |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 91 | |
| 92 | //////////////////////////////////////////////////////////////////////////////////// |
| 93 | // OSX-specifics |
| 94 | //////////////////////////////////////////////////////////////////////////////////// |
| 95 | |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 96 | /** |
| 97 | * configure ACL of a particular key |
| 98 | * @param keyName the name of key |
| 99 | * @param keyClass the class of key, e.g. Private Key |
| 100 | * @param acl the new acl of the key |
| 101 | * @param appPath the absolute path to the application |
| 102 | * @returns true if setting succeeds |
| 103 | */ |
| 104 | bool |
| 105 | setACL(const Name & keyName, KeyClass keyClass, int acl, const std::string & appPath); |
| 106 | |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 107 | // /** |
| 108 | // * verify data (test only) |
| 109 | // * @param keyName the name of key |
| 110 | // * @param pData the data to be verified |
| 111 | // * @param pSig the signature associated with the data |
| 112 | // * @param digestAlgo digest algorithm |
| 113 | // * @return true if signature can be verified, otherwise false |
| 114 | // */ |
| 115 | // bool |
| 116 | // 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] | 117 | |
| 118 | private: |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 119 | class Impl; |
| 120 | std::auto_ptr<Impl> impl_; |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | } |
| 124 | |
Jeff Thompson | c564781 | 2013-10-11 18:06:38 -0700 | [diff] [blame] | 125 | #endif // NDN_CPP_HAVE_OSX_SECURITY |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 126 | |
| 127 | #endif |