MySQL 8.3.0
Source Code Documentation
Channel Class Reference

SSL aware socket buffers. More...

#include <channel.h>

Public Types

using recv_buffer_type = std::vector< uint8_t, default_init_allocator< uint8_t > >
 
using recv_view_type = stdx::span< typename recv_buffer_type::value_type >
 
using Ssl = mysql_harness::Ssl
 

Public Member Functions

 Channel ()=default
 
 Channel (Ssl ssl)
 
void init_ssl (SSL_CTX *ssl_ctx)
 initialize the SSL session. More...
 
stdx::expected< void, std::error_code > tls_accept ()
 accept a TLS session. More...
 
stdx::expected< void, std::error_code > tls_connect ()
 connect a TLS session. More...
 
bool tls_init_is_finished ()
 
stdx::expected< bool, std::error_code > tls_shutdown ()
 
template<class DynamicBuffer >
std::enable_if< net::is_dynamic_buffer< DynamicBuffer >::value, stdx::expected< size_t, std::error_code > >::type write (DynamicBuffer &dyn_buf)
 write unencrypted net::dynamic_buffer to the channel. More...
 
stdx::expected< size_t, std::error_code > write (const net::const_buffer &b)
 write unencrypted net::const_buffer to the channel. More...
 
template<class DynamicBuffer >
stdx::expected< size_t, std::error_code > read (DynamicBuffer &dyn_buf, size_t sz)
 read unencrypted data from channel to a net::dynamic_buffer. More...
 
stdx::expected< size_t, std::error_code > read_to_plain (size_t sz)
 
stdx::expected< size_t, std::error_code > write_plain (const net::const_buffer &b)
 write unencrypted data from a net::const_buffer to the channel. More...
 
stdx::expected< size_t, std::error_code > read_plain (const net::mutable_buffer &b)
 read plaintext data from recv_plain_buffer() into b. More...
 
stdx::expected< size_t, std::error_code > flush_from_recv_buf ()
 flush data from receive buffer to recv_plain_buffer(). More...
 
stdx::expected< size_t, std::error_code > flush_to_send_buf ()
 flush data to the send buffer. More...
 
void want_recv (size_t wanted)
 bytes wanted. More...
 
size_t want_recv () const
 bytes wanted. More...
 
recv_buffer_typerecv_buffer ()
 buffer of data that was received from the socket. More...
 
recv_buffer_typesend_buffer ()
 buffer of data to be sent to the socket. More...
 
recv_buffer_typesend_plain_buffer ()
 unencrypted data to be sent to the socket. More...
 
const recv_buffer_typerecv_buffer () const
 buffer of data that was received from the socket. More...
 
const recv_view_typerecv_view () const
 network data after a recv(). More...
 
const recv_buffer_typesend_buffer () const
 buffer of data to be sent to the socket. More...
 
const recv_buffer_typepayload_buffer () const
 payload buffer for More...
 
recv_buffer_typepayload_buffer ()
 
const recv_view_typerecv_plain_view () const
 decrypted data after a recv(). More...
 
void consume_raw (size_t count)
 
void consume_plain (size_t count)
 
void view_discard_raw ()
 
void view_discard_plain ()
 
void view_sync_raw ()
 
void view_sync_plain ()
 
void is_tls (bool v)
 mark channel as containing TLS data in the recv_buffer(). More...
 
bool is_tls () const
 check if connection switched to TLS. More...
 
SSL * ssl () const
 get access to the raw SSL handle. More...
 
Ssl release_ssl ()
 release the internal Ssl structure. More...
 

Private Attributes

size_t want_recv_ {}
 
recv_buffer_type recv_buffer_
 
recv_view_type recv_view_
 
recv_buffer_type recv_plain_buffer_
 
recv_view_type recv_plain_view_
 
recv_buffer_type payload_buffer_
 
recv_buffer_type send_plain_buffer_
 
recv_buffer_type send_buffer_
 
bool is_tls_ {false}
 
Ssl ssl_ {}
 

Detailed Description

SSL aware socket buffers.

manages the raw and plaintext socket buffers of connection which may switch to TLS.

an external user like a socket class can

  • receive from a socket and store the socket data into the recv_buffer().
  • send to a socket from the send_buffer().

Once init_ssl() is called, the recv_plain() and write_plain() methods transparently decrypt and encrypt.

Member Typedef Documentation

◆ recv_buffer_type

using Channel::recv_buffer_type = std::vector<uint8_t, default_init_allocator<uint8_t> >

◆ recv_view_type

using Channel::recv_view_type = stdx::span<typename recv_buffer_type::value_type>

◆ Ssl

Constructor & Destructor Documentation

◆ Channel() [1/2]

Channel::Channel ( )
default

◆ Channel() [2/2]

Channel::Channel ( Ssl  ssl)
inlineexplicit

Member Function Documentation

◆ consume_plain()

void Channel::consume_plain ( size_t  count)

◆ consume_raw()

void Channel::consume_raw ( size_t  count)

◆ flush_from_recv_buf()

stdx::expected< size_t, std::error_code > Channel::flush_from_recv_buf ( )

flush data from receive buffer to recv_plain_buffer().

if an SSL session is active, flush_to_recv_buf() ensures that data encrypted data gets decrypted and added to the recv_plain_buffer().

In case no SSL session is active, it is a no-op.

◆ flush_to_send_buf()

stdx::expected< size_t, std::error_code > Channel::flush_to_send_buf ( )

flush data to the send buffer.

if write_plain() was used and an SSL session is active, flush_to_send_buf() ensures that data plaintext data gets encrypted and added to the send_buf().

In case no SSL session is active, it is a no-op.

◆ init_ssl()

void Channel::init_ssl ( SSL_CTX *  ssl_ctx)
inline

initialize the SSL session.

◆ is_tls() [1/2]

bool Channel::is_tls ( ) const
inline

check if connection switched to TLS.

◆ is_tls() [2/2]

void Channel::is_tls ( bool  v)
inline

mark channel as containing TLS data in the recv_buffer().

it is independent of calling init_tls() as the channel may be used to transfer encrypted data as is without ever call init_ssl().

◆ payload_buffer() [1/2]

recv_buffer_type & Channel::payload_buffer ( )
inline

◆ payload_buffer() [2/2]

const recv_buffer_type & Channel::payload_buffer ( ) const
inline

payload buffer for

◆ read()

template<class DynamicBuffer >
stdx::expected< size_t, std::error_code > Channel::read ( DynamicBuffer &  dyn_buf,
size_t  sz 
)
inline

read unencrypted data from channel to a net::dynamic_buffer.

if the channel has a ssl session in transparently decrypts before the data is appending to the recv_plain_buf()

◆ read_plain()

stdx::expected< size_t, std::error_code > Channel::read_plain ( const net::mutable_buffer b)

read plaintext data from recv_plain_buffer() into b.

◆ read_to_plain()

stdx::expected< size_t, std::error_code > Channel::read_to_plain ( size_t  sz)

◆ recv_buffer() [1/2]

recv_buffer_type & Channel::recv_buffer ( )
inline

buffer of data that was received from the socket.

◆ recv_buffer() [2/2]

const recv_buffer_type & Channel::recv_buffer ( ) const
inline

buffer of data that was received from the socket.

◆ recv_plain_view()

const Channel::recv_view_type & Channel::recv_plain_view ( ) const

decrypted data after a recv().

◆ recv_view()

const Channel::recv_view_type & Channel::recv_view ( ) const

network data after a recv().

◆ release_ssl()

Channel::Ssl Channel::release_ssl ( )

release the internal Ssl structure.

◆ send_buffer() [1/2]

recv_buffer_type & Channel::send_buffer ( )
inline

buffer of data to be sent to the socket.

written into by write(), write_plain(), flush_to_send_buf().

◆ send_buffer() [2/2]

const recv_buffer_type & Channel::send_buffer ( ) const
inline

buffer of data to be sent to the socket.

◆ send_plain_buffer()

Channel::recv_buffer_type & Channel::send_plain_buffer ( )

unencrypted data to be sent to the socket.

◆ ssl()

SSL * Channel::ssl ( ) const
inline

get access to the raw SSL handle.

can be used to call:

  • SSL_get_cipher_name()
  • SSL_version()
Return values
nullptrif channel has no SSL initialized.

◆ tls_accept()

stdx::expected< void, std::error_code > Channel::tls_accept ( )

accept a TLS session.

expects a Tls::ClientHello in the recv_buf.

◆ tls_connect()

stdx::expected< void, std::error_code > Channel::tls_connect ( )

connect a TLS session.

◆ tls_init_is_finished()

bool Channel::tls_init_is_finished ( )

◆ tls_shutdown()

stdx::expected< bool, std::error_code > Channel::tls_shutdown ( )
Returns
on success, true if shutdown is finished, false if not
on failure, an error-code

◆ view_discard_plain()

void Channel::view_discard_plain ( )

◆ view_discard_raw()

void Channel::view_discard_raw ( )

◆ view_sync_plain()

void Channel::view_sync_plain ( )

◆ view_sync_raw()

void Channel::view_sync_raw ( )

◆ want_recv() [1/2]

size_t Channel::want_recv ( ) const
inline

bytes wanted.

Returns
bytes wanted to be received at least.

◆ want_recv() [2/2]

void Channel::want_recv ( size_t  wanted)
inline

bytes wanted.

signals to the socket layer how many bytes should be at least read into the buffer.

◆ write() [1/2]

stdx::expected< size_t, std::error_code > Channel::write ( const net::const_buffer b)
inline

write unencrypted net::const_buffer to the channel.

if the channel has an ssl session it transparently encrypts before the data is appended to the send_buf()

◆ write() [2/2]

template<class DynamicBuffer >
std::enable_if< net::is_dynamic_buffer< DynamicBuffer >::value, stdx::expected< size_t, std::error_code > >::type Channel::write ( DynamicBuffer &  dyn_buf)
inline

write unencrypted net::dynamic_buffer to the channel.

if the channel has an ssl session it transparently encrypts before the data is appended to the send_buf()

◆ write_plain()

stdx::expected< size_t, std::error_code > Channel::write_plain ( const net::const_buffer b)

write unencrypted data from a net::const_buffer to the channel.

call flush_to_send_buf() ensure data is written to the send-buffers for the socket.

See also
flush_to_send_buf()

Member Data Documentation

◆ is_tls_

bool Channel::is_tls_ {false}
private

◆ payload_buffer_

recv_buffer_type Channel::payload_buffer_
private

◆ recv_buffer_

recv_buffer_type Channel::recv_buffer_
private

◆ recv_plain_buffer_

recv_buffer_type Channel::recv_plain_buffer_
private

◆ recv_plain_view_

recv_view_type Channel::recv_plain_view_
private

◆ recv_view_

recv_view_type Channel::recv_view_
private

◆ send_buffer_

recv_buffer_type Channel::send_buffer_
private

◆ send_plain_buffer_

recv_buffer_type Channel::send_plain_buffer_
private

◆ ssl_

Ssl Channel::ssl_ {}
private

◆ want_recv_

size_t Channel::want_recv_ {}
private

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