Botan 3.12.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)
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 27 of file ocsp.h.

Constructor & Destructor Documentation

◆ CertID() [1/2]

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

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

Referenced by CertID().

◆ CertID() [2/2]

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

Definition at line 25 of file ocsp.cpp.

25 : m_subject_serial(subject_serial) {
26 /*
27 In practice it seems some responders, including, notably,
28 ocsp.verisign.com, will reject anything but SHA-1 here
29 */
30 auto hash = HashFunction::create_or_throw("SHA-1");
31
32 m_hash_id = AlgorithmIdentifier(hash->name(), AlgorithmIdentifier::USE_NULL_PARAM);
33 m_issuer_key_hash = hash->process<std::vector<uint8_t>>(issuer.subject_public_key_bitstring());
34 m_issuer_dn_hash = hash->process<std::vector<uint8_t>>(issuer.raw_subject_dn());
35}
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 20 of file asn1_obj.cpp.

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

References encode_into().

Referenced by decode_from(), 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(), Botan::PSS_Params::PSS_Params(), and Botan::Certificate_Store_In_SQL::revoke_cert().

◆ 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 80 of file ocsp.cpp.

80 {
81 /*
82 * RFC 6960 Section 4.1.1
83 *
84 * CertID ::= SEQUENCE {
85 * hashAlgorithm AlgorithmIdentifier,
86 * issuerNameHash OCTET STRING,
87 * issuerKeyHash OCTET STRING,
88 * serialNumber CertificateSerialNumber }
89 */
90 from.start_sequence()
91 .decode(m_hash_id)
92 .decode(m_issuer_dn_hash, ASN1_Type::OctetString)
93 .decode(m_issuer_key_hash, ASN1_Type::OctetString)
94 .decode(m_subject_serial)
95 .end_cons();
96}

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 71 of file ocsp.cpp.

71 {
72 to.start_sequence()
73 .encode(m_hash_id)
74 .encode(m_issuer_dn_hash, ASN1_Type::OctetString)
75 .encode(m_issuer_key_hash, ASN1_Type::OctetString)
76 .encode(m_subject_serial)
77 .end_cons();
78}

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 37 of file ocsp.cpp.

37 {
38 try {
39 if(BigInt::from_bytes(subject.serial_number()) != m_subject_serial) {
40 return false;
41 }
42
43 const std::string hash_algo = m_hash_id.oid().to_formatted_string();
44
45 if(hash_algo != "SHA-1" && hash_algo != "SHA-256") {
46 return false;
47 }
48
49 auto hash = HashFunction::create_or_throw(hash_algo);
50
51 /*
52 RFC 6960 4.1.1
53 issuerNameHash is the hash of the issuer's distinguished name (DN).
54 The hash shall be calculated over the DER encoding of the issuer's name
55 field in the certificate being checked.
56 */
57 if(m_issuer_dn_hash != hash->process<std::vector<uint8_t>>(subject.raw_issuer_dn())) {
58 return false;
59 }
60
61 if(m_issuer_key_hash != hash->process<std::vector<uint8_t>>(issuer.subject_public_key_bitstring())) {
62 return false;
63 }
64 } catch(...) {
65 return false;
66 }
67
68 return true;
69}
static BigInt from_bytes(std::span< const uint8_t > bytes)
Definition bigint.cpp:83

References Botan::HashFunction::create_or_throw(), Botan::BigInt::from_bytes(), Botan::X509_Certificate::raw_issuer_dn(), Botan::X509_Certificate::serial_number(), and Botan::X509_Certificate::subject_public_key_bitstring().

Referenced by CertID().

◆ issuer_key_hash()

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

Definition at line 39 of file ocsp.h.

39{ return m_issuer_key_hash; }

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