Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [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: Xingyu Ma <maxy12@cs.ucla.edu> |
| 5 | * Yingdi Yu <yingdi@cs.ucla.edu> |
| 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 9 | #ifndef NDN_SECURITY_SEC_TPM_FILE_HPP |
| 10 | #define NDN_SECURITY_SEC_TPM_FILE_HPP |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 11 | |
| 12 | #include "../common.hpp" |
| 13 | |
| 14 | #include "sec-tpm.hpp" |
| 15 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 16 | namespace ndn { |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 17 | |
| 18 | class SecTpmFile : public SecTpm |
| 19 | { |
| 20 | public: |
| 21 | struct Error : public SecTpm::Error { Error(const std::string &what) : SecTpm::Error(what) {} }; |
| 22 | |
| 23 | SecTpmFile(const std::string & dir = ""); |
| 24 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 25 | virtual |
| 26 | ~SecTpmFile() {}; |
| 27 | |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame^] | 28 | virtual void |
| 29 | setTpmPassword(const uint8_t* password, size_t passwordLength) |
| 30 | {} |
| 31 | |
| 32 | virtual void |
| 33 | resetTpmPassword() |
| 34 | {} |
| 35 | |
| 36 | virtual void |
| 37 | setInTerminal(bool inTerminal) |
| 38 | { |
| 39 | m_inTerminal = inTerminal; |
| 40 | } |
| 41 | |
| 42 | virtual bool |
| 43 | getInTerminal() |
| 44 | { |
| 45 | return m_inTerminal; |
| 46 | } |
| 47 | |
| 48 | virtual bool |
| 49 | locked() |
| 50 | { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | virtual void |
| 55 | unlockTpm(const char* password, size_t passwordLength, bool usePassword) |
| 56 | {} |
| 57 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 58 | virtual void |
| 59 | generateKeyPairInTpm(const Name & keyName, KeyType keyType, int keySize); |
| 60 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 61 | virtual void |
| 62 | deleteKeyPairInTpm(const Name &keyName); |
| 63 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 64 | virtual shared_ptr<PublicKey> |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 65 | getPublicKeyFromTpm(const Name & keyName); |
| 66 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 67 | virtual Block |
| 68 | signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm); |
| 69 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 70 | virtual ConstBufferPtr |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 71 | decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric); |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 72 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 73 | virtual ConstBufferPtr |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 74 | encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric); |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 75 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 76 | virtual void |
| 77 | generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize); |
| 78 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 79 | virtual bool |
| 80 | doesKeyExistInTpm(const Name& keyName, KeyClass keyClass); |
| 81 | |
Yingdi Yu | 4b75275 | 2014-02-18 12:24:03 -0800 | [diff] [blame] | 82 | virtual bool |
| 83 | generateRandomBlock(uint8_t* res, size_t size); |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 84 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 85 | protected: |
| 86 | /****************************** |
| 87 | * From TrustedPlatformModule * |
| 88 | ******************************/ |
| 89 | virtual ConstBufferPtr |
| 90 | exportPrivateKeyPkcs1FromTpm(const Name& keyName); |
| 91 | |
| 92 | virtual bool |
| 93 | importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size); |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 94 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 95 | virtual bool |
| 96 | importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size); |
| 97 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 98 | private: |
| 99 | class Impl; |
Yingdi Yu | 4b75275 | 2014-02-18 12:24:03 -0800 | [diff] [blame] | 100 | shared_ptr<Impl> m_impl; |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame^] | 101 | bool m_inTerminal; |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 102 | }; |
Yingdi Yu | 4b75275 | 2014-02-18 12:24:03 -0800 | [diff] [blame] | 103 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 104 | } // namespace ndn |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 105 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 106 | #endif //NDN_SECURITY_SEC_TPM_FILE_HPP |