NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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-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_BACK_END_HPP
23 #define NDN_SECURITY_TPM_BACK_END_HPP
24 
26 
27 namespace ndn {
28 namespace security {
29 namespace tpm {
30 
36 class BackEnd : noncopyable
37 {
38 public:
39  using Error = Tpm::Error;
40 
41  virtual
43 
44 public: // key management
50  bool
51  hasKey(const Name& keyName) const;
52 
61  unique_ptr<KeyHandle>
62  getKeyHandle(const Name& keyName) const;
63 
71  unique_ptr<KeyHandle>
72  createKey(const Name& identityName, const KeyParams& params);
73 
82  void
83  deleteKey(const Name& keyName);
84 
96  exportKey(const Name& keyName, const char* pw, size_t pwLen);
97 
109  void
110  importKey(const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Len, const char* pw, size_t pwLen);
111 
117  void
118  importKey(const Name& keyName, shared_ptr<transform::PrivateKey> key);
119 
127  virtual bool
128  isTerminalMode() const;
129 
136  virtual void
137  setTerminalMode(bool isTerminal) const;
138 
146  virtual bool
147  isTpmLocked() const;
148 
159  NDN_CXX_NODISCARD virtual bool
160  unlockTpm(const char* pw, size_t pwLen) const;
161 
162 protected: // helper methods
166  Name
167  constructAsymmetricKeyName(const KeyHandle& key, const Name& identity,
168  const KeyParams& params) const;
169 
173  Name
174  constructHmacKeyName(const transform::PrivateKey& key, const Name& identity,
175  const KeyParams& params) const;
176 
177 private: // pure virtual methods
178  virtual bool
179  doHasKey(const Name& keyName) const = 0;
180 
181  virtual unique_ptr<KeyHandle>
182  doGetKeyHandle(const Name& keyName) const = 0;
183 
184  virtual unique_ptr<KeyHandle>
185  doCreateKey(const Name& identity, const KeyParams& params) = 0;
186 
187  virtual void
188  doDeleteKey(const Name& keyName) = 0;
189 
190  virtual ConstBufferPtr
191  doExportKey(const Name& keyName, const char* pw, size_t pwLen) = 0;
192 
193  virtual void
194  doImportKey(const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Len, const char* pw, size_t pwLen) = 0;
195 
196  virtual void
197  doImportKey(const Name& keyName, shared_ptr<transform::PrivateKey> key) = 0;
198 };
199 
200 } // namespace tpm
201 } // namespace security
202 } // namespace ndn
203 
204 #endif // NDN_SECURITY_TPM_BACK_END_HPP
ndn::security::tpm::Tpm::Error
Definition: tpm.hpp:69
ndn::KeyParams
Base class for key parameters.
Definition: key-params.hpp:36
ndn::security::tpm::BackEnd::~BackEnd
virtual ~BackEnd()
ndn::security::tpm::BackEnd::exportKey
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:87
ndn::security::tpm::BackEnd::constructHmacKeyName
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:144
ndn::security::tpm::BackEnd::setTerminalMode
virtual void setTerminalMode(bool isTerminal) const
Set the terminal mode of the TPM.
Definition: back-end.cpp:157
ndn::security::tpm::BackEnd
Abstract interface for a TPM backend implementation.
Definition: back-end.hpp:37
ndn::security::tpm::BackEnd::createKey
unique_ptr< KeyHandle > createKey(const Name &identityName, const KeyParams &params)
Create a key for identityName according to params.
Definition: back-end.cpp:53
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_CXX_NODISCARD
#define NDN_CXX_NODISCARD
Definition: backports.hpp:68
ndn::security::tpm::BackEnd::getKeyHandle
unique_ptr< KeyHandle > getKeyHandle(const Name &keyName) const
Get the handle of the key with name keyName.
Definition: back-end.cpp:47
ndn::security::tpm::BackEnd::isTpmLocked
virtual bool isTpmLocked() const
Check if the TPM is locked.
Definition: back-end.cpp:162
ndn::security::tpm::BackEnd::unlockTpm
virtual NDN_CXX_NODISCARD bool unlockTpm(const char *pw, size_t pwLen) const
Unlock the TPM.
Definition: back-end.cpp:168
ndn::security::tpm::BackEnd::constructAsymmetricKeyName
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:114
transform::PrivateKey
tpm.hpp
ndn::security::tpm::BackEnd::isTerminalMode
virtual bool isTerminalMode() const
Check if the TPM is in terminal mode.
Definition: back-end.cpp:151
ndn::security::tpm::BackEnd::importKey
void importKey(const Name &keyName, const uint8_t *pkcs8, size_t pkcs8Len, const char *pw, size_t pwLen)
Import a private key in encrypted PKCS #8 format.
Definition: back-end.cpp:96
ndn::security::tpm::BackEnd::hasKey
bool hasKey(const Name &keyName) const
Check if the key with name keyName exists in the TPM.
Definition: back-end.cpp:41
ndn::security::tpm::BackEnd::deleteKey
void deleteKey(const Name &keyName)
Delete the key with name keyName.
Definition: back-end.cpp:81
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