9 #ifndef BOTAN_TLS_CHANNEL_H__
10 #define BOTAN_TLS_CHANNEL_H__
12 #include <botan/tls_policy.h>
13 #include <botan/tls_session.h>
14 #include <botan/tls_alert.h>
15 #include <botan/tls_session_manager.h>
16 #include <botan/tls_callbacks.h>
17 #include <botan/x509cert.h>
26 class Connection_Cipher_State;
27 class Connection_Sequence_Numbers;
28 class Handshake_State;
29 class Handshake_Message;
39 typedef std::function<void (const uint8_t[], size_t)>
output_fn;
40 typedef std::function<void (const uint8_t[], size_t)>
data_cb;
41 typedef std::function<void (Alert, const uint8_t[], size_t)>
alert_cb;
69 size_t io_buf_sz = IO_BUF_DEFAULT_SIZE);
81 handshake_msg_cb hs_msg_cb,
86 size_t io_buf_sz = IO_BUF_DEFAULT_SIZE);
99 size_t received_data(
const uint8_t buf[],
size_t buf_size);
106 size_t received_data(
const std::vector<uint8_t>& buf);
112 void send(
const uint8_t buf[],
size_t buf_size);
118 void send(
const std::string& val);
124 template<
typename Alloc>
125 void send(
const std::vector<unsigned char, Alloc>& val)
127 send(val.data(), val.size());
135 void send_alert(
const Alert& alert);
155 bool is_active()
const;
160 bool is_closed()
const;
166 std::vector<X509_Certificate> peer_cert_chain()
const;
175 SymmetricKey key_material_export(
const std::string& label,
176 const std::string& context,
177 size_t length)
const;
184 void renegotiate(
bool force_full_renegotiation =
false);
190 bool secure_renegotiation_supported()
const;
198 bool timeout_check();
202 virtual void process_handshake_msg(
const Handshake_State* active_state,
205 const std::vector<uint8_t>& contents) = 0;
208 bool force_full_renegotiation) = 0;
210 virtual std::vector<X509_Certificate>
219 void activate_session();
227 void secure_renegotiation_check(
const Client_Hello* client_hello);
228 void secure_renegotiation_check(
const Server_Hello* server_hello);
230 std::vector<uint8_t> secure_renegotiation_data_for_client_hello()
const;
231 std::vector<uint8_t> secure_renegotiation_data_for_server_hello()
const;
243 void init(
size_t io_buf_sze);
245 void send_record(uint8_t record_type,
const std::vector<uint8_t>& record);
247 void send_record_under_epoch(uint16_t epoch, uint8_t record_type,
248 const std::vector<uint8_t>& record);
250 void send_record_array(uint16_t epoch, uint8_t record_type,
251 const uint8_t input[],
size_t length);
254 uint16_t epoch, uint8_t
type,
const uint8_t input[],
size_t length);
258 std::shared_ptr<Connection_Cipher_State> read_cipher_state_epoch(uint16_t epoch)
const;
260 std::shared_ptr<Connection_Cipher_State> write_cipher_state_epoch(uint16_t epoch)
const;
264 const Handshake_State* active_state()
const {
return m_active_state.get(); }
266 const Handshake_State* pending_state()
const {
return m_pending_state.get(); }
269 void process_handshake_ccs(
const secure_vector<uint8_t>& record,
270 uint64_t record_sequence,
272 Protocol_Version record_version);
274 void process_application_data(uint64_t req_no,
const secure_vector<uint8_t>& record);
276 void process_alert(
const secure_vector<uint8_t>& record);
281 std::unique_ptr<Compat_Callbacks> m_compat_callbacks;
282 Callbacks& m_callbacks;
285 Session_Manager& m_session_manager;
286 const Policy& m_policy;
287 RandomNumberGenerator&
m_rng;
290 std::unique_ptr<Connection_Sequence_Numbers> m_sequence_numbers;
293 std::unique_ptr<Handshake_State> m_active_state;
294 std::unique_ptr<Handshake_State> m_pending_state;
297 std::map<uint16_t, std::shared_ptr<Connection_Cipher_State>> m_write_cipher_states;
298 std::map<uint16_t, std::shared_ptr<Connection_Cipher_State>> m_read_cipher_states;
301 secure_vector<uint8_t> m_writebuf;
302 secure_vector<uint8_t> m_readbuf;
Callbacks & callbacks() const
std::function< void(Alert, const uint8_t[], size_t)> alert_cb
bool save_session(const Session &session) const
void send(const std::vector< unsigned char, Alloc > &val)
void send_warning_alert(Alert::Type type)
std::function< void(const uint8_t[], size_t)> output_fn
RandomNumberGenerator & rng()
std::function< bool(const Session &)> handshake_cb
static size_t IO_BUF_DEFAULT_SIZE
void send_fatal_alert(Alert::Type type)
RandomNumberGenerator & m_rng
std::function< void(const uint8_t[], size_t)> data_cb
void write_record(secure_vector< uint8_t > &output, Record_Message msg, Protocol_Version version, uint64_t seq, Connection_Cipher_State *cs, RandomNumberGenerator &rng)
const Policy & policy() const
Session_Manager & session_manager()
std::function< void(const Handshake_Message &)> handshake_msg_cb