Botan 3.13.0
Crypto and TLS for C&
Botan::OCSP::CertID Class Referencefinal

#include <ocsp.h>

Inheritance diagram for Botan::OCSP::CertID:
Botan::ASN1_Object

Public Member Functions

std::vector< uint8_t > BER_encode () const
 CertID ()=default
 CertID (const X509_Certificate &issuer, const BigInt &subject_serial)
 CertID (const X509_Certificate &issuer, const X509_Serial_Number &subject_serial)
void decode_from (BER_Decoder &from) override
void encode_into (DER_Encoder &to) const override
bool is_id_for (const X509_Certificate &issuer, const X509_Certificate &subject) const
const std::vector< uint8_t > & issuer_key_hash () const

Detailed Description

Definition at line 28 of file ocsp.h.

Constructor & Destructor Documentation

◆ CertID() [1/3]

Botan::OCSP::CertID::CertID ( )
default

References CertID(), decode_from(), encode_into(), and is_id_for().

Referenced by CertID(), and CertID().

◆ CertID() [2/3]

Botan::OCSP::CertID::CertID ( const X509_Certificate & issuer,
const BigInt & subject_serial )

Definition at line 44 of file ocsp.cpp.

44 :
45 CertID(issuer, X509_Serial_Number(subject_serial)) {}

References CertID().

◆ CertID() [3/3]

Botan::OCSP::CertID::CertID ( const X509_Certificate & issuer,
const X509_Serial_Number & subject_serial )

Definition at line 47 of file ocsp.cpp.

47 :
48 m_subject_serial(subject_serial) {
49 /*
50 In practice it seems some responders, including, notably,
51 ocsp.verisign.com, will reject anything but SHA-1 here
52 */
53 auto hash = HashFunction::create_or_throw("SHA-1");
54
55 m_hash_id = AlgorithmIdentifier(hash->name(), AlgorithmIdentifier::USE_NULL_PARAM);
56 m_issuer_key_hash = hash->process<std::vector<uint8_t>>(issuer.subject_public_key_bitstring());
57 m_issuer_dn_hash = hash->process<std::vector<uint8_t>>(issuer.raw_subject_dn());
58}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:308

References Botan::HashFunction::create_or_throw(), Botan::X509_Certificate::raw_subject_dn(), Botan::X509_Certificate::subject_public_key_bitstring(), and Botan::AlgorithmIdentifier::USE_NULL_PARAM.

Member Function Documentation

◆ BER_encode()

std::vector< uint8_t > Botan::ASN1_Object::BER_encode ( ) const
inherited

Return the encoding of this object. This is a convenience method when just one object needs to be serialized. Use DER_Encoder for complicated encodings.

Definition at line 21 of file asn1_obj.cpp.

21 {
22 std::vector<uint8_t> output;
23 DER_Encoder der(output);
24 this->encode_into(der);
25 return output;
26}
virtual void encode_into(DER_Encoder &to) const =0

References encode_into().

Referenced by decode_from(), Botan::PKCS12::export_to(), Botan::Certificate_Store_In_SQL::find_all_certs(), Botan::Certificate_Store_In_SQL::find_cert(), Botan::X509_Certificate::fingerprint(), Botan::Certificate_Store_In_SQL::insert_cert(), Botan::X509_Object::PEM_encode(), and Botan::PSS_Params::PSS_Params().

◆ decode_from()

void Botan::OCSP::CertID::decode_from ( BER_Decoder & from)
overridevirtual

Decode whatever this object is from from

Parameters
fromthe BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 113 of file ocsp.cpp.

113 {
114 /*
115 * RFC 6960 Section 4.1.1
116 *
117 * CertID ::= SEQUENCE {
118 * hashAlgorithm AlgorithmIdentifier,
119 * issuerNameHash OCTET STRING,
120 * issuerKeyHash OCTET STRING,
121 * serialNumber CertificateSerialNumber }
122 */
123 from.start_sequence()
124 .decode(m_hash_id)
125 .decode(m_issuer_dn_hash, ASN1_Type::OctetString)
126 .decode(m_issuer_key_hash, ASN1_Type::OctetString)
127 .decode(m_subject_serial)
128 .end_cons();
129
130 if(!m_hash_id.parameters_are_null_or_empty()) {
131 throw Decoding_Error("OCSP CertID hashAlgorithm has unexpected parameters");
132 }
133}

References Botan::BER_Decoder::decode(), Botan::BER_Decoder::end_cons(), Botan::OctetString, and Botan::BER_Decoder::start_sequence().

Referenced by CertID().

◆ encode_into()

void Botan::OCSP::CertID::encode_into ( DER_Encoder & to) const
overridevirtual

Encode whatever this object is into to

Parameters
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 104 of file ocsp.cpp.

104 {
105 to.start_sequence()
106 .encode(m_hash_id)
107 .encode(m_issuer_dn_hash, ASN1_Type::OctetString)
108 .encode(m_issuer_key_hash, ASN1_Type::OctetString)
109 .encode(m_subject_serial)
110 .end_cons();
111}

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::OctetString, and Botan::DER_Encoder::start_sequence().

Referenced by CertID().

◆ is_id_for()

bool Botan::OCSP::CertID::is_id_for ( const X509_Certificate & issuer,
const X509_Certificate & subject ) const

Definition at line 60 of file ocsp.cpp.

60 {
61 try {
62 if(subject.serial() != m_subject_serial) {
63 return false;
64 }
65
66 const auto hash_algo = m_hash_id.oid().registered_name();
67
68 /*
69 RFC 6960 4.1.1
70 issuerNameHash is the hash of the issuer's distinguished name (DN).
71 The hash shall be calculated over the DER encoding of the issuer's name
72 field in the certificate being checked.
73
74 issuerKeyHash is the hash of the issuer's public key. The hash shall be
75 calculated over the value (excluding tag and length) of the subject public key
76 field in the issuer's certificate.
77 */
78
79 if(hash_algo == "SHA-1") {
80 if(!std::ranges::equal(m_issuer_dn_hash, subject.raw_issuer_dn_sha1())) {
81 return false;
82 }
83 if(!std::ranges::equal(m_issuer_key_hash, issuer.subject_public_key_bitstring_sha1())) {
84 return false;
85 }
86 } else if(hash_algo == "SHA-256") {
87 if(!std::ranges::equal(m_issuer_dn_hash, subject.raw_issuer_dn_sha256())) {
88 return false;
89 }
90 if(!std::ranges::equal(m_issuer_key_hash, issuer.subject_public_key_bitstring_sha256())) {
91 return false;
92 }
93 } else {
94 // Exotic hashes are unlikely to occur in OCSP
95 return false;
96 }
97 } catch(...) {
98 return false;
99 }
100
101 return true;
102}

References Botan::X509_Certificate::raw_issuer_dn_sha1(), Botan::X509_Certificate::raw_issuer_dn_sha256(), Botan::X509_Certificate::serial(), Botan::X509_Certificate::subject_public_key_bitstring_sha1(), and Botan::X509_Certificate::subject_public_key_bitstring_sha256().

Referenced by CertID().

◆ issuer_key_hash()

const std::vector< uint8_t > & Botan::OCSP::CertID::issuer_key_hash ( ) const
inline

Definition at line 42 of file ocsp.h.

42{ return m_issuer_key_hash; }

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