tpm.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_SECURITY_TPM_TPM_HPP
23 #define NDN_SECURITY_TPM_TPM_HPP
24 
25 #include "ndn-cxx/name.hpp"
28 
29 #include <unordered_map>
30 
31 namespace ndn {
32 namespace security {
33 
34 namespace v2 {
35 class KeyChain;
36 } // namespace v2
37 
38 namespace tpm {
39 
40 class BackEnd;
41 
63 class Tpm : noncopyable
64 {
65 public:
66  class Error : public std::runtime_error
67  {
68  public:
69  using std::runtime_error::runtime_error;
70  };
71 
72 public:
73  ~Tpm();
74 
75  std::string
76  getTpmLocator() const;
77 
84  bool
85  hasKey(const Name& keyName) const;
86 
94  getPublicKey(const Name& keyName) const;
95 
102  sign(const uint8_t* buf, size_t size, const Name& keyName, DigestAlgorithm digestAlgorithm) const;
103 
110  decrypt(const uint8_t* buf, size_t size, const Name& keyName) const;
111 
112 public: // Management
116  bool
117  isTerminalMode() const;
118 
124  void
125  setTerminalMode(bool isTerminal) const;
126 
130  bool
131  isTpmLocked() const;
132 
139  bool
140  unlockTpm(const char* password, size_t passwordLength) const;
141 
150  Tpm(const std::string& scheme, const std::string& location, unique_ptr<BackEnd> impl);
151 
160  Name
161  createKey(const Name& identityName, const KeyParams& params);
162 
166  void
167  deleteKey(const Name& keyName);
168 
181  exportPrivateKey(const Name& keyName, const char* pw, size_t pwLen) const;
182 
193  void
194  importPrivateKey(const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Len,
195  const char* pw, size_t pwLen);
196 
202  void
203  clearKeyCache()
204  {
205  m_keys.clear();
206  }
207 
208 private:
214  const KeyHandle*
215  findKey(const Name& keyName) const;
216 
217 private:
218  std::string m_scheme;
219  std::string m_location;
220 
221  mutable std::unordered_map<Name, unique_ptr<KeyHandle>> m_keys;
222 
223  const unique_ptr<BackEnd> m_backEnd;
224 
225  friend class v2::KeyChain;
226 };
227 
228 } // namespace tpm
229 
230 using tpm::Tpm;
231 
232 } // namespace security
233 } // namespace ndn
234 
235 #endif // NDN_SECURITY_TPM_TPM_HPP
Definition: data.cpp:26
The interface of signing key management.
Definition: key-chain.hpp:46
Abstraction of TPM key handle.
Definition: key-handle.hpp:37
represents the front-end of TPM
Definition: tpm.hpp:63
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:43
Represents an absolute name.
Definition: name.hpp:43
Base class of key parameters.
Definition: key-params.hpp:35
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:126