Ark Server API (ASE) - Wiki
|
#include <SSLManager.h>
Public Types | |
using | PrivateKeyPassphraseHandlerPtr = Poco::SharedPtr<PrivateKeyPassphraseHandler> |
using | InvalidCertificateHandlerPtr = Poco::SharedPtr<InvalidCertificateHandler> |
Public Member Functions | |
void | initializeServer (PrivateKeyPassphraseHandlerPtr ptrPassphraseHandler, InvalidCertificateHandlerPtr ptrCertificateHandler, Context::Ptr ptrContext) |
Returns the instance of the SSLManager singleton. | |
void | initializeClient (PrivateKeyPassphraseHandlerPtr ptrPassphraseHandler, InvalidCertificateHandlerPtr ptrHandler, Context::Ptr ptrContext) |
Context::Ptr | defaultServerContext () |
Context::Ptr | defaultClientContext () |
PrivateKeyPassphraseHandlerPtr | serverPassphraseHandler () |
InvalidCertificateHandlerPtr | serverCertificateHandler () |
PrivateKeyPassphraseHandlerPtr | clientPassphraseHandler () |
InvalidCertificateHandlerPtr | clientCertificateHandler () |
PrivateKeyFactoryMgr & | privateKeyFactoryMgr () |
CertificateHandlerFactoryMgr & | certificateHandlerFactoryMgr () |
void | shutdown () |
Static Public Member Functions | |
static SSLManager & | instance () |
static bool | isFIPSEnabled () |
Public Attributes | |
Poco::BasicEvent< VerificationErrorArgs > | ServerVerificationError |
Poco::BasicEvent< VerificationErrorArgs > | ClientVerificationError |
Fired whenever a certificate verification error is detected by the server during a handshake. | |
Poco::BasicEvent< std::string > | PrivateKeyPassphraseRequired |
Fired whenever a certificate verification error is detected by the client during a handshake. | |
Static Public Attributes | |
static const std::string | CFG_SERVER_PREFIX |
static const std::string | CFG_CLIENT_PREFIX |
Protected Member Functions | |
int | contextIndex () const |
Static Protected Member Functions | |
static int | verifyClientCallback (int ok, X509_STORE_CTX *pStore) |
static int | verifyServerCallback (int ok, X509_STORE_CTX *pStore) |
static int | privateKeyPassphraseCallback (char *pBuf, int size, int flag, void *userData) |
static int | verifyOCSPResponseCallback (SSL *pSSL, void *arg) |
static Poco::Util::AbstractConfiguration & | appConfig () |
Private Member Functions | |
SSLManager () | |
~SSLManager () | |
Creates the SSLManager. | |
void | initDefaultContext (bool server) |
Destroys the SSLManager. | |
void | initEvents (bool server) |
Inits the default context, the first time it is accessed. | |
void | initPassphraseHandler (bool server) |
Registers delegates at the events according to the configuration. | |
void | initCertificateHandler (bool server) |
Inits the passphrase handler. | |
Static Private Member Functions | |
static int | verifyCallback (bool server, int ok, X509_STORE_CTX *pStore) |
Inits the certificate handler. | |
Static Private Attributes | |
static const std::string | CFG_PRIV_KEY_FILE |
static const std::string | CFG_CERTIFICATE_FILE |
static const std::string | CFG_CA_LOCATION |
static const std::string | CFG_VER_MODE |
static const Context::VerificationMode | VAL_VER_MODE |
static const std::string | CFG_VER_DEPTH |
static const int | VAL_VER_DEPTH |
static const std::string | CFG_ENABLE_DEFAULT_CA |
static const bool | VAL_ENABLE_DEFAULT_CA |
static const std::string | CFG_CIPHER_LIST |
static const std::string | CFG_CYPHER_LIST |
static const std::string | VAL_CIPHER_LIST |
static const std::string | CFG_PREFER_SERVER_CIPHERS |
static const std::string | CFG_DELEGATE_HANDLER |
static const std::string | VAL_DELEGATE_HANDLER |
static const std::string | CFG_CERTIFICATE_HANDLER |
static const std::string | VAL_CERTIFICATE_HANDLER |
static const std::string | CFG_CACHE_SESSIONS |
static const std::string | CFG_SESSION_ID_CONTEXT |
static const std::string | CFG_SESSION_CACHE_SIZE |
static const std::string | CFG_SESSION_TIMEOUT |
static const std::string | CFG_EXTENDED_VERIFICATION |
static const std::string | CFG_REQUIRE_TLSV1 |
static const std::string | CFG_REQUIRE_TLSV1_1 |
static const std::string | CFG_REQUIRE_TLSV1_2 |
static const std::string | CFG_REQUIRE_TLSV1_3 |
static const std::string | CFG_DISABLE_PROTOCOLS |
static const std::string | CFG_DH_PARAMS_FILE |
static const std::string | CFG_ECDH_CURVE |
Friends | |
class | Poco::SingletonHolder< SSLManager > |
class | Context |
SSLManager is a singleton for holding the default server/client Context and handling callbacks for certificate verification errors and private key passphrases.
Proper initialization of SSLManager is critical.
SSLManager can be initialized manually, by calling initializeServer() and/or initializeClient(), or initialization can be automatic. In the latter case, a Poco::Util::Application instance must be available and the required configuration properties must be set (see below).
Note that manual initialization must happen very early in the application, before defaultClientContext() or defaultServerContext() are called.
If defaultClientContext() and defaultServerContext() are never called in an application, initialization of SSLManager can be omitted. However, in this case, delegates for the ServerVerificationError, ClientVerificationError and PrivateKeyPassphraseRequired events must be registered.
An exemplary documentation which sets either the server or client default context and creates a PrivateKeyPassphraseHandler that reads the password from the XML file looks like this:
<AppConfig> <openSSL> <server|client> <privateKeyFile>mycert.key</privateKeyFile> <certificateFile>mycert.crt</certificateFile> <caConfig>rootcert.pem</caConfig> <verificationMode>none|relaxed|strict|once</verificationMode> <verificationDepth>1..9</verificationDepth> <loadDefaultCAFile>true|false</loadDefaultCAFile> <cipherList>ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH</cipherList> <preferServerCiphers>true|false</preferServerCiphers> <privateKeyPassphraseHandler> <name>KeyFileHandler</name> <options> <password>test</password> </options> </privateKeyPassphraseHandler> <invalidCertificateHandler> <name>ConsoleCertificateHandler</name> </invalidCertificateHandler> <cacheSessions>true|false</cacheSessions> <sessionIdContext>someString</sessionIdContext> <sessionCacheSize>0..n</sessionCacheSize> <sessionTimeout>0..n</sessionTimeout> <extendedVerification>true|false</extendedVerification> <requireTLSv1>true|false</requireTLSv1> <requireTLSv1_1>true|false</requireTLSv1_1> <requireTLSv1_2>true|false</requireTLSv1_2> <requireTLSv1_3>true|false</requireTLSv1_3> <disableProtocols>sslv2,sslv3,tlsv1,tlsv1_1,tlsv1_2,tlsv1_3</disableProtocols> <dhParamsFile>dh.pem</dhParamsFile> <ecdhCurve>prime256v1</ecdhCurve> </server|client> <fips>false</fips> </openSSL> </AppConfig>
Following is a list of supported configuration properties. Property names must always be prefixed with openSSL.server or openSSL.client. Some properties are only supported for servers.
Please see the Context class documentation regarding TLSv1.3 support.
Definition at line 44 of file SSLManager.h.
using Poco::Net::SSLManager::InvalidCertificateHandlerPtr = Poco::SharedPtr<InvalidCertificateHandler> |
Definition at line 161 of file SSLManager.h.
using Poco::Net::SSLManager::PrivateKeyPassphraseHandlerPtr = Poco::SharedPtr<PrivateKeyPassphraseHandler> |
Definition at line 160 of file SSLManager.h.
|
private |
Returns the index for SSL_CTX_set_ex_data() and SSL_CTX_get_ex_data() to store the Context* in the underlying SSL_CTX.
|
private |
Creates the SSLManager.
|
staticprotected |
The return value of this method defines how errors in verification are handled. Return 0 to terminate the handshake, or 1 to continue despite the error.
|
inline |
Returns the private key factory manager which stores the factories for the different registered passphrase handlers for private keys.
Definition at line 374 of file SSLManager.h.
InvalidCertificateHandlerPtr Poco::Net::SSLManager::clientCertificateHandler | ( | ) |
Returns the configured passphrase handler of the client. If none is set, the method will create a default one from an application configuration.
PrivateKeyPassphraseHandlerPtr Poco::Net::SSLManager::clientPassphraseHandler | ( | ) |
Returns an initialized certificate handler (used by the server to verify client cert) which determines how invalid certificates are treated. If none is set, it will try to auto-initialize one from an application configuration.
|
inlineprotected |
Returns the application configuration.
Throws a InvalidStateException if not application instance is available.
Definition at line 402 of file SSLManager.h.
Context::Ptr Poco::Net::SSLManager::defaultClientContext | ( | ) |
Returns the default Context used by the server.
Unless initializeServer() has been called, the first call to this method initializes the default Context from the application configuration.
Context::Ptr Poco::Net::SSLManager::defaultServerContext | ( | ) |
Initializes the client side of the SSLManager with a default passphrase handler, a default invalid certificate handler and a default context. If this method is never called the SSLmanager will try to initialize its members from an application configuration.
PtrPassphraseHandler and ptrCertificateHandler can be 0. However, in this case, event delegates must be registered with the ClientVerificationError and PrivateKeyPassphraseRequired events.
Note: Always create the handlers (or register the corresponding event delegates) before creating the Context, as during creation of the Context the passphrase for the private key might be needed.
Valid initialization code would be: SharedPtr<PrivateKeyPassphraseHandler> pConsoleHandler = new KeyConsoleHandler; SharedPtr<InvalidCertificateHandler> pInvalidCertHandler = new ConsoleCertificateHandler; Context::Ptr pContext = new Context(Context::CLIENT_USE, "", "", "rootcert.pem", Context::VERIFY_RELAXED, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); SSLManager::instance().initializeClient(pConsoleHandler, pInvalidCertHandler, pContext);
|
private |
Inits the passphrase handler.
|
private |
Destroys the SSLManager.
|
private |
Inits the default context, the first time it is accessed.
void Poco::Net::SSLManager::initializeClient | ( | PrivateKeyPassphraseHandlerPtr | ptrPassphraseHandler, |
InvalidCertificateHandlerPtr | ptrHandler, | ||
Context::Ptr | ptrContext ) |
Initializes the server side of the SSLManager with a default passphrase handler, a default invalid certificate handler and a default context. If this method is never called the SSLmanager will try to initialize its members from an application configuration.
PtrPassphraseHandler and ptrCertificateHandler can be 0. However, in this case, event delegates must be registered with the ServerVerificationError and PrivateKeyPassphraseRequired events.
Note: Always create the handlers (or register the corresponding event delegates) before creating the Context, as during creation of the Context the passphrase for the private key might be needed.
Valid initialization code would be: SharedPtr<PrivateKeyPassphraseHandler> pConsoleHandler = new KeyConsoleHandler; SharedPtr<InvalidCertificateHandler> pInvalidCertHandler = new ConsoleCertificateHandler; Context::Ptr pContext = new Context(Context::SERVER_USE, "any.pem", "any.pem", "rootcert.pem", Context::VERIFY_RELAXED, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); SSLManager::instance().initializeServer(pConsoleHandler, pInvalidCertHandler, pContext);
void Poco::Net::SSLManager::initializeServer | ( | PrivateKeyPassphraseHandlerPtr | ptrPassphraseHandler, |
InvalidCertificateHandlerPtr | ptrCertificateHandler, | ||
Context::Ptr | ptrContext ) |
Returns the instance of the SSLManager singleton.
|
private |
Registers delegates at the events according to the configuration.
|
static |
Fired when a encrypted certificate is loaded. Not setting the password in the event parameter will result in a failure to load the certificate.
|
inlinestatic |
Returns the CertificateHandlerFactoryMgr which stores the factories for the different registered certificate handlers.
Definition at line 380 of file SSLManager.h.
|
inline |
Returns an initialized certificate handler (used by the client to verify server cert) which determines how invalid certificates are treated. If none is set, it will try to auto-initialize one from an application configuration.
Definition at line 368 of file SSLManager.h.
|
staticprotected |
The return value of this method defines how errors in verification are handled. Return 0 to terminate the handshake, or 1 to continue despite the error.
InvalidCertificateHandlerPtr Poco::Net::SSLManager::serverCertificateHandler | ( | ) |
Returns the configured passphrase handler of the server. If none is set, the method will create a default one from an application configuration.
PrivateKeyPassphraseHandlerPtr Poco::Net::SSLManager::serverPassphraseHandler | ( | ) |
Returns the default Context used by the client.
Unless initializeClient() has been called, the first call to this method initializes the default Context from the application configuration.
void Poco::Net::SSLManager::shutdown | ( | ) |
|
staticprivate |
Inits the certificate handler.
|
inlinestaticprotected |
|
staticprotected |
Method is invoked by OpenSSL to retrieve a passwd for an encrypted certificate. The request is delegated to the PrivatekeyPassword event. This method returns the length of the password.
|
inlinestaticprotected |
The return value of this method defines how errors in verification are handled. Return 0 to terminate the handshake, or 1 to continue despite the error.
Definition at line 390 of file SSLManager.h.
|
friend |
Definition at line 361 of file SSLManager.h.
|
friend |
Definition at line 353 of file SSLManager.h.
|
private |
Definition at line 315 of file SSLManager.h.
|
private |
Definition at line 322 of file SSLManager.h.
|
private |
The return value of this method defines how errors in verification are handled. Return 0 to terminate the handshake, or 1 to continue despite the error.
Definition at line 314 of file SSLManager.h.
|
private |
Definition at line 323 of file SSLManager.h.
|
private |
Definition at line 321 of file SSLManager.h.
|
private |
Definition at line 320 of file SSLManager.h.
|
private |
Definition at line 319 of file SSLManager.h.
|
private |
Definition at line 316 of file SSLManager.h.
|
private |
Definition at line 318 of file SSLManager.h.
|
private |
Definition at line 317 of file SSLManager.h.
|
staticprivate |
Definition at line 327 of file SSLManager.h.
|
staticprivate |
Definition at line 342 of file SSLManager.h.
|
staticprivate |
Definition at line 326 of file SSLManager.h.
|
staticprivate |
Definition at line 340 of file SSLManager.h.
|
staticprivate |
Definition at line 334 of file SSLManager.h.
|
static |
Definition at line 257 of file SSLManager.h.
|
staticprivate |
Definition at line 335 of file SSLManager.h.
|
staticprivate |
Definition at line 338 of file SSLManager.h.
|
staticprivate |
Definition at line 352 of file SSLManager.h.
|
staticprivate |
Definition at line 351 of file SSLManager.h.
|
staticprivate |
Definition at line 353 of file SSLManager.h.
|
staticprivate |
Definition at line 332 of file SSLManager.h.
|
staticprivate |
Definition at line 346 of file SSLManager.h.
|
staticprivate |
Definition at line 337 of file SSLManager.h.
|
staticprivate |
Definition at line 325 of file SSLManager.h.
|
staticprivate |
Definition at line 347 of file SSLManager.h.
|
staticprivate |
Definition at line 348 of file SSLManager.h.
|
staticprivate |
Definition at line 349 of file SSLManager.h.
|
staticprivate |
Definition at line 350 of file SSLManager.h.
|
static |
Shuts down the SSLManager and releases the default Context objects. After a call to shutdown(), the SSLManager can no longer be used.
Normally, it's not necessary to call this method directly, as this will be called either by uninitializeSSL(), or when the SSLManager instance is destroyed.
Definition at line 256 of file SSLManager.h.
|
staticprivate |
Definition at line 344 of file SSLManager.h.
|
staticprivate |
Definition at line 343 of file SSLManager.h.
|
staticprivate |
Definition at line 345 of file SSLManager.h.
|
staticprivate |
Definition at line 330 of file SSLManager.h.
|
staticprivate |
Definition at line 328 of file SSLManager.h.
Poco::BasicEvent<VerificationErrorArgs> Poco::Net::SSLManager::ClientVerificationError |
Fired whenever a certificate verification error is detected by the server during a handshake.
Definition at line 166 of file SSLManager.h.
Poco::BasicEvent<std::string> Poco::Net::SSLManager::PrivateKeyPassphraseRequired |
Fired whenever a certificate verification error is detected by the client during a handshake.
Definition at line 169 of file SSLManager.h.
Poco::BasicEvent<VerificationErrorArgs> Poco::Net::SSLManager::ServerVerificationError |
Definition at line 163 of file SSLManager.h.
|
staticprivate |
Definition at line 341 of file SSLManager.h.
|
staticprivate |
Definition at line 336 of file SSLManager.h.
|
staticprivate |
Definition at line 339 of file SSLManager.h.
|
staticprivate |
Definition at line 333 of file SSLManager.h.
|
staticprivate |
Definition at line 331 of file SSLManager.h.
|
staticprivate |
Definition at line 329 of file SSLManager.h.