Botan 3.14.1
Crypto and TLS for C&
Botan::Cert_Extension::TNAuthList Class Referencefinal

#include <x509_ext.h>

Inheritance diagram for Botan::Cert_Extension::TNAuthList:
Botan::Certificate_Extension

Classes

class  Entry

Public Member Functions

std::unique_ptr< Certificate_Extension > copy () const override
bool encompasses (const TNAuthList &delegate) const
const std::vector< Entry > & entries () const
OID oid_of () const override
 TNAuthList ()=default
 TNAuthList (std::vector< Entry > entries)
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 TNAuthList from_der (std::span< const uint8_t > der)
static OID static_oid ()

Detailed Description

TNAuthList extension

RFC 8226 Secure Telephone Identity Credentials: Certificates, Section 9

The extension is a list of entries, each of which is a service provider code, a contiguous range of telephone numbers, or a single telephone number.

Definition at line 868 of file x509_ext.h.

Constructor & Destructor Documentation

◆ TNAuthList() [1/2]

Botan::Cert_Extension::TNAuthList::TNAuthList ( )
default

Create an empty extension; only useful as a decoding target

References entries(), from_der(), and TNAuthList().

Referenced by encompasses(), from_der(), TNAuthList(), and validate().

◆ TNAuthList() [2/2]

Botan::Cert_Extension::TNAuthList::TNAuthList ( std::vector< Entry > entries)
explicit

Create an extension from a list of entries; throws if entries is empty

Definition at line 1738 of file x509_ext.cpp.

1738 : m_tn_entries(std::move(entries)) {
1739 if(m_tn_entries.empty()) {
1740 throw Invalid_Argument("TNAuthList requires at least one entry");
1741 }
1742}
const std::vector< Entry > & entries() const
Definition x509_ext.h:977

References entries().

Member Function Documentation

◆ copy()

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

Make a copy of this extension

Returns
copy of this

Implements Botan::Certificate_Extension.

Definition at line 971 of file x509_ext.h.

971{ return std::make_unique<TNAuthList>(*this); }

References copy().

Referenced by copy().

◆ encompasses()

bool Botan::Cert_Extension::TNAuthList::encompasses ( const TNAuthList & delegate) const

Return true if every entry of delegate lies within the authority of this list, following RFC 9060 Section 4. Service provider codes must appear in this list verbatim. If this list contains a service provider code, all numbers and ranges are accepted, including numbers containing '' or '#': the numbers behind a code are not known locally, so the issuer's assignment checks are trusted. Otherwise, numbers containing '' or '#' must appear in this list verbatim, and numeric numbers and ranges must fall within this list's numbers and ranges.

Definition at line 1811 of file x509_ext.cpp.

1811 {
1812 // A block of numbers as (length, first, last); a number of another length is a
1813 // different number even if its value falls inside
1814 class TN_Interval final {
1815 public:
1816 explicit TN_Interval(const TelephoneNumber& tn) :
1817 m_length(tn.length()), m_first(tn.numeric_value().value()), m_last(m_first) {}
1818
1819 explicit TN_Interval(const TelephoneNumberRange& range) :
1820 m_length(range.start().length()),
1821 m_first(range.start().numeric_value().value()),
1822 m_last(m_first + range.count() - 1) {}
1823
1824 size_t length() const { return m_length; }
1825
1826 uint64_t first() const { return m_first; }
1827
1828 uint64_t last() const { return m_last; }
1829
1830 void update_last(uint64_t last) { m_last = last; }
1831
1832 bool operator<(const TN_Interval& other) const {
1833 return std::tie(m_length, m_first) < std::tie(other.m_length, other.m_first);
1834 }
1835
1836 private:
1837 size_t m_length;
1838 uint64_t m_first;
1839 uint64_t m_last;
1840 };
1841
1842 // Sort by (length, first) and coalesce overlapping or adjacent blocks of the same length
1843 const auto merge_intervals = [](std::vector<TN_Interval> intervals) {
1844 std::sort(intervals.begin(), intervals.end());
1845 std::vector<TN_Interval> merged;
1846 for(const auto& interval : intervals) {
1847 if(!merged.empty() && merged.back().length() == interval.length() &&
1848 interval.first() <= merged.back().last() + 1) {
1849 merged.back().update_last(std::max(merged.back().last(), interval.last()));
1850 } else {
1851 merged.push_back(interval);
1852 }
1853 }
1854 return merged;
1855 };
1856
1857 const auto is_covered = [](const TN_Interval& child, std::span<const TN_Interval> merged) {
1858 // The blocks are disjoint and sorted, so the only candidate is the last one starting at or before the child
1859 const auto after = std::upper_bound(merged.begin(), merged.end(), child);
1860 if(after == merged.begin()) {
1861 return false;
1862 }
1863 const TN_Interval& block = *(after - 1);
1864 return block.length() == child.length() && block.first() <= child.first() && child.last() <= block.last();
1865 };
1866
1867 std::set<std::string> spcs;
1868 std::set<TelephoneNumber> wildcards;
1869 std::vector<TN_Interval> intervals;
1870
1871 for(const auto& entry : m_tn_entries) {
1872 switch(entry.type()) {
1874 spcs.insert(entry.service_provider_code());
1875 break;
1877 if(entry.number().is_wildcard()) {
1878 wildcards.insert(entry.number());
1879 } else {
1880 intervals.emplace_back(entry.number());
1881 }
1882 break;
1884 intervals.emplace_back(entry.range());
1885 break;
1886 }
1887 }
1888
1889 const std::vector<TN_Interval> merged = merge_intervals(std::move(intervals));
1890
1891 for(const auto& entry : delegate.entries()) {
1892 switch(entry.type()) {
1894 if(!spcs.contains(entry.service_provider_code())) {
1895 return false;
1896 }
1897 break;
1899 if(!spcs.empty()) {
1900 break;
1901 }
1902 if(entry.number().is_wildcard()) {
1903 if(!wildcards.contains(entry.number())) {
1904 return false;
1905 }
1906 } else if(!is_covered(TN_Interval(entry.number()), merged)) {
1907 return false;
1908 }
1909 break;
1911 if(!spcs.empty()) {
1912 break;
1913 }
1914 if(!is_covered(TN_Interval(entry.range()), merged)) {
1915 return false;
1916 }
1917 break;
1918 }
1919 }
1920
1921 return true;
1922}
bool operator<(const OID &a, const OID &b)
Definition asn1_oid.cpp:175

References Botan::TelephoneNumberRange::count(), entries(), Botan::TelephoneNumber::length(), Botan::TelephoneNumber::numeric_value(), Botan::operator<(), Botan::Cert_Extension::TNAuthList::Entry::ServiceProviderCode, Botan::TelephoneNumberRange::start(), Botan::Cert_Extension::TNAuthList::Entry::TelephoneNumber, Botan::Cert_Extension::TNAuthList::Entry::TelephoneNumberRange, and TNAuthList().

◆ entries()

const std::vector< Entry > & Botan::Cert_Extension::TNAuthList::entries ( ) const
inline

Definition at line 977 of file x509_ext.h.

977{ return m_tn_entries; }

Referenced by encompasses(), TNAuthList(), and TNAuthList().

◆ from_der()

TNAuthList Botan::Cert_Extension::TNAuthList::from_der ( std::span< const uint8_t > der)
static

Decode a bare DER encoded TNAuthorizationList, such as one retrieved via an id-ad-stirTNList access description (RFC 8226 Section 10.1)

Definition at line 1744 of file x509_ext.cpp.

1744 {
1745 TNAuthList list;
1746 list.decode_inner(std::vector<uint8_t>(der.begin(), der.end()));
1747 return list;
1748}

References TNAuthList().

Referenced by TNAuthList().

◆ oid_of()

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

Return object identifier for this extension

Returns
OID representing this extension

Implements Botan::Certificate_Extension.

Definition at line 975 of file x509_ext.h.

975{ return static_oid(); }

References static_oid().

◆ static_oid()

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

Definition at line 973 of file x509_ext.h.

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

Referenced by oid_of().

◆ validate()

void Botan::Cert_Extension::TNAuthList::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

Checks this list against the list of every CA above it in the path, adding TN_AUTH_LIST_ERROR to this certificate's status if any of them does not encompass it.

Reimplemented from Botan::Certificate_Extension.

Definition at line 1929 of file x509_ext.cpp.

1933 {
1934 for(size_t i = pos + 1; i < cert_path.size(); ++i) {
1935 // A CA list that failed to decode is reported against the CA by Unknown_Extension
1936 const auto* ancestor = cert_path[i].v3_extensions().get_extension_object_as<TNAuthList>();
1937 if(ancestor != nullptr && !ancestor->encompasses(*this)) {
1938 cert_status.at(pos).insert(Certificate_Status_Code::TN_AUTH_LIST_ERROR);
1939 return;
1940 }
1941 }
1942}

References Botan::TN_AUTH_LIST_ERROR, and TNAuthList().


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