Botan 3.14.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_handshake_state_13.h>
16#include <botan/internal/tls_handshake_transitions.h>
17
18namespace Botan {
19
21
22namespace TLS {
23
24/**
25* SSL/TLS Client 1.3 implementation
26*/
27class Client_Impl_13 final : public Channel_Impl_13 {
28 public:
29 /**
30 * Set up a new TLS client session
31 *
32 * @param callbacks contains a set of callback function references
33 * required by the TLS client.
34 *
35 * @param session_manager manages session state
36 *
37 * @param creds manages application/user credentials
38 *
39 * @param policy specifies other connection policy information
40 *
41 * @param rng a random number generator
42 *
43 * @param server_info is identifying information about the TLS server
44 *
45 * @param next_protocols specifies protocols to advertise with ALPN
46 */
47 static std::shared_ptr<Client_Impl_13> create(const std::shared_ptr<Callbacks>& callbacks,
48 const std::shared_ptr<Session_Manager>& session_manager,
49 const std::shared_ptr<Credentials_Manager>& creds,
50 const std::shared_ptr<const Policy>& policy,
51 const std::shared_ptr<RandomNumberGenerator>& rng,
53 const std::vector<std::string>& next_protocols = {});
54
55 Client_Impl_13([[maybe_unused]] Private dont_call_me,
56 const std::shared_ptr<Callbacks>& callbacks,
57 const std::shared_ptr<Session_Manager>& session_manager,
58 const std::shared_ptr<Credentials_Manager>& creds,
59 const std::shared_ptr<const Policy>& policy,
60 const std::shared_ptr<RandomNumberGenerator>& rng,
61 Server_Information server_info = Server_Information()) :
62 Channel_Impl_13(callbacks, session_manager, creds, rng, policy, false /* is_server */),
63 m_info(std::move(server_info)),
64 m_handshake(std::make_unique<Pending_Handshake>()) {}
65
66 /**
67 * @return network protocol as advertised by the TLS server, if server sent the ALPN extension
68 */
69 std::string application_protocol() const override;
70
71 /**
72 * @return certificate chain of the peer (may be empty)
73 */
74 std::vector<X509_Certificate> peer_cert_chain() const override;
75
76 /**
77 * @return raw public key of the peer (may be nullptr)
78 */
79 std::shared_ptr<const Public_Key> peer_raw_public_key() const override;
80
81 /**
82 * @return identity of the PSK used for this connection
83 * or std::nullopt if no PSK was used.
84 */
85 std::optional<std::string> external_psk_identity() const override;
86
87 /**
88 * @return true if the TLS handshake finished successfully
89 */
90 bool is_handshake_complete() const override;
91
92 private:
93 void process_handshake_msg(Handshake_Message_13 msg) override;
94 void process_post_handshake_msg(Post_Handshake_Message_13 msg) override;
96
97 void maybe_log_secret(std::string_view label, std::span<const uint8_t> secret) const override;
98 bool compat_mode_ccs_requested() const override;
99
101 void handle(const Server_Hello_12_Shim& server_hello_msg);
102 void handle(const Server_Hello_13& server_hello_msg);
103 void handle(const Hello_Retry_Request& hrr_msg);
104 void handle(const Encrypted_Extensions& encrypted_extensions_msg);
105 void handle(const Certificate_Request_13& certificate_request_msg);
106 void handle(const Certificate_13& certificate_msg);
107 void handle(const Certificate_Verify_13& certificate_verify_msg);
108 void handle(const Finished_13& finished_msg);
109 void handle(const New_Session_Ticket_13& new_session_ticket);
110
111 void create_client_authentication_flight(Flight& flight);
112 std::optional<Session_with_Handle> find_session_for_resumption();
113
114 private:
115 const Server_Information m_info;
116
117 struct Pending_Handshake {
119 Handshake_Transitions transitions;
120 std::optional<Session_with_Handle> resumed_session;
121 std::optional<std::string> psk_identity;
122 };
123
124 std::unique_ptr<Pending_Handshake> m_handshake;
125 size_t m_session_tickets_received = 0;
126};
127
128} // namespace TLS
129
130} // namespace Botan
131
132#endif
const Policy & policy() const
void handle(const Key_Update &key_update)
RandomNumberGenerator & rng()
virtual bool compat_mode_ccs_requested() const =0
Channel_Impl_13(const std::shared_ptr< Callbacks > &callbacks, const std::shared_ptr< Session_Manager > &session_manager, const std::shared_ptr< Credentials_Manager > &credentials_manager, const std::shared_ptr< RandomNumberGenerator > &rng, const std::shared_ptr< const Policy > &policy, bool is_server)
virtual void process_dummy_change_cipher_spec()=0
Session_Manager & session_manager()
std::optional< std::string > external_psk_identity() const override
static std::shared_ptr< Client_Impl_13 > create(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={})
Client_Impl_13(Private dont_call_me, 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())
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
Handshake_State_13< Connection_Side::Client, Client_Handshake_13_Message, Server_Handshake_13_Message, Server_Post_Handshake_13_Message > Client_Handshake_State_13
std::variant< Client_Hello_13, Client_Hello_12_Shim, Server_Hello_13, Server_Hello_12_Shim, Hello_Retry_Request, Encrypted_Extensions, Certificate_13, Certificate_Request_13, Certificate_Verify_13, Finished_13 > Handshake_Message_13
std::variant< New_Session_Ticket_13, Key_Update > Post_Handshake_Message_13