Botan 3.14.1
Crypto and TLS for C&
tls_client_impl_12.h
Go to the documentation of this file.
1/*
2* TLS Client - implementation for TLS 1.2
3* (C) 2004-2011 Jack Lloyd
4* 2016 Matthias Gierlings
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_TLS_CLIENT_IMPL_12_H_
10#define BOTAN_TLS_CLIENT_IMPL_12_H_
11
12#include <botan/credentials_manager.h>
13#include <botan/tls_channel.h>
14#include <botan/internal/tls_channel_impl_12.h>
15#include <memory>
16#include <vector>
17
18namespace Botan::TLS {
19
20/**
21* SSL/TLS Client 1.2 implementation
22*/
23class Client_Impl_12 final : public Channel_Impl_12 {
24 public:
25 /**
26 * Set up a new TLS client session
27 *
28 * @param callbacks contains a set of callback function references
29 * required by the TLS client.
30 *
31 * @param session_manager manages session state
32 *
33 * @param creds manages application/user credentials
34 *
35 * @param policy specifies other connection policy information
36 *
37 * @param rng a random number generator
38 *
39 * @param server_info is identifying information about the TLS server
40 *
41 * @param flavor specifies the TLS flavor (TLS or DTLS)
42 *
43 * @param next_protocols specifies protocols to advertise with ALPN
44 *
45 * @param reserved_io_buffer_size This many bytes of memory will
46 * be preallocated for the read and write buffers. Smaller
47 * values just mean reallocations and copies are more likely.
48 */
49 static std::shared_ptr<Client_Impl_12> create(const std::shared_ptr<Callbacks>& callbacks,
50 const std::shared_ptr<Session_Manager>& session_manager,
51 const std::shared_ptr<Credentials_Manager>& creds,
52 const std::shared_ptr<const Policy>& policy,
53 const std::shared_ptr<RandomNumberGenerator>& rng,
56 const std::vector<std::string>& next_protocols = {},
57 size_t reserved_io_buffer_size = TLS::Channel::IO_BUF_DEFAULT_SIZE);
58
59 Client_Impl_12([[maybe_unused]] Private dont_call_me,
60 const std::shared_ptr<Callbacks>& callbacks,
61 const std::shared_ptr<Session_Manager>& session_manager,
62 const std::shared_ptr<Credentials_Manager>& creds,
63 const std::shared_ptr<const Policy>& policy,
64 const std::shared_ptr<RandomNumberGenerator>& rng,
65 Server_Information server_info,
67 size_t reserved_io_buffer_size) :
68 Channel_Impl_12(callbacks, session_manager, rng, policy, false, flavor, reserved_io_buffer_size),
69 m_creds(creds),
70 m_info(std::move(server_info)) {}
71
72#if defined(BOTAN_HAS_TLS_DOWNGRADE_SUPPORT)
73
74 static std::shared_ptr<Client_Impl_12> create_for_downgrade(Channel_Impl::Downgrade_Information& downgrade_info);
75
76 Client_Impl_12([[maybe_unused]] Private dont_call_me, Channel_Impl::Downgrade_Information& downgrade_info) :
77 Channel_Impl_12(downgrade_info.callbacks,
78 downgrade_info.session_manager,
79 downgrade_info.rng,
80 downgrade_info.policy,
81 false /* is_server */,
82 downgrade_info.flavor,
83 downgrade_info.io_buffer_size),
84 m_creds(downgrade_info.creds),
85 m_info(downgrade_info.server_info) {}
86
87#endif
88
89 /**
90 * @return network protocol as advertised by the TLS server, if server sent the ALPN extension
91 */
92 std::string application_protocol() const override {
93 // A renegotiation in progress does not affect the active connection
94 if(active_state().has_value()) {
95 return active_state()->application_protocol();
96 }
97 return m_application_protocol;
98 }
99
100 private:
101 std::string negotiated_application_protocol() const override { return m_application_protocol; }
102
103 void initiate_handshake(Handshake_State& state, bool force_full_renegotiation) override;
104
105 void send_client_hello(Handshake_State& state,
106 bool force_full_renegotiation,
107 Protocol_Version version,
108 std::optional<Session_with_Handle> session_and_handle = std::nullopt,
109 const std::vector<std::string>& next_protocols = {});
110
111 void process_handshake_msg(Handshake_State& pending_state,
112 Handshake_Type type,
113 const std::vector<uint8_t>& contents,
114 bool epoch0_restart) override;
115
116 std::unique_ptr<Handshake_State> new_handshake_state(std::unique_ptr<Handshake_IO> io) override;
117
118 std::shared_ptr<Credentials_Manager> m_creds;
119 const Server_Information m_info;
120 std::string m_application_protocol;
121};
122
123} // namespace Botan::TLS
124
125#endif
RandomNumberGenerator & rng()
virtual std::string negotiated_application_protocol() const =0
Channel_Impl_12(const std::shared_ptr< Callbacks > &callbacks, const std::shared_ptr< Session_Manager > &session_manager, const std::shared_ptr< RandomNumberGenerator > &rng, const std::shared_ptr< const Policy > &policy, bool is_server, TLS_Flavor flavor, size_t io_buf_sz=TLS::Channel::IO_BUF_DEFAULT_SIZE)
Session_Manager & session_manager()
const Policy & policy() const
const std::optional< Active_Connection_State_12 > & active_state() const
static constexpr size_t IO_BUF_DEFAULT_SIZE
Definition tls_channel.h:38
Client_Impl_12(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, TLS_Flavor flavor, size_t reserved_io_buffer_size)
std::string application_protocol() const override
static std::shared_ptr< Client_Impl_12 > 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(), TLS_Flavor flavor=TLS_Flavor::TLS, const std::vector< std::string > &next_protocols={}, size_t reserved_io_buffer_size=TLS::Channel::IO_BUF_DEFAULT_SIZE)