Botan
1.11.15
|
00001 /* 00002 * TLS Client 00003 * (C) 2004-2011 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_TLS_CLIENT_H__ 00009 #define BOTAN_TLS_CLIENT_H__ 00010 00011 #include <botan/tls_channel.h> 00012 #include <botan/credentials_manager.h> 00013 #include <vector> 00014 00015 namespace Botan { 00016 00017 namespace TLS { 00018 00019 /** 00020 * SSL/TLS Client 00021 */ 00022 class BOTAN_DLL Client : public Channel 00023 { 00024 public: 00025 /** 00026 * Set up a new TLS client session 00027 * 00028 * @param output_fn is called with data for the outbound socket 00029 * 00030 * @param app_data_cb is called when new application data is received 00031 * 00032 * @param alert_cb is called when a TLS alert is received 00033 * 00034 * @param handshake_cb is called when a handshake is completed 00035 * 00036 * @param session_manager manages session state 00037 * 00038 * @param creds manages application/user credentials 00039 * 00040 * @param policy specifies other connection policy information 00041 * 00042 * @param rng a random number generator 00043 * 00044 * @param server_info is identifying information about the TLS server 00045 * 00046 * @param offer_version specifies which version we will offer 00047 * to the TLS server. 00048 * 00049 * @param next_protocol allows the client to specify what the next 00050 * protocol will be. For more information read 00051 * http://technotes.googlecode.com/git/nextprotoneg.html. 00052 * 00053 * If the function is not empty, NPN will be negotiated 00054 * and if the server supports NPN the function will be 00055 * called with the list of protocols the server advertised; 00056 * the client should return the protocol it would like to use. 00057 * 00058 * @param reserved_io_buffer_size This many bytes of memory will 00059 * be preallocated for the read and write buffers. Smaller 00060 * values just mean reallocations and copies are more likely. 00061 */ 00062 00063 typedef std::function<std::string (std::vector<std::string>)> next_protocol_fn; 00064 00065 Client(output_fn out, 00066 data_cb app_data_cb, 00067 alert_cb alert_cb, 00068 handshake_cb hs_cb, 00069 Session_Manager& session_manager, 00070 Credentials_Manager& creds, 00071 const Policy& policy, 00072 RandomNumberGenerator& rng, 00073 const Server_Information& server_info = Server_Information(), 00074 const Protocol_Version offer_version = Protocol_Version::latest_tls_version(), 00075 next_protocol_fn next_protocol = next_protocol_fn(), 00076 size_t reserved_io_buffer_size = 16*1024 00077 ); 00078 private: 00079 std::vector<X509_Certificate> 00080 get_peer_cert_chain(const Handshake_State& state) const override; 00081 00082 void initiate_handshake(Handshake_State& state, 00083 bool force_full_renegotiation) override; 00084 00085 void send_client_hello(Handshake_State& state, 00086 bool force_full_renegotiation, 00087 Protocol_Version version, 00088 const std::string& srp_identifier = "", 00089 next_protocol_fn next_protocol = next_protocol_fn()); 00090 00091 void process_handshake_msg(const Handshake_State* active_state, 00092 Handshake_State& pending_state, 00093 Handshake_Type type, 00094 const std::vector<byte>& contents) override; 00095 00096 Handshake_State* new_handshake_state(Handshake_IO* io) override; 00097 00098 const Policy& m_policy; 00099 Credentials_Manager& m_creds; 00100 const Server_Information m_info; 00101 }; 00102 00103 } 00104 00105 } 00106 00107 #endif