Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | 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
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 ()=default
| 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 ()
boost::asio::const_buffer | send_buffer () const
size_t | send_pending_encrypted_data (boost::system::error_code &ec)
template<class T = ChannelT>
std::enable_if<!std::is_same< Channel, T >::value >::type | setup_native_handle (Connection_Side, boost::system::error_code &)
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<typename ConstBufferSequence >
void | tls_encrypt (const ConstBufferSequence &buffers, boost::system::error_code &ec)

## 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

## 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
executor_type | get_executor () noexcept
const next_layer_type & | next_layer () const
next_layer_type & | next_layer ()
lowest_layer_type & | lowest_layer ()
const lowest_layer_type & | lowest_layer () const
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

Currently only the TLS::Client specialization is implemented.

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 49 of file asio_stream.h.

## Member Typedef Documentation

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 105 of file asio_stream.h.

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 104 of file asio_stream.h.

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 106 of file asio_stream.h.

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 103 of file asio_stream.h.

## Constructor & Destructor Documentation

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 64 of file asio_stream.h.

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

65 : m_context(context)
66 , m_nextLayer(std::forward<Args>(args)...)
67 , m_core(m_receive_buffer, m_send_buffer, m_context)
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:709
Botan::TLS::Stream::m_nextLayer
StreamLayer m_nextLayer
Definition: asio_stream.h:699
Botan::TLS::Stream::m_core
StreamCore m_core
Definition: asio_stream.h:704
Botan::TLS::Stream::m_context
Context & m_context
Definition: asio_stream.h:698
Botan::TLS::MAX_CIPHERTEXT_SIZE
Definition: tls_magic.h:28
Botan::TLS::Stream::m_send_buffer
boost::beast::flat_buffer m_send_buffer
Definition: asio_stream.h:702
Botan::TLS::Stream::m_input_buffer_space
std::vector< uint8_t > m_input_buffer_space
Definition: asio_stream.h:708
Botan::TLS::Stream::m_receive_buffer
boost::beast::flat_buffer m_receive_buffer
Definition: asio_stream.h:701
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(m_receive_buffer, m_send_buffer, m_context)
87 , m_input_buffer_space(MAX_CIPHERTEXT_SIZE, '\0')
88 , m_input_buffer(m_input_buffer_space.data(), m_input_buffer_space.size())
89 {}
Botan::TLS::Stream::m_input_buffer
const boost::asio::mutable_buffer m_input_buffer
Definition: asio_stream.h:709
Botan::TLS::Stream::m_nextLayer
StreamLayer m_nextLayer
Definition: asio_stream.h:699
Botan::TLS::Stream::m_core
StreamCore m_core
Definition: asio_stream.h:704
Botan::TLS::Stream::m_context
Context & m_context
Definition: asio_stream.h:698
Botan::TLS::MAX_CIPHERTEXT_SIZE
Definition: tls_magic.h:28
Botan::TLS::Stream::m_send_buffer
boost::beast::flat_buffer m_send_buffer
Definition: asio_stream.h:702
Botan::TLS::Stream::m_input_buffer_space
std::vector< uint8_t > m_input_buffer_space
Definition: asio_stream.h:708
Botan::TLS::Stream::m_receive_buffer
boost::beast::flat_buffer m_receive_buffer
Definition: asio_stream.h:701
template<class StreamLayer , class ChannelT = Channel>

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

template<class StreamLayer , class ChannelT = Channel>

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

template<class StreamLayer , class ChannelT = Channel>

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

## Member Function Documentation

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)

Exceptions

  NotImplemented | if Connection_Side is not CLIENT

Definition at line 258 of file asio_stream.h.

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().

260 {
261 BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(HandshakeHandler, handler) type_check;
262
263 boost::system::error_code ec;
264 setup_native_handle(side, ec);
265 // If ec is set by setup_native_handle, the AsyncHandshakeOperation created below will do nothing but call the
266 // handler with the error_code set appropriately - no need to early return here.
267
268 boost::asio::async_completion<HandshakeHandler, void(boost::system::error_code)> init(handler);
269
270 detail::AsyncHandshakeOperation<typename std::decay<HandshakeHandler>::type, Stream>
271 op{std::move(init.completion_handler), *this, ec};
272
273 return init.result.get();
274 }
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:625
boost
Definition: asio_error.h:81
Botan::TLS::Stream::BOOST_ASIO_HANDSHAKE_HANDLER_CHECK
BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(BufferedHandshakeHandler, handler) type_check
std
Definition: bigint.h:1135
type
MechanismType type
Definition: p11_mechanism.cpp:44
Botan::TLS::Stream::handler
const ConstBufferSequence BufferedHandshakeHandler && handler
Definition: asio_stream.h:282
init
int(* init)(CTX *)
Definition: commoncrypto_hash.cpp:26
Botan::TLS::Stream::Stream
Stream(Context &context, Args &&...args)
Construct a new Stream.
Definition: asio_stream.h:64
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 504 of file asio_stream.h.

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

507 {
508 BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
509
510 boost::asio::async_completion<ReadHandler, void(boost::system::error_code, std::size_t)> init(handler);
511
512 detail::AsyncReadOperation<typename std::decay<ReadHandler>::type, Stream, MutableBufferSequence>
513 op{std::move(init.completion_handler), *this, buffers};
514 return init.result.get();
515 }
boost
Definition: asio_error.h:81
Botan::TLS::Stream::buffers
const ConstBufferSequence & buffers
Definition: asio_stream.h:280
std
Definition: bigint.h:1135
type
MechanismType type
Definition: p11_mechanism.cpp:44
Botan::TLS::Stream::handler
const ConstBufferSequence BufferedHandshakeHandler && handler
Definition: asio_stream.h:282
init
int(* init)(CTX *)
Definition: commoncrypto_hash.cpp:26
Botan::TLS::Stream::Stream
Stream(Context &context, Args &&...args)
Construct a new Stream.
Definition: asio_stream.h:64
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.

Parameters

  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 347 of file asio_stream.h.

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

348 {
349 BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(ShutdownHandler, handler) type_check;
350 BOTAN_UNUSED(handler);
351 throw Not_Implemented("async shutdown is not implemented");
352 // TODO: Implement a subclass of AsyncBase that calls native_handle()->close() and writes pending data from
353 // the core to the network, e.g. using AsyncWriteOperation.
354 }
Botan::TLS::Stream::BOOST_ASIO_HANDSHAKE_HANDLER_CHECK
BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(BufferedHandshakeHandler, handler) type_check
Botan::TLS::Stream::Not_Implemented
throw Not_Implemented("buffered async handshake is not implemented")
Botan::TLS::Stream::handler
const ConstBufferSequence BufferedHandshakeHandler && handler
Definition: asio_stream.h:282
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::TLS::Stream::shutdown
void shutdown()
Shut down SSL on the stream.
Definition: asio_stream.h:331
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 467 of file asio_stream.h.

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().

470 {
471 BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
472
473 boost::asio::async_completion<WriteHandler, void(boost::system::error_code, std::size_t)> init(handler);
474
475 boost::system::error_code ec;
476 tls_encrypt(buffers, ec);
477 if(ec)
478 {
479 // we cannot be sure how many bytes were committed here so clear the send_buffer and let the
480 // AsyncWriteOperation call the handler with the error_code set
481 consume_send_buffer(m_send_buffer.size());
482 detail::AsyncWriteOperation<typename std::decay<WriteHandler>::type, Stream>
483 op{std::move(init.completion_handler), *this, std::size_t(0), ec};
484 return init.result.get();
485 }
486
487 detail::AsyncWriteOperation<typename std::decay<WriteHandler>::type, Stream>
488 op{std::move(init.completion_handler), *this, boost::asio::buffer_size(buffers)};
489
490 return init.result.get();
491 }
boost
Definition: asio_error.h:81
Botan::TLS::Stream::buffers
const ConstBufferSequence & buffers
Definition: asio_stream.h:280
std
Definition: bigint.h:1135
type
MechanismType type
Definition: p11_mechanism.cpp:44
Botan::TLS::Stream::handler
const ConstBufferSequence BufferedHandshakeHandler && handler
Definition: asio_stream.h:282
Botan::TLS::Stream::m_send_buffer
boost::beast::flat_buffer m_send_buffer
Definition: asio_stream.h:702
Botan::TLS::Stream::tls_encrypt
void tls_encrypt(const ConstBufferSequence &buffers, boost::system::error_code &ec)
Definition: asio_stream.h:669
init
int(* init)(CTX *)
Definition: commoncrypto_hash.cpp:26
Botan::TLS::Stream::Stream
Stream(Context &context, Args &&...args)
Construct a new Stream.
Definition: asio_stream.h:64
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:617
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(), and Botan::TLS::Stream< StreamLayer, ChannelT >::async_shutdown().

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 |

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 617 of file asio_stream.h.

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().

617 { m_send_buffer.consume(bytesConsumed); }
Botan::TLS::Stream::m_send_buffer
boost::beast::flat_buffer m_send_buffer
Definition: asio_stream.h:702
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 602 of file asio_stream.h.

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().

603 {
604 // Note: It would be nice to avoid this buffer copy. This could be achieved by equipping the StreamCore with
605 // the user's desired target buffer once a read is started, and reading directly into that buffer in tls_record
606 // received. However, we need to deal with the case that the receive buffer provided by the caller is smaller
607 // than the decrypted record, so this optimization might not be worth the additional complexity.
608 const auto copiedBytes = boost::asio::buffer_copy(buffers, m_receive_buffer.data());
609 m_receive_buffer.consume(copiedBytes);
610 return copiedBytes;
611 }
Botan::TLS::Stream::buffers
const ConstBufferSequence & buffers
Definition: asio_stream.h:280
Botan::TLS::Stream::m_receive_buffer
boost::beast::flat_buffer m_receive_buffer
Definition: asio_stream.h:701
template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 108 of file asio_stream.h.

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

108 { return m_nextLayer.get_executor(); }
Botan::TLS::Stream::m_nextLayer
StreamLayer m_nextLayer
Definition: asio_stream.h:699
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, or if the chosen Connection_Side is not available

Definition at line 198 of file asio_stream.h.

199 {
200 boost::system::error_code ec;
201 handshake(side, ec);
202 boost::asio::detail::throw_error(ec, "handshake");
203 }
Botan::TLS::Stream::handshake
void handshake(Connection_Side side)
Performs SSL handshaking.
Definition: asio_stream.h:198
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 213 of file asio_stream.h.

References Botan::Exception::error_type(), 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 >::send_pending_encrypted_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::setup_native_handle(), Botan::TLS::TLS_Exception::type(), and Botan::Unknown.

214 {
215 setup_native_handle(side, ec);
216
217 // send client hello, which was written to the send buffer on client instantiation
218 send_pending_encrypted_data(ec);
219
220 while(!native_handle()->is_active() && !ec)
221 {
222 boost::asio::const_buffer read_buffer{input_buffer().data(), m_nextLayer.read_some(input_buffer(), ec)};
223 if(ec)
224 { return; }
225
226 try
227 {
228 native_handle()->received_data(static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size());
229 }
230 catch(const TLS_Exception& e)
231 {
232 ec = e.type();
233 }
234 catch(const Botan::Exception& e)
235 {
236 ec = e.error_type();
237 }
238 catch(const std::exception&)
239 {
240 ec = Botan::ErrorType::Unknown;
241 }
242
243 send_pending_encrypted_data(ec);
244 }
245 }
Botan::TLS::Stream::send_pending_encrypted_data
size_t send_pending_encrypted_data(boost::system::error_code &ec)
Definition: asio_stream.h:658
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:625
Botan::Exception
Definition: exceptn.h:85
Botan::Exception::error_type
virtual ErrorType error_type() const noexcept
Definition: exceptn.h:101
Botan::TLS::Stream::m_nextLayer
StreamLayer m_nextLayer
Definition: asio_stream.h:699
Botan::TLS::Stream::input_buffer
const boost::asio::mutable_buffer & input_buffer()
Definition: asio_stream.h:594
Botan::TLS::Stream::native_handle
native_handle_type native_handle()
Definition: asio_stream.h:116
Botan::ErrorType::Unknown
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 614 of file asio_stream.h.

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()().

614 { return m_send_buffer.size() > 0; }
Botan::TLS::Stream::m_send_buffer
boost::beast::flat_buffer m_send_buffer
Definition: asio_stream.h:702
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 598 of file asio_stream.h.

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().

598 { return m_receive_buffer.size() > 0; }
Botan::TLS::Stream::m_receive_buffer
boost::beast::flat_buffer m_receive_buffer
Definition: asio_stream.h:701
template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 594 of file asio_stream.h.

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().

594 { return m_input_buffer; }
Botan::TLS::Stream::m_input_buffer
const boost::asio::mutable_buffer m_input_buffer
Definition: asio_stream.h:709
template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 113 of file asio_stream.h.

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

113 { return m_nextLayer.lowest_layer(); }
Botan::TLS::Stream::m_nextLayer
StreamLayer m_nextLayer
Definition: asio_stream.h:699
template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 114 of file asio_stream.h.

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

114 { return m_nextLayer.lowest_layer(); }
Botan::TLS::Stream::m_nextLayer
StreamLayer m_nextLayer
Definition: asio_stream.h:699
template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 116 of file asio_stream.h.

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

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()(), Botan::TLS::Stream< StreamLayer, ChannelT >::read_some(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown(), and Botan::TLS::Stream< StreamLayer, ChannelT >::tls_encrypt().

116 { return m_native_handle.get(); }
Botan::TLS::Stream::m_native_handle
std::unique_ptr< ChannelT > m_native_handle
Definition: asio_stream.h:705
template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 110 of file asio_stream.h.

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()().

110 { return m_nextLayer; }
Botan::TLS::Stream::m_nextLayer
StreamLayer m_nextLayer
Definition: asio_stream.h:699
template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 111 of file asio_stream.h.

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

111 { return m_nextLayer; }
Botan::TLS::Stream::m_nextLayer
StreamLayer m_nextLayer
Definition: asio_stream.h:699
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 >::async_shutdown(), Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_depth(), and Botan::TLS::Stream< StreamLayer, ChannelT >::set_verify_mode().

template<class StreamLayer , class ChannelT = Channel>

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

template<class StreamLayer , class ChannelT = Channel>

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

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 occured, if any.

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

Definition at line 371 of file asio_stream.h.

References Botan::TLS::Stream< StreamLayer, ChannelT >::copy_received_data(), Botan::Exception::error_type(), 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 >::native_handle(), Botan::TLS::TLS_Exception::type(), and Botan::Unknown.

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

373 {
374 if(has_received_data())
375 { return copy_received_data(buffers); }
376
377 boost::asio::const_buffer read_buffer{input_buffer().data(), m_nextLayer.read_some(input_buffer(), ec)};
378 if(ec)
379 { return 0; }
380
381 try
382 {
383 native_handle()->received_data(static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size());
384 }
385 catch(const TLS_Exception& e)
386 {
387 ec = e.type();
388 }
389 catch(const Botan::Exception& e)
390 {
391 ec = e.error_type();
392 }
393 catch(const std::exception&)
394 {
395 ec = Botan::ErrorType::Unknown;
396 }
397
398 return !ec ? copy_received_data(buffers) : 0;
399 }
Botan::Exception
Definition: exceptn.h:85
Botan::TLS::Stream::buffers
const ConstBufferSequence & buffers
Definition: asio_stream.h:280
Botan::Exception::error_type
virtual ErrorType error_type() const noexcept
Definition: exceptn.h:101
Botan::TLS::Stream::m_nextLayer
StreamLayer m_nextLayer
Definition: asio_stream.h:699
Botan::TLS::Stream::input_buffer
const boost::asio::mutable_buffer & input_buffer()
Definition: asio_stream.h:594
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:602
Botan::TLS::Stream::native_handle
native_handle_type native_handle()
Definition: asio_stream.h:116
Botan::ErrorType::Unknown
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:598
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 412 of file asio_stream.h.

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

413 {
414 boost::system::error_code ec;
415 auto const n = read_some(buffers, ec);
416 boost::asio::detail::throw_error(ec, "read_some");
417 return n;
418 }
Botan::TLS::Stream::buffers
const ConstBufferSequence & buffers
Definition: asio_stream.h:280
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:371
template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 595 of file asio_stream.h.

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

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

595 { return m_send_buffer.data(); }
Botan::TLS::Stream::m_send_buffer
boost::beast::flat_buffer m_send_buffer
Definition: asio_stream.h:702
template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 658 of file asio_stream.h.

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

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

659 {
660 if(ec)
661 { return 0; }
662
663 auto writtenBytes = boost::asio::write(m_nextLayer, send_buffer(), ec);
664 consume_send_buffer(writtenBytes);
665 return writtenBytes;
666 }
Botan::TLS::Stream::m_nextLayer
StreamLayer m_nextLayer
Definition: asio_stream.h:699
Botan::TLS::Stream::send_buffer
boost::asio::const_buffer send_buffer() const
Definition: asio_stream.h:595
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:617
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 131 of file asio_stream.h.

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

132 {
133 m_context.set_verify_callback(std::move(callback));
134 }
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
Botan::TLS::Stream::m_context
Context & m_context
Definition: asio_stream.h:698
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 142 of file asio_stream.h.

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

143 {
144 BOTAN_UNUSED(ec);
145 m_context.set_verify_callback(std::move(callback));
146 }
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
Botan::TLS::Stream::m_context
Context & m_context
Definition: asio_stream.h:698
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
template<class StreamLayer , class ChannelT = Channel>

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

Exceptions

  Not_Implemented |

Definition at line 149 of file asio_stream.h.

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

150 {
151 BOTAN_UNUSED(depth);
152 throw Not_Implemented("set_verify_depth is not implemented");
153 }
Botan::TLS::Stream::Not_Implemented
throw Not_Implemented("buffered async handshake is not implemented")
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
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 160 of file asio_stream.h.

References BOTAN_UNUSED, and Botan::NotImplemented.

161 {
162 BOTAN_UNUSED(depth);
163 ec = Botan::ErrorType::NotImplemented;
164 }
Botan::ErrorType::NotImplemented
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
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 168 of file asio_stream.h.

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

169 {
170 BOTAN_UNUSED(v);
171 throw Not_Implemented("set_verify_mode is not implemented");
172 }
Botan::TLS::Stream::Not_Implemented
throw Not_Implemented("buffered async handshake is not implemented")
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
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 180 of file asio_stream.h.

References BOTAN_UNUSED, and Botan::NotImplemented.

181 {
182 BOTAN_UNUSED(v);
183 ec = Botan::ErrorType::NotImplemented;
184 }
Botan::ErrorType::NotImplemented
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
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 625 of file asio_stream.h.

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

625 {}
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 NotImplemented when side is SERVER - currently only CLIENT is implemented

Definition at line 638 of file asio_stream.h.

References Botan::TLS::CLIENT, 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::NotImplemented.

639 {
640 if(side == CLIENT)
641 {
642 m_native_handle = std::unique_ptr<Client>(
643 new Client(m_core,
644 m_context.m_session_manager,
645 m_context.m_credentials_manager,
646 m_context.m_policy,
647 m_context.m_rng,
648 m_context.m_server_info));
649 }
650 else
651 {
652 // TODO: First steps in order to support the server side of this stream would be to instantiate a
653 // Botan::TLS::Server instance as the stream's native_handle and implement the handshake appropriately.
654 ec = Botan::ErrorType::NotImplemented;
655 }
656 }
Botan::TLS::Context::m_rng
RandomNumberGenerator & m_rng
Definition: asio_context.h:108
Botan::ErrorType::NotImplemented
Botan::TLS::Context::m_credentials_manager
Credentials_Manager & m_credentials_manager
Definition: asio_context.h:107
Botan::TLS::Stream::m_core
StreamCore m_core
Definition: asio_stream.h:704
Botan::TLS::Stream::m_context
Context & m_context
Definition: asio_stream.h:698
Botan::TLS::Context::m_server_info
Server_Information m_server_info
Definition: asio_context.h:112
Botan::TLS::Context::m_policy
Policy & m_policy
Definition: asio_context.h:110
Botan::TLS::CLIENT
Definition: tls_magic.h:32
Botan::TLS::Context::m_session_manager
Session_Manager & m_session_manager
Definition: asio_context.h:109
Botan::TLS::Stream::m_native_handle
std::unique_ptr< ChannelT > m_native_handle
Definition: asio_stream.h:705
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.

Parameters

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

Definition at line 300 of file asio_stream.h.

References Botan::Exception::error_type(), Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), Botan::TLS::Stream< StreamLayer, ChannelT >::send_pending_encrypted_data(), Botan::TLS::TLS_Exception::type(), and Botan::Unknown.

301 {
302 try
303 {
304 native_handle()->close();
305 }
306 catch(const TLS_Exception& e)
307 {
308 ec = e.type();
309 }
310 catch(const Botan::Exception& e)
311 {
312 ec = e.error_type();
313 }
314 catch(const std::exception&)
315 {
316 ec = Botan::ErrorType::Unknown;
317 }
318
319 if(!ec)
320 { send_pending_encrypted_data(ec); }
321 }
Botan::TLS::Stream::send_pending_encrypted_data
size_t send_pending_encrypted_data(boost::system::error_code &ec)
Definition: asio_stream.h:658
Botan::Exception
Definition: exceptn.h:85
Botan::Exception::error_type
virtual ErrorType error_type() const noexcept
Definition: exceptn.h:101
Botan::TLS::Stream::native_handle
native_handle_type native_handle()
Definition: asio_stream.h:116
Botan::ErrorType::Unknown
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.

Exceptions

  boost::system::system_error | if error occured

Definition at line 331 of file asio_stream.h.

332 {
333 boost::system::error_code ec;
334 shutdown(ec);
335 boost::asio::detail::throw_error(ec, "shutdown");
336 }
Botan::TLS::Stream::shutdown
void shutdown()
Shut down SSL on the stream.
Definition: asio_stream.h:331
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

Definition at line 669 of file asio_stream.h.

References Botan::Exception::error_type(), Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), Botan::TLS::TLS_Exception::type(), and Botan::Unknown.

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

670 {
671 // NOTE: This is not asynchronous: it encrypts the data synchronously.
672 // The data encrypted by native_handle()->send() is synchronously stored in the send_buffer of m_core,
673 // but is not actually written to the wire, yet.
674 for(auto it = boost::asio::buffer_sequence_begin(buffers);
675 !ec && it != boost::asio::buffer_sequence_end(buffers);
676 it++)
677 {
678 const boost::asio::const_buffer buffer = *it;
679 try
680 {
681 native_handle()->send(static_cast<const uint8_t*>(buffer.data()), buffer.size());
682 }
683 catch(const TLS_Exception& e)
684 {
685 ec = e.type();
686 }
687 catch(const Botan::Exception& e)
688 {
689 ec = e.error_type();
690 }
691 catch(const std::exception&)
692 {
693 ec = Botan::ErrorType::Unknown;
694 }
695 }
696 }
Botan::Exception
Definition: exceptn.h:85
Botan::TLS::Stream::buffers
const ConstBufferSequence & buffers
Definition: asio_stream.h:280
Botan::Exception::error_type
virtual ErrorType error_type() const noexcept
Definition: exceptn.h:101
Botan::TLS::Stream::native_handle
native_handle_type native_handle()
Definition: asio_stream.h:116
Botan::ErrorType::Unknown
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 431 of file asio_stream.h.

References 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().

433 {
434 tls_encrypt(buffers, ec);
435 send_pending_encrypted_data(ec);
436 return !ec ? boost::asio::buffer_size(buffers) : 0;
437 }
Botan::TLS::Stream::send_pending_encrypted_data
size_t send_pending_encrypted_data(boost::system::error_code &ec)
Definition: asio_stream.h:658
Botan::TLS::Stream::buffers
const ConstBufferSequence & buffers
Definition: asio_stream.h:280
Botan::TLS::Stream::tls_encrypt
void tls_encrypt(const ConstBufferSequence &buffers, boost::system::error_code &ec)
Definition: asio_stream.h:669
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 450 of file asio_stream.h.

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

451 {
452 boost::system::error_code ec;
453 auto const n = write_some(buffers, ec);
454 boost::asio::detail::throw_error(ec, "write_some");
455 return n;
456 }
Botan::TLS::Stream::buffers
const ConstBufferSequence & buffers
Definition: asio_stream.h:280
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:431

## Friends And Related Function Documentation

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

friend class detail::AsyncHandshakeOperation
| friend

Definition at line 522 of file asio_stream.h.

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

friend class detail::AsyncReadOperation
| friend

Definition at line 520 of file asio_stream.h.

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

friend class detail::AsyncWriteOperation
| friend

Definition at line 521 of file asio_stream.h.

## Member Data Documentation

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 280 of file asio_stream.h.

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

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 282 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().

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 698 of file asio_stream.h.

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

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 704 of file asio_stream.h.

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

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 709 of file asio_stream.h.

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

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 708 of file asio_stream.h.

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 705 of file asio_stream.h.

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

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 699 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().

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 701 of file asio_stream.h.

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

template<class StreamLayer , class ChannelT = Channel>

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

Definition at line 702 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(), and Botan::TLS::Stream< StreamLayer, ChannelT >::send_buffer().

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

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