Botan 2.19.5 Crypto and TLS for C&

Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Botan::TLS::Stream< StreamLayer, ChannelT > Class Template Reference

boost::asio compatible SSL/TLS stream More...

`#include <asio_stream.h>`

## Classes
class | StreamCore
| Helper class that implements Botan::TLS::Callbacks. More...

## Public Member Functions
bool | shutdown_received () const
| Indicates whether a close_notify alert has been received from the peer. More...
construction
template<typename... Args>
| Stream (Context &context, Args &&... args)
| Construct a new Stream. More...
template<typename Arg >
| Stream (Arg &&arg, Context &context)
| Construct a new Stream. More...
virtual | ~Stream ()
| Stream (Stream &&other)=default
Stream & | operator= (Stream &&other)=default
| Stream (const Stream &other)=delete
Stream & | operator= (const Stream &other)=delete
configuration and callback setters
void | set_verify_callback (Context::Verify_Callback callback)
| Override the tls_verify_cert_chain callback. More...
void | set_verify_callback (Context::Verify_Callback callback, boost::system::error_code &ec)
| Compatibility overload of set_verify_callback. More...
void | set_verify_depth (int depth)
void | set_verify_depth (int depth, boost::system::error_code &ec)
template<typename verify_mode >
void | set_verify_mode (verify_mode v)
template<typename verify_mode >
void | set_verify_mode (verify_mode v, boost::system::error_code &ec)
shutdown methods
void | shutdown (boost::system::error_code &ec)
| Shut down SSL on the stream. More...
void | shutdown ()
| Shut down SSL on the stream. More...
template<typename ShutdownHandler >
void | async_shutdown (ShutdownHandler &&handler)
| Asynchronously shut down SSL on the stream. More...
I/O methods
template<typename MutableBufferSequence >
std::size_t | read_some (const MutableBufferSequence &buffers, boost::system::error_code &ec)
| Read some data from the stream. More...
template<typename MutableBufferSequence >
std::size_t | read_some (const MutableBufferSequence &buffers)
| Read some data from the stream. More...
template<typename ConstBufferSequence >
std::size_t | write_some (const ConstBufferSequence &buffers, boost::system::error_code &ec)
| Write some data to the stream. More...
template<typename ConstBufferSequence >
std::size_t | write_some (const ConstBufferSequence &buffers)
| Write some data to the stream. More...
template<typename ConstBufferSequence , typename WriteHandler >
auto | async_write_some (const ConstBufferSequence &buffers, WriteHandler &&handler) -> BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void(boost::system::error_code, std::size_t))
| Start an asynchronous write. The function call always returns immediately. More...
template<typename MutableBufferSequence , typename ReadHandler >
auto | async_read_some (const MutableBufferSequence &buffers, ReadHandler &&handler) -> BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void(boost::system::error_code, std::size_t))
| Start an asynchronous read. The function call always returns immediately. More...

## Protected Member Functions
void | consume_send_buffer (std::size_t bytesConsumed)
| Mark bytes in the send buffer as consumed, removing them from the buffer. More...
template<typename MutableBufferSequence >
std::size_t | copy_received_data (MutableBufferSequence buffers)
| Copy decrypted data into the user-provided buffer. More...
bool | has_data_to_send () const
| Check if encrypted data is available in the send buffer. More...
bool | has_received_data () const
| Check if decrypted data is available in the receive buffer. More...
const boost::asio::mutable_buffer & | input_buffer ()
void | process_encrypted_data (const boost::asio::const_buffer &read_buffer, boost::system::error_code &ec)
| Pass encrypted data to the native handle for processing. More...
boost::asio::const_buffer | send_buffer () const
size_t | send_pending_encrypted_data (boost::system::error_code &ec)
| Synchronously write encrypted data from the send buffer to the next layer. More...
void | set_shutdown_received ()
template<class T = ChannelT>
std::enable_if< std::is_same< Channel, T >::value >::type | setup_native_handle (Connection_Side side, boost::system::error_code &ec)
| Create the native handle. More...
template<class T = ChannelT>
std::enable_if<!std::is_same< Channel, T >::value >::type | setup_native_handle (Connection_Side, boost::system::error_code &)
template<typename ConstBufferSequence >
void | tls_encrypt (const ConstBufferSequence &buffers, boost::system::error_code &ec)
| Pass plaintext data to the native handle for processing. More...
template<typename Fun >
void | try_with_error_code (Fun f, boost::system::error_code &ec)
| Catch exceptions and set an error_code. More...

## Protected Attributes
Context & | m_context
StreamCore | m_core
const boost::asio::mutable_buffer | m_input_buffer
std::vector< uint8_t > | m_input_buffer_space
std::unique_ptr< ChannelT > | m_native_handle
StreamLayer | m_nextLayer
boost::beast::flat_buffer | m_receive_buffer
boost::beast::flat_buffer | m_send_buffer
bool | m_shutdown_received

## Friends
template<class H , class S , class A >
class | detail::AsyncHandshakeOperation
template<class H , class S , class M , class A >
class | detail::AsyncReadOperation
template<class H , class S , class A >
class | detail::AsyncWriteOperation

## boost::asio accessor methods
using | next_layer_type = typename std::remove_reference< StreamLayer >::type
using | lowest_layer_type = typename next_layer_type::lowest_layer_type
using | executor_type = typename next_layer_type::executor_type
using | native_handle_type = typename std::add_pointer< ChannelT >::type
const next_layer_type & | next_layer () const
next_layer_type & | next_layer ()
lowest_layer_type & | lowest_layer ()
const lowest_layer_type & | lowest_layer () const
executor_type | get_executor () noexcept
native_handle_type | native_handle ()

## handshake methods
const ConstBufferSequence & | buffers
const ConstBufferSequence BufferedHandshakeHandler && | handler
void | handshake (Connection_Side side)
| Performs SSL handshaking. More...
void | handshake (Connection_Side side, boost::system::error_code &ec)
| Performs SSL handshaking. More...
template<typename HandshakeHandler >
auto | async_handshake (Connection_Side side, HandshakeHandler &&handler) ->
| Starts an asynchronous SSL handshake. More...
template<typename ConstBufferSequence , typename BufferedHandshakeHandler >
| BOOST_ASIO_INITFN_RESULT_TYPE (BufferedHandshakeHandler, void(boost::system::error_code, std::size_t)) async_handshake(Connection_Side side
| BOOST_ASIO_HANDSHAKE_HANDLER_CHECK (BufferedHandshakeHandler, handler) type_check
throw | Not_Implemented ("buffered async handshake is not implemented")

## Detailed Description

template<class StreamLayer, class ChannelT = Channel>
class Botan::TLS::Stream< StreamLayer, ChannelT >

boost::asio compatible SSL/TLS stream

Template Parameters

  StreamLayer | type of the next layer, usually a network socket
  ChannelT | type of the native_handle, defaults to Botan::TLS::Channel, only needed for testing purposes

Definition at line 48 of file asio_stream.h.

## Member Typedef Documentation

## ◆ executor_type

template<class StreamLayer , class ChannelT = Channel>

using Botan::TLS::Stream< StreamLayer, ChannelT >::executor_type = typename next_layer_type::executor_type

Definition at line 126 of file asio_stream.h.

## ◆ lowest_layer_type

template<class StreamLayer , class ChannelT = Channel>

using Botan::TLS::Stream< StreamLayer, ChannelT >::lowest_layer_type = typename next_layer_type::lowest_layer_type

Definition at line 120 of file asio_stream.h.

## ◆ native_handle_type

template<class StreamLayer , class ChannelT = Channel>

using Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle_type = typename std::add_pointer<ChannelT>::type

Definition at line 129 of file asio_stream.h.

## ◆ next_layer_type

template<class StreamLayer , class ChannelT = Channel>

using Botan::TLS::Stream< StreamLayer, ChannelT >::next_layer_type = typename std::remove_reference<StreamLayer>::type

Definition at line 104 of file asio_stream.h.

## Constructor & Destructor Documentation

## ◆ Stream() [1/4]

template<class StreamLayer , class ChannelT = Channel>
template<typename... Args>

Botan::TLS::Stream< StreamLayer, ChannelT >::Stream | ( | Context & | context,
|  | Args &&... | args
| ) |  |
| inline explicit

Construct a new Stream.

Parameters

  context | The context parameter is used to set up the underlying native handle. Using code is responsible for lifetime management of the context and must ensure that it is available for the lifetime of the stream.
  args | Arguments to be forwarded to the construction of the next layer.

Definition at line 63 of file asio_stream.h.

64 : m_context(context)
65 , m_nextLayer(std::forward<Args>(args)...)
66 , m_core(*this)
67 , m_shutdown_received(false)
68 , m_input_buffer_space(MAX_CIPHERTEXT_SIZE, '\0')
69 , m_input_buffer(m_input_buffer_space.data(), m_input_buffer_space.size())
70 {}
Botan::TLS::Stream::m_input_buffer
const boost::asio::mutable_buffer m_input_buffer
Definition: asio_stream.h:828
Botan::TLS::Stream::m_shutdown_received
bool m_shutdown_received
Definition: asio_stream.h:824
Botan::TLS::Stream::m_input_buffer_space
std::vector< uint8_t > m_input_buffer_space
Definition: asio_stream.h:827
Botan::TLS::Stream::m_nextLayer
StreamLayer m_nextLayer
Definition: asio_stream.h:816
Botan::TLS::Stream::m_context
Context & m_context
Definition: asio_stream.h:815
Botan::TLS::Stream::m_core
StreamCore m_core
Definition: asio_stream.h:821
Botan::TLS::MAX_CIPHERTEXT_SIZE
@ MAX_CIPHERTEXT_SIZE
Definition: tls_magic.h:28

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_read_some().

## ◆ Stream() [2/4]

template<class StreamLayer , class ChannelT = Channel>
template<typename Arg >

Botan::TLS::Stream< StreamLayer, ChannelT >::Stream | ( | Arg && | arg,
|  | Context & | context
| ) |  |
| inline explicit

Construct a new Stream.

Convenience overload for boost::asio::ssl::stream compatibility.

Parameters

  arg | This argument is forwarded to the construction of the next layer.
  context | The context parameter is used to set up the underlying native handle. Using code is responsible for lifetime management of the context and must ensure that is available for the lifetime of the stream.

Definition at line 83 of file asio_stream.h.

84 : m_context(context)
85 , m_nextLayer(std::forward<Arg>(arg))
86 , m_core(*this)
87 , m_shutdown_received(false)
88 , m_input_buffer_space(MAX_CIPHERTEXT_SIZE, '\0')
89 , m_input_buffer(m_input_buffer_space.data(), m_input_buffer_space.size())
90 {}

## ◆ ~Stream()

template<class StreamLayer , class ChannelT = Channel>

virtual Botan::TLS::Stream< StreamLayer, ChannelT >::~Stream | ( |  | ) |
| inline virtual

Definition at line 92 of file asio_stream.h.

92{}

## ◆ Stream() [3/4]

template<class StreamLayer , class ChannelT = Channel>

Botan::TLS::Stream< StreamLayer, ChannelT >::Stream | ( | Stream< StreamLayer, ChannelT > && | other | ) |
| default

## ◆ Stream() [4/4]

template<class StreamLayer , class ChannelT = Channel>

Botan::TLS::Stream< StreamLayer, ChannelT >::Stream | ( | const Stream< StreamLayer, ChannelT > & | other | ) |
| delete

## Member Function Documentation

## ◆ async_handshake()

template<class StreamLayer , class ChannelT = Channel>
template<typename HandshakeHandler >

auto Botan::TLS::Stream< StreamLayer, ChannelT >::async_handshake | ( | Connection_Side | side,
|  | HandshakeHandler && | handler
| ) |  | ->
| inline

Starts an asynchronous SSL handshake.

This function call always returns immediately.

Parameters

  side | The type of handshaking to be performed, i.e. as a client or as a server.
  handler | The handler to be called when the handshake operation completes. The equivalent function signature of the handler must be: void(boost::system::error_code)

Definition at line 264 of file asio_stream.h.

266 {
267 BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(HandshakeHandler, handler) type_check;
268
269 boost::system::error_code ec;
270 setup_native_handle(side, ec);
271 // If ec is set by setup_native_handle, the AsyncHandshakeOperation created below will do nothing but call the
272 // handler with the error_code set appropriately - no need to early return here.
273
274 boost::asio::async_completion<HandshakeHandler, void(boost::system::error_code)> init(handler);
275
276 detail::AsyncHandshakeOperation<typename std::decay<HandshakeHandler>::type, Stream>
277 op{std::move(init.completion_handler), *this, ec};
278
279 return init.result.get();
280 }
Botan::TLS::Stream::setup_native_handle
std::enable_if<!std::is_same< Channel, T >::value >::type setup_native_handle(Connection_Side, boost::system::error_code &)
Definition: asio_stream.h:683
Botan::TLS::Stream::Stream
Stream(Context &context, Args &&... args)
Construct a new Stream.
Definition: asio_stream.h:63
Botan::TLS::Stream::handler
const ConstBufferSequence BufferedHandshakeHandler && handler
Definition: asio_stream.h:288
Botan::TLS::Stream::BOOST_ASIO_HANDSHAKE_HANDLER_CHECK
BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(BufferedHandshakeHandler, handler) type_check
init
int(* init)(CTX *)
Definition: commoncrypto_hash.cpp:27
type
MechanismType type
Definition: p11_mechanism.cpp:44

References Botan::TLS::Stream< StreamLayer, ChannelT >::BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(), Botan::TLS::Stream< StreamLayer, ChannelT >::handler, init, and Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle().

## ◆ async_read_some()

template<class StreamLayer , class ChannelT = Channel>
template<typename MutableBufferSequence , typename ReadHandler >

auto Botan::TLS::Stream< StreamLayer, ChannelT >::async_read_some | ( | const MutableBufferSequence & | buffers,
|  | ReadHandler && | handler
| ) |  | -> BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void(boost::system::error_code, std::size_t))
| inline

Start an asynchronous read. The function call always returns immediately.

Parameters

  buffers | The buffers into which the data will be read. Although the buffers object may be copied as necessary, ownership of the underlying buffers is retained by the caller, which must guarantee that they remain valid until the handler is called.
  handler | The handler to be called when the read operation completes. The equivalent function signature of the handler must be: void(boost::system::error_code, std::size_t)

Definition at line 553 of file asio_stream.h.

556 {
557 BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
558
559 boost::asio::async_completion<ReadHandler, void(boost::system::error_code, std::size_t)> init(handler);
560
561 detail::AsyncReadOperation<typename std::decay<ReadHandler>::type, Stream, MutableBufferSequence>
562 op{std::move(init.completion_handler), *this, buffers};
563 return init.result.get();
564 }
Botan::TLS::Stream::buffers
const ConstBufferSequence & buffers
Definition: asio_stream.h:286

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, Botan::TLS::Stream< StreamLayer, ChannelT >::handler, init, and Botan::TLS::Stream< StreamLayer, ChannelT >::Stream().

## ◆ async_shutdown()

template<class StreamLayer , class ChannelT = Channel>
template<typename ShutdownHandler >

void Botan::TLS::Stream< StreamLayer, ChannelT >::async_shutdown | ( | ShutdownHandler && | handler | ) |
| inline

Asynchronously shut down SSL on the stream.

This function call always returns immediately.

Note that this can be used in reaction of a received shutdown alert from the peer.

Parameters

  handler | The handler to be called when the shutdown operation completes. The equivalent function signature of the handler must be: void(boost::system::error_code)

Definition at line 381 of file asio_stream.h.

382 {
383 boost::system::error_code ec;
384 try_with_error_code([&]
385 {
386 native_handle()->close();
387 }, ec);
388 // If ec is set by native_handle->close(), the AsyncWriteOperation created below will do nothing but call the
389 // handler with the error_code set appropriately - no need to early return here.
390
391 using ShutdownHandlerWrapper = Wrapper<ShutdownHandler, typename Stream::executor_type>;
392
393 ShutdownHandlerWrapper w{std::forward<ShutdownHandler>(handler), get_executor()};
394 BOOST_ASIO_SHUTDOWN_HANDLER_CHECK(ShutdownHandler, w) type_check;
395
396 boost::asio::async_completion<ShutdownHandlerWrapper, void(boost::system::error_code, std::size_t)>
397 init(w);
398
399 detail::AsyncWriteOperation<typename std::decay<ShutdownHandlerWrapper>::type, Stream>
400 op{std::move(init.completion_handler), *this, boost::asio::buffer_size(send_buffer())};
401
402 return init.result.get();
403 }
Botan::TLS::Stream::native_handle
native_handle_type native_handle()
Definition: asio_stream.h:130
Botan::TLS::Stream::try_with_error_code
void try_with_error_code(Fun f, boost::system::error_code &ec)
Catch exceptions and set an error_code.
Definition: asio_stream.h:790
Botan::TLS::Stream::send_buffer
boost::asio::const_buffer send_buffer() const
Definition: asio_stream.h:653
Botan::TLS::Stream::get_executor
executor_type get_executor() noexcept
Definition: asio_stream.h:127

References Botan::TLS::Stream< StreamLayer, ChannelT >::get_executor(), Botan::TLS::Stream< StreamLayer, ChannelT >::handler, init, Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), Botan::TLS::Stream< StreamLayer, ChannelT >::send_buffer(), and Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code().

## ◆ async_write_some()

template<class StreamLayer , class ChannelT = Channel>
template<typename ConstBufferSequence , typename WriteHandler >

auto Botan::TLS::Stream< StreamLayer, ChannelT >::async_write_some | ( | const ConstBufferSequence & | buffers,
|  | WriteHandler && | handler
| ) |  | -> BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void(boost::system::error_code, std::size_t))
| inline

Start an asynchronous write. The function call always returns immediately.

Parameters

  buffers | The data to be written.
  handler | The handler to be called when the write operation completes. Copies will be made of the handler as required. The equivalent function signature of the handler must be: void(boost::system::error_code, std::size_t)

Definition at line 516 of file asio_stream.h.

519 {
520 BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
521
522 boost::asio::async_completion<WriteHandler, void(boost::system::error_code, std::size_t)> init(handler);
523
524 boost::system::error_code ec;
525 tls_encrypt(buffers, ec);
526 if(ec)
527 {
528 // we cannot be sure how many bytes were committed here so clear the send_buffer and let the
529 // AsyncWriteOperation call the handler with the error_code set
530 consume_send_buffer(m_send_buffer.size());
531 detail::AsyncWriteOperation<typename std::decay<WriteHandler>::type, Stream>
532 op{std::move(init.completion_handler), *this, std::size_t(0), ec};
533 return init.result.get();
534 }
535
536 detail::AsyncWriteOperation<typename std::decay<WriteHandler>::type, Stream>
537 op{std::move(init.completion_handler), *this, boost::asio::buffer_size(buffers)};
538
539 return init.result.get();
540 }
Botan::TLS::Stream::consume_send_buffer
void consume_send_buffer(std::size_t bytesConsumed)
Mark bytes in the send buffer as consumed, removing them from the buffer.
Definition: asio_stream.h:675
Botan::TLS::Stream::tls_encrypt
void tls_encrypt(const ConstBufferSequence &buffers, boost::system::error_code &ec)
Pass plaintext data to the native handle for processing.
Definition: asio_stream.h:755
Botan::TLS::Stream::m_send_buffer
boost::beast::flat_buffer m_send_buffer
Definition: asio_stream.h:819

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, Botan::TLS::Stream< StreamLayer, ChannelT >::consume_send_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::handler, init, Botan::TLS::Stream< StreamLayer, ChannelT >::m_send_buffer, and Botan::TLS::Stream< StreamLayer, ChannelT >::tls_encrypt().

## ◆ BOOST_ASIO_HANDSHAKE_HANDLER_CHECK()

template<class StreamLayer , class ChannelT = Channel>

Botan::TLS::Stream< StreamLayer, ChannelT >::BOOST_ASIO_HANDSHAKE_HANDLER_CHECK | ( | BufferedHandshakeHandler | ,
|  | handler |
| ) |  |

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_handshake().

## ◆ BOOST_ASIO_INITFN_RESULT_TYPE()

template<class StreamLayer , class ChannelT = Channel>
template<typename ConstBufferSequence , typename BufferedHandshakeHandler >

Botan::TLS::Stream< StreamLayer, ChannelT >::BOOST_ASIO_INITFN_RESULT_TYPE | ( | BufferedHandshakeHandler | ,
|  | void(boost::system::error_code, std::size_t) |
| ) |  |

Exceptions

  Not_Implemented |

## ◆ consume_send_buffer()

template<class StreamLayer , class ChannelT = Channel>

void Botan::TLS::Stream< StreamLayer, ChannelT >::consume_send_buffer | ( | std::size_t | bytesConsumed | ) |
| inline protected

Mark bytes in the send buffer as consumed, removing them from the buffer.

Definition at line 675 of file asio_stream.h.

675{ m_send_buffer.consume(bytesConsumed); }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_send_buffer.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_write_some(), Botan::TLS::detail::AsyncWriteOperation< Handler, Stream, Allocator >::operator()(), and Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data().

## ◆ copy_received_data()

template<class StreamLayer , class ChannelT = Channel>
template<typename MutableBufferSequence >

std::size_t Botan::TLS::Stream< StreamLayer, ChannelT >::copy_received_data | ( | MutableBufferSequence | buffers | ) |
| inline protected

Copy decrypted data into the user-provided buffer.

Definition at line 660 of file asio_stream.h.

661 {
662 // Note: It would be nice to avoid this buffer copy. This could be achieved by equipping the StreamCore with
663 // the user's desired target buffer once a read is started, and reading directly into that buffer in tls_record
664 // received. However, we need to deal with the case that the receive buffer provided by the caller is smaller
665 // than the decrypted record, so this optimization might not be worth the additional complexity.
666 const auto copiedBytes = boost::asio::buffer_copy(buffers, m_receive_buffer.data());
667 m_receive_buffer.consume(copiedBytes);
668 return copiedBytes;
669 }
Botan::TLS::Stream::m_receive_buffer
boost::beast::flat_buffer m_receive_buffer
Definition: asio_stream.h:818

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, and Botan::TLS::Stream< StreamLayer, ChannelT >::m_receive_buffer.

Referenced by Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::operator()(), and Botan::TLS::Stream< StreamLayer, ChannelT >::read_some().

## ◆ get_executor()

template<class StreamLayer , class ChannelT = Channel>

executor_type Botan::TLS::Stream< StreamLayer, ChannelT >::get_executor | ( |  | ) |
| inline noexcept

Definition at line 127 of file asio_stream.h.

127{ return m_nextLayer.get_executor(); }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_shutdown().

## ◆ handshake() [1/2]

template<class StreamLayer , class ChannelT = Channel>

void Botan::TLS::Stream< StreamLayer, ChannelT >::handshake | ( | Connection_Side | side | ) |
| inline

Performs SSL handshaking.

The function call will block until handshaking is complete or an error occurs.

Parameters

  side | The type of handshaking to be performed, i.e. as a client or as a server.

Exceptions

  boost::system::system_error | if error occured

Definition at line 217 of file asio_stream.h.

218 {
219 boost::system::error_code ec;
220 handshake(side, ec);
221 boost::asio::detail::throw_error(ec, "handshake");
222 }
Botan::TLS::Stream::handshake
void handshake(Connection_Side side)
Performs SSL handshaking.
Definition: asio_stream.h:217

References Botan::TLS::Stream< StreamLayer, ChannelT >::handshake().

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::handshake().

## ◆ handshake() [2/2]

template<class StreamLayer , class ChannelT = Channel>

void Botan::TLS::Stream< StreamLayer, ChannelT >::handshake | ( | Connection_Side | side,
|  | boost::system::error_code & | ec
| ) |  |
| inline

Performs SSL handshaking.

The function call will block until handshaking is complete or an error occurs.

Parameters

  side | The type of handshaking to be performed, i.e. as a client or as a server.
  ec | Set to indicate what error occurred, if any.

Definition at line 232 of file asio_stream.h.

233 {
234 setup_native_handle(side, ec);
235
236 if(side == CLIENT)
237 {
238 // send client hello, which was written to the send buffer on client instantiation
239 send_pending_encrypted_data(ec);
240 }
241
242 while(!native_handle()->is_active() && !ec)
243 {
244 boost::asio::const_buffer read_buffer{input_buffer().data(), m_nextLayer.read_some(input_buffer(), ec)};
245 if(ec)
246 { return; }
247
248 process_encrypted_data(read_buffer, ec);
249
250 send_pending_encrypted_data(ec);
251 }
252 }
Botan::TLS::Stream::input_buffer
const boost::asio::mutable_buffer & input_buffer()
Definition: asio_stream.h:652
Botan::TLS::Stream::process_encrypted_data
void process_encrypted_data(const boost::asio::const_buffer &read_buffer, boost::system::error_code &ec)
Pass encrypted data to the native handle for processing.
Definition: asio_stream.h:780
Botan::TLS::Stream::send_pending_encrypted_data
size_t send_pending_encrypted_data(boost::system::error_code &ec)
Synchronously write encrypted data from the send buffer to the next layer.
Definition: asio_stream.h:732
Botan::TLS::CLIENT
@ CLIENT
Definition: tls_magic.h:32

References Botan::TLS::CLIENT, Botan::TLS::Stream< StreamLayer, ChannelT >::input_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer, Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), Botan::TLS::Stream< StreamLayer, ChannelT >::process_encrypted_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data(), and Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle().

## ◆ has_data_to_send()

template<class StreamLayer , class ChannelT = Channel>

bool Botan::TLS::Stream< StreamLayer, ChannelT >::has_data_to_send | ( |  | ) | const
| inline protected

Check if encrypted data is available in the send buffer.

Definition at line 672 of file asio_stream.h.

672{ return m_send_buffer.size() > 0; }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_send_buffer.

Referenced by Botan::TLS::detail::AsyncWriteOperation< Handler, Stream, Allocator >::operator()(), and Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::operator()().

## ◆ has_received_data()

template<class StreamLayer , class ChannelT = Channel>

bool Botan::TLS::Stream< StreamLayer, ChannelT >::has_received_data | ( |  | ) | const
| inline protected

Check if decrypted data is available in the receive buffer.

Definition at line 656 of file asio_stream.h.

656{ return m_receive_buffer.size() > 0; }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_receive_buffer.

Referenced by Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::operator()(), and Botan::TLS::Stream< StreamLayer, ChannelT >::read_some().

## ◆ input_buffer()

template<class StreamLayer , class ChannelT = Channel>

const boost::asio::mutable_buffer & Botan::TLS::Stream< StreamLayer, ChannelT >::input_buffer | ( |  | ) |
| inline protected

Definition at line 652 of file asio_stream.h.

652{ return m_input_buffer; }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_input_buffer.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::handshake(), Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::operator()(), Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::operator()(), and Botan::TLS::Stream< StreamLayer, ChannelT >::read_some().

## ◆ lowest_layer() [1/2]

template<class StreamLayer , class ChannelT = Channel>

lowest_layer_type & Botan::TLS::Stream< StreamLayer, ChannelT >::lowest_layer | ( |  | ) |
| inline

Definition at line 122 of file asio_stream.h.

122{ return m_nextLayer.lowest_layer(); }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer.

## ◆ lowest_layer() [2/2]

template<class StreamLayer , class ChannelT = Channel>

const lowest_layer_type & Botan::TLS::Stream< StreamLayer, ChannelT >::lowest_layer | ( |  | ) | const
| inline

Definition at line 123 of file asio_stream.h.

123{ return m_nextLayer.lowest_layer(); }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer.

## ◆ native_handle()

template<class StreamLayer , class ChannelT = Channel>

native_handle_type Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle | ( |  | ) |
| inline

Definition at line 130 of file asio_stream.h.

131 {
132 if(m_native_handle == nullptr)
133 { throw Invalid_State("Invalid handshake state"); }
134 return m_native_handle.get();
135 }
Botan::TLS::Stream::m_native_handle
std::unique_ptr< ChannelT > m_native_handle
Definition: asio_stream.h:822

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_native_handle.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_shutdown(), Botan::TLS::Stream< StreamLayer, ChannelT >::handshake(), Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::operator()(), Botan::TLS::Stream< StreamLayer, ChannelT >::process_encrypted_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown(), and Botan::TLS::Stream< StreamLayer, ChannelT >::tls_encrypt().

## ◆ next_layer() [1/2]

template<class StreamLayer , class ChannelT = Channel>

next_layer_type & Botan::TLS::Stream< StreamLayer, ChannelT >::next_layer | ( |  | ) |
| inline

Definition at line 107 of file asio_stream.h.

107{ return m_nextLayer; }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer.

## ◆ next_layer() [2/2]

template<class StreamLayer , class ChannelT = Channel>

const next_layer_type & Botan::TLS::Stream< StreamLayer, ChannelT >::next_layer | ( |  | ) | const
| inline

Definition at line 106 of file asio_stream.h.

106{ return m_nextLayer; }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer.

Referenced by Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::operator()(), Botan::TLS::detail::AsyncWriteOperation< Handler, Stream, Allocator >::operator()(), and Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::operator()().

## ◆ Not_Implemented()

template<class StreamLayer , class ChannelT = Channel>

throw Botan::TLS::Stream< StreamLayer, ChannelT >::Not_Implemented | ( | "buffered async handshake is not implemented" |  | ) |

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_depth(), and Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_mode().

## ◆ operator=() [1/2]

template<class StreamLayer , class ChannelT = Channel>

Stream & Botan::TLS::Stream< StreamLayer, ChannelT >::operator= | ( | const Stream< StreamLayer, ChannelT > & | other | ) |
| delete

## ◆ operator=() [2/2]

template<class StreamLayer , class ChannelT = Channel>

Stream & Botan::TLS::Stream< StreamLayer, ChannelT >::operator= | ( | Stream< StreamLayer, ChannelT > && | other | ) |
| default

## ◆ process_encrypted_data()

template<class StreamLayer , class ChannelT = Channel>

void Botan::TLS::Stream< StreamLayer, ChannelT >::process_encrypted_data | ( | const boost::asio::const_buffer & | read_buffer,
|  | boost::system::error_code & | ec
| ) |  |
| inline protected

Pass encrypted data to the native handle for processing.

If an exception occurs while processing the data, an error code will be set.

Parameters

  read_buffer | Input buffer containing the encrypted data.
  ec | Set to indicate what error occurred, if any.

Definition at line 780 of file asio_stream.h.

781 {
782 try_with_error_code([&]
783 {
784 native_handle()->received_data(static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size());
785 }, ec);
786 }

References Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), and Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code().

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::handshake(), Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::operator()(), Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::operator()(), and Botan::TLS::Stream< StreamLayer, ChannelT >::read_some().

## ◆ read_some() [1/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename MutableBufferSequence >

std::size_t Botan::TLS::Stream< StreamLayer, ChannelT >::read_some | ( | const MutableBufferSequence & | buffers | ) |
| inline

Read some data from the stream.

The function call will block until one or more bytes of data has been read successfully, or until an error occurs.

Parameters

  buffers | The buffers into which the data will be read.

Returns
  The number of bytes read. Returns 0 if an error occurred.

Exceptions

  boost::system::system_error | if error occured

Definition at line 461 of file asio_stream.h.

462 {
463 boost::system::error_code ec;
464 auto const n = read_some(buffers, ec);
465 boost::asio::detail::throw_error(ec, "read_some");
466 return n;
467 }
Botan::TLS::Stream::read_some
std::size_t read_some(const MutableBufferSequence &buffers, boost::system::error_code &ec)
Read some data from the stream.
Definition: asio_stream.h:421

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, and Botan::TLS::Stream< StreamLayer, ChannelT >::read_some().

## ◆ read_some() [2/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename MutableBufferSequence >

std::size_t Botan::TLS::Stream< StreamLayer, ChannelT >::read_some | ( | const MutableBufferSequence & | buffers,
|  | boost::system::error_code & | ec
| ) |  |
| inline

Read some data from the stream.

The function call will block until one or more bytes of data has been read successfully, or until an error occurs.

Parameters

  buffers | The buffers into which the data will be read.
  ec | Set to indicate what error occurred, if any. Specifically, StreamTruncated will be set if the peer has closed the connection but did not properly shut down the SSL connection.

Returns
  The number of bytes read. Returns 0 if an error occurred.

Definition at line 421 of file asio_stream.h.

423 {
424 if(has_received_data())
425 { return copy_received_data(buffers); }
426
427 boost::asio::const_buffer read_buffer{input_buffer().data(), m_nextLayer.read_some(input_buffer(), ec)};
428 if(ec)
429 { return 0; }
430
431 process_encrypted_data(read_buffer, ec);
432
433 if(ec) // something went wrong in process_encrypted_data()
434 { return 0; }
435
436 if(shutdown_received())
437 {
438 // we just received a 'close_notify' from the peer and don't expect any more data
439 ec = boost::asio::error::eof;
440 }
441 else if(ec == boost::asio::error::eof)
442 {
443 // we did not expect this disconnection from the peer
444 ec = StreamError::StreamTruncated;
445 }
446
447 return !ec ? copy_received_data(buffers) : 0;
448 }
Botan::TLS::Stream::copy_received_data
std::size_t copy_received_data(MutableBufferSequence buffers)
Copy decrypted data into the user-provided buffer.
Definition: asio_stream.h:660
Botan::TLS::Stream::has_received_data
bool has_received_data() const
Check if decrypted data is available in the receive buffer.
Definition: asio_stream.h:656
Botan::TLS::Stream::shutdown_received
bool shutdown_received() const
Indicates whether a close_notify alert has been received from the peer.
Definition: asio_stream.h:569
Botan::TLS::StreamTruncated
@ StreamTruncated
Definition: asio_error.h:35

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, Botan::TLS::Stream< StreamLayer, ChannelT >::copy_received_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::has_received_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::input_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer, Botan::TLS::Stream< StreamLayer, ChannelT >::process_encrypted_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown_received(), and Botan::TLS::StreamTruncated.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::read_some().

## ◆ send_buffer()

template<class StreamLayer , class ChannelT = Channel>

boost::asio::const_buffer Botan::TLS::Stream< StreamLayer, ChannelT >::send_buffer | ( |  | ) | const
| inline protected

Definition at line 653 of file asio_stream.h.

653{ return m_send_buffer.data(); }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_send_buffer.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_shutdown(), Botan::TLS::detail::AsyncWriteOperation< Handler, Stream, Allocator >::operator()(), and Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data().

## ◆ send_pending_encrypted_data()

template<class StreamLayer , class ChannelT = Channel>

size_t Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data | ( | boost::system::error_code & | ec | ) |
| inline protected

Synchronously write encrypted data from the send buffer to the next layer.

If this function is called with an error code other than 'Success', it will do nothing and return 0.

Parameters

  ec | Set to indicate what error occurred, if any. Specifically, StreamTruncated will be set if the peer has closed the connection but did not properly shut down the SSL connection.

Returns
  The number of bytes written.

Definition at line 732 of file asio_stream.h.

733 {
734 if(ec)
735 { return 0; }
736
737 auto writtenBytes = boost::asio::write(m_nextLayer, send_buffer(), ec);
738 consume_send_buffer(writtenBytes);
739
740 if(ec == boost::asio::error::eof && !shutdown_received())
741 {
742 // transport layer was closed by peer without receiving 'close_notify'
743 ec = StreamError::StreamTruncated;
744 }
745
746 return writtenBytes;
747 }

References Botan::TLS::Stream< StreamLayer, ChannelT >::consume_send_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer, Botan::TLS::Stream< StreamLayer, ChannelT >::send_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown_received(), and Botan::TLS::StreamTruncated.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::handshake(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown(), and Botan::TLS::Stream< StreamLayer, ChannelT >::write_some().

## ◆ set_shutdown_received()

template<class StreamLayer , class ChannelT = Channel>

void Botan::TLS::Stream< StreamLayer, ChannelT >::set_shutdown_received | ( |  | ) |
| inline protected

Definition at line 810 of file asio_stream.h.

811 {
812 m_shutdown_received = true;
813 }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_shutdown_received.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::StreamCore::tls_alert().

## ◆ set_verify_callback() [1/2]

template<class StreamLayer , class ChannelT = Channel>

void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_callback | ( | Context::Verify_Callback | callback | ) |
| inline

Override the tls_verify_cert_chain callback.

This changes the verify_callback in the stream's TLS::Context, and hence the tls_verify_cert_chain callback used in the handshake. Using this function is equivalent to setting the callback via

See also
  Botan::TLS::Context::set_verify_callback

Note
  This function should only be called before initiating the TLS handshake

Definition at line 150 of file asio_stream.h.

151 {
152 m_context.set_verify_callback(std::move(callback));
153 }
Botan::TLS::Context::set_verify_callback
void set_verify_callback(Verify_Callback callback)
Override the tls_verify_cert_chain callback.
Definition: asio_context.h:84

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_context, and Botan::TLS::Context::set_verify_callback().

## ◆ set_verify_callback() [2/2]

template<class StreamLayer , class ChannelT = Channel>

void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_callback | ( | Context::Verify_Callback | callback,
|  | boost::system::error_code & | ec
| ) |  |
| inline

Compatibility overload of set_verify_callback.

Parameters

  callback | the callback implementation
  ec | This parameter is unused.

Definition at line 161 of file asio_stream.h.

162 {
163 BOTAN_UNUSED(ec);
164 m_context.set_verify_callback(std::move(callback));
165 }
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142

References BOTAN_UNUSED, Botan::TLS::Stream< StreamLayer, ChannelT >::m_context, and Botan::TLS::Context::set_verify_callback().

## ◆ set_verify_depth() [1/2]

template<class StreamLayer , class ChannelT = Channel>

void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_depth | ( | int | depth | ) |
| inline

Exceptions

  Not_Implemented |

Definition at line 168 of file asio_stream.h.

169 {
170 BOTAN_UNUSED(depth);
171 throw Not_Implemented("set_verify_depth is not implemented");
172 }
Botan::TLS::Stream::Not_Implemented
throw Not_Implemented("buffered async handshake is not implemented")

References BOTAN_UNUSED, and Botan::TLS::Stream< StreamLayer, ChannelT >::Not_Implemented().

## ◆ set_verify_depth() [2/2]

template<class StreamLayer , class ChannelT = Channel>

void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_depth | ( | int | depth,
|  | boost::system::error_code & | ec
| ) |  |
| inline

Not Implemented.

Parameters

  depth | the desired verification depth
  ec | Will be set to `Botan::ErrorType::NotImplemented`

Definition at line 179 of file asio_stream.h.

180 {
181 BOTAN_UNUSED(depth);
182 ec = Botan::ErrorType::NotImplemented;
183 }
Botan::ErrorType::NotImplemented
@ NotImplemented

References BOTAN_UNUSED, and Botan::NotImplemented.

## ◆ set_verify_mode() [1/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename verify_mode >

void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_mode | ( | verify_mode | v | ) |
| inline

Exceptions

  Not_Implemented |

Definition at line 187 of file asio_stream.h.

188 {
189 BOTAN_UNUSED(v);
190 throw Not_Implemented("set_verify_mode is not implemented");
191 }

References BOTAN_UNUSED, and Botan::TLS::Stream< StreamLayer, ChannelT >::Not_Implemented().

## ◆ set_verify_mode() [2/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename verify_mode >

void Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_mode | ( | verify_mode | v,
|  | boost::system::error_code & | ec
| ) |  |
| inline

Not Implemented.

Parameters

  v | the desired verify mode
  ec | Will be set to `Botan::ErrorType::NotImplemented`

Definition at line 199 of file asio_stream.h.

200 {
201 BOTAN_UNUSED(v);
202 ec = Botan::ErrorType::NotImplemented;
203 }

References BOTAN_UNUSED, and Botan::NotImplemented.

## ◆ setup_native_handle() [1/2]

template<class StreamLayer , class ChannelT = Channel>
template<class T = ChannelT>

std::enable_if< std::is_same< Channel, T >::value >::type Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle | ( | Connection_Side | side,
|  | boost::system::error_code & | ec
| ) |  |
| inline protected

Create the native handle.

Depending on the desired connection side, this function will create a Botan::TLS::Client or a Botan::TLS::Server.

Parameters

  side | The desired connection side (client or server)
  ec | Set to indicate what error occurred, if any.

Definition at line 696 of file asio_stream.h.

697 {
698 try_with_error_code([&]
699 {
700 if(side == CLIENT)
701 {
702 m_native_handle = std::unique_ptr<Client>(
703 new Client(m_core,
704 m_context.m_session_manager,
705 m_context.m_credentials_manager,
706 m_context.m_policy,
707 m_context.m_rng,
708 m_context.m_server_info,
709 Protocol_Version::latest_tls_version()));
710 }
711 else
712 {
713 m_native_handle = std::unique_ptr<Server>(
714 new Server(m_core,
715 m_context.m_session_manager,
716 m_context.m_credentials_manager,
717 m_context.m_policy,
718 m_context.m_rng,
719 false /* no DTLS */));
720 }
721 }, ec);
722 }
Botan::TLS::Context::m_credentials_manager
Credentials_Manager & m_credentials_manager
Definition: asio_context.h:107
Botan::TLS::Context::m_server_info
Server_Information m_server_info
Definition: asio_context.h:112
Botan::TLS::Context::m_rng
RandomNumberGenerator & m_rng
Definition: asio_context.h:108
Botan::TLS::Context::m_policy
Policy & m_policy
Definition: asio_context.h:110
Botan::TLS::Context::m_session_manager
Session_Manager & m_session_manager
Definition: asio_context.h:109
Botan::TLS::Protocol_Version::latest_tls_version
static Protocol_Version latest_tls_version()
Definition: tls_version.h:36

References Botan::TLS::CLIENT, Botan::TLS::Protocol_Version::latest_tls_version(), Botan::TLS::Stream< StreamLayer, ChannelT >::m_context, Botan::TLS::Stream< StreamLayer, ChannelT >::m_core, Botan::TLS::Context::m_credentials_manager, Botan::TLS::Stream< StreamLayer, ChannelT >::m_native_handle, Botan::TLS::Context::m_policy, Botan::TLS::Context::m_rng, Botan::TLS::Context::m_server_info, Botan::TLS::Context::m_session_manager, and Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code().

## ◆ setup_native_handle() [2/2]

template<class StreamLayer , class ChannelT = Channel>
template<class T = ChannelT>

std::enable_if<!std::is_same< Channel, T >::value >::type Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle | ( | Connection_Side | ,
|  | boost::system::error_code & |
| ) |  |
| inline protected

Definition at line 683 of file asio_stream.h.

683{}

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_handshake(), and Botan::TLS::Stream< StreamLayer, ChannelT >::handshake().

## ◆ shutdown() [1/2]

template<class StreamLayer , class ChannelT = Channel>

void Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown | ( |  | ) |
| inline

Shut down SSL on the stream.

This function is used to shut down SSL on the stream. The function call will block until SSL has been shut down or an error occurs. Note that this will not close the lowest layer.

Note that this can be used in reaction of a received shutdown alert from the peer.

Exceptions

  boost::system::system_error | if error occured

Definition at line 328 of file asio_stream.h.

329 {
330 boost::system::error_code ec;
331 shutdown(ec);
332 boost::asio::detail::throw_error(ec, "shutdown");
333 }
Botan::TLS::Stream::shutdown
void shutdown()
Shut down SSL on the stream.
Definition: asio_stream.h:328

References Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown().

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown().

## ◆ shutdown() [2/2]

template<class StreamLayer , class ChannelT = Channel>

void Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown | ( | boost::system::error_code & | ec | ) |
| inline

Shut down SSL on the stream.

This function is used to shut down SSL on the stream. The function call will block until SSL has been shut down or an error occurs. Note that this will not close the lowest layer.

Note that this can be used in reaction of a received shutdown alert from the peer.

Parameters

  ec | Set to indicate what error occured, if any.

Definition at line 308 of file asio_stream.h.

309 {
310 try_with_error_code([&]
311 {
312 native_handle()->close();
313 }, ec);
314
315 send_pending_encrypted_data(ec);
316 }

References Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data(), and Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code().

## ◆ shutdown_received()

template<class StreamLayer , class ChannelT = Channel>

bool Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown_received | ( |  | ) | const
| inline

Indicates whether a close_notify alert has been received from the peer.

Definition at line 569 of file asio_stream.h.

570 {
571 return m_shutdown_received;
572 }

References Botan::TLS::Stream< StreamLayer, ChannelT >::m_shutdown_received.

Referenced by Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::operator()(), Botan::TLS::detail::AsyncWriteOperation< Handler, Stream, Allocator >::operator()(), Botan::TLS::Stream< StreamLayer, ChannelT >::read_some(), and Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data().

## ◆ tls_encrypt()

template<class StreamLayer , class ChannelT = Channel>
template<typename ConstBufferSequence >

void Botan::TLS::Stream< StreamLayer, ChannelT >::tls_encrypt | ( | const ConstBufferSequence & | buffers,
|  | boost::system::error_code & | ec
| ) |  |
| inline protected

Pass plaintext data to the native handle for processing.

The native handle will then create TLS records and hand them back to the Stream via the tls_emit_data callback.

Definition at line 755 of file asio_stream.h.

756 {
757 // NOTE: This is not asynchronous: it encrypts the data synchronously.
758 // The data encrypted by native_handle()->send() is synchronously stored in the send_buffer of m_core,
759 // but is not actually written to the wire, yet.
760 for(auto it = boost::asio::buffer_sequence_begin(buffers);
761 !ec && it != boost::asio::buffer_sequence_end(buffers);
762 it++)
763 {
764 const boost::asio::const_buffer buffer = *it;
765 try_with_error_code([&]
766 {
767 native_handle()->send(static_cast<const uint8_t*>(buffer.data()), buffer.size());
768 }, ec);
769 }
770 }

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), and Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code().

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_write_some(), and Botan::TLS::Stream< StreamLayer, ChannelT >::write_some().

## ◆ try_with_error_code()

template<class StreamLayer , class ChannelT = Channel>
template<typename Fun >

void Botan::TLS::Stream< StreamLayer, ChannelT >::try_with_error_code | ( | Fun | f,
|  | boost::system::error_code & | ec
| ) |  |
| inline protected

Catch exceptions and set an error_code.

Definition at line 790 of file asio_stream.h.

791 {
792 try
793 {
794 f();
795 }
796 catch(const TLS_Exception& e)
797 {
798 ec = e.type();
799 }
800 catch(const Botan::Exception& e)
801 {
802 ec = e.error_type();
803 }
804 catch(const std::exception&)
805 {
806 ec = Botan::ErrorType::Unknown;
807 }
808 }
Botan::Exception
Definition: exceptn.h:86
Botan::Exception::error_type
virtual ErrorType error_type() const noexcept
Definition: exceptn.h:101
Botan::ErrorType::Unknown
@ Unknown

References Botan::TLS::TLS_Exception::error_type(), Botan::TLS::TLS_Exception::type(), and Botan::Unknown.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_shutdown(), Botan::TLS::Stream< StreamLayer, ChannelT >::process_encrypted_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown(), and Botan::TLS::Stream< StreamLayer, ChannelT >::tls_encrypt().

## ◆ write_some() [1/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename ConstBufferSequence >

std::size_t Botan::TLS::Stream< StreamLayer, ChannelT >::write_some | ( | const ConstBufferSequence & | buffers | ) |
| inline

Write some data to the stream.

The function call will block until one or more bytes of data has been written successfully, or until an error occurs.

Parameters

  buffers | The data to be written.

Returns
  The number of bytes written.

Exceptions

  boost::system::system_error | if error occured

Definition at line 499 of file asio_stream.h.

500 {
501 boost::system::error_code ec;
502 auto const n = write_some(buffers, ec);
503 boost::asio::detail::throw_error(ec, "write_some");
504 return n;
505 }
Botan::TLS::Stream::write_some
std::size_t write_some(const ConstBufferSequence &buffers, boost::system::error_code &ec)
Write some data to the stream.
Definition: asio_stream.h:480

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, and Botan::TLS::Stream< StreamLayer, ChannelT >::write_some().

## ◆ write_some() [2/2]

template<class StreamLayer , class ChannelT = Channel>
template<typename ConstBufferSequence >

std::size_t Botan::TLS::Stream< StreamLayer, ChannelT >::write_some | ( | const ConstBufferSequence & | buffers,
|  | boost::system::error_code & | ec
| ) |  |
| inline

Write some data to the stream.

The function call will block until one or more bytes of data has been written successfully, or until an error occurs.

Parameters

  buffers | The data to be written.
  ec | Set to indicate what error occurred, if any.

Returns
  The number of bytes processed from the input buffers.

Definition at line 480 of file asio_stream.h.

482 {
483 tls_encrypt(buffers, ec);
484 send_pending_encrypted_data(ec);
485 return !ec ? boost::asio::buffer_size(buffers) : 0;
486 }

References Botan::TLS::Stream< StreamLayer, ChannelT >::buffers, Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data(), and Botan::TLS::Stream< StreamLayer, ChannelT >::tls_encrypt().

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::write_some().

## Friends And Related Function Documentation

## ◆ detail::AsyncHandshakeOperation

template<class StreamLayer , class ChannelT = Channel>
template<class H , class S , class A >

friend class detail::AsyncHandshakeOperation
| friend

Definition at line 577 of file asio_stream.h.

## ◆ detail::AsyncReadOperation

template<class StreamLayer , class ChannelT = Channel>
template<class H , class S , class M , class A >

friend class detail::AsyncReadOperation
| friend

Definition at line 575 of file asio_stream.h.

## ◆ detail::AsyncWriteOperation

template<class StreamLayer , class ChannelT = Channel>
template<class H , class S , class A >

friend class detail::AsyncWriteOperation
| friend

Definition at line 576 of file asio_stream.h.

## Member Data Documentation

## ◆ buffers

template<class StreamLayer , class ChannelT = Channel>

const ConstBufferSequence& Botan::TLS::Stream< StreamLayer, ChannelT >::buffers

Definition at line 286 of file asio_stream.h.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_read_some(), Botan::TLS::Stream< StreamLayer, ChannelT >::async_write_some(), Botan::TLS::Stream< StreamLayer, ChannelT >::copy_received_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::read_some(), Botan::TLS::Stream< StreamLayer, ChannelT >::tls_encrypt(), and Botan::TLS::Stream< StreamLayer, ChannelT >::write_some().

## ◆ handler

template<class StreamLayer , class ChannelT = Channel>

const ConstBufferSequence BufferedHandshakeHandler&& Botan::TLS::Stream< StreamLayer, ChannelT >::handler

Initial value:
{
BOTAN_UNUSED(side, buffers, handler)

Definition at line 287 of file asio_stream.h.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_handshake(), Botan::TLS::Stream< StreamLayer, ChannelT >::async_read_some(), Botan::TLS::Stream< StreamLayer, ChannelT >::async_shutdown(), and Botan::TLS::Stream< StreamLayer, ChannelT >::async_write_some().

## ◆ m_context

template<class StreamLayer , class ChannelT = Channel>

Context& Botan::TLS::Stream< StreamLayer, ChannelT >::m_context
| protected

Definition at line 815 of file asio_stream.h.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_callback(), Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle(), and Botan::TLS::Stream< StreamLayer, ChannelT >::StreamCore::tls_verify_cert_chain().

## ◆ m_core

template<class StreamLayer , class ChannelT = Channel>

StreamCore Botan::TLS::Stream< StreamLayer, ChannelT >::m_core
| protected

Definition at line 821 of file asio_stream.h.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle().

## ◆ m_input_buffer

template<class StreamLayer , class ChannelT = Channel>

const boost::asio::mutable_buffer Botan::TLS::Stream< StreamLayer, ChannelT >::m_input_buffer
| protected

Definition at line 828 of file asio_stream.h.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::input_buffer().

## ◆ m_input_buffer_space

template<class StreamLayer , class ChannelT = Channel>

std::vector<uint8_t> Botan::TLS::Stream< StreamLayer, ChannelT >::m_input_buffer_space
| protected

Definition at line 827 of file asio_stream.h.

## ◆ m_native_handle

template<class StreamLayer , class ChannelT = Channel>

std::unique_ptr<ChannelT> Botan::TLS::Stream< StreamLayer, ChannelT >::m_native_handle
| protected

Definition at line 822 of file asio_stream.h.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), and Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle().

## ◆ m_nextLayer

template<class StreamLayer , class ChannelT = Channel>

StreamLayer Botan::TLS::Stream< StreamLayer, ChannelT >::m_nextLayer
| protected

Definition at line 816 of file asio_stream.h.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::get_executor(), Botan::TLS::Stream< StreamLayer, ChannelT >::handshake(), Botan::TLS::Stream< StreamLayer, ChannelT >::lowest_layer(), Botan::TLS::Stream< StreamLayer, ChannelT >::next_layer(), Botan::TLS::Stream< StreamLayer, ChannelT >::read_some(), and Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data().

## ◆ m_receive_buffer

template<class StreamLayer , class ChannelT = Channel>

boost::beast::flat_buffer Botan::TLS::Stream< StreamLayer, ChannelT >::m_receive_buffer
| protected

Definition at line 818 of file asio_stream.h.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::copy_received_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::has_received_data(), and Botan::TLS::Stream< StreamLayer, ChannelT >::StreamCore::tls_record_received().

## ◆ m_send_buffer

template<class StreamLayer , class ChannelT = Channel>

boost::beast::flat_buffer Botan::TLS::Stream< StreamLayer, ChannelT >::m_send_buffer
| protected

Definition at line 819 of file asio_stream.h.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::async_write_some(), Botan::TLS::Stream< StreamLayer, ChannelT >::consume_send_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::has_data_to_send(), Botan::TLS::Stream< StreamLayer, ChannelT >::send_buffer(), and Botan::TLS::Stream< StreamLayer, ChannelT >::StreamCore::tls_emit_data().

## ◆ m_shutdown_received

template<class StreamLayer , class ChannelT = Channel>

bool Botan::TLS::Stream< StreamLayer, ChannelT >::m_shutdown_received
| protected

Definition at line 824 of file asio_stream.h.

Referenced by Botan::TLS::Stream< StreamLayer, ChannelT >::set_shutdown_received(), and Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown_received().

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

- src/lib/tls/asio/asio_stream.h