Botan 3.13.0
Crypto and TLS for C&
x509_utils.h
Go to the documentation of this file.
1/*
2* (C) 2025 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_X509_UTILS_H_
8#define BOTAN_X509_UTILS_H_
9
10#include <botan/asn1_obj.h>
11#include <algorithm>
12#include <initializer_list>
13#include <optional>
14#include <string_view>
15
16namespace Botan {
17
18class X509_CRL;
20class X509_DN;
21
22inline std::optional<uint32_t> is_sub_element_of(const OID& oid, std::initializer_list<uint32_t> prefix) {
23 const auto& c = oid.get_components();
24
25 if(c.size() != prefix.size() + 1) {
26 return {};
27 }
28
29 if(!std::equal(c.begin(), c.end() - 1, prefix.begin(), prefix.end())) {
30 return {};
31 }
32
33 return c[c.size() - 1];
34}
35
36/*
37* DirectoryName subtree match according to RFC 5280 7.1. The constraint's
38* RDN sequence must be a prefix of the candidate name's RDN sequence.
39*/
40bool x509_dn_subtree_match(const X509_DN& name, const X509_DN& constraint);
41
42/*
43* Combined result of the two has_matching_distribution_point* questions:
44* - `any`: at least one DP (explicit or implicit) name-matches per
45* RFC 5280 6.3.3 (b)(1) and (b)(2)(i).
46* - `any_with_absent_reasons`: also true if a matching DP omits the reasons
47* field (or the match is via the implicit DP, which has no reasons by
48* construction).
49* Sharing a single DP-loop pass between the two predicates keeps their
50* matching rules in sync and avoids re-walking the cert's CDP.
51*/
56
58
59/*
60* Does the wildcard SAN @p pattern have some expansion that falls
61* inside the excluded DNS subtree @p constraint? Used by
62* NameConstraints to check whether a wildcard SAN could resolve to a
63* name inside an excludedSubtrees entry, regardless of whether a TLS
64* client would actually trust the wildcard for that name.
65*
66* @p pattern must contain a single '*' in the leftmost label
67* (DNSName::from_san_string guarantees this for SAN values).
68* @p constraint is the DNS name-constraint value (bare-host or
69* leading-dot form). Both inputs assumed lowercased.
70*/
72bool wildcard_intersects_excluded_dns_subtree(std::string_view pattern, std::string_view constraint);
73
74} // namespace Botan
75
76#endif
#define BOTAN_TEST_API
Definition api.h:41
const std::vector< uint32_t > & get_components() const
Definition asn1_obj.h:530
bool wildcard_intersects_excluded_dns_subtree(std::string_view pattern, std::string_view constraint)
std::optional< uint32_t > is_sub_element_of(const OID &oid, std::initializer_list< uint32_t > prefix)
Definition x509_utils.h:22
bool x509_dn_subtree_match(const X509_DN &name, const X509_DN &constraint)
Definition x509_dn.cpp:358
DistributionPointMatch distribution_point_match(const X509_CRL &crl, const X509_Certificate &cert)
Definition x509_crl.cpp:458