Botan 3.13.0
Crypto and TLS for C&
Botan::TLS::Callbacks Class Referenceabstract

#include <tls_callbacks.h>

Public Member Functions

virtual ~Callbacks ()=default
Mandatory

Those callbacks must be implemented by all applications that use TLS.

virtual void tls_emit_data (std::span< const uint8_t > data)=0
virtual void tls_record_received (uint64_t seq_no, std::span< const uint8_t > data)=0
virtual void tls_alert (Alert alert)=0
Informational

Override these to obtain deeper insights into the TLS connection. Throwing from any of these callbacks will result in the termination of the TLS connection.

virtual void tls_session_established (const Session_Summary &session)
virtual void tls_session_activated ()
virtual bool tls_peer_closed_connection ()
virtual bool tls_should_persist_resumption_information (const Session &session)
virtual void tls_verify_cert_chain (const std::vector< X509_Certificate > &cert_chain, const std::vector< std::optional< OCSP::Response > > &ocsp_responses, const std::vector< Certificate_Store * > &trusted_roots, Usage_Type usage, std::string_view hostname, const TLS::Policy &policy)
virtual void tls_verify_raw_public_key (const Public_Key &raw_public_key, Usage_Type usage, std::string_view hostname, const TLS::Policy &policy)
virtual std::chrono::milliseconds tls_verify_cert_chain_ocsp_timeout () const
virtual std::vector< uint8_t > tls_provide_cert_status (const std::vector< X509_Certificate > &chain, const Certificate_Status_Request &csr)
virtual std::vector< std::vector< uint8_t > > tls_provide_cert_chain_status (const std::vector< X509_Certificate > &chain, const Certificate_Status_Request &csr)
virtual std::vector< uint8_t > tls_sign_message (const Private_Key &key, RandomNumberGenerator &rng, std::string_view padding, Signature_Format format, const std::vector< uint8_t > &msg)
virtual bool tls_verify_message (const Public_Key &key, std::string_view padding, Signature_Format format, const std::vector< uint8_t > &msg, const std::vector< uint8_t > &sig)
virtual std::unique_ptr< Public_Keytls_deserialize_peer_public_key (const std::variant< TLS::Group_Params, DL_Group > &group, std::span< const uint8_t > key_bits)
virtual std::unique_ptr< Private_Keytls_kem_generate_key (TLS::Group_Params group, RandomNumberGenerator &rng)
virtual KEM_Encapsulation tls_kem_encapsulate (TLS::Group_Params group, const std::vector< uint8_t > &encoded_public_key, RandomNumberGenerator &rng, const Policy &policy)
virtual secure_vector< uint8_t > tls_kem_decapsulate (TLS::Group_Params group, const Private_Key &private_key, const std::vector< uint8_t > &encapsulated_bytes, RandomNumberGenerator &rng, const Policy &policy)
virtual std::unique_ptr< PK_Key_Agreement_Keytls_generate_ephemeral_key (const std::variant< TLS::Group_Params, DL_Group > &group, RandomNumberGenerator &rng)
virtual std::unique_ptr< PK_Key_Agreement_Keytls12_generate_ephemeral_ecdh_key (TLS::Group_Params group, RandomNumberGenerator &rng, EC_Point_Format tls12_ecc_pubkey_encoding_format)
virtual secure_vector< uint8_t > tls_ephemeral_key_agreement (const std::variant< TLS::Group_Params, DL_Group > &group, const PK_Key_Agreement_Key &private_key, const std::vector< uint8_t > &public_value, RandomNumberGenerator &rng, const Policy &policy)
virtual void tls_inspect_handshake_msg (const Handshake_Message &message)
virtual std::string tls_server_choose_app_protocol (const std::vector< std::string > &client_protos)
virtual void tls_modify_extensions (Extensions &extn, Connection_Side which_side, Handshake_Type which_message)
virtual void tls_examine_extensions (const Extensions &extn, Connection_Side which_side, Handshake_Type which_message)
virtual std::optional< OCSP::Responsetls_parse_ocsp_response (const std::vector< uint8_t > &raw_response)
virtual std::string tls_peer_network_identity ()
virtual std::chrono::system_clock::time_point tls_current_timestamp ()
virtual uint64_t tls_current_monotonic_clock_ms ()
virtual void tls_log_error (const char *err)
virtual void tls_log_debug (const char *what)
virtual void tls_log_debug_bin (const char *descr, const uint8_t val[], size_t val_len)
virtual void tls_ssl_key_log_data (std::string_view label, std::span< const uint8_t > client_random, std::span< const uint8_t > secret) const
virtual std::unique_ptr< KDFtls12_protocol_specific_kdf (std::string_view prf_algo) const

Detailed Description

Encapsulates the callbacks that a TLS channel will make which are due to channel specific operations.

Definition at line 57 of file tls_callbacks.h.

Constructor & Destructor Documentation

◆ ~Callbacks()

virtual Botan::TLS::Callbacks::~Callbacks ( )
virtualdefault

Member Function Documentation

◆ tls12_generate_ephemeral_ecdh_key()

std::unique_ptr< PK_Key_Agreement_Key > Botan::TLS::Callbacks::tls12_generate_ephemeral_ecdh_key ( TLS::Group_Params group,
RandomNumberGenerator & rng,
EC_Point_Format tls12_ecc_pubkey_encoding_format )
virtual

Generate an ECDH key pair for the TLS 1.2 handshake.

Note that this callback is called exclusively by TLS 1.2 to handle the ECDH public key serialization format explicitly. TLS 1.3 fixes this format to 'uncompressed' and does not allow negotiating anything else. X25519 and X448 feature a defined and fixed public key encoding and are therefore not explicitly handled by this callback either.

Users may override this if they want to provide a custom keypair type to offload TLS 1.2's ECDH handling to custom hardware, for instance. It is worth noting that support for compressed points in Botan is deprecated and this callback will disappear when it is removed in a future release.

Typical use cases of the library don't need to do that and serious security risks are associated with customizing TLS's key exchange mechanism.

Exceptions
TLS_Exception(Alert::DecodeError)if the group is not known.
Parameters
groupECDH group identifier to generate an ephemeral keypair for
Random Number Generatorsa random number generator
tls12_ecc_pubkey_encoding_formatthe key's serialization format
Returns
an ECDH private key of an algorithm usable for key agreement

Definition at line 409 of file tls_callbacks.cpp.

410 {
411 // Delegating to the "universal" callback to obtain an ECDH key pair
412 auto key = tls_generate_ephemeral_key(group, rng);
413
414 // For ordinary ECDH key pairs (that are derived from `ECDH_PublicKey`), we
415 // set the internal point encoding flag for the key before passing it on into
416 // the TLS 1.2 implementation. For user-defined keypair types (e.g. to
417 // offload to some crypto hardware) inheriting from Botan's `ECDH_PublicKey`
418 // might not be feasible. Such users should consider overriding this
419 // ECDH-specific callback and ensure that their custom class handles the
420 // public point encoding as requested by `tls12_ecc_pubkey_encoding_format`.
421 if(auto* ecc_key = dynamic_cast<ECDH_PublicKey*>(key.get())) {
422 ecc_key->set_point_encoding(tls12_ecc_pubkey_encoding_format);
423 }
424
425 return key;
426}
virtual std::unique_ptr< PK_Key_Agreement_Key > tls_generate_ephemeral_key(const std::variant< TLS::Group_Params, DL_Group > &group, RandomNumberGenerator &rng)

References tls_generate_ephemeral_key().

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

◆ tls12_protocol_specific_kdf()

std::unique_ptr< KDF > Botan::TLS::Callbacks::tls12_protocol_specific_kdf ( std::string_view prf_algo) const
virtual

Returns the key derivation function to be used for TLS 1.2

The default implementation can be overridden to provide a user-defined key derivation function, for example to delegate key derivation to a hardware-protected environment when a pre-shared key must remain inaccessible to the non-secure world.

Parameters
prf_algoname of the hash function (e.g. "SHA-256")
Returns
TLS 1.2 KDF implementation

Definition at line 492 of file tls_callbacks.cpp.

492 {
493 if(prf_algo == "MD5" || prf_algo == "SHA-1") {
494 return KDF::create_or_throw("TLS-12-PRF(SHA-256)");
495 }
496
497 return KDF::create_or_throw(Botan::fmt("TLS-12-PRF({})", prf_algo));
498}
static std::unique_ptr< KDF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition kdf.cpp:208
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::KDF::create_or_throw(), and Botan::fmt().

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

◆ tls_alert()

virtual void Botan::TLS::Callbacks::tls_alert ( Alert alert)
pure virtual

Mandatory callback: alert received

Called when an alert is received from the peer. If fatal, the connection is closing. If not fatal, the connection may still be closing (depending on the error and the peer).

Note that alerts received before the handshake is complete are not authenticated and could have been inserted by a MITM attacker.

References tls_session_established().

◆ tls_current_monotonic_clock_ms()

uint64_t Botan::TLS::Callbacks::tls_current_monotonic_clock_ms ( )
virtual

Optional callback: provide the current monotonic timer in milliseconds.

Used internally by DTLS for retransmit timer scheduling. The default implementation reads std::chrono::steady_clock. Override only to substitute a deterministic / virtual clock for testing; production code should not need to.

Definition at line 65 of file tls_callbacks.cpp.

65 {
66 const auto now = std::chrono::steady_clock::now().time_since_epoch();
67 return std::chrono::duration_cast<std::chrono::milliseconds>(now).count();
68}

Referenced by Botan::TLS::Channel_Impl_12::change_cipher_spec_reader(), and Botan::TLS::Channel_Impl_12::create_handshake_state().

◆ tls_current_timestamp()

std::chrono::system_clock::time_point Botan::TLS::Callbacks::tls_current_timestamp ( )
virtual

Optional callback: return a custom time stamp value

This allows the library user to specify a custom "now" timestamp when needed. By default it will use the current system clock time.

Note that typical usages will not need to override this callback but it is useful for testing purposes to allow for deterministic test outcomes.

TODO(Botan4) change return type to uint64_t

Definition at line 61 of file tls_callbacks.cpp.

61 {
62 return std::chrono::system_clock::now();
63}

Referenced by Botan::TLS::make_hello_random(), Botan::TLS::PSK::PSK(), Botan::TLS::Session_Manager::retrieve(), and tls_verify_cert_chain().

◆ tls_deserialize_peer_public_key()

std::unique_ptr< Public_Key > Botan::TLS::Callbacks::tls_deserialize_peer_public_key ( const std::variant< TLS::Group_Params, DL_Group > & group,
std::span< const uint8_t > key_bits )
virtual

Optional callback: deserialize a public key received from the peer

Default implementation simply parses the public key using Botan's public keys. Override to provide a different approach, e.g. using an external device.

If deserialization fails, the default implementation throws a Botan::Decoding_Error exception that will be translated into a TLS_Exception with an Alert::IllegalParameter.

Parameters
groupthe group identifier or (in case of TLS 1.2) an explicit discrete-log group of the public key
key_bitsthe serialized public key
Returns
the deserialized and ready-to-use public key

Definition at line 196 of file tls_callbacks.cpp.

197 {
198 if(is_dh_group(group)) {
199 // TLS 1.2 allows specifying arbitrary DL_Group parameters in-lieu of
200 // a standardized DH group identifier.
201 const auto dl_group = get_dl_group(group);
202
203 auto Y = BigInt::from_bytes(key_bits);
204
205 /*
206 * A basic check for key validity. As we do not know q here we
207 * cannot check that Y is in the right subgroup. However since
208 * our key is ephemeral there does not seem to be any
209 * advantage to bogus keys anyway.
210 */
211 if(Y <= 1 || Y >= dl_group.get_p() - 1) {
212 throw Decoding_Error("Server sent bad DH key for DHE exchange");
213 }
214
215 return std::make_unique<DH_PublicKey>(dl_group, Y);
216 }
217
218 // The special case for TLS 1.2 with an explicit DH group definition is
219 // handled above. All other cases are based on the opaque group definition.
220 BOTAN_ASSERT_NOMSG(std::holds_alternative<TLS::Group_Params>(group));
221 const auto group_params = std::get<TLS::Group_Params>(group);
222
223 if(group_params.is_ecdh_named_curve()) {
224 const auto ec_group = EC_Group::from_name(group_params.to_algorithm_spec().value());
225 // TLS 1.3 requires uncompressed points (checked when parsing the key
226 // share); TLS 1.2 may negotiate the compressed format. The deprecated
227 // hybrid encoding and the identity element are never accepted.
228
229 auto point = [&]() -> EC_AffinePoint {
230 if(auto pt_uncompressed = EC_AffinePoint::deserialize_uncompressed(ec_group, key_bits)) {
231 return std::move(pt_uncompressed).value();
232 } else if(auto pt_compressed = EC_AffinePoint::deserialize_compressed(ec_group, key_bits)) {
233 return std::move(pt_compressed).value();
234 } else {
235 throw Decoding_Error("Invalid ECDH public key encoding");
236 }
237 }();
238 return std::make_unique<ECDH_PublicKey>(ec_group, std::move(point));
239 }
240
241#if defined(BOTAN_HAS_X25519)
242 if(group_params.is_x25519()) {
243 return std::make_unique<X25519_PublicKey>(key_bits);
244 }
245#endif
246
247#if defined(BOTAN_HAS_X448)
248 if(group_params.is_x448()) {
249 return std::make_unique<X448_PublicKey>(key_bits);
250 }
251#endif
252
253#if defined(BOTAN_HAS_TLS_13_PQC)
254 if(group_params.is_pqc_hybrid()) {
255 return Hybrid_KEM_PublicKey::load_for_group(group_params, key_bits);
256 }
257#endif
258
259#if defined(BOTAN_HAS_ML_KEM)
260 if(group_params.is_pure_ml_kem()) {
261 return std::make_unique<ML_KEM_PublicKey>(key_bits, ML_KEM_Mode(group_params.to_algorithm_spec().value()));
262 }
263#endif
264
265#if defined(BOTAN_HAS_FRODOKEM)
266 if(group_params.is_pure_frodokem()) {
267 return std::make_unique<FrodoKEM_PublicKey>(key_bits, FrodoKEMMode(group_params.to_algorithm_spec().value()));
268 }
269#endif
270
271 throw Decoding_Error("cannot create a key offering without a group definition");
272}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75
static BigInt from_bytes(std::span< const uint8_t > bytes)
Definition bigint.cpp:83
static std::optional< EC_AffinePoint > deserialize_uncompressed(const EC_Group &group, std::span< const uint8_t > bytes)
static std::optional< EC_AffinePoint > deserialize_compressed(const EC_Group &group, std::span< const uint8_t > bytes)
static EC_Group from_name(std::string_view name)
Definition ec_group.cpp:478
static std::unique_ptr< Hybrid_KEM_PublicKey > load_for_group(Group_Params group, std::span< const uint8_t > concatenated_public_values)
KyberMode ML_KEM_Mode
Definition ml_kem.h:21

References BOTAN_ASSERT_NOMSG, Botan::EC_AffinePoint::deserialize_compressed(), Botan::EC_AffinePoint::deserialize_uncompressed(), Botan::BigInt::from_bytes(), Botan::EC_Group::from_name(), and Botan::TLS::Hybrid_KEM_PublicKey::load_for_group().

Referenced by tls_ephemeral_key_agreement(), and tls_kem_encapsulate().

◆ tls_emit_data()

virtual void Botan::TLS::Callbacks::tls_emit_data ( std::span< const uint8_t > data)
pure virtual

Mandatory callback: output function

The channel will call this with data which needs to be sent to the peer (eg, over a socket or some other form of IPC). The array will be overwritten when the function returns so a copy must be made if the data cannot be sent immediately.

As an example you could use the syscall send to perform a blocking write on a socket, or append the data to a queue managed by your application and initiate an asynchronous write.

For TLS all writes must occur in the order requested. For DTLS this ordering is not strictly required, but is still recommended.

Parameters
dataa contiguous data buffer to send

◆ tls_ephemeral_key_agreement()

secure_vector< uint8_t > Botan::TLS::Callbacks::tls_ephemeral_key_agreement ( const std::variant< TLS::Group_Params, DL_Group > & group,
const PK_Key_Agreement_Key & private_key,
const std::vector< uint8_t > & public_value,
RandomNumberGenerator & rng,
const Policy & policy )
virtual

Agree on a shared secret with the peer's ephemeral public key for the TLS handshake.

Applications may use this to add custom groups, curves or entirely different ephemeral key agreement mechanisms to the TLS handshake. Note that this callback must be used in conjunction with Callbacks::tls_generate_ephemeral_key.

Typical use cases of the library don't need to do that and serious security risks are associated with customizing TLS's key exchange mechanism.

Parameters
groupthe TLS group identifier to be used TLS 1.2 allows for specifying custom discrete logarithm parameters as part of the protocol. Hence the variant<>.
private_keythe private key (generated ahead in tls_generate_ephemeral_key)
public_valuethe public key exchange information received by the peer
Random Number Generatorsa random number generator
policya TLS policy object
Returns
the shared secret derived from public_value and private_key

TODO(Botan4) change public_value to a std::span

Definition at line 428 of file tls_callbacks.cpp.

433 {
434 const auto kex_pub_key = [&]() {
435 try {
436 return tls_deserialize_peer_public_key(group, public_value);
437 } catch(const Decoding_Error& ex) {
438 // This exception means that the public key was invalid. However,
439 // TLS' DecodeError would imply that a protocol message was invalid.
440 throw TLS_Exception(Alert::IllegalParameter, ex.what());
441 } catch(const Invalid_Argument& ex) {
442 throw TLS_Exception(Alert::IllegalParameter, ex.what());
443 }
444 }();
445
446 BOTAN_ASSERT_NONNULL(kex_pub_key);
447 policy.check_peer_key_acceptable(*kex_pub_key);
448
449 // RFC 8422 - 5.11.
450 // With X25519 and X448, a receiving party MUST check whether the
451 // computed premaster secret is the all-zero value and abort the
452 // handshake if so, as described in Section 6 of [RFC7748].
453 //
454 // This is done within the key agreement operation and throws
455 // an Invalid_Argument exception if the shared secret is all-zero.
456 try {
457 const PK_Key_Agreement ka(private_key, rng, "Raw");
458 return ka.derive_key(0, kex_pub_key->raw_public_key_bits()).bits_of();
459 } catch(const Invalid_Argument& ex) {
460 throw TLS_Exception(Alert::IllegalParameter, ex.what());
461 }
462}
#define BOTAN_ASSERT_NONNULL(ptr)
Definition assert.h:114
virtual std::unique_ptr< Public_Key > tls_deserialize_peer_public_key(const std::variant< TLS::Group_Params, DL_Group > &group, std::span< const uint8_t > key_bits)

References Botan::OctetString::bits_of(), BOTAN_ASSERT_NONNULL, Botan::TLS::Policy::check_peer_key_acceptable(), Botan::PK_Key_Agreement::derive_key(), tls_deserialize_peer_public_key(), and Botan::Exception::what().

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), tls_kem_decapsulate(), and tls_kem_encapsulate().

◆ tls_examine_extensions()

void Botan::TLS::Callbacks::tls_examine_extensions ( const Extensions & extn,
Connection_Side which_side,
Handshake_Type which_message )
virtual

Optional callback: examine peer extensions.

Both client and server will call this callback with the Extensions object after receiving it from the peer. This allows examining the Extensions, for example to implement a custom extension. It also allows an application to require that a particular extension be implemented; throw an exception from this function to abort the handshake.

Default implementation does nothing.

Parameters
extnthe extensions
which_sidewill be Connection_Side::Client if these are are the clients extensions (ie we are the server) or Connection_Side::Server if these are the server extensions (we are the client).
which_messagewill state the handshake message type containing the extensions

Definition at line 74 of file tls_callbacks.cpp.

76 {}

Referenced by Botan::TLS::Certificate_13::validate_extensions().

◆ tls_generate_ephemeral_key()

std::unique_ptr< PK_Key_Agreement_Key > Botan::TLS::Callbacks::tls_generate_ephemeral_key ( const std::variant< TLS::Group_Params, DL_Group > & group,
RandomNumberGenerator & rng )
virtual

Generate an ephemeral key pair for the TLS handshake.

Applications may use this to add custom groups, curves or entirely different ephemeral key agreement mechanisms to the TLS handshake. Note that this callback must be used in conjunction with Callbacks::tls_ephemeral_key_agreement.

Typical use cases of the library don't need to do that and serious security risks are associated with customizing TLS's key exchange mechanism.

Exceptions
TLS_Exception(Alert::DecodeError)if the group is not known.
Parameters
groupthe group identifier to generate an ephemeral keypair for TLS 1.2 allows for specifying custom discrete logarithm parameters as part of the protocol. Hence the variant<>.
Random Number Generatorsa random number generator
Returns
a private key of an algorithm usable for key agreement

Definition at line 361 of file tls_callbacks.cpp.

362 {
363 if(is_dh_group(group)) {
364 const DL_Group dl_group = get_dl_group(group);
365 return std::make_unique<DH_PrivateKey>(rng, dl_group);
366 }
367
368 BOTAN_ASSERT_NOMSG(std::holds_alternative<TLS::Group_Params>(group));
369 const auto group_params = std::get<TLS::Group_Params>(group);
370
371 if(group_params.is_ecdh_named_curve()) {
372 const auto ec_group = EC_Group::from_name(group_params.to_algorithm_spec().value());
373 auto ecdh_key = std::make_unique<ECDH_PrivateKey>(rng, ec_group);
374
375 // RFC 8446 Ch. 4.2.8.2
376 //
377 // Note: Versions of TLS prior to 1.3 permitted point format
378 // negotiation; TLS 1.3 removes this feature in favor of a single point
379 // format for each curve.
380 //
381 // Hence, TLS 1.3 won't take Policy::use_ecc_point_compression() or
382 // ClientHello::prefers_compressed_ec_points() into account but always use
383 // uncompressed point encoding. Note that TLS 1.2 uses the
384 // `tls12_generate_ephemeral_ecdh_key()` callback, which allows to specify
385 // the point encoding format.
386 ecdh_key->set_point_encoding(EC_Point_Format::Uncompressed);
387 return ecdh_key;
388 }
389
390#if defined(BOTAN_HAS_X25519)
391 if(group_params.is_x25519()) {
392 return std::make_unique<X25519_PrivateKey>(rng);
393 }
394#endif
395
396#if defined(BOTAN_HAS_X448)
397 if(group_params.is_x448()) {
398 return std::make_unique<X448_PrivateKey>(rng);
399 }
400#endif
401
402 if(group_params.is_kem()) {
403 throw TLS_Exception(Alert::IllegalParameter, "cannot generate an ephemeral KEX key for a KEM");
404 }
405
406 throw TLS_Exception(Alert::DecodeError, "cannot create a key offering without a group definition");
407}

References BOTAN_ASSERT_NOMSG, Botan::EC_Group::from_name(), and Botan::Uncompressed.

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), tls12_generate_ephemeral_ecdh_key(), tls_kem_encapsulate(), and tls_kem_generate_key().

◆ tls_inspect_handshake_msg()

void Botan::TLS::Callbacks::tls_inspect_handshake_msg ( const Handshake_Message & message)
virtual

Optional callback: inspect handshake message Throw an exception to abort the handshake. Default simply ignores the message.

Note: On connections that negotiated TLS 1.3 this callback is also invoked for post-handshake messages.

Parameters
messagethe handshake message

Definition at line 49 of file tls_callbacks.cpp.

49 {
50 // default is no op
51}

◆ tls_kem_decapsulate()

secure_vector< uint8_t > Botan::TLS::Callbacks::tls_kem_decapsulate ( TLS::Group_Params group,
const Private_Key & private_key,
const std::vector< uint8_t > & encapsulated_bytes,
RandomNumberGenerator & rng,
const Policy & policy )
virtual

Performs a key decapsulation operation (used for TLS 1.3 clients).

Applications may use this to add custom KEM algorithms or entirely different key exchange schemes to the TLS 1.3 handshake. For instance, this could provide an entry point to implement a hybrid key exchange with both a traditional algorithm like ECDH and a quantum-secure KEM. Typical use cases of the library don't need to do that and serious security risks are associated with customizing TLS's key encapsulation mechanism.

Note that the KEM interface is usable for TLS 1.3 handshakes, only.

The default implementation simply delegates this to the tls_ephemeral_key_agreement() callback to obtain the shared secret.

Parameters
groupthe group identifier of the KEM/KEX algorithm
private_keythe private key used for decapsulation/KEX
encapsulated_bytesthe content to decapsulate (or the public key share)
Random Number Generatorsa random number generator
policya TLS policy object
Returns
the plaintext shared secret from encapsulated_bytes after decapsulation with private_key.

TODO(Botan4) change encapsulated_bytes to a std::span

Definition at line 334 of file tls_callbacks.cpp.

338 {
339 if(group.is_kem()) {
340 PK_KEM_Decryptor kemdec(private_key, rng, "Raw");
341 if(encapsulated_bytes.size() != kemdec.encapsulated_key_length()) {
342 throw TLS_Exception(Alert::IllegalParameter, "Invalid encapsulated key length");
343 }
344 try {
345 return kemdec.decrypt(encapsulated_bytes, 0, {});
346 } catch(const Decoding_Error& ex) {
347 throw TLS_Exception(Alert::IllegalParameter, ex.what());
348 } catch(const Invalid_Argument& ex) {
349 throw TLS_Exception(Alert::IllegalParameter, ex.what());
350 }
351 }
352
353 try {
354 const auto& key_agreement_key = dynamic_cast<const PK_Key_Agreement_Key&>(private_key);
355 return tls_ephemeral_key_agreement(group, key_agreement_key, encapsulated_bytes, rng, policy);
356 } catch(const std::bad_cast&) {
357 throw Invalid_Argument("provided ephemeral key is not a PK_Key_Agreement_Key");
358 }
359}
virtual secure_vector< uint8_t > tls_ephemeral_key_agreement(const std::variant< TLS::Group_Params, DL_Group > &group, const PK_Key_Agreement_Key &private_key, const std::vector< uint8_t > &public_value, RandomNumberGenerator &rng, const Policy &policy)

References Botan::PK_KEM_Decryptor::decrypt(), Botan::PK_KEM_Decryptor::encapsulated_key_length(), Botan::TLS::Group_Params::is_kem(), tls_ephemeral_key_agreement(), and Botan::Exception::what().

◆ tls_kem_encapsulate()

KEM_Encapsulation Botan::TLS::Callbacks::tls_kem_encapsulate ( TLS::Group_Params group,
const std::vector< uint8_t > & encoded_public_key,
RandomNumberGenerator & rng,
const Policy & policy )
virtual

Performs a key encapsulation operation (used for TLS 1.3 servers)

Applications may use this to add custom KEM algorithms or entirely different key exchange schemes to the TLS 1.3 handshake. For instance, this could provide an entry point to implement a hybrid key exchange with both a traditional algorithm like ECDH and a quantum-secure KEM. Typical use cases of the library don't need to do that and serious security risks are associated with customizing TLS's key encapsulation mechanism.

Note that the KEM interface is usable for TLS 1.3 handshakes, only.

The default implementation implements this key encapsulation as a combination of tls_generate_ephemeral_key() followed by tls_ephemeral_key_agreement() with the provided encoded_public_key. The just-generated ephemeral private key is destroyed immediately.

Parameters
groupthe group identifier of the KEM/KEX algorithm
encoded_public_keythe public key used for encapsulation/KEX
Random Number Generatorsa random number generator
policya TLS policy object
Returns
the shared secret both in plaintext and encapsulated with encoded_public_key.

TODO(Botan4) change this return type to something else so the pubkey.h dependency is removed TODO(Botan4) change encoded_public_key to a span

Definition at line 296 of file tls_callbacks.cpp.

299 {
300 if(group.is_kem()) {
301 auto kem_pub_key = [&] {
302 try {
303 return tls_deserialize_peer_public_key(group, encoded_public_key);
304 } catch(const Decoding_Error& ex) {
305 // This exception means that the public key was invalid. However,
306 // TLS' DecodeError would imply that a protocol message was invalid.
307 throw TLS_Exception(Alert::IllegalParameter, ex.what());
308 } catch(const Invalid_Argument& ex) {
309 throw TLS_Exception(Alert::IllegalParameter, ex.what());
310 }
311 }();
312
313 BOTAN_ASSERT_NONNULL(kem_pub_key);
314 policy.check_peer_key_acceptable(*kem_pub_key);
315
316 try {
317 return PK_KEM_Encryptor(*kem_pub_key, "Raw").encrypt(rng);
318 } catch(const Decoding_Error& ex) {
319 throw TLS_Exception(Alert::IllegalParameter, ex.what());
320 } catch(const Invalid_Argument& ex) {
321 throw TLS_Exception(Alert::IllegalParameter, ex.what());
322 }
323 } else {
324 // TODO: We could use the KEX_to_KEM_Adapter to remove the case distinction
325 // of KEM and KEX. However, the workarounds in this adapter class
326 // should first be addressed.
327 auto ephemeral_keypair = tls_generate_ephemeral_key(group, rng);
328 BOTAN_ASSERT_NONNULL(ephemeral_keypair);
329 return {ephemeral_keypair->public_value(),
330 tls_ephemeral_key_agreement(group, *ephemeral_keypair, encoded_public_key, rng, policy)};
331 }
332}

References BOTAN_ASSERT_NONNULL, Botan::TLS::Policy::check_peer_key_acceptable(), Botan::PK_KEM_Encryptor::encrypt(), Botan::TLS::Group_Params::is_kem(), tls_deserialize_peer_public_key(), tls_ephemeral_key_agreement(), tls_generate_ephemeral_key(), and Botan::Exception::what().

◆ tls_kem_generate_key()

std::unique_ptr< Private_Key > Botan::TLS::Callbacks::tls_kem_generate_key ( TLS::Group_Params group,
RandomNumberGenerator & rng )
virtual

Generate an ephemeral KEM key for a TLS 1.3 handshake

Applications may use this to add custom KEM algorithms or entirely different key exchange schemes to the TLS 1.3 handshake. For instance, this could provide an entry point to implement a hybrid key exchange with both a traditional algorithm like ECDH and a quantum-secure KEM. Typical use cases of the library don't need to do that and serious security risks are associated with customizing TLS's key encapsulation mechanism.

Note that the KEM interface is usable for TLS 1.3 handshakes, only.

The default implementation simply delegates this to the tls_generate_ephemeral_key() call when appropriate.

Parameters
groupthe group identifier to generate an ephemeral keypair for
Random Number Generatorsa random number generator
Returns
a keypair whose public key will be provided to the peer and the private key will be provided to tls_kem_decapsulate later in the handshake.

Definition at line 274 of file tls_callbacks.cpp.

274 {
275#if defined(BOTAN_HAS_ML_KEM)
276 if(group.is_pure_ml_kem()) {
277 return std::make_unique<ML_KEM_PrivateKey>(rng, ML_KEM_Mode(group.to_algorithm_spec().value()));
278 }
279#endif
280
281#if defined(BOTAN_HAS_FRODOKEM)
282 if(group.is_pure_frodokem()) {
283 return std::make_unique<FrodoKEM_PrivateKey>(rng, FrodoKEMMode(group.to_algorithm_spec().value()));
284 }
285#endif
286
287#if defined(BOTAN_HAS_TLS_13_PQC)
288 if(group.is_pqc_hybrid()) {
290 }
291#endif
292
293 return tls_generate_ephemeral_key(group, rng);
294}
static std::unique_ptr< Hybrid_KEM_PrivateKey > generate_from_group(Group_Params group, RandomNumberGenerator &rng)

References Botan::TLS::Hybrid_KEM_PrivateKey::generate_from_group(), Botan::TLS::Group_Params::is_pqc_hybrid(), Botan::TLS::Group_Params::is_pure_frodokem(), Botan::TLS::Group_Params::is_pure_ml_kem(), tls_generate_ephemeral_key(), and Botan::TLS::Group_Params::to_algorithm_spec().

◆ tls_log_debug()

void Botan::TLS::Callbacks::tls_log_debug ( const char * what)
virtual

Optional callback: debug logging. (not currently called)

Parameters
whatSome hopefully informative string

TODO(Botan4) remove this

Definition at line 478 of file tls_callbacks.cpp.

478 {
479 BOTAN_UNUSED(what);
480}
#define BOTAN_UNUSED
Definition assert.h:144

References BOTAN_UNUSED.

◆ tls_log_debug_bin()

void Botan::TLS::Callbacks::tls_log_debug_bin ( const char * descr,
const uint8_t val[],
size_t val_len )
virtual

Optional callback: debug logging taking a buffer. (not currently called)

Parameters
descrWhat this buffer is
valthe bytes
val_lenlength of val

TODO(Botan4) remove this

Definition at line 482 of file tls_callbacks.cpp.

482 {
483 BOTAN_UNUSED(descr, val, val_len);
484}

References BOTAN_UNUSED.

◆ tls_log_error()

void Botan::TLS::Callbacks::tls_log_error ( const char * err)
virtual

Optional callback: error logging. (not currently called)

Parameters
errAn error message related to this connection.

TODO(Botan4) remove this

Definition at line 474 of file tls_callbacks.cpp.

474 {
475 BOTAN_UNUSED(err);
476}

References BOTAN_UNUSED.

◆ tls_modify_extensions()

void Botan::TLS::Callbacks::tls_modify_extensions ( Extensions & extn,
Connection_Side which_side,
Handshake_Type which_message )
virtual

Optional callback: examine/modify Extensions before sending.

Both client and server will call this callback on the Extensions object before serializing it in the specific handshake message. This allows an application to modify which extensions are sent during the handshake.

Default implementation does nothing.

Parameters
extnthe extensions
which_sidewill be Connection_Side::Client or Connection_Side::Server which is the current applications role in the exchange.
which_messagewill state the handshake message type containing the extensions

Definition at line 70 of file tls_callbacks.cpp.

72 {}

Referenced by Botan::TLS::Client_Hello_12::Client_Hello_12(), Botan::TLS::Client_Hello_12::Client_Hello_12(), Botan::TLS::Client_Hello_13::Client_Hello_13(), Botan::TLS::Encrypted_Extensions::Encrypted_Extensions(), Botan::TLS::Hello_Retry_Request::Hello_Retry_Request(), Botan::TLS::New_Session_Ticket_13::New_Session_Ticket_13(), and Botan::TLS::Client_Hello_13::retry().

◆ tls_parse_ocsp_response()

std::optional< OCSP::Response > Botan::TLS::Callbacks::tls_parse_ocsp_response ( const std::vector< uint8_t > & raw_response)
virtual

Optional callback: parse a single OCSP Response

Note: Typically a user of the library would not want to override this callback. We provide this callback to be able to support OCSP related tests from BoringSSL's BoGo tests that provide unparsable responses.

Default implementation tries to parse the provided raw OCSP response.

This function should not throw an exception but return a std::nullopt if the OCSP response cannot be parsed.

Parameters
raw_responseraw OCSP response buffer
Returns
the parsed OCSP response or std::nullopt on error

TODO(Botan4) change raw_response to a std::span

Definition at line 137 of file tls_callbacks.cpp.

137 {
138 try {
139 return OCSP::Response(raw_response);
140 } catch(const Decoding_Error&) {
141 // ignore parsing errors and just ignore the broken OCSP response
142 return std::nullopt;
143 }
144}

◆ tls_peer_closed_connection()

virtual bool Botan::TLS::Callbacks::tls_peer_closed_connection ( )
inlinevirtual

Optional callback: peer closed connection (sent a "close_notify" alert)

The peer signaled that it wishes to shut down the connection. The application should not expect to receive any more data from the peer and may tear down the underlying transport socket.

Prior to TLS 1.3 it was required that peers discard pending writes and immediately respond with their own "close_notify". With TLS 1.3, applications can continue to send data despite the peer having already signaled their wish to shut down.

Returning true will cause the TLS 1.3 implementation to write all pending data and then also signal a connection shut down. Otherwise the application is responsible to call the Channel::close() method.

For TLS 1.2 the return value has no effect.

Returns
true causes the implementation to respond with a "close_notify"

Definition at line 176 of file tls_callbacks.h.

176{ return true; }

◆ tls_peer_network_identity()

std::string Botan::TLS::Callbacks::tls_peer_network_identity ( )
virtual

Callback: return peer network identity

There is no expected or specified format. The only expectation is this function will return a unique value. For example returning the peer host IP and port.

This is used to bind the DTLS cookie to a particular network identity (RFC 6347 4.2.1 / RFC 9147 11: "the cookie MUST depend on the client's address"). DTLS servers MUST override this to return a non-empty value; the default empty implementation will cause cookie verification to throw.

Definition at line 57 of file tls_callbacks.cpp.

57 {
58 return "";
59}

◆ tls_provide_cert_chain_status()

std::vector< std::vector< uint8_t > > Botan::TLS::Callbacks::tls_provide_cert_chain_status ( const std::vector< X509_Certificate > & chain,
const Certificate_Status_Request & csr )
virtual

Called by TLS 1.3 client or server whenever the peer indicated that OCSP stapling is supported. In contrast to tls_provide_cert_status, this allows providing OCSP responses for each certificate in the chain.

The default implementation invokes tls_provide_cert_status assuming that no OCSP responses for intermediate certificates are available.

Returns
a vector of OCSP response buffers. An empty buffer indicates that no OCSP response should be provided for the respective certificate (at the same list index). The returned vector MUST be exactly the same length as the incoming chain.

Definition at line 146 of file tls_callbacks.cpp.

147 {
148 std::vector<std::vector<uint8_t>> result(chain.size());
149 if(!chain.empty()) {
150 result[0] = tls_provide_cert_status(chain, csr);
151 }
152 return result;
153}
virtual std::vector< uint8_t > tls_provide_cert_status(const std::vector< X509_Certificate > &chain, const Certificate_Status_Request &csr)

References tls_provide_cert_status().

◆ tls_provide_cert_status()

std::vector< uint8_t > Botan::TLS::Callbacks::tls_provide_cert_status ( const std::vector< X509_Certificate > & chain,
const Certificate_Status_Request & csr )
virtual

Called by the TLS server whenever the client included the status_request extension (see RFC 6066, a.k.a OCSP stapling) in the ClientHello.

Returns
the encoded OCSP response to be sent to the client which indicates the revocation status of the server certificate. Return an empty vector to indicate that no response is available, and thus suppress the Certificate_Status message.

Default implementation returns an empty vector, disabling certificate status

Definition at line 468 of file tls_callbacks.cpp.

469 {
470 BOTAN_UNUSED(chain, csr);
471 return std::vector<uint8_t>();
472}

References BOTAN_UNUSED.

Referenced by tls_provide_cert_chain_status().

◆ tls_record_received()

virtual void Botan::TLS::Callbacks::tls_record_received ( uint64_t seq_no,
std::span< const uint8_t > data )
pure virtual

Mandatory callback: process application data

Called when application data record is received from the peer. The array is overwritten immediately after the function returns.

Currently empty records are ignored and do not instigate a callback, but this may change in a future release.

For TLS the record number will always increase. For DTLS, it is possible to receive records with the seq_no field out of order, or with gaps, corresponding to reordered or lost datagrams.

Parameters
seq_nothe underlying TLS/DTLS record sequence number
dataa contiguous data buffer containing the received record

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

◆ tls_server_choose_app_protocol()

std::string Botan::TLS::Callbacks::tls_server_choose_app_protocol ( const std::vector< std::string > & client_protos)
virtual

Optional callback for server: choose ALPN protocol

ALPN (RFC 7301) works by the client sending a list of application protocols it is willing to negotiate. The server then selects which protocol to use. RFC 7301 requires that if the server does not support any protocols offered by the client, then it should close the connection with an alert of no_application_protocol. Within this callback this would be done by throwing a TLS_Exception(Alert::NoApplicationProtocol)

Parameters
client_protosthe vector of protocols the client is willing to negotiate
Returns
the protocol selected by the server; if the empty string is returned, the server does not reply to the client ALPN extension.

The default implementation returns the empty string, causing client ALPN to be ignored.

It is highly recommended to support ALPN whenever possible to avoid cross-protocol attacks.

Definition at line 53 of file tls_callbacks.cpp.

53 {
54 return "";
55}

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

◆ tls_session_activated()

virtual void Botan::TLS::Callbacks::tls_session_activated ( )
inlinevirtual

Optional callback: session activated

By default does nothing. This is called when the session is activated, that is once it is possible to send or receive data on the channel. In particular it is possible for an implementation of this function to perform an initial write on the channel.

Definition at line 154 of file tls_callbacks.h.

154{}

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

◆ tls_session_established()

void Botan::TLS::Callbacks::tls_session_established ( const Session_Summary & session)
virtual

Optional callback: session established

Called whenever a negotiation completes. This can happen more than once on TLS 1.2 connections, if renegotiation occurs. The session parameter provides information about the session which was just established.

If this function wishes to cancel the handshake, it can throw an exception which will send a close message to the counterparty and reset the connection state.

Parameters
sessionthe session descriptor

Definition at line 464 of file tls_callbacks.cpp.

464 {
465 BOTAN_UNUSED(session);
466}

References BOTAN_UNUSED.

Referenced by tls_alert().

◆ tls_should_persist_resumption_information()

bool Botan::TLS::Callbacks::tls_should_persist_resumption_information ( const Session & session)
virtual

Optional callback: Resumption information was received/established

TLS 1.3 calls this when we sent or received a TLS 1.3 session ticket at any point after the initial handshake has finished.

TLS 1.2 calls this when a session was established successfully and its resumption information may be stored for later usage.

Note that for servers this is called as soon as resumption information is available and could be sent to the client. If this callback returns 'false', the information will neither be cached nor sent.

Parameters
sessionthe session descriptor
Returns
false to prevent the resumption information from being cached, and true to cache it in the configured Session_Manager

Definition at line 78 of file tls_callbacks.cpp.

78 {
79 // RFC 5077 3.3
80 // The ticket_lifetime_hint field contains a hint from the server about
81 // how long the ticket should be stored. A value of zero is reserved to
82 // indicate that the lifetime of the ticket is unspecified.
83 //
84 // RFC 8446 4.6.1
85 // [A ticket_lifetime] of zero indicates that the ticket should be discarded
86 // immediately.
87 //
88 // By default we opt to keep all sessions, except for TLS 1.3 with a lifetime
89 // hint of zero.
90 return session.lifetime_hint().count() > 0 || session.version().is_pre_tls_13();
91}

References Botan::TLS::Protocol_Version::is_pre_tls_13(), Botan::TLS::Session::lifetime_hint(), and Botan::TLS::Session_Base::version().

◆ tls_sign_message()

std::vector< uint8_t > Botan::TLS::Callbacks::tls_sign_message ( const Private_Key & key,
RandomNumberGenerator & rng,
std::string_view padding,
Signature_Format format,
const std::vector< uint8_t > & msg )
virtual

Optional callback with default impl: sign a message

Default implementation uses PK_Signer::sign_message(). Override to provide a different approach, e.g. using an external device.

Parameters
keythe private key of the signer
Random Number Generatorsa random number generator
paddingthe encoding method to be applied to the message
formatthe signature format
msgthe input data for the signature
Returns
the signature

Definition at line 155 of file tls_callbacks.cpp.

159 {
160 PK_Signer signer(key, rng, padding, format);
161
162 return signer.sign_message(msg, rng);
163}

References Botan::PK_Signer::sign_message().

Referenced by Botan::TLS::Certificate_Verify_12::Certificate_Verify_12(), Botan::TLS::Certificate_Verify_13::Certificate_Verify_13(), and Botan::TLS::Server_Key_Exchange::Server_Key_Exchange().

◆ tls_ssl_key_log_data()

void Botan::TLS::Callbacks::tls_ssl_key_log_data ( std::string_view label,
std::span< const uint8_t > client_random,
std::span< const uint8_t > secret ) const
virtual

Optional callback: Allows access to a connection's secret data

Useful to implement the SSLKEYLOGFILE for connection debugging as specified in ietf.org/archive/id/draft-thomson-tls-keylogfile-00.html

Invoked if Policy::allow_ssl_key_log_file returns true.

Default implementation simply ignores the inputs.

Parameters
labelIdentifies the reported secret type See draft-thomson-tls-keylogfile-00 Section 3.1 and 3.2
client_randomrandom value from ClientHello message acting as an identifier of the TLS sessions
secretthe actual secret value

Definition at line 486 of file tls_callbacks.cpp.

488 {
489 BOTAN_UNUSED(label, client_random, secret);
490}

References BOTAN_UNUSED.

◆ tls_verify_cert_chain()

void Botan::TLS::Callbacks::tls_verify_cert_chain ( const std::vector< X509_Certificate > & cert_chain,
const std::vector< std::optional< OCSP::Response > > & ocsp_responses,
const std::vector< Certificate_Store * > & trusted_roots,
Usage_Type usage,
std::string_view hostname,
const TLS::Policy & policy )
virtual

Optional callback with default impl: verify cert chain

Default implementation performs a standard PKIX validation and initiates network OCSP request for end-entity cert. Override to provide different behavior.

Check the certificate chain is valid up to a trusted root, and optionally (if hostname != "") that the hostname given is consistent with the leaf certificate.

This function should throw an exception derived from std::exception with an informative what() result if the certificate chain cannot be verified.

Parameters
cert_chainspecifies a certificate chain leading to a trusted root CA certificate.
ocsp_responsesthe server may have provided some
trusted_rootsthe list of trusted certificates
usagewhat this cert chain is being used for Usage_Type::TLS_SERVER_AUTH for server chains, Usage_Type::TLS_CLIENT_AUTH for client chains, Usage_Type::UNSPECIFIED for other uses
hostnamewhen authenticating a server, this is the hostname the client requested (eg via SNI). When authenticating a client, this is the server name the client is authenticating to. Empty in other cases or if no hostname was used.
policythe TLS policy associated with the session being authenticated using the certificate chain

Definition at line 93 of file tls_callbacks.cpp.

98 {
99 if(cert_chain.empty()) {
100 throw Invalid_Argument("Certificate chain was empty");
101 }
102
103 const Path_Validation_Restrictions restrictions(policy.require_cert_revocation_info(),
104 policy.minimum_signature_strength());
105
106 /*
107 Hostname is always provided in order to allow host-specific logic if required,
108 but it should not be passed to x509_path_validate unless we are verifying
109 the server.
110 */
111 const std::string_view name_to_match = (usage == Usage_Type::TLS_CLIENT_AUTH) ? std::string_view{} : hostname;
112
113 const Path_Validation_Result result = x509_path_validate(cert_chain,
114 restrictions,
115 trusted_roots,
116 name_to_match,
117 usage,
120 ocsp_responses);
121
122 if(!result.successful_validation()) {
123 throw TLS_Exception(Alert::BadCertificate, "Certificate validation failure: " + result.result_string());
124 }
125}
virtual std::chrono::milliseconds tls_verify_cert_chain_ocsp_timeout() const
virtual std::chrono::system_clock::time_point tls_current_timestamp()
Path_Validation_Result x509_path_validate(const std::vector< X509_Certificate > &end_certs, const Path_Validation_Restrictions &restrictions, const std::vector< Certificate_Store * > &trusted_roots, std::string_view hostname, Usage_Type usage, std::chrono::system_clock::time_point ref_time, std::chrono::milliseconds ocsp_timeout, const std::vector< std::optional< OCSP::Response > > &ocsp_resp)

References Botan::TLS::Policy::minimum_signature_strength(), Botan::TLS::Policy::require_cert_revocation_info(), Botan::Path_Validation_Result::result_string(), Botan::Path_Validation_Result::successful_validation(), Botan::TLS_CLIENT_AUTH, tls_current_timestamp(), tls_verify_cert_chain_ocsp_timeout(), and Botan::x509_path_validate().

◆ tls_verify_cert_chain_ocsp_timeout()

virtual std::chrono::milliseconds Botan::TLS::Callbacks::tls_verify_cert_chain_ocsp_timeout ( ) const
inlinevirtual

Called by default tls_verify_cert_chain to get the timeout to use for OCSP requests. Return 0 to disable online OCSP checks.

This function should not be "const" since the implementation might need to perform some side effecting operation to compute the result.

TODO(Botan4) change return type to uint64_t

Definition at line 275 of file tls_callbacks.h.

275 {
276 return std::chrono::milliseconds(0);
277 }

Referenced by tls_verify_cert_chain().

◆ tls_verify_message()

bool Botan::TLS::Callbacks::tls_verify_message ( const Public_Key & key,
std::string_view padding,
Signature_Format format,
const std::vector< uint8_t > & msg,
const std::vector< uint8_t > & sig )
virtual

Optional callback with default impl: verify a message signature

Default implementation uses PK_Verifier::verify_message(). Override to provide a different approach, e.g. using an external device.

Parameters
keythe public key of the signer
paddingthe encoding method to be applied to the message
formatthe signature format
msgthe input data for the signature
sigthe signature to be checked
Returns
true if the signature is valid, false otherwise

Definition at line 165 of file tls_callbacks.cpp.

169 {
170 PK_Verifier verifier(key, padding, format);
171
172 return verifier.verify_message(msg, sig);
173}

References Botan::PK_Verifier::verify_message().

Referenced by Botan::TLS::Certificate_Verify_12::verify(), Botan::TLS::Certificate_Verify_13::verify(), and Botan::TLS::Server_Key_Exchange::verify().

◆ tls_verify_raw_public_key()

void Botan::TLS::Callbacks::tls_verify_raw_public_key ( const Public_Key & raw_public_key,
Usage_Type usage,
std::string_view hostname,
const TLS::Policy & policy )
virtual

Optional callback. Default impl always rejects.

This allows using raw public keys for authentication of peers as described in RFC 7250 and RFC 8446 4.2.2. Applications that wish to use raw public keys MUST override this callback to verify the authenticity of the received public keys.

Default implementation always rejects the raw public key.

This function should throw an exception derived from std::exception with an informative what() result if the raw public key cannot be verified.

Parameters
raw_public_keyspecifies the raw public key to be used for peer authentication
usagewhat this cert chain is being used for Usage_Type::TLS_SERVER_AUTH for server chains, Usage_Type::TLS_CLIENT_AUTH for client chains,
hostnamewhen authenticating a server, this is the hostname the client requested (eg via SNI). When authenticating a client, this is the server name the client is authenticating to. Empty in other cases or if no hostname was used.
policythe TLS policy associated with the session being authenticated using the raw public key

Definition at line 127 of file tls_callbacks.cpp.

130 {
131 BOTAN_UNUSED(raw_public_key, usage, hostname, policy);
132 // There is no good default implementation for authenticating raw public key.
133 // Applications that wish to use them for authentication, must override this.
134 throw TLS_Exception(Alert::CertificateUnknown, "Application did not provide a means to validate the raw public key");
135}

References BOTAN_UNUSED.

Referenced by Botan::TLS::Certificate_13::verify().


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