NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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-2017 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 "key-handle.hpp"
26 #include "../key-params.hpp"
27 #include "../../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  explicit
70  Error(const std::string& what)
71  : std::runtime_error(what)
72  {
73  }
74  };
75 
76 public:
77  ~Tpm();
78 
79  std::string
80  getTpmLocator() const;
81 
88  bool
89  hasKey(const Name& keyName) const;
90 
98  getPublicKey(const Name& keyName) const;
99 
106  sign(const uint8_t* buf, size_t size, const Name& keyName, DigestAlgorithm digestAlgorithm) const;
107 
114  decrypt(const uint8_t* buf, size_t size, const Name& keyName) const;
115 
116 public: // Management
120  bool
121  isTerminalMode() const;
122 
128  void
129  setTerminalMode(bool isTerminal) const;
130 
134  bool
135  isTpmLocked() const;
136 
143  bool
144  unlockTpm(const char* password, size_t passwordLength) const;
145 
147  /*
148  * @brief Create a new TPM instance with the specified @p location.
149  *
150  * @param scheme The scheme for the TPM
151  * @param location The location for the TPM
152  * @param impl The back-end implementation
153  */
154  Tpm(const std::string& scheme, const std::string& location, unique_ptr<BackEnd> impl);
155 
164  Name
165  createKey(const Name& identityName, const KeyParams& params);
166 
170  void
171  deleteKey(const Name& keyName);
172 
185  exportPrivateKey(const Name& keyName, const char* pw, size_t pwLen) const;
186 
197  void
198  importPrivateKey(const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Len,
199  const char* pw, size_t pwLen);
200 
206  void
208  {
209  m_keys.clear();
210  }
211 
212 private:
218  const KeyHandle*
219  findKey(const Name& keyName) const;
220 
221 private:
222  std::string m_scheme;
223  std::string m_location;
224 
225  mutable std::unordered_map<Name, unique_ptr<KeyHandle>> m_keys;
226 
227  const unique_ptr<BackEnd> m_backEnd;
228 
229  friend class v2::KeyChain;
230 };
231 
232 } // namespace tpm
233 
234 using tpm::Tpm;
235 
236 } // namespace security
237 } // namespace ndn
238 
239 #endif // NDN_SECURITY_TPM_TPM_HPP
ConstBufferPtr sign(const uint8_t *buf, size_t size, const Name &keyName, DigestAlgorithm digestAlgorithm) const
Sign blob using the key with name keyName and using the digest digestAlgorithm.
Definition: tpm.cpp:90
Copyright (c) 2011-2015 Regents of the University of California.
The interface of signing key management.
Definition: key-chain.hpp:46
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:43
bool hasKey(const Name &keyName) const
Check if a private key exists.
Definition: tpm.cpp:46
Abstraction of TPM key handle.
Definition: key-handle.hpp:38
STL namespace.
Name createKey(const Name &identityName, const KeyParams &params)
Create key for identityName according to params.
Definition: tpm.cpp:52
ConstBufferPtr getPublicKey(const Name &keyName) const
Definition: tpm.cpp:79
bool isTpmLocked() const
Definition: tpm.cpp:124
represents the front-end of TPM
Definition: tpm.hpp:63
ConstBufferPtr exportPrivateKey(const Name &keyName, const char *pw, size_t pwLen) const
Export a private key.
Definition: tpm.cpp:136
void clearKeyCache()
Clear the key cache.
Definition: tpm.hpp:207
bool unlockTpm(const char *password, size_t passwordLength) const
Unlock the TPM.
Definition: tpm.cpp:130
void setTerminalMode(bool isTerminal) const
Set the terminal mode of the TPM.
Definition: tpm.cpp:118
Represents an absolute name.
Definition: name.hpp:42
void deleteKey(const Name &keyName)
Delete a key pair with name keyName.
Definition: tpm.cpp:69
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE const std::string & location
Definition: tpm.hpp:154
std::string getTpmLocator() const
Definition: tpm.cpp:40
void importPrivateKey(const Name &keyName, const uint8_t *pkcs8, size_t pkcs8Len, const char *pw, size_t pwLen)
Import a private key.
Definition: tpm.cpp:142
Base class of key parameters.
Definition: key-params.hpp:35
ConstBufferPtr decrypt(const uint8_t *buf, size_t size, const Name &keyName) const
Decrypt blob using the key with name keyName.
Definition: tpm.cpp:101
bool isTerminalMode() const
Check if the TPM is in terminal mode.
Definition: tpm.cpp:112
ndn security v2 KeyChain
Definition: key-chain.cpp:70
Error(const std::string &what)
Definition: tpm.hpp:70
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE const std::string unique_ptr< BackEnd > impl
Definition: tpm.hpp:154
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:89