NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
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_SEC_TPM_HPP
25 #define NDN_SECURITY_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 "v1/public-key.hpp"
33 
34 namespace ndn {
35 namespace security {
36 
42 class SecTpm : noncopyable
43 {
44 public:
45  class Error : public std::runtime_error
46  {
47  public:
48  explicit
49  Error(const std::string& what)
50  : std::runtime_error(what)
51  {
52  }
53  };
54 
55  explicit
56  SecTpm(const std::string& location);
57 
58  virtual
59  ~SecTpm();
60 
61  std::string
62  getTpmLocator();
63 
74  virtual void
75  setTpmPassword(const uint8_t* password, size_t passwordLength) = 0;
76 
80  virtual void
81  resetTpmPassword() = 0;
82 
89  virtual void
90  setInTerminal(bool inTerminal) = 0;
91 
95  virtual bool
96  getInTerminal() const = 0;
97 
101  virtual bool
102  isLocked() = 0;
103 
112  virtual bool
113  unlockTpm(const char* password, size_t passwordLength, bool usePassword) = 0;
114 
122  virtual void
123  generateKeyPairInTpm(const Name& keyName, const KeyParams& params) = 0;
124 
130  virtual void
131  deleteKeyPairInTpm(const Name& keyName) = 0;
132 
140  virtual shared_ptr<v1::PublicKey>
141  getPublicKeyFromTpm(const Name& keyName) = 0;
142 
153  virtual Block
154  signInTpm(const uint8_t* data, size_t dataLength,
155  const Name& keyName,
156  DigestAlgorithm digestAlgorithm) = 0;
157 
168  virtual ConstBufferPtr
169  decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric) = 0;
170 
181  virtual ConstBufferPtr
182  encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric) = 0;
183 
191  virtual void
192  generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params) = 0;
193 
201  virtual bool
202  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass) = 0;
203 
211  virtual bool
212  generateRandomBlock(uint8_t* res, size_t size) = 0;
213 
222  virtual void
223  addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl) = 0;
224 
234  exportPrivateKeyPkcs5FromTpm(const Name& keyName, const std::string& password);
235 
248  bool
249  importPrivateKeyPkcs5IntoTpm(const Name& keyName,
250  const uint8_t* buffer, size_t bufferSize,
251  const std::string& password);
252 
253 protected:
254  virtual std::string
255  getScheme() = 0;
256 
263  virtual ConstBufferPtr
264  exportPrivateKeyPkcs8FromTpm(const Name& keyName) = 0;
265 
275  virtual bool
276  importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize) = 0;
277 
287  virtual bool
288  importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize) = 0;
289 
297  virtual bool
298  getImpExpPassWord(std::string& password, const std::string& prompt);
299 
300 protected:
301  std::string m_location;
302 };
303 
304 } // namespace security
305 
306 using security::SecTpm;
307 
308 } // namespace ndn
309 
310 #endif // NDN_SECURITY_SEC_TPM_HPP
Copyright (c) 2011-2015 Regents of the University of California.
virtual void deleteKeyPairInTpm(const Name &keyName)=0
Delete a key pair of asymmetric keys.
virtual void generateKeyPairInTpm(const Name &keyName, const KeyParams &params)=0
Generate a pair of asymmetric keys.
virtual void setTpmPassword(const uint8_t *password, size_t passwordLength)=0
set password of TPM
std::string m_location
Definition: sec-tpm.hpp:301
virtual void setInTerminal(bool inTerminal)=0
Set inTerminal flag to inTerminal.
SecTpm is the base class of the TPM classes.
Definition: sec-tpm.hpp:42
STL namespace.
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
virtual Block signInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm)=0
Sign data.
virtual bool unlockTpm(const char *password, size_t passwordLength, bool usePassword)=0
Unlock the TPM.
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.
ConstBufferPtr exportPrivateKeyPkcs5FromTpm(const Name &keyName, const std::string &password)
Export a private key in PKCS#5 format.
Definition: sec-tpm.cpp:50
SecTpm(const std::string &location)
Definition: sec-tpm.cpp:34
std::string getTpmLocator()
Definition: sec-tpm.cpp:44
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.
virtual bool generateRandomBlock(uint8_t *res, size_t size)=0
Generate a random block.
virtual shared_ptr< v1::PublicKey > getPublicKeyFromTpm(const Name &keyName)=0
Get a public key.
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.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
virtual bool getInTerminal() const =0
Get value of inTerminal flag.
virtual bool isLocked()=0
Check if TPM is locked.
virtual ConstBufferPtr decryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)=0
Decrypt data.
virtual ConstBufferPtr exportPrivateKeyPkcs8FromTpm(const Name &keyName)=0
Export a private key in PKCS#8 format.
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:167
Base class of key parameters.
Definition: key-params.hpp:35
virtual void generateSymmetricKeyInTpm(const Name &keyName, const KeyParams &params)=0
Generate a symmetric key.
virtual std::string getScheme()=0
virtual bool getImpExpPassWord(std::string &password, const std::string &prompt)
Get import/export password.
Definition: sec-tpm.cpp:349
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
virtual ConstBufferPtr encryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)=0
Encrypt data.
Error(const std::string &what)
Definition: sec-tpm.hpp:49
virtual bool doesKeyExistInTpm(const Name &keyName, KeyClass keyClass)=0
Check if a particular key exists.
virtual void resetTpmPassword()=0
reset password of TPM