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 if either the DH parameters are
53 supplied via callback or the SSL_OP_SINGLE_DH_USE option of
54 SSL_CTX_set_options(3) is set (or both). It will immediately create a
55 DH key if DH parameters are supplied via SSL_CTX_set_tmp_dh() and
56 SSL_OP_SINGLE_DH_USE is not set. In this case, it may happen that a
57 key is generated on initialization without later being needed, while on
58 the other hand the computer time during the negotiation is being saved.
59
60 If "strong" primes were used to generate the DH parameters, it is not
61 strictly necessary to generate a new key for each handshake but it does
62 improve forward secrecy. If it is not assured that "strong" primes were
63 used, SSL_OP_SINGLE_DH_USE must be used in order to prevent small
64 subgroup attacks. Always using SSL_OP_SINGLE_DH_USE has an impact on
65 the computer time needed during negotiation, but it is not very large,
66 so application authors/users should consider always enabling this
67 option. The option is required to implement perfect forward secrecy
68 (PFS).
69
70 As generating DH parameters is extremely time consuming, an application
71 should not generate the parameters on the fly but supply the
72 parameters. DH parameters can be reused, as the actual key is newly
73 generated during the negotiation. The risk in reusing DH parameters is
74 that an attacker may specialize on a very often used DH group.
75 Applications should therefore generate their own DH parameters during
76 the installation process using the openssl dhparam(1) application. This
77 application guarantees that "strong" primes are used.
78
79 Files dh2048.pem, and dh4096.pem in the 'apps' directory of the current
80 version of the OpenSSL distribution contain the 'SKIP' DH parameters,
81 which use safe primes and were generated verifiably pseudo-randomly.
82 These files can be converted into C code using the -C option of the
83 dhparam(1) application. Generation of custom DH parameters during
84 installation should still be preferred to stop an attacker from
85 specializing on a commonly used group. Files dh1024.pem and dh512.pem
86 contain old parameters that must not be used by applications.
87
88 An application may either directly specify the DH parameters or can
89 supply the DH parameters via a callback function.
90
91 Previous versions of the callback used is_export and keylength
92 parameters to control parameter generation for export and non-export
93 cipher suites. Modern servers that do not support export ciphersuites
94 are advised to either use SSL_CTX_set_tmp_dh() in combination with
95 SSL_OP_SINGLE_DH_USE, or alternatively, use the callback but ignore
96 keylength and is_export and simply supply at least 2048-bit parameters
97 in the callback.
98
100 Setup DH parameters with a key length of 2048 bits. (Error handling
101 partly left out.)
102
103 Command-line parameter generation:
104 $ openssl dhparam -out dh_param_2048.pem 2048
105
106 Code for setting up parameters during server initialization:
107
108 ...
109 SSL_CTX ctx = SSL_CTX_new();
110 ...
111
112 /* Set up ephemeral DH parameters. */
113 DH *dh_2048 = NULL;
114 FILE *paramfile;
115 paramfile = fopen("dh_param_2048.pem", "r");
116 if (paramfile) {
117 dh_2048 = PEM_read_DHparams(paramfile, NULL, NULL, NULL);
118 fclose(paramfile);
119 } else {
120 /* Error. */
121 }
122 if (dh_2048 == NULL) {
123 /* Error. */
124 }
125 if (SSL_CTX_set_tmp_dh(ctx, dh_2048) != 1) {
126 /* Error. */
127 }
128 SSL_CTX_set_options(ctx, SSL_OP_SINGLE_DH_USE);
129 ...
130
132 SSL_CTX_set_tmp_dh_callback() and SSL_set_tmp_dh_callback() do not
133 return diagnostic output.
134
135 SSL_CTX_set_tmp_dh() and SSL_set_tmp_dh() do return 1 on success and 0
136 on failure. Check the error queue to find out the reason of failure.
137
139 ssl(3), SSL_CTX_set_cipher_list(3), SSL_CTX_set_tmp_rsa_callback(3),
140 SSL_CTX_set_options(3), ciphers(1), dhparam(1)
141
142
143
1441.0.1e 2017-03-22 SSL_CTX_set_tmp_dh_callback(3)