]> git.ipfire.org Git - thirdparty/openssl.git/blob - doc/man3/SSL_CTX_set_tmp_dh_callback.pod
Update copyright year
[thirdparty/openssl.git] / doc / man3 / SSL_CTX_set_tmp_dh_callback.pod
1 =pod
2
3 =head1 NAME
4
5 SSL_CTX_set_dh_auto, SSL_set_dh_auto, SSL_CTX_set0_tmp_dh_pkey,
6 SSL_set0_tmp_dh_pkey, SSL_CTX_set_tmp_dh_callback, SSL_CTX_set_tmp_dh,
7 SSL_set_tmp_dh_callback, SSL_set_tmp_dh
8 - handle DH keys for ephemeral key exchange
9
10 =head1 SYNOPSIS
11
12 #include <openssl/ssl.h>
13
14 long SSL_CTX_set_dh_auto(SSL_CTX *ctx, int onoff);
15 long SSL_set_dh_auto(SSL *s, int onoff);
16 int SSL_CTX_set0_tmp_dh_pkey(SSL_CTX *ctx, EVP_PKEY *dhpkey);
17 int SSL_set0_tmp_dh_pkey(SSL *s, EVP_PKEY *dhpkey);
18
19 The following functions have been deprecated since OpenSSL 3.0, and can be
20 hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
21 see L<openssl_user_macros(7)>:
22
23 void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
24 DH *(*tmp_dh_callback)(SSL *ssl, int is_export,
25 int keylength));
26 long SSL_CTX_set_tmp_dh(SSL_CTX *ctx, DH *dh);
27
28 void SSL_set_tmp_dh_callback(SSL *ctx,
29 DH *(*tmp_dh_callback)(SSL *ssl, int is_export,
30 int keylength));
31 long SSL_set_tmp_dh(SSL *ssl, DH *dh);
32
33 =head1 DESCRIPTION
34
35 The functions described on this page are relevant for servers only.
36
37 Some ciphersuites may use ephemeral Diffie-Hellman (DH) key exchange. In these
38 cases, the session data is negotiated using the ephemeral/temporary DH key and
39 the key supplied and certified by the certificate chain is only used for
40 signing. Anonymous ciphers (without a permanent server key) also use ephemeral
41 DH keys.
42
43 Using ephemeral DH key exchange yields forward secrecy as the connection
44 can only be decrypted when the DH key is known. By generating a temporary
45 DH key inside the server application that is lost when the application
46 is left, it becomes impossible for an attacker to decrypt past sessions,
47 even if they get hold of the normal (certified) key, as this key was
48 only used for signing.
49
50 In order to perform a DH key exchange the server must use a DH group
51 (DH parameters) and generate a DH key. The server will always generate
52 a new DH key during the negotiation.
53
54 As generating DH parameters is extremely time consuming, an application
55 should not generate the parameters on the fly. DH parameters can be reused, as
56 the actual key is newly generated during the negotiation.
57
58 Typically applications should use well know DH parameters that have built-in
59 support in OpenSSL. The macros SSL_CTX_set_dh_auto() and SSL_set_dh_auto()
60 configure OpenSSL to use the default built-in DH parameters for the B<SSL_CTX>
61 and B<SSL> objects respectively. Passing a value of 1 in the I<onoff> parameter
62 switches the feature on, and passing a value of 0 switches it off. The default
63 setting is off.
64
65 If "auto" DH parameters are switched on then the parameters will be selected to
66 be consistent with the size of the key associated with the server's certificate.
67 If there is no certificate (e.g. for PSK ciphersuites), then it it will be
68 consistent with the size of the negotiated symmetric cipher key.
69
70 Applications may supply their own DH parameters instead of using the built-in
71 values. This approach is discouraged and applications should in preference use
72 the built-in parameter support described above. Applications wishing to supply
73 their own DH parameters should call SSL_CTX_set0_tmp_dh_pkey() or
74 SSL_set0_tmp_dh_pkey() to supply the parameters for the B<SSL_CTX> or B<SSL>
75 respectively. The parameters should be supplied in the I<dhpkey> argument as
76 an B<EVP_PKEY> containing DH parameters. Ownership of the I<dhpkey> value is
77 passed to the B<SSL_CTX> or B<SSL> object as a result of this call, and so the
78 caller should not free it if the function call is successful.
79
80 The deprecated macros SSL_CTX_set_tmp_dh() and SSL_set_tmp_dh() do the same
81 thing as SSL_CTX_set0_tmp_dh_pkey() and SSL_set0_tmp_dh_pkey() except that the
82 DH parameters are supplied in a B<DH> object instead in the I<dh> argument, and
83 ownership of the B<DH> object is retained by the application. Applications
84 should use "auto" parameters instead, or call SSL_CTX_set0_tmp_dh_pkey() or
85 SSL_set0_tmp_dh_pkey() as appropriate.
86
87 An application may instead specify the DH parameters via a callback function
88 using the functions SSL_CTX_set_tmp_dh_callback() or SSL_set_tmp_dh_callback()
89 to set the callback for the B<SSL_CTX> or B<SSL> object respectively. These
90 functions are deprecated. Applications should instead use "auto" parameters, or
91 specify the parameters via SSL_CTX_set0_tmp_dh_pkey() or SSL_set0_tmp_dh_pkey()
92 as appropriate.
93
94 The callback will be invoked during a connection when DH parameters are
95 required. The B<SSL> object for the current connection is supplied as an
96 argument. Previous versions of OpenSSL used the B<is_export> and B<keylength>
97 arguments to control parameter generation for export and non-export
98 cipher suites. Modern OpenSSL does not support export ciphersuites and so these
99 arguments are unused and can be ignored by the callback. The callback should
100 return the parameters to be used in a DH object. Ownership of the DH object is
101 retained by the application and should later be freed.
102
103 =head1 RETURN VALUES
104
105 All of these functions/macros return 1 for success or 0 on error.
106
107 =head1 SEE ALSO
108
109 L<ssl(7)>, L<SSL_CTX_set_cipher_list(3)>,
110 L<SSL_CTX_set_options(3)>,
111 L<openssl-ciphers(1)>, L<openssl-dhparam(1)>
112
113 =head1 COPYRIGHT
114
115 Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
116
117 Licensed under the Apache License 2.0 (the "License"). You may not use
118 this file except in compliance with the License. You can obtain a copy
119 in the file LICENSE in the source distribution or at
120 L<https://www.openssl.org/source/license.html>.
121
122 =cut