Botan 3.0.0
Crypto and TLS for C&
Public Member Functions | Static Public Attributes | List of all members
Botan::TLS::Client Class Referencefinal

#include <tls_client.h>

Inheritance diagram for Botan::TLS::Client:
Botan::TLS::Channel

Public Member Functions

std::string application_protocol () const override
 
 Client (const std::shared_ptr< Callbacks > &callbacks, const std::shared_ptr< Session_Manager > &session_manager, const std::shared_ptr< Credentials_Manager > &creds, const std::shared_ptr< const Policy > &policy, const std::shared_ptr< RandomNumberGenerator > &rng, Server_Information server_info=Server_Information(), Protocol_Version offer_version=Protocol_Version::latest_tls_version(), const std::vector< std::string > &next_protocols={}, size_t reserved_io_buffer_size=TLS::Client::IO_BUF_DEFAULT_SIZE)
 
void close () override
 
size_t from_peer (std::span< const uint8_t > data) override
 
bool is_active () const override
 
bool is_closed () const override
 
bool is_closed_for_reading () const override
 
bool is_closed_for_writing () const override
 
SymmetricKey key_material_export (std::string_view label, std::string_view context, size_t length) const override
 
std::vector< X509_Certificatepeer_cert_chain () const override
 
size_t received_data (const uint8_t buf[], size_t buf_size)
 
size_t received_data (std::span< const uint8_t > data)
 
void renegotiate (bool force_full_renegotiation=false) override
 
bool secure_renegotiation_supported () const override
 
void send (const uint8_t buf[], size_t buf_size)
 
void send (std::span< const uint8_t > data)
 
void send (std::string_view val)
 
void send_alert (const Alert &alert) override
 
void send_fatal_alert (Alert::Type type) override
 
void send_warning_alert (Alert::Type type) override
 
bool timeout_check () override
 
void to_peer (std::span< const uint8_t > data) override
 
void update_traffic_keys (bool request_peer_update=false) override
 
 ~Client ()
 

Static Public Attributes

static constexpr size_t IO_BUF_DEFAULT_SIZE = 10*1024
 

Detailed Description

SSL/TLS Client

Definition at line 30 of file tls_client.h.

Constructor & Destructor Documentation

◆ Client()

Botan::TLS::Client::Client ( const std::shared_ptr< Callbacks > &  callbacks,
const std::shared_ptr< Session_Manager > &  session_manager,
const std::shared_ptr< Credentials_Manager > &  creds,
const std::shared_ptr< const Policy > &  policy,
const std::shared_ptr< RandomNumberGenerator > &  rng,
Server_Information  server_info = Server_Information(),
Protocol_Version  offer_version = Protocol_Version::latest_tls_version(),
const std::vector< std::string > &  next_protocols = {},
size_t  reserved_io_buffer_size = TLS::Client::IO_BUF_DEFAULT_SIZE 
)

Set up a new TLS client session

Parameters
callbackscontains a set of callback function references required by the TLS client.
session_managermanages session state
credsmanages application/user credentials
policyspecifies other connection policy information
rnga random number generator
server_infois identifying information about the TLS server
offer_versionspecifies which version we will offer to the TLS server.
next_protocolsspecifies protocols to advertise with ALPN
reserved_io_buffer_sizeThis many bytes of memory will be preallocated for the read and write buffers. Smaller values just mean reallocations and copies are more likely.

Definition at line 29 of file tls_client.cpp.

38 {
39 BOTAN_ARG_CHECK(policy->acceptable_protocol_version(offer_version),
40 "Policy does not allow to offer requested protocol version");
41
42#if defined(BOTAN_HAS_TLS_13)
43 if(offer_version == Protocol_Version::TLS_V13)
44 {
45 m_impl = std::make_unique<Client_Impl_13>(
46 callbacks, session_manager, creds, policy,
47 rng, std::move(info), next_protocols);
48
49 if(m_impl->expects_downgrade())
50 { m_impl->set_io_buffer_size(io_buf_sz); }
51
52 if(m_impl->is_downgrading())
53 {
54 // TLS 1.3 implementation found a resumable TLS 1.2 session and
55 // requested a downgrade right away.
56 downgrade();
57 }
58 }
59 else
60#endif
61 m_impl = std::make_unique<Client_Impl_12>(
62 callbacks, session_manager, creds, policy,
63 rng, std::move(info), offer_version.is_datagram_protocol(),
64 next_protocols, io_buf_sz);
65 }
#define BOTAN_ARG_CHECK(expr, msg)
Definition: assert.h:36

References BOTAN_ARG_CHECK, and Botan::TLS::Protocol_Version::is_datagram_protocol().

◆ ~Client()

Botan::TLS::Client::~Client ( )
default

Member Function Documentation

◆ application_protocol()

std::string Botan::TLS::Client::application_protocol ( ) const
overridevirtual
Returns
network protocol as advertised by the TLS server, if server sent the ALPN extension

Implements Botan::TLS::Channel.

Definition at line 178 of file tls_client.cpp.

179 {
180 return m_impl->application_protocol();
181 }

◆ close()

void Botan::TLS::Client::close ( )
overridevirtual

Send a close notification alert

Implements Botan::TLS::Channel.

Definition at line 168 of file tls_client.cpp.

169 {
170 m_impl->close();
171 }

◆ from_peer()

size_t Botan::TLS::Client::from_peer ( std::span< const uint8_t >  data)
overridevirtual

Implements Botan::TLS::Channel.

Definition at line 89 of file tls_client.cpp.

90 {
91 auto read = m_impl->from_peer(data);
92
93 if(m_impl->is_downgrading())
94 {
95 read = downgrade();
96 }
97
98 return read;
99 }

◆ is_active()

bool Botan::TLS::Client::is_active ( ) const
overridevirtual
Returns
true iff the connection is active for sending application data

Implements Botan::TLS::Channel.

Definition at line 101 of file tls_client.cpp.

102 {
103 return m_impl->is_active();
104 }

◆ is_closed()

bool Botan::TLS::Client::is_closed ( ) const
overridevirtual

Note: For TLS 1.3 a connection is closed only after both peers have signaled a "close_notify". While TLS 1.2 automatically responded in suit once the peer had sent "close_notify", TLS 1.3 allows to continue transmitting data even if the peer closed their writing end.

Returns
true iff the connection has been definitely closed

Implements Botan::TLS::Channel.

Definition at line 106 of file tls_client.cpp.

107 {
108 return m_impl->is_closed();
109 }

◆ is_closed_for_reading()

bool Botan::TLS::Client::is_closed_for_reading ( ) const
overridevirtual
Returns
true iff the peer closed their channel (i.e. no more incoming data expected)

Implements Botan::TLS::Channel.

Definition at line 111 of file tls_client.cpp.

112 {
113 return m_impl->is_closed_for_reading();
114 }

◆ is_closed_for_writing()

bool Botan::TLS::Client::is_closed_for_writing ( ) const
overridevirtual
Returns
true iff we closed our channel (i.e. no more outgoing data allowed)

Implements Botan::TLS::Channel.

Definition at line 116 of file tls_client.cpp.

117 {
118 return m_impl->is_closed_for_writing();
119 }

◆ key_material_export()

SymmetricKey Botan::TLS::Client::key_material_export ( std::string_view  label,
std::string_view  context,
size_t  length 
) const
overridevirtual

Key material export (RFC 5705)

Parameters
labela disambiguating label string
contexta per-association context value
lengththe length of the desired key in bytes
Returns
key of length bytes

Implements Botan::TLS::Channel.

Definition at line 126 of file tls_client.cpp.

129 {
130 return m_impl->key_material_export(label, context, length);
131 }

◆ peer_cert_chain()

std::vector< X509_Certificate > Botan::TLS::Client::peer_cert_chain ( ) const
overridevirtual
Returns
certificate chain of the peer (may be empty)

Implements Botan::TLS::Channel.

Definition at line 121 of file tls_client.cpp.

122 {
123 return m_impl->peer_cert_chain();
124 }

◆ received_data() [1/2]

size_t Botan::TLS::Channel::received_data ( const uint8_t  buf[],
size_t  buf_size 
)
inlineinherited

Definition at line 49 of file tls_channel.h.

50 { return this->from_peer(std::span(buf, buf_size)); }
virtual size_t from_peer(std::span< const uint8_t > data)=0

◆ received_data() [2/2]

size_t Botan::TLS::Channel::received_data ( std::span< const uint8_t >  data)
inlineinherited

Inject TLS traffic received from counterparty

Returns
a hint as to how many more bytes we need to process the current record (this may be 0 if on a record boundary)

Definition at line 47 of file tls_channel.h.

48 { return this->from_peer(data); }

◆ renegotiate()

void Botan::TLS::Client::renegotiate ( bool  force_full_renegotiation = false)
overridevirtual

Attempt to renegotiate the session

Parameters
force_full_renegotiationif true, require a full renegotiation, otherwise allow session resumption

Implements Botan::TLS::Channel.

Definition at line 133 of file tls_client.cpp.

134 {
135 m_impl->renegotiate(force_full_renegotiation);
136 }

◆ secure_renegotiation_supported()

bool Botan::TLS::Client::secure_renegotiation_supported ( ) const
overridevirtual
Returns
true iff the counterparty supports the secure renegotiation extensions.

Implements Botan::TLS::Channel.

Definition at line 143 of file tls_client.cpp.

144 {
145 return m_impl->secure_renegotiation_supported();
146 }

◆ send() [1/3]

void Botan::TLS::Channel::send ( const uint8_t  buf[],
size_t  buf_size 
)
inlineinherited

Definition at line 58 of file tls_channel.h.

59 { this->to_peer(std::span(buf, buf_size)); }
virtual void to_peer(std::span< const uint8_t > data)=0

◆ send() [2/3]

void Botan::TLS::Channel::send ( std::span< const uint8_t >  data)
inlineinherited

Inject plaintext intended for counterparty Throws an exception if is_active() is false

Definition at line 56 of file tls_channel.h.

57 { this->to_peer(data); }

◆ send() [3/3]

void Botan::TLS::Channel::send ( std::string_view  val)
inlineinherited

Inject plaintext intended for counterparty Throws an exception if is_active() is false

Definition at line 65 of file tls_channel.h.

66 { this->send(std::span(cast_char_ptr_to_uint8(val.data()), val.size())); }
void send(std::span< const uint8_t > data)
Definition: tls_channel.h:56
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:183

References Botan::cast_char_ptr_to_uint8().

◆ send_alert()

void Botan::TLS::Client::send_alert ( const Alert alert)
overridevirtual

Inject plaintext intended for counterparty Throws an exception if is_active() is false Send a TLS alert message. If the alert is fatal, the internal state (keys, etc) will be reset.

Parameters
alertthe Alert to send

Implements Botan::TLS::Channel.

Definition at line 153 of file tls_client.cpp.

154 {
155 m_impl->send_alert(alert);
156 }

◆ send_fatal_alert()

void Botan::TLS::Client::send_fatal_alert ( Alert::Type  type)
overridevirtual

Send a fatal alert

Implements Botan::TLS::Channel.

Definition at line 163 of file tls_client.cpp.

164 {
165 m_impl->send_fatal_alert(type);
166 }

◆ send_warning_alert()

void Botan::TLS::Client::send_warning_alert ( Alert::Type  type)
overridevirtual

Send a warning alert

Implements Botan::TLS::Channel.

Definition at line 158 of file tls_client.cpp.

159 {
160 m_impl->send_warning_alert(type);
161 }

◆ timeout_check()

bool Botan::TLS::Client::timeout_check ( )
overridevirtual

Perform a handshake timeout check. This does nothing unless this is a DTLS channel with a pending handshake state, in which case we check for timeout and potentially retransmit handshake packets.

Implements Botan::TLS::Channel.

Definition at line 173 of file tls_client.cpp.

174 {
175 return m_impl->timeout_check();
176 }

◆ to_peer()

void Botan::TLS::Client::to_peer ( std::span< const uint8_t >  data)
overridevirtual

Implements Botan::TLS::Channel.

Definition at line 148 of file tls_client.cpp.

149 {
150 m_impl->to_peer(data);
151 }

◆ update_traffic_keys()

void Botan::TLS::Client::update_traffic_keys ( bool  request_peer_update = false)
overridevirtual

Attempt to update the session's traffic key material Note that this is possible with a TLS 1.3 channel, only.

Parameters
request_peer_updateif true, require a reciprocal key update

Implements Botan::TLS::Channel.

Definition at line 138 of file tls_client.cpp.

139 {
140 m_impl->update_traffic_keys(request_peer_update);
141 }

Member Data Documentation

◆ IO_BUF_DEFAULT_SIZE

constexpr size_t Botan::TLS::Channel::IO_BUF_DEFAULT_SIZE = 10*1024
staticconstexprinherited

Definition at line 33 of file tls_channel.h.

Referenced by Botan::TLS::Channel_Impl_13::expect_downgrade().


The documentation for this class was generated from the following files: