SSL_CTX_SET_SECURITY_LEVEL(3SSL)
πΈ SSL_CTX_set_security_level πΈ (from the OpenSSL 3SSL manual)
β¨ NAME β¨
okay bestie, gather round, because this whole pile of functions is the SSL/TLS security framework π :
SSL_CTX_set_security_level,SSL_set_security_levelSSL_CTX_get_security_level,SSL_get_security_levelSSL_CTX_set_security_callback,SSL_set_security_callbackSSL_CTX_get_security_callback,SSL_get_security_callbackSSL_CTX_set0_security_ex_data,SSL_set0_security_ex_dataSSL_CTX_get0_security_ex_data,SSL_get0_security_ex_data
π SYNOPSIS π
literally the whole cast list, typed out exactly so you can copy-paste like the icon you are:
#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, the β¨vibeβ¨ of this page is: you get to tell OpenSSL how much security you want, and OpenSSL says "say less" and enforces it everywhere.
SSL_CTX_set_security_level()andSSL_set_security_level()set the security level tolevel. And if you don't set it? bestie, the library default security level is what you get. no notes. πSSL_CTX_get_security_level()andSSL_get_security_level()hand you back the security level you're currently running.SSL_CTX_set_security_callback(),SSL_set_security_callback(),SSL_CTX_get_security_callback()andSSL_get_security_callback()get or set the security callback attached toctxors. If you never set one, a default security callback is used. what those parameters mean and how the default callbacks behave is all written out below, keep reading π«ΆSSL_CTX_set0_security_ex_data(),SSL_set0_security_ex_data(),SSL_CTX_get0_security_ex_data()andSSL_get0_security_ex_data()set the extra data pointer that gets passed to theexparameter of the callback. this value goes to the callback verbatim β OpenSSL does not peek at it, so set it to literally any application-specific value that's convenient for you. iconic. π
π DEFAULT CALLBACK BEHAVIOUR π
if an application doesn't set its own security callback, the default callback steps in. its whole goal is to give you sane defaults, no cap. and every level means something specific, so here's the tea:
Level 0
Everything is permitted. This retains compatibility with previous versions of OpenSSL. (yes, everything. we're being feral but backwards-compatible π)
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.
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.
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.
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.
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.
bestie these key sizes get big. π₯ we're talking main-character-sized RSA keys, so know what you're signing up for.
π 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 every single time 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. and a rejected parameter is not advertised or used, as appropriate. periodt. π
The callback arguments are:
s,ctxβ TheSSLorSSL_CTXthe check applies to. One of the two isNULL: checks originating from a connection passs(withctxNULL), and checks originating from a context passctx(withsNULL).opβ The operation being checked, one of theSSL_SECOP_*values below.bitsβ The number of bits of security the parameter provides, or0when not meaningful forop.nidβ An identifier whose meaning depends onop, orNID_undefwhen not applicable.otherβ A pointer to the object being checked, whose type depends onopas listed below. It isNULLwhen no object is associated with the operation.exβ The extra data pointer previously set withSSL_CTX_set0_security_ex_data()orSSL_set0_security_ex_data(), orNULL.
Several operations have _SUPPORTED, _SHARED and _CHECK variants, and they are NOT the same thing, okay?
- 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.
The defined operations, and the corresponding type of other, are:
πΈ the operations πΈ
SSL_SECOP_CIPHER_SUPPORTED,SSL_SECOP_CIPHER_SHARED,SSL_SECOP_CIPHER_CHECKβ Advertise/select/accept a TLS cipher suite.otheris theSSL_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.nidis the group andotherpoints 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_MASKis used when building the mask of permitted signature algorithms.nidis its hash andotherpoints to its two byte TLS codepoint.SSL_SECOP_VERSIONβ Negotiate a protocol version.nidis the version, for exampleTLS1_2_VERSION, andotherisNULL.SSL_SECOP_TMP_DHβ Use an ephemeral DH key.otheris theEVP_PKEY.SSL_SECOP_EE_KEY,SSL_SECOP_CA_KEYβ Accept an end entity or CA certificate public key.otheris theX509certificate.SSL_SECOP_TICKET,SSL_SECOP_COMPRESSIONβ Issue or accept a session ticket, or enable record compression.otherisNULL.
π NOTES π
- The default security level can be configured when OpenSSL is compiled by setting
-DOPENSSL_TLS_SECURITY_LEVEL=level. If not set then2is used. - The security framework disables or reject 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. π (the old days were rough, bestie)
- By setting an appropriate security level much of this complexity can be avoided. slay. β¨
- 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
ALLthen only cipher suites consistent with the security level are permissible. - 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.
π« yeah. that's not a typo. that's the price of level 5.
- 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. π
- 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. (check your return values, bestie, i'm begging π₯Ί)
π RETURN VALUES π
SSL_CTX_set_security_level()andSSL_set_security_level()do not return values.SSL_CTX_get_security_level()andSSL_get_security_level()return a integer that represents the security level withSSL_CTXorSSL, respectively.SSL_CTX_set_security_callback()andSSL_set_security_callback()do not return values.SSL_CTX_get_security_callback()andSSL_get_security_callback()return the pointer to the security callback orNULLif the callback is not set.SSL_CTX_get0_security_ex_data()andSSL_get0_security_ex_data()return the extra data pointer orNULLif the ex data is not set.
π SEE ALSO π
β HISTORY β
These functions were added in OpenSSL 1.1.0.
okay that's half the story, bestie, and there's more where that came from πΈ don't go anywhere β
π COPYRIGHT π
Okay bestie, legal era incoming, and honestly? Respect the paperwork. β¨
Copyright 2014-2026 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. Yeah β it's giving "read the terms, queen," no cap. π«Ά
You can grab a copy of the License right here:
- in the file
LICENSEin the source distribution, or - at <https://www.openssl.org/source/license.html> πΈ
Not me being legally obligated to say this, but fr fr: the license is not optional and the vibes are "compliance is the main character." π
And that's a wrap on SSL_CTX_SET_SECURITY_LEVEL(3SSL), bestie β you ate the whole thing. π₯ This one ships as OpenSSL 4.0.3, dated 2026-09-29. Now go set your security levels responsibly, icon. πππ¦
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms