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