28 #ifndef WEBSOCKETPP_TRANSPORT_SECURITY_TLS_HPP 29 #define WEBSOCKETPP_TRANSPORT_SECURITY_TLS_HPP 49 namespace tls_socket {
55 typedef lib::function<lib::shared_ptr<lib::asio::ssl::context>(
connection_hdl)>
63 class connection :
public lib::enable_shared_from_this<connection> {
68 typedef lib::shared_ptr<type>
ptr;
71 typedef lib::asio::ssl::stream<lib::asio::ip::tcp::socket>
socket_type;
77 typedef lib::shared_ptr<lib::asio::io_service::strand>
strand_ptr;
88 return shared_from_this();
104 return m_socket->lowest_layer();
112 return m_socket->next_layer();
132 m_socket_init_handler = h;
145 m_tls_init_handler = h;
161 lib::asio::error_code aec;
162 lib::asio::ip::tcp::endpoint ep = m_socket->lowest_layer().remote_endpoint(aec);
166 s <<
"Error getting remote endpoint: " << aec
167 <<
" (" << aec.message() <<
")";
170 ec = lib::error_code();
185 lib::error_code
init_asio (io_service_ptr service, strand_ptr strand,
188 if (!m_tls_init_handler) {
191 m_context = m_tls_init_handler(m_hdl);
196 m_socket = lib::make_shared<socket_type>(
199 m_io_service = service;
201 m_is_server = is_server;
203 return lib::error_code();
235 #if OPENSSL_VERSION_NUMBER >= 0x90812f 240 long res = SSL_set_tlsext_host_name(
241 get_socket().native_handle(), m_uri->get_host().c_str());
248 if (m_socket_init_handler) {
252 callback(lib::error_code());
268 m_socket->async_handshake(
269 get_handshake_type(),
270 m_strand->wrap(lib::bind(
273 lib::placeholders::_1
277 m_socket->async_handshake(
278 get_handshake_type(),
282 lib::placeholders::_1
303 m_ec = lib::error_code();
323 lib::asio::error_code ec;
330 m_socket->async_shutdown(m_strand->wrap(callback));
332 m_socket->async_shutdown(callback);
355 template <
typename ErrorCodeType>
357 if (ec.category() == lib::asio::error::get_ssl_category()) {
358 if (ERR_GET_REASON(ec.value()) == SSL_R_SHORT_READ) {
386 socket_type::handshake_type get_handshake_type() {
394 io_service_ptr m_io_service;
396 context_ptr m_context;
401 lib::error_code m_ec;
404 socket_init_handler m_socket_init_handler;
443 m_socket_init_handler = h;
456 m_tls_init_handler = h;
468 lib::error_code
init(socket_con_ptr scon) {
469 scon->set_socket_init_handler(m_socket_init_handler);
470 scon->set_tls_init_handler(m_tls_init_handler);
471 return lib::error_code();
475 socket_init_handler m_socket_init_handler;
484 #endif // WEBSOCKETPP_TRANSPORT_SECURITY_TLS_HPP
void async_shutdown(socket::shutdown_handler callback)
lib::error_code make_error_code(error::value e)
TLS enabled Asio connection socket component.
websocketpp::server< websocketpp::config::asio > server
socket_type & get_socket()
Retrieve a pointer to the wrapped socket.
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection socket component.
lib::error_code make_error_code(error::value e)
Create an error code with the given value and the asio transport category.
lib::asio::error_code cancel_socket()
Cancel all async operations on this socket.
bool is_secure() const
Checks whether the endpoint creates secure connections.
void pre_init(init_handler callback)
Pre-initialize security policy.
#define _WEBSOCKETPP_REF(x)
bool is_secure() const
Check whether or not this connection is secure.
connection type
Type of this connection socket component.
void set_handle(connection_hdl hdl)
Sets the connection handle.
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
Required tls_init handler not present.
lib::function< lib::shared_ptr< lib::asio::ssl::context >connection_hdl)> tls_init_handler
The signature of the tls_init_handler for this socket policy.
lib::error_code translate_ec(ErrorCodeType ec)
Translate any security policy specific information about an error code.
lib::error_code init(socket_con_ptr scon)
Initialize a connection.
underlying transport pass through
void handle_init(init_handler callback, lib::asio::error_code const &ec)
socket_type::next_layer_type & get_next_layer()
Retrieve a pointer to the layer below the ssl stream.
connection socket_con_type
The type of the corresponding connection socket component.
std::string get_remote_endpoint(lib::error_code &ec) const
Get the remote endpoint address.
void set_tls_init_handler(tls_init_handler h)
Set TLS init handler.
lib::error_code get_ec() const
lib::shared_ptr< lib::asio::ssl::context > context_ptr
Type of a shared pointer to the ASIO TLS context being used.
void set_uri(uri_ptr u)
Set hostname hook.
lib::shared_ptr< socket_type > socket_ptr
Type of a shared pointer to the ASIO socket being used.
void set_socket_init_handler(socket_init_handler h)
Set socket init handler.
lib::asio::io_service * io_service_ptr
Type of a pointer to the ASIO io_service being used.
The application was prompted to provide a TLS context and it was empty or otherwise invalid...
ptr get_shared()
Get a shared pointer to this component.
there was an error in the underlying transport library
Namespace for the WebSocket++ project.
lib::function< void(lib::error_code const &)> init_handler
The type and signature of the callback passed to the init hook.
lib::error_code init_asio(io_service_ptr service, strand_ptr strand, bool is_server)
Perform one time initializations.
socket_type::lowest_layer_type & get_raw_socket()
Retrieve a pointer to the underlying socket.
endpoint type
The type of this endpoint socket component.
lib::function< void(connection_hdl, lib::asio::ssl::stream< lib::asio::ip::tcp::socket > &)> socket_init_handler
The signature of the socket_init_handler for this socket policy.
void set_tls_init_handler(tls_init_handler h)
Set TLS init handler.
lib::function< void(lib::asio::error_code const &)> shutdown_handler
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
void set_socket_init_handler(socket_init_handler h)
Set the socket initialization handler.
lib::asio::ssl::stream< lib::asio::ip::tcp::socket > socket_type
Type of the ASIO socket being used.
void post_init(init_handler callback)
Post-initialize security policy.
TLS enabled Asio endpoint socket component.
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_co...
Failed to set TLS SNI hostname.
Catch-all error for socket component errors that don't fit in other categories.
socket_con_type::ptr socket_con_ptr
The type of a shared pointer to the corresponding connection socket component.
websocketpp::client< websocketpp::config::asio_client > client
====== WARNING ======== This example is presently used as a scratch space.
lib::error_code make_error_code(error::value e)
lib::shared_ptr< lib::asio::io_service::strand > strand_ptr
Type of a pointer to the ASIO io_service strand being used.