Botan 3.4.0
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
20class Credentials_Manager;
21
22namespace TLS {
23
24/**
25* SSL/TLS Client 1.3 implementation
26*/
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 explicit Client_Impl_13(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 /**
56 * @return network protocol as advertised by the TLS server, if server sent the ALPN extension
57 */
58 std::string application_protocol() const override;
59
60 /**
61 * @return certificate chain of the peer (may be empty)
62 */
63 std::vector<X509_Certificate> peer_cert_chain() const override;
64
65 /**
66 * @return raw public key of the peer (may be nullptr)
67 */
68 std::shared_ptr<const Public_Key> peer_raw_public_key() const override;
69
70 /**
71 * @return identity of the PSK used for this connection
72 * or std::nullopt if no PSK was used.
73 */
74 std::optional<std::string> external_psk_identity() const override;
75
76 /**
77 * @return true if the TLS handshake finished successfully
78 */
79 bool is_handshake_complete() const override;
80
81 private:
82 void process_handshake_msg(Handshake_Message_13 msg) override;
83 void process_post_handshake_msg(Post_Handshake_Message_13 msg) override;
84 void process_dummy_change_cipher_spec() override;
85
86 bool prepend_ccs() override;
87
89 void handle(const Server_Hello_12& server_hello_msg);
90 void handle(const Server_Hello_13& server_hello_msg);
91 void handle(const Hello_Retry_Request& hrr_msg);
92 void handle(const Encrypted_Extensions& encrypted_extensions_msg);
93 void handle(const Certificate_Request_13& certificate_request_msg);
94 void handle(const Certificate_13& certificate_msg);
95 void handle(const Certificate_Verify_13& certificate_verify_msg);
96 void handle(const Finished_13& finished_msg);
97 void handle(const New_Session_Ticket_13& new_session_ticket);
98
99 void send_client_authentication(Channel_Impl_13::AggregatedHandshakeMessages& flight);
100 std::optional<Session_with_Handle> find_session_for_resumption();
101
102 private:
103 const Server_Information m_info;
104
105 Client_Handshake_State_13 m_handshake_state;
106 Handshake_Transitions m_transitions;
107
108 bool m_should_send_ccs;
109
110 std::optional<Session_with_Handle> m_resumed_session;
111 std::optional<std::string> m_psk_identity;
112};
113
114} // namespace TLS
115
116} // namespace Botan
117
118#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