Botan 3.13.0
Crypto and TLS for C&
Botan::Cert_Extension::IPAddressBlocks Class Referencefinal

#include <x509_ext.h>

Inheritance diagram for Botan::Cert_Extension::IPAddressBlocks:
Botan::Certificate_Extension

Classes

class  IPAddress
class  IPAddressChoice
class  IPAddressFamily
class  IPAddressOrRange

Public Types

enum class  Version : uint8_t { IPv4 = 4 , IPv6 = 16 }

Public Member Functions

template<Version V>
void add_address (const std::array< uint8_t, static_cast< size_t >(V)> &address, std::optional< uint8_t > safi=std::nullopt)
 Add a single IP address to this extension (for the specified SAFI, if any).
template<Version V>
void add_address (const std::array< uint8_t, static_cast< std::size_t >(V)> &min, const std::array< uint8_t, static_cast< std::size_t >(V)> &max, std::optional< uint8_t > safi=std::nullopt)
 Add an IP address range to this extension (for the specified SAFI, if any).
const std::vector< IPAddressFamily > & addr_blocks () const
std::unique_ptr< Certificate_Extensioncopy () const override
template<Version V>
void inherit (std::optional< uint8_t > safi=std::nullopt)
 Mark the specified IP version as 'inherit' (for the specified SAFI, if any).
 IPAddressBlocks ()=default
 IPAddressBlocks (const std::vector< IPAddressFamily > &blocks)
OID oid_of () const override
template<Version V>
void restrict (std::optional< uint8_t > safi=std::nullopt)
 Make the extension contain no allowed IP addresses for the specified IP version (and SAFI, if any).
size_t v4_count () const
 The number of IPv4 families contained in the extension.
size_t v6_count () const
 The number of IPv6 families contained in the extension.
void validate (const X509_Certificate &subject, const std::optional< X509_Certificate > &issuer, const std::vector< X509_Certificate > &cert_path, std::vector< std::set< Certificate_Status_Code > > &cert_status, size_t pos) const override

Static Public Member Functions

static OID static_oid ()

Detailed Description

IP Address Blocks Extension

RFC 3779 X.509 Extensions for IP Addr

Definition at line 926 of file x509_ext.h.

Member Enumeration Documentation

◆ Version

Enumerator
IPv4 
IPv6 

Definition at line 928 of file x509_ext.h.

928 : uint8_t {
929 IPv4 = 4,
930 IPv6 = 16,
931 };

Constructor & Destructor Documentation

◆ IPAddressBlocks() [1/2]

Botan::Cert_Extension::IPAddressBlocks::IPAddressBlocks ( )
default

Referenced by validate().

◆ IPAddressBlocks() [2/2]

Botan::Cert_Extension::IPAddressBlocks::IPAddressBlocks ( const std::vector< IPAddressFamily > & blocks)
inlineexplicit

Definition at line 1058 of file x509_ext.h.

1058 : m_ip_addr_blocks(blocks) {
1059 this->sort_and_merge();
1060 }

Member Function Documentation

◆ add_address() [1/2]

template<Version V>
void Botan::Cert_Extension::IPAddressBlocks::add_address ( const std::array< uint8_t, static_cast< size_t >(V)> & address,
std::optional< uint8_t > safi = std::nullopt )
inline

Add a single IP address to this extension (for the specified SAFI, if any).

Definition at line 1076 of file x509_ext.h.

1077 {
1078 add_address<V>(address, address, safi);
1079 }
void add_address(const std::array< uint8_t, static_cast< size_t >(V)> &address, std::optional< uint8_t > safi=std::nullopt)
Add a single IP address to this extension (for the specified SAFI, if any).
Definition x509_ext.h:1076

References add_address().

Referenced by add_address().

◆ add_address() [2/2]

template<Version V>
void Botan::Cert_Extension::IPAddressBlocks::add_address ( const std::array< uint8_t, static_cast< std::size_t >(V)> & min,
const std::array< uint8_t, static_cast< std::size_t >(V)> & max,
std::optional< uint8_t > safi = std::nullopt )
inline

Add an IP address range to this extension (for the specified SAFI, if any).

Definition at line 1083 of file x509_ext.h.

◆ addr_blocks()

const std::vector< IPAddressFamily > & Botan::Cert_Extension::IPAddressBlocks::addr_blocks ( ) const
inline

Definition at line 1106 of file x509_ext.h.

1106{ return m_ip_addr_blocks; }

Referenced by validate().

◆ copy()

std::unique_ptr< Certificate_Extension > Botan::Cert_Extension::IPAddressBlocks::copy ( ) const
inlineoverridevirtual

Make a copy of this extension

Returns
copy of this

Implements Botan::Certificate_Extension.

Definition at line 1062 of file x509_ext.h.

1062{ return std::make_unique<IPAddressBlocks>(*this); }

◆ inherit()

template<Version V>
void Botan::Cert_Extension::IPAddressBlocks::inherit ( std::optional< uint8_t > safi = std::nullopt)
inline

Mark the specified IP version as 'inherit' (for the specified SAFI, if any).

Definition at line 1101 of file x509_ext.h.

1101 {
1102 m_ip_addr_blocks.push_back(IPAddressFamily(IPAddressChoice<V>(), safi));
1103 sort_and_merge();
1104 }

◆ oid_of()

OID Botan::Cert_Extension::IPAddressBlocks::oid_of ( ) const
inlineoverridevirtual

Return object identifier for this extension

Returns
OID representing this extension

Implements Botan::Certificate_Extension.

Definition at line 1066 of file x509_ext.h.

1066{ return static_oid(); }

References static_oid().

◆ restrict()

template<Version V>
void Botan::Cert_Extension::IPAddressBlocks::restrict ( std::optional< uint8_t > safi = std::nullopt)
inline

Make the extension contain no allowed IP addresses for the specified IP version (and SAFI, if any).

Definition at line 1093 of file x509_ext.h.

1093 {
1094 std::vector<IPAddressOrRange<V>> addresses = {};
1095 m_ip_addr_blocks.push_back(IPAddressFamily(IPAddressChoice<V>(addresses), safi));
1096 sort_and_merge();
1097 }

◆ static_oid()

OID Botan::Cert_Extension::IPAddressBlocks::static_oid ( )
inlinestatic

Definition at line 1064 of file x509_ext.h.

1064{ return OID({1, 3, 6, 1, 5, 5, 7, 1, 7}); }

Referenced by oid_of().

◆ v4_count()

size_t Botan::Cert_Extension::IPAddressBlocks::v4_count ( ) const
inline

The number of IPv4 families contained in the extension.

Definition at line 1109 of file x509_ext.h.

1109{ return m_v4_count; }

Referenced by botan_x509_ext_ip_addr_blocks_get_address(), botan_x509_ext_ip_addr_blocks_get_counts(), and botan_x509_ext_ip_addr_blocks_get_family().

◆ v6_count()

size_t Botan::Cert_Extension::IPAddressBlocks::v6_count ( ) const
inline

The number of IPv6 families contained in the extension.

Definition at line 1112 of file x509_ext.h.

1112{ return m_v6_count; }

◆ validate()

void Botan::Cert_Extension::IPAddressBlocks::validate ( const X509_Certificate & subject,
const std::optional< X509_Certificate > & issuer,
const std::vector< X509_Certificate > & cert_path,
std::vector< std::set< Certificate_Status_Code > > & cert_status,
size_t pos ) const
overridevirtual

Callback visited during path validation.

An extension can implement this callback to inspect the path during path validation.

If an error occurs during validation of this extension, an appropriate status code shall be added to cert_status.

Parameters
subjectSubject certificate that contains this extension
issuerIssuer certificate. nullopt for certificates with no available issuer (e.g. non self-signed trust anchors).
cert_pathCertificate path which is currently validated
cert_statusCertificate validation status codes for subject certificate
posPosition of subject certificate in cert_path

Reimplemented from Botan::Certificate_Extension.

Definition at line 2199 of file x509_ext.cpp.

2203 {
2204 // maps in the form of (s)afi -> (needs_checking, ranges)
2205 auto [v4_needs_check, v6_needs_check] = create_validation_map(m_ip_addr_blocks);
2206
2207 if(pos == cert_path.size() - 1) {
2208 // checks if any range / family has 'inherit' as a value somewhere, not allowed for the root cert
2209 auto validate_root_cert_ext = [&](const auto& map) {
2210 // check if any range has a value of 'false', indicating 'inherit'
2211 return std::any_of(map.begin(), map.end(), [&](const auto& it) {
2212 const auto& [_1, validation_info] = it;
2213 const auto& [needs_checking, _2] = validation_info;
2214 return !needs_checking;
2215 });
2216 };
2217 if(validate_root_cert_ext(v4_needs_check) || validate_root_cert_ext(v6_needs_check)) {
2218 cert_status.at(pos).insert(Certificate_Status_Code::IPADDR_BLOCKS_ERROR);
2219 }
2220 return;
2221 }
2222
2223 // traverse the chain until we find a cert with concrete values for the extension (so not 'inherit')
2224 for(auto cert_path_it = cert_path.begin() + pos + 1; cert_path_it != cert_path.end(); cert_path_it++) {
2225 const IPAddressBlocks* const parent_ip = cert_path_it->v3_extensions().get_extension_object_as<IPAddressBlocks>();
2226 // extension not present for parent
2227 if(parent_ip == nullptr) {
2228 cert_status.at(pos).insert(Certificate_Status_Code::IPADDR_BLOCKS_ERROR);
2229 return;
2230 }
2231 auto [issuer_v4, issuer_v6] = create_validation_map(parent_ip->addr_blocks());
2232
2233 auto validate_against_issuer = [&](auto& subject_map, const auto& issuer_map) {
2234 for(auto map_it = subject_map.begin(); map_it != subject_map.end(); map_it++) {
2235 auto& [afam, validation_info] = *map_it;
2236
2237 // the issuer does not have this combination of afi/safi
2238 if(issuer_map.count(afam) == 0) {
2239 cert_status.at(pos).insert(Certificate_Status_Code::IPADDR_BLOCKS_ERROR);
2240 return false;
2241 }
2242
2243 auto& [needs_check, subject_value] = validation_info;
2244 const auto& [issuer_has_value, issuer_value] = issuer_map.at(afam);
2245 BOTAN_ASSERT_NOMSG(!needs_check || subject_value != nullptr);
2246 BOTAN_ASSERT_NOMSG(!issuer_has_value || issuer_value != nullptr);
2247
2248 // we still need to check this range and the issuer has an actual value for it (so not 'inherit')
2249 if(needs_check && issuer_has_value) {
2250 if(!validate_subject_in_issuer(std::span(*subject_value), std::span(*issuer_value))) {
2251 cert_status.at(pos).insert(Certificate_Status_Code::IPADDR_BLOCKS_ERROR);
2252 return false;
2253 }
2254 needs_check = false;
2255 }
2256 }
2257 return true;
2258 };
2259
2260 if(!validate_against_issuer(v4_needs_check, issuer_v4) || !validate_against_issuer(v6_needs_check, issuer_v6)) {
2261 return;
2262 }
2263
2264 auto validate_no_checks_left = [&](const auto& map) {
2265 // check if all ranges have been checked, either by comparing their ranges if they have any,
2266 // or if they are inherit, their parent(s) will be validated later
2267 return std::all_of(map.begin(), map.end(), [&](const auto& it) {
2268 const auto& [_1, validation_info] = it;
2269 const auto& [needs_checking, _2] = validation_info;
2270 return !needs_checking;
2271 });
2272 };
2273
2274 if(validate_no_checks_left(v4_needs_check) && validate_no_checks_left(v6_needs_check)) {
2275 // we've validated what we need to and can stop traversing the cert chain
2276 return;
2277 }
2278 }
2279}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75

References addr_blocks(), BOTAN_ASSERT_NOMSG, Botan::IPADDR_BLOCKS_ERROR, and IPAddressBlocks().


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