Botan 3.14.1
Crypto and TLS for C&
Botan::Cert_Extension::Subject_Key_ID Class Referencefinal

#include <x509_ext.h>

Inheritance diagram for Botan::Cert_Extension::Subject_Key_ID:
Botan::Certificate_Extension

Public Member Functions

std::unique_ptr< Certificate_Extension > copy () const override
const std::vector< uint8_t > & get_key_id () const
OID oid_of () const override
 Subject_Key_ID ()=default
 Subject_Key_ID (const Public_Key &pub_key)
 Subject_Key_ID (const std::vector< uint8_t > &k)
 Subject_Key_ID (const std::vector< uint8_t > &public_key, std::string_view hash_fn)
virtual void validate (const X509_Certificate &subject, const std::optional< X509_Certificate > &issuer, const std::vector< X509_Certificate > &cert_path, std::vector< std::set< Certificate_Status_Code > > &cert_status, size_t pos) const

Static Public Member Functions

static OID static_oid ()

Detailed Description

Subject Key Identifier Extension

Definition at line 113 of file x509_ext.h.

Constructor & Destructor Documentation

◆ Subject_Key_ID() [1/4]

Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID ( )
default

◆ Subject_Key_ID() [2/4]

Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID ( const std::vector< uint8_t > & k)
inlineexplicit

Definition at line 117 of file x509_ext.h.

117: m_key_id(k) {}

◆ Subject_Key_ID() [3/4]

Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID ( const Public_Key & pub_key)
explicit

Derive the key identifier from the public key, using the first method given in RFC 5280 4.2.1.2:

(1) The keyIdentifier is composed of the 160-bit SHA-1 hash of the value of the BIT STRING subjectPublicKey (excluding the tag, length, and number of unused bits).

Definition at line 561 of file x509_ext.cpp.

561 {
562 /*
563 * RFC 5280 4.2.1.2:
564 * (1) The keyIdentifier is composed of the 160-bit SHA-1 hash of the
565 * value of the BIT STRING subjectPublicKey (excluding the tag, length,
566 * and number of unused bits).
567 */
568 auto hash = HashFunction::create_or_throw("SHA-1");
569
570 m_key_id.resize(hash->output_length());
571
572 hash->update(pub_key.public_key_bits());
573 hash->final(m_key_id.data());
574}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:311

References Botan::HashFunction::create_or_throw(), and Botan::Public_Key::public_key_bits().

◆ Subject_Key_ID() [4/4]

Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID ( const std::vector< uint8_t > & public_key,
std::string_view hash_fn )

Definition at line 579 of file x509_ext.cpp.

579 {
580 auto hash = HashFunction::create_or_throw(hash_name);
581
582 m_key_id.resize(hash->output_length());
583
584 hash->update(pub_key);
585 hash->final(m_key_id.data());
586
587 // Truncate longer hashes, 192 bits here seems plenty
588 const size_t max_skid_len = (192 / 8);
589 if(m_key_id.size() > max_skid_len) {
590 m_key_id.resize(max_skid_len);
591 }
592}

References Botan::HashFunction::create_or_throw().

Member Function Documentation

◆ copy()

std::unique_ptr< Certificate_Extension > Botan::Cert_Extension::Subject_Key_ID::copy ( ) const
inlineoverridevirtual

Make a copy of this extension

Returns
copy of this

Implements Botan::Certificate_Extension.

Definition at line 132 of file x509_ext.h.

132 {
133 return std::make_unique<Subject_Key_ID>(m_key_id);
134 }

References copy().

Referenced by copy().

◆ get_key_id()

const std::vector< uint8_t > & Botan::Cert_Extension::Subject_Key_ID::get_key_id ( ) const
inline

Definition at line 136 of file x509_ext.h.

136{ return m_key_id; }

◆ oid_of()

OID Botan::Cert_Extension::Subject_Key_ID::oid_of ( ) const
inlineoverridevirtual

Return object identifier for this extension

Returns
OID representing this extension

Implements Botan::Certificate_Extension.

Definition at line 140 of file x509_ext.h.

140{ return static_oid(); }

References static_oid().

◆ static_oid()

OID Botan::Cert_Extension::Subject_Key_ID::static_oid ( )
inlinestatic

Definition at line 138 of file x509_ext.h.

138{ return OID({2, 5, 29, 14}); }

Referenced by oid_of().

◆ validate()

void Botan::Certificate_Extension::validate ( const X509_Certificate & subject,
const std::optional< X509_Certificate > & issuer,
const std::vector< X509_Certificate > & cert_path,
std::vector< std::set< Certificate_Status_Code > > & cert_status,
size_t pos ) const
virtualinherited

Callback visited during path validation.

An extension can implement this callback to inspect the path during path validation.

If an error occurs during validation of this extension, an appropriate status code shall be added to cert_status.

Parameters
subjectSubject certificate that contains this extension
issuerIssuer certificate. nullopt for certificates with no available issuer (e.g. non self-signed trust anchors).
cert_pathCertificate path which is currently validated
cert_statusCertificate validation status codes for subject certificate
posPosition of subject certificate in cert_path

Reimplemented in Botan::Cert_Extension::ASBlocks, Botan::Cert_Extension::Certificate_Policies, Botan::Cert_Extension::IPAddressBlocks, Botan::Cert_Extension::Name_Constraints, Botan::Cert_Extension::NoRevocationAvailable, Botan::Cert_Extension::OCSP_NoCheck, Botan::Cert_Extension::TNAuthList, and Botan::Cert_Extension::Unknown_Extension.

Definition at line 171 of file x509_ext.cpp.

175 {}

Referenced by is_appropriate_context().


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