You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.3 KiB

  1. From 5d769ca828fdb055052b3dbc232864bdf2853c9f Mon Sep 17 00:00:00 2001
  2. From: Remi Gacogne <rgacogne@aquaray.fr>
  3. Date: Thu, 28 May 2015 16:23:00 +0200
  4. Subject: [PATCH 12/14] BUG/MEDIUM: ssl: fix tune.ssl.default-dh-param value
  5. being overwritten
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. Hervé Commowick reported that the logic used to avoid complaining about
  10. ssl-default-dh-param not being set when static DH params are present
  11. in the certificate file was clearly wrong when more than one sni_ctx
  12. is used.
  13. This patch stores whether static DH params are being used for each
  14. SSL_CTX individually, and does not overwrite the value of
  15. tune.ssl.default-dh-param.
  16. (cherry picked from commit 4f902b88323927c9d25d391a809e3678ac31df41)
  17. ---
  18. src/ssl_sock.c | 28 +++++++++++++++++++++++-----
  19. 1 file changed, 23 insertions(+), 5 deletions(-)
  20. diff --git a/src/ssl_sock.c b/src/ssl_sock.c
  21. index a78fc6a..0f7819b 100644
  22. --- a/src/ssl_sock.c
  23. +++ b/src/ssl_sock.c
  24. @@ -47,6 +47,9 @@
  25. #ifdef SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB
  26. #include <openssl/ocsp.h>
  27. #endif
  28. +#ifndef OPENSSL_NO_DH
  29. +#include <openssl/dh.h>
  30. +#endif
  31. #include <common/buffer.h>
  32. #include <common/compat.h>
  33. @@ -107,6 +110,7 @@ int sslconns = 0;
  34. int totalsslconns = 0;
  35. #ifndef OPENSSL_NO_DH
  36. +static int ssl_dh_ptr_index = -1;
  37. static DH *local_dh_1024 = NULL;
  38. static DH *local_dh_2048 = NULL;
  39. static DH *local_dh_4096 = NULL;
  40. @@ -1076,10 +1080,12 @@ int ssl_sock_load_dh_params(SSL_CTX *ctx, const char *file)
  41. if (dh) {
  42. ret = 1;
  43. SSL_CTX_set_tmp_dh(ctx, dh);
  44. - /* Setting ssl default dh param to the size of the static DH params
  45. - found in the file. This way we know that there is no use
  46. - complaining later about ssl-default-dh-param not being set. */
  47. - global.tune.ssl_default_dh_param = DH_size(dh) * 8;
  48. +
  49. + if (ssl_dh_ptr_index >= 0) {
  50. + /* store a pointer to the DH params to avoid complaining about
  51. + ssl-default-dh-param not being set for this SSL_CTX */
  52. + SSL_CTX_set_ex_data(ctx, ssl_dh_ptr_index, dh);
  53. + }
  54. }
  55. else {
  56. /* Clear openssl global errors stack */
  57. @@ -1274,6 +1280,12 @@ static int ssl_sock_load_cert_file(const char *path, struct bind_conf *bind_conf
  58. * the tree, so it will be discovered and cleaned in time.
  59. */
  60. #ifndef OPENSSL_NO_DH
  61. + /* store a NULL pointer to indicate we have not yet loaded
  62. + a custom DH param file */
  63. + if (ssl_dh_ptr_index >= 0) {
  64. + SSL_CTX_set_ex_data(ctx, ssl_dh_ptr_index, NULL);
  65. + }
  66. +
  67. ret = ssl_sock_load_dh_params(ctx, path);
  68. if (ret < 0) {
  69. if (err)
  70. @@ -1593,7 +1605,9 @@ int ssl_sock_prepare_ctx(struct bind_conf *bind_conf, SSL_CTX *ctx, struct proxy
  71. /* If tune.ssl.default-dh-param has not been set and
  72. no static DH params were in the certificate file. */
  73. - if (global.tune.ssl_default_dh_param == 0) {
  74. + if (global.tune.ssl_default_dh_param == 0 &&
  75. + (ssl_dh_ptr_index == -1 ||
  76. + SSL_CTX_get_ex_data(ctx, ssl_dh_ptr_index) == NULL)) {
  77. ciphers = ctx->cipher_list;
  78. if (ciphers) {
  79. @@ -4715,6 +4729,10 @@ static void __ssl_sock_init(void)
  80. bind_register_keywords(&bind_kws);
  81. srv_register_keywords(&srv_kws);
  82. cfg_register_keywords(&cfg_kws);
  83. +
  84. +#ifndef OPENSSL_NO_DH
  85. + ssl_dh_ptr_index = SSL_CTX_get_ex_new_index(0, NULL, NULL, NULL, NULL);
  86. +#endif
  87. }
  88. __attribute__((destructor))
  89. --
  90. 2.0.5