Botan 3.14.1
Crypto and TLS for C&
Botan::TLS::Server_Certificate_Type Class Referencefinal

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::Server_Certificate_Type:
Botan::TLS::Certificate_Type_Base Botan::TLS::Extension

Public Member Functions

 Certificate_Type_Base (const Certificate_Type_Base &certificate_type_from_client, std::span< const Certificate_Type > server_preference)
 Certificate_Type_Base (std::vector< Certificate_Type > supported_cert_types)
 Certificate_Type_Base (TLS_Data_Reader &reader, uint16_t extension_size, Connection_Side from)
bool empty () const override
virtual bool is_implemented () const
Certificate_Type selected_certificate_type () const
std::vector< uint8_t > serialize (Connection_Side whoami) const override
 Server_Certificate_Type (const Server_Certificate_Type &sct, const Policy &policy)
Extension_Code type () const override
void validate_selection (const Certificate_Type_Base &from_server) const

Static Public Member Functions

static Extension_Code static_type ()

Detailed Description

Definition at line 239 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Server_Certificate_Type()

Botan::TLS::Server_Certificate_Type::Server_Certificate_Type ( const Server_Certificate_Type & sct,
const Policy & policy )

Creates the Server Hello extension from the received client preferences.

Definition at line 583 of file tls_extensions.cpp.

583 :
584 Certificate_Type_Base(sct, policy.accepted_server_certificate_types()) {}
Certificate_Type_Base(std::vector< Certificate_Type > supported_cert_types)

References Certificate_Type_Base(), and Server_Certificate_Type().

Referenced by Server_Certificate_Type().

Member Function Documentation

◆ Certificate_Type_Base() [1/3]

Botan::TLS::Certificate_Type_Base::Certificate_Type_Base ( const Certificate_Type_Base & certificate_type_from_client,
std::span< const Certificate_Type > server_preference )

Called by the server to select a cert type to be used in the handshake.

Definition at line 200 of file tls_extensions.cpp.

587 :
589 // RFC 7250 4.2
590 // The server_certificate_type extension in the client hello indicates the
591 // types of certificates the client is able to process when provided by
592 // the server in a subsequent certificate payload. [...] With the
593 // server_certificate_type extension in the server hello, the TLS server
594 // indicates the certificate type carried in the Certificate payload.
595 for(const auto server_supported_cert_type : server_preference) {
596 if(value_exists(certificate_type_from_client.m_certificate_types, server_supported_cert_type)) {
597 m_certificate_types.push_back(server_supported_cert_type);
598 return;
599 }
600 }
601
602 // RFC 7250 4.2 (2.)
603 // The server supports the extension defined in this document, but
604 // it does not have any certificate type in common with the client.
605 // Then, the server terminates the session with a fatal alert of
606 // type "unsupported_certificate".
607 throw TLS_Exception(Alert::UnsupportedCertificate, "Failed to agree on certificate_type");
608}
bool value_exists(const std::vector< T > &vec, const V &val)
Definition stl_util.h:44

◆ Certificate_Type_Base() [2/3]

Botan::TLS::Certificate_Type_Base::Certificate_Type_Base ( std::vector< Certificate_Type > supported_cert_types)
explicit

Called by the client to advertise support for a number of cert types.

Definition at line 194 of file tls_extensions.cpp.

575 :
576 m_certificate_types(std::move(supported_cert_types)), m_from(Connection_Side::Client) {
577 BOTAN_ARG_CHECK(!m_certificate_types.empty(), "at least one certificate type must be supported");
578}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33

Referenced by Server_Certificate_Type().

◆ Certificate_Type_Base() [3/3]

Definition at line 204 of file tls_extensions.cpp.

610 :
611 m_from(from) {
612 if(extension_size == 0) {
613 throw Decoding_Error("Certificate type extension cannot be empty");
614 }
615
616 if(from == Connection_Side::Client) {
617 const auto type_bytes = reader.get_tls_length_value(1);
618 if(static_cast<size_t>(extension_size) != type_bytes.size() + 1) {
619 throw Decoding_Error("certificate type extension had inconsistent length");
620 }
621 // RFC 7250 4: {client,server}_certificate_types<1..2^8-1> so must be non-empty
622 if(type_bytes.empty()) {
623 throw Decoding_Error("Certificate type extension contains no types");
624 }
625 std::transform(
626 type_bytes.begin(), type_bytes.end(), std::back_inserter(m_certificate_types), [](const auto type_byte) {
627 return static_cast<Certificate_Type>(type_byte);
628 });
629
630 // RFC 7250 4.1
631 // If the client has no remaining certificate types to send in the
632 // client hello, other than the default X.509 type, it MUST omit the
633 // client_certificate_type extension in the client hello.
634 // [...]
635 // If the client has no remaining certificate types to send in the
636 // client hello, other than the default X.509 certificate type, it
637 // MUST omit the entire server_certificate_type extension from the
638 // client hello.
639 if(m_certificate_types.size() == 1 && m_certificate_types.front() == Certificate_Type::X509) {
640 throw TLS_Exception(Alert::IllegalParameter, "Certificate type extension contains only the default type");
641 }
642 } else {
643 // RFC 7250 4.2
644 // Note that only a single value is permitted in the
645 // server_certificate_type extension when carried in the server hello.
646 if(extension_size != 1) {
647 throw Decoding_Error("Server's certificate type extension must be of length 1");
648 }
649 const auto type_byte = reader.get_byte();
650 m_certificate_types.push_back(static_cast<Certificate_Type>(type_byte));
651 }
652}

◆ empty()

bool Botan::TLS::Certificate_Type_Base::empty ( ) const
inlineoverridevirtualinherited

Predicate if a TLS extension should be included or not

Returns
true if this extension should be encoded, otherwise false

Implements Botan::TLS::Extension.

Definition at line 211 of file tls_extensions.h.

211 {
212 // RFC 7250 4.1
213 // If the client has no remaining certificate types to send in the
214 // client hello, other than the default X.509 type, it MUST omit the
215 // entire client[/server]_certificate_type extension [...].
216 return m_from == Connection_Side::Client && m_certificate_types.size() == 1 &&
217 m_certificate_types.front() == Certificate_Type::X509;
218 }

References Botan::TLS::Client, and Botan::TLS::X509.

◆ is_implemented()

virtual bool Botan::TLS::Extension::is_implemented ( ) const
inlinevirtualinherited

Predicate if the extension is known/implemented

Note
this exists primarily to support unknown extension handling and doesn't need to be overridden even in the custom extension case.
Returns
true if this extension is known

Reimplemented in Botan::TLS::Unknown_Extension.

Definition at line 113 of file tls_extensions.h.

113{ return true; }

◆ selected_certificate_type()

Certificate_Type Botan::TLS::Certificate_Type_Base::selected_certificate_type ( ) const
inherited

Definition at line 685 of file tls_extensions.cpp.

685 {
687 BOTAN_ASSERT_NOMSG(m_certificate_types.size() == 1);
688 return m_certificate_types.front();
689}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82

References BOTAN_ASSERT_NOMSG, and Botan::TLS::Server.

Referenced by validate_selection().

◆ serialize()

std::vector< uint8_t > Botan::TLS::Certificate_Type_Base::serialize ( Connection_Side whoami) const
overridevirtualinherited

Serialize a TLS extension

Parameters
whoamiwhich peer we are acting as in the protocol
Returns
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 654 of file tls_extensions.cpp.

654 {
655 std::vector<uint8_t> result;
656 if(whoami == Connection_Side::Client) {
657 std::vector<uint8_t> type_bytes;
658 std::transform(
659 m_certificate_types.begin(), m_certificate_types.end(), std::back_inserter(type_bytes), [](const auto type) {
660 return static_cast<uint8_t>(type);
661 });
662 append_tls_length_value(result, type_bytes, 1);
663 } else {
664 BOTAN_ASSERT_NOMSG(m_certificate_types.size() == 1);
665 result.push_back(static_cast<uint8_t>(m_certificate_types.front()));
666 }
667 return result;
668}
virtual Extension_Code type() const =0
void append_tls_length_value(std::vector< uint8_t, Alloc > &buf, const T *vals, size_t vals_size, size_t tag_size)
Definition tls_reader.h:182

References Botan::TLS::append_tls_length_value(), BOTAN_ASSERT_NOMSG, Botan::TLS::Client, and Botan::TLS::Extension::type().

◆ static_type()

Extension_Code Botan::TLS::Server_Certificate_Type::static_type ( )
inlinestatic

Definition at line 248 of file tls_extensions.h.

References Botan::TLS::ServerCertificateType.

Referenced by type().

◆ type()

Extension_Code Botan::TLS::Server_Certificate_Type::type ( ) const
inlineoverridevirtual

Return TLS extension code

Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 250 of file tls_extensions.h.

250{ return static_type(); }
static Extension_Code static_type()

References static_type().

◆ validate_selection()

void Botan::TLS::Certificate_Type_Base::validate_selection ( const Certificate_Type_Base & from_server) const
inherited

Definition at line 670 of file tls_extensions.cpp.

670 {
672 BOTAN_ASSERT_NOMSG(from_server.m_from == Connection_Side::Server);
673
674 // RFC 7250 4.2
675 // The value conveyed in the [client_]certificate_type extension MUST be
676 // selected from one of the values provided in the [client_]certificate_type
677 // extension sent in the client hello.
678 if(!value_exists(m_certificate_types, from_server.selected_certificate_type())) {
679 throw TLS_Exception(Alert::IllegalParameter,
680 Botan::fmt("Selected certificate type was not offered: {}",
681 certificate_type_to_string(from_server.selected_certificate_type())));
682 }
683}
std::string certificate_type_to_string(Certificate_Type type)
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References BOTAN_ASSERT_NOMSG, Certificate_Type_Base(), Botan::TLS::certificate_type_to_string(), Botan::TLS::Client, Botan::fmt(), selected_certificate_type(), Botan::TLS::Server, and Botan::value_exists().


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