TLS enabled Asio connection socket component. More...
#include <tls.hpp>
Public Types | |
typedef connection | type |
Type of this connection socket component. More... | |
typedef lib::shared_ptr< type > | ptr |
Type of a shared pointer to this connection socket component. More... | |
typedef lib::asio::ssl::stream< lib::asio::ip::tcp::socket > | socket_type |
Type of the ASIO socket being used. More... | |
typedef lib::shared_ptr< socket_type > | socket_ptr |
Type of a shared pointer to the ASIO socket being used. More... | |
typedef lib::asio::io_service * | io_service_ptr |
Type of a pointer to the ASIO io_service being used. More... | |
typedef lib::shared_ptr< lib::asio::io_service::strand > | strand_ptr |
Type of a pointer to the ASIO io_service strand being used. More... | |
typedef lib::shared_ptr< lib::asio::ssl::context > | context_ptr |
Type of a shared pointer to the ASIO TLS context being used. More... | |
Public Member Functions | |
connection () | |
ptr | get_shared () |
Get a shared pointer to this component. More... | |
bool | is_secure () const |
Check whether or not this connection is secure. More... | |
socket_type::lowest_layer_type & | get_raw_socket () |
Retrieve a pointer to the underlying socket. More... | |
socket_type::next_layer_type & | get_next_layer () |
Retrieve a pointer to the layer below the ssl stream. More... | |
socket_type & | get_socket () |
Retrieve a pointer to the wrapped socket. More... | |
void | set_socket_init_handler (socket_init_handler h) |
Set the socket initialization handler. More... | |
void | set_tls_init_handler (tls_init_handler h) |
Set TLS init handler. More... | |
std::string | get_remote_endpoint (lib::error_code &ec) const |
Get the remote endpoint address. More... | |
Protected Member Functions | |
lib::error_code | init_asio (io_service_ptr service, strand_ptr strand, bool is_server) |
Perform one time initializations. More... | |
void | set_uri (uri_ptr u) |
Set hostname hook. More... | |
void | pre_init (init_handler callback) |
Pre-initialize security policy. More... | |
void | post_init (init_handler callback) |
Post-initialize security policy. More... | |
void | set_handle (connection_hdl hdl) |
Sets the connection handle. More... | |
void | handle_init (init_handler callback, lib::asio::error_code const &ec) |
lib::error_code | get_ec () const |
lib::asio::error_code | cancel_socket () |
Cancel all async operations on this socket. More... | |
void | async_shutdown (socket::shutdown_handler callback) |
template<typename ErrorCodeType > | |
lib::error_code | translate_ec (ErrorCodeType ec) |
Translate any security policy specific information about an error code. More... | |
lib::error_code | translate_ec (lib::error_code ec) |
Overload of translate_ec to catch cases where lib::error_code is the same type as lib::asio::error_code. More... | |
TLS enabled Asio connection socket component.
transport::asio::tls_socket::connection implements a secure connection socket component that uses Asio's ssl::stream to wrap an ip::tcp::socket.
typedef lib::shared_ptr<type> websocketpp::transport::asio::tls_socket::connection::ptr |
typedef lib::asio::ssl::stream<lib::asio::ip::tcp::socket> websocketpp::transport::asio::tls_socket::connection::socket_type |
typedef lib::shared_ptr<socket_type> websocketpp::transport::asio::tls_socket::connection::socket_ptr |
typedef lib::asio::io_service* websocketpp::transport::asio::tls_socket::connection::io_service_ptr |
typedef lib::shared_ptr<lib::asio::io_service::strand> websocketpp::transport::asio::tls_socket::connection::strand_ptr |
typedef lib::shared_ptr<lib::asio::ssl::context> websocketpp::transport::asio::tls_socket::connection::context_ptr |
|
inlineexplicit |
|
inline |
Get a shared pointer to this component.
Definition at line 87 of file tls.hpp.
Referenced by websocketpp::transport::asio::connection< config >::get_shared(), and post_init().
|
inline |
Check whether or not this connection is secure.
Definition at line 95 of file tls.hpp.
Referenced by websocketpp::transport::asio::connection< config >::is_secure().
|
inline |
Retrieve a pointer to the underlying socket.
This is used internally. It can also be used to set socket options, etc
Definition at line 103 of file tls.hpp.
Referenced by cancel_socket().
|
inline |
Retrieve a pointer to the layer below the ssl stream.
This is used internally.
Definition at line 111 of file tls.hpp.
Referenced by websocketpp::transport::asio::connection< config >::proxy_read(), and websocketpp::transport::asio::connection< config >::proxy_write().
|
inline |
Retrieve a pointer to the wrapped socket.
This is used internally.
Definition at line 119 of file tls.hpp.
Referenced by websocketpp::transport::asio::connection< config >::async_read_at_least(), websocketpp::transport::asio::connection< config >::async_write(), and pre_init().
|
inline |
|
inline |
Set TLS init handler.
The tls init handler is called when needed to request a TLS context for the library to use. A TLS init handler must be set and it must return a valid TLS context in order for this endpoint to be able to initialize TLS connections
h | The new tls_init_handler |
|
inline |
Get the remote endpoint address.
The iostream transport has no information about the ultimate remote endpoint. It will return the string "iostream transport". To indicate this.
TODO: allow user settable remote endpoint addresses if this seems useful
Definition at line 158 of file tls.hpp.
References websocketpp::transport::asio::error::make_error_code(), and websocketpp::transport::asio::error::pass_through.
Referenced by websocketpp::transport::asio::connection< config >::get_remote_endpoint().
|
inlineprotected |
Perform one time initializations.
init_asio is called once immediately after construction to initialize Asio components to the io_service
service | A pointer to the endpoint's io_service |
strand | A pointer to the connection's strand |
is_server | Whether or not the endpoint is a server or not. |
Definition at line 185 of file tls.hpp.
References _WEBSOCKETPP_REF, websocketpp::transport::asio::socket::error::invalid_tls_context, websocketpp::transport::asio::socket::make_error_code(), and websocketpp::transport::asio::socket::error::missing_tls_init_handler.
Referenced by websocketpp::transport::asio::connection< config >::init_asio().
|
inlineprotected |
Set hostname hook.
Called by the transport as a connection is being established to provide the hostname being connected to to the security/socket layer.
This socket policy uses the hostname to set the appropriate TLS SNI header.
u | The uri to set |
Definition at line 218 of file tls.hpp.
Referenced by websocketpp::transport::asio::connection< config >::set_uri().
|
inlineprotected |
Pre-initialize security policy.
Called by the transport after a new connection is created to initialize the socket component of the connection. This method is not allowed to write any bytes to the wire. This initialization happens before any proxies or other intermediate wrappers are negotiated.
callback | Handler to call back with completion information |
Definition at line 231 of file tls.hpp.
References get_socket(), websocketpp::transport::asio::socket::make_error_code(), and websocketpp::transport::asio::socket::error::tls_failed_sni_hostname.
Referenced by websocketpp::transport::asio::connection< config >::init().
|
inlineprotected |
Post-initialize security policy.
Called by the transport after all intermediate proxies have been negotiated. This gives the security policy the chance to talk with the real remote endpoint for a bit before the websocket handshake.
callback | Handler to call back with completion information |
Definition at line 263 of file tls.hpp.
References get_shared(), handle_init(), websocketpp::transport::asio::socket::make_error_code(), and websocketpp::transport::asio::socket::error::tls_handshake_timeout.
Referenced by websocketpp::transport::asio::connection< config >::post_init().
|
inlineprotected |
Sets the connection handle.
The connection handle is passed to any handlers to identify the connection
hdl | The new handle |
Definition at line 295 of file tls.hpp.
Referenced by websocketpp::transport::asio::connection< config >::set_handle().
|
inlineprotected |
Definition at line 299 of file tls.hpp.
References websocketpp::transport::asio::socket::make_error_code(), and websocketpp::transport::asio::socket::error::tls_handshake_failed.
Referenced by post_init().
|
inlineprotected |
Definition at line 309 of file tls.hpp.
Referenced by websocketpp::transport::asio::connection< config >::handle_post_init_timeout().
|
inlineprotected |
Cancel all async operations on this socket.
Attempts to cancel all async operations on this socket and reports any failures.
NOTE: Windows XP and earlier do not support socket cancellation.
Definition at line 322 of file tls.hpp.
References get_raw_socket().
Referenced by websocketpp::transport::asio::connection< config >::cancel_socket_checked().
|
inlineprotected |
Definition at line 328 of file tls.hpp.
Referenced by websocketpp::transport::asio::connection< config >::async_shutdown().
|
inlineprotected |
Translate any security policy specific information about an error code.
Translate_ec takes an Asio error code and attempts to convert its value to an appropriate websocketpp error code. In the case that the Asio and Websocketpp error types are the same (such as using boost::asio and boost::system_error or using standalone asio and std::system_error the code will be passed through natively.
In the case of a mismatch (boost::asio with std::system_error) a translated code will be returned. Any error that is determined to be related to TLS but does not have a more specific websocketpp error code is returned under the catch all error tls_error
. Non-TLS related errors are returned as the transport generic error pass_through
ec | The error code to translate_ec |
Definition at line 356 of file tls.hpp.
References websocketpp::error::make_error_code(), websocketpp::transport::error::pass_through, websocketpp::transport::error::tls_error, and websocketpp::transport::error::tls_short_read.
Referenced by websocketpp::transport::asio::connection< config >::handle_async_read(), and websocketpp::transport::asio::connection< config >::handle_async_shutdown().
|
inlineprotected |