ndn::security::tpm::BackEnd Class Referenceabstract

Abstract interface for a TPM backend implementation. More...

#include <ndn-cxx/security/tpm/back-end.hpp>

+ Inheritance diagram for ndn::security::tpm::BackEnd:
+ Collaboration diagram for ndn::security::tpm::BackEnd:

Public Types

using Error = Tpm::Error
 

Public Member Functions

virtual ~BackEnd ()
 
unique_ptr< KeyHandlecreateKey (const Name &identityName, const KeyParams &params)
 Create a key for identityName according to params. More...
 
void deleteKey (const Name &keyName)
 Delete the key with name keyName. More...
 
ConstBufferPtr exportKey (const Name &keyName, const char *pw, size_t pwLen)
 Get the private key with name keyName in encrypted PKCS #8 format. More...
 
unique_ptr< KeyHandlegetKeyHandle (const Name &keyName) const
 Get the handle of the key with name keyName. More...
 
bool hasKey (const Name &keyName) const
 Check if the key with name keyName exists in the TPM. More...
 
void importKey (const Name &keyName, shared_ptr< transform::PrivateKey > key)
 Import a private key. More...
 
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. More...
 
virtual bool isTerminalMode () const
 Check if the TPM is in terminal mode. More...
 
virtual bool isTpmLocked () const
 Check if the TPM is locked. More...
 
virtual void setTerminalMode (bool isTerminal) const
 Set the terminal mode of the TPM. More...
 
virtual bool unlockTpm (const char *pw, size_t pwLen) const
 Unlock the TPM. More...
 

Protected Member Functions

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. More...
 
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. More...
 

Detailed Description

Abstract interface for a TPM backend implementation.

This class provides KeyHandle to the front-end and other TPM management operations.

Definition at line 34 of file back-end.hpp.

Member Typedef Documentation

◆ Error

Definition at line 37 of file back-end.hpp.

Constructor & Destructor Documentation

◆ ~BackEnd()

ndn::security::tpm::BackEnd::~BackEnd ( )
virtualdefault

Member Function Documentation

◆ constructAsymmetricKeyName()

Name ndn::security::tpm::BackEnd::constructAsymmetricKeyName ( const KeyHandle key,
const Name identity,
const KeyParams params 
) const
protected

Construct and return the name of a RSA or EC key, based on identity and params.

Definition at line 112 of file back-end.cpp.

◆ constructHmacKeyName()

Name ndn::security::tpm::BackEnd::constructHmacKeyName ( const transform::PrivateKey key,
const Name identity,
const KeyParams params 
) const
protected

Construct and return the name of a HMAC key, based on identity and params.

Definition at line 142 of file back-end.cpp.

◆ createKey()

unique_ptr< KeyHandle > ndn::security::tpm::BackEnd::createKey ( const Name identityName,
const KeyParams params 
)

Create a key for identityName according to params.

Returns
The handle of the created key.
Exceptions
std::invalid_argumentparams are invalid.
ErrorThe key could not be created.

Definition at line 51 of file back-end.cpp.

◆ deleteKey()

void ndn::security::tpm::BackEnd::deleteKey ( const Name keyName)

Delete the key with name keyName.

Warning
Continuing to use existing KeyHandle objects for a deleted key results in undefined behavior.
Exceptions
ErrorThe key could not be deleted.

Definition at line 79 of file back-end.cpp.

◆ exportKey()

ConstBufferPtr ndn::security::tpm::BackEnd::exportKey ( const Name keyName,
const char *  pw,
size_t  pwLen 
)

Get the private key with name keyName in encrypted PKCS #8 format.

Parameters
keyNameThe name of the key.
pwThe password to encrypt the private key.
pwLenThe length of the password.
Returns
The encoded private key.
Exceptions
ErrorThe key does not exist or cannot be exported.

Definition at line 85 of file back-end.cpp.

◆ getKeyHandle()

unique_ptr< KeyHandle > ndn::security::tpm::BackEnd::getKeyHandle ( const Name keyName) const

Get the handle of the key with name keyName.

Calling this function multiple times with the same keyName will return different KeyHandle objects that all refer to the same key.

Returns
The handle of the key, or nullptr if the key does not exist.

Definition at line 45 of file back-end.cpp.

◆ hasKey()

bool ndn::security::tpm::BackEnd::hasKey ( const Name keyName) const

Check if the key with name keyName exists in the TPM.

Returns
True if the key exists, false otherwise.

Definition at line 39 of file back-end.cpp.

◆ importKey() [1/2]

void ndn::security::tpm::BackEnd::importKey ( const Name keyName,
shared_ptr< transform::PrivateKey key 
)

Import a private key.

Exceptions
ErrorThe key could not be imported.

Definition at line 103 of file back-end.cpp.

◆ importKey() [2/2]

void ndn::security::tpm::BackEnd::importKey ( const Name keyName,
span< const uint8_t >  pkcs8,
const char *  pw,
size_t  pwLen 
)

Import a private key in encrypted PKCS #8 format.

Parameters
keyNameThe name of the key to use in the TPM.
pkcs8The key in encrypted PKCS #8 format.
pwThe password to decrypt the private key.
pwLenThe length of the password.
Exceptions
ErrorThe key could not be imported.

Definition at line 94 of file back-end.cpp.

◆ isTerminalMode()

virtual bool ndn::security::tpm::BackEnd::isTerminalMode ( ) const
inlinevirtual

Check if the TPM is in terminal mode.

Deprecated:

The default implementation always returns true.

Definition at line 125 of file back-end.hpp.

◆ isTpmLocked()

virtual bool ndn::security::tpm::BackEnd::isTpmLocked ( ) const
inlinevirtual

Check if the TPM is locked.

Deprecated:

The default implementation always returns false.

Definition at line 151 of file back-end.hpp.

◆ setTerminalMode()

virtual void ndn::security::tpm::BackEnd::setTerminalMode ( bool  isTerminal) const
inlinevirtual

Set the terminal mode of the TPM.

Deprecated:

In terminal mode, the TPM will not ask for a password from the GUI. The default implementation does nothing.

Definition at line 139 of file back-end.hpp.

◆ unlockTpm()

virtual bool ndn::security::tpm::BackEnd::unlockTpm ( const char *  pw,
size_t  pwLen 
) const
inlinevirtual

Unlock the TPM.

Deprecated:

The default implementation does nothing and always returns true.

Parameters
pwThe password to unlock the TPM.
pwLenThe length of the password.
Returns
True if the TPM was unlocked.

Definition at line 168 of file back-end.hpp.