join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::TlsContext Class Reference

TLS/DTLS context. More...

#include <tls_context.hpp>

Public Types

enum  Role { TlsClient , TlsServer , DtlsClient , DtlsServer }
 TLS/DTLS role. More...
 

Public Member Functions

 TlsContext () noexcept=default
 create an empty context, unable to negotiate.
 
 TlsContext (Role role)
 create TLS/DTLS context for the given role.
 
 TlsContext (const TlsContext &)=default
 copy constructor.
 
TlsContextoperator= (const TlsContext &)=default
 copy assignment operator.
 
 TlsContext (TlsContext &&)=default
 move constructor.
 
TlsContextoperator= (TlsContext &&)=default
 move assignment operator.
 
 ~TlsContext ()=default
 destroy instance.
 
int setCertificate (const std::string &cert, const std::string &key="") noexcept
 set the certificate and the private key.
 
int setCaPath (const std::string &caPath)
 set the location of the trusted CA certificates.
 
int setCaFile (const std::string &caFile)
 set the location of the trusted CA certificate file.
 
void setVerify (bool verify, int depth=-1) noexcept
 enable or disable peer certificate verification.
 
int setCipher (const std::string &cipher) noexcept
 set the cipher list (TLSv1.2 and below).
 
int setCipher_1_3 (const std::string &cipher) noexcept
 set the cipher list (TLSv1.3).
 
int setAlpnProtocols (const std::vector< std::string > &protocols)
 set the ALPN protocols list.
 
SSL_CTX * handle () const noexcept
 get the native SSL_CTX handle.
 
bool verify () const noexcept
 check if peer verification is enabled.
 
int depth () const noexcept
 get the maximum certificate chain depth.
 
bool isServer () const noexcept
 check if the role is a server role.
 

Detailed Description

TLS/DTLS context.

Member Enumeration Documentation

◆ Role

TLS/DTLS role.

Enumerator
TlsClient 

TLS client.

TlsServer 

TLS server.

DtlsClient 

DTLS client.

DtlsServer 

DTLS server.

Constructor & Destructor Documentation

◆ TlsContext() [1/4]

join::TlsContext::TlsContext ( )
defaultnoexcept

create an empty context, unable to negotiate.

◆ TlsContext() [2/4]

TlsContext::TlsContext ( Role role)
explicit

create TLS/DTLS context for the given role.

Parameters
roleclient or server, TLS or DTLS.
Exceptions
std::runtime_errorif SSL_CTX_new fails.

◆ TlsContext() [3/4]

join::TlsContext::TlsContext ( const TlsContext & )
default

copy constructor.

Parameters
otherother object to copy.

◆ TlsContext() [4/4]

join::TlsContext::TlsContext ( TlsContext && )
default

move constructor.

Parameters
otherother object to move.

◆ ~TlsContext()

join::TlsContext::~TlsContext ( )
default

destroy instance.

Member Function Documentation

◆ depth()

int TlsContext::depth ( ) const
noexcept

get the maximum certificate chain depth.

Returns
depth.

◆ handle()

SSL_CTX * TlsContext::handle ( ) const
noexcept

get the native SSL_CTX handle.

Returns
SSL_CTX*.

◆ isServer()

bool TlsContext::isServer ( ) const
noexcept

check if the role is a server role.

Returns
true if the role is a server role, false otherwise.

◆ operator=() [1/2]

TlsContext & join::TlsContext::operator= ( const TlsContext & )
default

copy assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ operator=() [2/2]

TlsContext & join::TlsContext::operator= ( TlsContext && )
default

move assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ setAlpnProtocols()

int TlsContext::setAlpnProtocols ( const std::vector< std::string > & protocols)

set the ALPN protocols list.

Parameters
protocolslist of protocol names (e.g. {"h2", "http/1.1"}).
Returns
0 on success, -1 on failure.

◆ setCaFile()

int TlsContext::setCaFile ( const std::string & caFile)

set the location of the trusted CA certificate file.

Parameters
caFilepath of the trusted CA certificate file.
Returns
0 on success, -1 on failure.

◆ setCaPath()

int TlsContext::setCaPath ( const std::string & caPath)

set the location of the trusted CA certificates.

Parameters
caPathpath of the trusted CA certificates.
Returns
0 on success, -1 on failure.

◆ setCertificate()

int TlsContext::setCertificate ( const std::string & cert,
const std::string & key = "" )
noexcept

set the certificate and the private key.

Parameters
certcertificate path.
keyprivate key path.
Returns
0 on success, -1 on failure.

◆ setCipher()

int TlsContext::setCipher ( const std::string & cipher)
noexcept

set the cipher list (TLSv1.2 and below).

Parameters
cipherthe cipher list.
Returns
0 on success, -1 on failure.

◆ setCipher_1_3()

int TlsContext::setCipher_1_3 ( const std::string & cipher)
noexcept

set the cipher list (TLSv1.3).

Parameters
cipherthe cipher list.
Returns
0 on success, -1 on failure.

◆ setVerify()

void TlsContext::setVerify ( bool verify,
int depth = -1 )
noexcept

enable or disable peer certificate verification.

Parameters
verifytrue to enable peer verification.
depthmaximum certificate chain depth (-1 = no limit).

◆ verify()

bool TlsContext::verify ( ) const
noexcept

check if peer verification is enabled.

Returns
true if enabled.

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