xref: /freebsd/crypto/openssl/doc/man3/SSL_CTX_set_security_level.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimSSL_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
6e71b7053SJung-uk Kim
7e71b7053SJung-uk Kim=head1 SYNOPSIS
8e71b7053SJung-uk Kim
9e71b7053SJung-uk Kim #include <openssl/ssl.h>
10e71b7053SJung-uk Kim
11e71b7053SJung-uk Kim void SSL_CTX_set_security_level(SSL_CTX *ctx, int level);
12e71b7053SJung-uk Kim void SSL_set_security_level(SSL *s, int level);
13e71b7053SJung-uk Kim
14e71b7053SJung-uk Kim int SSL_CTX_get_security_level(const SSL_CTX *ctx);
15e71b7053SJung-uk Kim int SSL_get_security_level(const SSL *s);
16e71b7053SJung-uk Kim
17e71b7053SJung-uk Kim void SSL_CTX_set_security_callback(SSL_CTX *ctx,
18e71b7053SJung-uk Kim                                    int (*cb)(SSL *s, SSL_CTX *ctx, int op,
19e71b7053SJung-uk Kim                                              int bits, int nid,
20e71b7053SJung-uk Kim                                              void *other, void *ex));
21e71b7053SJung-uk Kim
22e71b7053SJung-uk Kim void SSL_set_security_callback(SSL *s, int (*cb)(SSL *s, SSL_CTX *ctx, int op,
23e71b7053SJung-uk Kim                                                  int bits, int nid,
24e71b7053SJung-uk Kim                                                  void *other, void *ex));
25e71b7053SJung-uk Kim
26e71b7053SJung-uk Kim int (*SSL_CTX_get_security_callback(const SSL_CTX *ctx))(SSL *s, SSL_CTX *ctx, int op,
27e71b7053SJung-uk Kim                                                          int bits, int nid, void *other,
28e71b7053SJung-uk Kim                                                          void *ex);
29e71b7053SJung-uk Kim int (*SSL_get_security_callback(const SSL *s))(SSL *s, SSL_CTX *ctx, int op,
30e71b7053SJung-uk Kim                                                int bits, int nid, void *other,
31e71b7053SJung-uk Kim                                                void *ex);
32e71b7053SJung-uk Kim
33e71b7053SJung-uk Kim void SSL_CTX_set0_security_ex_data(SSL_CTX *ctx, void *ex);
34e71b7053SJung-uk Kim void SSL_set0_security_ex_data(SSL *s, void *ex);
35e71b7053SJung-uk Kim
36e71b7053SJung-uk Kim void *SSL_CTX_get0_security_ex_data(const SSL_CTX *ctx);
37e71b7053SJung-uk Kim void *SSL_get0_security_ex_data(const SSL *s);
38e71b7053SJung-uk Kim
39e71b7053SJung-uk Kim=head1 DESCRIPTION
40e71b7053SJung-uk Kim
41e71b7053SJung-uk KimThe functions SSL_CTX_set_security_level() and SSL_set_security_level() set
42e71b7053SJung-uk Kimthe security level to B<level>. If not set the library default security level
43e71b7053SJung-uk Kimis used.
44e71b7053SJung-uk Kim
45e71b7053SJung-uk KimThe functions SSL_CTX_get_security_level() and SSL_get_security_level()
46e71b7053SJung-uk Kimretrieve the current security level.
47e71b7053SJung-uk Kim
48e71b7053SJung-uk KimSSL_CTX_set_security_callback(), SSL_set_security_callback(),
49e71b7053SJung-uk KimSSL_CTX_get_security_callback() and SSL_get_security_callback() get or set
50e71b7053SJung-uk Kimthe security callback associated with B<ctx> or B<s>. If not set a default
51e71b7053SJung-uk Kimsecurity callback is used. The meaning of the parameters and the behaviour
52e71b7053SJung-uk Kimof the default callbacks is described below.
53e71b7053SJung-uk Kim
54e71b7053SJung-uk KimSSL_CTX_set0_security_ex_data(), SSL_set0_security_ex_data(),
55e71b7053SJung-uk KimSSL_CTX_get0_security_ex_data() and SSL_get0_security_ex_data() set the
56e71b7053SJung-uk Kimextra data pointer passed to the B<ex> parameter of the callback. This
57e71b7053SJung-uk Kimvalue is passed to the callback verbatim and can be set to any convenient
58e71b7053SJung-uk Kimapplication specific value.
59e71b7053SJung-uk Kim
60e71b7053SJung-uk Kim=head1 DEFAULT CALLBACK BEHAVIOUR
61e71b7053SJung-uk Kim
62e71b7053SJung-uk KimIf an application doesn't set its own security callback the default
63e71b7053SJung-uk Kimcallback is used. It is intended to provide sane defaults. The meaning
64e71b7053SJung-uk Kimof each level is described below.
65e71b7053SJung-uk Kim
66e71b7053SJung-uk Kim=over 4
67e71b7053SJung-uk Kim
68e71b7053SJung-uk Kim=item B<Level 0>
69e71b7053SJung-uk Kim
70e71b7053SJung-uk KimEverything is permitted. This retains compatibility with previous versions of
71e71b7053SJung-uk KimOpenSSL.
72e71b7053SJung-uk Kim
73e71b7053SJung-uk Kim=item B<Level 1>
74e71b7053SJung-uk Kim
75e71b7053SJung-uk KimThe security level corresponds to a minimum of 80 bits of security. Any
76e71b7053SJung-uk Kimparameters offering below 80 bits of security are excluded. As a result RSA,
77e71b7053SJung-uk KimDSA and DH keys shorter than 1024 bits and ECC keys shorter than 160 bits
78e71b7053SJung-uk Kimare prohibited. All export cipher suites are prohibited since they all offer
79e71b7053SJung-uk Kimless than 80 bits of security. SSL version 2 is prohibited. Any cipher suite
80*b077aed3SPierre Proncheryusing MD5 for the MAC is also prohibited. Note that signatures using SHA1
81*b077aed3SPierre Proncheryand MD5 are also forbidden at this level as they have less than 80 security
82*b077aed3SPierre Proncherybits.
83e71b7053SJung-uk Kim
84e71b7053SJung-uk Kim=item B<Level 2>
85e71b7053SJung-uk Kim
86e71b7053SJung-uk KimSecurity level set to 112 bits of security. As a result RSA, DSA and DH keys
87e71b7053SJung-uk Kimshorter than 2048 bits and ECC keys shorter than 224 bits are prohibited.
88e71b7053SJung-uk KimIn addition to the level 1 exclusions any cipher suite using RC4 is also
89e71b7053SJung-uk Kimprohibited. SSL version 3 is also not allowed. Compression is disabled.
90e71b7053SJung-uk Kim
91e71b7053SJung-uk Kim=item B<Level 3>
92e71b7053SJung-uk Kim
93e71b7053SJung-uk KimSecurity level set to 128 bits of security. As a result RSA, DSA and DH keys
94e71b7053SJung-uk Kimshorter than 3072 bits and ECC keys shorter than 256 bits are prohibited.
95e71b7053SJung-uk KimIn addition to the level 2 exclusions cipher suites not offering forward
96e71b7053SJung-uk Kimsecrecy are prohibited. TLS versions below 1.1 are not permitted. Session
97e71b7053SJung-uk Kimtickets are disabled.
98e71b7053SJung-uk Kim
99e71b7053SJung-uk Kim=item B<Level 4>
100e71b7053SJung-uk Kim
101e71b7053SJung-uk KimSecurity level set to 192 bits of security. As a result RSA, DSA and
102e71b7053SJung-uk KimDH keys shorter than 7680 bits and ECC keys shorter than 384 bits are
103e71b7053SJung-uk Kimprohibited.  Cipher suites using SHA1 for the MAC are prohibited. TLS
104e71b7053SJung-uk Kimversions below 1.2 are not permitted.
105e71b7053SJung-uk Kim
106e71b7053SJung-uk Kim=item B<Level 5>
107e71b7053SJung-uk Kim
108e71b7053SJung-uk KimSecurity level set to 256 bits of security. As a result RSA, DSA and DH keys
109e71b7053SJung-uk Kimshorter than 15360 bits and ECC keys shorter than 512 bits are prohibited.
110e71b7053SJung-uk Kim
111e71b7053SJung-uk Kim=back
112e71b7053SJung-uk Kim
113e71b7053SJung-uk Kim=head1 APPLICATION DEFINED SECURITY CALLBACKS
114e71b7053SJung-uk Kim
115e71b7053SJung-uk KimI<Documentation to be provided.>
116e71b7053SJung-uk Kim
117e71b7053SJung-uk Kim=head1 NOTES
118e71b7053SJung-uk Kim
119e71b7053SJung-uk KimThe default security level can be configured when OpenSSL is compiled by
120e71b7053SJung-uk Kimsetting B<-DOPENSSL_TLS_SECURITY_LEVEL=level>. If not set then 1 is used.
121e71b7053SJung-uk Kim
122e71b7053SJung-uk KimThe security framework disables or reject parameters inconsistent with the
123e71b7053SJung-uk Kimset security level. In the past this was difficult as applications had to set
124e71b7053SJung-uk Kima number of distinct parameters (supported ciphers, supported curves supported
125e71b7053SJung-uk Kimsignature algorithms) to achieve this end and some cases (DH parameter size
126e71b7053SJung-uk Kimfor example) could not be checked at all.
127e71b7053SJung-uk Kim
128e71b7053SJung-uk KimBy setting an appropriate security level much of this complexity can be
129e71b7053SJung-uk Kimavoided.
130e71b7053SJung-uk Kim
131e71b7053SJung-uk KimThe bits of security limits affect all relevant parameters including
132e71b7053SJung-uk Kimcipher suite encryption algorithms, supported ECC curves, supported
133e71b7053SJung-uk Kimsignature algorithms, DH parameter sizes, certificate key sizes and
134e71b7053SJung-uk Kimsignature algorithms. This limit applies no matter what other custom
135e71b7053SJung-uk Kimsettings an application has set: so if the cipher suite is set to B<ALL>
136e71b7053SJung-uk Kimthen only cipher suites consistent with the security level are permissible.
137e71b7053SJung-uk Kim
138e71b7053SJung-uk KimSee SP800-57 for how the security limits are related to individual
139e71b7053SJung-uk Kimalgorithms.
140e71b7053SJung-uk Kim
141e71b7053SJung-uk KimSome security levels require large key sizes for non-ECC public key
142e71b7053SJung-uk Kimalgorithms which can severely degrade performance. For example 256 bits
143e71b7053SJung-uk Kimof security requires the use of RSA keys of at least 15360 bits in size.
144e71b7053SJung-uk Kim
145e71b7053SJung-uk KimSome restrictions can be gracefully handled: for example cipher suites
146e71b7053SJung-uk Kimoffering insufficient security are not sent by the client and will not
147e71b7053SJung-uk Kimbe selected by the server. Other restrictions such as the peer certificate
148e71b7053SJung-uk Kimkey size or the DH parameter size will abort the handshake with a fatal
149e71b7053SJung-uk Kimalert.
150e71b7053SJung-uk Kim
151e71b7053SJung-uk KimAttempts to set certificates or parameters with insufficient security are
152*b077aed3SPierre Proncheryalso blocked. For example trying to set a certificate using a 512 bit RSA key
153*b077aed3SPierre Proncheryor a certificate with a signature with SHA1 digest at level 1 using
154*b077aed3SPierre ProncherySSL_CTX_use_certificate(). Applications which do not check the return values
155*b077aed3SPierre Proncheryfor errors will misbehave: for example it might appear that a certificate is
156*b077aed3SPierre Proncherynot set at all because it had been rejected.
157e71b7053SJung-uk Kim
158e71b7053SJung-uk Kim=head1 RETURN VALUES
159e71b7053SJung-uk Kim
160e71b7053SJung-uk KimSSL_CTX_set_security_level() and SSL_set_security_level() do not return values.
161e71b7053SJung-uk Kim
162e71b7053SJung-uk KimSSL_CTX_get_security_level() and SSL_get_security_level() return a integer that
163e71b7053SJung-uk Kimrepresents the security level with B<SSL_CTX> or B<SSL>, respectively.
164e71b7053SJung-uk Kim
165e71b7053SJung-uk KimSSL_CTX_set_security_callback() and SSL_set_security_callback() do not return
166e71b7053SJung-uk Kimvalues.
167e71b7053SJung-uk Kim
168e71b7053SJung-uk KimSSL_CTX_get_security_callback() and SSL_get_security_callback() return the pointer
169e71b7053SJung-uk Kimto the security callback or NULL if the callback is not set.
170e71b7053SJung-uk Kim
171e71b7053SJung-uk KimSSL_CTX_get0_security_ex_data() and SSL_get0_security_ex_data() return the extra
172e71b7053SJung-uk Kimdata pointer or NULL if the ex data is not set.
173e71b7053SJung-uk Kim
174*b077aed3SPierre Pronchery=head1 SEE ALSO
175*b077aed3SPierre Pronchery
176*b077aed3SPierre ProncheryL<ssl(7)>
177*b077aed3SPierre Pronchery
178e71b7053SJung-uk Kim=head1 HISTORY
179e71b7053SJung-uk Kim
1806935a639SJung-uk KimThese functions were added in OpenSSL 1.1.0.
181e71b7053SJung-uk Kim
182e71b7053SJung-uk Kim=head1 COPYRIGHT
183e71b7053SJung-uk Kim
184*b077aed3SPierre ProncheryCopyright 2014-2021 The OpenSSL Project Authors. All Rights Reserved.
185e71b7053SJung-uk Kim
186*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
187e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
188e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
189e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
190e71b7053SJung-uk Kim
191e71b7053SJung-uk Kim=cut
192