Botan 3.11.0
Crypto and TLS for C&
tls_callbacks.h
Go to the documentation of this file.
1/*
2* TLS Callbacks
3* (C) 2016 Matthias Gierlings
4* 2016 Jack Lloyd
5* 2017 Harry Reimann, Rohde & Schwarz Cybersecurity
6* 2022 René Meusel, Rohde & Schwarz Cybersecurity
7* 2025 Frederik Dornemann, CARIAD SE
8*
9* Botan is released under the Simplified BSD License (see license.txt)
10*/
11
12#ifndef BOTAN_TLS_CALLBACKS_H_
13#define BOTAN_TLS_CALLBACKS_H_
14
15#include <botan/ec_point_format.h>
16#include <botan/kdf.h>
17#include <botan/pubkey.h>
18#include <botan/tls_alert.h>
19#include <botan/tls_algos.h>
20#include <botan/tls_magic.h>
21#include <chrono>
22#include <memory>
23#include <optional>
24#include <variant>
25
26namespace Botan {
27
28enum class Signature_Format : uint8_t;
29enum class Usage_Type : uint8_t;
30class DL_Group;
34class Public_Key;
35class Private_Key;
37
38namespace OCSP {
39
40class Response;
41
42}
43
44namespace TLS {
45
46class Handshake_Message;
47class Policy;
48class Extensions;
49class Certificate_Status_Request;
50class Session_Summary;
51class Session;
52
53/**
54* Encapsulates the callbacks that a TLS channel will make which are due to
55* channel specific operations.
56*/
57class BOTAN_PUBLIC_API(2, 0) Callbacks /* NOLINT(*-special-member-functions) */ {
58 public:
59 virtual ~Callbacks() = default;
60
61 /**
62 * @name Mandatory
63 *
64 * Those callbacks must be implemented by all applications that use TLS.
65 * @{
66 */
67
68 /**
69 * Mandatory callback: output function
70 *
71 * The channel will call this with data which needs to be sent to the peer
72 * (eg, over a socket or some other form of IPC). The array will be overwritten
73 * when the function returns so a copy must be made if the data cannot be
74 * sent immediately.
75 *
76 * As an example you could use the syscall ``send`` to perform a blocking
77 * write on a socket, or append the data to a queue managed by your
78 * application and initiate an asynchronous write.
79 *
80 * For TLS all writes must occur *in the order requested*. For DTLS this
81 * ordering is not strictly required, but is still recommended.
82 *
83 * @param data a contiguous data buffer to send
84 */
85 virtual void tls_emit_data(std::span<const uint8_t> data) = 0;
86
87 /**
88 * Mandatory callback: process application data
89 *
90 * Called when application data record is received from the peer. The
91 * array is overwritten immediately after the function returns.
92 *
93 * Currently empty records are ignored and do not instigate a callback,
94 * but this may change in a future release.
95 *
96 * For TLS the record number will always increase. For DTLS, it is
97 * possible to receive records with the @p seq_no field out of order, or
98 * with gaps, corresponding to reordered or lost datagrams.
99 *
100 * @param seq_no the underlying TLS/DTLS record sequence number
101 *
102 * @param data a contiguous data buffer containing the received record
103 */
104 virtual void tls_record_received(uint64_t seq_no, std::span<const uint8_t> data) = 0;
105
106 /**
107 * Mandatory callback: alert received
108 *
109 * Called when an alert is received from the peer. If fatal, the
110 * connection is closing. If not fatal, the connection may still be
111 * closing (depending on the error and the peer).
112 *
113 * Note that alerts received before the handshake is complete are not
114 * authenticated and could have been inserted by a MITM attacker.
115 */
116 virtual void tls_alert(Alert alert) = 0;
117
118 /// @}
119 // End of mandatory callbacks
120
121 /**
122 * @name Informational
123 *
124 * Override these to obtain deeper insights into the TLS connection.
125 * Throwing from any of these callbacks will result in the termination of
126 * the TLS connection.
127 * @{
128 */
129
130 /**
131 * Optional callback: session established
132 *
133 * Called whenever a negotiation completes. This can happen more than once
134 * on TLS 1.2 connections, if renegotiation occurs. The @p session
135 * parameter provides information about the session which was just
136 * established.
137 *
138 * If this function wishes to cancel the handshake, it can throw an
139 * exception which will send a close message to the counterparty and reset
140 * the connection state.
141 *
142 * @param session the session descriptor
143 */
144 virtual void tls_session_established(const Session_Summary& session);
145
146 /**
147 * Optional callback: session activated
148 *
149 * By default does nothing. This is called when the session is activated,
150 * that is once it is possible to send or receive data on the channel. In
151 * particular it is possible for an implementation of this function to
152 * perform an initial write on the channel.
153 */
154 virtual void tls_session_activated() {}
155
156 /**
157 * Optional callback: peer closed connection (sent a "close_notify" alert)
158 *
159 * The peer signaled that it wishes to shut down the connection. The
160 * application should not expect to receive any more data from the peer
161 * and may tear down the underlying transport socket.
162 *
163 * Prior to TLS 1.3 it was required that peers discard pending writes
164 * and immediately respond with their own "close_notify". With TLS 1.3,
165 * applications can continue to send data despite the peer having already
166 * signaled their wish to shut down.
167 *
168 * Returning `true` will cause the TLS 1.3 implementation to write all
169 * pending data and then also signal a connection shut down. Otherwise
170 * the application is responsible to call the `Channel::close()` method.
171 *
172 * For TLS 1.2 the return value has no effect.
173 *
174 * @return true causes the implementation to respond with a "close_notify"
175 */
176 virtual bool tls_peer_closed_connection() { return true; }
177
178 /**
179 * Optional callback: Resumption information was received/established
180 *
181 * TLS 1.3 calls this when we sent or received a TLS 1.3 session ticket at
182 * any point after the initial handshake has finished.
183 *
184 * TLS 1.2 calls this when a session was established successfully and
185 * its resumption information may be stored for later usage.
186 *
187 * Note that for servers this is called as soon as resumption information
188 * is available and _could_ be sent to the client. If this callback
189 * returns 'false', the information will neither be cached nor sent.
190 *
191 * @param session the session descriptor
192 *
193 * @return false to prevent the resumption information from being cached,
194 * and true to cache it in the configured Session_Manager
195 */
196 virtual bool tls_should_persist_resumption_information(const Session& session);
197
198 /**
199 * Optional callback with default impl: verify cert chain
200 *
201 * Default implementation performs a standard PKIX validation
202 * and initiates network OCSP request for end-entity cert.
203 * Override to provide different behavior.
204 *
205 * Check the certificate chain is valid up to a trusted root, and
206 * optionally (if hostname != "") that the hostname given is
207 * consistent with the leaf certificate.
208 *
209 * This function should throw an exception derived from
210 * std::exception with an informative what() result if the
211 * certificate chain cannot be verified.
212 *
213 * @param cert_chain specifies a certificate chain leading to a
214 * trusted root CA certificate.
215 * @param ocsp_responses the server may have provided some
216 * @param trusted_roots the list of trusted certificates
217 * @param usage what this cert chain is being used for
218 * Usage_Type::TLS_SERVER_AUTH for server chains,
219 * Usage_Type::TLS_CLIENT_AUTH for client chains,
220 * Usage_Type::UNSPECIFIED for other uses
221 * @param hostname when authenticating a server, this is the hostname
222 * the client requested (eg via SNI). When authenticating a client,
223 * this is the server name the client is authenticating *to*.
224 * Empty in other cases or if no hostname was used.
225 * @param policy the TLS policy associated with the session being authenticated
226 * using the certificate chain
227 */
228 virtual void tls_verify_cert_chain(const std::vector<X509_Certificate>& cert_chain,
229 const std::vector<std::optional<OCSP::Response>>& ocsp_responses,
230 const std::vector<Certificate_Store*>& trusted_roots,
231 Usage_Type usage,
232 std::string_view hostname,
233 const TLS::Policy& policy);
234
235 /**
236 * Optional callback. Default impl always rejects.
237 *
238 * This allows using raw public keys for authentication of peers as
239 * described in RFC 7250 and RFC 8446 4.2.2. Applications that wish
240 * to use raw public keys MUST override this callback to verify the
241 * authenticity of the received public keys.
242 *
243 * Default implementation always rejects the raw public key.
244 *
245 * This function should throw an exception derived from
246 * std::exception with an informative what() result if the
247 * raw public key cannot be verified.
248 *
249 * @param raw_public_key specifies the raw public key to be used
250 * for peer authentication
251 * @param usage what this cert chain is being used for
252 * Usage_Type::TLS_SERVER_AUTH for server chains,
253 * Usage_Type::TLS_CLIENT_AUTH for client chains,
254 * @param hostname when authenticating a server, this is the hostname
255 * the client requested (eg via SNI). When authenticating a client,
256 * this is the server name the client is authenticating *to*.
257 * Empty in other cases or if no hostname was used.
258 * @param policy the TLS policy associated with the session being authenticated
259 * using the raw public key
260 */
261 virtual void tls_verify_raw_public_key(const Public_Key& raw_public_key,
262 Usage_Type usage,
263 std::string_view hostname,
264 const TLS::Policy& policy);
265
266 /**
267 * Called by default `tls_verify_cert_chain` to get the timeout to use for OCSP
268 * requests. Return 0 to disable online OCSP checks.
269 *
270 * This function should not be "const" since the implementation might need
271 * to perform some side effecting operation to compute the result.
272 *
273 * TODO(Botan4) change return type to uint64_t
274 */
275 virtual std::chrono::milliseconds tls_verify_cert_chain_ocsp_timeout() const {
276 return std::chrono::milliseconds(0);
277 }
278
279 /**
280 * Called by the TLS server whenever the client included the
281 * status_request extension (see RFC 6066, a.k.a OCSP stapling)
282 * in the ClientHello.
283 *
284 * @return the encoded OCSP response to be sent to the client which
285 * indicates the revocation status of the server certificate. Return an
286 * empty vector to indicate that no response is available, and thus
287 * suppress the Certificate_Status message.
288 *
289 * Default implementation returns an empty vector, disabling certificate status
290 */
291 virtual std::vector<uint8_t> tls_provide_cert_status(const std::vector<X509_Certificate>& chain,
292 const Certificate_Status_Request& csr);
293
294 /**
295 * Called by TLS 1.3 client or server whenever the peer indicated that
296 * OCSP stapling is supported. In contrast to `tls_provide_cert_status`,
297 * this allows providing OCSP responses for each certificate in the chain.
298 *
299 * The default implementation invokes `tls_provide_cert_status` assuming
300 * that no OCSP responses for intermediate certificates are available.
301 *
302 * @return a vector of OCSP response buffers. An empty buffer indicates
303 * that no OCSP response should be provided for the respective
304 * certificate (at the same list index). The returned vector
305 * MUST be exactly the same length as the incoming \p chain.
306 */
307 virtual std::vector<std::vector<uint8_t>> tls_provide_cert_chain_status(
308 const std::vector<X509_Certificate>& chain, const Certificate_Status_Request& csr);
309
310 /**
311 * Optional callback with default impl: sign a message
312 *
313 * Default implementation uses PK_Signer::sign_message().
314 * Override to provide a different approach, e.g. using an external device.
315 *
316 * @param key the private key of the signer
317 * @param rng a random number generator
318 * @param padding the encoding method to be applied to the message
319 * @param format the signature format
320 * @param msg the input data for the signature
321 *
322 * @return the signature
323 */
324 virtual std::vector<uint8_t> tls_sign_message(const Private_Key& key,
326 std::string_view padding,
327 Signature_Format format,
328 const std::vector<uint8_t>& msg);
329
330 /**
331 * Optional callback with default impl: verify a message signature
332 *
333 * Default implementation uses PK_Verifier::verify_message().
334 * Override to provide a different approach, e.g. using an external device.
335 *
336 * @param key the public key of the signer
337 * @param padding the encoding method to be applied to the message
338 * @param format the signature format
339 * @param msg the input data for the signature
340 * @param sig the signature to be checked
341 *
342 * @return true if the signature is valid, false otherwise
343 */
344 virtual bool tls_verify_message(const Public_Key& key,
345 std::string_view padding,
346 Signature_Format format,
347 const std::vector<uint8_t>& msg,
348 const std::vector<uint8_t>& sig);
349
350 /**
351 * Optional callback: deserialize a public key received from the peer
352 *
353 * Default implementation simply parses the public key using Botan's
354 * public keys. Override to provide a different approach, e.g. using an
355 * external device.
356 *
357 * If deserialization fails, the default implementation throws a
358 * Botan::Decoding_Error exception that will be translated into a
359 * TLS_Exception with an Alert::IllegalParameter.
360 *
361 * @param group the group identifier or (in case of TLS 1.2) an explicit
362 * discrete-log group of the public key
363 * @param key_bits the serialized public key
364 *
365 * @return the deserialized and ready-to-use public key
366 */
367 virtual std::unique_ptr<Public_Key> tls_deserialize_peer_public_key(
368 const std::variant<TLS::Group_Params, DL_Group>& group, std::span<const uint8_t> key_bits);
369
370 /**
371 * Generate an ephemeral KEM key for a TLS 1.3 handshake
372 *
373 * Applications may use this to add custom KEM algorithms or entirely
374 * different key exchange schemes to the TLS 1.3 handshake. For instance,
375 * this could provide an entry point to implement a hybrid key exchange
376 * with both a traditional algorithm like ECDH and a quantum-secure KEM.
377 * Typical use cases of the library don't need to do that and serious
378 * security risks are associated with customizing TLS's key encapsulation
379 * mechanism.
380 *
381 * Note that the KEM interface is usable for TLS 1.3 handshakes, only.
382 *
383 * The default implementation simply delegates this to the
384 * tls_generate_ephemeral_key() call when appropriate.
385 *
386 * @param group the group identifier to generate an ephemeral keypair for
387 * @param rng a random number generator
388 *
389 * @returns a keypair whose public key will be provided to the peer and
390 * the private key will be provided to tls_kem_decapsulate later
391 * in the handshake.
392 */
393 virtual std::unique_ptr<Private_Key> tls_kem_generate_key(TLS::Group_Params group, RandomNumberGenerator& rng);
394
395 /**
396 * Performs a key encapsulation operation (used for TLS 1.3 servers)
397 *
398 * Applications may use this to add custom KEM algorithms or entirely
399 * different key exchange schemes to the TLS 1.3 handshake. For instance,
400 * this could provide an entry point to implement a hybrid key exchange
401 * with both a traditional algorithm like ECDH and a quantum-secure KEM.
402 * Typical use cases of the library don't need to do that and serious
403 * security risks are associated with customizing TLS's key encapsulation
404 * mechanism.
405 *
406 * Note that the KEM interface is usable for TLS 1.3 handshakes, only.
407 *
408 * The default implementation implements this key encapsulation as a
409 * combination of tls_generate_ephemeral_key() followed by
410 * tls_ephemeral_key_agreement() with the provided @p encoded_public_key.
411 * The just-generated ephemeral private key is destroyed immediately.
412 *
413 * @param group the group identifier of the KEM/KEX algorithm
414 * @param encoded_public_key the public key used for encapsulation/KEX
415 * @param rng a random number generator
416 * @param policy a TLS policy object
417 *
418 * @returns the shared secret both in plaintext and encapsulated with
419 * @p encoded_public_key.
420 *
421 * TODO(Botan4) change this return type to something else so the pubkey.h
422 * dependency is removed
423 * TODO(Botan4) change encoded_public_key to a span
424 */
425 virtual KEM_Encapsulation tls_kem_encapsulate(TLS::Group_Params group,
426 const std::vector<uint8_t>& encoded_public_key,
428 const Policy& policy);
429
430 /**
431 * Performs a key decapsulation operation (used for TLS 1.3 clients).
432 *
433 * Applications may use this to add custom KEM algorithms or entirely
434 * different key exchange schemes to the TLS 1.3 handshake. For instance,
435 * this could provide an entry point to implement a hybrid key exchange
436 * with both a traditional algorithm like ECDH and a quantum-secure KEM.
437 * Typical use cases of the library don't need to do that and serious
438 * security risks are associated with customizing TLS's key encapsulation
439 * mechanism.
440 *
441 * Note that the KEM interface is usable for TLS 1.3 handshakes, only.
442 *
443 * The default implementation simply delegates this to the
444 * tls_ephemeral_key_agreement() callback to obtain the shared secret.
445 *
446 * @param group the group identifier of the KEM/KEX algorithm
447 * @param private_key the private key used for decapsulation/KEX
448 * @param encapsulated_bytes the content to decapsulate (or the public key share)
449 * @param rng a random number generator
450 * @param policy a TLS policy object
451 *
452 * @returns the plaintext shared secret from @p encapsulated_bytes after
453 * decapsulation with @p private_key.
454 *
455 * TODO(Botan4) change encapsulated_bytes to a std::span
456 */
457 virtual secure_vector<uint8_t> tls_kem_decapsulate(TLS::Group_Params group,
458 const Private_Key& private_key,
459 const std::vector<uint8_t>& encapsulated_bytes,
461 const Policy& policy);
462
463 /**
464 * Generate an ephemeral key pair for the TLS handshake.
465 *
466 * Applications may use this to add custom groups, curves or entirely
467 * different ephemeral key agreement mechanisms to the TLS handshake.
468 * Note that this callback must be used in conjunction with
469 * Callbacks::tls_ephemeral_key_agreement.
470 *
471 * Typical use cases of the library don't need to do that and serious
472 * security risks are associated with customizing TLS's key exchange
473 * mechanism.
474 *
475 * @throws TLS_Exception(Alert::DecodeError) if the @p group is not known.
476 *
477 * @param group the group identifier to generate an ephemeral keypair for
478 * TLS 1.2 allows for specifying custom discrete logarithm
479 * parameters as part of the protocol. Hence the variant<>.
480 * @param rng a random number generator
481 *
482 * @return a private key of an algorithm usable for key agreement
483 */
484 virtual std::unique_ptr<PK_Key_Agreement_Key> tls_generate_ephemeral_key(
485 const std::variant<TLS::Group_Params, DL_Group>& group, RandomNumberGenerator& rng);
486
487 /**
488 * Generate an ECDH key pair for the TLS 1.2 handshake.
489 *
490 * Note that this callback is called exclusively by TLS 1.2 to handle the
491 * ECDH public key serialization format explicitly. TLS 1.3 fixes this
492 * format to 'uncompressed' and does not allow negotiating anything else.
493 * X25519 and X448 feature a defined and fixed public key encoding and are
494 * therefore not explicitly handled by this callback either.
495 *
496 * Users may override this if they want to provide a custom keypair type
497 * to offload TLS 1.2's ECDH handling to custom hardware, for instance. It
498 * is worth noting that support for compressed points in Botan is
499 * deprecated and this callback will disappear when it is removed in a
500 * future release.
501 *
502 * Typical use cases of the library don't need to do that and serious
503 * security risks are associated with customizing TLS's key exchange
504 * mechanism.
505 *
506 * @throws TLS_Exception(Alert::DecodeError) if the @p group is not known.
507 *
508 * @param group ECDH group identifier to generate an ephemeral keypair for
509 * @param rng a random number generator
510 * @param tls12_ecc_pubkey_encoding_format the key's serialization format
511 *
512 * @return an ECDH private key of an algorithm usable for key agreement
513 */
514 virtual std::unique_ptr<PK_Key_Agreement_Key> tls12_generate_ephemeral_ecdh_key(
515 TLS::Group_Params group, RandomNumberGenerator& rng, EC_Point_Format tls12_ecc_pubkey_encoding_format);
516
517 /**
518 * Agree on a shared secret with the peer's ephemeral public key for
519 * the TLS handshake.
520 *
521 * Applications may use this to add custom groups, curves or entirely
522 * different ephemeral key agreement mechanisms to the TLS handshake.
523 * Note that this callback must be used in conjunction with
524 * Callbacks::tls_generate_ephemeral_key.
525 *
526 * Typical use cases of the library don't need to do that and serious
527 * security risks are associated with customizing TLS's key exchange
528 * mechanism.
529 *
530 * @param group the TLS group identifier to be used
531 * TLS 1.2 allows for specifying custom discrete
532 * logarithm parameters as part of the protocol.
533 * Hence the variant<>.
534 * @param private_key the private key (generated ahead in tls_generate_ephemeral_key)
535 * @param public_value the public key exchange information received by the peer
536 * @param rng a random number generator
537 * @param policy a TLS policy object
538 *
539 * @return the shared secret derived from public_value and private_key
540 *
541 * TODO(Botan4) change public_value to a std::span
542 */
543 virtual secure_vector<uint8_t> tls_ephemeral_key_agreement(const std::variant<TLS::Group_Params, DL_Group>& group,
544 const PK_Key_Agreement_Key& private_key,
545 const std::vector<uint8_t>& public_value,
547 const Policy& policy);
548
549 /**
550 * Optional callback: inspect handshake message
551 * Throw an exception to abort the handshake.
552 * Default simply ignores the message.
553 *
554 * Note: On connections that negotiated TLS 1.3 this callback is also
555 * invoked for post-handshake messages.
556 *
557 * @param message the handshake message
558 */
559 virtual void tls_inspect_handshake_msg(const Handshake_Message& message);
560
561 /**
562 * Optional callback for server: choose ALPN protocol
563 *
564 * ALPN (RFC 7301) works by the client sending a list of application
565 * protocols it is willing to negotiate. The server then selects which
566 * protocol to use. RFC 7301 requires that if the server does not support
567 * any protocols offered by the client, then it should close the connection
568 * with an alert of no_application_protocol. Within this callback this would
569 * be done by throwing a TLS_Exception(Alert::NoApplicationProtocol)
570 *
571 * @param client_protos the vector of protocols the client is willing to negotiate
572 *
573 * @return the protocol selected by the server; if the empty string is
574 * returned, the server does not reply to the client ALPN extension.
575 *
576 * The default implementation returns the empty string, causing client
577 * ALPN to be ignored.
578 *
579 * It is highly recommended to support ALPN whenever possible to avoid
580 * cross-protocol attacks.
581 */
582 virtual std::string tls_server_choose_app_protocol(const std::vector<std::string>& client_protos);
583
584 /**
585 * Optional callback: examine/modify Extensions before sending.
586 *
587 * Both client and server will call this callback on the Extensions object
588 * before serializing it in the specific handshake message. This allows an
589 * application to modify which extensions are sent during the handshake.
590 *
591 * Default implementation does nothing.
592 *
593 * @param extn the extensions
594 * @param which_side will be Connection_Side::Client or Connection_Side::Server which is the current
595 * applications role in the exchange.
596 * @param which_message will state the handshake message type containing the extensions
597 */
598 virtual void tls_modify_extensions(Extensions& extn, Connection_Side which_side, Handshake_Type which_message);
599
600 /**
601 * Optional callback: examine peer extensions.
602 *
603 * Both client and server will call this callback with the Extensions
604 * object after receiving it from the peer. This allows examining the
605 * Extensions, for example to implement a custom extension. It also allows
606 * an application to require that a particular extension be implemented;
607 * throw an exception from this function to abort the handshake.
608 *
609 * Default implementation does nothing.
610 *
611 * @param extn the extensions
612 * @param which_side will be Connection_Side::Client if these are are the clients extensions (ie we are
613 * the server) or Connection_Side::Server if these are the server extensions (we are the client).
614 * @param which_message will state the handshake message type containing the extensions
615 */
616 virtual void tls_examine_extensions(const Extensions& extn,
617 Connection_Side which_side,
618 Handshake_Type which_message);
619
620 /**
621 * Optional callback: parse a single OCSP Response
622 *
623 * Note: Typically a user of the library would not want to override this
624 * callback. We provide this callback to be able to support OCSP
625 * related tests from BoringSSL's BoGo tests that provide unparsable
626 * responses.
627 *
628 * Default implementation tries to parse the provided raw OCSP response.
629 *
630 * This function should not throw an exception but return a std::nullopt
631 * if the OCSP response cannot be parsed.
632 *
633 * @param raw_response raw OCSP response buffer
634 * @returns the parsed OCSP response or std::nullopt on error
635 *
636 * TODO(Botan4) change raw_response to a std::span
637 */
638 virtual std::optional<OCSP::Response> tls_parse_ocsp_response(const std::vector<uint8_t>& raw_response);
639
640 /**
641 * Optional callback: return peer network identity
642 *
643 * There is no expected or specified format. The only expectation is this
644 * function will return a unique value. For example returning the peer
645 * host IP and port.
646 *
647 * This is used to bind the DTLS cookie to a particular network identity.
648 * It is only called if the dtls-cookie-secret PSK is also defined.
649 */
650 virtual std::string tls_peer_network_identity();
651
652 /**
653 * Optional callback: return a custom time stamp value
654 *
655 * This allows the library user to specify a custom "now" timestamp when
656 * needed. By default it will use the current system clock time.
657 *
658 * Note that typical usages will not need to override this callback but it
659 * is useful for testing purposes to allow for deterministic test outcomes.
660 *
661 * TODO(Botan4) change return type to uint64_t
662 */
663 virtual std::chrono::system_clock::time_point tls_current_timestamp();
664
665 /**
666 * Optional callback: error logging. (not currently called)
667 * @param err An error message related to this connection.
668 *
669 * TODO(Botan4) remove this
670 */
671 virtual void tls_log_error(const char* err);
672
673 /**
674 * Optional callback: debug logging. (not currently called)
675 * @param what Some hopefully informative string
676 *
677 * TODO(Botan4) remove this
678 */
679 virtual void tls_log_debug(const char* what);
680
681 /**
682 * Optional callback: debug logging taking a buffer. (not currently called)
683 * @param descr What this buffer is
684 * @param val the bytes
685 * @param val_len length of val
686 *
687 * TODO(Botan4) remove this
688 */
689 virtual void tls_log_debug_bin(const char* descr, const uint8_t val[], size_t val_len);
690
691 /**
692 * Optional callback: Allows access to a connection's secret data
693 *
694 * Useful to implement the SSLKEYLOGFILE for connection debugging as
695 * specified in ietf.org/archive/id/draft-thomson-tls-keylogfile-00.html
696 *
697 * Invoked if Policy::allow_ssl_key_log_file returns true.
698 *
699 * Default implementation simply ignores the inputs.
700 *
701 * @param label Identifies the reported secret type
702 * See draft-thomson-tls-keylogfile-00 Section 3.1 and 3.2
703 * @param client_random random value from ClientHello message acting as
704 * an identifier of the TLS sessions
705 * @param secret the actual secret value
706 */
707 virtual void tls_ssl_key_log_data(std::string_view label,
708 std::span<const uint8_t> client_random,
709 std::span<const uint8_t> secret) const;
710
711 /**
712 * Returns the key derivation function to be used for TLS 1.2
713 *
714 * The default implementation can be overridden to provide a user-defined
715 * key derivation function, for example to delegate key derivation to a
716 * hardware-protected environment when a pre-shared key must remain
717 * inaccessible to the non-secure world.
718 *
719 * @param prf_algo name of the hash function (e.g. "SHA-256")
720 *
721 * @return TLS 1.2 KDF implementation
722 */
723 virtual std::unique_ptr<KDF> tls12_protocol_specific_kdf(std::string_view prf_algo) const;
724};
725
726} // namespace TLS
727
728} // namespace Botan
729
730#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
virtual std::chrono::milliseconds tls_verify_cert_chain_ocsp_timeout() const
virtual ~Callbacks()=default
virtual void tls_session_activated()
virtual void tls_session_established(const Session_Summary &session)
virtual void tls_record_received(uint64_t seq_no, std::span< const uint8_t > data)=0
virtual void tls_alert(Alert alert)=0
virtual bool tls_peer_closed_connection()
virtual void tls_emit_data(std::span< const uint8_t > data)=0
Signature_Format
Definition pk_keys.h:32
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:68