ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
Loading...
Searching...
No Matches
ndn::Certificate Class Reference

NDN Certificate. More...

#include <ndn/certificate.hpp>

Public Member Functions

 Certificate ()=default
 Default constructor.
 
Error toData (Data &data) const
 Convert the Certificate to a Data packet.
 
Error encode (uint8_t *buf, size_t bufSize, size_t &encodedLen) const
 Encode the Certificate to TLV wire format.
 
Error buildName (Name &name) const
 Build the full certificate name and store it in a Name.
 
bool isValidAt (std::string_view timestamp) const
 Check if the certificate is valid at a given time.
 
Identity Name
const NameidentityName () const
 Get the identity name.
 
CertificatesetIdentityName (const Name &name)
 Set the identity name.
 
Error setIdentityName (std::string_view uri)
 Set the identity name from a URI string.
 
Key ID
const uint8_t * keyId () const
 Get the Key ID.
 
size_t keyIdSize () const
 Get the Key ID size.
 
Error setKeyId (const uint8_t *id, size_t len)
 Set the Key ID.
 
Issuer ID
const uint8_t * issuerId () const
 Get the Issuer ID.
 
size_t issuerIdSize () const
 Get the Issuer ID size.
 
Error setIssuerId (const uint8_t *id, size_t len)
 Set the Issuer ID (bytes)
 
Error setIssuerId (std::string_view id)
 Set the Issuer ID (string)
 
Version
uint64_t version () const
 Get the version.
 
CertificatesetVersion (uint64_t version)
 Set the version.
 
Public Key
const uint8_t * publicKey () const
 Get the public key.
 
size_t publicKeySize () const
 Get the public key size.
 
Error setPublicKey (const uint8_t *key, size_t len)
 Set the public key.
 
Validity Period
const ValidityPeriodvalidity () const
 Get the validity period (const)
 
ValidityPeriodvalidity ()
 Get the validity period.
 
CertificatesetValidity (const ValidityPeriod &validity)
 Set the validity period.
 
Signature
SignatureType signatureType () const
 Get the signature type.
 
CertificatesetSignatureType (SignatureType type)
 Set the signature type.
 
Error signWithDigestSha256 ()
 Sign with DigestSha256.
 
Error signWithHmac (const uint8_t *key, size_t keyLen)
 Sign with HMAC-SHA256.
 
bool verifyDigestSha256 () const
 Verify a DigestSha256 signature.
 
bool verifyHmac (const uint8_t *key, size_t keyLen) const
 Verify an HMAC-SHA256 signature.
 

Static Public Member Functions

static Result< CertificatefromData (const Data &data)
 Create a Certificate from a Data packet.
 
static Result< CertificatefromWire (const uint8_t *buf, size_t len)
 Decode a Certificate from TLV wire format.
 

Detailed Description

NDN Certificate.

A class representing an NDN certificate. A certificate is a special Data packet with ContentType=KEY, Content=public key (DER format), and a ValidityPeriod in the SignatureInfo.

Certificate name format: /<IdentityName>/KEY/<KeyId>/<IssuerId>/<Version>

cert.setIdentityName("/example/user");
cert.setKeyId(keyIdBytes, 8);
cert.setIssuerId("self");
cert.setVersion(1);
cert.setPublicKey(derEncodedKey, keyLen);
cert.validity().setNotBefore(2024, 1, 1, 0, 0, 0);
cert.validity().setNotAfter(2025, 12, 31, 23, 59, 59);
// Self-sign
// Encode as Data packet
uint8_t buf[512];
size_t len;
cert.encode(buf, sizeof(buf), len);
NDN Certificate.
Certificate & setVersion(uint64_t version)
Set the version.
Error setIssuerId(const uint8_t *id, size_t len)
Set the Issuer ID (bytes)
Error signWithDigestSha256()
Sign with DigestSha256.
Error setKeyId(const uint8_t *id, size_t len)
Set the Key ID.
Certificate & setIdentityName(const Name &name)
Set the identity name.
Error encode(uint8_t *buf, size_t bufSize, size_t &encodedLen) const
Encode the Certificate to TLV wire format.
Error setPublicKey(const uint8_t *key, size_t len)
Set the public key.
const ValidityPeriod & validity() const
Get the validity period (const)
Error setNotAfter(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
Set the NotAfter time from date/time components.
Error setNotBefore(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
Set the NotBefore time from date/time components.

Definition at line 185 of file certificate.hpp.

Member Function Documentation

◆ buildName()

Error ndn::Certificate::buildName ( Name name) const

Build the full certificate name and store it in a Name.

/<IdentityName>/KEY/<KeyId>/<IssuerId>/<Version>

Parameters
nameOutput Name
Returns
Error::Success on success

Definition at line 454 of file certificate.cpp.

References ndn::Name::appendComponent(), ndn::Name::component(), and ndn::Name::componentCount().

Referenced by toData().

◆ encode()

Error ndn::Certificate::encode ( uint8_t *  buf,
size_t  bufSize,
size_t &  encodedLen 
) const

Encode the Certificate to TLV wire format.

Parameters
bufOutput buffer
bufSizeBuffer size
encodedLenStores the number of encoded bytes
Returns
Error::Success on success

Definition at line 347 of file certificate.cpp.

References ndn::tlv::Data, ndn::PACKET_MAX_SIZE, ndn::tlv::SignatureValue, ndn::TlvEncoder::size(), ndn::varNumberSize(), ndn::TlvEncoder::writeBytes(), ndn::TlvEncoder::writeLength(), ndn::TlvEncoder::writeTlv(), and ndn::TlvEncoder::writeType().

◆ fromData()

◆ fromWire()

Result< Certificate > ndn::Certificate::fromWire ( const uint8_t *  buf,
size_t  len 
)
static

Decode a Certificate from TLV wire format.

Parameters
bufInput buffer
lenBuffer length
Returns
Certificate on success, error on failure

Definition at line 309 of file certificate.cpp.

References fromData(), and ndn::Data::fromWire().

◆ identityName()

const Name & ndn::Certificate::identityName ( ) const
inline

Get the identity name.

Returns
Identity name

Definition at line 235 of file certificate.hpp.

Referenced by fromData().

◆ issuerId()

const uint8_t * ndn::Certificate::issuerId ( ) const
inline

Get the Issuer ID.

Returns
Pointer to Issuer ID bytes

Definition at line 285 of file certificate.hpp.

◆ issuerIdSize()

size_t ndn::Certificate::issuerIdSize ( ) const
inline

Get the Issuer ID size.

Returns
Issuer ID size in bytes

Definition at line 291 of file certificate.hpp.

◆ isValidAt()

bool ndn::Certificate::isValidAt ( std::string_view  timestamp) const

Check if the certificate is valid at a given time.

Parameters
timestampISO 8601 format time (YYYYMMDDThhmmss)
Returns
true if valid

Definition at line 663 of file certificate.cpp.

References ndn::ValidityPeriod::isValidAt().

◆ keyId()

const uint8_t * ndn::Certificate::keyId ( ) const
inline

Get the Key ID.

Returns
Pointer to Key ID bytes

Definition at line 260 of file certificate.hpp.

◆ keyIdSize()

size_t ndn::Certificate::keyIdSize ( ) const
inline

Get the Key ID size.

Returns
Key ID size in bytes

Definition at line 266 of file certificate.hpp.

◆ publicKey()

const uint8_t * ndn::Certificate::publicKey ( ) const
inline

Get the public key.

Returns
Pointer to the DER-encoded public key

Definition at line 335 of file certificate.hpp.

◆ publicKeySize()

size_t ndn::Certificate::publicKeySize ( ) const
inline

Get the public key size.

Returns
Public key size in bytes

Definition at line 341 of file certificate.hpp.

◆ setIdentityName() [1/2]

Certificate & ndn::Certificate::setIdentityName ( const Name name)

Set the identity name.

Parameters
nameIdentity name
Returns
Reference to this Certificate

Definition at line 394 of file certificate.cpp.

◆ setIdentityName() [2/2]

Error ndn::Certificate::setIdentityName ( std::string_view  uri)

Set the identity name from a URI string.

Parameters
uriURI string
Returns
Error::Success on success

Definition at line 399 of file certificate.cpp.

References ndn::Name::fromUri().

◆ setIssuerId() [1/2]

Error ndn::Certificate::setIssuerId ( const uint8_t *  id,
size_t  len 
)

Set the Issuer ID (bytes)

Parameters
idIssuer ID bytes
lenSize in bytes
Returns
Error::Success on success

Definition at line 417 of file certificate.cpp.

Referenced by setIssuerId().

◆ setIssuerId() [2/2]

Error ndn::Certificate::setIssuerId ( std::string_view  id)

Set the Issuer ID (string)

Parameters
idIssuer ID string
Returns
Error::Success on success

Definition at line 426 of file certificate.cpp.

References setIssuerId().

◆ setKeyId()

Error ndn::Certificate::setKeyId ( const uint8_t *  id,
size_t  len 
)

Set the Key ID.

Parameters
idKey ID bytes
lenSize in bytes
Returns
Error::Success on success

Definition at line 408 of file certificate.cpp.

◆ setPublicKey()

Error ndn::Certificate::setPublicKey ( const uint8_t *  key,
size_t  len 
)

Set the public key.

Parameters
keyDER-encoded public key
lenSize in bytes
Returns
Error::Success on success

Definition at line 435 of file certificate.cpp.

References ndn::CERTIFICATE_MAX_KEY_SIZE.

◆ setSignatureType()

Certificate & ndn::Certificate::setSignatureType ( SignatureType  type)

Set the signature type.

Definition at line 449 of file certificate.cpp.

◆ setValidity()

Certificate & ndn::Certificate::setValidity ( const ValidityPeriod validity)

Set the validity period.

Parameters
validityValidity period
Returns
Reference to this Certificate

Definition at line 444 of file certificate.cpp.

References validity().

◆ setVersion()

Certificate & ndn::Certificate::setVersion ( uint64_t  version)

Set the version.

Parameters
versionVersion number
Returns
Reference to this Certificate

Definition at line 430 of file certificate.cpp.

References version().

◆ signatureType()

SignatureType ndn::Certificate::signatureType ( ) const
inline

Get the signature type.

Definition at line 383 of file certificate.hpp.

◆ signWithDigestSha256()

Error ndn::Certificate::signWithDigestSha256 ( )

Sign with DigestSha256.

Returns
Error::Success on success

Definition at line 574 of file certificate.cpp.

References ndn::PACKET_MAX_SIZE, and ndn::SHA256_DIGEST_SIZE.

◆ signWithHmac()

Error ndn::Certificate::signWithHmac ( const uint8_t *  key,
size_t  keyLen 
)

Sign with HMAC-SHA256.

Parameters
keyKey data
keyLenKey length
Returns
Error::Success on success

Definition at line 593 of file certificate.cpp.

References ndn::HMAC_SHA256_SIZE, and ndn::PACKET_MAX_SIZE.

◆ toData()

Error ndn::Certificate::toData ( Data data) const

Convert the Certificate to a Data packet.

Parameters
dataOutput Data packet
Returns
Error::Success on success

Definition at line 319 of file certificate.cpp.

References buildName(), ndn::Data::setContent(), ndn::Data::setContentType(), ndn::Data::setFreshnessPeriod(), ndn::Data::setName(), and ndn::Data::setSignatureType().

◆ validity() [1/2]

ValidityPeriod & ndn::Certificate::validity ( )
inline

Get the validity period.

Returns
Reference to the validity period

Definition at line 366 of file certificate.hpp.

◆ validity() [2/2]

const ValidityPeriod & ndn::Certificate::validity ( ) const
inline

Get the validity period (const)

Returns
Reference to the validity period

Definition at line 360 of file certificate.hpp.

Referenced by setValidity().

◆ verifyDigestSha256()

bool ndn::Certificate::verifyDigestSha256 ( ) const

Verify a DigestSha256 signature.

Returns
true if the signature is valid

Definition at line 616 of file certificate.cpp.

References ndn::PACKET_MAX_SIZE, and ndn::SHA256_DIGEST_SIZE.

◆ verifyHmac()

bool ndn::Certificate::verifyHmac ( const uint8_t *  key,
size_t  keyLen 
) const

Verify an HMAC-SHA256 signature.

Parameters
keyKey data
keyLenKey length
Returns
true if the signature is valid

Definition at line 638 of file certificate.cpp.

References ndn::HMAC_SHA256_SIZE, and ndn::PACKET_MAX_SIZE.

◆ version()

uint64_t ndn::Certificate::version ( ) const
inline

Get the version.

Returns
Version number

Definition at line 317 of file certificate.hpp.

Referenced by fromData(), and setVersion().


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