SSL_CTX_SET_SECURITY_LEVEL(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… SSL_CTX_SET_SECURITY_LEVEL β€” the OpenSSL security framework, but make it make sense

okay so bestie, this is a page from 3ossl (that's the OpenSSL manual section, slay) and it's literally all about the SSL/TLS security framework. no cap, it's kind of a lot, but we're gonna get through it together 🫢


✨ 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 whole SSL/TLS security framework, like the entire vibe check for how much crypto security you're demanding πŸ‘‘


🌸 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)(SSL *s, SSL_CTX *ctx, int op,
                                             int bits, int nid,
                                             void *other, void *ex));

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

int (*SSL_CTX_get_security_callback(const SSL_CTX *ctx))(SSL *s, SSL_CTX *ctx, int op,
                                                         int bits, int nid, void *other,
                                                         void *ex);
int (*SSL_get_security_callback(const SSL *s))(SSL *s, 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);

like, yes, those callback getter signatures are giving "pointer to function returning pointer to function" and honestly? iconic but unhinged πŸ’€


πŸ¦‹ DESCRIPTION πŸ¦‹

first up, the levels:

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 is used. easy ✨

SSL_CTX_get_security_level() and SSL_get_security_level() retrieve the current security level. just a lil peek at what you've got going on πŸ”

next, the callbacks:

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 associated with ctx or s. if you don't set one, a default security callback is used. the meaning of the parameters and the behaviour of the default callbacks is described below πŸ‘‡

and finally, the ex data:

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 passed to the ex parameter of the callback. this value is passed to the callback verbatim and can be set to any convenient application specific value. so like, your bag of whatever, hand it over, nobody's judging πŸŽ€


πŸ’– DEFAULT CALLBACK BEHAVIOUR πŸ’–

if an application doesn't set its own security callback, the default callback is used. it's intended to provide sane defaults. the meaning of each level is described below β€” buckle up bestie, we're going 0 to 5 πŸ’…

Level 0

literally everything is permitted. this retains compatibility with previous versions of OpenSSL. the "we're all friends here" level πŸ•ŠοΈ

Level 1

the security level corresponds to a minimum of 80 bits of security. any parameters offering below 80 bits of security are excluded. so 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. like, all of them. gone 🫑

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. no more zip, we're being serious now 😀

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. forward secrecy or bust, periodt πŸ”₯

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 really said "my time is up" πŸ’€

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 maximum security main character energy, your keys are HUGE πŸ‘‘


🧚 APPLICATION DEFINED SECURITY CALLBACKS 🧚

Documentation to be provided.

(no fr, that's literally what it says. the docs are… forthcoming. we love a mystery 🫢)


🌈 NOTES 🌈

the default security level can be configured when OpenSSL is compiled by setting -DOPENSSL_TLS_SECURITY_LEVEL=level. if not set then 2 is used. so level 2 is the factory setting, iykyk ⭐

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. like, imagine doing all that manually. couldn't be us πŸ™ˆ

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 ALL then only cipher suites consistent with the security level are permissible. yes, even ALL gets filtered. the security level is the final boss πŸ”₯

see SP800-57 for how the security limits are related to individual algorithms. homework, but make it NIST πŸŽ€

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. bestie that's not a key, that's a whole apartment building 😭 your CPU will feel it.

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. so some stuff gets quietly ghosted, other stuff gets a dramatic exit πŸ’€

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.

⚠️ real talk: check your return values!! if you don't, your cert might look like it just… isn't there, when actually it got rejected for being too weak. gaslighting, honestly πŸ™ˆ

⭐ RETURN VALUES ⭐

  • SSL_CTX_set_security_level() and SSL_set_security_level() do not return values. they're setters, they just vibe.
  • 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.
  • 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.
  • 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) β€” go read it, bestie, it's the whole ecosystem πŸ’œ


πŸ‘‘ HISTORY πŸ‘‘

these functions were added in OpenSSL 1.1.0. vintage but not ancient ✨


Copyright 2014-2020 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 page!! this was version 3.5.0, dated 2026-09-25, from the SSL_CTX_SET_SECURITY_LEVEL(3ossl) manual β€” mwah, go forth and set your security levels responsibly πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from