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 | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 8 | #ifndef NDN_SECURITY_SEC_TPM_OSX_HPP |
| 9 | #define NDN_SECURITY_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 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 14 | namespace ndn { |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 15 | |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 16 | class SecTpmOsx : public SecTpm { |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 17 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 18 | class Error : public SecTpm::Error |
| 19 | { |
| 20 | public: |
| 21 | explicit |
| 22 | Error(const std::string& what) |
| 23 | : SecTpm::Error(what) |
| 24 | { |
| 25 | } |
| 26 | }; |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 27 | |
Yingdi Yu | 2b2b479 | 2014-02-04 16:27:07 -0800 | [diff] [blame] | 28 | SecTpmOsx(); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 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 | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 34 | /****************************** |
| 35 | * From TrustedPlatformModule * |
| 36 | ******************************/ |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 37 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 38 | virtual void |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 39 | setTpmPassword(const uint8_t* password, size_t passwordLength); |
| 40 | |
| 41 | virtual void |
| 42 | resetTpmPassword(); |
| 43 | |
| 44 | virtual void |
| 45 | setInTerminal(bool inTerminal); |
| 46 | |
| 47 | virtual bool |
| 48 | getInTerminal(); |
| 49 | |
| 50 | virtual bool |
| 51 | locked(); |
| 52 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 53 | virtual bool |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 54 | unlockTpm(const char* password, size_t passwordLength, bool usePassword); |
| 55 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 56 | virtual void |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 57 | generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize) |
| 58 | { |
| 59 | generateKeyPairInTpmInternal(keyName, keyType, keySize, false); |
| 60 | } |
| 61 | |
| 62 | virtual void |
| 63 | deleteKeyPairInTpm(const Name& keyName) |
| 64 | { |
| 65 | deleteKeyPairInTpmInternal(keyName, false); |
| 66 | } |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 67 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 68 | virtual shared_ptr<PublicKey> |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 69 | getPublicKeyFromTpm(const Name& keyName); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 70 | |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 71 | virtual Block |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 72 | signInTpm(const uint8_t* data, size_t dataLength, |
| 73 | const Name& keyName, DigestAlgorithm digestAlgorithm) |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 74 | { |
| 75 | return signInTpmInternal(data, dataLength, keyName, digestAlgorithm, false); |
| 76 | } |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 78 | virtual ConstBufferPtr |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 79 | decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 80 | |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 81 | virtual ConstBufferPtr |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 82 | encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 83 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 84 | virtual void |
Yingdi Yu | b4bb85a | 2014-01-16 10:11:04 -0800 | [diff] [blame] | 85 | generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 86 | |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 87 | virtual bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 88 | doesKeyExistInTpm(const Name& keyName, KeyClass keyClass); |
Yingdi Yu | 4b75275 | 2014-02-18 12:24:03 -0800 | [diff] [blame] | 89 | |
| 90 | virtual bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 91 | generateRandomBlock(uint8_t* res, size_t size); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 92 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 93 | virtual void |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 94 | addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl); |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 95 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 96 | protected: |
| 97 | /****************************** |
| 98 | * From TrustedPlatformModule * |
| 99 | ******************************/ |
| 100 | virtual ConstBufferPtr |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 101 | exportPrivateKeyPkcs1FromTpm(const Name& keyName) |
| 102 | { |
| 103 | return exportPrivateKeyPkcs1FromTpmInternal(keyName, false); |
| 104 | } |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 105 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 106 | virtual bool |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 107 | importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size) |
| 108 | { |
| 109 | return importPrivateKeyPkcs1IntoTpmInternal(keyName, buf, size, false); |
| 110 | } |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 111 | |
| 112 | virtual bool |
| 113 | importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size); |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 114 | |
| 115 | /****************************** |
| 116 | * OSX-specifics * |
| 117 | ******************************/ |
| 118 | void |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 119 | generateKeyPairInTpmInternal(const Name& keyName, KeyType keyType, int keySize, bool needRetry); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 120 | |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 121 | void |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 122 | deleteKeyPairInTpmInternal(const Name& keyName, bool needRetry); |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 123 | |
| 124 | ConstBufferPtr |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 125 | exportPrivateKeyPkcs1FromTpmInternal(const Name& keyName, bool needRetry); |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 126 | |
| 127 | bool |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 128 | importPrivateKeyPkcs1IntoTpmInternal(const Name& keyName, |
| 129 | const uint8_t* buf, size_t size, |
| 130 | bool needRetry); |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 131 | |
| 132 | Block |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 133 | signInTpmInternal(const uint8_t* data, size_t dataLength, |
| 134 | const Name& keyName, DigestAlgorithm digestAlgorithm, |
| 135 | bool needRetry); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 136 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 137 | private: |
Alexander Afanasyev | 04b22a9 | 2014-01-05 22:40:17 -0800 | [diff] [blame] | 138 | class Impl; |
Yingdi Yu | 4b75275 | 2014-02-18 12:24:03 -0800 | [diff] [blame] | 139 | shared_ptr<Impl> m_impl; |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 140 | }; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 141 | |
Alexander Afanasyev | 1950885 | 2014-01-29 01:01:51 -0800 | [diff] [blame] | 142 | } // namespace ndn |
Jeff Thompson | 2747dc0 | 2013-10-04 19:11:34 -0700 | [diff] [blame] | 143 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 144 | #endif // NDN_SECURITY_SEC_TPM_OSX_HPP |