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 "../security-common.hpp"
26 #include "../../name.hpp"
27 #include "../key-params.hpp"
28 #include "key-handle.hpp"
29 
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 
165  Name
166  createKey(const Name& identityName, const KeyParams& params);
167 
171  void
172  deleteKey(const Name& keyName);
173 
186  exportPrivateKey(const Name& keyName, const char* pw, size_t pwLen) const;
187 
198  bool
199  importPrivateKey(const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Len,
200  const char* pw, size_t pwLen);
201 
207  void
208  clearKeyCache()
209  {
210  m_keys.clear();
211  }
212 
213 private:
219  const KeyHandle*
220  findKey(const Name& keyName) const;
221 
222 private:
223  std::string m_scheme;
224  std::string m_location;
225 
226  mutable std::unordered_map<Name, unique_ptr<KeyHandle>> m_keys;
227 
228  const unique_ptr<BackEnd> m_backEnd;
229 
230  friend class v2::KeyChain;
231 };
232 
233 } // namespace tpm
234 
235 using tpm::Tpm;
236 
237 } // namespace security
238 } // namespace ndn
239 
240 #endif // NDN_SECURITY_TPM_TPM_HPP
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
The interface of signing key management.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:43
Abstraction of TPM key handle.
Definition: key-handle.hpp:38
STL namespace.
represents the front-end of TPM
Definition: tpm.hpp:64
Represents an absolute name.
Definition: name.hpp:42
Base class of key parameters.
Definition: key-params.hpp:35
Error(const std::string &what)
Definition: tpm.hpp:71
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:89