All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sec-tpm-osx.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_OSX_HPP
9 #define NDN_SECURITY_SEC_TPM_OSX_HPP
10 
11 #include "../common.hpp"
12 #include "sec-tpm.hpp"
13 
14 namespace ndn {
15 
16 class SecTpmOsx : public SecTpm
17 {
18 public:
19  class Error : public SecTpm::Error
20  {
21  public:
22  explicit
23  Error(const std::string& what)
24  : SecTpm::Error(what)
25  {
26  }
27  };
28 
29  SecTpmOsx();
30 
31  virtual
32  ~SecTpmOsx();
33 
34 
35  /******************************
36  * From TrustedPlatformModule *
37  ******************************/
38 
39  virtual void
40  setTpmPassword(const uint8_t* password, size_t passwordLength);
41 
42  virtual void
44 
45  virtual void
46  setInTerminal(bool inTerminal);
47 
48  virtual bool
49  getInTerminal();
50 
51  virtual bool
52  locked();
53 
54  virtual bool
55  unlockTpm(const char* password, size_t passwordLength, bool usePassword);
56 
57  virtual void
58  generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize)
59  {
60  generateKeyPairInTpmInternal(keyName, keyType, keySize, false);
61  }
62 
63  virtual void
64  deleteKeyPairInTpm(const Name& keyName)
65  {
66  deleteKeyPairInTpmInternal(keyName, false);
67  }
68 
69  virtual shared_ptr<PublicKey>
70  getPublicKeyFromTpm(const Name& keyName);
71 
72  virtual Block
73  signInTpm(const uint8_t* data, size_t dataLength,
74  const Name& keyName, DigestAlgorithm digestAlgorithm)
75  {
76  return signInTpmInternal(data, dataLength, keyName, digestAlgorithm, false);
77  }
78 
79  virtual ConstBufferPtr
80  decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
81 
82  virtual ConstBufferPtr
83  encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
84 
85  virtual void
86  generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
87 
88  virtual bool
89  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
90 
91  virtual bool
92  generateRandomBlock(uint8_t* res, size_t size);
93 
94  virtual void
95  addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl);
96 
97 protected:
98  /******************************
99  * From TrustedPlatformModule *
100  ******************************/
101  virtual ConstBufferPtr
103  {
104  return exportPrivateKeyPkcs8FromTpmInternal(keyName, false);
105  }
106 
107  virtual bool
108  importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buf, size_t size)
109  {
110  return importPrivateKeyPkcs8IntoTpmInternal(keyName, buf, size, false);
111  }
112 
113  virtual bool
114  importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
115 
116  /******************************
117  * OSX-specifics *
118  ******************************/
119  void
120  generateKeyPairInTpmInternal(const Name& keyName, KeyType keyType, int keySize, bool needRetry);
121 
122  void
123  deleteKeyPairInTpmInternal(const Name& keyName, bool needRetry);
124 
126  exportPrivateKeyPkcs8FromTpmInternal(const Name& keyName, bool needRetry);
127 
128  bool
130  const uint8_t* buf, size_t size,
131  bool needRetry);
132 
133  Block
134  signInTpmInternal(const uint8_t* data, size_t dataLength,
135  const Name& keyName, DigestAlgorithm digestAlgorithm,
136  bool needRetry);
137 
138 private:
139  class Impl;
140  shared_ptr<Impl> m_impl;
141 };
142 
143 } // namespace ndn
144 
145 #endif // NDN_SECURITY_SEC_TPM_OSX_HPP
void deleteKeyPairInTpmInternal(const Name &keyName, bool needRetry)
virtual bool getInTerminal()
get inTerminal flag
virtual Block signInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm)
Sign data.
Definition: sec-tpm-osx.hpp:73
virtual ConstBufferPtr encryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Encrypt data.
virtual bool importPublicKeyPkcs1IntoTpm(const Name &keyName, const uint8_t *buf, size_t size)
Import a public key in PKCS#1 format.
Class representing wire element of the NDN packet.
Definition: block.hpp:26
ConstBufferPtr exportPrivateKeyPkcs8FromTpmInternal(const Name &keyName, bool needRetry)
virtual void addAppToACL(const Name &keyName, KeyClass keyClass, const std::string &appPath, AclType acl)
Add the application into the ACL of a particular key.
void generateKeyPairInTpmInternal(const Name &keyName, KeyType keyType, int keySize, bool needRetry)
virtual void setTpmPassword(const uint8_t *password, size_t passwordLength)
set password of TPM
virtual ~SecTpmOsx()
virtual void deleteKeyPairInTpm(const Name &keyName)
Delete a key pair of asymmetric keys.
Definition: sec-tpm-osx.hpp:64
virtual ConstBufferPtr exportPrivateKeyPkcs8FromTpm(const Name &keyName)
Export a private key in PKCS#8 format.
virtual void resetTpmPassword()
reset password of TPM
virtual bool importPrivateKeyPkcs8IntoTpm(const Name &keyName, const uint8_t *buf, size_t size)
Import a private key in PKCS#8 format.
ptr_lib::shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:17
virtual bool locked()
check if TPM is locked.
virtual void generateSymmetricKeyInTpm(const Name &keyName, KeyType keyType, int keySize)
Generate a symmetric key.
virtual shared_ptr< PublicKey > getPublicKeyFromTpm(const Name &keyName)
Get a public key.
SecTpm is the base class of the TPM classes.
Definition: sec-tpm.hpp:25
Error(const std::string &what)
Definition: sec-tpm-osx.hpp:23
bool importPrivateKeyPkcs8IntoTpmInternal(const Name &keyName, const uint8_t *buf, size_t size, bool needRetry)
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:26
virtual ConstBufferPtr decryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Decrypt data.
virtual void generateKeyPairInTpm(const Name &keyName, KeyType keyType, int keySize)
Generate a pair of asymmetric keys.
Definition: sec-tpm-osx.hpp:58
virtual bool doesKeyExistInTpm(const Name &keyName, KeyClass keyClass)
Check if a particular key exists.
virtual void setInTerminal(bool inTerminal)
set inTerminal flag
Block signInTpmInternal(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm, bool needRetry)
virtual bool generateRandomBlock(uint8_t *res, size_t size)
Generate a random block.
virtual bool unlockTpm(const char *password, size_t passwordLength, bool usePassword)
Unlock the TPM.