All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sec-tpm-file.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
9 #ifndef NDN_SECURITY_SEC_TPM_FILE_HPP
10 #define NDN_SECURITY_SEC_TPM_FILE_HPP
11 
12 #include "../common.hpp"
13 
14 #include "sec-tpm.hpp"
15 
16 namespace ndn {
17 
18 class SecTpmFile : public SecTpm
19 {
20 public:
21  class Error : public SecTpm::Error
22  {
23  public:
24  explicit
25  Error(const std::string& what)
26  : SecTpm::Error(what)
27  {
28  }
29  };
30 
31  SecTpmFile(const std::string& dir = "");
32 
33  virtual
35  {
36  }
37 
38  virtual void
39  setTpmPassword(const uint8_t* password, size_t passwordLength)
40  {
41  }
42 
43  virtual void
45  {
46  }
47 
48  virtual void
49  setInTerminal(bool inTerminal)
50  {
51  m_inTerminal = inTerminal;
52  }
53 
54  virtual bool
56  {
57  return m_inTerminal;
58  }
59 
60  virtual bool
62  {
63  return false;
64  }
65 
66  virtual bool
67  unlockTpm(const char* password, size_t passwordLength, bool usePassword)
68  {
69  return !locked();
70  }
71 
72  virtual void
73  generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize);
74 
75  virtual void
76  deleteKeyPairInTpm(const Name& keyName);
77 
78  virtual shared_ptr<PublicKey>
79  getPublicKeyFromTpm(const Name& keyName);
80 
81  virtual Block
82  signInTpm(const uint8_t* data, size_t dataLength,
83  const Name& keyName, DigestAlgorithm digestAlgorithm);
84 
85  virtual ConstBufferPtr
86  decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
87 
88  virtual ConstBufferPtr
89  encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
90 
91  virtual void
92  generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
93 
94  virtual bool
95  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
96 
97  virtual bool
98  generateRandomBlock(uint8_t* res, size_t size);
99 
100  virtual void
101  addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl)
102  {
103  }
104 
105 protected:
106  /******************************
107  * From TrustedPlatformModule *
108  ******************************/
109  virtual ConstBufferPtr
110  exportPrivateKeyPkcs8FromTpm(const Name& keyName);
111 
112  virtual bool
113  importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
114 
115  virtual bool
116  importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
117 
118 private:
119  class Impl;
120  shared_ptr<Impl> m_impl;
121  bool m_inTerminal;
122 };
123 
124 } // namespace ndn
125 
126 #endif //NDN_SECURITY_SEC_TPM_FILE_HPP
virtual bool unlockTpm(const char *password, size_t passwordLength, bool usePassword)
Unlock the TPM.
virtual void resetTpmPassword()
reset password of TPM
virtual void generateSymmetricKeyInTpm(const Name &keyName, KeyType keyType, int keySize)
Generate a symmetric key.
Error(const std::string &what)
virtual bool doesKeyExistInTpm(const Name &keyName, KeyClass keyClass)
Check if a particular key exists.
virtual void setTpmPassword(const uint8_t *password, size_t passwordLength)
set password of TPM
virtual bool getInTerminal()
get inTerminal flag
Class representing wire element of the NDN packet.
Definition: block.hpp:26
SecTpmFile(const std::string &dir="")
ptr_lib::shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:17
virtual void deleteKeyPairInTpm(const Name &keyName)
Delete a key pair of asymmetric keys.
virtual shared_ptr< PublicKey > getPublicKeyFromTpm(const Name &keyName)
Get a public key.
virtual ConstBufferPtr decryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Decrypt data.
SecTpm is the base class of the TPM classes.
Definition: sec-tpm.hpp:25
virtual bool generateRandomBlock(uint8_t *res, size_t size)
Generate a random block.
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:26
virtual ConstBufferPtr exportPrivateKeyPkcs8FromTpm(const Name &keyName)
Export a private key in PKCS#8 format.
virtual void setInTerminal(bool inTerminal)
set inTerminal flag
virtual Block signInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm)
Sign data.
virtual bool importPublicKeyPkcs1IntoTpm(const Name &keyName, const uint8_t *buf, size_t size)
Import a public key in PKCS#1 format.
virtual ConstBufferPtr encryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Encrypt data.
virtual ~SecTpmFile()
virtual void addAppToACL(const Name &keyName, KeyClass keyClass, const std::string &appPath, AclType acl)
Add the application into the ACL of a particular key.
virtual bool importPrivateKeyPkcs8IntoTpm(const Name &keyName, const uint8_t *buf, size_t size)
Import a private key in PKCS#8 format.
virtual void generateKeyPairInTpm(const Name &keyName, KeyType keyType, int keySize)
Generate a pair of asymmetric keys.
virtual bool locked()
check if TPM is locked.