manpagez: man pages & more
man SSL_CTX_set_security_level(3)
Home | html | info | man
SSL_CTX_SET_SECURITY_LEVEL(3ossl)   OpenSSL  SSL_CTX_SET_SECURITY_LEVEL(3ossl)


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 - SSL/TLS
     security framework


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

     The functions SSL_CTX_set_security_level(3) and SSL_set_security_level()
     set the security level to level. If not set the library default security
     level is used.

     The functions SSL_CTX_get_security_level() and SSL_get_security_level()
     retrieve the current security level.

     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 not set a default
     security callback is used. The meaning of the parameters and the
     behaviour of the default callbacks is described below.

     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.


DEFAULT CALLBACK BEHAVIOUR

     If an application doesn't set its own security callback the default
     callback is used. It is intended to provide sane defaults. The meaning of
     each level is described below.

     Level 0
         Everything is permitted. This retains compatibility with previous
         versions of OpenSSL.

     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.


APPLICATION DEFINED SECURITY CALLBACKS

     An application defined security callback is installed with
     SSL_CTX_set_security_callback() or SSL_set_security_callback() and
     replaces the default callback. It is 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.

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

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

     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 not set then 2 is 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.

     By setting an appropriate security level much of this complexity can be
     avoided.

     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.

     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.

     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.


RETURN VALUES

     SSL_CTX_set_security_level(3) and SSL_set_security_level() do not return
     values.

     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)


HISTORY

     These functions were added in OpenSSL 1.1.0.


COPYRIGHT

     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.  You can obtain a copy
     in the file LICENSE in the source distribution or at
     <https://www.openssl.org/source/license.html>.

3.6.5                             2026-09-29 SSL_CTX_SET_SECURITY_LEVEL(3ossl)

openssl 3.6.5 - Generated Sat Oct 3 08:34:16 CDT 2026
© manpagez.com 2000-2026
Individual documents may contain additional copyright information.