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 | |
| 28 | /** |
| 29 | * Generate a pair of asymmetric keys. |
| 30 | * @param keyName The name of the key pair. |
| 31 | * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA. |
| 32 | * @param keySize The size of the key pair. |
| 33 | */ |
| 34 | virtual void |
| 35 | generateKeyPairInTpm(const Name & keyName, KeyType keyType, int keySize); |
| 36 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 37 | virtual void |
| 38 | deleteKeyPairInTpm(const Name &keyName); |
| 39 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame^] | 40 | virtual shared_ptr<PublicKey> |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 41 | getPublicKeyFromTpm(const Name & keyName); |
| 42 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 43 | virtual Block |
| 44 | signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm); |
| 45 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 46 | virtual ConstBufferPtr |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame^] | 47 | 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] | 48 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 49 | virtual ConstBufferPtr |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame^] | 50 | 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] | 51 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 52 | virtual void |
| 53 | generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize); |
| 54 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 55 | virtual bool |
| 56 | doesKeyExistInTpm(const Name& keyName, KeyClass keyClass); |
| 57 | |
Yingdi Yu | 4b75275 | 2014-02-18 12:24:03 -0800 | [diff] [blame] | 58 | virtual bool |
| 59 | generateRandomBlock(uint8_t* res, size_t size); |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 60 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 61 | protected: |
| 62 | /****************************** |
| 63 | * From TrustedPlatformModule * |
| 64 | ******************************/ |
| 65 | virtual ConstBufferPtr |
| 66 | exportPrivateKeyPkcs1FromTpm(const Name& keyName); |
| 67 | |
| 68 | virtual bool |
| 69 | importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size); |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 70 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 71 | virtual bool |
| 72 | importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size); |
| 73 | |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 74 | private: |
| 75 | class Impl; |
Yingdi Yu | 4b75275 | 2014-02-18 12:24:03 -0800 | [diff] [blame] | 76 | shared_ptr<Impl> m_impl; |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 77 | }; |
Yingdi Yu | 4b75275 | 2014-02-18 12:24:03 -0800 | [diff] [blame] | 78 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame^] | 79 | } // namespace ndn |
Yingdi Yu | 2d9c50f | 2014-01-21 18:25:00 -0800 | [diff] [blame] | 80 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame^] | 81 | #endif //NDN_SECURITY_SEC_TPM_FILE_HPP |