back-end-osx.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_SECURITY_TPM_BACK_END_OSX_HPP
23 #define NDN_SECURITY_TPM_BACK_END_OSX_HPP
24 
25 #include "back-end.hpp"
26 #include "helper-osx.hpp"
27 
28 #ifndef NDN_CXX_HAVE_OSX_SECURITY
29 #error "This file should not be compiled ..."
30 #endif
31 
32 namespace ndn {
33 namespace security {
34 namespace tpm {
35 
39 class BackEndOsx : public BackEnd
40 {
41 public:
42  class Error : public BackEnd::Error
43  {
44  public:
45  explicit
46  Error(const std::string& what)
47  : BackEnd::Error(what)
48  {
49  }
50  };
51 
52 public:
57  explicit
58  BackEndOsx(const std::string& location = "");
59 
60  ~BackEndOsx() override;
61 
62  static const std::string&
63  getScheme();
64 
65 public: // management
66  bool
67  isTerminalMode() const final;
68 
69  void
70  setTerminalMode(bool isTerminal) const final;
71 
72  bool
73  isTpmLocked() const final;
74 
75  bool
76  unlockTpm(const char* pw, size_t pwLen) const final;
77 
78 public: // crypto transformation
83  sign(const KeyRefOsx& key, DigestAlgorithm digestAlgorithm, const uint8_t* buf, size_t size) const;
84 
86  decrypt(const KeyRefOsx& key, const uint8_t* cipherText, size_t cipherSize) const;
87 
89  derivePublicKey(const KeyRefOsx& key) const;
90 
91 private: // inherited from tpm::BackEnd
92 
96  bool
97  doHasKey(const Name& keyName) const final;
98 
102  unique_ptr<KeyHandle>
103  doGetKeyHandle(const Name& keyName) const final;
104 
113  unique_ptr<KeyHandle>
114  doCreateKey(const Name& identityName, const KeyParams& params) final;
115 
121  void
122  doDeleteKey(const Name& keyName) final;
123 
129  doExportKey(const Name& keyName, const char* pw, size_t pwLen) final;
130 
141  void
142  doImportKey(const Name& keyName, const uint8_t* buf, size_t size, const char* pw, size_t pwLen) final;
143 
144 private:
145  class Impl;
146  unique_ptr<Impl> m_impl;
147 };
148 
149 } // namespace tpm
150 } // namespace security
151 } // namespace ndn
152 
153 #endif // NDN_SECURITY_TPM_BACK_END_OSX_HPP
bool isTpmLocked() const final
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
The back-end implementation of TPM based on macOS Keychain Services.
ConstBufferPtr sign(const KeyRefOsx &key, DigestAlgorithm digestAlgorithm, const uint8_t *buf, size_t size) const
Sign buf with key using digestAlgorithm.
bool isTerminalMode() const final
Check if TPM is in terminal mode.
Abstraction of TPM key handle.
Definition: key-handle.hpp:38
Error(const std::string &what)
Abstraction of Tpm back-end.
Definition: back-end.hpp:41
static const std::string & getScheme()
ConstBufferPtr derivePublicKey(const KeyRefOsx &key) const
ConstBufferPtr decrypt(const KeyRefOsx &key, const uint8_t *cipherText, size_t cipherSize) const
void setTerminalMode(bool isTerminal) const final
Set the terminal mode of TPM.
BackEndOsx(const std::string &location="")
Create TPM backed based on macOS KeyChain service.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
bool unlockTpm(const char *pw, size_t pwLen) const final
Unlock TPM.
Base class of key parameters.
Definition: key-params.hpp:36
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33