Botan 3.13.0
Crypto and TLS for C&
Botan::TLS::Text_Policy Class Reference

#include <tls_policy.h>

Inheritance diagram for Botan::TLS::Text_Policy:
Botan::TLS::Policy

Public Member Functions

virtual bool abort_connection_on_undesired_renegotiation () const
virtual std::optional< std::vector< Signature_Scheme > > acceptable_certificate_signature_schemes () const
virtual bool acceptable_ciphersuite (const Ciphersuite &suite) const
virtual bool acceptable_protocol_version (Protocol_Version version) const
std::vector< Signature_Schemeacceptable_signature_schemes () const override
std::vector< Certificate_Typeaccepted_client_certificate_types () const override
std::vector< Certificate_Typeaccepted_server_certificate_types () const override
bool allow_client_initiated_renegotiation () const override
bool allow_dtls12 () const override
virtual bool allow_dtls_epoch0_restart () const
bool allow_insecure_renegotiation () const override
virtual bool allow_resumption_for_renegotiation () const
bool allow_server_initiated_renegotiation () const override
bool allow_ssl_key_log_file () const override
bool allow_tls12 () const override
bool allow_tls13 () const override
std::vector< std::string > allowed_ciphers () const override
std::vector< std::string > allowed_key_exchange_methods () const override
std::vector< std::string > allowed_macs () const override
bool allowed_signature_hash (std::string_view hash) const
std::vector< std::string > allowed_signature_hashes () const override
bool allowed_signature_method (std::string_view sig_method) const
std::vector< std::string > allowed_signature_methods () const override
std::vector< Signature_Schemeallowed_signature_schemes () const override
virtual void check_peer_key_acceptable (const Public_Key &public_key) const
virtual Group_Params choose_key_exchange_group (const std::vector< Group_Params > &supported_by_peer, const std::vector< Group_Params > &offered_by_peer) const
virtual std::vector< uint16_t > ciphersuite_list (Protocol_Version version) const
virtual Group_Params default_dh_group () const
size_t dtls_default_mtu () const override
size_t dtls_initial_timeout () const override
std::optional< size_t > dtls_maximum_hello_verify_requests () const override
virtual std::optional< size_t > dtls_maximum_retransmissions () const
size_t dtls_maximum_timeout () const override
virtual bool dtls_server_require_cookie_exchange () const
bool hash_hello_random () const override
bool hide_unknown_users () const override
bool include_time_in_hello_random () const override
std::vector< Group_Paramskey_exchange_groups () const override
std::vector< Group_Paramskey_exchange_groups_to_offer () const override
virtual Protocol_Version latest_supported_version (bool datagram) const
virtual size_t maximum_certificate_chain_size () const
virtual size_t maximum_dh_group_size () const
virtual size_t maximum_handshake_message_size () const
size_t maximum_session_tickets_per_client_hello () const override
virtual size_t maximum_session_tickets_per_connection () const
size_t minimum_dh_group_size () const override
size_t minimum_ecdh_group_size () const override
size_t minimum_ecdsa_group_size () const override
virtual uint64_t minimum_key_update_interval_ms () const
size_t minimum_rsa_bits () const override
size_t minimum_signature_strength () const override
bool negotiate_encrypt_then_mac () const override
size_t new_session_tickets_upon_handshake_success () const override
virtual bool only_resume_with_exact_version () const
virtual void print (std::ostream &o) const
size_t record_padding_bytes (size_t plaintext_bytes) const override
std::optional< uint16_t > record_size_limit () const override
virtual bool request_client_certificate_authentication () const
bool require_cert_revocation_info () const override
bool require_client_certificate_authentication () const override
bool require_extended_master_secret () const override
bool reuse_session_tickets () const override
bool server_uses_own_ciphersuite_preferences () const override
std::chrono::seconds session_ticket_lifetime () const override
void set (const std::string &key, const std::string &value)
std::vector< uint16_t > srtp_profiles () const override
bool support_cert_status_message () const override
 Text_Policy (std::istream &in)
 Text_Policy (std::string_view s)
bool tls_13_middlebox_compatibility_mode () const override
std::string to_string () const
bool use_ecc_point_compression () const override

Protected Member Functions

bool get_bool (const std::string &key, bool def) const
std::chrono::seconds get_duration (const std::string &key, std::chrono::seconds def) const
size_t get_len (const std::string &key, size_t def) const
std::vector< std::string > get_list (const std::string &key, const std::vector< std::string > &def) const
std::string get_str (const std::string &key, const std::string &def="") const
std::vector< Certificate_Typeread_cert_type_list (const std::string &cert_type_str) const
std::vector< Group_Paramsread_group_list (std::string_view group_str) const
std::vector< Signature_Schemeread_sig_scheme_list (std::string_view sig_scheme_str) const
bool set_value (const std::string &key, std::string_view val, bool overwrite)

Detailed Description

Definition at line 859 of file tls_policy.h.

Constructor & Destructor Documentation

◆ Text_Policy() [1/2]

Botan::TLS::Text_Policy::Text_Policy ( std::string_view s)
explicit

Definition at line 256 of file tls_text_policy.cpp.

256 {
257 std::istringstream iss{std::string(s)}; // FIXME C++23 avoid copy
258 m_kv = read_cfg(iss);
259}
std::map< std::string, std::string > read_cfg(std::istream &is)
Definition read_cfg.cpp:35

References Botan::read_cfg().

◆ Text_Policy() [2/2]

Botan::TLS::Text_Policy::Text_Policy ( std::istream & in)
explicit

Definition at line 261 of file tls_text_policy.cpp.

261: m_kv(read_cfg(in)) {}

References Botan::read_cfg().

Member Function Documentation

◆ abort_connection_on_undesired_renegotiation()

bool Botan::TLS::Policy::abort_connection_on_undesired_renegotiation ( ) const
virtualinherited

If true, a request to renegotiate will close the connection with a fatal alert. Otherwise, a warning alert is sent.

See also
allow_client_initiated_renegotiation
allow_server_initiated_renegotiation

Default: false

Note
Has no effect for TLS 1.3 connections.

Definition at line 459 of file tls_policy.cpp.

459 {
460 return false;
461}

◆ acceptable_certificate_signature_schemes()

std::optional< std::vector< Signature_Scheme > > Botan::TLS::Policy::acceptable_certificate_signature_schemes ( ) const
virtualinherited

Return a list of schemes we are willing to accept for signatures in certificates.

By default, the same restrictions as in acceptable_signature_schemes() apply.

Returns
std::nullopt if the same restrictions as defined in acceptable_signature_schemes() should apply

Definition at line 48 of file tls_policy.cpp.

48 {
49 // the restrictions of ::acceptable_signature_schemes() shall apply
50 return std::nullopt;
51}

Referenced by Botan::TLS::Client_Hello_12::Client_Hello_12(), Botan::TLS::Client_Hello_12::Client_Hello_12(), and Botan::TLS::Client_Hello_13::Client_Hello_13().

◆ acceptable_ciphersuite()

bool Botan::TLS::Policy::acceptable_ciphersuite ( const Ciphersuite & suite) const
virtualinherited

Allows policy to reject any ciphersuites which are undesirable for whatever reason without having to reimplement ciphersuite_list

Definition at line 361 of file tls_policy.cpp.

361 {
362 return value_exists(allowed_ciphers(), ciphersuite.cipher_algo()) &&
363 value_exists(allowed_macs(), ciphersuite.mac_algo());
364}
virtual std::vector< std::string > allowed_macs() const
virtual std::vector< std::string > allowed_ciphers() const
bool value_exists(const std::vector< T > &vec, const V &val)
Definition stl_util.h:44

References allowed_ciphers(), allowed_macs(), Botan::TLS::Ciphersuite::cipher_algo(), Botan::TLS::Ciphersuite::mac_algo(), and Botan::value_exists().

Referenced by ciphersuite_list().

◆ acceptable_protocol_version()

bool Botan::TLS::Policy::acceptable_protocol_version ( Protocol_Version version) const
virtualinherited
Returns
true if and only if we are willing to accept this version Default accepts TLS v1.2 and later or DTLS v1.2 or later.

Definition at line 323 of file tls_policy.cpp.

323 {
324#if defined(BOTAN_HAS_TLS_13)
325 if(version == Protocol_Version::TLS_V13 && allow_tls13()) {
326 return true;
327 }
328#endif
329
330#if defined(BOTAN_HAS_TLS_12)
331 if(version == Protocol_Version::TLS_V12 && allow_tls12()) {
332 return true;
333 }
334
335 if(version == Protocol_Version::DTLS_V12 && allow_dtls12()) {
336 return true;
337 }
338#endif
339
340 BOTAN_UNUSED(version);
341 return false;
342}
#define BOTAN_UNUSED
Definition assert.h:144
virtual bool allow_tls12() const
virtual bool allow_tls13() const
virtual bool allow_dtls12() const

References allow_dtls12(), allow_tls12(), allow_tls13(), and BOTAN_UNUSED.

Referenced by Botan::TLS::Client_Hello_12::Client_Hello_12(), Botan::TLS::Client_Hello_12::Client_Hello_12(), Botan::TLS::Client_Hello_13::highest_supported_version(), and latest_supported_version().

◆ acceptable_signature_schemes()

std::vector< Signature_Scheme > Botan::TLS::Text_Policy::acceptable_signature_schemes ( ) const
overridevirtual

Return a list of schemes we are willing to accept

Reimplemented from Botan::TLS::Policy.

Definition at line 50 of file tls_text_policy.cpp.

50 {
51 const auto sig_schemes_str = get_str("acceptable_signature_schemes", "");
52 return (sig_schemes_str.empty()) ? Policy::acceptable_signature_schemes() : read_sig_scheme_list(sig_schemes_str);
53}
virtual std::vector< Signature_Scheme > acceptable_signature_schemes() const
std::string get_str(const std::string &key, const std::string &def="") const
std::vector< Signature_Scheme > read_sig_scheme_list(std::string_view sig_scheme_str) const

References Botan::TLS::Policy::acceptable_signature_schemes(), get_str(), and read_sig_scheme_list().

◆ accepted_client_certificate_types()

std::vector< Certificate_Type > Botan::TLS::Text_Policy::accepted_client_certificate_types ( ) const
overridevirtual

Returns a list of accepted certificate types for client authentication in order of preference. See RFC 7250 and RFC 8446 4.4.2 for details. Defaults to X509 only.

Note that it is the application's responsibility to provide public keys and/or certificates according to the specification in this list via the Credentials_Manager.

Reimplemented from Botan::TLS::Policy.

Definition at line 87 of file tls_text_policy.cpp.

87 {
88 const auto cert_types = get_str("accepted_client_certificate_types");
89 return (cert_types.empty()) ? Policy::accepted_client_certificate_types() : read_cert_type_list(cert_types);
90}
virtual std::vector< Certificate_Type > accepted_client_certificate_types() const
std::vector< Certificate_Type > read_cert_type_list(const std::string &cert_type_str) const

References Botan::TLS::Policy::accepted_client_certificate_types(), get_str(), and read_cert_type_list().

◆ accepted_server_certificate_types()

std::vector< Certificate_Type > Botan::TLS::Text_Policy::accepted_server_certificate_types ( ) const
overridevirtual

Returns a list of accepted certificate types for server authentication in order of preference. See RFC 7250 and RFC 8446 4.4.2 for details. Defaults to X509 only.

Note that it is the application's responsibility to provide public keys and/or certificates according to the specification in this list via the Credentials_Manager.

Reimplemented from Botan::TLS::Policy.

Definition at line 92 of file tls_text_policy.cpp.

92 {
93 const auto cert_types = get_str("accepted_server_certificate_types");
94 return (cert_types.empty()) ? Policy::accepted_server_certificate_types() : read_cert_type_list(cert_types);
95}
virtual std::vector< Certificate_Type > accepted_server_certificate_types() const

References Botan::TLS::Policy::accepted_server_certificate_types(), get_str(), and read_cert_type_list().

◆ allow_client_initiated_renegotiation()

bool Botan::TLS::Text_Policy::allow_client_initiated_renegotiation ( ) const
overridevirtual

Consulted by server side. If true, allows clients to initiate a new handshake

If this function returns true, a server will accept a client-initiated renegotiation attempt. Otherwise it will send the client a non-fatal TLS::AlertType::NoRenegotiation alert.

Default: false

Note
Has no effect for TLS 1.3 connections.

Reimplemented from Botan::TLS::Policy.

Definition at line 83 of file tls_text_policy.cpp.

83 {
84 return get_bool("allow_client_initiated_renegotiation", Policy::allow_client_initiated_renegotiation());
85}
virtual bool allow_client_initiated_renegotiation() const
bool get_bool(const std::string &key, bool def) const

References Botan::TLS::Policy::allow_client_initiated_renegotiation(), and get_bool().

◆ allow_dtls12()

bool Botan::TLS::Text_Policy::allow_dtls12 ( ) const
overridevirtual

Allow DTLS v1.2

Reimplemented from Botan::TLS::Policy.

Definition at line 67 of file tls_text_policy.cpp.

67 {
68 return get_bool("allow_dtls12", Policy::allow_dtls12());
69}

References Botan::TLS::Policy::allow_dtls12(), and get_bool().

◆ allow_dtls_epoch0_restart()

bool Botan::TLS::Policy::allow_dtls_epoch0_restart ( ) const
virtualinherited

If true, then allow a DTLS client to restart a connection to the same server association as described in section 4.2.8 of the DTLS RFC

Definition at line 471 of file tls_policy.cpp.

471 {
472 return false;
473}

Referenced by Botan::TLS::Channel_Impl_12::from_peer().

◆ allow_insecure_renegotiation()

bool Botan::TLS::Text_Policy::allow_insecure_renegotiation ( ) const
overridevirtual

Allow renegotiation even if the counterparty doesn't support the secure renegotiation extension.

Default: false

Warning
Changing this to true exposes you to injected plaintext attacks. Read RFC 5746 for background.
Note
Has no effect for TLS 1.3 connections.

Reimplemented from Botan::TLS::Policy.

Definition at line 71 of file tls_text_policy.cpp.

71 {
72 return get_bool("allow_insecure_renegotiation", Policy::allow_insecure_renegotiation());
73}
virtual bool allow_insecure_renegotiation() const

References Botan::TLS::Policy::allow_insecure_renegotiation(), and get_bool().

◆ allow_resumption_for_renegotiation()

bool Botan::TLS::Policy::allow_resumption_for_renegotiation ( ) const
virtualinherited
Note
Has no effect for TLS 1.3 connections.

Definition at line 435 of file tls_policy.cpp.

435 {
436 return true;
437}

Referenced by Botan::TLS::Channel_Impl_12::renegotiate().

◆ allow_server_initiated_renegotiation()

bool Botan::TLS::Text_Policy::allow_server_initiated_renegotiation ( ) const
overridevirtual

Consulted by client side. If true, allows servers to initiate a new handshake

If this function returns true, a client will accept a server-initiated renegotiation attempt. Otherwise it will send the server a non-fatal TLS::AlertType::NoRenegotiation alert.

Default: false

Note
Has no effect for TLS 1.3 connections.

Reimplemented from Botan::TLS::Policy.

Definition at line 97 of file tls_text_policy.cpp.

97 {
98 return get_bool("allow_server_initiated_renegotiation", Policy::allow_server_initiated_renegotiation());
99}
virtual bool allow_server_initiated_renegotiation() const

References Botan::TLS::Policy::allow_server_initiated_renegotiation(), and get_bool().

◆ allow_ssl_key_log_file()

bool Botan::TLS::Text_Policy::allow_ssl_key_log_file ( ) const
overridevirtual

Allow ssl key log file

Note
If function returns true, then Callbacks::tls_ssl_key_log_data will be invoked containing secret information for logging purposes

Reimplemented from Botan::TLS::Policy.

Definition at line 21 of file tls_text_policy.cpp.

21 {
22 return get_bool("allow_ssl_key_log_file", Policy::allow_ssl_key_log_file());
23}
virtual bool allow_ssl_key_log_file() const

References Botan::TLS::Policy::allow_ssl_key_log_file(), and get_bool().

◆ allow_tls12()

bool Botan::TLS::Text_Policy::allow_tls12 ( ) const
overridevirtual

Allow TLS v1.2

Reimplemented from Botan::TLS::Policy.

Definition at line 59 of file tls_text_policy.cpp.

59 {
60 return get_bool("allow_tls12", Policy::allow_tls12());
61}

References Botan::TLS::Policy::allow_tls12(), and get_bool().

◆ allow_tls13()

bool Botan::TLS::Text_Policy::allow_tls13 ( ) const
overridevirtual

Allow TLS v1.3

Reimplemented from Botan::TLS::Policy.

Definition at line 63 of file tls_text_policy.cpp.

63 {
64 return get_bool("allow_tls13", Policy::allow_tls13());
65}

References Botan::TLS::Policy::allow_tls13(), and get_bool().

◆ allowed_ciphers()

std::vector< std::string > Botan::TLS::Text_Policy::allowed_ciphers ( ) const
overridevirtual

Returns a list of ciphers we are willing to negotiate, in order of preference.

Reimplemented from Botan::TLS::Policy.

Definition at line 25 of file tls_text_policy.cpp.

25 {
26 return get_list("ciphers", Policy::allowed_ciphers());
27}
std::vector< std::string > get_list(const std::string &key, const std::vector< std::string > &def) const

References Botan::TLS::Policy::allowed_ciphers(), and get_list().

◆ allowed_key_exchange_methods()

std::vector< std::string > Botan::TLS::Text_Policy::allowed_key_exchange_methods ( ) const
overridevirtual

Returns a list of key exchange algorithms we are willing to use, in order of preference. Allowed values: DH, empty string (representing RSA using server certificate key)

Reimplemented from Botan::TLS::Policy.

Definition at line 37 of file tls_text_policy.cpp.

37 {
38 return get_list("key_exchange_methods", Policy::allowed_key_exchange_methods());
39}
virtual std::vector< std::string > allowed_key_exchange_methods() const

References Botan::TLS::Policy::allowed_key_exchange_methods(), and get_list().

◆ allowed_macs()

std::vector< std::string > Botan::TLS::Text_Policy::allowed_macs ( ) const
overridevirtual

Returns a list of MAC algorithms we are willing to use.

Reimplemented from Botan::TLS::Policy.

Definition at line 33 of file tls_text_policy.cpp.

33 {
34 return get_list("macs", Policy::allowed_macs());
35}

References Botan::TLS::Policy::allowed_macs(), and get_list().

◆ allowed_signature_hash()

bool Botan::TLS::Policy::allowed_signature_hash ( std::string_view hash) const
inherited

Definition at line 116 of file tls_policy.cpp.

116 {
117 return value_exists(allowed_signature_hashes(), sig_hash);
118}
virtual std::vector< std::string > allowed_signature_hashes() const

References allowed_signature_hashes(), and Botan::value_exists().

Referenced by allowed_signature_schemes(), and Botan::TLS::Handshake_State::choose_sig_format().

◆ allowed_signature_hashes()

std::vector< std::string > Botan::TLS::Text_Policy::allowed_signature_hashes ( ) const
overridevirtual

Returns a list of hash algorithms we are willing to use for signatures, in order of preference.

Reimplemented from Botan::TLS::Policy.

Definition at line 29 of file tls_text_policy.cpp.

29 {
30 return get_list("signature_hashes", Policy::allowed_signature_hashes());
31}

References Botan::TLS::Policy::allowed_signature_hashes(), and get_list().

◆ allowed_signature_method()

bool Botan::TLS::Policy::allowed_signature_method ( std::string_view sig_method) const
inherited

Definition at line 112 of file tls_policy.cpp.

112 {
113 return value_exists(allowed_signature_methods(), sig_method);
114}
virtual std::vector< std::string > allowed_signature_methods() const

References allowed_signature_methods(), and Botan::value_exists().

Referenced by allowed_signature_schemes(), Botan::TLS::Certificate_13::Certificate_13(), and Botan::TLS::Handshake_State::parse_sig_format().

◆ allowed_signature_methods()

std::vector< std::string > Botan::TLS::Text_Policy::allowed_signature_methods ( ) const
overridevirtual

Returns a list of signature algorithms we are willing to use, in order of preference.

Reimplemented from Botan::TLS::Policy.

Definition at line 41 of file tls_text_policy.cpp.

41 {
42 return get_list("signature_methods", Policy::allowed_signature_methods());
43}

References Botan::TLS::Policy::allowed_signature_methods(), and get_list().

◆ allowed_signature_schemes()

std::vector< Signature_Scheme > Botan::TLS::Text_Policy::allowed_signature_schemes ( ) const
overridevirtual

Returns a list of signature schemes we are willing to use, in order of preference. By default, this list contains all supported schemes that comply with the outputs of allowed_signature_methods() and allowed_signature_hashes().

Reimplemented from Botan::TLS::Policy.

Definition at line 45 of file tls_text_policy.cpp.

45 {
46 const auto sig_schemes_str = get_str("signature_schemes", "");
47 return (sig_schemes_str.empty()) ? Policy::allowed_signature_schemes() : read_sig_scheme_list(sig_schemes_str);
48}
virtual std::vector< Signature_Scheme > allowed_signature_schemes() const

References Botan::TLS::Policy::allowed_signature_schemes(), get_str(), and read_sig_scheme_list().

◆ check_peer_key_acceptable()

void Botan::TLS::Policy::check_peer_key_acceptable ( const Public_Key & public_key) const
virtualinherited

Allows the policy to examine peer public keys. Throw an exception if the key should be rejected. Default implementation checks against policy values minimum_dh_group_size(), minimum_rsa_bits(), minimum_ecdsa_group_size(), and minimum_ecdh_group_size().

Override if you'd like to perform some other kind of test on (or logging of) the peer's keys.

Definition at line 281 of file tls_policy.cpp.

281 {
282 const std::string algo_name = public_key.algo_name();
283
284 const size_t keylength = public_key.key_length();
285 size_t expected_keylength = 0;
286
287 if(algo_name == "RSA") {
288 expected_keylength = minimum_rsa_bits();
289 } else if(algo_name == "DH") {
290 expected_keylength = minimum_dh_group_size();
291 } else if(algo_name == "ECDH" || algo_name == "X25519" || algo_name == "X448") {
292 expected_keylength = minimum_ecdh_group_size();
293 } else if(algo_name == "ECDSA") {
294 expected_keylength = minimum_ecdsa_group_size();
295 }
296 // else some other algo, so leave expected_keylength as zero and the check is a no-op
297
298 if(keylength < expected_keylength) {
299 throw TLS_Exception(Alert::InsufficientSecurity,
300 "Peer sent " + std::to_string(keylength) + " bit " + algo_name +
301 " key"
302 ", policy requires at least " +
303 std::to_string(expected_keylength));
304 }
305}
virtual size_t minimum_ecdh_group_size() const
virtual size_t minimum_rsa_bits() const
virtual size_t minimum_dh_group_size() const
virtual size_t minimum_ecdsa_group_size() const

References Botan::Asymmetric_Key::algo_name(), Botan::Public_Key::key_length(), minimum_dh_group_size(), minimum_ecdh_group_size(), minimum_ecdsa_group_size(), and minimum_rsa_bits().

Referenced by Botan::TLS::Certificate_13::Certificate_13(), Botan::TLS::Callbacks::tls_ephemeral_key_agreement(), Botan::TLS::Callbacks::tls_kem_encapsulate(), Botan::TLS::Certificate_Verify_12::verify(), and Botan::TLS::Server_Key_Exchange::verify().

◆ choose_key_exchange_group()

Group_Params Botan::TLS::Policy::choose_key_exchange_group ( const std::vector< Group_Params > & supported_by_peer,
const std::vector< Group_Params > & offered_by_peer ) const
virtualinherited

Select a key exchange group to use, from the list of groups sent by the peer. In TLS 1.3 handshakes the peer might have provided cryptographic material for a subset of its available groups. Choosing a group for which no share was provided will result in an additional round trip. If none are acceptable, return Group_Params::NONE.

By default this will try to optimize for less round trips even if this results in the usage of a less preferred group.

Definition at line 124 of file tls_policy.cpp.

125 {
126 if(supported_by_peer.empty()) {
127 return Group_Params::NONE;
128 }
129
130 const auto our_groups = key_exchange_groups();
131
132 // First check if the peer sent a PQ share of a group we also support
133 for(auto share : offered_by_peer) {
134 if(share.is_post_quantum() && value_exists(our_groups, share)) {
135 return share;
136 }
137 }
138
139 // Then check if the peer offered a PQ algo we also support
140 for(auto share : supported_by_peer) {
141 if(share.is_post_quantum() && value_exists(our_groups, share)) {
142 return share;
143 }
144 }
145
146 // Prefer groups that were offered by the peer for the sake of saving
147 // an additional round trip. For TLS 1.2, this won't be used.
148 for(auto g : offered_by_peer) {
149 if(value_exists(our_groups, g)) {
150 return g;
151 }
152 }
153
154 // If no pre-offered groups fit our supported set, we prioritize our
155 // own preference.
156 for(auto g : our_groups) {
157 if(value_exists(supported_by_peer, g)) {
158 return g;
159 }
160 }
161
162 return Group_Params::NONE;
163}
virtual std::vector< Group_Params > key_exchange_groups() const

References key_exchange_groups(), and Botan::value_exists().

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Server_Hello_13::create(), and Botan::TLS::Server_Key_Exchange::Server_Key_Exchange().

◆ ciphersuite_list()

std::vector< uint16_t > Botan::TLS::Policy::ciphersuite_list ( Protocol_Version version) const
virtualinherited

Return allowed ciphersuites, in order of preference for the provided protocol version.

Parameters
versionthe exact protocol version to select supported and allowed ciphersuites for

Definition at line 614 of file tls_policy.cpp.

614 {
615 const std::vector<std::string> ciphers = allowed_ciphers();
616 const std::vector<std::string> macs = allowed_macs();
617 const std::vector<std::string> kex = allowed_key_exchange_methods();
618 const std::vector<std::string> sigs = allowed_signature_methods();
619
620 std::vector<Ciphersuite> ciphersuites;
621
622 for(auto&& suite : Ciphersuite::all_known_ciphersuites()) {
623 // Can we use it?
624 if(!suite.valid()) {
625 continue;
626 }
627
628 // Can we use it in this version?
629 if(!suite.usable_in_version(version)) {
630 continue;
631 }
632
633 // Is it acceptable to the policy?
634 if(!this->acceptable_ciphersuite(suite)) {
635 continue;
636 }
637
638 if(!value_exists(ciphers, suite.cipher_algo())) {
639 continue; // unsupported cipher
640 }
641
642 // Our non EtM TLS-CBC decryption step still has a residual Lucky13 timing
643 // channel. The leak is minor but for DTLS, which allows repeated
644 // observations, that is likely more than enough to allow plaintext
645 // recovery. Refuse CBC suites in DTLS.
646 if(version.is_datagram_protocol() && suite.cbc_ciphersuite()) {
647 continue;
648 }
649
650 // In DTLS, prohibit any potentially brute-forceable MACs
651 //
652 // DTLS allows repeated attempts without a connection teardown, and we
653 // don't currently offer any facility for an application to respond to
654 // a flood of invalid packets.
655 if(version.is_datagram_protocol() && suite.uses_short_authentication_tag()) {
656 continue;
657 }
658
659 // these checks are irrelevant for TLS 1.3
660 // TODO: consider making a method for this logic
661 if(version.is_pre_tls_13()) {
662 if(!value_exists(kex, suite.kex_algo())) {
663 continue; // unsupported key exchange
664 }
665
666 if(!value_exists(macs, suite.mac_algo())) {
667 continue; // unsupported MAC algo
668 }
669
670 if(!value_exists(sigs, suite.sig_algo())) {
671 // allow if it's an empty sig algo and we want to use PSK
672 if(suite.auth_method() != Auth_Method::IMPLICIT || !suite.psk_ciphersuite()) {
673 continue;
674 }
675 }
676 }
677
678 // OK, consider it
679 ciphersuites.push_back(suite);
680 }
681
682 if(ciphersuites.empty()) {
683 throw Invalid_State("Policy does not allow any available cipher suite");
684 }
685
686 const Ciphersuite_Preference_Ordering order(ciphers, macs, kex, sigs);
687 std::sort(ciphersuites.begin(), ciphersuites.end(), order);
688
689 std::vector<uint16_t> ciphersuite_codes;
690 ciphersuite_codes.reserve(ciphersuites.size());
691 for(const auto& i : ciphersuites) {
692 ciphersuite_codes.push_back(i.ciphersuite_code());
693 }
694 return ciphersuite_codes;
695}
static const std::vector< Ciphersuite > & all_known_ciphersuites()
virtual bool acceptable_ciphersuite(const Ciphersuite &suite) const

References acceptable_ciphersuite(), Botan::TLS::Ciphersuite::all_known_ciphersuites(), allowed_ciphers(), allowed_key_exchange_methods(), allowed_macs(), allowed_signature_methods(), Botan::TLS::IMPLICIT, Botan::TLS::Protocol_Version::is_datagram_protocol(), Botan::TLS::Protocol_Version::is_pre_tls_13(), and Botan::value_exists().

Referenced by Botan::TLS::Client_Hello_12::Client_Hello_12(), Botan::TLS::Client_Hello_12::Client_Hello_12(), and Botan::TLS::Client_Hello_13::Client_Hello_13().

◆ default_dh_group()

Group_Params Botan::TLS::Policy::default_dh_group ( ) const
virtualinherited

For ephemeral Diffie-Hellman key exchange, the server sends a group parameter. Return the 2 Byte TLS group identifier specifying the group parameter a server should use.

Default: 2048 bit IETF IPsec group ("modp/ietf/2048")

Note
Has no effect for TLS 1.3 connections.

Definition at line 165 of file tls_policy.cpp.

165 {
166 /*
167 * Return the first listed or just default to 2048
168 */
169 for(auto g : key_exchange_groups()) {
170 if(g.is_dh_named_group()) {
171 return g;
172 }
173 }
174
175 return Group_Params::FFDHE_2048;
176}

References key_exchange_groups().

Referenced by Botan::TLS::Server_Key_Exchange::Server_Key_Exchange().

◆ dtls_default_mtu()

size_t Botan::TLS::Text_Policy::dtls_default_mtu ( ) const
overridevirtual
Returns
the default MTU for DTLS

Reimplemented from Botan::TLS::Policy.

Definition at line 182 of file tls_text_policy.cpp.

182 {
183 return get_len("dtls_default_mtu", Policy::dtls_default_mtu());
184}
virtual size_t dtls_default_mtu() const
size_t get_len(const std::string &key, size_t def) const

References Botan::TLS::Policy::dtls_default_mtu(), and get_len().

◆ dtls_initial_timeout()

size_t Botan::TLS::Text_Policy::dtls_initial_timeout ( ) const
overridevirtual
Returns
the initial timeout for DTLS

Reimplemented from Botan::TLS::Policy.

Definition at line 186 of file tls_text_policy.cpp.

186 {
187 return get_len("dtls_initial_timeout", Policy::dtls_initial_timeout());
188}
virtual size_t dtls_initial_timeout() const

References Botan::TLS::Policy::dtls_initial_timeout(), and get_len().

◆ dtls_maximum_hello_verify_requests()

std::optional< size_t > Botan::TLS::Text_Policy::dtls_maximum_hello_verify_requests ( ) const
overridevirtual
Returns
the number of HelloVerifyRequest messages a DTLS client will act on within one handshake before abandoning it. Return nullopt to accept them without limit; return 0 to reject any cookie exchange.

RFC 6347 4.2.1 requires more than one to be tolerated: "This may result in clients receiving multiple HelloVerifyRequest messages with different cookies. Clients SHOULD handle this by sending a new ClientHello with a cookie in response to the new HelloVerifyRequest." A HelloVerifyRequest is unauthenticated and carries no retransmission state of its own, so without a bound a forged stream of them makes a client re-send its ClientHello indefinitely.

Reimplemented from Botan::TLS::Policy.

Definition at line 194 of file tls_text_policy.cpp.

194 {
195 const std::string v = get_str("dtls_maximum_hello_verify_requests");
196
197 if(v.empty()) {
199 }
200
201 if(v == "none") {
202 return std::nullopt;
203 }
204
205 return to_u32bit(v);
206}
virtual std::optional< size_t > dtls_maximum_hello_verify_requests() const
uint32_t to_u32bit(std::string_view input)
Definition parsing.cpp:76

References Botan::TLS::Policy::dtls_maximum_hello_verify_requests(), get_str(), and Botan::to_u32bit().

◆ dtls_maximum_retransmissions()

std::optional< size_t > Botan::TLS::Policy::dtls_maximum_retransmissions ( ) const
virtualinherited
Returns
the maximum number of times a DTLS handshake flight will be retransmitted on timeouts before the handshake is abandoned. After this many timer-driven retransmissions without progress, timeout_check() throws to signal the handshake has failed. Return nullopt to retransmit indefinitely (the historical behavior).

RFC 6347 4.2.4.1 gives the retransmission timer schedule but states no condition for giving up, so this bound is local policy rather than a protocol requirement.

Definition at line 522 of file tls_policy.cpp.

522 {
523 // Matches BoringSSL's DTLS1_MAX_TIMEOUTS.
524 //
525 // With the default schedule of a 1 second initial timeout and 60
526 // second maximum, this gives up after roughly 8 minutes
527 // (1+2+4+8+16+32+7*60 s).
528
529 return 12;
530}

Referenced by Botan::TLS::Channel_Impl_12::create_handshake_state().

◆ dtls_maximum_timeout()

size_t Botan::TLS::Text_Policy::dtls_maximum_timeout ( ) const
overridevirtual
Returns
the maximum timeout for DTLS

Reimplemented from Botan::TLS::Policy.

Definition at line 190 of file tls_text_policy.cpp.

190 {
191 return get_len("dtls_maximum_timeout", Policy::dtls_maximum_timeout());
192}
virtual size_t dtls_maximum_timeout() const

References Botan::TLS::Policy::dtls_maximum_timeout(), and get_len().

◆ dtls_server_require_cookie_exchange()

bool Botan::TLS::Policy::dtls_server_require_cookie_exchange ( ) const
virtualinherited

DTLS defines an cookie exchange protocol which is used to ensure routability on the path between the server and client. This is especially useful when using a connectionless datagram layer like UDP, where a client's source address can easily be spoofed.

This cookie exchange prevents abusing the server for DoS amplification attacks, and additionally provides assurance for the server that the client's purported address is theirs, which can be helpful for attribution/logging purposes.

The server creates cookies by hashing the original client hello and the peer's source address along with a secret key. The cookie value is then sent back to the client address. The client can then retry the connection, with their updated client hello including the cookie value. So this cookie exchange implies one extra round trip during the handshake.

By default this function returns true. If this function returns true then the DTLS session cookie Credentials_Manager::dtls_cookie_secret must be set, and TLS::Callbacks::tls_peer_network_identity must return a non-empty string.

It is unsafe to disable this cookie exchange if the server is exposed to arbitrary Internet traffic.

Definition at line 475 of file tls_policy.cpp.

475 {
476 /*
477 RFC 9147 Section 11 "Security Considerations":
478
479 The primary additional security consideration raised by DTLS is that of
480 denial of service by excessive resource consumption. DTLS includes a
481 cookie exchange designed to protect against denial of service. [...]
482 In particular, DTLS servers that do not use the cookie exchange may be
483 used as attack amplifiers even if they themselves are not experiencing
484 DoS. Therefore, DTLS servers SHOULD use the cookie exchange unless there
485 is good reason to believe that amplification is not a threat in their
486 environment.
487 */
488 return true;
489}

◆ get_bool()

bool Botan::TLS::Text_Policy::get_bool ( const std::string & key,
bool def ) const
protected

Definition at line 356 of file tls_text_policy.cpp.

356 {
357 const std::string v = get_str(key);
358
359 if(v.empty()) {
360 return def;
361 }
362
363 if(v == "true" || v == "True") {
364 return true;
365 } else if(v == "false" || v == "False") {
366 return false;
367 } else {
368 throw Decoding_Error("Invalid boolean '" + v + "'");
369 }
370}

References get_str().

Referenced by allow_client_initiated_renegotiation(), allow_dtls12(), allow_insecure_renegotiation(), allow_server_initiated_renegotiation(), allow_ssl_key_log_file(), allow_tls12(), allow_tls13(), hash_hello_random(), hide_unknown_users(), include_time_in_hello_random(), negotiate_encrypt_then_mac(), require_cert_revocation_info(), require_client_certificate_authentication(), require_extended_master_secret(), reuse_session_tickets(), server_uses_own_ciphersuite_preferences(), support_cert_status_message(), tls_13_middlebox_compatibility_mode(), and use_ecc_point_compression().

◆ get_duration()

std::chrono::seconds Botan::TLS::Text_Policy::get_duration ( const std::string & key,
std::chrono::seconds def ) const
protected

Definition at line 337 of file tls_text_policy.cpp.

337 {
338 using rep_t = std::chrono::seconds::rep;
339 constexpr rep_t max_seconds = std::chrono::seconds::max().count();
340 constexpr auto max_sizet = std::numeric_limits<size_t>::max();
341 using ull = unsigned long long;
342
343 // The concrete type of `rep` is not specified exactly. Let's play it extra safe...
344 // e.g. on 32-bit platforms size_t is 32 bits but rep_t is "at least 35 bits"
345
346 // at least zero and certainly fitting into rep_t
347 const rep_t positive_default = std::max(def.count(), rep_t(0));
348 // at least zero but capped to whatever size_t can handle
349 const size_t positive_capped_default = static_cast<size_t>(std::min<ull>(positive_default, max_sizet));
350 // at least zero but capped to whatever rep_t can handle
351 const rep_t result = static_cast<rep_t>(std::min<ull>(get_len(key, positive_capped_default), max_seconds));
352
353 return std::chrono::seconds(result);
354}

References get_len().

Referenced by session_ticket_lifetime().

◆ get_len()

size_t Botan::TLS::Text_Policy::get_len ( const std::string & key,
size_t def ) const
protected

◆ get_list()

std::vector< std::string > Botan::TLS::Text_Policy::get_list ( const std::string & key,
const std::vector< std::string > & def ) const
protected

Definition at line 263 of file tls_text_policy.cpp.

263 {
264 const std::string v = get_str(key);
265
266 if(v.empty()) {
267 return def;
268 }
269
270 return split_on(v, ' ');
271}
std::vector< std::string > split_on(std::string_view str, char delim)
Definition parsing.cpp:141

References get_str(), and Botan::split_on().

Referenced by allowed_ciphers(), allowed_key_exchange_methods(), allowed_macs(), allowed_signature_hashes(), allowed_signature_methods(), and srtp_profiles().

◆ get_str()

std::string Botan::TLS::Text_Policy::get_str ( const std::string & key,
const std::string & def = "" ) const
protected

Definition at line 372 of file tls_text_policy.cpp.

372 {
373 auto i = m_kv.find(key);
374 if(i == m_kv.end()) {
375 return def;
376 }
377
378 return i->second;
379}

Referenced by acceptable_signature_schemes(), accepted_client_certificate_types(), accepted_server_certificate_types(), allowed_signature_schemes(), dtls_maximum_hello_verify_requests(), get_bool(), get_len(), get_list(), key_exchange_groups(), and key_exchange_groups_to_offer().

◆ hash_hello_random()

bool Botan::TLS::Text_Policy::hash_hello_random ( ) const
overridevirtual

Hash the RNG output for the client/server hello random. This is a pre-caution to avoid writing "raw" RNG output to the wire.

There's not normally a reason to disable this, except when deterministic output is required for testing.

Default: true

Reimplemented from Botan::TLS::Policy.

Definition at line 248 of file tls_text_policy.cpp.

248 {
249 return get_bool("hash_hello_random", Policy::hash_hello_random());
250}
virtual bool hash_hello_random() const

References get_bool(), and Botan::TLS::Policy::hash_hello_random().

◆ hide_unknown_users()

bool Botan::TLS::Text_Policy::hide_unknown_users ( ) const
overridevirtual

The PSK suites work using an identifier along with a shared secret. If this function returns true, when an identifier that the server does not recognize is provided by a client, a random shared secret will be generated in such a way that a client should not be able to tell the difference between the identifier not being known and the secret being wrong. This can help protect against some username probing attacks. If it returns false, the server will instead send an TLS::AlertType::UnknownPSKIdentity alert when an unknown identifier is used.

Default: false

Reimplemented from Botan::TLS::Policy.

Definition at line 212 of file tls_text_policy.cpp.

212 {
213 return get_bool("hide_unknown_users", Policy::hide_unknown_users());
214}
virtual bool hide_unknown_users() const

References get_bool(), and Botan::TLS::Policy::hide_unknown_users().

◆ include_time_in_hello_random()

bool Botan::TLS::Text_Policy::include_time_in_hello_random ( ) const
overridevirtual

The protocol dictates that the first 32 bits of the random field are the current time in seconds. However this allows client fingerprinting attacks. Set to false to disable, in which case random bytes will be used instead.

Default: true

Reimplemented from Botan::TLS::Policy.

Definition at line 75 of file tls_text_policy.cpp.

75 {
76 return get_bool("include_time_in_hello_random", Policy::include_time_in_hello_random());
77}
virtual bool include_time_in_hello_random() const

References get_bool(), and Botan::TLS::Policy::include_time_in_hello_random().

◆ key_exchange_groups()

std::vector< Group_Params > Botan::TLS::Text_Policy::key_exchange_groups ( ) const
overridevirtual

Return a list of ECC curve and DH group TLS identifiers we are willing to use, in order of preference. The default ordering puts the best performing ECC first.

Default: Group_Params::X25519, Group_Params::SECP256R1, Group_Params::BRAINPOOL256R1, Group_Params::SECP384R1, Group_Params::BRAINPOOL384R1, Group_Params::SECP521R1, Group_Params::BRAINPOOL512R1, Group_Params::FFDHE_2048, Group_Params::FFDHE_3072, Group_Params::FFDHE_4096, Group_Params::FFDHE_6144, Group_Params::FFDHE_8192

No other values are currently defined.

Reimplemented from Botan::TLS::Policy.

Definition at line 132 of file tls_text_policy.cpp.

132 {
133 std::string group_str = get_str("key_exchange_groups");
134
135 if(group_str.empty()) {
136 // fall back to previously used name
137 group_str = get_str("groups");
138 }
139
140 if(group_str.empty()) {
142 }
143
144 return read_group_list(group_str);
145}
std::vector< Group_Params > read_group_list(std::string_view group_str) const

References get_str(), Botan::TLS::Policy::key_exchange_groups(), and read_group_list().

◆ key_exchange_groups_to_offer()

std::vector< Group_Params > Botan::TLS::Text_Policy::key_exchange_groups_to_offer ( ) const
overridevirtual

Return a list of groups to provide prepared key share offers in the initial client hello for. Groups in this list must be reflected in key_exchange_groups() and in the same order. If an empty list is returned, no prepared key share offers are sent and the decision of the group to use is left to the server.

Default: the most preferred group from key_exchange_groups().

Note
Has an effect on TLS 1.3 clients, only.

Reimplemented from Botan::TLS::Policy.

Definition at line 147 of file tls_text_policy.cpp.

147 {
148 const std::string group_str = get_str("key_exchange_groups_to_offer", "notset");
149
150 if(group_str.empty() || group_str == "notset") {
151 // policy was not set, fall back to default behaviour
153 }
154
155 if(group_str == "none") {
156 return {};
157 }
158
159 return read_group_list(group_str);
160}
virtual std::vector< Group_Params > key_exchange_groups_to_offer() const

References get_str(), Botan::TLS::Policy::key_exchange_groups_to_offer(), and read_group_list().

◆ latest_supported_version()

Protocol_Version Botan::TLS::Policy::latest_supported_version ( bool datagram) const
virtualinherited

Returns the most recent protocol version we are willing to use, for either TLS or DTLS depending on datagram param. Shouldn't ever need to override this unless you want to allow a user to disable specific TLS versions.

Definition at line 344 of file tls_policy.cpp.

344 {
345 if(datagram) {
346 if(acceptable_protocol_version(Protocol_Version::DTLS_V12)) {
347 return Protocol_Version::DTLS_V12;
348 }
349 } else {
350 if(acceptable_protocol_version(Protocol_Version::TLS_V13)) {
351 return Protocol_Version::TLS_V13;
352 }
353 if(acceptable_protocol_version(Protocol_Version::TLS_V12)) {
354 return Protocol_Version::TLS_V12;
355 }
356 }
357
358 throw Invalid_State("Policy forbids all available TLS version");
359}
virtual bool acceptable_protocol_version(Protocol_Version version) const

References acceptable_protocol_version().

◆ maximum_certificate_chain_size()

size_t Botan::TLS::Policy::maximum_certificate_chain_size ( ) const
virtualinherited
Returns
the maximum size of the certificate chain, in bytes. Return 0 to disable this and accept any size.

Definition at line 495 of file tls_policy.cpp.

495 {
496 return 65536;
497}

Referenced by Botan::TLS::Certificate_12::Certificate_12(), and Botan::TLS::Certificate_13::Certificate_13().

◆ maximum_dh_group_size()

size_t Botan::TLS::Policy::maximum_dh_group_size ( ) const
virtualinherited

Largest DH group size (in bits) the client will accept from a server.

Default: 8192 bits (the largest FFDHE group)

This only affects the TLS 1.2 client

Definition at line 248 of file tls_policy.cpp.

248 {
249 return 8192;
250}

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange().

◆ maximum_handshake_message_size()

size_t Botan::TLS::Policy::maximum_handshake_message_size ( ) const
virtualinherited
Returns
the maximum size of a single handshake message, in bytes. Messages larger than this will be rejected prior to processing. Return 0 to disable this and accept any size.

Definition at line 491 of file tls_policy.cpp.

491 {
492 return 65536;
493}

◆ maximum_session_tickets_per_client_hello()

size_t Botan::TLS::Text_Policy::maximum_session_tickets_per_client_hello ( ) const
overridevirtual

Defines the maximum number of session tickets a client might offer in a single resumption attempt. Must be greater than 0.

TODO: Currently, the TLS 1.3 client implementation supports exactly one ticket per handshake. RFC 8446 allows for an arbitrary amount, though.

Default: 1

Note
Has an effect on TLS 1.3 connections, only.

Reimplemented from Botan::TLS::Policy.

Definition at line 216 of file tls_text_policy.cpp.

216 {
217 return get_len("maximum_session_tickets_per_client_hello", Policy::maximum_session_tickets_per_client_hello());
218}
virtual size_t maximum_session_tickets_per_client_hello() const

References get_len(), and Botan::TLS::Policy::maximum_session_tickets_per_client_hello().

◆ maximum_session_tickets_per_connection()

size_t Botan::TLS::Policy::maximum_session_tickets_per_connection ( ) const
virtualinherited
Returns
the maximum number of NewSessionTicket messages to accept from a server on a single connection. Return 0 to disable the limit.
Note
Only applies to TLS 1.3 client connections.

Definition at line 503 of file tls_policy.cpp.

503 {
504 return 10;
505}

◆ minimum_dh_group_size()

size_t Botan::TLS::Text_Policy::minimum_dh_group_size ( ) const
overridevirtual

Return the minimum DH group size we're willing to use

Return the minimum size in bits for a Diffie-Hellman group that a client will accept. Due to the design of the protocol the client has only two options - accept the group, or reject it with a fatal alert then attempt to reconnect after disabling ephemeral Diffie-Hellman.

Default: 2048 bits

This only affects the TLS 1.2 client

Reimplemented from Botan::TLS::Policy.

Definition at line 170 of file tls_text_policy.cpp.

170 {
171 return get_len("minimum_dh_group_size", Policy::minimum_dh_group_size());
172}

References get_len(), and Botan::TLS::Policy::minimum_dh_group_size().

◆ minimum_ecdh_group_size()

size_t Botan::TLS::Text_Policy::minimum_ecdh_group_size ( ) const
overridevirtual

Return the minimum ECDH group size we're willing to use for key exchange

Default 255, allowing x25519 and larger x25519 is the smallest curve we will negotiate P-521 is the largest

Reimplemented from Botan::TLS::Policy.

Definition at line 162 of file tls_text_policy.cpp.

162 {
163 return get_len("minimum_ecdh_group_size", Policy::minimum_ecdh_group_size());
164}

References get_len(), and Botan::TLS::Policy::minimum_ecdh_group_size().

◆ minimum_ecdsa_group_size()

size_t Botan::TLS::Text_Policy::minimum_ecdsa_group_size ( ) const
overridevirtual

For ECDSA authenticated ciphersuites, the smallest key size the client will accept. This policy is currently only enforced on the server by the client.

Default: 256

Reimplemented from Botan::TLS::Policy.

Definition at line 166 of file tls_text_policy.cpp.

166 {
167 return get_len("minimum_ecdsa_group_size", Policy::minimum_ecdsa_group_size());
168}

References get_len(), and Botan::TLS::Policy::minimum_ecdsa_group_size().

◆ minimum_key_update_interval_ms()

uint64_t Botan::TLS::Policy::minimum_key_update_interval_ms ( ) const
virtualinherited
Returns
the minimum number of milliseconds that must elapse between two received KeyUpdate messages. If a KeyUpdate arrives sooner than this interval after the previous one, the connection is terminated. Return 0 to disable rate limiting.
Note
Only applies to TLS 1.3 connections.

Definition at line 499 of file tls_policy.cpp.

499 {
500 return 1000;
501}

◆ minimum_rsa_bits()

size_t Botan::TLS::Text_Policy::minimum_rsa_bits ( ) const
overridevirtual

Return the minimum bit size we're willing to accept for RSA key exchange or server signatures.

It does not place any requirements on the size of any RSA signature(s) which were used to check the server certificate. This is only concerned with the server's public key.

Default is 2048 which is smallest RSA key size still secure for medium term security.

Reimplemented from Botan::TLS::Policy.

Definition at line 174 of file tls_text_policy.cpp.

174 {
175 return get_len("minimum_rsa_bits", Policy::minimum_rsa_bits());
176}

References get_len(), and Botan::TLS::Policy::minimum_rsa_bits().

◆ minimum_signature_strength()

size_t Botan::TLS::Text_Policy::minimum_signature_strength ( ) const
overridevirtual

The minimum signature strength we will accept

Returning 80 allows RSA 1024 and SHA-1. Values larger than 80 disable SHA-1 support. Returning 110 allows RSA 2048. Return 128 to force ECC (P-256) or large (~3000 bit) RSA keys.

Default is 110

Reimplemented from Botan::TLS::Policy.

Definition at line 178 of file tls_text_policy.cpp.

178 {
179 return get_len("minimum_signature_strength", Policy::minimum_signature_strength());
180}
virtual size_t minimum_signature_strength() const

References get_len(), and Botan::TLS::Policy::minimum_signature_strength().

◆ negotiate_encrypt_then_mac()

bool Botan::TLS::Text_Policy::negotiate_encrypt_then_mac ( ) const
overridevirtual

Indicates whether the encrypt-then-MAC extension should be negotiated (RFC 7366)

Note
Has no effect for TLS 1.3 connections.

Reimplemented from Botan::TLS::Policy.

Definition at line 105 of file tls_text_policy.cpp.

105 {
106 return get_bool("negotiate_encrypt_then_mac", Policy::negotiate_encrypt_then_mac());
107}
virtual bool negotiate_encrypt_then_mac() const

References get_bool(), and Botan::TLS::Policy::negotiate_encrypt_then_mac().

◆ new_session_tickets_upon_handshake_success()

size_t Botan::TLS::Text_Policy::new_session_tickets_upon_handshake_success ( ) const
overridevirtual

Return the number of new session tickets a TLS 1.3 server should issue automatically upon a successful handshake. Note that applications can use TLS::Server::send_new_session_tickets() regardless of this policy.

For convenience (and compatibility with the TLS 1.2 behaviour), this returns '1' by default.

Note
Has an effect on TLS 1.3 connections, only.

Reimplemented from Botan::TLS::Policy.

Definition at line 228 of file tls_text_policy.cpp.

228 {
229 return get_len("new_session_tickets_upon_handshake_success", Policy::new_session_tickets_upon_handshake_success());
230}
virtual size_t new_session_tickets_upon_handshake_success() const

References get_len(), and Botan::TLS::Policy::new_session_tickets_upon_handshake_success().

◆ only_resume_with_exact_version()

bool Botan::TLS::Policy::only_resume_with_exact_version ( ) const
virtualinherited

Only resume sessions when their original protocol version matches the current version exactly.

Default: true

Definition at line 447 of file tls_policy.cpp.

447 {
448 return true;
449}

◆ print()

void Botan::TLS::Policy::print ( std::ostream & o) const
virtualinherited

Convert this policy to a printable format.

Parameters
ostream to be printed to

Definition at line 758 of file tls_policy.cpp.

758 {
759 print_bool(o, "allow_tls12", allow_tls12());
760 print_bool(o, "allow_tls13", allow_tls13());
761 print_bool(o, "allow_dtls12", allow_dtls12());
762 print_bool(o, "allow_ssl_key_log_file", allow_ssl_key_log_file());
763 print_vec(o, "ciphers", allowed_ciphers());
764 print_vec(o, "macs", allowed_macs());
765 print_vec(o, "signature_hashes", allowed_signature_hashes());
766 print_vec(o, "signature_methods", allowed_signature_methods());
767 print_vec(o, "signature_schemes", allowed_signature_schemes());
768 print_vec(o, "acceptable_signature_schemes", acceptable_signature_schemes());
769 print_vec(o, "key_exchange_methods", allowed_key_exchange_methods());
770 print_vec(o, "key_exchange_groups", key_exchange_groups());
771 const auto groups_to_offer = key_exchange_groups_to_offer();
772 if(groups_to_offer.empty()) {
773 print_vec(o, "key_exchange_groups_to_offer", {std::string("none")});
774 } else {
775 print_vec(o, "key_exchange_groups_to_offer", groups_to_offer);
776 }
777 print_bool(o, "allow_insecure_renegotiation", allow_insecure_renegotiation());
778 print_bool(o, "include_time_in_hello_random", include_time_in_hello_random());
779 print_bool(o, "allow_server_initiated_renegotiation", allow_server_initiated_renegotiation());
780 print_bool(o, "hide_unknown_users", hide_unknown_users());
781 print_bool(o, "server_uses_own_ciphersuite_preferences", server_uses_own_ciphersuite_preferences());
782 print_bool(o, "negotiate_encrypt_then_mac", negotiate_encrypt_then_mac());
783 print_bool(o, "require_extended_master_secret", require_extended_master_secret());
784 print_bool(o, "support_cert_status_message", support_cert_status_message());
785 print_bool(o, "tls_13_middlebox_compatibility_mode", tls_13_middlebox_compatibility_mode());
786 print_vec(o, "accepted_client_certificate_types", accepted_client_certificate_types());
787 print_vec(o, "accepted_server_certificate_types", accepted_server_certificate_types());
788 print_bool(o, "hash_hello_random", hash_hello_random());
789 if(record_size_limit().has_value()) {
790 o << "record_size_limit = " << record_size_limit().value() << '\n';
791 }
792 o << "maximum_session_tickets_per_client_hello = " << maximum_session_tickets_per_client_hello() << '\n';
793 o << "session_ticket_lifetime = " << session_ticket_lifetime().count() << '\n';
794 print_bool(o, "reuse_session_tickets", reuse_session_tickets());
795 o << "new_session_tickets_upon_handshake_success = " << new_session_tickets_upon_handshake_success() << '\n';
796 o << "minimum_dh_group_size = " << minimum_dh_group_size() << '\n';
797 o << "minimum_ecdh_group_size = " << minimum_ecdh_group_size() << '\n';
798 o << "minimum_rsa_bits = " << minimum_rsa_bits() << '\n';
799 o << "minimum_signature_strength = " << minimum_signature_strength() << '\n';
800}
virtual bool reuse_session_tickets() const
virtual bool tls_13_middlebox_compatibility_mode() const
virtual bool require_extended_master_secret() const
virtual bool server_uses_own_ciphersuite_preferences() const
virtual bool support_cert_status_message() const
virtual std::optional< uint16_t > record_size_limit() const
virtual std::chrono::seconds session_ticket_lifetime() const

References acceptable_signature_schemes(), accepted_client_certificate_types(), accepted_server_certificate_types(), allow_dtls12(), allow_insecure_renegotiation(), allow_server_initiated_renegotiation(), allow_ssl_key_log_file(), allow_tls12(), allow_tls13(), allowed_ciphers(), allowed_key_exchange_methods(), allowed_macs(), allowed_signature_hashes(), allowed_signature_methods(), allowed_signature_schemes(), hash_hello_random(), hide_unknown_users(), include_time_in_hello_random(), key_exchange_groups(), key_exchange_groups_to_offer(), maximum_session_tickets_per_client_hello(), minimum_dh_group_size(), minimum_ecdh_group_size(), minimum_rsa_bits(), minimum_signature_strength(), negotiate_encrypt_then_mac(), new_session_tickets_upon_handshake_success(), record_size_limit(), require_extended_master_secret(), reuse_session_tickets(), server_uses_own_ciphersuite_preferences(), session_ticket_lifetime(), support_cert_status_message(), and tls_13_middlebox_compatibility_mode().

Referenced by to_string().

◆ read_cert_type_list()

std::vector< Certificate_Type > Botan::TLS::Text_Policy::read_cert_type_list ( const std::string & cert_type_str) const
protected

Definition at line 310 of file tls_text_policy.cpp.

310 {
311 std::vector<Certificate_Type> cert_types;
312 for(const std::string& cert_type_name : split_on(cert_type_names, ' ')) {
313 cert_types.push_back(certificate_type_from_string(cert_type_name));
314 }
315
316 return cert_types;
317}
Certificate_Type certificate_type_from_string(const std::string &type_str)

References Botan::TLS::certificate_type_from_string(), and Botan::split_on().

Referenced by accepted_client_certificate_types(), and accepted_server_certificate_types().

◆ read_group_list()

std::vector< Group_Params > Botan::TLS::Text_Policy::read_group_list ( std::string_view group_str) const
protected

Definition at line 273 of file tls_text_policy.cpp.

273 {
274 std::vector<Group_Params> groups;
275 for(const auto& group_name : split_on(group_str, ' ')) {
276 Group_Params group_id = Group_Params::from_string(group_name).value_or(Group_Params::NONE);
277
278 if(!group_id.is_available()) {
279 continue;
280 }
281
282 if(group_id == Group_Params::NONE) {
283 try {
284 size_t consumed = 0;
285 const unsigned long ll_id = std::stoul(group_name, &consumed, 0);
286 if(consumed != group_name.size()) {
287 continue; // some other cruft
288 }
289
290 const uint16_t id = static_cast<uint16_t>(ll_id);
291
292 if(id != ll_id) {
293 continue; // integer too large
294 }
295
296 group_id = static_cast<Group_Params>(id);
297 } catch(...) {
298 continue;
299 }
300 }
301
302 if(group_id != Group_Params::NONE) {
303 groups.push_back(group_id);
304 }
305 }
306
307 return groups;
308}
static std::optional< Group_Params > from_string(std::string_view group_name)

References Botan::TLS::Group_Params::from_string(), Botan::TLS::Group_Params::is_available(), and Botan::split_on().

Referenced by key_exchange_groups(), and key_exchange_groups_to_offer().

◆ read_sig_scheme_list()

std::vector< Signature_Scheme > Botan::TLS::Text_Policy::read_sig_scheme_list ( std::string_view sig_scheme_str) const
protected

Definition at line 319 of file tls_text_policy.cpp.

319 {
320 std::vector<Signature_Scheme> sig_schemes;
321 for(const auto& sig_scheme_name : split_on(sig_scheme_str, ' ')) {
322 sig_schemes.push_back(Signature_Scheme::from_string(sig_scheme_name));
323 }
324 return sig_schemes;
325}
static Signature_Scheme from_string(std::string_view str)

References Botan::TLS::Signature_Scheme::from_string(), and Botan::split_on().

Referenced by acceptable_signature_schemes(), and allowed_signature_schemes().

◆ record_padding_bytes()

size_t Botan::TLS::Text_Policy::record_padding_bytes ( size_t plaintext_bytes) const
overridevirtual

Defines the number of padding octets added to a protected TLS 1.3 record that contains plaintext_bytes of plaintext. The plaintext size is counted like the record size limit, i.e. per RFC 8449 4.: "The value includes the content type and padding added in TLS 1.3 (that is, the complete length of TLSInnerPlaintext)."

This may be used to reduce the amount of information leaked by the length of TLS records.

Padding that would grow a record beyond the negotiated record size limit is truncated to reach exactly that limit.

Note
This feature is available in TLS 1.3 only (see RFC 9846 5.4).

Default: 0 (records are not padded)

Reimplemented from Botan::TLS::Policy.

Definition at line 121 of file tls_text_policy.cpp.

121 {
122 // Text policies can express the simplest padding scheme only: pad
123 // records to a fixed minimum size.
124 const auto minimum_record_size = get_len("minimum_record_size", 0);
125 return (plaintext_bytes < minimum_record_size) ? minimum_record_size - plaintext_bytes : 0;
126}

References get_len().

◆ record_size_limit()

std::optional< uint16_t > Botan::TLS::Text_Policy::record_size_limit ( ) const
overridevirtual

Defines the maximum TLS record length for TLS connections. This is based on the Record Size Limit extension described in RFC 8449. By default (i.e. if std::nullopt is returned), TLS clients will omit this extension altogether.

This value may be between 64 and 16385 (TLS 1.3) or 16384 (TLS 1.2).

Note
This is currently not implemented for TLS 1.2, hence the limit won't be negotiated by TLS 1.3 clients that support downgrading to TLS 1.2 (i.e. allow_tls12() returning true).

Reimplemented from Botan::TLS::Policy.

Definition at line 113 of file tls_text_policy.cpp.

113 {
114 const auto limit = get_len("record_size_limit", 0);
115 // RFC 8449 4.
116 // TLS 1.3 uses a limit of 2^14+1 octets.
117 BOTAN_ARG_CHECK(limit <= 16385, "record size limit too large");
118 return (limit > 0) ? std::make_optional(static_cast<uint16_t>(limit)) : std::nullopt;
119}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33

References BOTAN_ARG_CHECK, and get_len().

◆ request_client_certificate_authentication()

bool Botan::TLS::Policy::request_client_certificate_authentication ( ) const
virtualinherited

Indicate if client certificate authentication is requested. If true, then a cert will be requested.

Definition at line 455 of file tls_policy.cpp.

455 {
457}
virtual bool require_client_certificate_authentication() const

References require_client_certificate_authentication().

Referenced by Botan::TLS::Certificate_Request_13::maybe_create().

◆ require_cert_revocation_info()

bool Botan::TLS::Text_Policy::require_cert_revocation_info ( ) const
overridevirtual

Return if certificate revocation info (CRL/OCSP) is required

If true, certificates won't be trusted unless a valid CRL or OCSP response was examined.

Default: true

Reimplemented from Botan::TLS::Policy.

Definition at line 208 of file tls_text_policy.cpp.

208 {
209 return get_bool("require_cert_revocation_info", Policy::require_cert_revocation_info());
210}
virtual bool require_cert_revocation_info() const

References get_bool(), and Botan::TLS::Policy::require_cert_revocation_info().

◆ require_client_certificate_authentication()

bool Botan::TLS::Text_Policy::require_client_certificate_authentication ( ) const
overridevirtual

Indicate if client certificate authentication is required. If true, then a cert will be requested and if the client does not send a certificate the connection will be closed.

Reimplemented from Botan::TLS::Policy.

Definition at line 79 of file tls_text_policy.cpp.

79 {
80 return get_bool("require_client_certificate_authentication", Policy::require_client_certificate_authentication());
81}

References get_bool(), and Botan::TLS::Policy::require_client_certificate_authentication().

◆ require_extended_master_secret()

bool Botan::TLS::Text_Policy::require_extended_master_secret ( ) const
overridevirtual

Require that TLS 1.2 / DTLS 1.2 handshakes use the Extended Master Secret extension (RFC 7627). When true, both the server and the client abort fresh handshakes whose peer did not negotiate EMS. RFC 9325 4.4 recommends requiring this extension.

Note
Has no effect for TLS 1.3 connections, where the equivalent binding is built in.

Reimplemented from Botan::TLS::Policy.

Definition at line 109 of file tls_text_policy.cpp.

109 {
110 return get_bool("require_extended_master_secret", Policy::require_extended_master_secret());
111}

References get_bool(), and Botan::TLS::Policy::require_extended_master_secret().

◆ reuse_session_tickets()

bool Botan::TLS::Text_Policy::reuse_session_tickets ( ) const
overridevirtual

Decides whether stored session tickets should be used multiple times (until their lifetime runs out). This might allow passive observers to correlate connections (RFC 8446 Appendix C.4). This has no effect on TLS 1.2 resumptions based on session IDs as those are negotiated in the clear anyway.

Default: false

Reimplemented from Botan::TLS::Policy.

Definition at line 224 of file tls_text_policy.cpp.

224 {
225 return get_bool("reuse_session_tickets", Policy::reuse_session_tickets());
226}

References get_bool(), and Botan::TLS::Policy::reuse_session_tickets().

◆ server_uses_own_ciphersuite_preferences()

bool Botan::TLS::Text_Policy::server_uses_own_ciphersuite_preferences ( ) const
overridevirtual

Default: true

Returns
true if servers should choose the ciphersuite matching their highest preference, rather than the clients. Has no effect on client side.

Reimplemented from Botan::TLS::Policy.

Definition at line 101 of file tls_text_policy.cpp.

101 {
102 return get_bool("server_uses_own_ciphersuite_preferences", Policy::server_uses_own_ciphersuite_preferences());
103}

References get_bool(), and Botan::TLS::Policy::server_uses_own_ciphersuite_preferences().

◆ session_ticket_lifetime()

std::chrono::seconds Botan::TLS::Text_Policy::session_ticket_lifetime ( ) const
overridevirtual

Return the allowed lifetime of a session ticket. If 0, session tickets do not expire until the session ticket key rolls over. For TLS 1.3 session tickets the lifetime must not be longer than seven days. Expired session tickets cannot be used to resume a session.

Default: 1 day

Reimplemented from Botan::TLS::Policy.

Definition at line 220 of file tls_text_policy.cpp.

220 {
221 return get_duration("session_ticket_lifetime", Policy::session_ticket_lifetime());
222}
std::chrono::seconds get_duration(const std::string &key, std::chrono::seconds def) const

References get_duration(), and Botan::TLS::Policy::session_ticket_lifetime().

◆ set()

void Botan::TLS::Text_Policy::set ( const std::string & key,
const std::string & value )

Definition at line 252 of file tls_text_policy.cpp.

252 {
253 m_kv[key] = value;
254}

◆ set_value()

bool Botan::TLS::Text_Policy::set_value ( const std::string & key,
std::string_view val,
bool overwrite )
protected

Definition at line 381 of file tls_text_policy.cpp.

381 {
382 auto i = m_kv.find(key);
383
384 if(overwrite == false && i != m_kv.end()) {
385 return false;
386 }
387
388 m_kv.insert(i, std::make_pair(key, val));
389 return true;
390}

◆ srtp_profiles()

std::vector< uint16_t > Botan::TLS::Text_Policy::srtp_profiles ( ) const
overridevirtual

If this returns a non-empty vector, and DTLS is negotiated, then we will also attempt to negotiate the SRTP extension from RFC 5764 using the returned values as the profile ids.

Reimplemented from Botan::TLS::Policy.

Definition at line 232 of file tls_text_policy.cpp.

232 {
233 std::vector<uint16_t> r;
234 for(const auto& p : get_list("srtp_profiles", std::vector<std::string>())) {
235 if(const auto srtp = parse_u16(p)) {
236 r.push_back(srtp.value());
237 } else {
238 throw Invalid_Argument(fmt("Failed to parse input '{}' as a SRTP profile id", p));
239 }
240 }
241 return r;
242}
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
std::optional< uint16_t > parse_u16(std::string_view input, bool require_canonical)
Definition parsing.cpp:60

References Botan::fmt(), get_list(), and Botan::parse_u16().

◆ support_cert_status_message()

bool Botan::TLS::Text_Policy::support_cert_status_message ( ) const
overridevirtual

Indicates whether certificate status messages should be supported

Reimplemented from Botan::TLS::Policy.

Definition at line 128 of file tls_text_policy.cpp.

128 {
129 return get_bool("support_cert_status_message", Policy::support_cert_status_message());
130}

References get_bool(), and Botan::TLS::Policy::support_cert_status_message().

◆ tls_13_middlebox_compatibility_mode()

bool Botan::TLS::Text_Policy::tls_13_middlebox_compatibility_mode ( ) const
overridevirtual

Defines whether or not the middlebox compatibility mode should be used. Enabled by default.

RFC 8446 Appendix D.4 [This makes] the TLS 1.3 handshake resemble TLS 1.2 session resumption, which improves the chance of successfully connecting through middleboxes.

Default: true

Note
Has an effect on TLS 1.3 connections, only.

Reimplemented from Botan::TLS::Policy.

Definition at line 244 of file tls_text_policy.cpp.

244 {
245 return get_bool("tls_13_middlebox_compatibility_mode", Policy::tls_13_middlebox_compatibility_mode());
246}

References get_bool(), and Botan::TLS::Policy::tls_13_middlebox_compatibility_mode().

◆ to_string()

std::string Botan::TLS::Policy::to_string ( ) const
inherited

Convert this policy to a printable format. Same as calling print on a ostringstream and reading o.str()

Definition at line 802 of file tls_policy.cpp.

802 {
803 std::ostringstream oss;
804 this->print(oss);
805 return oss.str();
806}
virtual void print(std::ostream &o) const

References print().

◆ use_ecc_point_compression()

bool Botan::TLS::Text_Policy::use_ecc_point_compression ( ) const
overridevirtual

Request that ECC curve points are sent compressed

Signals that we prefer ECC points to be compressed when transmitted to us. The other party may not support ECC point compression and therefore may still send points uncompressed.

Note that the certificate used during authentication must also follow the other party's preference.

Note
Support for EC point compression is deprecated and will be removed in a future major release. TLS 1.3 does not support point compression at all (see RFC 8446 4.2.8.2)

Reimplemented from Botan::TLS::Policy.

Definition at line 55 of file tls_text_policy.cpp.

55 {
56 return get_bool("use_ecc_point_compression", Policy::use_ecc_point_compression());
57}
virtual bool use_ecc_point_compression() const

References get_bool(), and Botan::TLS::Policy::use_ecc_point_compression().


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