summaryrefslogtreecommitdiff
path: root/src/lib/libssl/doc/SSL_CTX_set_tmp_dh_callback.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/doc/SSL_CTX_set_tmp_dh_callback.3')
-rw-r--r--src/lib/libssl/doc/SSL_CTX_set_tmp_dh_callback.3233
1 files changed, 233 insertions, 0 deletions
diff --git a/src/lib/libssl/doc/SSL_CTX_set_tmp_dh_callback.3 b/src/lib/libssl/doc/SSL_CTX_set_tmp_dh_callback.3
new file mode 100644
index 0000000000..f28d083f45
--- /dev/null
+++ b/src/lib/libssl/doc/SSL_CTX_set_tmp_dh_callback.3
@@ -0,0 +1,233 @@
1.Dd $Mdocdate: October 12 2014 $
2.Dt SSL_CTX_SET_TMP_DH_CALLBACK 3
3.Os
4.Sh NAME
5.Nm SSL_CTX_set_tmp_dh_callback ,
6.Nm SSL_CTX_set_tmp_dh ,
7.Nm SSL_set_tmp_dh_callback ,
8.Nm SSL_set_tmp_dh
9.Nd handle DH keys for ephemeral key exchange
10.Sh SYNOPSIS
11.In openssl/ssl.h
12.Ft void
13.Fo SSL_CTX_set_tmp_dh_callback
14.Fa "SSL_CTX *ctx"
15.Fa "DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength)"
16.Fc
17.Ft long
18.Fn SSL_CTX_set_tmp_dh "SSL_CTX *ctx" "DH *dh"
19.Ft void
20.Fo SSL_set_tmp_dh_callback
21.Fa "SSL *ssl"
22.Fa "DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength"
23.Fc
24.Ft long
25.Fn SSL_set_tmp_dh "SSL *ssl" "DH *dh"
26.Sh DESCRIPTION
27.Fn SSL_CTX_set_tmp_dh_callback
28sets the callback function for
29.Fa ctx
30to be used when a DH parameters are required to
31.Fa tmp_dh_callback .
32The callback is inherited by all
33.Vt ssl
34objects created from
35.Fa ctx .
36.Pp
37.Fn SSL_CTX_set_tmp_dh
38sets DH parameters to be used to be
39.Sy dh Ns .
40The key is inherited by all
41.Fa ssl
42objects created from
43.Fa ctx .
44.Pp
45.Fn SSL_set_tmp_dh_callback
46sets the callback only for
47.Fa ssl .
48.Pp
49.Fn SSL_set_tmp_dh
50sets the parameters only for
51.Fa ssl .
52.Pp
53These functions apply to SSL/TLS servers only.
54.Sh NOTES
55When using a cipher with RSA authentication,
56an ephemeral DH key exchange can take place.
57Ciphers with DSA keys always use ephemeral DH keys as well.
58In these cases, the session data are negotiated using the ephemeral/temporary
59DH key and the key supplied and certified by the certificate chain is only used
60for signing.
61Anonymous ciphers (without a permanent server key) also use ephemeral DH keys.
62.Pp
63Using ephemeral DH key exchange yields forward secrecy,
64as the connection can only be decrypted when the DH key is known.
65By generating a temporary DH key inside the server application that is lost
66when the application is left, it becomes impossible for an attacker to decrypt
67past sessions, even if he gets hold of the normal (certified) key,
68as this key was only used for signing.
69.Pp
70In order to perform a DH key exchange the server must use a DH group
71(DH parameters) and generate a DH key.
72The server will always generate a new DH key during the negotiation,
73when the DH parameters are supplied via callback and/or when the
74.Dv SSL_OP_SINGLE_DH_USE
75option of
76.Xr SSL_CTX_set_options 3
77is set.
78It will immediately create a DH key, when DH parameters are supplied via
79.Fn SSL_CTX_set_tmp_dh
80and
81.Dv SSL_OP_SINGLE_DH_USE
82is not set.
83In this case, it may happen that a key is generated on initialization without
84later being needed, while on the other hand the computer time during the
85negotiation is being saved.
86.Pp
87If
88.Dq strong
89primes were used to generate the DH parameters, it is not strictly necessary to
90generate a new key for each handshake but it does improve forward secrecy.
91If it is not assured that
92.Dq strong
93primes were used (see especially the section about DSA parameters below),
94.Dv SSL_OP_SINGLE_DH_USE
95must be used in order to prevent small subgroup attacks.
96Always using
97.Dv SSL_OP_SINGLE_DH_USE
98has an impact on the computer time needed during negotiation,
99but it is not very large,
100so application authors/users should consider always enabling this option.
101.Pp
102As generating DH parameters is extremely time consuming, an application should
103not generate the parameters on the fly but supply the parameters.
104DH parameters can be reused,
105as the actual key is newly generated during the negotiation.
106The risk in reusing DH parameters is that an attacker may specialize on a very
107often used DH group.
108Applications should therefore generate their own DH parameters during the
109installation process using the openssl
110.Xr dhparam 1
111application.
112In order to reduce the computer time needed for this generation,
113it is possible to use DSA parameters instead (see
114.Xr dhparam 1 ) ,
115but in this case
116.Dv SSL_OP_SINGLE_DH_USE
117is mandatory.
118.Pp
119Application authors may compile in DH parameters.
120Files
121.Pa dh512.pem ,
122.Pa dh1024.pem ,
123.Pa dh2048.pem ,
124and
125.Pa dh4096.pem
126in the
127.Pa apps
128directory of the current version of the OpenSSL distribution contain the
129.Sq SKIP
130DH parameters,
131which use safe primes and were generated verifiably pseudo-randomly.
132These files can be converted into C code using the
133.Fl C
134option of the
135.Xr dhparam 1
136application.
137Authors may also generate their own set of parameters using
138.Xr dhparam 1 ,
139but a user may not be sure how the parameters were generated.
140The generation of DH parameters during installation is therefore recommended.
141.Pp
142An application may either directly specify the DH parameters or can supply the
143DH parameters via a callback function.
144The callback approach has the advantage that the callback may supply DH
145parameters for different key lengths.
146.Pp
147The
148.Fa tmp_dh_callback
149is called with the
150.Fa keylength
151needed and the
152.Fa is_export
153information.
154The
155.Fa is_export
156flag is set when the ephemeral DH key exchange is performed with an export
157cipher.
158.Sh RETURN VALUES
159.Fn SSL_CTX_set_tmp_dh_callback
160and
161.Fn SSL_set_tmp_dh_callback
162do not return diagnostic output.
163.Pp
164.Fn SSL_CTX_set_tmp_dh
165and
166.Fn SSL_set_tmp_dh
167do return 1 on success and 0 on failure.
168Check the error queue to find out the reason of failure.
169.Sh EXAMPLES
170Handle DH parameters for key lengths of 512 and 1024 bits.
171(Error handling partly left out.)
172.Bd -literal
173\&...
174/* Set up ephemeral DH stuff */
175DH *dh_512 = NULL;
176DH *dh_1024 = NULL;
177FILE *paramfile;
178
179\&...
180
181/* "openssl dhparam -out dh_param_512.pem -2 512" */
182paramfile = fopen("dh_param_512.pem", "r");
183if (paramfile) {
184 dh_512 = PEM_read_DHparams(paramfile, NULL, NULL, NULL);
185 fclose(paramfile);
186}
187/* "openssl dhparam -out dh_param_1024.pem -2 1024" */
188paramfile = fopen("dh_param_1024.pem", "r");
189if (paramfile) {
190 dh_1024 = PEM_read_DHparams(paramfile, NULL, NULL, NULL);
191 fclose(paramfile);
192}
193
194\&...
195
196/* "openssl dhparam -C -2 512" etc... */
197DH *get_dh512() { ... }
198DH *get_dh1024() { ... }
199
200DH *
201tmp_dh_callback(SSL *s, int is_export, int keylength)
202{
203 DH *dh_tmp=NULL;
204
205 switch (keylength) {
206 case 512:
207 if (!dh_512)
208 dh_512 = get_dh512();
209 dh_tmp = dh_512;
210 break;
211 case 1024:
212 if (!dh_1024)
213 dh_1024 = get_dh1024();
214 dh_tmp = dh_1024;
215 break;
216 default:
217 /*
218 * Generating a key on the fly is very costly,
219 * so use what is there
220 */
221 setup_dh_parameters_like_above();
222 }
223
224 return(dh_tmp);
225}
226.Ed
227.Sh SEE ALSO
228.Xr ciphers 1 ,
229.Xr dhparam 1 ,
230.Xr ssl 3 ,
231.Xr SSL_CTX_set_cipher_list 3 ,
232.Xr SSL_CTX_set_options 3 ,
233.Xr SSL_CTX_set_tmp_rsa_callback 3