1SSL_CTX_SET_TMP_DH_CALLBACK(3) OpenSSL SSL_CTX_SET_TMP_DH_CALLBACK(3)
2
3
4
6 SSL_CTX_set_tmp_dh_callback, SSL_CTX_set_tmp_dh,
7 SSL_set_tmp_dh_callback, SSL_set_tmp_dh - handle DH keys for ephemeral
8 key exchange
9
11 #include <openssl/ssl.h>
12
13 void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
14 DH *(*tmp_dh_callback)(SSL *ssl, int is_export,
15 int keylength));
16 long SSL_CTX_set_tmp_dh(SSL_CTX *ctx, DH *dh);
17
18 void SSL_set_tmp_dh_callback(SSL *ctx,
19 DH *(*tmp_dh_callback)(SSL *ssl, int is_export,
20 int keylength));
21 long SSL_set_tmp_dh(SSL *ssl, DH *dh)
22
24 SSL_CTX_set_tmp_dh_callback() sets the callback function for ctx to be
25 used when a DH parameters are required to tmp_dh_callback. The
26 callback is inherited by all ssl objects created from ctx.
27
28 SSL_CTX_set_tmp_dh() sets DH parameters to be used to be dh. The key
29 is inherited by all ssl objects created from ctx.
30
31 SSL_set_tmp_dh_callback() sets the callback only for ssl.
32
33 SSL_set_tmp_dh() sets the parameters only for ssl.
34
35 These functions apply to SSL/TLS servers only.
36
38 When using a cipher with RSA authentication, an ephemeral DH key
39 exchange can take place. Ciphers with DSA keys always use ephemeral DH
40 keys as well. In these cases, the session data are negotiated using
41 the ephemeral/temporary DH key and the key supplied and certified by
42 the certificate chain is only used for signing. Anonymous ciphers
43 (without a permanent server key) also use ephemeral DH keys.
44
45 Using ephemeral DH key exchange yields forward secrecy, as the
46 connection can only be decrypted, when the DH key is known. By
47 generating a temporary DH key inside the server application that is
48 lost when the application is left, it becomes impossible for an
49 attacker to decrypt past sessions, even if he gets hold of the normal
50 (certified) key, as this key was only used for signing.
51
52 In order to perform a DH key exchange the server must use a DH group
53 (DH parameters) and generate a DH key. The server will always generate
54 a new DH key during the negotiation.
55
56 As generating DH parameters is extremely time consuming, an application
57 should not generate the parameters on the fly but supply the
58 parameters. DH parameters can be reused, as the actual key is newly
59 generated during the negotiation. The risk in reusing DH parameters is
60 that an attacker may specialize on a very often used DH group.
61 Applications should therefore generate their own DH parameters during
62 the installation process using the openssl dhparam(1) application. This
63 application guarantees that "strong" primes are used.
64
65 Files dh2048.pem, and dh4096.pem in the 'apps' directory of the current
66 version of the OpenSSL distribution contain the 'SKIP' DH parameters,
67 which use safe primes and were generated verifiably pseudo-randomly.
68 These files can be converted into C code using the -C option of the
69 dhparam(1) application. Generation of custom DH parameters during
70 installation should still be preferred to stop an attacker from
71 specializing on a commonly used group. File dh1024.pem contains old
72 parameters that must not be used by applications.
73
74 An application may either directly specify the DH parameters or can
75 supply the DH parameters via a callback function.
76
77 Previous versions of the callback used is_export and keylength
78 parameters to control parameter generation for export and non-export
79 cipher suites. Modern servers that do not support export cipher suites
80 are advised to either use SSL_CTX_set_tmp_dh() or alternatively, use
81 the callback but ignore keylength and is_export and simply supply at
82 least 2048-bit parameters in the callback.
83
85 SSL_CTX_set_tmp_dh_callback() and SSL_set_tmp_dh_callback() do not
86 return diagnostic output.
87
88 SSL_CTX_set_tmp_dh() and SSL_set_tmp_dh() do return 1 on success and 0
89 on failure. Check the error queue to find out the reason of failure.
90
92 Setup DH parameters with a key length of 2048 bits. (Error handling
93 partly left out.)
94
95 Command-line parameter generation:
96
97 $ openssl dhparam -out dh_param_2048.pem 2048
98
99 Code for setting up parameters during server initialization:
100
101 SSL_CTX ctx = SSL_CTX_new();
102
103 DH *dh_2048 = NULL;
104 FILE *paramfile = fopen("dh_param_2048.pem", "r");
105
106 if (paramfile) {
107 dh_2048 = PEM_read_DHparams(paramfile, NULL, NULL, NULL);
108 fclose(paramfile);
109 } else {
110 /* Error. */
111 }
112 if (dh_2048 == NULL)
113 /* Error. */
114 if (SSL_CTX_set_tmp_dh(ctx, dh_2048) != 1)
115 /* Error. */
116 ...
117
119 ssl(7), SSL_CTX_set_cipher_list(3), SSL_CTX_set_options(3), ciphers(1),
120 dhparam(1)
121
123 Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
124
125 Licensed under the OpenSSL license (the "License"). You may not use
126 this file except in compliance with the License. You can obtain a copy
127 in the file LICENSE in the source distribution or at
128 <https://www.openssl.org/source/license.html>.
129
130
131
1321.1.1c 2019-05-28 SSL_CTX_SET_TMP_DH_CALLBACK(3)