SSL_CTX_SET_SECURITY_LEVEL(3ossl)

πŸ’– SSL_CTX_SET_SECURITY_LEVEL πŸ’–

okay bestie, so this is the manual page for SSL_CTX_SET_SECURITY_LEVEL(3ossl) from the OpenSSL crew, and it's literally the whole SSL/TLS security framework. no cap. it's giving ✨bouncer at the club✨ but for crypto parameters. sit down, get comfy, we're doing this. 🫢


🌸 NAME 🌸

SSL_CTX_set_security_level, SSL_set_security_level, SSL_CTX_get_security_level, SSL_get_security_level, SSL_CTX_set_security_callback, SSL_set_security_callback, SSL_CTX_get_security_callback, SSL_get_security_callback, SSL_CTX_set0_security_ex_data, SSL_set0_security_ex_data, SSL_CTX_get0_security_ex_data, SSL_get0_security_ex_data β€” the SSL/TLS security framework, aka the vibe check for your crypto πŸ’…


✨ SYNOPSIS ✨

#include <openssl/ssl.h>

void SSL_CTX_set_security_level(SSL_CTX *ctx, int level);
void SSL_set_security_level(SSL *s, int level);

int SSL_CTX_get_security_level(const SSL_CTX *ctx);
int SSL_get_security_level(const SSL *s);

void SSL_CTX_set_security_callback(SSL_CTX *ctx,
                                   int (*cb)(const SSL *s, const SSL_CTX *ctx,
                                             int op, int bits, int nid,
                                             void *other, void *ex));

void SSL_set_security_callback(SSL *s,
                               int (*cb)(const SSL *s, const SSL_CTX *ctx,
                                         int op, int bits, int nid,
                                         void *other, void *ex));

int (*SSL_CTX_get_security_callback(const SSL_CTX *ctx))(const SSL *s,
                                                         const SSL_CTX *ctx,
                                                         int op, int bits,
                                                         int nid, void *other,
                                                         void *ex);
int (*SSL_get_security_callback(const SSL *s))(const SSL *s,
                                               const SSL_CTX *ctx, int op,
                                               int bits, int nid, void *other,
                                               void *ex);

void SSL_CTX_set0_security_ex_data(SSL_CTX *ctx, void *ex);
void SSL_set0_security_ex_data(SSL *s, void *ex);

void *SSL_CTX_get0_security_ex_data(const SSL_CTX *ctx);
void *SSL_get0_security_ex_data(const SSL *s);

πŸ¦‹ DESCRIPTION πŸ¦‹

so SSL_CTX_set_security_level() and SSL_set_security_level() set the security level to level. if you don't set it, the library default security level gets used instead. she has a default, she's independent like that. πŸ‘‘

then SSL_CTX_get_security_level() and SSL_get_security_level() retrieve whatever the current security level is. the getters, the gossip queens, they'll tell you everything. πŸ’…

next up: SSL_CTX_set_security_callback(), SSL_set_security_callback(), SSL_CTX_get_security_callback() and SSL_get_security_callback() get or set the security callback that's attached to ctx or s. if you don't set one, a default security callback steps in. the meaning of the parameters and how the default callbacks behave? bestie, that's described below, keep reading. πŸŽ€

and finally, SSL_CTX_set0_security_ex_data(), SSL_set0_security_ex_data(), SSL_CTX_get0_security_ex_data() and SSL_get0_security_ex_data() set the extra data pointer that gets passed to the ex parameter of the callback. this value gets handed to the callback verbatim, no edits, no filter, and you can set it to literally any convenient application specific value you want. it's your little secret to pass along. πŸ™ˆ


🌈 DEFAULT CALLBACK BEHAVIOUR 🌈

if an application doesn't set its own security callback, the default callback is what's used. it's intended to provide sane defaults, and honestly? it ate. the meaning of each level is described below. πŸ’–

Level 0

everything is permitted. absolutely unhinged, no rules, chaos. this retains compatibility with previous versions of OpenSSL. the wild west era. πŸ’€

Level 1

the security level corresponds to a minimum of 80 bits of security. any parameters offering below 80 bits of security are excluded. as a result, RSA, DSA and DH keys shorter than 1024 bits and ECC keys shorter than 160 bits are prohibited. any cipher suite using MD5 for the MAC is also prohibited. any cipher suites using CCM with a 64 bit authentication tag are prohibited. note that signatures using SHA1 and MD5 are also forbidden at this level as they have less than 80 security bits. additionally, SSLv3, TLS 1.0, TLS 1.1 and DTLS 1.0 are all disabled at this level. so many exclusions, it's giving "you're not on the list." 🚫

Level 2

security level set to 112 bits of security. as a result, RSA, DSA and DH keys shorter than 2048 bits and ECC keys shorter than 224 bits are prohibited. in addition to the level 1 exclusions, any cipher suite using RC4 is also prohibited. compression is disabled. RIP compression, you will not be missed. 😭

Level 3

security level set to 128 bits of security. as a result, RSA, DSA and DH keys shorter than 3072 bits and ECC keys shorter than 256 bits are prohibited. in addition to the level 2 exclusions, cipher suites not offering forward secrecy are prohibited. session tickets are disabled. no forward secrecy? not invited. πŸŽ€

Level 4

security level set to 192 bits of security. as a result, RSA, DSA and DH keys shorter than 7680 bits and ECC keys shorter than 384 bits are prohibited. cipher suites using SHA1 for the MAC are prohibited. SHA1, it's over babe. πŸ’…

Level 5

security level set to 256 bits of security. as a result, RSA, DSA and DH keys shorter than 15360 bits and ECC keys shorter than 512 bits are prohibited. this is the final boss level. main character energy only. πŸ‘‘


🧚 APPLICATION DEFINED SECURITY CALLBACKS 🧚

an application defined security callback gets installed with SSL_CTX_set_security_callback() or SSL_set_security_callback(), and it replaces the default callback. it gets consulted whenever the library needs to decide whether an algorithm, key, parameter or protocol version meets the configured security level. it should return 1 to permit the operation and 0 to reject it. a rejected parameter is not advertised or used, as appropriate. it's a yes-or-no girly, no maybe. ✨

the callback arguments are:

s, ctx

the SSL or SSL_CTX the check applies to. one of the two is NULL: checks originating from a connection pass s (with ctx NULL), and checks originating from a context pass ctx (with s NULL). only one shows up to the party at a time. 🫢

op

the operation being checked, one of the SSL_SECOP_* values below.

bits

the number of bits of security the parameter provides, or 0 when it's not meaningful for op.

nid

an identifier whose meaning depends on op, or NID_undef when not applicable.

other

a pointer to the object being checked, whose type depends on op as listed below. it is NULL when no object is associated with the operation.

ex

the extra data pointer previously set with SSL_CTX_set0_security_ex_data() or SSL_set0_security_ex_data(), or NULL.


several operations have _SUPPORTED, _SHARED and _CHECK variants. the supported variant checks a parameter before advertising support for it. the shared variant checks a parameter when selecting from the options offered by both peers. the check variant checks a parameter the peer has selected before accepting it. three stages, three vibes, one framework. πŸ’œ

the defined operations, and the corresponding type of other, are:

  • SSL_SECOP_CIPHER_SUPPORTED, SSL_SECOP_CIPHER_SHARED, SSL_SECOP_CIPHER_CHECK β€” advertise/select/accept a TLS cipher suite. other is the SSL_CIPHER.
  • SSL_SECOP_CURVE_SUPPORTED, SSL_SECOP_CURVE_SHARED, SSL_SECOP_CURVE_CHECK β€” advertise/select/accept a named group used for key exchange, either an elliptic curve or a finite-field DH group. nid is the group and other points to its two byte TLS codepoint.
  • SSL_SECOP_SIGALG_SUPPORTED, SSL_SECOP_SIGALG_SHARED, SSL_SECOP_SIGALG_CHECK, SSL_SECOP_SIGALG_MASK β€” advertise/select/accept a signature algorithm used in the handshake; SSL_SECOP_SIGALG_MASK is used when building the mask of permitted signature algorithms. nid is its hash and other points to its two byte TLS codepoint.
  • SSL_SECOP_VERSION β€” negotiate a protocol version. nid is the version, for example TLS1_2_VERSION, and other is NULL.
  • SSL_SECOP_TMP_DH β€” use an ephemeral DH key. other is the EVP_PKEY.
  • SSL_SECOP_EE_KEY, SSL_SECOP_CA_KEY β€” accept an end entity or CA certificate public key. other is the X509 certificate.
  • SSL_SECOP_TICKET, SSL_SECOP_COMPRESSION β€” issue or accept a session ticket, or enable record compression. other is NULL.

πŸ’€ NOTES πŸ’€

the default security level can be configured when OpenSSL is compiled by setting -DOPENSSL_TLS_SECURITY_LEVEL=level. if it's not set then 2 is used. (yes, level 2 is the factory setting, she comes pre-slayed. πŸ’…)

the security framework disables or rejects parameters inconsistent with the set security level. in the past this was difficult as applications had to set a number of distinct parameters (supported ciphers, supported curves, supported signature algorithms) to achieve this end, and some cases (DH parameter size for example) could not be checked at all. so much manual labour, it was giving unpaid internship. 😭

by setting an appropriate security level, much of this complexity can be avoided. iconic behaviour, honestly. ✨

the bits of security limits affect all relevant parameters including cipher suite encryption algorithms, supported ECC curves, supported signature algorithms, DH parameter sizes, certificate key sizes and signature algorithms. this limit applies no matter what other custom settings an application has set: so if the cipher suite is set to ALL then only cipher suites consistent with the security level are permissible. you can't sneak past the bouncer, bestie. 🚫

see SP800-57 for how the security limits are related to individual algorithms. πŸ“š

some security levels require large key sizes for non-ECC public key algorithms, which can severely degrade performance. for example, 256 bits of security requires the use of RSA keys of at least 15360 bits in size. big keys, big cost, no free lunch. πŸ’Έ

some restrictions can be gracefully handled: for example, cipher suites offering insufficient security are not sent by the client and will not be selected by the server. other restrictions such as the peer certificate key size or the DH parameter size will abort the handshake with a fatal alert. dramatic exits, honestly. πŸ’€

attempts to set certificates or parameters with insufficient security are also blocked. for example, trying to set a certificate using a 512 bit RSA key or a certificate with a signature with SHA1 digest at level 1 using SSL_CTX_use_certificate(). applications which do not check the return values for errors will misbehave: for example it might appear that a certificate is not set at all because it had been rejected. so pls, check your return values, it's literally free. πŸ™ˆ

πŸŽ€ RETURN VALUES πŸŽ€

SSL_CTX_set_security_level() and SSL_set_security_level() do not return values. they're setters, they don't gossip back. πŸ’…

SSL_CTX_get_security_level() and SSL_get_security_level() return a integer that represents the security level with SSL_CTX or SSL, respectively.

SSL_CTX_set_security_callback() and SSL_set_security_callback() do not return values. also silent. mysterious. πŸ¦‹

SSL_CTX_get_security_callback() and SSL_get_security_callback() return the pointer to the security callback, or NULL if the callback is not set. if she's not set, she's NULL, simple as. 🌸

SSL_CTX_get0_security_ex_data() and SSL_get0_security_ex_data() return the extra data pointer, or NULL if the ex data is not set.


πŸ‘‘ SEE ALSO πŸ‘‘

ssl(7)


⭐ HISTORY ⭐

these functions were added in OpenSSL 1.1.0. vintage, but still serving looks. πŸ’–

okay bestie, last section, and it's the legal one so we're being cute but we're being exact πŸ’… no cap:

Copyright 2014-2026 The OpenSSL Project Authors. All Rights Reserved.

that's 2014 through 2026, The OpenSSL Project Authors, and yes, All Rights Reserved. β€” the whole glow-up era of OpenSSL, fr fr 😌


and now the licensing part, which is giving very much "read before you copy" energy, so here it is in the original wording because legalese is NOT the place for a vibe rewrite πŸ™ˆ:

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>.

so like β€” you can't just use this file however you want, you have to actually follow the License, and if you want the receipts they're sitting right there in the LICENSE file in the source distribution, or at that URL up there 🫢 Apache License 2.0 is the vibe, and the vibe is a condition, not a suggestion, iykyk πŸ’€


and that's the whole page, bestie!! πŸŽ€ every last bit of SSL_CTX_SET_SECURITY_LEVEL(3ossl) β€” security levels, callbacks, return values, see alsos, history, and the legal fine print β€” all accounted for ✨

this one shipped as OpenSSL 3.5.9, dated 2026-09-29, and it lives on the page SSL_CTX_SET_SECURITY_LEVEL(3ossl) πŸ‘‘

go forth and configure your security levels responsibly, queen πŸ‘‘πŸ’–

πŸ“¦ where this page comes from