Botan 3.6.1
Crypto and TLS for C&
tls_client_impl_13.h
Go to the documentation of this file.
1/*
2* TLS Client - implementation for TLS 1.3
3* (C) 2022 Jack Lloyd
4* 2021 Elektrobit Automotive GmbH
5* 2022 Hannes Rantzsch, René Meusel - neXenio GmbH
6*
7* Botan is released under the Simplified BSD License (see license.txt)
8*/
9
10#ifndef BOTAN_TLS_CLIENT_IMPL_13_H_
11#define BOTAN_TLS_CLIENT_IMPL_13_H_
12
13#include <botan/tls_server_info.h>
14#include <botan/internal/tls_channel_impl_13.h>
15#include <botan/internal/tls_cipher_state.h>
16#include <botan/internal/tls_handshake_state_13.h>
17#include <botan/internal/tls_handshake_transitions.h>
18
19namespace Botan {
20
21class Credentials_Manager;
22
23namespace TLS {
24
25/**
26* SSL/TLS Client 1.3 implementation
27*/
29 public:
30 /**
31 * Set up a new TLS client session
32 *
33 * @param callbacks contains a set of callback function references
34 * required by the TLS client.
35 *
36 * @param session_manager manages session state
37 *
38 * @param creds manages application/user credentials
39 *
40 * @param policy specifies other connection policy information
41 *
42 * @param rng a random number generator
43 *
44 * @param server_info is identifying information about the TLS server
45 *
46 * @param next_protocols specifies protocols to advertise with ALPN
47 */
48 explicit Client_Impl_13(const std::shared_ptr<Callbacks>& callbacks,
49 const std::shared_ptr<Session_Manager>& session_manager,
50 const std::shared_ptr<Credentials_Manager>& creds,
51 const std::shared_ptr<const Policy>& policy,
52 const std::shared_ptr<RandomNumberGenerator>& rng,
54 const std::vector<std::string>& next_protocols = {});
55
56 /**
57 * @return network protocol as advertised by the TLS server, if server sent the ALPN extension
58 */
59 std::string application_protocol() const override;
60
61 /**
62 * @return certificate chain of the peer (may be empty)
63 */
64 std::vector<X509_Certificate> peer_cert_chain() const override;
65
66 /**
67 * @return raw public key of the peer (may be nullptr)
68 */
69 std::shared_ptr<const Public_Key> peer_raw_public_key() const override;
70
71 /**
72 * @return identity of the PSK used for this connection
73 * or std::nullopt if no PSK was used.
74 */
75 std::optional<std::string> external_psk_identity() const override;
76
77 /**
78 * @return true if the TLS handshake finished successfully
79 */
80 bool is_handshake_complete() const override;
81
82 private:
83 void process_handshake_msg(Handshake_Message_13 msg) override;
84 void process_post_handshake_msg(Post_Handshake_Message_13 msg) override;
85 void process_dummy_change_cipher_spec() override;
86
87 void maybe_log_secret(std::string_view label, std::span<const uint8_t> secret) const override;
88 bool prepend_ccs() override;
89
91 void handle(const Server_Hello_12& server_hello_msg);
92 void handle(const Server_Hello_13& server_hello_msg);
93 void handle(const Hello_Retry_Request& hrr_msg);
94 void handle(const Encrypted_Extensions& encrypted_extensions_msg);
95 void handle(const Certificate_Request_13& certificate_request_msg);
96 void handle(const Certificate_13& certificate_msg);
97 void handle(const Certificate_Verify_13& certificate_verify_msg);
98 void handle(const Finished_13& finished_msg);
99 void handle(const New_Session_Ticket_13& new_session_ticket);
100
101 void send_client_authentication(Channel_Impl_13::AggregatedHandshakeMessages& flight);
102 std::optional<Session_with_Handle> find_session_for_resumption();
103
104 private:
105 const Server_Information m_info;
106
107 Client_Handshake_State_13 m_handshake_state;
108 Handshake_Transitions m_transitions;
109
110 bool m_should_send_ccs;
111
112 std::optional<Session_with_Handle> m_resumed_session;
113 std::optional<std::string> m_psk_identity;
114};
115
116} // namespace TLS
117
118} // namespace Botan
119
120#endif
const Policy & policy() const
void handle(const Key_Update &key_update)
RandomNumberGenerator & rng()
Session_Manager & session_manager()
Client_Impl_13(const std::shared_ptr< Callbacks > &callbacks, const std::shared_ptr< Session_Manager > &session_manager, const std::shared_ptr< Credentials_Manager > &creds, const std::shared_ptr< const Policy > &policy, const std::shared_ptr< RandomNumberGenerator > &rng, Server_Information server_info=Server_Information(), const std::vector< std::string > &next_protocols={})
std::optional< std::string > external_psk_identity() const override
std::string application_protocol() const override
std::shared_ptr< const Public_Key > peer_raw_public_key() const override
bool is_handshake_complete() const override
std::vector< X509_Certificate > peer_cert_chain() const override
std::variant< New_Session_Ticket_13, Key_Update > Post_Handshake_Message_13
std::variant< Client_Hello_13, Client_Hello_12, Server_Hello_13, Server_Hello_12, Hello_Retry_Request, Encrypted_Extensions, Certificate_13, Certificate_Request_13, Certificate_Verify_13, Finished_13 > Handshake_Message_13