Context Class Reference

#include <Pt/Ssl/Context.h>

Shared configuration for SSL connections. More...

Inherits NonCopyable.

Public Member Functions

 Context ()
 Creates a context for the highest available TLS protocol.
 Context (Protocol protocol)
 Creates a context for protocol.
 ~Context ()
 Destructor.
void assign (const Context &ctx)
 Copies protocol, verify settings and certificates from ctx.
Protocol protocol () const
 Returns the protocol.
void setProtocol (Protocol protocol)
 Sets the protocol.
void setVerifyDepth (int n)
 Limits how many certificates are checked in the peer chain.
VerifyMode verifyMode () const
 Returns the verification mode.
void setVerifyMode (VerifyMode mode)
 Sets the verification mode.
void addCACertificate (const Certificate &trustedCert)
 Adds trustedCert to the trusted CA certificates.
void setIdentity (const Certificate &cert)
 Sets the certificate presented to the peer.
void addCertificate (const Certificate &cert)
 Adds cert to the chain presented with the identity.

Detailed Description

Context is the configuration the group described: protocol, verification, identity, chain, and trusted CAs, used by every stream opened with it. It is not a connected stream. Keep the context alive while a stream that opened with it is still open.

The default constructor selects TLS, the highest available protocol, and TryVerify. The protocol constructor selects that protocol and the same default verify mode. setProtocol() and setVerifyMode() change them later. setVerifyDepth() limits how many certificates in the peer's chain are checked.

setIdentity() is required on a server context and optional on a client context. addCertificate() extends the chain presented with that identity. addCACertificate() extends the trust store used to verify the peer. Each of those calls copies what it needs from the Certificate argument, which must be valid for the call. Unusable material throws InvalidCertificate.

The object is not copyable. assign() copies protocol, verify settings, and certificates from another context into this one.

Member Function Documentation

◆ addCACertificate()

void addCACertificate ( const Certificate & trustedCert)
Exceptions
%InvalidCertificateif trustedCert cannot be used.

◆ setIdentity()

void setIdentity ( const Certificate & cert)

Required for a server context. For a client context, needed only for client authentication.

Exceptions
%InvalidCertificateif cert cannot be used as identity.

◆ addCertificate()

void addCertificate ( const Certificate & cert)
Exceptions
%InvalidCertificateif cert cannot be used.