NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
ndn::security::SecTpmFile Class Reference

#include <sec-tpm-file.hpp>

Inheritance diagram for ndn::security::SecTpmFile:
Collaboration diagram for ndn::security::SecTpmFile:

Classes

class  Error
 

Public Member Functions

 SecTpmFile (const std::string &dir="")
 
virtual ~SecTpmFile ()
 
virtual void setTpmPassword (const uint8_t *password, size_t passwordLength)
 set password of TPM More...
 
virtual void resetTpmPassword ()
 reset password of TPM More...
 
virtual void setInTerminal (bool inTerminal)
 Set inTerminal flag to inTerminal. More...
 
virtual bool getInTerminal () const
 Get value of inTerminal flag. More...
 
virtual bool isLocked ()
 Check if TPM is locked. More...
 
virtual bool unlockTpm (const char *password, size_t passwordLength, bool usePassword)
 Unlock the TPM. More...
 
virtual void generateKeyPairInTpm (const Name &keyName, const KeyParams &params)
 Generate a pair of asymmetric keys. More...
 
virtual void deleteKeyPairInTpm (const Name &keyName)
 Delete a key pair of asymmetric keys. More...
 
virtual shared_ptr< v1::PublicKeygetPublicKeyFromTpm (const Name &keyName)
 Get a public key. More...
 
virtual Block signInTpm (const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm)
 Sign data. More...
 
virtual ConstBufferPtr decryptInTpm (const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
 Decrypt data. More...
 
virtual ConstBufferPtr encryptInTpm (const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
 Encrypt data. More...
 
virtual void generateSymmetricKeyInTpm (const Name &keyName, const KeyParams &params)
 Generate a symmetric key. More...
 
virtual bool doesKeyExistInTpm (const Name &keyName, KeyClass keyClass)
 Check if a particular key exists. More...
 
virtual bool generateRandomBlock (uint8_t *res, size_t size)
 Generate a random block. More...
 
virtual void addAppToAcl (const Name &keyName, KeyClass keyClass, const std::string &appPath, AclType acl)
 Add the application into the ACL of a particular key. More...
 
- Public Member Functions inherited from ndn::security::SecTpm
 SecTpm (const std::string &location)
 
virtual ~SecTpm ()
 
std::string getTpmLocator ()
 
ConstBufferPtr exportPrivateKeyPkcs5FromTpm (const Name &keyName, const std::string &password)
 Export a private key in PKCS#5 format. More...
 
bool importPrivateKeyPkcs5IntoTpm (const Name &keyName, const uint8_t *buffer, size_t bufferSize, const std::string &password)
 Import a private key in PKCS#5 formatted buffer of size bufferSize. More...
 

Static Public Attributes

static const std::string SCHEME
 

Protected Member Functions

virtual std::string getScheme ()
 
virtual ConstBufferPtr exportPrivateKeyPkcs8FromTpm (const Name &keyName)
 Export a private key in PKCS#8 format. More...
 
virtual bool importPrivateKeyPkcs8IntoTpm (const Name &keyName, const uint8_t *buf, size_t size)
 Import a private key from PKCS#8 formatted buffer of size bufferSize. More...
 
virtual bool importPublicKeyPkcs1IntoTpm (const Name &keyName, const uint8_t *buf, size_t size)
 Import a public key in PKCS#1 formatted buffer of size bufferSize. More...
 
- Protected Member Functions inherited from ndn::security::SecTpm
virtual bool getImpExpPassWord (std::string &password, const std::string &prompt)
 Get import/export password. More...
 

Additional Inherited Members

- Protected Attributes inherited from ndn::security::SecTpm
std::string m_location
 

Detailed Description

Definition at line 36 of file sec-tpm-file.hpp.

Constructor & Destructor Documentation

◆ SecTpmFile()

ndn::security::SecTpmFile::SecTpmFile ( const std::string &  dir = "")
explicit

Definition at line 115 of file sec-tpm-file.cpp.

Referenced by ndn::security::SecTpmFile::Error::Error().

◆ ~SecTpmFile()

ndn::security::SecTpmFile::~SecTpmFile ( )
virtual

Definition at line 122 of file sec-tpm-file.cpp.

Referenced by ndn::security::SecTpmFile::Error::Error().

Member Function Documentation

◆ setTpmPassword()

virtual void ndn::security::SecTpmFile::setTpmPassword ( const uint8_t *  password,
size_t  passwordLength 
)
inlinevirtual

set password of TPM

Password is used to unlock TPM when it is locked. You should be cautious when using this method, because remembering password is kind of dangerous.

Parameters
passwordThe password
passwordLengthThe length of password

Implements ndn::security::SecTpm.

Definition at line 56 of file sec-tpm-file.hpp.

◆ resetTpmPassword()

virtual void ndn::security::SecTpmFile::resetTpmPassword ( )
inlinevirtual

reset password of TPM

Implements ndn::security::SecTpm.

Definition at line 61 of file sec-tpm-file.hpp.

◆ setInTerminal()

virtual void ndn::security::SecTpmFile::setInTerminal ( bool  inTerminal)
inlinevirtual

Set inTerminal flag to inTerminal.

If the inTerminal flag is set, and password is not set, TPM may ask for password via terminal. inTerminal flag is set by default.

Implements ndn::security::SecTpm.

Definition at line 66 of file sec-tpm-file.hpp.

◆ getInTerminal()

virtual bool ndn::security::SecTpmFile::getInTerminal ( ) const
inlinevirtual

Get value of inTerminal flag.

Implements ndn::security::SecTpm.

Definition at line 72 of file sec-tpm-file.hpp.

◆ isLocked()

virtual bool ndn::security::SecTpmFile::isLocked ( )
inlinevirtual

Check if TPM is locked.

Implements ndn::security::SecTpm.

Definition at line 78 of file sec-tpm-file.hpp.

Referenced by unlockTpm().

◆ unlockTpm()

virtual bool ndn::security::SecTpmFile::unlockTpm ( const char *  password,
size_t  passwordLength,
bool  usePassword 
)
inlinevirtual

Unlock the TPM.

Parameters
passwordThe password.
passwordLengthThe password size. 0 indicates no password.
usePasswordTrue if we want to use the supplied password to unlock the TPM.
Returns
true if TPM is unlocked, otherwise false.

Implements ndn::security::SecTpm.

Definition at line 84 of file sec-tpm-file.hpp.

References decryptInTpm(), deleteKeyPairInTpm(), doesKeyExistInTpm(), encryptInTpm(), generateKeyPairInTpm(), generateRandomBlock(), generateSymmetricKeyInTpm(), getPublicKeyFromTpm(), isLocked(), and signInTpm().

◆ generateKeyPairInTpm()

void ndn::security::SecTpmFile::generateKeyPairInTpm ( const Name keyName,
const KeyParams params 
)
virtual

Generate a pair of asymmetric keys.

Parameters
keyNameThe name of the key pair.
paramsThe parameters of key.
Exceptions
SecTpm::Errorif fails.

Implements ndn::security::SecTpm.

Definition at line 127 of file sec-tpm-file.cpp.

References doesKeyExistInTpm(), ndn::EC, ndn::SimplePublicKeyParams< KeyParamsInfo >::getKeySize(), ndn::KeyParams::getKeyType(), ndn::PRIVATE, ndn::PUBLIC, ndn::RSA, and ndn::Name::toUri().

Referenced by unlockTpm().

◆ deleteKeyPairInTpm()

void ndn::security::SecTpmFile::deleteKeyPairInTpm ( const Name keyName)
virtual

Delete a key pair of asymmetric keys.

Parameters
keyNameThe name of the key pair.

Implements ndn::security::SecTpm.

Definition at line 223 of file sec-tpm-file.cpp.

References ndn::Name::toUri().

Referenced by unlockTpm().

◆ getPublicKeyFromTpm()

shared_ptr< v1::PublicKey > ndn::security::SecTpmFile::getPublicKeyFromTpm ( const Name keyName)
virtual

Get a public key.

Parameters
keyNameThe public key name.
Returns
The public key.
Exceptions
SecTpm::Errorif public key does not exist in TPM.

Implements ndn::security::SecTpm.

Definition at line 236 of file sec-tpm-file.cpp.

References doesKeyExistInTpm(), ndn::PUBLIC, and ndn::Name::toUri().

Referenced by signInTpm(), and unlockTpm().

◆ signInTpm()

Block ndn::security::SecTpmFile::signInTpm ( const uint8_t *  data,
size_t  dataLength,
const Name keyName,
DigestAlgorithm  digestAlgorithm 
)
virtual

Sign data.

Parameters
dataPointer to the byte array to be signed.
dataLengthThe length of data.
keyNameThe name of the signing key.
digestAlgorithmthe digest algorithm.
Returns
The signature block.
Exceptions
SecTpm::Errorif signing fails.

Implements ndn::security::SecTpm.

Definition at line 311 of file sec-tpm-file.cpp.

References ndn::OBufferStream::buf(), doesKeyExistInTpm(), ndn::EC, ndn::security::file, getPublicKeyFromTpm(), ndn::PRIVATE, ndn::RSA, ndn::SHA256, ndn::tlv::SignatureValue, and ndn::Name::toUri().

Referenced by unlockTpm().

◆ decryptInTpm()

ConstBufferPtr ndn::security::SecTpmFile::decryptInTpm ( const uint8_t *  data,
size_t  dataLength,
const Name keyName,
bool  isSymmetric 
)
virtual

Decrypt data.

Parameters
dataPointer to the byte arry to be decrypted.
dataLengthThe length of data.
keyNameThe name of the decrypting key.
isSymmetricIf true symmetric encryption is used, otherwise asymmetric encryption.
Returns
The decrypted data.
Exceptions
SecTpm::Errorif decryption fails.

Implements ndn::security::SecTpm.

Definition at line 402 of file sec-tpm-file.cpp.

Referenced by unlockTpm().

◆ encryptInTpm()

ConstBufferPtr ndn::security::SecTpmFile::encryptInTpm ( const uint8_t *  data,
size_t  dataLength,
const Name keyName,
bool  isSymmetric 
)
virtual

Encrypt data.

Parameters
dataPointer to the byte arry to be decrypted.
dataLengthThe length of data.
keyNameThe name of the encrypting key.
isSymmetricIf true symmetric encryption is used, otherwise asymmetric encryption.
Returns
The encrypted data.
Exceptions
SecTpm::Errorif encryption fails.

Implements ndn::security::SecTpm.

Definition at line 465 of file sec-tpm-file.cpp.

Referenced by unlockTpm().

◆ generateSymmetricKeyInTpm()

void ndn::security::SecTpmFile::generateSymmetricKeyInTpm ( const Name keyName,
const KeyParams params 
)
virtual

Generate a symmetric key.

Parameters
keyNameThe name of the key.
paramsThe parameter of the key.
Exceptions
SecTpm::Errorif key generating fails.

Implements ndn::security::SecTpm.

Definition at line 527 of file sec-tpm-file.cpp.

Referenced by unlockTpm().

◆ doesKeyExistInTpm()

bool ndn::security::SecTpmFile::doesKeyExistInTpm ( const Name keyName,
KeyClass  keyClass 
)
virtual

Check if a particular key exists.

Parameters
keyNameThe name of the key.
keyClassThe class of the key, e.g. KeyClass::PUBLIC, KeyClass::PRIVATE.
Returns
True if the key exists, otherwise false.

Implements ndn::security::SecTpm.

Definition at line 562 of file sec-tpm-file.cpp.

References ndn::PRIVATE, ndn::PUBLIC, ndn::SYMMETRIC, and ndn::Name::toUri().

Referenced by generateKeyPairInTpm(), getPublicKeyFromTpm(), signInTpm(), and unlockTpm().

◆ generateRandomBlock()

bool ndn::security::SecTpmFile::generateRandomBlock ( uint8_t *  res,
size_t  size 
)
virtual

Generate a random block.

Parameters
resThe pointer to the generated block
sizeThe random block size
Returns
true for success, otherwise false

Implements ndn::security::SecTpm.

Definition at line 578 of file sec-tpm-file.cpp.

Referenced by unlockTpm().

◆ addAppToAcl()

virtual void ndn::security::SecTpmFile::addAppToAcl ( const Name keyName,
KeyClass  keyClass,
const std::string &  appPath,
AclType  acl 
)
inlinevirtual

Add the application into the ACL of a particular key.

Parameters
keyNamethe name of key
keyClassthe class of key, e.g. Private Key
appPaththe absolute path to the application
aclthe new acl of the key

Implements ndn::security::SecTpm.

Definition at line 118 of file sec-tpm-file.hpp.

References exportPrivateKeyPkcs8FromTpm(), getScheme(), importPrivateKeyPkcs8IntoTpm(), and importPublicKeyPkcs1IntoTpm().

◆ getScheme()

std::string ndn::security::SecTpmFile::getScheme ( )
protectedvirtual

Implements ndn::security::SecTpm.

Definition at line 259 of file sec-tpm-file.cpp.

References SCHEME.

Referenced by addAppToAcl().

◆ exportPrivateKeyPkcs8FromTpm()

ConstBufferPtr ndn::security::SecTpmFile::exportPrivateKeyPkcs8FromTpm ( const Name keyName)
protectedvirtual

Export a private key in PKCS#8 format.

Parameters
keyNameThe private key name.
Returns
The private key info (in PKCS#8 format) if exist, otherwise a NULL pointer.

Implements ndn::security::SecTpm.

Definition at line 265 of file sec-tpm-file.cpp.

References ndn::OBufferStream::buf(), and ndn::Name::toUri().

Referenced by addAppToAcl().

◆ importPrivateKeyPkcs8IntoTpm()

bool ndn::security::SecTpmFile::importPrivateKeyPkcs8IntoTpm ( const Name keyName,
const uint8_t *  buffer,
size_t  bufferSize 
)
protectedvirtual

Import a private key from PKCS#8 formatted buffer of size bufferSize.

Parameters
keyNameThe private key name.
bufferPointer to the first byte of the buffer containing PKCS#8-encoded private key info
bufferSizeSize of the buffer
Returns
false if import fails

Implements ndn::security::SecTpm.

Definition at line 275 of file sec-tpm-file.cpp.

References ndn::Name::toUri().

Referenced by addAppToAcl().

◆ importPublicKeyPkcs1IntoTpm()

bool ndn::security::SecTpmFile::importPublicKeyPkcs1IntoTpm ( const Name keyName,
const uint8_t *  buffer,
size_t  bufferSize 
)
protectedvirtual

Import a public key in PKCS#1 formatted buffer of size bufferSize.

Parameters
keyNameThe public key name
bufferPointer to the first byte of the buffer containing PKCS#1-encoded private key info
bufferSizeSize of the buffer
Returns
false if import fails

Implements ndn::security::SecTpm.

Definition at line 293 of file sec-tpm-file.cpp.

References ndn::Name::toUri().

Referenced by addAppToAcl().

Member Data Documentation

◆ SCHEME

const std::string ndn::security::SecTpmFile::SCHEME
static

Definition at line 139 of file sec-tpm-file.hpp.

Referenced by getScheme().


The documentation for this class was generated from the following files: