SSL_CTX_NEW(3SSL)
π SSL_CTX_NEW β OpenSSL's "make me a context" era β¨
Okay bestie, this one's from OpenSSL (the 3SSL corner of the manpage universe), and it's literally the page that tells you how to spin up an SSL_CTX object β the whole framework vibe for TLS/SSL and DTLS stuff. Grab a strawberry drink, we're going in π
πΈ NAME πΈ
So these are all the little functions that live on this page β think of it as one big friend group π«Ά
- Context creators + refcounting:
SSL_CTX_new_ex,SSL_CTX_new,SSL_CTX_up_ref - The version-flexible TLS squad:
TLS_method,TLS_server_method,TLS_client_method - The legacy-rename girlies:
SSLv23_method,SSLv23_server_method,SSLv23_client_method - SSLv3 (yes, the deprecated one π):
SSLv3_method,SSLv3_server_method,SSLv3_client_method - TLSv1 crew:
TLSv1_method,TLSv1_server_method,TLSv1_client_method - TLSv1.1 crew:
TLSv1_1_method,TLSv1_1_server_method,TLSv1_1_client_method - TLSv1.2 crew:
TLSv1_2_method,TLSv1_2_server_method,TLSv1_2_client_method - The version-flexible DTLS squad:
DTLS_method,DTLS_server_method,DTLS_client_method - DTLSv1 crew:
DTLSv1_method,DTLSv1_server_method,DTLSv1_client_method - DTLSv1.2 crew:
DTLSv1_2_method,DTLSv1_2_server_method,DTLSv1_2_client_method
And what do they all do? They create a new SSL_CTX object as framework for TLS/SSL or DTLS enabled functions. That's the whole assignment, no cap π
β¨ SYNOPSIS β¨
Here's the exact code, character for character, don't touch a thing:
#include <openssl/ssl.h>
SSL_CTX *SSL_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq,
const SSL_METHOD *method);
SSL_CTX *SSL_CTX_new(const SSL_METHOD *method);
int SSL_CTX_up_ref(SSL_CTX *ctx);
const SSL_METHOD *TLS_method(void);
const SSL_METHOD *TLS_server_method(void);
const SSL_METHOD *TLS_client_method(void);
const SSL_METHOD *SSLv23_method(void);
const SSL_METHOD *SSLv23_server_method(void);
const SSL_METHOD *SSLv23_client_method(void);
#ifndef OPENSSL_NO_SSL3_METHOD
const SSL_METHOD *SSLv3_method(void);
const SSL_METHOD *SSLv3_server_method(void);
const SSL_METHOD *SSLv3_client_method(void);
#endif
#ifndef OPENSSL_NO_TLS1_METHOD
const SSL_METHOD *TLSv1_method(void);
const SSL_METHOD *TLSv1_server_method(void);
const SSL_METHOD *TLSv1_client_method(void);
#endif
#ifndef OPENSSL_NO_TLS1_1_METHOD
const SSL_METHOD *TLSv1_1_method(void);
const SSL_METHOD *TLSv1_1_server_method(void);
const SSL_METHOD *TLSv1_1_client_method(void);
#endif
#ifndef OPENSSL_NO_TLS1_2_METHOD
const SSL_METHOD *TLSv1_2_method(void);
const SSL_METHOD *TLSv1_2_server_method(void);
const SSL_METHOD *TLSv1_2_client_method(void);
#endif
const SSL_METHOD *DTLS_method(void);
const SSL_METHOD *DTLS_server_method(void);
const SSL_METHOD *DTLS_client_method(void);
#ifndef OPENSSL_NO_DTLS1_METHOD
const SSL_METHOD *DTLSv1_method(void);
const SSL_METHOD *DTLSv1_server_method(void);
const SSL_METHOD *DTLSv1_client_method(void);
#endif
#ifndef OPENSSL_NO_DTLS1_2_METHOD
const SSL_METHOD *DTLSv1_2_method(void);
const SSL_METHOD *DTLSv1_2_server_method(void);
const SSL_METHOD *DTLSv1_2_client_method(void);
#endif
π¦ DESCRIPTION π¦
So SSL_CTX_new_ex() is the main character here β it creates a new SSL_CTX object, which holds all the configuration and data relevant to SSL/TLS or DTLS session establishment. Later on, an SSL object (the one representing an actual active session) inherits all of that. Passing down the family traits, iconic π
The method parameter is the "who is this for" β it says whether the context is for the client side, the server side, or both. Deets live down in NOTES.
The library context libctx (peep OSSL_LIB_CTX(3)) is what provides the cryptographic algorithms needed for the session. Any crypto algorithms used by any SSL objects created from this SSL_CTX get fetched from that libctx using the property query string propq β see "ALGORITHM FETCHING" in crypto(7). And good news: either or both of the libctx or propq parameters can be NULL π
SSL_CTX_new() does literally the same as SSL_CTX_new_ex() except it uses the default library context and specifies no property query string. Simple, lowkey, no notes.
Now β the reference counting moment, pay attention bestie π An SSL_CTX object is reference counted:
- Creating one for the first time increments the reference count.
- Freeing it (with
SSL_CTX_free) decrements it. - When the reference count drops to zero, any memory or resources allocated to that
SSL_CTXobject get freed. SSL_CTX_up_ref()increments the reference count for an existingSSL_CTXstructure.
β οΈ Important vibe check: anSSL_CTXobject should not be changed after it's been used to create anySSLobjects, or from multiple threads concurrently β because the implementation does not provide serialization of access for these cases. Don't be that girl π
π₯ NOTES π₯
On session establishment, by default, no peer credentials verification is done. You have to explicitly ask for it, typically with SSL_CTX_set_verify(3). For verifying peer certificates there's a whole toolbox of options via functions like SSL_CTX_load_verify_locations(3) and SSL_CTX_set1_param(3) β¨
The SSL/(D)TLS implementation uses X509_STORE_CTX_set_default(3) to prepare checks for X509_PURPOSE_SSL_SERVER on the client side and X509_PURPOSE_SSL_CLIENT on the server side. If you wanna override the default purpose of the session, use X509_VERIFY_PARAM_set_purpose(3) β and you can pair it with SSL_CTX_get0_param(3) to do that πΈ
The SSL_CTX object uses method as the connection method. Three variants exist: a generic method (client or server use), a server-only method, and a client-only method.
The method parameter of SSL_CTX_new_ex() and SSL_CTX_new() can be one of these:
TLS_method(), TLS_server_method(), TLS_client_method()
These are the general-purpose, version-flexible SSL/TLS methods π The actual protocol version used gets negotiated up to the highest version mutually supported by client and server. Supported protocols: SSLv3, TLSv1, TLSv1.1, TLSv1.2 and TLSv1.3. Applications should use these methods and avoid the version-specific ones below β those are deprecated, periodt.
SSLv23_method(), SSLv23_server_method(), SSLv23_client_method()
Bestie these functions do not exist anymore π they've been renamed to TLS_method(), TLS_server_method() and TLS_client_method() respectively. Right now, the old function calls get renamed to the corresponding new ones by preprocessor macros, so existing code using the old names still compiles. But using the old names is deprecated and new code should call the new functions instead. Move on, we've grown π
TLSv1_2_method(), TLSv1_2_server_method(), TLSv1_2_client_method()
A TLS/SSL connection established with these methods will only understand the TLSv1.2 protocol. These methods are deprecated.
TLSv1_1_method(), TLSv1_1_server_method(), TLSv1_1_client_method()
A TLS/SSL connection established with these methods will only understand the TLSv1.1 protocol. These methods are deprecated.
TLSv1_method(), TLSv1_server_method(), TLSv1_client_method()
A TLS/SSL connection established with these methods will only understand the TLSv1 protocol. These methods are deprecated.
SSLv3_method(), SSLv3_server_method(), SSLv3_client_method()
A TLS/SSL connection established with these methods will only understand the SSLv3 protocol. The SSLv3 protocol is deprecated and should not be used. π«
DTLS_method(), DTLS_server_method(), DTLS_client_method()
These are the version-flexible DTLS methods π¦ Currently supported protocols are DTLS 1.0 and DTLS 1.2.
DTLSv1_2_method(), DTLSv1_2_server_method(), DTLSv1_2_client_method()
These are the version-specific methods for DTLSv1.2. These methods are deprecated.
DTLSv1_method(), DTLSv1_server_method(), DTLSv1_client_method()
These are the version-specific methods for DTLSv1. These methods are deprecated.
SSL_CTX_new() initializes the list of ciphers, the session cache setting, the callbacks, the keys and certificates, and the options β all to their default values. Fresh start, clean slate β¨
TLS_method(), TLS_server_method(), TLS_client_method(), DTLS_method(), DTLS_server_method() and DTLS_client_method() are the version-flexible methods. Every other method only supports one specific protocol version. So use the version-flexible ones instead of the version-specific ones, iykyk π
If you wanna limit the supported protocols for the version-flexible methods, you can use SSL_CTX_set_min_proto_version(3), SSL_set_min_proto_version(3), SSL_CTX_set_max_proto_version(3) and SSL_set_max_proto_version(3). With these you could, for example, pick TLS_server_method() and still negotiate with all possible clients, but only allow newer protocols like TLS 1.0, TLS 1.1, TLS 1.2 or TLS 1.3. Chef's kiss π
You can also limit the list of available protocols using the SSL_OP_NO_SSLv3, SSL_OP_NO_TLSv1, SSL_OP_NO_TLSv1_1, SSL_OP_NO_TLSv1_3, SSL_OP_NO_TLSv1_2 and SSL_OP_NO_TLSv1_3 options of the SSL_CTX_set_options(3) or SSL_set_options(3) functions β but this approach is not recommended π Clients should avoid creating "holes" in the set of protocols they support. When disabling a protocol, make sure you also disable either all previous or all subsequent protocol versions. And in clients: when a protocol version is disabled without disabling all previous protocol versions, the effect is to also disable all subsequent protocol versions. The way this works is a little unhinged but okay π
The SSLv3 protocol is deprecated and should generally not be used. Applications should typically use SSL_CTX_set_min_proto_version(3) to set the minimum protocol to at least TLS1_VERSION.
β RETURN VALUES β
Here's what you might get back:
NULLβ the creation of a newSSL_CTXobject failed π Check the error stack to find out the reason.- Pointer to an
SSL_CTXobject β the return value points to an allocatedSSL_CTXobject. Slay.
And separately: SSL_CTX_up_ref() returns 1 for success and 0 for failure.
π SEE ALSO π
Go read these next, bestie, they're all linked up:
SSL_CTX_set_options(3), SSL_CTX_free(3), X509_STORE_CTX_set_default(3), SSL_CTX_set_verify(3), SSL_CTX_set1_param(3), SSL_CTX_get0_param(3), SSL_connect(3), SSL_accept(3), SSL_CTX_set_min_proto_version(3), ssl(7), SSL_set_connect_state(3)
π§ HISTORY π§
A little lore for you:
- Support for SSLv2 and the corresponding
SSLv2_method(),SSLv2_server_method()andSSLv2_client_method()functions where removed in OpenSSL 1.1.0. (Yes, "where" β that's the original wording, we don't fix, we preserve π ) SSLv23_method(),SSLv23_server_method()andSSLv23_client_method()were deprecated, and the preferredTLS_method(),TLS_server_method()andTLS_client_method()functions were added in OpenSSL 1.1.0.- All version-specific methods were deprecated in OpenSSL 1.1.0.
SSL_CTX_new_ex()was added in OpenSSL 3.0. Queen behavior π
π COPYRIGHT π
Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
And that's the whole page, bestie!! π This was 3.5.7, dated 2026-06-09, and it's the SSL_CTX_NEW(3SSL) page β go forth and make your contexts responsibly β¨π¦π
π¦ where this page comes from
- debian trixie: libssl-doc 3.5.7-1~deb13u2 Β· Apache-2.0
- debian trixie: libssl-doc 3.5.7-1~deb13u3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms