All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sec-tpm-memory.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
8 #ifndef NDN_SECURITY_SEC_TPM_MEMORY_HPP
9 #define NDN_SECURITY_SEC_TPM_MEMORY_HPP
10 
11 #include "../common.hpp"
12 #include "sec-tpm.hpp"
13 
14 struct rsa_st;
15 
16 namespace ndn {
17 
23 class SecTpmMemory : public SecTpm
24 {
25 public:
26  class Error : public SecTpm::Error
27  {
28  public:
29  explicit
30  Error(const std::string& what)
31  : SecTpm::Error(what)
32  {
33  }
34  };
35 
36  virtual
37  ~SecTpmMemory();
38 
39  /******************************
40  * From TrustedPlatformModule *
41  ******************************/
42 
43  virtual void
44  setTpmPassword(const uint8_t* password, size_t passwordLength)
45  {
46  }
47 
48  virtual void
50  {
51  }
52 
53  virtual void
54  setInTerminal(bool inTerminal)
55  {
56  m_inTerminal = inTerminal;
57  }
58 
59  virtual bool
61  {
62  return m_inTerminal;
63  }
64 
65  virtual bool
67  {
68  return true;
69  }
70 
71  virtual bool
72  unlockTpm(const char* password, size_t passwordLength, bool usePassword)
73  {
74  return !locked();
75  }
76 
77  virtual void
78  generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize);
79 
80  virtual shared_ptr<PublicKey>
81  getPublicKeyFromTpm(const Name& keyName);
82 
83  virtual void
84  deleteKeyPairInTpm(const Name& keyName);
85 
86  virtual Block
87  signInTpm(const uint8_t* data, size_t dataLength,
88  const Name& keyName, DigestAlgorithm digestAlgorithm);
89 
90  virtual ConstBufferPtr
91  decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
92 
93  virtual ConstBufferPtr
94  encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
95 
96  virtual void
97  generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
98 
99  virtual bool
100  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
101 
102  virtual bool
103  generateRandomBlock(uint8_t* res, size_t size);
104 
105  virtual void
106  addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl)
107  {
108  }
109 
110  /******************************
111  * SecTpmMemory specific *
112  ******************************/
113 
123  void setKeyPairForKeyName(const Name& keyName,
124  const uint8_t* publicKeyDer, size_t publicKeyDerLength,
125  const uint8_t* privateKeyDer, size_t privateKeyDerLength);
126 
127 protected:
128  /******************************
129  * From TrustedPlatformModule *
130  ******************************/
131  virtual ConstBufferPtr
132  exportPrivateKeyPkcs1FromTpm(const Name& keyName);
133 
134  virtual bool
135  importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
136 
137  virtual bool
138  importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
139 
140 
141 private:
142  class RsaPrivateKey;
143 
144  typedef std::map<std::string, shared_ptr<PublicKey> > PublicKeyStore;
145  typedef std::map<std::string, shared_ptr<RsaPrivateKey> > PrivateKeyStore;
146 
147  PublicKeyStore m_publicKeyStore;
148  PrivateKeyStore m_privateKeyStore;
150  bool m_inTerminal;
151 };
152 
153 } // namespace ndn
154 
155 #endif //NDN_SECURITY_SEC_TPM_MEMORY_HPP
virtual void generateKeyPairInTpm(const Name &keyName, KeyType keyType, int keySize)
Generate a pair of asymmetric keys.
virtual Block signInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm)
Sign data.
virtual bool importPrivateKeyPkcs1IntoTpm(const Name &keyName, const uint8_t *buf, size_t size)
virtual bool importPublicKeyPkcs1IntoTpm(const Name &keyName, const uint8_t *buf, size_t size)
Import a public key in PKCS#1 format.
virtual bool locked()
check if TPM is locked.
SecTpmMemory implements a simple in-memory TPM.
virtual bool unlockTpm(const char *password, size_t passwordLength, bool usePassword)
Unlock the TPM.
virtual ConstBufferPtr encryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Encrypt data.
Class representing wire element of the NDN packet.
Definition: block.hpp:26
virtual void addAppToACL(const Name &keyName, KeyClass keyClass, const std::string &appPath, AclType acl)
Add the application into the ACL of a particular key.
virtual shared_ptr< PublicKey > getPublicKeyFromTpm(const Name &keyName)
Get a public key.
ptr_lib::shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:17
SecTpm is the base class of the TPM classes.
Definition: sec-tpm.hpp:25
virtual void setTpmPassword(const uint8_t *password, size_t passwordLength)
set password of TPM
virtual void resetTpmPassword()
reset password of TPM
virtual void deleteKeyPairInTpm(const Name &keyName)
Delete a key pair of asymmetric keys.
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:26
virtual bool getInTerminal()
get inTerminal flag
virtual bool doesKeyExistInTpm(const Name &keyName, KeyClass keyClass)
Check if a particular key exists.
virtual ConstBufferPtr exportPrivateKeyPkcs1FromTpm(const Name &keyName)
virtual ConstBufferPtr decryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Decrypt data.
virtual void generateSymmetricKeyInTpm(const Name &keyName, KeyType keyType, int keySize)
Generate a symmetric key.
virtual bool generateRandomBlock(uint8_t *res, size_t size)
Generate a random block.
virtual void setInTerminal(bool inTerminal)
set inTerminal flag
Error(const std::string &what)
void setKeyPairForKeyName(const Name &keyName, const uint8_t *publicKeyDer, size_t publicKeyDerLength, const uint8_t *privateKeyDer, size_t privateKeyDerLength)
Set the public and private key for the keyName.