All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ndn::SecTpmMemory Class Referenceabstract

SecTpmMemory implements a simple in-memory TPM. More...

#include <sec-tpm-memory.hpp>

Inheritance diagram for ndn::SecTpmMemory:
[legend]
Collaboration diagram for ndn::SecTpmMemory:
[legend]

Data Structures

class  Error
 
class  RsaPrivateKey
 RsaPrivateKey is a simple class to hold an RSA private key. More...
 

Public Member Functions

virtual ~SecTpmMemory ()
 
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 More...
 
virtual bool getInTerminal ()
 get inTerminal flag More...
 
virtual bool locked ()
 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, KeyType keyType, int keySize)
 Generate a pair of asymmetric keys. More...
 
virtual shared_ptr< PublicKeygetPublicKeyFromTpm (const Name &keyName)
 Get a public key. More...
 
virtual void deleteKeyPairInTpm (const Name &keyName)
 Delete a key pair of asymmetric keys. 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, KeyType keyType, int keySize)
 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...
 
void setKeyPairForKeyName (const Name &keyName, const uint8_t *publicKeyDer, size_t publicKeyDerLength, const uint8_t *privateKeyDer, size_t privateKeyDerLength)
 Set the public and private key for the keyName. More...
 
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 *buf, size_t size, const std::string &password)
 Import a private key in PKCS#5 format. More...
 

Protected Member Functions

virtual ConstBufferPtr exportPrivateKeyPkcs1FromTpm (const Name &keyName)
 
virtual bool importPrivateKeyPkcs1IntoTpm (const Name &keyName, const uint8_t *buf, size_t size)
 
virtual bool importPublicKeyPkcs1IntoTpm (const Name &keyName, const uint8_t *buf, size_t size)
 Import a public key in PKCS#1 format. More...
 
virtual ConstBufferPtr exportPrivateKeyPkcs8FromTpm (const Name &keyName)=0
 Export a private key in PKCS#8 format. More...
 
virtual bool importPrivateKeyPkcs8IntoTpm (const Name &keyName, const uint8_t *buf, size_t size)=0
 Import a private key in PKCS#8 format. More...
 
virtual bool getImpExpPassWord (std::string &password, const std::string &prompt)
 Get import/export password. More...
 

Detailed Description

SecTpmMemory implements a simple in-memory TPM.

You should initialize by calling setKeyPairForKeyName.

Definition at line 23 of file sec-tpm-memory.hpp.

Constructor & Destructor Documentation

ndn::SecTpmMemory::~SecTpmMemory ( )
virtual

Definition at line 51 of file sec-tpm-memory.cpp.

Member Function Documentation

virtual void ndn::SecTpmMemory::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::SecTpm.

Definition at line 106 of file sec-tpm-memory.hpp.

ConstBufferPtr ndn::SecTpmMemory::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::SecTpm.

Definition at line 139 of file sec-tpm-memory.cpp.

void ndn::SecTpmMemory::deleteKeyPairInTpm ( const Name keyName)
virtual

Delete a key pair of asymmetric keys.

Parameters
keyNameThe name of the key pair.

Implements ndn::SecTpm.

Definition at line 72 of file sec-tpm-memory.cpp.

bool ndn::SecTpmMemory::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. KEY_CLASS_PUBLIC, KEY_CLASS_PRIVATE.
Returns
True if the key exists, otherwise false.

Implements ndn::SecTpm.

Definition at line 159 of file sec-tpm-memory.cpp.

ConstBufferPtr ndn::SecTpmMemory::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::SecTpm.

Definition at line 146 of file sec-tpm-memory.cpp.

ConstBufferPtr ndn::SecTpmMemory::exportPrivateKeyPkcs1FromTpm ( const Name keyName)
protectedvirtual

Definition at line 78 of file sec-tpm-memory.cpp.

ConstBufferPtr ndn::SecTpm::exportPrivateKeyPkcs5FromTpm ( const Name keyName,
const std::string &  password 
)
inherited

Export a private key in PKCS#5 format.

Parameters
keyNameThe private key name.
passwordThe password to encrypt the private key.
Returns
The private key info (in PKCS8 format) if exist.
Exceptions
SecTpm::Errorif private key cannot be exported.

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

virtual ConstBufferPtr ndn::SecTpm::exportPrivateKeyPkcs8FromTpm ( const Name keyName)
protectedpure virtualinherited

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.

Implemented in ndn::SecTpmFile, and ndn::SecTpmOsx.

void ndn::SecTpmMemory::generateKeyPairInTpm ( const Name keyName,
KeyType  keyType,
int  keySize 
)
virtual

Generate a pair of asymmetric keys.

Parameters
keyNameThe name of the key pair.
keyTypeThe type of the key pair, e.g. KEY_TYPE_RSA.
keySizeThe size of the key pair.
Exceptions
SecTpm::Errorif fails.

Implements ndn::SecTpm.

Definition at line 66 of file sec-tpm-memory.cpp.

bool ndn::SecTpmMemory::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::SecTpm.

Definition at line 171 of file sec-tpm-memory.cpp.

void ndn::SecTpmMemory::generateSymmetricKeyInTpm ( const Name keyName,
KeyType  keyType,
int  keySize 
)
virtual

Generate a symmetric key.

Parameters
keyNameThe name of the key.
keyTypeThe type of the key, e.g. KEY_TYPE_AES.
keySizeThe size of the key.
Exceptions
SecTpm::Errorif key generating fails.

Implements ndn::SecTpm.

Definition at line 153 of file sec-tpm-memory.cpp.

bool ndn::SecTpm::getImpExpPassWord ( std::string &  password,
const std::string &  prompt 
)
inlineprotectedvirtualinherited

Get import/export password.

Parameters
passwordOn return, the password.
promptPrompt for password, i.e., "Password for key:"
Returns
true if password has been obtained.

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

virtual bool ndn::SecTpmMemory::getInTerminal ( )
inlinevirtual

get inTerminal flag

Returns
inTerminal flag.

Implements ndn::SecTpm.

Definition at line 60 of file sec-tpm-memory.hpp.

shared_ptr< PublicKey > ndn::SecTpmMemory::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::SecTpm.

Definition at line 96 of file sec-tpm-memory.cpp.

bool ndn::SecTpmMemory::importPrivateKeyPkcs1IntoTpm ( const Name keyName,
const uint8_t *  buf,
size_t  size 
)
protectedvirtual

Definition at line 84 of file sec-tpm-memory.cpp.

bool ndn::SecTpm::importPrivateKeyPkcs5IntoTpm ( const Name keyName,
const uint8_t *  buf,
size_t  size,
const std::string &  password 
)
inherited

Import a private key in PKCS#5 format.

Also recover the public key and installed it in TPM.

Parameters
keyNameThe private key name.
keyThe encoded private key info.
passwordThe password to encrypt the private key.
Returns
False if import fails.

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

virtual bool ndn::SecTpm::importPrivateKeyPkcs8IntoTpm ( const Name keyName,
const uint8_t *  buf,
size_t  size 
)
protectedpure virtualinherited

Import a private key in PKCS#8 format.

Parameters
keyNameThe private key name.
keyThe encoded private key info.
Returns
False if import fails.

Implemented in ndn::SecTpmFile, and ndn::SecTpmOsx.

bool ndn::SecTpmMemory::importPublicKeyPkcs1IntoTpm ( const Name keyName,
const uint8_t *  buf,
size_t  size 
)
protectedvirtual

Import a public key in PKCS#1 format.

Parameters
keyNameThe public key name.
keyThe encoded public key info.
Returns
False if import fails.

Implements ndn::SecTpm.

Definition at line 90 of file sec-tpm-memory.cpp.

virtual bool ndn::SecTpmMemory::locked ( )
inlinevirtual

check if TPM is locked.

Returns
true if locked, false otherwise

Implements ndn::SecTpm.

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

virtual void ndn::SecTpmMemory::resetTpmPassword ( )
inlinevirtual

reset password of TPM

Implements ndn::SecTpm.

Definition at line 49 of file sec-tpm-memory.hpp.

virtual void ndn::SecTpmMemory::setInTerminal ( bool  inTerminal)
inlinevirtual

set inTerminal flag

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

Parameters
inTerminal.

Implements ndn::SecTpm.

Definition at line 54 of file sec-tpm-memory.hpp.

void ndn::SecTpmMemory::setKeyPairForKeyName ( const Name keyName,
const uint8_t *  publicKeyDer,
size_t  publicKeyDerLength,
const uint8_t *  privateKeyDer,
size_t  privateKeyDerLength 
)

Set the public and private key for the keyName.

Parameters
keyNameThe key name.
publicKeyDerThe public key DER byte array.
publicKeyDerLengthThe length of publicKeyDer.
privateKeyDerThe private key DER byte array.
privateKeyDerLengthThe length of privateKeyDer.

Definition at line 56 of file sec-tpm-memory.cpp.

virtual void ndn::SecTpmMemory::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::SecTpm.

Definition at line 44 of file sec-tpm-memory.hpp.

Block ndn::SecTpmMemory::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::SecTpm.

Definition at line 105 of file sec-tpm-memory.cpp.

virtual bool ndn::SecTpmMemory::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::SecTpm.

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