Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

ocsp_types.cpp
Go to the documentation of this file.
1 /*
2 * OCSP subtypes
3 * (C) 2012 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/ocsp_types.h>
9 #include <botan/der_enc.h>
10 #include <botan/ber_dec.h>
11 #include <botan/x509_ext.h>
12 #include <botan/hash.h>
13 #include <botan/oids.h>
14
15 namespace Botan {
16
17 namespace OCSP {
18
19 CertID::CertID(const X509_Certificate& issuer,
20 const BigInt& subject_serial)
21 {
22 /*
23 In practice it seems some responders, including, notably,
24 ocsp.verisign.com, will reject anything but SHA-1 here
25 */
26 std::unique_ptr<HashFunction> hash(HashFunction::create("SHA-160"));
27
28 m_hash_id = AlgorithmIdentifier(hash->name(), AlgorithmIdentifier::USE_NULL_PARAM);
29 m_issuer_key_hash = unlock(hash->process(issuer.subject_public_key_bitstring()));
30 m_issuer_dn_hash = unlock(hash->process(issuer.raw_subject_dn()));
31 m_subject_serial = subject_serial;
32 }
33
34 bool CertID::is_id_for(const X509_Certificate& issuer,
35 const X509_Certificate& subject) const
36 {
37 try
38 {
39 if(BigInt::decode(subject.serial_number()) != m_subject_serial)
40 return false;
41
42 std::unique_ptr<HashFunction> hash(HashFunction::create(OIDS::lookup(m_hash_id.oid)));
43
44 if(m_issuer_dn_hash != unlock(hash->process(subject.raw_issuer_dn())))
45 return false;
46
47 if(m_issuer_key_hash != unlock(hash->process(issuer.subject_public_key_bitstring())))
48 return false;
49 }
50 catch(...)
51 {
52 return false;
53 }
54
55 return true;
56 }
57
58 void CertID::encode_into(class DER_Encoder& to) const
59 {
60 to.start_cons(SEQUENCE)
61 .encode(m_hash_id)
62 .encode(m_issuer_dn_hash, OCTET_STRING)
63 .encode(m_issuer_key_hash, OCTET_STRING)
64 .encode(m_subject_serial)
65 .end_cons();
66 }
67
68 void CertID::decode_from(class BER_Decoder& from)
69 {
70 from.start_cons(SEQUENCE)
71 .decode(m_hash_id)
72 .decode(m_issuer_dn_hash, OCTET_STRING)
73 .decode(m_issuer_key_hash, OCTET_STRING)
74 .decode(m_subject_serial)
75 .end_cons();
76
77 }
78
79 void SingleResponse::encode_into(class DER_Encoder&) const
80 {
81 throw Not_Implemented("SingleResponse::encode_into");
82 }
83
84 void SingleResponse::decode_from(class BER_Decoder& from)
85 {
86 BER_Object cert_status;
87 Extensions extensions;
88
89 from.start_cons(SEQUENCE)
90 .decode(m_certid)
91 .get_next(cert_status)
92 .decode(m_thisupdate)
93 .decode_optional(m_nextupdate, ASN1_Tag(0),
94 ASN1_Tag(CONTEXT_SPECIFIC | CONSTRUCTED))
95 .decode_optional(extensions,
96 ASN1_Tag(1),
97 ASN1_Tag(CONTEXT_SPECIFIC | CONSTRUCTED))
98 .end_cons();
99
100 m_cert_status = cert_status.type_tag;
101 }
102
103 }
104
105 }
Botan::CONTEXT_SPECIFIC
Definition: asn1_obj.h:25
Botan::BigInt
Definition: bigint.h:23
Botan::X509_Certificate::serial_number
std::vector< uint8_t > serial_number() const
Definition: x509cert.cpp:427
Botan::X509_Certificate::subject_public_key_bitstring
std::vector< uint8_t > subject_public_key_bitstring() const
Definition: x509cert.cpp:226
Botan::OCSP::CertID::CertID
CertID()=default
Botan::OCSP::SingleResponse::encode_into
void encode_into(class DER_Encoder &to) const override
Definition: ocsp_types.cpp:79
Botan::OCSP::CertID::is_id_for
bool is_id_for(const X509_Certificate &issuer, const X509_Certificate &subject) const
Definition: ocsp_types.cpp:34
Botan::Extensions
Definition: x509_ext.h:86
Botan::X509_Certificate::raw_subject_dn
std::vector< uint8_t > raw_subject_dn() const
Definition: x509cert.cpp:454
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:376
Botan::DER_Encoder::end_cons
DER_Encoder & end_cons()
Definition: der_enc.cpp:147
Botan::BER_Decoder::get_next
BER_Decoder & get_next(BER_Object &ber)
Definition: ber_dec.cpp:239
Botan::DER_Encoder::encode
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:216
Botan::BER_Decoder::decode_optional
BER_Decoder & decode_optional(T &out, ASN1_Tag type_tag, ASN1_Tag class_tag, const T &default_value=T())
Definition: ber_dec.h:213
Botan::OCTET_STRING
Definition: asn1_obj.h:35
Botan::DER_Encoder
Definition: der_enc.h:22
Botan::X509_Certificate
Definition: x509cert.h:36
Botan::CONSTRUCTED
Definition: asn1_obj.h:27
Botan::BER_Decoder::end_cons
BER_Decoder & end_cons()
Definition: ber_dec.cpp:272
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:18
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_obj.h:22
Botan::AlgorithmIdentifier::oid
OID oid
Definition: alg_id.h:36
Botan::HashFunction::create
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:93
Botan::SEQUENCE
Definition: asn1_obj.h:39
Botan::BER_Decoder::start_cons
BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: ber_dec.cpp:258
Botan::OCSP::SingleResponse::decode_from
void decode_from(class BER_Decoder &from) override
Definition: ocsp_types.cpp:84
Botan
Definition: alg_id.cpp:13
Botan::OCSP::CertID::encode_into
void encode_into(class DER_Encoder &to) const override
Definition: ocsp_types.cpp:58
Botan::unlock
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:125
Botan::BER_Object::type_tag
ASN1_Tag type_tag
Definition: asn1_obj.h:91
Botan::X509_Certificate::raw_issuer_dn
std::vector< uint8_t > raw_issuer_dn() const
Definition: x509cert.cpp:437
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::DER_Encoder::start_cons
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:137
Botan::Not_Implemented
Definition: exceptn.h:244
Botan::AlgorithmIdentifier::USE_NULL_PARAM
Definition: alg_id.h:23
Botan::BER_Decoder
Definition: ber_dec.h:19
Botan::BER_Object
Definition: asn1_obj.h:85
Botan::OCSP::SingleResponse::cert_status
size_t cert_status() const
Definition: ocsp_types.h:48
hash
MechanismType hash
Definition: p11_mechanism.cpp:63
Botan::BigInt::decode
static BigInt decode(const uint8_t buf[], size_t length, Base base=Binary)
Definition: big_code.cpp:114
Botan::OCSP::CertID::decode_from
void decode_from(class BER_Decoder &from) override
Definition: ocsp_types.cpp:68