Botan 3.14.1
Crypto and TLS for C&
Botan::PKIX Namespace Reference

Functions

Certificate_Status_Code build_all_certificate_paths (std::vector< std::vector< X509_Certificate > > &cert_paths, const std::vector< Certificate_Store * > &trusted_certstores, const X509_Certificate &end_entity, const std::vector< X509_Certificate > &end_entity_extra, std::optional< size_t > max_paths=std::nullopt)
Certificate_Status_Code build_certificate_path (std::vector< X509_Certificate > &cert_path_out, const std::vector< Certificate_Store * > &trusted_certstores, const X509_Certificate &end_entity, const std::vector< X509_Certificate > &end_entity_extra, std::optional< size_t > max_paths=std::nullopt)
CertificatePathStatusCodes check_chain (const std::vector< X509_Certificate > &cert_path, std::chrono::system_clock::time_point ref_time, std::string_view hostname, Usage_Type usage, const Path_Validation_Restrictions &restrictions)
CertificatePathStatusCodes check_crl (const std::vector< X509_Certificate > &cert_path, const std::vector< Certificate_Store * > &certstores, std::chrono::system_clock::time_point ref_time)
CertificatePathStatusCodes check_crl (const std::vector< X509_Certificate > &cert_path, const std::vector< Certificate_Store * > &certstores, std::chrono::system_clock::time_point ref_time, const Path_Validation_Restrictions &restrictions)
CertificatePathStatusCodes check_crl (const std::vector< X509_Certificate > &cert_path, const std::vector< std::optional< X509_CRL > > &crls, std::chrono::system_clock::time_point ref_time)
CertificatePathStatusCodes check_crl (const std::vector< X509_Certificate > &cert_path, const std::vector< std::optional< X509_CRL > > &crls, std::chrono::system_clock::time_point ref_time, const Path_Validation_Restrictions &restrictions)
CertificatePathStatusCodes check_ocsp (const std::vector< X509_Certificate > &cert_path, const std::vector< std::optional< OCSP::Response > > &ocsp_responses, const std::vector< Certificate_Store * > &certstores, std::chrono::system_clock::time_point ref_time, const Path_Validation_Restrictions &restrictions)
void merge_revocation_status (CertificatePathStatusCodes &chain_status, const CertificatePathStatusCodes &crl_status, const CertificatePathStatusCodes &ocsp_status, const Path_Validation_Restrictions &restrictions)
Certificate_Status_Code overall_status (const CertificatePathStatusCodes &cert_status)

Detailed Description

namespace PKIX holds the building blocks that are called by x509_path_validate. This allows custom validation logic to be written by applications and makes for easier testing, but unless you're positive you know what you're doing you probably want to just call x509_path_validate instead.

Function Documentation

◆ build_all_certificate_paths()

Certificate_Status_Code Botan::PKIX::build_all_certificate_paths ( std::vector< std::vector< X509_Certificate > > & cert_paths,
const std::vector< Certificate_Store * > & trusted_certstores,
const X509_Certificate & end_entity,
const std::vector< X509_Certificate > & end_entity_extra,
std::optional< size_t > max_paths = std::nullopt )

Create all certificate paths by identifying all possible routes from the end-entity certificate to any certificate in the certificate store list. Paths may also end in intermediate or leaf certificates found in the certificate stores.

WARNING: The validity (e.g. signatures or constraints) of the output path IS NOT checked.

Parameters
cert_pathsoutput parameter to be filled with all discovered certificate paths
trusted_certstoreslist of certificate stores that contain trusted certificates
end_entitythe cert to be validated
end_entity_extraoptional list of additional untrusted certs for path building
max_pathsif set, enumerate at most this many paths and return EXCEEDED_SEARCH_LIMITS if more paths exist; if nullopt, unbounded
Returns
result of the path building operation (OK or error)

Definition at line 1095 of file x509path.cpp.

1099 {
1100 if(!cert_paths_out.empty()) {
1101 throw Invalid_Argument("PKIX::build_all_certificate_paths: cert_paths_out must be empty");
1102 }
1103 CertificatePathBuilder builder(
1104 trusted_certstores, end_entity, end_entity_extra, PathBuildingDfsBudget, /*require_self_signed=*/false);
1105
1106 while(auto path = builder.next()) {
1107 BOTAN_ASSERT_NOMSG(path->empty() == false);
1108 if(max_paths.has_value() && cert_paths_out.size() >= max_paths.value()) {
1109 // More paths exist than the caller permitted us to enumerate
1111 }
1112 cert_paths_out.push_back(std::move(*path));
1113 }
1114
1115 if(!cert_paths_out.empty()) {
1116 // Was able to generate at least one potential path
1118 } else {
1119 // Could not construct any potentially valid path...
1120 return builder.error();
1121 }
1122}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
const char * path
Definition ffi_tls.h:139

References BOTAN_ASSERT_NOMSG, Botan::EXCEEDED_SEARCH_LIMITS, Botan::OK, and path.

◆ build_certificate_path()

Certificate_Status_Code Botan::PKIX::build_certificate_path ( std::vector< X509_Certificate > & cert_path_out,
const std::vector< Certificate_Store * > & trusted_certstores,
const X509_Certificate & end_entity,
const std::vector< X509_Certificate > & end_entity_extra,
std::optional< size_t > max_paths = std::nullopt )

Same as build_all_certificate_paths but only outputs a single path. If there are paths ending in self-signed certificates, these are prioritized over paths ending in intermediate or leaf certificates of the certificate store.

WARNING: The validity (e.g. signatures or constraints) of the output path IS NOT checked.

Parameters
cert_path_outoutput parameter, cert_path will be appended to this vector
trusted_certstoreslist of certificate stores that contain trusted certificates
end_entitythe cert to be validated
end_entity_extraoptional list of additional untrusted certs for path building
max_pathsif set, examine at most this many candidate paths; if nullopt, unbounded
Returns
result of the path building operation (OK or error)

Definition at line 1050 of file x509path.cpp.

1054 {
1055 if(max_paths.has_value() && max_paths.value() == 0) {
1057 }
1058
1059 CertificatePathBuilder builder(
1060 trusted_certstores, end_entity, end_entity_extra, PathBuildingDfsBudget, /*require_self_signed=*/false);
1061
1062 std::vector<X509_Certificate> first_path;
1063 size_t paths_examined = 0;
1064
1065 while(auto path = builder.next()) {
1066 BOTAN_ASSERT_NOMSG(path->empty() == false);
1067
1068 if(max_paths.has_value() && paths_examined >= max_paths.value()) {
1069 break;
1070 }
1071 paths_examined += 1;
1072
1073 // Prefer paths ending in self-signed certificates.
1074 if(path->back().is_self_signed()) {
1075 cert_path.insert(cert_path.end(), path->begin(), path->end());
1077 }
1078
1079 // Save the first path for later just in case we find nothing better
1080 if(first_path.empty()) {
1081 first_path = std::move(*path);
1082 }
1083 }
1084
1085 if(!first_path.empty()) {
1086 // We found a path, it's not self-signed but it's as good as can be formed...
1087 cert_path.insert(cert_path.end(), first_path.begin(), first_path.end());
1089 }
1090
1091 // Failed to build any path at all
1092 return builder.error();
1093}

References BOTAN_ASSERT_NOMSG, Botan::EXCEEDED_SEARCH_LIMITS, Botan::OK, and path.

◆ check_chain()

CertificatePathStatusCodes Botan::PKIX::check_chain ( const std::vector< X509_Certificate > & cert_path,
std::chrono::system_clock::time_point ref_time,
std::string_view hostname,
Usage_Type usage,
const Path_Validation_Restrictions & restrictions )

Check the certificate chain, but not any revocation data

Parameters
cert_pathpath built by build_certificate_path with OK result. The first element is the end entity certificate, the last element is the trusted root certificate. The signature on the trusted root is not verified; it is trusted because it was provided as a trust anchor.
ref_timewhatever time you want to perform the validation against (normally current system clock)
hostnamethe hostname
usageend entity usage checks
restrictionsthe relevant path validation restrictions object
Returns
vector of results on per certificate in the path, each containing a set of results. If all codes in the set are < Certificate_Status_Code::FIRST_ERROR_STATUS, then the result for that certificate is successful. If all results are

Definition at line 344 of file x509path.cpp.

348 {
349 if(cert_path.empty()) {
350 throw Invalid_Argument("PKIX::check_chain cert_path empty");
351 }
352
353 const bool is_end_entity_trust_anchor = (cert_path.size() == 1);
354
355 const X509_Time validation_time(ref_time);
356
357 CertificatePathStatusCodes cert_status(cert_path.size());
358
359 // Before anything else verify the entire chain of signatures
360 // starting from the certificate issued by the trust anchor and
361 // working towards the leaf. This precludes denial of service
362 // attacks based on long certificate chains which are valid except
363 // for the final forged (invalid) signature purportedly by the
364 // trust root.
365 //
366 // The trust anchor's own signature is not checked. RFC 5280 6.1.1:
367 // "The trust anchor information is trusted because it was
368 // delivered to the path processing procedure by some trustworthy
369 // out-of-band procedure."
370 for(size_t i = cert_path.size() - 1; i-- > 0;) {
371 std::set<Certificate_Status_Code>& status = cert_status.at(i);
372
373 const X509_Certificate& subject = cert_path[i];
374 const X509_Certificate& issuer = cert_path[i + 1];
375
376 // Check the signature algorithm is known
377 if(!subject.signature_algorithm().oid().registered_oid()) {
379 } else {
380 std::unique_ptr<Public_Key> issuer_key;
381 try {
382 issuer_key = issuer.subject_public_key();
383 } catch(...) {
385 }
386
387 if(issuer_key) {
388 if(issuer_key->estimated_strength() < restrictions.minimum_key_strength()) {
390 }
391
392 const auto sig_status = subject.verify_signature(*issuer_key);
393
394 if(sig_status.first != Certificate_Status_Code::VERIFIED) {
395 status.insert(sig_status.first);
396 } else {
397 // Signature is valid, check if hash used was acceptable
398 const std::string hash_used_for_signature = sig_status.second;
399 BOTAN_ASSERT_NOMSG(!hash_used_for_signature.empty());
400 const auto& trusted_hashes = restrictions.trusted_hashes();
401
402 if(!trusted_hashes.empty() && !trusted_hashes.contains(hash_used_for_signature)) {
404 }
405 }
406 }
407 }
408
409 // If any of the signatures were invalid, return immediately; we know the
410 // chain is invalid and signature failure is always considered the most
411 // critical result. This does mean other problems in the certificate (eg
412 // expired) will not be reported, but we'd have to assume any such data is
413 // anyway arbitrary considering we couldn't verify the signature chain
414 for(const auto s : status) {
415 // This ignores errors relating to the key or hash being weak since
416 // these are somewhat advisory
417 if(static_cast<uint32_t>(s) >= 5000) {
418 return cert_status;
419 }
420 }
421 }
422
423 if(!hostname.empty() && !cert_path[0].matches_dns_name(hostname)) {
424 cert_status[0].insert(Certificate_Status_Code::CERT_NAME_NOMATCH);
425 }
426
427 if(!cert_path[0].allowed_usage(usage)) {
428 if(usage == Usage_Type::OCSP_RESPONDER) {
430 }
431 cert_status[0].insert(Certificate_Status_Code::INVALID_USAGE);
432 }
433
434 if(cert_path[0].has_constraints(Key_Constraints::KeyCertSign) && cert_path[0].is_CA_cert() == false) {
435 /*
436 "If the keyCertSign bit is asserted, then the cA bit in the
437 basic constraints extension (Section 4.2.1.9) MUST also be
438 asserted." - RFC 5280
439
440 We don't bother doing this check on the rest of the path since they
441 must have the cA bit asserted or the validation will fail anyway.
442 */
443 cert_status[0].insert(Certificate_Status_Code::INVALID_USAGE);
444 }
445
446 for(size_t i = 0; i != cert_path.size(); ++i) {
447 std::set<Certificate_Status_Code>& status = cert_status.at(i);
448
449 const bool at_trust_anchor = (i == cert_path.size() - 1);
450
451 const X509_Certificate& subject = cert_path[i];
452 const auto issuer = [&]() -> std::optional<X509_Certificate> {
453 if(!at_trust_anchor) {
454 return cert_path[i + 1];
455 } else if(subject.is_self_signed()) {
456 return cert_path[i];
457 } else {
458 return {}; // Non self-signed trust anchors have no checkable issuers.
459 }
460 }();
461
462 if(restrictions.require_self_signed_trust_anchors() && !issuer.has_value()) {
464 }
465
466 // This should never happen; it indicates a bug in path building
467 if(issuer.has_value() && subject.issuer_dn() != issuer->subject_dn()) {
469 }
470
471 // Check the serial number
472 if(subject.serial().is_negative()) {
474 }
475
476 // Check the subject's DN components' length
477
478 for(const auto& rdn : subject.subject_dn().rdns()) {
479 for(const auto& ava : rdn) {
480 const size_t dn_ub = X509_DN::lookup_ub(ava.first);
481 if(dn_ub > 0 && ava.second.size() > dn_ub) {
483 }
484 }
485 }
486
487 // If so configured, allow trust anchors outside the validity period with
488 // a warning rather than a hard error
489 const bool enforce_validity_period = !at_trust_anchor || !restrictions.ignore_trusted_root_time_range();
490 // Check all certs for valid time range
491 if(validation_time < subject.not_before()) {
492 if(enforce_validity_period) {
494 } else {
495 status.insert(Certificate_Status_Code::TRUSTED_CERT_NOT_YET_VALID); // only warn
496 }
497 }
498
499 if(validation_time > subject.not_after()) {
500 if(enforce_validity_period) {
502 } else {
503 status.insert(Certificate_Status_Code::TRUSTED_CERT_HAS_EXPIRED); // only warn
504 }
505 }
506
507 // Check issuer constraints
508 if(issuer.has_value() && !issuer->is_CA_cert() && !is_end_entity_trust_anchor) {
510 }
511
512 // Check cert extensions
513
514 if(subject.x509_version() == 1) {
515 if(subject.v2_issuer_key_id().empty() == false || subject.v2_subject_key_id().empty() == false) {
517 }
518 }
519
520 const Extensions& extensions = subject.v3_extensions();
521 if(subject.x509_version() < 3 && !extensions.get_extension_oids().empty()) {
523 }
524
525 extensions.validate(subject, issuer, cert_path, cert_status, i);
526 }
527
528 // path len check
529 size_t max_path_length = cert_path.size();
530 for(size_t i = cert_path.size() - 1; i > 0; --i) {
531 std::set<Certificate_Status_Code>& status = cert_status.at(i);
532 const X509_Certificate& subject = cert_path[i];
533
534 /*
535 * If the certificate was not self-issued, verify that max_path_length is
536 * greater than zero and decrement max_path_length by 1.
537 */
538 if(subject.subject_dn() != subject.issuer_dn()) {
539 if(max_path_length > 0) {
540 max_path_length -= 1;
541 } else {
543 }
544 }
545
546 /*
547 * If pathLenConstraint is present in the certificate and is less than max_path_length,
548 * set max_path_length to the value of pathLenConstraint.
549 */
550 if(auto path_len_constraint = subject.path_length_constraint()) {
551 max_path_length = std::min(max_path_length, *path_len_constraint);
552 }
553 }
554
555 return cert_status;
556}
const OID & oid() const
Definition asn1_obj.h:688
bool registered_oid() const
Definition asn1_oid.cpp:153
const std::set< std::string > & trusted_hashes() const
Definition x509path.h:134
bool ignore_trusted_root_time_range() const
Definition x509path.h:165
bool require_self_signed_trust_anchors() const
Definition x509path.h:175
bool is_CA_cert() const
Definition x509cert.cpp:481
const X509_DN & subject_dn() const
Definition x509cert.cpp:458
const X509_DN & issuer_dn() const
Definition x509cert.cpp:454
std::unique_ptr< Public_Key > subject_public_key() const
Definition x509cert.cpp:756
static size_t lookup_ub(const OID &oid)
const AlgorithmIdentifier & signature_algorithm() const
Definition x509_obj.cpp:73
std::pair< Certificate_Status_Code, std::string > verify_signature(const Public_Key &key) const
Definition x509_obj.cpp:130
std::vector< std::set< Certificate_Status_Code > > CertificatePathStatusCodes
Definition x509path.h:29
ASN1_Time X509_Time
Definition asn1_obj.h:27

References BOTAN_ASSERT_NOMSG, Botan::CA_CERT_NOT_FOR_CERT_ISSUER, Botan::CERT_CHAIN_TOO_LONG, Botan::CERT_HAS_EXPIRED, Botan::CERT_NAME_NOMATCH, Botan::CERT_NOT_YET_VALID, Botan::CERT_PUBKEY_INVALID, Botan::CERT_SERIAL_NEGATIVE, Botan::CHAIN_LACKS_TRUST_ROOT, Botan::CHAIN_NAME_MISMATCH, Botan::DN_TOO_LONG, Botan::EXT_IN_V1_V2_CERT, Botan::Extensions::get_extension_oids(), Botan::Path_Validation_Restrictions::ignore_trusted_root_time_range(), Botan::INVALID_USAGE, Botan::X509_Serial_Number::is_negative(), Botan::X509_Certificate::is_self_signed(), Botan::X509_Certificate::issuer_dn(), Botan::Key_Constraints::KeyCertSign, Botan::X509_DN::lookup_ub(), Botan::Path_Validation_Restrictions::minimum_key_strength(), Botan::X509_Certificate::not_after(), Botan::X509_Certificate::not_before(), Botan::OCSP_RESPONDER, Botan::OCSP_RESPONSE_MISSING_KEYUSAGE, Botan::AlgorithmIdentifier::oid(), Botan::X509_Certificate::path_length_constraint(), Botan::X509_DN::rdns(), Botan::OID::registered_oid(), Botan::Path_Validation_Restrictions::require_self_signed_trust_anchors(), Botan::X509_Certificate::serial(), Botan::SIGNATURE_ALGO_UNKNOWN, Botan::X509_Object::signature_algorithm(), Botan::SIGNATURE_METHOD_TOO_WEAK, Botan::X509_Certificate::subject_dn(), Botan::X509_Certificate::subject_public_key(), Botan::TRUSTED_CERT_HAS_EXPIRED, Botan::TRUSTED_CERT_NOT_YET_VALID, Botan::Path_Validation_Restrictions::trusted_hashes(), Botan::UNTRUSTED_HASH, Botan::V2_IDENTIFIERS_IN_V1_CERT, Botan::X509_Certificate::v2_issuer_key_id(), Botan::X509_Certificate::v2_subject_key_id(), Botan::X509_Certificate::v3_extensions(), Botan::Extensions::validate(), Botan::VERIFIED, Botan::X509_Object::verify_signature(), and Botan::X509_Certificate::x509_version().

Referenced by Botan::x509_path_validate().

◆ check_crl() [1/4]

CertificatePathStatusCodes Botan::PKIX::check_crl ( const std::vector< X509_Certificate > & cert_path,
const std::vector< Certificate_Store * > & certstores,
std::chrono::system_clock::time_point ref_time )

Check CRLs for revocation information

Equivalent to calling check_crl with a default Path_Validation_Restrictions

Definition at line 836 of file x509path.cpp.

838 {
839 return PKIX::check_crl(cert_path, certstores, ref_time, Path_Validation_Restrictions());
840}
CertificatePathStatusCodes check_crl(const std::vector< X509_Certificate > &cert_path, const std::vector< std::optional< X509_CRL > > &crls, std::chrono::system_clock::time_point ref_time, const Path_Validation_Restrictions &restrictions)
Definition x509path.cpp:744

References check_crl().

◆ check_crl() [2/4]

CertificatePathStatusCodes Botan::PKIX::check_crl ( const std::vector< X509_Certificate > & cert_path,
const std::vector< Certificate_Store * > & certstores,
std::chrono::system_clock::time_point ref_time,
const Path_Validation_Restrictions & restrictions )

Check CRLs for revocation information

Parameters
cert_pathpath already validated by check_chain
certstoresa list of certificate stores to query for the CRL
ref_timewhatever time you want to perform the validation against (normally current system clock)
restrictionsthe relevant path validation restrictions object
Returns
revocation status

Definition at line 842 of file x509path.cpp.

845 {
846 if(cert_path.empty()) {
847 throw Invalid_Argument("PKIX::check_crl cert_path empty");
848 }
849
850 if(certstores.empty()) {
851 throw Invalid_Argument("PKIX::check_crl certstores empty");
852 }
853
854 std::vector<std::optional<X509_CRL>> crls(cert_path.size());
855
856 for(size_t i = 0; i != cert_path.size(); ++i) {
857 if(cert_path[i].skip_revocation_check()) {
858 continue;
859 }
860 for(const auto* certstore : certstores) {
861 crls[i] = certstore->find_crl_for(cert_path[i]);
862 if(crls[i]) {
863 break;
864 }
865 }
866 }
867
868 return PKIX::check_crl(cert_path, crls, ref_time, restrictions);
869}

References check_crl().

◆ check_crl() [3/4]

CertificatePathStatusCodes Botan::PKIX::check_crl ( const std::vector< X509_Certificate > & cert_path,
const std::vector< std::optional< X509_CRL > > & crls,
std::chrono::system_clock::time_point ref_time )

Check CRLs for revocation information

Equivalent to calling check_crl with a default Path_Validation_Restrictions

Definition at line 738 of file x509path.cpp.

740 {
741 return PKIX::check_crl(cert_path, crls, ref_time, Path_Validation_Restrictions());
742}

References check_crl().

◆ check_crl() [4/4]

CertificatePathStatusCodes Botan::PKIX::check_crl ( const std::vector< X509_Certificate > & cert_path,
const std::vector< std::optional< X509_CRL > > & crls,
std::chrono::system_clock::time_point ref_time,
const Path_Validation_Restrictions & restrictions )

Check CRLs for revocation information

Parameters
cert_pathpath already validated by check_chain
crlsthe list of CRLs to check, it is assumed that crls[i] (if not null) is the associated CRL for the subject in cert_path[i].
ref_timewhatever time you want to perform the validation against (normally current system clock)
restrictionsthe relevant path validation restrictions object
Returns
revocation status

Definition at line 744 of file x509path.cpp.

747 {
748 if(cert_path.empty()) {
749 throw Invalid_Argument("PKIX::check_crl cert_path empty");
750 }
751
752 CertificatePathStatusCodes cert_status(cert_path.size());
753 const X509_Time validation_time(ref_time);
754
755 for(size_t i = 0; i != cert_path.size() - 1; ++i) {
756 std::set<Certificate_Status_Code>& status = cert_status.at(i);
757
758 if(cert_path.at(i).skip_revocation_check()) {
759 continue;
760 }
761
762 if(i < crls.size() && crls[i].has_value()) {
763 const X509_Certificate& subject = cert_path.at(i);
764 const X509_Certificate& ca = cert_path.at(i + 1);
765
766 // RFC 5280 6.3.3 step (b)(2): if the CRL's IDP scope or
767 // distributionPoint name excludes this certificate, do not use it
768 // to determine revocation status. Treat as if no CRL was supplied
769 // so the caller's policy (strict revocation or soft fail) decides
770 // the outcome.
771 const auto applic = crl_applicability_for(*crls[i], subject);
772 if(!applic.usable) {
773 continue;
774 }
775
776 if(!ca.allowed_usage(Key_Constraints::CrlSign)) {
778 }
779
780 if(validation_time < crls[i]->this_update()) {
782 }
783
784 if(crls[i]->next_update().time_is_set() && validation_time > crls[i]->next_update()) {
786 }
787
788 const auto ca_key = ca.subject_public_key();
789 const auto sig_status = crls[i]->verify_signature(*ca_key);
790 const auto& trusted_hashes = restrictions.trusted_hashes();
791
792 if(sig_status.first != Certificate_Status_Code::VERIFIED) {
794 } else if(!trusted_hashes.empty() && !trusted_hashes.contains(sig_status.second)) {
796 } else {
797 /*
798 RFC 5280 5.2 "If a CRL contains a critical extension that the
799 application cannot process, then the application MUST NOT use that
800 CRL to determine the status of certificates."
801
802 RFC 5280 5.3 "If a CRL contains a critical CRL entry extension that
803 the application cannot process, then the application MUST NOT use
804 that CRL to determine the status of any certificates."
805 */
806 const bool crl_is_not_usable = crls[i]->has_unknown_critical_extension();
807
808 if(crl_is_not_usable) {
810 } else if(crls[i]->is_revoked(subject)) {
811 // A reason-limited CRL that lists the cert still proves the
812 // cert is revoked (the cert was revoked for whichever reason
813 // the CRL covers). Surface CERT_IS_REVOKED regardless of
814 // full-coverage status.
816 } else if(applic.full_coverage) {
817 // Cert not listed AND the CRL covers every reason: positive
818 // non-revocation evidence.
820 }
821 // else: cert not listed but CRL only covers some reasons. No
822 // positive evidence is recorded; the caller's policy (strict
823 // revocation -> NO_REVOCATION_DATA, soft fail -> validates)
824 // decides what happens next.
825 }
826 }
827 }
828
829 while(!cert_status.empty() && cert_status.back().empty()) {
830 cert_status.pop_back();
831 }
832
833 return cert_status;
834}

References Botan::X509_Certificate::allowed_usage(), Botan::CA_CERT_NOT_FOR_CRL_ISSUER, Botan::CERT_IS_REVOKED, Botan::CRL_BAD_SIGNATURE, Botan::CRL_HAS_EXPIRED, Botan::CRL_HAS_UNKNOWN_CRITICAL_EXTENSION, Botan::CRL_NOT_YET_VALID, Botan::Key_Constraints::CrlSign, Botan::X509_Certificate::subject_public_key(), Botan::Path_Validation_Restrictions::trusted_hashes(), Botan::UNTRUSTED_HASH, Botan::VALID_CRL_CHECKED, and Botan::VERIFIED.

Referenced by check_crl(), check_crl(), check_crl(), and Botan::x509_path_validate().

◆ check_ocsp()

CertificatePathStatusCodes Botan::PKIX::check_ocsp ( const std::vector< X509_Certificate > & cert_path,
const std::vector< std::optional< OCSP::Response > > & ocsp_responses,
const std::vector< Certificate_Store * > & certstores,
std::chrono::system_clock::time_point ref_time,
const Path_Validation_Restrictions & restrictions )

Check OCSP responses for revocation information

Parameters
cert_pathpath already validated by check_chain
ocsp_responsesthe OCSP responses to consider
certstorestrusted roots
ref_timewhatever time you want to perform the validation against (normally current system clock)
restrictionsthe relevant path validation restrictions object
Returns
revocation status

Definition at line 705 of file x509path.cpp.

709 {
710 if(cert_path.empty()) {
711 throw Invalid_Argument("PKIX::check_ocsp cert_path empty");
712 }
713
714 CertificatePathStatusCodes cert_status(cert_path.size() - 1);
715
716 for(size_t i = 0; i != cert_path.size() - 1; ++i) {
717 const X509_Certificate& subject = cert_path.at(i);
718 const X509_Certificate& ca = cert_path.at(i + 1);
719
720 if(subject.skip_revocation_check()) {
721 continue;
722 }
723
724 if(i < ocsp_responses.size() && ocsp_responses.at(i).has_value() &&
725 ocsp_responses.at(i)->status() == OCSP::Response_Status_Code::Successful) {
726 try {
727 cert_status.at(i) = evaluate_ocsp_response(
728 ocsp_responses.at(i).value(), subject, ca, cert_path, certstores, ref_time, restrictions);
729 } catch(Exception&) {
730 cert_status.at(i).insert(Certificate_Status_Code::OCSP_RESPONSE_INVALID);
731 }
732 }
733 }
734
735 return cert_status;
736}
bool skip_revocation_check() const
Definition x509cert.cpp:450

References Botan::OCSP_RESPONSE_INVALID, Botan::X509_Certificate::skip_revocation_check(), and Botan::OCSP::Successful.

Referenced by Botan::x509_path_validate().

◆ merge_revocation_status()

void Botan::PKIX::merge_revocation_status ( CertificatePathStatusCodes & chain_status,
const CertificatePathStatusCodes & crl_status,
const CertificatePathStatusCodes & ocsp_status,
const Path_Validation_Restrictions & restrictions )

Merge the results from CRL and/or OCSP checks into chain_status

Parameters
chain_statusthe certificate status
crl_statusresults from check_crl
ocsp_statusresults from check_ocsp
restrictionsthe relevant path validation restrictions object

Definition at line 1124 of file x509path.cpp.

1127 {
1128 if(chain_status.empty()) {
1129 throw Invalid_Argument("PKIX::merge_revocation_status chain_status was empty");
1130 }
1131
1132 for(size_t i = 0; i != chain_status.size() - 1; ++i) {
1133 bool had_crl = false;
1134 bool had_ocsp = false;
1135
1136 // RFC 5280 6.3.3 treats revocation status as determined once cert_status
1137 // is not UNREVOKED, so CERT_IS_REVOKED (whether from CRL or OCSP) is
1138 // revocation evidence on a par with VALID_CRL_CHECKED / OCSP_RESPONSE_GOOD;
1139 // omitting it would surface a spurious NO_REVOCATION_DATA alongside the
1140 // revocation, e.g. when a reason-limited CRL lists the cert.
1141 if(i < crl_status.size() && !crl_status[i].empty()) {
1142 for(auto&& code : crl_status[i]) {
1144 had_crl = true;
1145 }
1146 chain_status[i].insert(code);
1147 }
1148 }
1149
1150 if(i < ocsp_status.size() && !ocsp_status[i].empty()) {
1151 for(auto&& code : ocsp_status[i]) {
1152 const bool was_definitive =
1154
1155 const bool was_softfail = code == Certificate_Status_Code::OCSP_NO_REVOCATION_URL ||
1158
1159 const bool accepted_softfail = was_softfail && restrictions.accept_ocsp_softfail();
1160
1161 if(was_definitive || accepted_softfail) {
1162 had_ocsp = true;
1163 }
1164
1165 chain_status[i].insert(code);
1166 }
1167 }
1168
1169 if(had_crl == false && had_ocsp == false) {
1170 if((restrictions.require_revocation_information() && i == 0) ||
1171 (restrictions.ocsp_all_intermediates() && i > 0)) {
1172 chain_status[i].insert(Certificate_Status_Code::NO_REVOCATION_DATA);
1173 }
1174 }
1175 }
1176}
bool require_revocation_information() const
Definition x509path.h:123

References Botan::Path_Validation_Restrictions::accept_ocsp_softfail(), Botan::CERT_IS_REVOKED, Botan::NO_REVOCATION_DATA, Botan::Path_Validation_Restrictions::ocsp_all_intermediates(), Botan::OCSP_NO_HTTP, Botan::OCSP_NO_REVOCATION_URL, Botan::OCSP_RESPONSE_GOOD, Botan::OCSP_SERVER_NOT_AVAILABLE, Botan::Path_Validation_Restrictions::require_revocation_information(), and Botan::VALID_CRL_CHECKED.

Referenced by Botan::x509_path_validate().

◆ overall_status()

Certificate_Status_Code Botan::PKIX::overall_status ( const CertificatePathStatusCodes & cert_status)

Find overall status (OK, error) of a validation

Parameters
cert_statusresult of merge_revocation_status or check_chain

Definition at line 1178 of file x509path.cpp.

1178 {
1179 if(cert_status.empty()) {
1180 throw Invalid_Argument("PKIX::overall_status empty cert status");
1181 }
1182
1184
1185 // take the "worst" error as overall
1186 for(const std::set<Certificate_Status_Code>& s : cert_status) {
1187 if(!s.empty()) {
1188 const auto worst = *s.rbegin();
1189 // Leave informative OCSP/CRL confirmations on cert-level status only
1191 overall_status = worst;
1192 }
1193 }
1194 }
1195 return overall_status;
1196}
Certificate_Status_Code overall_status(const CertificatePathStatusCodes &cert_status)
Certificate_Status_Code
Definition pkix_enums.h:21

References Botan::FIRST_ERROR_STATUS, Botan::OK, and overall_status().

Referenced by overall_status(), and Botan::x509_path_validate().