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