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