All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
tpm-back-end.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_TPM_BACK_END_HPP
24 #define NDN_TPM_BACK_END_HPP
25 
26 #include "../../name.hpp"
27 #include "../key-params.hpp"
28 
29 namespace ndn {
30 
31 class TpmKeyHandle;
32 
39 class TpmBackEnd {
40 public:
45  class Error : public std::runtime_error
46  {
47  public:
48  Error(const std::string& what)
49  : std::runtime_error(what)
50  {
51  }
52  };
53 
54  virtual
55  ~TpmBackEnd();
56 
62  bool
63  hasKey(const Name& keyName) const { return doHasKey(keyName); }
64 
72  ptr_lib::shared_ptr<TpmKeyHandle>
73  getKeyHandle(const Name& keyName) const { return doGetKeyHandle(keyName); }
74 
83  ptr_lib::shared_ptr<TpmKeyHandle>
84  createKey(const Name& identityName, const KeyParams& params);
85 
93  void
94  deleteKey(const Name& keyName) { doDeleteKey(keyName); }
95 
109  Blob
110  exportKey(const Name& keyName, const uint8_t* password, size_t passwordLength);
111 
128  void
129  importKey
130  (const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Length,
131  const uint8_t* password, size_t passwordLength);
132 
138  virtual bool
139  isTerminalMode() const;
140 
146  virtual void
147  setTerminalMode(bool isTerminal) const;
148 
153  virtual bool
154  isTpmLocked() const;
155 
163  virtual bool
164  unlockTpm(const uint8_t* password, size_t passwordLength) const;
165 
166 protected:
167  TpmBackEnd() {}
168 
172  static void
173  setKeyName
174  (TpmKeyHandle& keyHandle, const Name& identityName, const KeyParams& params);
175 
176 private:
182  virtual bool
183  doHasKey(const Name& keyName) const = 0;
184 
190  virtual ptr_lib::shared_ptr<TpmKeyHandle>
191  doGetKeyHandle(const Name& keyName) const = 0;
192 
202  virtual ptr_lib::shared_ptr<TpmKeyHandle>
203  doCreateKey(const Name& identityName, const KeyParams& params) = 0;
204 
210  virtual void
211  doDeleteKey(const Name& keyName) = 0;
212 
226  virtual Blob
227  doExportKey(const Name& keyName, const uint8_t* password, size_t passwordLength);
228 
244  virtual void
245  doImportKey
246  (const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Length,
247  const uint8_t* password, size_t passwordLength);
248 
249  // Disable the copy constructor and assignment operator.
250  TpmBackEnd(const TpmBackEnd& other);
251  TpmBackEnd& operator=(const TpmBackEnd& other);
252 };
253 
254 }
255 
256 #endif
virtual void setTerminalMode(bool isTerminal) const
Set the terminal mode of the TPM.
Definition: tpm-back-end.cpp:118
void importKey(const Name &keyName, const uint8_t *pkcs8, size_t pkcs8Length, const uint8_t *password, size_t passwordLength)
Import an encoded private key with name keyName in PKCS #8 format, possibly password-encrypted.
Definition: tpm-back-end.cpp:82
virtual bool isTpmLocked() const
Check if the TPM is locked.
Definition: tpm-back-end.cpp:121
TpmBackEnd is an abstract base class for a TPM backend implementation which provides a TpmKeyHandle t...
Definition: tpm-back-end.hpp:39
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
virtual bool unlockTpm(const uint8_t *password, size_t passwordLength) const
Unlock the TPM.
Definition: tpm-back-end.cpp:124
static void setKeyName(TpmKeyHandle &keyHandle, const Name &identityName, const KeyParams &params)
Set the key name in keyHandle according to identityName and params.
Definition: tpm-back-end.cpp:93
bool hasKey(const Name &keyName) const
Check if the key with name keyName exists in the TPM.
Definition: tpm-back-end.hpp:63
Blob exportKey(const Name &keyName, const uint8_t *password, size_t passwordLength)
Get the encoded private key with name keyName in PKCS #8 format, possibly password-encrypted.
Definition: tpm-back-end.cpp:72
KeyParams is a base class for key parameters.
Definition: key-params.hpp:36
ptr_lib::shared_ptr< TpmKeyHandle > createKey(const Name &identityName, const KeyParams &params)
Create a key for the identityName according to params.
Definition: tpm-back-end.cpp:37
virtual bool isTerminalMode() const
Check if the TPM is in terminal mode.
Definition: tpm-back-end.cpp:115
void deleteKey(const Name &keyName)
Delete the key with name keyName.
Definition: tpm-back-end.hpp:94
A TpmBackEnd::Error extends runtime_error and represents a non-semantic error in backend TPM processi...
Definition: tpm-back-end.hpp:45
ptr_lib::shared_ptr< TpmKeyHandle > getKeyHandle(const Name &keyName) const
Get the handle of the key with name keyName.
Definition: tpm-back-end.hpp:73