All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
tpm-back-end-osx.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_TPM_BACK_END_OSX_HPP
24 #define NDN_TPM_BACK_END_OSX_HPP
25 
26 // Only compile if ndn-cpp-config.h defines NDN_CPP_HAVE_OSX_SECURITY 1.
27 #include "../../ndn-cpp-config.h"
28 #if NDN_CPP_HAVE_OSX_SECURITY
29 
30 #include "helper-osx.hpp"
31 #include "tpm-back-end.hpp"
32 
33 namespace ndn {
34 
39 class TpmBackEndOsx : public TpmBackEnd {
40 public:
45  class Error : public TpmBackEnd::Error
46  {
47  public:
48  Error(const std::string& what)
49  : TpmBackEnd::Error(what)
50  {
51  }
52  };
53 
59  TpmBackEndOsx(const std::string& location = "");
60 
61  static std::string
62  getScheme() { return "tpm-osxkeychain"; }
63 
64  // Management
65 
70  virtual bool
71  isTerminalMode() const;
72 
78  virtual void
79  setTerminalMode(bool isTerminal) const;
80 
85  virtual bool
86  isTpmLocked() const;
87 
94  virtual bool
95  unlockTpm(const uint8_t* password, size_t passwordLength) const;
96 
97  // Cryptographic transformation
98 
102  static Blob
103  sign
104  (const KeyRefOsx& key, DigestAlgorithm digestAlgorithm,
105  const uint8_t* data, size_t dataLength);
106 
107  static Blob
108  decrypt
109  (const KeyRefOsx& key, const uint8_t* cipherText, size_t cipherTextLength);
110 
111  static Blob
112  derivePublicKey(const KeyRefOsx& key);
113 
114 private:
120  virtual bool
121  doHasKey(const Name& keyName) const;
122 
128  virtual ptr_lib::shared_ptr<TpmKeyHandle>
129  doGetKeyHandle(const Name& keyName) const;
130 
140  virtual ptr_lib::shared_ptr<TpmKeyHandle>
141  doCreateKey(const Name& identityName, const KeyParams& params);
142 
148  virtual void
149  doDeleteKey(const Name& keyName);
150 
151  // TODO: doExportKey.
152  // TODO: doImportKey.
153 
159  static CFReleaser<SecKeychainItemRef>
160  getKey(const Name& keyName);
161 
162  SecKeychainRef keyChainRef_;
163  bool isTerminalMode_;
164 };
165 
166 }
167 
168 #endif // NDN_CPP_HAVE_OSX_SECURITY
169 
170 #endif