v1/sec-tpm-osx.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_OSX_HPP
25 #define NDN_SECURITY_V1_SEC_TPM_OSX_HPP
26 
27 #include "../../common.hpp"
28 
29 #ifndef NDN_CXX_HAVE_OSX_SECURITY
30 #error "This files should not be compiled ..."
31 #endif
32 
33 #include "sec-tpm.hpp"
34 
35 namespace ndn {
36 namespace security {
37 namespace v1 {
38 
39 class SecTpmOsx : public SecTpm
40 {
41 public:
42  class Error : public SecTpm::Error
43  {
44  public:
45  explicit
46  Error(const std::string& what)
47  : SecTpm::Error(what)
48  {
49  }
50  };
51 
52  explicit
53  SecTpmOsx(const std::string& location = "");
54 
55  virtual
56  ~SecTpmOsx();
57 
58  // Following methods are inherited from SecTpm
59  virtual void
60  setTpmPassword(const uint8_t* password, size_t passwordLength);
61 
62  virtual void
64 
65  virtual void
66  setInTerminal(bool inTerminal);
67 
68  virtual bool
69  getInTerminal() const;
70 
71  virtual bool
72  isLocked();
73 
74  virtual bool
75  unlockTpm(const char* password, size_t passwordLength, bool usePassword);
76 
77  virtual void
78  generateKeyPairInTpm(const Name& keyName, const KeyParams& params)
79  {
80  generateKeyPairInTpmInternal(keyName, params, false);
81  }
82 
83  virtual void
84  deleteKeyPairInTpm(const Name& keyName)
85  {
86  deleteKeyPairInTpmInternal(keyName, false);
87  }
88 
89  virtual shared_ptr<v1::PublicKey>
90  getPublicKeyFromTpm(const Name& keyName);
91 
92  virtual Block
93  signInTpm(const uint8_t* data, size_t dataLength,
94  const Name& keyName, DigestAlgorithm digestAlgorithm)
95  {
96  return signInTpmInternal(data, dataLength, keyName, digestAlgorithm, false);
97  }
98 
99  virtual ConstBufferPtr
100  decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
101 
102  virtual ConstBufferPtr
103  encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
104 
105  virtual void
106  generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params);
107 
108  virtual bool
109  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
110 
111  virtual bool
112  generateRandomBlock(uint8_t* res, size_t size);
113 
114  virtual void
115  addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl);
116 
117 protected:
118  // Following methods are inherited from SecTpm
119  virtual std::string
120  getScheme();
121 
122  virtual ConstBufferPtr
124  {
125  return exportPrivateKeyPkcs8FromTpmInternal(keyName, false);
126  }
127 
128  virtual bool
129  importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buf, size_t size)
130  {
131  return importPrivateKeyPkcs8IntoTpmInternal(keyName, buf, size, false);
132  }
133 
134  virtual bool
135  importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
136 
137  // Following methods are OSX-specific
138  void
139  generateKeyPairInTpmInternal(const Name& keyName, const KeyParams& params, bool needRetry);
140 
141  void
142  deleteKeyPairInTpmInternal(const Name& keyName, bool needRetry);
143 
145  exportPrivateKeyPkcs8FromTpmInternal(const Name& keyName, bool needRetry);
146 
147  bool
149  const uint8_t* buf, size_t size,
150  bool needRetry);
151 
152  Block
153  signInTpmInternal(const uint8_t* data, size_t dataLength,
154  const Name& keyName, DigestAlgorithm digestAlgorithm,
155  bool needRetry);
156 
157 public:
158  static const std::string SCHEME;
159 
160 private:
161  class Impl;
162  shared_ptr<Impl> m_impl;
163 };
164 
165 } // namespace v1
166 } // namespace security
167 } // namespace ndn
168 
169 #endif // NDN_SECURITY_V1_SEC_TPM_OSX_HPP
bool importPrivateKeyPkcs8IntoTpmInternal(const Name &keyName, const uint8_t *buf, size_t size, bool needRetry)
virtual std::string getScheme()
virtual bool doesKeyExistInTpm(const Name &keyName, KeyClass keyClass)
Check if a particular key exists.
virtual void setTpmPassword(const uint8_t *password, size_t passwordLength)
set password of TPM
virtual void generateKeyPairInTpm(const Name &keyName, const KeyParams &params)
Generate a pair of asymmetric keys.
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
virtual bool importPrivateKeyPkcs8IntoTpm(const Name &keyName, const uint8_t *buf, size_t size)
Import a private key from PKCS#8 formatted buffer of size bufferSize.
virtual void deleteKeyPairInTpm(const Name &keyName)
Delete a key pair of asymmetric keys.
virtual void generateSymmetricKeyInTpm(const Name &keyName, const KeyParams &params)
Generate a symmetric key.
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
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.
virtual void resetTpmPassword()
reset password of TPM
SecTpmOsx(const std::string &location="")
virtual Block signInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm)
Sign data.
virtual bool importPublicKeyPkcs1IntoTpm(const Name &keyName, const uint8_t *buf, size_t size)
Import a public key in PKCS#1 formatted buffer of size bufferSize.
virtual bool getInTerminal() const
Get value of inTerminal flag.
virtual ConstBufferPtr decryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Decrypt data.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
virtual bool generateRandomBlock(uint8_t *res, size_t size)
Generate a random block.
void generateKeyPairInTpmInternal(const Name &keyName, const KeyParams &params, bool needRetry)
virtual bool unlockTpm(const char *password, size_t passwordLength, bool usePassword)
Unlock the TPM.
virtual ConstBufferPtr exportPrivateKeyPkcs8FromTpm(const Name &keyName)
Export a private key in PKCS#8 format.
virtual void setInTerminal(bool inTerminal)
Set inTerminal flag to inTerminal.
virtual ConstBufferPtr encryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Encrypt data.
SecTpm is the base class of the TPM classes.
Definition: v1/sec-tpm.hpp:43
void deleteKeyPairInTpmInternal(const Name &keyName, bool needRetry)
Base class of key parameters.
Definition: key-params.hpp:36
Error(const std::string &what)
virtual bool isLocked()
Check if TPM is locked.
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
static const std::string SCHEME
Block signInTpmInternal(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm, bool needRetry)
virtual shared_ptr< v1::PublicKey > getPublicKeyFromTpm(const Name &keyName)
Get a public key.