tpm.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_SECURITY_TPM_TPM_HPP
23 #define NDN_SECURITY_TPM_TPM_HPP
24 
25 #include "../../common.hpp"
26 #include "../security-common.hpp"
27 #include "../../name.hpp"
28 #include "../key-params.hpp"
29 #include "key-handle.hpp"
30 #include <unordered_map>
31 
32 namespace ndn {
33 namespace security {
34 
35 namespace v2 {
36 class KeyChain;
37 } // namespace v2
38 
39 namespace tpm {
40 
41 class BackEnd;
42 
64 class Tpm : noncopyable
65 {
66 public:
67  class Error : public std::runtime_error
68  {
69  public:
70  explicit
71  Error(const std::string& what)
72  : std::runtime_error(what)
73  {
74  }
75  };
76 
77 public:
78  ~Tpm();
79 
80  std::string
81  getTpmLocator() const;
82 
89  bool
90  hasKey(const Name& keyName) const;
91 
99  getPublicKey(const Name& keyName) const;
100 
107  sign(const uint8_t* buf, size_t size, const Name& keyName, DigestAlgorithm digestAlgorithm) const;
108 
115  decrypt(const uint8_t* buf, size_t size, const Name& keyName) const;
116 
117 public: // Management
121  bool
122  isTerminalMode() const;
123 
129  void
130  setTerminalMode(bool isTerminal) const;
131 
135  bool
136  isTpmLocked() const;
137 
144  bool
145  unlockTpm(const char* password, size_t passwordLength) const;
146 
148  /*
149  * @brief Create a new TPM instance with the specified @p location
150  *
151  * @param scheme The scheme for the TPM
152  * @param location The location for the TPM
153  * @param impl The back-end implementation
154  */
155  Tpm(const std::string& scheme, const std::string& location, unique_ptr<BackEnd> impl);
156 
157  BackEnd*
158  getBackEnd()
159  {
160  return m_backEnd.get();
161  }
162 
171  Name
172  createKey(const Name& identityName, const KeyParams& params);
173 
177  void
178  deleteKey(const Name& keyName);
179 
191  exportPrivateKey(const Name& keyName, const char* pw, size_t pwLen);
192 
203  bool
204  importPrivateKey(const Name& keyName,
205  const uint8_t* pkcs8, size_t pkcs8Len,
206  const char* pw, size_t pwLen);
207 
213  void
214  clearKeyCache()
215  {
216  m_keys.clear();
217  }
218 
219 private:
225  const KeyHandle*
226  findKey(const Name& keyName) const;
227 
228 private:
229  std::string m_scheme;
230  std::string m_location;
231 
232  mutable std::unordered_map<Name, unique_ptr<KeyHandle>> m_keys;
233 
234  unique_ptr<BackEnd> m_backEnd;
235 
236  friend class v2::KeyChain;
237 };
238 
239 } // namespace tpm
240 
241 using tpm::Tpm;
242 
243 } // namespace security
244 } // namespace ndn
245 
246 #endif // NDN_SECURITY_TPM_TPM_HPP
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
std::string getTpmLocator() const
Definition: tpm.cpp:40
The interface of signing key management.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:43
STL namespace.
ConstBufferPtr sign(const uint8_t *buf, size_t size, const Name &keyName, DigestAlgorithm digestAlgorithm) const
Sign blob using key with name keyName with digest digestAlgorithm.
Definition: tpm.cpp:90
represents the front-end of TPM
Definition: tpm.hpp:64
Abstraction of Tpm back-end.
Definition: back-end.hpp:41
bool isTerminalMode() const
Check if TPM is in terminal mode.
Definition: tpm.cpp:112
bool hasKey(const Name &keyName) const
Check if a private key exist.
Definition: tpm.cpp:46
bool isTpmLocked() const
Definition: tpm.cpp:124
bool unlockTpm(const char *password, size_t passwordLength) const
Unlock TPM.
Definition: tpm.cpp:130
Name abstraction to represent an absolute name.
Definition: name.hpp:46
ConstBufferPtr getPublicKey(const Name &keyName) const
Definition: tpm.cpp:79
void setTerminalMode(bool isTerminal) const
Set the terminal mode of TPM.
Definition: tpm.cpp:118
ConstBufferPtr decrypt(const uint8_t *buf, size_t size, const Name &keyName) const
Decrypt blob using key with name keyName.
Definition: tpm.cpp:101
Base class of key parameters.
Definition: key-params.hpp:36
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
ndn security v2 KeyChain
Error(const std::string &what)
Definition: tpm.hpp:71