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-2019 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 #include <boost/logic/tribool.hpp>
31 
32 namespace ndn {
33 namespace security {
34 
35 namespace transform {
36 class PrivateKey;
37 } // namespace transform
38 
39 namespace v2 {
40 class KeyChain;
41 } // namespace v2
42 
43 namespace tpm {
44 
45 class BackEnd;
46 
65 class Tpm : noncopyable
66 {
67 public:
68  class Error : public std::runtime_error
69  {
70  public:
71  using std::runtime_error::runtime_error;
72  };
73 
74  ~Tpm();
75 
76  std::string
77  getTpmLocator() const;
78 
85  bool
86  hasKey(const Name& keyName) const;
87 
95  getPublicKey(const Name& keyName) const;
96 
103  sign(const uint8_t* buf, size_t size, const Name& keyName, DigestAlgorithm digestAlgorithm) const;
104 
112  boost::logic::tribool
113  verify(const uint8_t* buf, size_t bufLen, const uint8_t* sig, size_t sigLen,
114  const Name& keyName, DigestAlgorithm digestAlgorithm) const;
115 
122  decrypt(const uint8_t* buf, size_t size, const Name& keyName) const;
123 
124 public: // Management
128  bool
129  isTerminalMode() const;
130 
136  void
137  setTerminalMode(bool isTerminal) const;
138 
142  bool
143  isTpmLocked() const;
144 
151  NDN_CXX_NODISCARD bool
152  unlockTpm(const char* password, size_t passwordLength) const;
153 
162  Tpm(const std::string& scheme, const std::string& location, unique_ptr<BackEnd> impl);
163 
174  Name
175  createKey(const Name& identityName, const KeyParams& params);
176 
180  void
181  deleteKey(const Name& keyName);
182 
195  exportPrivateKey(const Name& keyName, const char* pw, size_t pwLen) const;
196 
207  void
208  importPrivateKey(const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Len,
209  const char* pw, size_t pwLen);
210 
214  void
215  importPrivateKey(const Name& keyName, shared_ptr<transform::PrivateKey> key);
216 
222  void
224  {
225  m_keys.clear();
226  }
227 
228 private:
234  const KeyHandle*
235  findKey(const Name& keyName) const;
236 
237 private:
238  std::string m_scheme;
239  std::string m_location;
240 
241  mutable std::unordered_map<Name, unique_ptr<KeyHandle>> m_keys;
242 
243  const unique_ptr<BackEnd> m_backEnd;
244 
245  friend class v2::KeyChain;
246 };
247 
248 } // namespace tpm
249 
250 using tpm::Tpm;
251 
252 } // namespace security
253 } // namespace ndn
254 
255 #endif // NDN_SECURITY_TPM_TPM_HPP
buf
const uint8_t * buf
Definition: verification-helpers.cpp:47
ndn::security::tpm::Tpm::Error
Definition: tpm.hpp:69
ndn::KeyParams
Base class for key parameters.
Definition: key-params.hpp:36
bufLen
size_t bufLen
Definition: verification-helpers.cpp:48
transform
sigLen
size_t sigLen
Definition: verification-helpers.cpp:50
ndn::security::tpm::Tpm::exportPrivateKey
ConstBufferPtr exportPrivateKey(const Name &keyName, const char *pw, size_t pwLen) const
Export a private key.
Definition: tpm.cpp:142
ndn::security::tpm::Tpm::impl
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE const std::string unique_ptr< BackEnd > impl
Definition: tpm.hpp:162
ndn::security::tpm::Tpm::getPublicKey
ConstBufferPtr getPublicKey(const Name &keyName) const
Definition: tpm.cpp:73
name.hpp
ndn::security::tpm::Tpm::location
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE const std::string & location
Definition: tpm.hpp:162
ndn::security::tpm::Tpm::deleteKey
void deleteKey(const Name &keyName)
Delete a key pair with name keyName.
Definition: tpm.cpp:63
ndn::DigestAlgorithm
DigestAlgorithm
Definition: security-common.hpp:96
ndn::security::tpm::KeyHandle
Abstraction of TPM key handle.
Definition: key-handle.hpp:38
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
ndn::security::tpm::Tpm::isTpmLocked
bool isTpmLocked() const
Definition: tpm.cpp:130
NDN_CXX_NODISCARD
#define NDN_CXX_NODISCARD
Definition: backports.hpp:68
key-handle.hpp
ndn::security::v2::KeyChain
The interface of signing key management.
Definition: key-chain.hpp:47
ndn::security::tpm::Tpm::verify
boost::logic::tribool verify(const uint8_t *buf, size_t bufLen, const uint8_t *sig, size_t sigLen, const Name &keyName, DigestAlgorithm digestAlgorithm) const
Verify blob using the key with name keyName and using the digest digestAlgorithm.
Definition: tpm.cpp:95
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:48
sig
const uint8_t * sig
Definition: verification-helpers.cpp:49
ndn::security::tpm::Tpm
TPM front-end class.
Definition: tpm.hpp:66
ndn::security::tpm::Tpm::getTpmLocator
std::string getTpmLocator() const
Definition: tpm.cpp:42
ndn::security::tpm::Tpm::importPrivateKey
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:148
ndn::security::tpm::Tpm::unlockTpm
NDN_CXX_NODISCARD bool unlockTpm(const char *password, size_t passwordLength) const
Unlock the TPM.
Definition: tpm.cpp:136
ndn::security::tpm::Tpm::setTerminalMode
void setTerminalMode(bool isTerminal) const
Set the terminal mode of the TPM.
Definition: tpm.cpp:124
ndn::security::tpm::Tpm::clearKeyCache
void clearKeyCache()
Clear the key cache.
Definition: tpm.hpp:223
ndn::security::tpm::Tpm::isTerminalMode
bool isTerminalMode() const
Check if the TPM is in terminal mode.
Definition: tpm.cpp:118
ndn::security::v2::KeyChain
ndn security v2 KeyChain
Definition: key-chain.cpp:68
ndn::security::tpm::Tpm::decrypt
ConstBufferPtr decrypt(const uint8_t *buf, size_t size, const Name &keyName) const
Decrypt blob using the key with name keyName.
Definition: tpm.cpp:107
key-params.hpp
ndn::security::tpm::Tpm::hasKey
bool hasKey(const Name &keyName) const
Check if a private key exists.
Definition: tpm.cpp:48
ndn::security::tpm::Tpm::createKey
Name createKey(const Name &identityName, const KeyParams &params)
Create key for identityName according to params.
Definition: tpm.cpp:54
ndn::ConstBufferPtr
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:126
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::security::tpm::Tpm::~Tpm
~Tpm()
ndn::security::tpm::Tpm::sign
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:84