RESTinio
Public Member Functions | Private Attributes | List of all members
restinio::connection_state::tls_accessor_t Class Reference

Accessor to TLS-specific information related to a connection. More...

#include <tls.hpp>

Public Member Functions

 tls_accessor_t (tls_socket_t &tls_socket)
 
RESTINIO_NODISCARD auto native_handle () const noexcept
 Get the access to native handle behind Asio's ssl_stream. More...
 

Private Attributes

tls_socket_tm_tls_socket
 

Detailed Description

Accessor to TLS-specific information related to a connection.

Note
You have to manually include restinio/tls.hpp to get the definition of that class. This definition is not present if you include only restinio/all.hpp
Since
v.0.6.0
Examples
sample/tls_inspector/main.cpp.

Definition at line 30 of file tls.hpp.

Constructor & Destructor Documentation

◆ tls_accessor_t()

restinio::connection_state::tls_accessor_t::tls_accessor_t ( tls_socket_t tls_socket)
inline

Definition at line 35 of file tls.hpp.

Member Function Documentation

◆ native_handle()

RESTINIO_NODISCARD auto restinio::connection_state::tls_accessor_t::native_handle ( ) const
inlinenoexcept

Get the access to native handle behind Asio's ssl_stream.

Usage example:

struct openssl_free_t {
void operator()(void * ptr) const noexcept
{
OPENSSL_free( ptr );
}
};
std::string extract_user_name_from_client_certificate(
{
auto nhandle = info.native_handle();
std::unique_ptr<X509, decltype(&X509_free)> client_cert{
SSL_get_peer_certificate(nhandle),
X509_free
};
if( !client_cert )
throw std::runtime_error( "Unable to get client certificate!" );
X509_NAME * subject_name = X509_get_subject_name( client_cert.get() );
int last_pos = -1;
last_pos = X509_NAME_get_index_by_NID(
subject_name,
NID_commonName,
last_pos );
if( last_pos < 0 )
throw std::runtime_error( "commonName is not found!" );
unsigned char * common_name_utf8{};
if( ASN1_STRING_to_UTF8(
&common_name_utf8,
X509_NAME_ENTRY_get_data(
X509_NAME_get_entry( subject_name, last_pos ) ) ) < 0 )
throw std::runtime_error( "ASN1_STRING_to_UTF8 failed!" );
std::unique_ptr<unsigned char, openssl_free_t > common_name_deleter{
common_name_utf8
};
return { reinterpret_cast<char *>(common_name_utf8) };
}
Accessor to TLS-specific information related to a connection.
Definition: tls.hpp:31
RESTINIO_NODISCARD auto native_handle() const noexcept
Get the access to native handle behind Asio's ssl_stream.
Definition: tls.hpp:89
Since
v.0.6.0
Examples
sample/tls_inspector/main.cpp.

Definition at line 89 of file tls.hpp.

Member Data Documentation

◆ m_tls_socket

tls_socket_t& restinio::connection_state::tls_accessor_t::m_tls_socket
private

Definition at line 32 of file tls.hpp.


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