Botan  2.1.0
Crypto and TLS for C++11
tls_client.h
Go to the documentation of this file.
1 /*
2 * TLS Client
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_H__
10 #define BOTAN_TLS_CLIENT_H__
11 
12 #include <botan/tls_channel.h>
13 #include <botan/credentials_manager.h>
14 #include <vector>
15 
16 namespace Botan {
17 
18 namespace TLS {
19 
20 /**
21 * SSL/TLS Client
22 */
23 class BOTAN_DLL Client final : public Channel
24  {
25  public:
26 
27  /**
28  * Set up a new TLS client session
29  *
30  * @param callbacks contains a set of callback function references
31  * required by the TLS client.
32  *
33  * @param session_manager manages session state
34  *
35  * @param creds manages application/user credentials
36  *
37  * @param policy specifies other connection policy information
38  *
39  * @param rng a random number generator
40  *
41  * @param server_info is identifying information about the TLS server
42  *
43  * @param offer_version specifies which version we will offer
44  * to the TLS server.
45  *
46  * @param next_protocols specifies protocols to advertise with ALPN
47  *
48  * @param reserved_io_buffer_size This many bytes of memory will
49  * be preallocated for the read and write buffers. Smaller
50  * values just mean reallocations and copies are more likely.
51  */
52  Client(Callbacks& callbacks,
53  Session_Manager& session_manager,
54  Credentials_Manager& creds,
55  const Policy& policy,
57  const Server_Information& server_info = Server_Information(),
59  const std::vector<std::string>& next_protocols = {},
60  size_t reserved_io_buffer_size = TLS::Client::IO_BUF_DEFAULT_SIZE
61  );
62 
63  /**
64  * DEPRECATED. This constructor is only provided for backward
65  * compatibility and should not be used in new code.
66  *
67  * Set up a new TLS client session
68  *
69  * @param output_fn is called with data for the outbound socket
70  *
71  * @param app_data_cb is called when new application data is received
72  *
73  * @param alert_cb is called when a TLS alert is received
74  *
75  * @param hs_cb is called when a handshake is completed
76  *
77  * @param session_manager manages session state
78  *
79  * @param creds manages application/user credentials
80  *
81  * @param policy specifies other connection policy information
82  *
83  * @param rng a random number generator
84  *
85  * @param server_info is identifying information about the TLS server
86  *
87  * @param offer_version specifies which version we will offer
88  * to the TLS server.
89  *
90  * @param next_protocols specifies protocols to advertise with ALPN
91  *
92  * @param reserved_io_buffer_size This many bytes of memory will
93  * be preallocated for the read and write buffers. Smaller
94  * values just mean reallocations and copies are more likely.
95  */
96  BOTAN_DEPRECATED("Use TLS::Client(TLS::Callbacks ...)")
98  data_cb app_data_cb,
100  handshake_cb hs_cb,
101  Session_Manager& session_manager,
102  Credentials_Manager& creds,
103  const Policy& policy,
105  const Server_Information& server_info = Server_Information(),
107  const std::vector<std::string>& next_protocols = {},
108  size_t reserved_io_buffer_size = TLS::Client::IO_BUF_DEFAULT_SIZE
109  );
110 
111  /**
112  * DEPRECATED. This constructor is only provided for backward
113  * compatibility and should not be used in new implementations.
114  */
115  BOTAN_DEPRECATED("Use TLS::Client(TLS::Callbacks ...)")
116  Client(output_fn out,
117  data_cb app_data_cb,
118  alert_cb alert_cb,
119  handshake_cb hs_cb,
120  handshake_msg_cb hs_msg_cb,
121  Session_Manager& session_manager,
122  Credentials_Manager& creds,
123  const Policy& policy,
125  const Server_Information& server_info = Server_Information(),
127  const std::vector<std::string>& next_protocols = {}
128  );
129 
130  /**
131  * @return network protocol as advertised by the TLS server, if server sent the ALPN extension
132  */
133  const std::string& application_protocol() const { return m_application_protocol; }
134  private:
135  void init(const Protocol_Version& protocol_version,
136  const std::vector<std::string>& next_protocols);
137 
138  std::vector<X509_Certificate>
139  get_peer_cert_chain(const Handshake_State& state) const override;
140 
141  void initiate_handshake(Handshake_State& state,
142  bool force_full_renegotiation) override;
143 
144  void send_client_hello(Handshake_State& state,
145  bool force_full_renegotiation,
146  Protocol_Version version,
147  const std::string& srp_identifier = "",
148  const std::vector<std::string>& next_protocols = {});
149 
150  void process_handshake_msg(const Handshake_State* active_state,
151  Handshake_State& pending_state,
153  const std::vector<uint8_t>& contents) override;
154 
155  Handshake_State* new_handshake_state(Handshake_IO* io) override;
156 
157  Credentials_Manager& m_creds;
158  const Server_Information m_info;
159  std::string m_application_protocol;
160  };
161 
162 }
163 
164 }
165 
166 #endif
std::function< void(Alert, const uint8_t[], size_t)> alert_cb
Definition: tls_channel.h:41
std::function< void(const uint8_t[], size_t)> output_fn
Definition: tls_channel.h:39
static Protocol_Version latest_tls_version()
Definition: tls_version.h:36
MechanismType type
const std::string & application_protocol() const
Definition: tls_client.h:133
class BOTAN_DLL BOTAN_DEPRECATED("LibraryInitializer is no longer required") LibraryInitializer
Definition: init.h:22
std::function< bool(const Session &)> handshake_cb
Definition: tls_channel.h:42
static size_t IO_BUF_DEFAULT_SIZE
Definition: tls_channel.h:44
Definition: alg_id.cpp:13
std::function< void(const uint8_t[], size_t)> data_cb
Definition: tls_channel.h:40
std::function< void(const Handshake_Message &)> handshake_msg_cb
Definition: tls_channel.h:43