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.

66 lines
2.5 KiB

  1. From 5fbcf1a914507b4c73d83387fdc5e8f612d83558 Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Thu, 22 Dec 2016 21:58:38 +0100
  4. Subject: [PATCH 16/19] BUG/MEDIUM: ssl: for a handshake when server-side SNI
  5. changes
  6. Calling SSL_set_tlsext_host_name() on the current SSL ctx has no effect
  7. if the session is being resumed because the hostname is already stored
  8. in the session and is not advertised again in subsequent connections.
  9. It's visible when enabling SNI and health checks at the same time because
  10. checks do not send an SNI and regular traffic reuses the same connection,
  11. resulting in no SNI being sent.
  12. The only short-term solution is to reset the reused session when the
  13. SNI changes compared to the previous one. It can make the server-side
  14. performance suffer when SNIs are interleaved but it will work. A better
  15. long-term solution would be to keep a small cache of a few contexts for
  16. a few SNIs.
  17. Now with SSL_set_session(ctx, NULL) it works. This needs to be double-
  18. checked though. The man says that SSL_set_session() frees any previously
  19. existing context. Some people report a bit of breakage when calling
  20. SSL_set_session(NULL) on openssl 1.1.0a (freed session not reusable at
  21. all though it's not an issue for now).
  22. This needs to be backported to 1.7 and 1.6.
  23. (cherry picked from commit 119a4084bf88418bce74d8af686576e371700c20)
  24. ---
  25. src/ssl_sock.c | 15 +++++++++++++++
  26. 1 file changed, 15 insertions(+)
  27. diff --git a/src/ssl_sock.c b/src/ssl_sock.c
  28. index 55eaa28..77fb4b3 100644
  29. --- a/src/ssl_sock.c
  30. +++ b/src/ssl_sock.c
  31. @@ -4143,12 +4143,27 @@ char *ssl_sock_get_version(struct connection *conn)
  32. return (char *)SSL_get_version(conn->xprt_ctx);
  33. }
  34. +/* Sets advertised SNI for outgoing connections. Please set <hostname> to NULL
  35. + * to disable SNI.
  36. + */
  37. void ssl_sock_set_servername(struct connection *conn, const char *hostname)
  38. {
  39. #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
  40. + char *prev_name;
  41. +
  42. if (!ssl_sock_is_ssl(conn))
  43. return;
  44. + /* if the SNI changes, we must destroy the reusable context so that a
  45. + * new connection will present a new SNI. As an optimization we could
  46. + * later imagine having a small cache of ssl_ctx to hold a few SNI per
  47. + * server.
  48. + */
  49. + prev_name = (char *)SSL_get_servername(conn->xprt_ctx, TLSEXT_NAMETYPE_host_name);
  50. + if ((!prev_name && hostname) ||
  51. + (prev_name && (!hostname || strcmp(hostname, prev_name) != 0)))
  52. + SSL_set_session(conn->xprt_ctx, NULL);
  53. +
  54. SSL_set_tlsext_host_name(conn->xprt_ctx, hostname);
  55. #endif
  56. }
  57. --
  58. 2.10.2