SSL_CTX_set_tmp_dh_callback.pod 4.7 KB

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