Botan 3.14.1
Crypto and TLS for C&
ocsp.cpp
Go to the documentation of this file.
1/*
2* OCSP
3* (C) 2012,2013 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/ocsp.h>
9
10#include <botan/base64.h>
11#include <botan/ber_dec.h>
12#include <botan/certstor.h>
13#include <botan/der_enc.h>
14#include <botan/hash.h>
15#include <botan/pubkey.h>
16#include <botan/uri.h>
17#include <botan/x509_ext.h>
18#include <botan/x509path.h>
19#include <botan/internal/fmt.h>
20
21#if defined(BOTAN_HAS_HTTP_UTIL)
22 #include <botan/internal/http_util.h>
23#endif
24
25namespace Botan::OCSP {
26
27namespace {
28
29/*
30* RFC 6960 requires producedAt, thisUpdate, nextUpdate, and revocationTime
31* to be encoded as GeneralizedTime. ASN1_Time also accepts UTCTime since that
32* is required for X.509 certificates and CRLs (RFC 5280), so enforce the
33* stricter OCSP requirement at the call site.
34*/
35void check_generalized_time(const ASN1_Time& time, const char* field) {
36 if(time.tagging() != ASN1_Type::GeneralizedTime) {
37 throw Decoding_Error(fmt("OCSP response {} was not encoded as GeneralizedTime", field));
38 }
39}
40
41} // namespace
42
43CertID::CertID(const X509_Certificate& issuer, const BigInt& subject_serial) :
44 CertID(issuer, X509_Serial_Number(subject_serial)) {}
45
46CertID::CertID(const X509_Certificate& issuer, const X509_Serial_Number& subject_serial) :
47 m_subject_serial(subject_serial) {
48 /*
49 In practice it seems some responders, including, notably,
50 ocsp.verisign.com, will reject anything but SHA-1 here
51 */
52 auto hash = HashFunction::create_or_throw("SHA-1");
53
55 m_issuer_key_hash = hash->process<std::vector<uint8_t>>(issuer.subject_public_key_bitstring());
56 m_issuer_dn_hash = hash->process<std::vector<uint8_t>>(issuer.raw_subject_dn());
57}
58
59bool CertID::is_id_for(const X509_Certificate& issuer, const X509_Certificate& subject) const {
60 try {
61 if(subject.serial() != m_subject_serial) {
62 return false;
63 }
64
65 const auto hash_algo = m_hash_id.oid().registered_name();
66
67 /*
68 RFC 6960 4.1.1
69 issuerNameHash is the hash of the issuer's distinguished name (DN).
70 The hash shall be calculated over the DER encoding of the issuer's name
71 field in the certificate being checked.
72
73 issuerKeyHash is the hash of the issuer's public key. The hash shall be
74 calculated over the value (excluding tag and length) of the subject public key
75 field in the issuer's certificate.
76 */
77
78 if(hash_algo == "SHA-1") {
79 if(!std::ranges::equal(m_issuer_dn_hash, subject.raw_issuer_dn_sha1())) {
80 return false;
81 }
82 if(!std::ranges::equal(m_issuer_key_hash, issuer.subject_public_key_bitstring_sha1())) {
83 return false;
84 }
85 } else if(hash_algo == "SHA-256") {
86 if(!std::ranges::equal(m_issuer_dn_hash, subject.raw_issuer_dn_sha256())) {
87 return false;
88 }
89 if(!std::ranges::equal(m_issuer_key_hash, issuer.subject_public_key_bitstring_sha256())) {
90 return false;
91 }
92 } else {
93 // Exotic hashes are unlikely to occur in OCSP
94 return false;
95 }
96 } catch(...) {
97 return false;
98 }
99
100 return true;
101}
102
104 to.start_sequence()
105 .encode(m_hash_id)
106 .encode(m_issuer_dn_hash, ASN1_Type::OctetString)
107 .encode(m_issuer_key_hash, ASN1_Type::OctetString)
108 .encode(m_subject_serial)
109 .end_cons();
110}
111
113 /*
114 * RFC 6960 Section 4.1.1
115 *
116 * CertID ::= SEQUENCE {
117 * hashAlgorithm AlgorithmIdentifier,
118 * issuerNameHash OCTET STRING,
119 * issuerKeyHash OCTET STRING,
120 * serialNumber CertificateSerialNumber }
121 */
122 from.start_sequence()
123 .decode(m_hash_id)
124 .decode(m_issuer_dn_hash, ASN1_Type::OctetString)
125 .decode(m_issuer_key_hash, ASN1_Type::OctetString)
126 .decode(m_subject_serial)
127 .end_cons();
128
129 if(!m_hash_id.parameters_are_null_or_empty()) {
130 throw Decoding_Error("OCSP CertID hashAlgorithm has unexpected parameters");
131 }
132}
133
134//static
136 return SingleResponse(
137 std::move(certid), 0, std::nullopt, std::nullopt, std::move(this_update), std::move(next_update));
138}
139
140//static
142 return SingleResponse(
143 std::move(certid), 2, std::nullopt, std::nullopt, std::move(this_update), std::move(next_update));
144}
145
146//static
149 std::optional<CRL_Code> reason,
152 return SingleResponse(
153 std::move(certid), 1, std::move(revocation_time), reason, std::move(this_update), std::move(next_update));
154}
155
157 size_t cert_status,
158 std::optional<X509_Time> revocation_time,
159 std::optional<CRL_Code> revocation_reason,
160 X509_Time this_update,
161 X509_Time next_update) :
162 m_certid(std::move(certid)),
163 m_cert_status(cert_status),
164 m_thisupdate(std::move(this_update)),
165 m_nextupdate(std::move(next_update)),
166 m_revocation_time(std::move(revocation_time)),
167 m_revocation_reason(revocation_reason) {
168 const auto require_generalized_time = [](const X509_Time& t, const char* field) {
170 throw Invalid_Argument(fmt("OCSP SingleResponse {} must be a GeneralizedTime", field));
171 }
172 };
173
174 require_generalized_time(m_thisupdate, "thisUpdate");
175 if(m_nextupdate.time_is_set()) {
176 require_generalized_time(m_nextupdate, "nextUpdate");
177 }
178 if(m_cert_status == 1) {
179 if(!m_revocation_time.has_value()) {
180 throw Invalid_Argument("Revoked OCSP SingleResponse lacks a revocation time");
181 }
182 require_generalized_time(*m_revocation_time, "revocationTime");
183 }
184}
185
187 // The SingleResponse / CertStatus / RevokedInfo ASN.1 is quoted in
188 // decode_from below
189 to.start_sequence();
190 to.encode(m_certid);
191 if(m_cert_status == 1) {
192 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
193 to.start_cons(ASN1_Type(1), ASN1_Class::ContextSpecific).encode(m_revocation_time.value());
194 if(m_revocation_reason.has_value() && *m_revocation_reason != CRL_Code::Unspecified) {
195 to.start_explicit(0)
196 .encode(static_cast<size_t>(*m_revocation_reason), ASN1_Type::Enumerated, ASN1_Class::Universal)
197 .end_explicit();
198 }
199 to.end_cons();
200 } else {
201 // good [0] / unknown [2], both IMPLICIT NULL
202 const std::span<const uint8_t> empty;
203 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
204 to.add_object(ASN1_Type(m_cert_status), ASN1_Class::ContextSpecific, empty);
205 }
206 to.encode(m_thisupdate);
207 if(m_nextupdate.time_is_set()) {
208 to.start_explicit(0).encode(m_nextupdate).end_explicit();
209 }
210 to.end_cons();
211}
212
214 /*
215 * RFC 6960 Section 4.2.1
216 *
217 * SingleResponse ::= SEQUENCE {
218 * certID CertID,
219 * certStatus CertStatus,
220 * thisUpdate GeneralizedTime,
221 * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
222 * singleExtensions [1] EXPLICIT Extensions OPTIONAL }
223 *
224 * CertStatus ::= CHOICE {
225 * good [0] IMPLICIT NULL,
226 * revoked [1] IMPLICIT RevokedInfo,
227 * unknown [2] IMPLICIT UnknownInfo }
228 *
229 * RevokedInfo ::= SEQUENCE {
230 * revocationTime GeneralizedTime,
231 * revocationReason [0] EXPLICIT CRLReason OPTIONAL }
232 */
234 Extensions extensions;
235
236 auto seq = from.start_sequence();
237 seq.decode(m_certid)
239 .decode(m_thisupdate)
241
242 check_generalized_time(m_thisupdate, "thisUpdate");
243 if(m_nextupdate.time_is_set()) {
244 check_generalized_time(m_nextupdate, "nextUpdate");
245 }
246
247 if(seq.more_items()) {
248 const BER_Object next = seq.get_next_object();
250 BER_Decoder ext_decoder(next, BER_Decoder::Limits::DER());
251 extensions.decode_from(ext_decoder, Extension_Context::OCSP_Response);
252 ext_decoder.verify_end();
253 } else {
254 throw Decoding_Error("Unexpected tag in OCSP SingleResponse");
255 }
256 }
257 seq.end_cons();
258
259 const auto cert_status_class = cert_status.get_class();
260 if(cert_status_class != ASN1_Class::ContextSpecific &&
261 cert_status_class != (ASN1_Class::ContextSpecific | ASN1_Class::Constructed)) {
262 throw Decoding_Error("OCSP::SingleResponse: certStatus has unexpected class tag");
263 }
264
265 m_cert_status = static_cast<uint32_t>(cert_status.type());
266 if(m_cert_status > 2) {
267 throw Decoding_Error("Unknown OCSP CertStatus tag");
268 }
269
270 m_revocation_time.reset();
271 m_revocation_reason.reset();
272
273 if(m_cert_status == 1) {
276 revoked_info.decode(revocation_time);
277 check_generalized_time(revocation_time, "revocationTime");
278 m_revocation_time = std::move(revocation_time);
279
281 size_t reason = 0;
283 if(reason == 7 || reason > 10) {
284 throw Decoding_Error(fmt("CRLReason has unknown enumeration value {}", reason));
285 }
286 m_revocation_reason = static_cast<CRL_Code>(reason);
287 }
288 revoked_info.verify_end();
289 } else if(cert_status.length() != 0) {
290 // good [0] / unknown [2] are both IMPLICIT NULL
291 throw Decoding_Error("OCSP CertStatus has unexpected content");
292 }
293
294 // We don't currently recognize any extensions here so if any are critical we should reject
295 m_has_unknown_critical_ext = !extensions.critical_extensions().empty();
296}
297
298namespace {
299
300// TODO: should this be in a header somewhere?
301void decode_optional_list(BER_Decoder& ber, ASN1_Type tag, std::vector<X509_Certificate>& output) {
302 const BER_Object obj = ber.get_next_object();
303
305 ber.push_back(obj);
306 return;
307 }
308
310 auto seq = list.start_sequence();
311 while(seq.more_items()) {
312 output.push_back([&] {
313 X509_Certificate cert;
314 cert.decode_from(seq);
315 return cert;
316 }());
317 }
318 seq.end_cons();
319 list.verify_end();
320}
321
322} // namespace
323
324Request::Request(const X509_Certificate& issuer_cert, const X509_Certificate& subject_cert) :
325 m_issuer(issuer_cert), m_certid(m_issuer, subject_cert.serial()) {
326 if(subject_cert.issuer_dn() != issuer_cert.subject_dn()) {
327 throw Invalid_Argument("Invalid cert pair to OCSP::Request (mismatched issuer,subject args?)");
328 }
329}
330
331Request::Request(const X509_Certificate& issuer_cert, const BigInt& subject_serial) :
332 m_issuer(issuer_cert), m_certid(m_issuer, subject_serial) {}
333
334std::vector<uint8_t> Request::BER_encode() const {
335 /*
336 * RFC 6960 Section 4.1.1
337 *
338 * OCSPRequest ::= SEQUENCE {
339 * tbsRequest TBSRequest,
340 * optionalSignature [0] EXPLICIT Signature OPTIONAL }
341 *
342 * TBSRequest ::= SEQUENCE {
343 * version [0] EXPLICIT Version DEFAULT v1,
344 * requestList SEQUENCE OF Request }
345 *
346 * Request ::= SEQUENCE {
347 * reqCert CertID }
348 */
349 std::vector<uint8_t> output;
350 DER_Encoder(output)
354 .encode(static_cast<size_t>(0)) // version #
355 .end_explicit()
358 .encode(m_certid)
359 .end_cons()
360 .end_cons()
361 .end_cons()
362 .end_cons();
363
364 return output;
365}
366
367std::string Request::base64_encode() const {
369}
370
373
374Response::Response(const uint8_t response_bits[], size_t response_bits_len) :
375 m_response_bits(response_bits, response_bits + response_bits_len) {
376 /*
377 * RFC 6960 Section 4.2.1
378 *
379 * OCSPResponse ::= SEQUENCE {
380 * responseStatus OCSPResponseStatus,
381 * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }
382 *
383 * OCSPResponseStatus ::= ENUMERATED { ... }
384 *
385 * ResponseBytes ::= SEQUENCE {
386 * responseType OBJECT IDENTIFIER,
387 * response OCTET STRING }
388 */
389 BER_Decoder outer_decoder(m_response_bits, BER_Decoder::Limits::DER());
390 BER_Decoder response_outer = outer_decoder.start_sequence();
391
392 size_t resp_status = 0;
393
394 response_outer.decode(resp_status, ASN1_Type::Enumerated, ASN1_Class::Universal);
395
396 /*
397 RFC 6960 4.2.1
398
399 OCSPResponseStatus ::= ENUMERATED {
400 successful (0), -- Response has valid confirmations
401 malformedRequest (1), -- Illegal confirmation request
402 internalError (2), -- Internal error in issuer
403 tryLater (3), -- Try again later
404 -- (4) is not used
405 sigRequired (5), -- Must sign the request
406 unauthorized (6) -- Request unauthorized
407 }
408 */
409 if(resp_status == 4 || resp_status >= 7) {
410 throw Decoding_Error("Unknown OCSPResponseStatus code");
411 }
412
413 m_status = static_cast<Response_Status_Code>(resp_status);
414
415 /*
416 * RFC 6960 4.2.1: "If the value of responseStatus is one of the error
417 * conditions, the responseBytes field is not set."
418 */
419 const bool successful = (m_status == Response_Status_Code::Successful);
420 const bool has_response_bytes = response_outer.more_items();
421
422 if(successful && !has_response_bytes) {
423 throw Decoding_Error("OCSP response with successful status is missing responseBytes");
424 }
425 if(!successful && has_response_bytes) {
426 throw Decoding_Error("OCSP response with non-successful status includes responseBytes");
427 }
428
429 if(successful) {
430 BER_Decoder response_bytes_ctx = response_outer.start_context_specific(0);
431 BER_Decoder response_bytes = response_bytes_ctx.start_sequence();
432
433 response_bytes.decode_and_check(OID::from_string("PKIX.OCSP.BasicResponse"),
434 "Unknown response type in OCSP response");
435
436 /*
437 * RFC 6960 Section 4.2.1
438 *
439 * BasicOCSPResponse ::= SEQUENCE {
440 * tbsResponseData ResponseData,
441 * signatureAlgorithm AlgorithmIdentifier,
442 * signature BIT STRING,
443 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
444 */
445 BER_Decoder basic_response_decoder(response_bytes.get_next_octet_string(), BER_Decoder::Limits::DER());
446 BER_Decoder basicresponse = basic_response_decoder.start_sequence();
447
448 basicresponse.start_sequence()
449 .raw_bytes(m_tbs_bits)
450 .end_cons()
451 .decode(m_sig_algo)
452 .decode_octet_aligned_bitstring(m_signature);
453 decode_optional_list(basicresponse, ASN1_Type(0), m_certs);
454
455 basicresponse.verify_end();
456 basic_response_decoder.verify_end();
457
458 /*
459 * RFC 6960 Section 4.2.1
460 *
461 * ResponseData ::= SEQUENCE {
462 * version [0] EXPLICIT Version DEFAULT v1,
463 * responderID ResponderID,
464 * producedAt GeneralizedTime,
465 * responses SEQUENCE OF SingleResponse,
466 * responseExtensions [1] EXPLICIT Extensions OPTIONAL }
467 *
468 * ResponderID ::= CHOICE {
469 * byName [1] Name,
470 * byKey [2] KeyHash }
471 */
472 size_t responsedata_version = 0;
473 Extensions extensions;
474
475 BER_Decoder tbs_decoder(m_tbs_bits, BER_Decoder::Limits::DER());
476 tbs_decoder
478
480
483
484 .decode(m_produced_at)
485
486 .decode_list(m_responses);
487
488 check_generalized_time(m_produced_at, "producedAt");
489
490 if(tbs_decoder.more_items()) {
491 const BER_Object next = tbs_decoder.get_next_object();
493 BER_Decoder ext_decoder(next, BER_Decoder::Limits::DER());
494 extensions.decode_from(ext_decoder, Extension_Context::OCSP_Response);
495 ext_decoder.verify_end();
496 } else {
497 throw Decoding_Error("Unexpected tag in OCSP ResponseData");
498 }
499 }
500 tbs_decoder.verify_end();
501
502 const bool has_signer = !m_signer_name.empty();
503 const bool has_key_hash = !m_key_hash.empty();
504
505 if(has_signer && has_key_hash) {
506 throw Decoding_Error("OCSP response includes both byName and byKey in responderID field");
507 }
508 if(!has_signer && !has_key_hash) {
509 throw Decoding_Error("OCSP response contains neither byName nor byKey in responderID field");
510 }
511 if(has_key_hash && m_key_hash.size() != 20) {
512 // KeyHash ::= OCTET STRING -- SHA-1 hash of responder's public key
513 throw Decoding_Error("OCSP response contains a byKey with invalid length");
514 }
515
516 response_bytes.verify_end();
517 response_bytes_ctx.verify_end();
518
519 // We don't currently recognize any extensions here so if any are critical we should reject
520 m_has_unknown_critical_ext = !extensions.critical_extensions().empty();
521 }
522
523 response_outer.verify_end();
524 outer_decoder.verify_end();
525
526 if(m_has_unknown_critical_ext == false) {
527 // Check all of the SingleResponse extensions
528 for(const auto& sr : m_responses) {
529 if(sr.has_unknown_critical_extension()) {
530 m_has_unknown_critical_ext = true;
531 break;
532 }
533 }
534 }
535}
536
537bool Response::is_issued_by(const X509_Certificate& candidate) const {
538 if(!m_signer_name.empty()) {
539 return (candidate.subject_dn() == m_signer_name);
540 }
541
542 if(!m_key_hash.empty()) {
543 return (candidate.subject_public_key_bitstring_sha1() == m_key_hash);
544 }
545
546 return false;
547}
548
550 const Path_Validation_Restrictions restrictions;
551
552 return this->verify_signature(issuer, restrictions);
553}
554
556 const Path_Validation_Restrictions& restrictions) const {
557 if(m_dummy_response_status) {
558 return m_dummy_response_status.value();
559 }
560
561 if(m_signer_name.empty() && m_key_hash.empty()) {
563 }
564
565 if(!is_issued_by(issuer)) {
567 }
568
569 try {
570 auto pub_key = issuer.subject_public_key();
571
572 PK_Verifier verifier(*pub_key, m_sig_algo);
573 verifier.update(ASN1::der_sequence_header(m_tbs_bits.size()));
574 verifier.update(m_tbs_bits);
575 const bool valid_signature = verifier.check_signature(m_signature);
576
577 if(valid_signature == false) {
579 }
580
581 if(m_has_unknown_critical_ext) {
583 }
584
585 const auto& trusted_hashes = restrictions.trusted_hashes();
586 if(!trusted_hashes.empty() && !trusted_hashes.contains(verifier.hash_function())) {
588 }
589
590 if(pub_key->estimated_strength() < restrictions.minimum_key_strength()) {
592 }
593
595 } catch(Exception&) {
597 }
598}
599
600std::optional<X509_Certificate> Response::find_signing_certificate(
601 const X509_Certificate& issuer_certificate, const Certificate_Store* trusted_ocsp_responders) const {
602 using namespace std::placeholders;
603
604 // Check whether the CA issuing the certificate in question also signed this
605 if(is_issued_by(issuer_certificate)) {
606 return issuer_certificate;
607 }
608
609 // Then try to find a delegated responder certificate in the stapled certs
610 for(const auto& cert : m_certs) {
611 if(this->is_issued_by(cert)) {
612 return cert;
613 }
614 }
615
616 // Last resort: check the additionally provides trusted OCSP responders
617 if(trusted_ocsp_responders != nullptr) {
618 if(!m_key_hash.empty()) {
619 auto signing_cert = trusted_ocsp_responders->find_cert_by_pubkey_sha1(m_key_hash);
620 if(signing_cert) {
621 return signing_cert;
622 }
623 }
624
625 if(!m_signer_name.empty()) {
626 auto signing_cert = trusted_ocsp_responders->find_cert(m_signer_name, {});
627 if(signing_cert) {
628 return signing_cert;
629 }
630 }
631 }
632
633 return std::nullopt;
634}
635
637 const X509_Certificate& subject,
638 std::chrono::system_clock::time_point ref_time,
639 std::chrono::seconds max_age) const {
640 if(m_dummy_response_status) {
641 return m_dummy_response_status.value();
642 }
643
644 for(const auto& response : m_responses) {
645 if(response.certid().is_id_for(issuer, subject)) {
646 const X509_Time x509_ref_time(ref_time);
647
648 /*
649 * We check certificate status prior to checking expiration, since otherwise it's
650 * possible to take an OCSP response indicating revocation, wait for it to expire,
651 * and then staple it. If such a response was reported as "expired" rather than
652 * "revoked" it's easy to dismiss as a clock issue or other misconfiguration.
653 */
654
655 if(response.cert_status() == 1) {
657 }
658
659 try {
660 if(response.this_update() > x509_ref_time) {
662 }
663
664 if(response.next_update().time_is_set()) {
665 if(x509_ref_time > response.next_update()) {
667 }
668 } else if(max_age > std::chrono::seconds::zero() &&
669 ref_time - response.this_update().to_std_timepoint() > max_age) {
671 }
672 } catch(Exception&) {
673 // This can occur if eg the OCSP time is not representable by the system clock
675 }
676
677 if(response.cert_status() == 0) {
679 } else {
681 }
682 }
683 }
684
686}
687
688#if defined(BOTAN_HAS_HTTP_UTIL)
689
690Response online_check(const X509_Certificate& issuer,
691 const BigInt& subject_serial,
692 std::string_view ocsp_responder,
693 std::chrono::milliseconds timeout) {
694 if(ocsp_responder.empty()) {
695 throw Invalid_Argument("No OCSP responder specified");
696 }
697
698 if(auto uri = URI::from_string(ocsp_responder)) {
699 return online_check(issuer, subject_serial, *uri, timeout);
700 } else {
701 throw Invalid_Argument("Unparsable URI for OCSP responder");
702 }
703}
704
705Response online_check(const X509_Certificate& issuer,
706 const BigInt& subject_serial,
707 const URI& ocsp_responder,
708 std::chrono::milliseconds timeout) {
709 const OCSP::Request req(issuer, subject_serial);
710
711 const auto http = HTTP::POST_sync(ocsp_responder,
712 "application/ocsp-request",
713 req.BER_encode(),
714 HTTP::RequestLimits().set_timeout(timeout).set_max_body_size(64 * 1024));
715
716 http.throw_unless_ok();
717
718 // Check the MIME type?
719
720 return OCSP::Response(http.body());
721}
722
723Response online_check(const X509_Certificate& issuer,
724 const X509_Certificate& subject,
725 std::chrono::milliseconds timeout) {
726 if(subject.issuer_dn() != issuer.subject_dn()) {
727 throw Invalid_Argument("Invalid cert pair to OCSP::online_check (mismatched issuer,subject args?)");
728 }
729
730 const auto responders = URI::filter_scheme("http", subject.ocsp_responder_uris());
731
732 if(responders.empty()) {
733 throw Invalid_Argument("No HTTP OCSP responder URLs available for this certificate");
734 }
735
736 const auto subject_serial = subject.serial().to_bigint();
737
738 // Try the first N - 1 responder addresses in sequence, ignoring errors
739 for(size_t i = 0; i + 1 < responders.size(); ++i) {
740 try {
741 return online_check(issuer, subject_serial, responders[i], timeout);
742 } catch(...) {}
743 }
744
745 // Now try the final responder and let any errors propagate
746 return online_check(issuer, subject_serial, responders.back(), timeout);
747}
748
749#endif
750
751} // namespace Botan::OCSP
ASN1_Type tagging() const
Return the tag (UtcTime or GeneralizedTime) this time was encoded with.
Definition asn1_time.h:36
bool time_is_set() const
Return if the time has been set somehow.
static Limits DER()
Definition ber_dec.h:44
BER_Decoder & raw_bytes(T &out_wrapped)
Definition ber_dec.h:343
BER_Decoder & decode_optional_string(T &out_wrapped, ASN1_Type real_type, uint32_t expected_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
Definition ber_dec.h:719
const BER_Object & peek_next_object()
Definition ber_dec.cpp:510
void push_back(const BER_Object &obj)
Definition ber_dec.cpp:605
BER_Object get_next_object()
Definition ber_dec.cpp:521
BER_Decoder & decode(bool &out)
Definition ber_dec.h:361
bool more_items() const
Definition ber_dec.cpp:461
std::vector< uint8_t > get_next_octet_string()
Definition ber_dec.h:376
BER_Decoder & verify_end()
Definition ber_dec.cpp:471
BER_Decoder & end_cons()
Definition ber_dec.cpp:635
BER_Decoder start_sequence()
Definition ber_dec.h:279
BER_Decoder start_context_specific(uint32_t tag)
Definition ber_dec.h:294
BER_Decoder & decode_octet_aligned_bitstring(T &out_wrapped, ASN1_Type type_tag=ASN1_Type::BitString, ASN1_Class class_tag=ASN1_Class::Universal)
Definition ber_dec.h:458
BER_Decoder & decode_optional(T &out, ASN1_Type type_tag, ASN1_Class class_tag, const T &default_value=T())
Definition ber_dec.h:550
BER_Decoder & decode_and_check(const T &expected, std::string_view error_msg)
Definition ber_dec.h:698
BER_Decoder & get_next(BER_Object &ber)
Definition ber_dec.h:214
BER_Decoder & decode_list(std::vector< T > &vec, ASN1_Type type_tag=ASN1_Type::Sequence, ASN1_Class class_tag=ASN1_Class::Universal)
Definition ber_dec.h:895
bool is_a(ASN1_Type type_tag, ASN1_Class class_tag) const
Definition asn1_obj.cpp:97
virtual std::optional< X509_Certificate > find_cert_by_pubkey_sha1(const std::vector< uint8_t > &key_hash) const =0
virtual std::optional< X509_Certificate > find_cert(const X509_DN &subject_dn, const std::vector< uint8_t > &key_id) const
Definition certstor.cpp:38
DER_Encoder & add_object(ASN1_Type type_tag, ASN1_Class class_tag, const uint8_t rep[], size_t length)
Definition der_enc.cpp:285
DER_Encoder & end_explicit()
Definition der_enc.cpp:230
DER_Encoder & start_explicit(uint16_t type_tag)
Definition der_enc.cpp:223
DER_Encoder & start_sequence()
Definition der_enc.h:86
DER_Encoder & start_cons(ASN1_Type type_tag, ASN1_Class class_tag)
Definition der_enc.cpp:192
DER_Encoder & end_cons()
Definition der_enc.cpp:208
DER_Encoder & encode(bool b)
Definition der_enc.cpp:313
std::vector< OID > critical_extensions() const
Definition x509_ext.cpp:118
void decode_from(BER_Decoder &from) override
Definition x509_ext.cpp:312
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:311
void decode_from(BER_Decoder &from) override
Definition ocsp.cpp:112
void encode_into(DER_Encoder &to) const override
Definition ocsp.cpp:103
bool is_id_for(const X509_Certificate &issuer, const X509_Certificate &subject) const
Definition ocsp.cpp:59
std::string base64_encode() const
Definition ocsp.cpp:367
Request(const X509_Certificate &issuer_cert, const X509_Certificate &subject_cert)
Definition ocsp.cpp:324
std::vector< uint8_t > BER_encode() const
Definition ocsp.cpp:334
BOTAN_FUTURE_EXPLICIT Response(Certificate_Status_Code status)
Definition ocsp.cpp:371
Certificate_Status_Code status_for(const X509_Certificate &issuer, const X509_Certificate &subject, std::chrono::system_clock::time_point ref_time=std::chrono::system_clock::now(), std::chrono::seconds max_age=std::chrono::seconds::zero()) const
Definition ocsp.cpp:636
Response_Status_Code status() const
Definition ocsp.h:240
std::optional< X509_Certificate > find_signing_certificate(const X509_Certificate &issuer_certificate, const Certificate_Store *trusted_ocsp_responders=nullptr) const
Definition ocsp.cpp:600
Certificate_Status_Code verify_signature(const X509_Certificate &signing_certificate) const
Definition ocsp.cpp:549
const std::optional< X509_Time > & revocation_time() const
The revocationTime; set only when cert_status() is 1 (revoked).
Definition ocsp.h:81
const CertID & certid() const
Definition ocsp.h:72
static SingleResponse unknown(CertID certid, X509_Time this_update, X509_Time next_update)
As good(), but asserting an unknown status.
Definition ocsp.cpp:141
const X509_Time & next_update() const
Definition ocsp.h:78
static SingleResponse revoked(CertID certid, X509_Time revocation_time, std::optional< CRL_Code > reason, X509_Time this_update, X509_Time next_update)
As good(), but asserting a revoked status with the given RevokedInfo.
Definition ocsp.cpp:147
static SingleResponse good(CertID certid, X509_Time this_update, X509_Time next_update)
Definition ocsp.cpp:135
void decode_from(BER_Decoder &from) override
Definition ocsp.cpp:213
const X509_Time & this_update() const
Definition ocsp.h:76
size_t cert_status() const
Definition ocsp.h:74
void encode_into(DER_Encoder &to) const override
Definition ocsp.cpp:186
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80
void update(uint8_t in)
Definition pubkey.h:378
std::string hash_function() const
Definition pubkey.cpp:490
bool check_signature(const uint8_t sig[], size_t length)
Definition pubkey.cpp:541
const std::set< std::string > & trusted_hashes() const
Definition x509path.h:134
static std::optional< URI > from_string(std::string_view raw)
Definition uri.cpp:163
static std::vector< URI > filter_scheme(std::string_view scheme, std::span< const URI > uris)
Definition uri.cpp:366
const X509_DN & subject_dn() const
Definition x509cert.cpp:458
const X509_Serial_Number & serial() const
Definition x509cert.cpp:442
const std::vector< uint8_t > & raw_subject_dn() const
Definition x509cert.cpp:466
std::span< const uint8_t, 32 > subject_public_key_bitstring_sha256() const
Definition x509cert.cpp:426
const std::vector< uint8_t > & subject_public_key_bitstring_sha1() const
Definition x509cert.cpp:418
const X509_DN & issuer_dn() const
Definition x509cert.cpp:454
const std::vector< uint8_t > & raw_issuer_dn_sha256() const
Definition x509cert.cpp:768
const std::vector< uint8_t > & subject_public_key_bitstring() const
Definition x509cert.cpp:414
std::unique_ptr< Public_Key > subject_public_key() const
Definition x509cert.cpp:756
std::span< const uint8_t, 20 > raw_issuer_dn_sha1() const
Definition x509cert.cpp:782
bool empty() const
Definition pkix_types.h:202
void decode_from(BER_Decoder &from) override
Definition x509_obj.cpp:93
std::vector< uint8_t > der_sequence_header(size_t contents_len)
Definition der_enc.cpp:71
Response POST_sync(const URI &uri, std::string_view content_type, const std::vector< uint8_t > &body, const RequestLimits &limits)
Response_Status_Code
Definition ocsp.h:158
ASN1_Time X509_Time
Definition asn1_obj.h:27
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
ASN1_Type
Definition asn1_obj.h:47
Certificate_Status_Code
Definition pkix_enums.h:21
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition base64.cpp:167