Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::network::TlsContext Class Reference

Server TLS settings: certificates (with SNI) and ALPN. More...

#include <TlsContext.hpp>

Collaboration diagram for orbit::network::TlsContext:

Public Member Functions

 TlsContext (const std::string &cert_file, const std::string &key_file, config::HttpVersion http_version)
 
 TlsContext (const config::TlsCertificate &default_cert, std::vector< config::TlsCertificate > sni_certs, config::HttpVersion http_version)
 
 ~TlsContext ()
 
 TlsContext (const TlsContext &)=delete
 
TlsContext & operator= (const TlsContext &)=delete
 
SSL_CTX * get () const
 
config::HttpVersion get_http_version () const
 
bool reload (std::string *error=nullptr)
 Re-reads every certificate and key file. Thread-safe.
 
bool files_changed () const
 True if a certificate or key file changed since it was last loaded.
 
std::string certificate_for (const std::string &server_name) const
 The certificate file that serves server_name (for tests and logs).
 
void configure (SSL_CTX *ctx)
 Configures a context to match this one (protocol floor, ALPN).
 

Private Member Functions

std::shared_ptr< const CertSet > current () const
 
std::string file_stamp () const
 

Static Private Member Functions

static int servername_cb (SSL *ssl, int *alert, void *arg)
 

Private Attributes

SSL_CTX * ctx_ {nullptr}
 
config::HttpVersion http_version_ {config::HttpVersion::Http1_1}
 
config::TlsCertificate default_cert_
 
std::vector< config::TlsCertificate > sni_certs_
 
std::mutex mutex_
 
std::shared_ptr< const CertSet > certs_
 
std::string stamp_
 

Detailed Description

Server TLS settings: certificates (with SNI) and ALPN.

get() returns one SSL_CTX for the server's lifetime. During each handshake a servername callback moves the connection to the context holding the certificate for the requested name, so certificates can be chosen by SNI and replaced (reload()) without touching that SSL_CTX.

Constructor & Destructor Documentation

◆ TlsContext() [1/3]

orbit::network::TlsContext::TlsContext ( const std::string &  cert_file,
const std::string &  key_file,
config::HttpVersion  http_version 
)

◆ TlsContext() [2/3]

orbit::network::TlsContext::TlsContext ( const config::TlsCertificate &  default_cert,
std::vector< config::TlsCertificate >  sni_certs,
config::HttpVersion  http_version 
)
Parameters
default_certServed when no SNI certificate matches the name.
sni_certsChosen by the DNS names in each one's subjectAltName (or CN).

◆ ~TlsContext()

orbit::network::TlsContext::~TlsContext ( )

◆ TlsContext() [3/3]

orbit::network::TlsContext::TlsContext ( const TlsContext &  )
delete

Member Function Documentation

◆ certificate_for()

std::string orbit::network::TlsContext::certificate_for ( const std::string &  server_name) const

The certificate file that serves server_name (for tests and logs).

◆ configure()

void orbit::network::TlsContext::configure ( SSL_CTX *  ctx)

Configures a context to match this one (protocol floor, ALPN).

◆ current()

std::shared_ptr< const CertSet > orbit::network::TlsContext::current ( ) const
private

◆ file_stamp()

std::string orbit::network::TlsContext::file_stamp ( ) const
private

◆ files_changed()

bool orbit::network::TlsContext::files_changed ( ) const

True if a certificate or key file changed since it was last loaded.

◆ get()

SSL_CTX * orbit::network::TlsContext::get ( ) const
inline

◆ get_http_version()

config::HttpVersion orbit::network::TlsContext::get_http_version ( ) const
inline

◆ operator=()

TlsContext & orbit::network::TlsContext::operator= ( const TlsContext &  )
delete

◆ reload()

bool orbit::network::TlsContext::reload ( std::string *  error = nullptr)

Re-reads every certificate and key file. Thread-safe.

New handshakes use the new certificates; established connections are unaffected. If any file fails to load, the current certificates stay.

Parameters
errorReceives the reason on failure.

◆ servername_cb()

static int orbit::network::TlsContext::servername_cb ( SSL *  ssl,
int *  alert,
void *  arg 
)
staticprivate

Member Data Documentation

◆ certs_

std::shared_ptr<const CertSet> orbit::network::TlsContext::certs_
private

◆ ctx_

SSL_CTX* orbit::network::TlsContext::ctx_ {nullptr}
private

◆ default_cert_

config::TlsCertificate orbit::network::TlsContext::default_cert_
private

◆ http_version_

config::HttpVersion orbit::network::TlsContext::http_version_ {config::HttpVersion::Http1_1}
private

◆ mutex_

std::mutex orbit::network::TlsContext::mutex_
mutableprivate

◆ sni_certs_

std::vector<config::TlsCertificate> orbit::network::TlsContext::sni_certs_
private

◆ stamp_

std::string orbit::network::TlsContext::stamp_
private

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