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