ndn-cxx: NDN C++ Library 0.9.0-34-ga362e65e
Loading...
Searching...
No Matches
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-2025 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_CXX_SECURITY_TPM_TPM_HPP
23#define NDN_CXX_SECURITY_TPM_TPM_HPP
24
25#include "ndn-cxx/name.hpp"
28
29#include <unordered_map>
30#include <boost/logic/tribool.hpp>
31
32namespace ndn::security {
33
34namespace transform {
35class PrivateKey;
36} // namespace transform
37
38class KeyChain;
39
40namespace tpm {
41
42class BackEnd;
43
62class Tpm : noncopyable
63{
64public:
65 class Error : public std::runtime_error
66 {
67 public:
68 using std::runtime_error::runtime_error;
69 };
70
72
76 const std::string&
78 {
79 return m_locator;
80 }
81
88 bool
89 hasKey(const Name& keyName) const;
90
98 getPublicKey(const Name& keyName) const;
99
107 sign(const InputBuffers& bufs, const Name& keyName, DigestAlgorithm digestAlgorithm) const;
108
117 [[nodiscard]] boost::logic::tribool
118 verify(const InputBuffers& bufs, span<const uint8_t> sig, const Name& keyName,
119 DigestAlgorithm digestAlgorithm) const;
120
127 decrypt(span<const uint8_t> buf, const Name& keyName) const;
128
129NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // operations accessible only by KeyChain
136 Tpm(const std::string& locator, unique_ptr<BackEnd> impl);
137
148 Name
149 createKey(const Name& identityName, const KeyParams& params);
150
154 void
155 deleteKey(const Name& keyName);
156
170 exportPrivateKey(const Name& keyName, const char* pw, size_t pwLen) const;
171
184 void
185 importPrivateKey(const Name& keyName, span<const uint8_t> pkcs8, const char* pw, size_t pwLen);
186
190 void
191 importPrivateKey(const Name& keyName, shared_ptr<transform::PrivateKey> key);
192
198 void
199 clearKeyCache()
200 {
201 m_keys.clear();
202 }
203
204private:
210 const KeyHandle*
211 findKey(const Name& keyName) const;
212
213private:
214 const std::string m_locator;
215 const unique_ptr<BackEnd> m_backEnd;
216
217 mutable std::unordered_map<Name, unique_ptr<KeyHandle>> m_keys;
218
219 friend KeyChain;
220};
221
222} // namespace tpm
223
224using tpm::Tpm;
225
226} // namespace ndn::security
227
228#endif // NDN_CXX_SECURITY_TPM_TPM_HPP
Base class for key parameters.
Represents an absolute name.
Definition name.hpp:45
The main interface for signing key management.
Definition key-chain.hpp:87
TPM front-end class.
Definition tpm.hpp:63
ConstBufferPtr getPublicKey(const Name &keyName) const
Definition tpm.cpp:63
ConstBufferPtr decrypt(span< const uint8_t > buf, const Name &keyName) const
Decrypt blob using the key with name keyName.
Definition tpm.cpp:88
boost::logic::tribool verify(const InputBuffers &bufs, span< const uint8_t > sig, const Name &keyName, DigestAlgorithm digestAlgorithm) const
Verify discontiguous ranges using the key with name keyName and using the digest digestAlgorithm.
Definition tpm.cpp:77
const std::string & getTpmLocator() const
Return the TPM Locator.
Definition tpm.hpp:77
ConstBufferPtr sign(const InputBuffers &bufs, const Name &keyName, DigestAlgorithm digestAlgorithm) const
Sign discontiguous ranges using the key with name keyName and using the digest digestAlgorithm.
Definition tpm.cpp:70
bool hasKey(const Name &keyName) const
Check if a private key exists.
Definition tpm.cpp:39
Abstraction of a private key in crypto transformations.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition common.hpp:49
Contains the ndn-cxx security framework.
std::shared_ptr< const Buffer > ConstBufferPtr
Definition buffer.hpp:140
InputBuffers bufs
span< const uint8_t > sig