Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
14 namespace Botan {
15
16 namespace TLS {
17
18 /**
19 * Blocking TLS Client
20 * Can be used directly, or subclass to get handshake and alert notifications
21 */
22 class BOTAN_PUBLIC_API(2,0) Blocking_Client
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")
33 Blocking_Client(read_fn reader,
34 write_fn writer,
35 Session_Manager& session_manager,
36 Credentials_Manager& creds,
37 const Policy& policy,
38 RandomNumberGenerator& rng,
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
Botan::TLS::Channel
Definition: tls_channel.h:37
Botan::TLS::Session_Manager
Definition: tls_session_manager.h:29
Botan::TLS::Session
Definition: tls_session.h:27
Botan::TLS::Blocking_Client
Definition: tls_blocking.h:22
Botan::RandomNumberGenerator
Definition: rng.h:24
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
std
Definition: bigint.h:1135
Botan::TLS::Blocking_Client::read_fn
std::function< size_t(uint8_t[], size_t)> read_fn
Definition: tls_blocking.h:29
Botan::TLS::Blocking_Client::alert_notification
virtual void alert_notification(const Alert &)
Definition: tls_blocking.h:83
Botan::TLS::Protocol_Version
Definition: tls_version.h:21
Botan::TLS::Blocking_Client::write
void write(const uint8_t buf[], size_t buf_len)
Definition: tls_blocking.h:60
Botan::TLS::Blocking_Client::underlying_channel
TLS::Channel & underlying_channel()
Definition: tls_blocking.h:63
Botan::TLS::Blocking_Client::is_closed
bool is_closed() const
Definition: tls_blocking.h:67
Botan::TLS::Blocking_Client::write_fn
std::function< void(const uint8_t[], size_t)> write_fn
Definition: tls_blocking.h:30
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::TLS::Blocking_Client::underlying_channel
const TLS::Channel & underlying_channel() const
Definition: tls_blocking.h:62
Botan::TLS::Server_Information
Definition: tls_server_info.h:21
Botan
Definition: alg_id.cpp:13
Botan::Credentials_Manager
Definition: credentials_manager.h:30
Botan::TLS::Blocking_Client::handshake_complete
virtual bool handshake_complete(const Session &)
Definition: tls_blocking.h:78
Botan::TLS::Policy
Definition: tls_policy.h:28
Botan::TLS::Blocking_Client::peer_cert_chain
std::vector< X509_Certificate > peer_cert_chain() const
Definition: tls_blocking.h:69
Botan::TLS::Blocking_Client::pending
size_t pending() const
Definition: tls_blocking.h:52
Botan::TLS::Alert
Definition: tls_alert.h:21
Botan::TLS::Blocking_Client::close
void close()
Definition: tls_blocking.h:65
Botan::TLS::Client
Definition: tls_client.h:24