Blame doc/man3/SSL_CTX_set_tmp_dh_callback.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
SSL_CTX_set_tmp_dh_callback, SSL_CTX_set_tmp_dh, SSL_set_tmp_dh_callback, SSL_set_tmp_dh - handle DH keys for ephemeral key exchange
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/ssl.h>
Packit c4476c
Packit c4476c
 void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
Packit c4476c
                                  DH *(*tmp_dh_callback)(SSL *ssl, int is_export,
Packit c4476c
                                                         int keylength));
Packit c4476c
 long SSL_CTX_set_tmp_dh(SSL_CTX *ctx, DH *dh);
Packit c4476c
Packit c4476c
 void SSL_set_tmp_dh_callback(SSL *ctx,
Packit c4476c
                              DH *(*tmp_dh_callback)(SSL *ssl, int is_export,
Packit c4476c
                                                     int keylength));
Packit c4476c
 long SSL_set_tmp_dh(SSL *ssl, DH *dh)
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
SSL_CTX_set_tmp_dh_callback() sets the callback function for B<ctx> to be
Packit c4476c
used when a DH parameters are required to B<tmp_dh_callback>.
Packit c4476c
The callback is inherited by all B<ssl> objects created from B<ctx>.
Packit c4476c
Packit c4476c
SSL_CTX_set_tmp_dh() sets DH parameters to be used to be B<dh>.
Packit c4476c
The key is inherited by all B<ssl> objects created from B<ctx>.
Packit c4476c
Packit c4476c
SSL_set_tmp_dh_callback() sets the callback only for B<ssl>.
Packit c4476c
Packit c4476c
SSL_set_tmp_dh() sets the parameters only for B<ssl>.
Packit c4476c
Packit c4476c
These functions apply to SSL/TLS servers only.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
When using a cipher with RSA authentication, an ephemeral DH key exchange
Packit c4476c
can take place. Ciphers with DSA keys always use ephemeral DH keys as well.
Packit c4476c
In these cases, the session data are negotiated using the
Packit c4476c
ephemeral/temporary DH key and the key supplied and certified
Packit c4476c
by the certificate chain is only used for signing.
Packit c4476c
Anonymous ciphers (without a permanent server key) also use ephemeral DH keys.
Packit c4476c
Packit c4476c
Using ephemeral DH key exchange yields forward secrecy, as the connection
Packit c4476c
can only be decrypted, when the DH key is known. By generating a temporary
Packit c4476c
DH key inside the server application that is lost when the application
Packit c4476c
is left, it becomes impossible for an attacker to decrypt past sessions,
Packit c4476c
even if he gets hold of the normal (certified) key, as this key was
Packit c4476c
only used for signing.
Packit c4476c
Packit c4476c
In order to perform a DH key exchange the server must use a DH group
Packit c4476c
(DH parameters) and generate a DH key. The server will always generate
Packit c4476c
a new DH key during the negotiation.
Packit c4476c
Packit c4476c
As generating DH parameters is extremely time consuming, an application
Packit c4476c
should not generate the parameters on the fly but supply the parameters.
Packit c4476c
DH parameters can be reused, as the actual key is newly generated during
Packit c4476c
the negotiation. The risk in reusing DH parameters is that an attacker
Packit c4476c
may specialize on a very often used DH group. Applications should therefore
Packit c4476c
generate their own DH parameters during the installation process using the
Packit c4476c
openssl L<dhparam(1)> application. This application
Packit c4476c
guarantees that "strong" primes are used.
Packit c4476c
Packit c4476c
Files dh2048.pem, and dh4096.pem in the 'apps' directory of the current
Packit c4476c
version of the OpenSSL distribution contain the 'SKIP' DH parameters,
Packit c4476c
which use safe primes and were generated verifiably pseudo-randomly.
Packit c4476c
These files can be converted into C code using the B<-C> option of the
Packit c4476c
L<dhparam(1)> application. Generation of custom DH
Packit c4476c
parameters during installation should still be preferred to stop an
Packit c4476c
attacker from specializing on a commonly used group. File dh1024.pem
Packit c4476c
contains old parameters that must not be used by applications.
Packit c4476c
Packit c4476c
An application may either directly specify the DH parameters or
Packit c4476c
can supply the DH parameters via a callback function.
Packit c4476c
Packit c4476c
Previous versions of the callback used B<is_export> and B<keylength>
Packit c4476c
parameters to control parameter generation for export and non-export
Packit c4476c
cipher suites. Modern servers that do not support export cipher suites
Packit c4476c
are advised to either use SSL_CTX_set_tmp_dh() or alternatively, use
Packit c4476c
the callback but ignore B<keylength> and B<is_export> and simply
Packit c4476c
supply at least 2048-bit parameters in the callback.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
SSL_CTX_set_tmp_dh_callback() and SSL_set_tmp_dh_callback() do not return
Packit c4476c
diagnostic output.
Packit c4476c
Packit c4476c
SSL_CTX_set_tmp_dh() and SSL_set_tmp_dh() do return 1 on success and 0
Packit c4476c
on failure. Check the error queue to find out the reason of failure.
Packit c4476c
Packit c4476c
=head1 EXAMPLES
Packit c4476c
Packit c4476c
Setup DH parameters with a key length of 2048 bits. (Error handling
Packit c4476c
partly left out.)
Packit c4476c
Packit c4476c
Command-line parameter generation:
Packit c4476c
Packit c4476c
 $ openssl dhparam -out dh_param_2048.pem 2048
Packit c4476c
Packit c4476c
Code for setting up parameters during server initialization:
Packit c4476c
Packit c4476c
 SSL_CTX ctx = SSL_CTX_new();
Packit c4476c
Packit c4476c
 DH *dh_2048 = NULL;
Packit c4476c
 FILE *paramfile = fopen("dh_param_2048.pem", "r");
Packit c4476c
Packit c4476c
 if (paramfile) {
Packit c4476c
     dh_2048 = PEM_read_DHparams(paramfile, NULL, NULL, NULL);
Packit c4476c
     fclose(paramfile);
Packit c4476c
 } else {
Packit c4476c
     /* Error. */
Packit c4476c
 }
Packit c4476c
 if (dh_2048 == NULL)
Packit c4476c
     /* Error. */
Packit c4476c
 if (SSL_CTX_set_tmp_dh(ctx, dh_2048) != 1)
Packit c4476c
     /* Error. */
Packit c4476c
 ...
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<ssl(7)>, L<SSL_CTX_set_cipher_list(3)>,
Packit c4476c
L<SSL_CTX_set_options(3)>,
Packit c4476c
L<ciphers(1)>, L<dhparam(1)>
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut