v1/sec-tpm.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
24 #ifndef NDN_SECURITY_V1_SEC_TPM_HPP
25 #define NDN_SECURITY_V1_SEC_TPM_HPP
26 
27 #include "../../common.hpp"
28 #include "../security-common.hpp"
29 #include "../../name.hpp"
30 #include "../../data.hpp"
31 #include "../key-params.hpp"
32 #include "public-key.hpp"
33 
34 namespace ndn {
35 namespace security {
36 namespace v1 {
37 
43 class SecTpm : noncopyable
44 {
45 public:
46  class Error : public std::runtime_error
47  {
48  public:
49  explicit
50  Error(const std::string& what)
51  : std::runtime_error(what)
52  {
53  }
54  };
55 
56  explicit
57  SecTpm(const std::string& location);
58 
59  virtual
60  ~SecTpm();
61 
62  std::string
63  getTpmLocator();
64 
75  virtual void
76  setTpmPassword(const uint8_t* password, size_t passwordLength) = 0;
77 
81  virtual void
82  resetTpmPassword() = 0;
83 
90  virtual void
91  setInTerminal(bool inTerminal) = 0;
92 
96  virtual bool
97  getInTerminal() const = 0;
98 
102  virtual bool
103  isLocked() = 0;
104 
113  virtual bool
114  unlockTpm(const char* password, size_t passwordLength, bool usePassword) = 0;
115 
123  virtual void
124  generateKeyPairInTpm(const Name& keyName, const KeyParams& params) = 0;
125 
131  virtual void
132  deleteKeyPairInTpm(const Name& keyName) = 0;
133 
141  virtual shared_ptr<v1::PublicKey>
142  getPublicKeyFromTpm(const Name& keyName) = 0;
143 
154  virtual Block
155  signInTpm(const uint8_t* data, size_t dataLength,
156  const Name& keyName,
157  DigestAlgorithm digestAlgorithm) = 0;
158 
169  virtual ConstBufferPtr
170  decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric) = 0;
171 
182  virtual ConstBufferPtr
183  encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric) = 0;
184 
192  virtual void
193  generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params) = 0;
194 
202  virtual bool
203  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass) = 0;
204 
212  virtual bool
213  generateRandomBlock(uint8_t* res, size_t size) = 0;
214 
223  virtual void
224  addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl) = 0;
225 
235  exportPrivateKeyPkcs5FromTpm(const Name& keyName, const std::string& password);
236 
249  bool
250  importPrivateKeyPkcs5IntoTpm(const Name& keyName,
251  const uint8_t* buffer, size_t bufferSize,
252  const std::string& password);
253 
254 protected:
255  virtual std::string
256  getScheme() = 0;
257 
264  virtual ConstBufferPtr
265  exportPrivateKeyPkcs8FromTpm(const Name& keyName) = 0;
266 
276  virtual bool
277  importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize) = 0;
278 
288  virtual bool
289  importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize) = 0;
290 
298  virtual bool
299  getImpExpPassWord(std::string& password, const std::string& prompt);
300 
301 protected:
302  std::string m_location;
303 };
304 
305 } // namespace v1
306 
307 #ifdef NDN_CXX_KEEP_SECURITY_V1_ALIASES
308 using v1::SecTpm;
309 #endif // NDN_CXX_KEEP_SECURITY_V1_ALIASES
310 
311 } // namespace security
312 
313 #ifdef NDN_CXX_KEEP_SECURITY_V1_ALIASES
315 #endif // NDN_CXX_KEEP_SECURITY_V1_ALIASES
316 
317 } // namespace ndn
318 
319 #endif // NDN_SECURITY_V1_SEC_TPM_HPP
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
Error(const std::string &what)
Definition: v1/sec-tpm.hpp:50
virtual shared_ptr< v1::PublicKey > getPublicKeyFromTpm(const Name &keyName)=0
Get a public key.
virtual ConstBufferPtr exportPrivateKeyPkcs8FromTpm(const Name &keyName)=0
Export a private key in PKCS#8 format.
STL namespace.
virtual std::string getScheme()=0
virtual void resetTpmPassword()=0
reset password of TPM
std::string getTpmLocator()
Definition: sec-tpm.cpp:45
virtual Block signInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm)=0
Sign data.
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
virtual bool isLocked()=0
Check if TPM is locked.
virtual bool generateRandomBlock(uint8_t *res, size_t size)=0
Generate a random block.
virtual bool unlockTpm(const char *password, size_t passwordLength, bool usePassword)=0
Unlock the TPM.
virtual void generateSymmetricKeyInTpm(const Name &keyName, const KeyParams &params)=0
Generate a symmetric key.
bool importPrivateKeyPkcs5IntoTpm(const Name &keyName, const uint8_t *buffer, size_t bufferSize, const std::string &password)
Import a private key in PKCS#5 formatted buffer of size bufferSize.
Definition: sec-tpm.cpp:168
virtual bool doesKeyExistInTpm(const Name &keyName, KeyClass keyClass)=0
Check if a particular key exists.
virtual bool getInTerminal() const =0
Get value of inTerminal flag.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
virtual void addAppToAcl(const Name &keyName, KeyClass keyClass, const std::string &appPath, AclType acl)=0
Add the application into the ACL of a particular key.
virtual ConstBufferPtr encryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)=0
Encrypt data.
virtual bool importPublicKeyPkcs1IntoTpm(const Name &keyName, const uint8_t *buffer, size_t bufferSize)=0
Import a public key in PKCS#1 formatted buffer of size bufferSize.
SecTpm is the base class of the TPM classes.
Definition: v1/sec-tpm.hpp:43
virtual void deleteKeyPairInTpm(const Name &keyName)=0
Delete a key pair of asymmetric keys.
Base class of key parameters.
Definition: key-params.hpp:36
SecTpm(const std::string &location)
Definition: sec-tpm.cpp:35
virtual void setInTerminal(bool inTerminal)=0
Set inTerminal flag to inTerminal.
virtual void setTpmPassword(const uint8_t *password, size_t passwordLength)=0
set password of TPM
ConstBufferPtr exportPrivateKeyPkcs5FromTpm(const Name &keyName, const std::string &password)
Export a private key in PKCS#5 format.
Definition: sec-tpm.cpp:51
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
virtual bool getImpExpPassWord(std::string &password, const std::string &prompt)
Get import/export password.
Definition: sec-tpm.cpp:350
virtual ConstBufferPtr decryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)=0
Decrypt data.
virtual bool importPrivateKeyPkcs8IntoTpm(const Name &keyName, const uint8_t *buffer, size_t bufferSize)=0
Import a private key from PKCS#8 formatted buffer of size bufferSize.
virtual void generateKeyPairInTpm(const Name &keyName, const KeyParams &params)=0
Generate a pair of asymmetric keys.