Botan 2.19.3
Crypto and TLS for C&
tls_blocking.h
Go to the documentation of this file.
1/*
2* TLS Blocking API
3* (C) 2013 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_BLOCKING_CHANNELS_H_
10#define BOTAN_TLS_BLOCKING_CHANNELS_H_
11
12#include <botan/tls_client.h>
13
14namespace Botan {
15
16namespace TLS {
17
18/**
19* Blocking TLS Client
20* Can be used directly, or subclass to get handshake and alert notifications
21*/
23 {
24 public:
25 /*
26 * These functions are expected to block until completing entirely, or
27 * fail by throwing an exception.
28 */
29 typedef std::function<size_t (uint8_t[], size_t)> read_fn;
30 typedef std::function<void (const uint8_t[], size_t)> write_fn;
31
32 BOTAN_DEPRECATED("Use the regular TLS::Client interface")
34 write_fn writer,
35 Session_Manager& session_manager,
37 const Policy& policy,
39 const Server_Information& server_info = Server_Information(),
40 const Protocol_Version& offer_version = Protocol_Version::latest_tls_version(),
41 const std::vector<std::string>& next_protos = {});
42
43 /**
44 * Completes full handshake then returns
45 */
46 void do_handshake();
47
48 /**
49 * Number of bytes pending read in the plaintext buffer (bytes
50 * readable without blocking)
51 */
52 size_t pending() const { return m_plaintext.size(); }
53
54 /**
55 * Blocking read, will return at least 1 byte (eventually) or else 0 if the connection
56 * is closed.
57 */
58 size_t read(uint8_t buf[], size_t buf_len);
59
60 void write(const uint8_t buf[], size_t buf_len) { m_channel.send(buf, buf_len); }
61
62 const TLS::Channel& underlying_channel() const { return m_channel; }
63 TLS::Channel& underlying_channel() { return m_channel; }
64
65 void close() { m_channel.close(); }
66
67 bool is_closed() const { return m_channel.is_closed(); }
68
69 std::vector<X509_Certificate> peer_cert_chain() const
70 { return m_channel.peer_cert_chain(); }
71
72 virtual ~Blocking_Client() = default;
73
74 protected:
75 /**
76 * Application can override to get the handshake complete notification
77 */
78 virtual bool handshake_complete(const Session&) { return true; }
79
80 /**
81 * Application can override to get notification of alerts
82 */
83 virtual void alert_notification(const Alert&) {}
84
85 private:
86
87 bool handshake_cb(const Session&);
88
89 void data_cb(const uint8_t data[], size_t data_len);
90
91 void alert_cb(const Alert& alert);
92
93 read_fn m_read;
94 std::unique_ptr<Compat_Callbacks> m_callbacks;
95 TLS::Client m_channel;
96 secure_vector<uint8_t> m_plaintext;
97 };
98
99}
100
101}
102
103#endif
std::function< size_t(uint8_t[], size_t)> read_fn
std::function< void(const uint8_t[], size_t)> write_fn
void write(const uint8_t buf[], size_t buf_len)
TLS::Channel & underlying_channel()
virtual bool handshake_complete(const Session &)
virtual ~Blocking_Client()=default
std::vector< X509_Certificate > peer_cert_chain() const
const TLS::Channel & underlying_channel() const
virtual void alert_notification(const Alert &)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:65
Definition bigint.h:1143