All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
tpm.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_TPM_HPP
24 #define NDN_TPM_HPP
25 
26 #include <map>
27 #include "../../name.hpp"
28 #include "../key-params.hpp"
29 
30 namespace ndn {
31 
32 class TpmKeyHandle;
33 class TpmBackEnd;
34 
54 class Tpm {
55 public:
60  class Error : public std::runtime_error
61  {
62  public:
63  Error(const std::string& what)
64  : std::runtime_error(what)
65  {
66  }
67  };
68 
69  std::string
70  getTpmLocator() const;
71 
77  bool
78  hasKey(const Name& keyName) const;
79 
85  Blob
86  getPublicKey(const Name& keyName) const;
87 
98  Blob
99  sign
100  (const uint8_t* data, size_t dataLength, const Name& keyName,
101  DigestAlgorithm digestAlgorithm) const;
102 
111  Blob
112  decrypt
113  (const uint8_t* cipherText, size_t cipherTextLength,
114  const Name& keyName) const;
115 
116  // TPM Management
117 
122  bool
123  isTerminalMode() const;
124 
130  void
131  setTerminalMode(bool isTerminal) const;
132 
137  bool
138  isTpmLocked() const;
139 
146  bool
147  unlockTpm(const uint8_t* password, size_t passwordLength) const;
148 
149 private:
150  friend class KeyChain;
151  friend class SafeBag;
152 
153  /*
154  * Create a new TPM instance with the specified location. This constructor
155  * should only be called by KeyChain.
156  * @param scheme The scheme for the TPM.
157  * @param location The location for the TPM.
158  * @param backEnd The TPM back-end implementation.
159  */
160  Tpm(const std::string& scheme, const std::string& location,
161  const ptr_lib::shared_ptr<TpmBackEnd>& backEnd);
162 
163  TpmBackEnd*
164  getBackEnd() { return backEnd_.get(); }
165 
175  Name
176  createKey(const Name& identityName, const KeyParams& params);
177 
184  void
185  deleteKey(const Name& keyName);
186 
201  Blob
202  exportPrivateKey
203  (const Name& keyName, const uint8_t* password, size_t passwordLength);
204 
220  void
221  importPrivateKey
222  (const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Length,
223  const uint8_t* password, size_t passwordLength);
224 
232  const TpmKeyHandle*
233  findKey(const Name& keyName) const;
234 
235  // Disable the copy constructor and assignment operator.
236  Tpm(const Tpm& other);
237  Tpm& operator=(const Tpm& other);
238 
239  std::string scheme_;
240  std::string location_;
241 
242  std::map<Name, ptr_lib::shared_ptr<TpmKeyHandle>> keys_;
243 
244  ptr_lib::shared_ptr<TpmBackEnd> backEnd_;
245 };
246 
247 }
248 
249 #endif
bool isTpmLocked() const
Check if the TPM is locked.
Definition: tpm.cpp:92
void setTerminalMode(bool isTerminal) const
Set the terminal mode of the TPM.
Definition: tpm.cpp:86
bool isTerminalMode() const
Check if the TPM is in terminal mode.
Definition: tpm.cpp:83
Blob getPublicKey(const Name &keyName) const
Get the public portion of an asymmetric key pair with name keyName.
Definition: tpm.cpp:47
bool unlockTpm(const uint8_t *password, size_t passwordLength) const
Unlock the TPM.
Definition: tpm.cpp:95
The TPM (Trusted Platform Module) stores the private portion of a user's cryptography keys...
Definition: tpm.hpp:54
TpmBackEnd is an abstract base class for a TPM backend implementation which provides a TpmKeyHandle t...
Definition: tpm-back-end.hpp:39
TpmKeyHandle is an abstract base class for a TPM key handle, which provides an interface to perform c...
Definition: tpm-key-handle.hpp:35
KeyChain is the main class of the security library.
Definition: key-chain.hpp:53
bool hasKey(const Name &keyName) const
Check if the key with name keyName exists in the TPM.
Definition: tpm.cpp:44
A Tpm::Error extends runtime_error and represents a semantic error in TPM processing.
Definition: tpm.hpp:60
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
A Blob holds a pointer to an immutable byte array implemented as const std::vector<uint8_t>.
Definition: blob.hpp:42
A SafeBag represents a container for sensitive related information such as a certificate and private ...
Definition: safe-bag.hpp:35
KeyParams is a base class for key parameters.
Definition: key-params.hpp:36
Blob decrypt(const uint8_t *cipherText, size_t cipherTextLength, const Name &keyName) const
Return the plain text which is decrypted from cipherText using the key with name keyName.
Definition: tpm.cpp:72
Blob sign(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm) const
Compute a digital signature from the byte array using the key with name keyName.
Definition: tpm.cpp:59