ndn-cxx: NDN C++ Library 0.9.0-33-g832ea91d
Loading...
Searching...
No Matches
back-end.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2024 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_BACK_END_HPP
23#define NDN_CXX_SECURITY_TPM_BACK_END_HPP
24
26
27namespace ndn::security::tpm {
28
34class BackEnd : noncopyable
35{
36public:
38
39 virtual
41
42public: // key management
48 bool
49 hasKey(const Name& keyName) const;
50
59 unique_ptr<KeyHandle>
60 getKeyHandle(const Name& keyName) const;
61
69 unique_ptr<KeyHandle>
70 createKey(const Name& identityName, const KeyParams& params);
71
80 void
81 deleteKey(const Name& keyName);
82
94 exportKey(const Name& keyName, const char* pw, size_t pwLen);
95
106 void
107 importKey(const Name& keyName, span<const uint8_t> pkcs8, const char* pw, size_t pwLen);
108
114 void
115 importKey(const Name& keyName, shared_ptr<transform::PrivateKey> key);
116
123 [[deprecated]]
124 virtual bool
126 {
127 return true;
128 }
129
137 [[deprecated]]
138 virtual void
139 setTerminalMode(bool isTerminal) const
140 {
141 }
142
149 [[deprecated]]
150 virtual bool
152 {
153 return false;
154 }
155
166 [[deprecated]]
167 [[nodiscard]] virtual bool
168 unlockTpm(const char* pw, size_t pwLen) const
169 {
170 return true;
171 }
172
173protected: // helper methods
177 Name
178 constructAsymmetricKeyName(const KeyHandle& key, const Name& identity,
179 const KeyParams& params) const;
180
184 Name
185 constructHmacKeyName(const transform::PrivateKey& key, const Name& identity,
186 const KeyParams& params) const;
187
188private: // pure virtual methods
189 virtual bool
190 doHasKey(const Name& keyName) const = 0;
191
192 virtual unique_ptr<KeyHandle>
193 doGetKeyHandle(const Name& keyName) const = 0;
194
195 virtual unique_ptr<KeyHandle>
196 doCreateKey(const Name& identity, const KeyParams& params) = 0;
197
198 virtual void
199 doDeleteKey(const Name& keyName) = 0;
200
201 virtual ConstBufferPtr
202 doExportKey(const Name& keyName, const char* pw, size_t pwLen) = 0;
203
204 virtual void
205 doImportKey(const Name& keyName, span<const uint8_t> pkcs8, const char* pw, size_t pwLen) = 0;
206
207 virtual void
208 doImportKey(const Name& keyName, shared_ptr<transform::PrivateKey> key) = 0;
209};
210
211} // namespace ndn::security::tpm
212
213#endif // NDN_CXX_SECURITY_TPM_BACK_END_HPP
Base class for key parameters.
Represents an absolute name.
Definition name.hpp:45
Abstract interface for a TPM backend implementation.
Definition back-end.hpp:35
unique_ptr< KeyHandle > createKey(const Name &identityName, const KeyParams &params)
Create a key for identityName according to params.
Definition back-end.cpp:51
void importKey(const Name &keyName, span< const uint8_t > pkcs8, const char *pw, size_t pwLen)
Import a private key in encrypted PKCS #8 format.
Definition back-end.cpp:94
virtual bool isTpmLocked() const
Check if the TPM is locked.
Definition back-end.hpp:151
bool hasKey(const Name &keyName) const
Check if the key with name keyName exists in the TPM.
Definition back-end.cpp:39
Name constructAsymmetricKeyName(const KeyHandle &key, const Name &identity, const KeyParams &params) const
Construct and return the name of a RSA or EC key, based on identity and params.
Definition back-end.cpp:112
void deleteKey(const Name &keyName)
Delete the key with name keyName.
Definition back-end.cpp:79
virtual bool unlockTpm(const char *pw, size_t pwLen) const
Unlock the TPM.
Definition back-end.hpp:168
virtual bool isTerminalMode() const
Check if the TPM is in terminal mode.
Definition back-end.hpp:125
ConstBufferPtr exportKey(const Name &keyName, const char *pw, size_t pwLen)
Get the private key with name keyName in encrypted PKCS #8 format.
Definition back-end.cpp:85
unique_ptr< KeyHandle > getKeyHandle(const Name &keyName) const
Get the handle of the key with name keyName.
Definition back-end.cpp:45
virtual void setTerminalMode(bool isTerminal) const
Set the terminal mode of the TPM.
Definition back-end.hpp:139
Name constructHmacKeyName(const transform::PrivateKey &key, const Name &identity, const KeyParams &params) const
Construct and return the name of a HMAC key, based on identity and params.
Definition back-end.cpp:142
Abstraction of TPM key handle.
Abstraction of a private key in crypto transformations.
std::shared_ptr< const Buffer > ConstBufferPtr
Definition buffer.hpp:140