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.

70 lines
2.1 KiB

  1. From b2b0eab46a8ae36f2dd49159e65c90c1089a0f96 Mon Sep 17 00:00:00 2001
  2. From: "Thierry FOURNIER / OZON.IO" <thierry.fournier@ozon.io>
  3. Date: Thu, 6 Oct 2016 10:56:48 +0200
  4. Subject: [PATCH 11/26] BUG/MINOR: ssl: prevent multiple entries for the same
  5. certificate
  6. Today, the certificate are indexed int he SNI tree using their CN and the
  7. list of thier AltNames. So, Some certificates have the same names in the
  8. CN and one of the AltNames entries.
  9. Typically Let's Encrypt duplicate the the DNS name in the CN and the
  10. AltName.
  11. This patch prevents the creation of identical entries in the trees. It
  12. checks the same DNS name and the same SSL context.
  13. If the same certificate is registered two time it will be duplicated.
  14. This patch should be backported in the 1.6 and 1.5 version.
  15. (cherry picked from commit 07c3d78c2c0693ee37db71c34723597638b6ab3f)
  16. ---
  17. src/ssl_sock.c | 22 +++++++++++++++++++---
  18. 1 file changed, 19 insertions(+), 3 deletions(-)
  19. diff --git a/src/ssl_sock.c b/src/ssl_sock.c
  20. index 5f9a203..ad8054d 100644
  21. --- a/src/ssl_sock.c
  22. +++ b/src/ssl_sock.c
  23. @@ -1556,6 +1556,7 @@ static int ssl_sock_add_cert_sni(SSL_CTX *ctx, struct bind_conf *s, char *name,
  24. {
  25. struct sni_ctx *sc;
  26. int wild = 0, neg = 0;
  27. + struct ebmb_node *node;
  28. if (*name == '!') {
  29. neg = 1;
  30. @@ -1571,12 +1572,27 @@ static int ssl_sock_add_cert_sni(SSL_CTX *ctx, struct bind_conf *s, char *name,
  31. if (*name) {
  32. int j, len;
  33. len = strlen(name);
  34. + for (j = 0; j < len && j < trash.size; j++)
  35. + trash.str[j] = tolower(name[j]);
  36. + if (j >= trash.size)
  37. + return order;
  38. + trash.str[j] = 0;
  39. +
  40. + /* Check for duplicates. */
  41. + if (wild)
  42. + node = ebst_lookup(&s->sni_w_ctx, trash.str);
  43. + else
  44. + node = ebst_lookup(&s->sni_ctx, trash.str);
  45. + for (; node; node = ebmb_next_dup(node)) {
  46. + sc = ebmb_entry(node, struct sni_ctx, name);
  47. + if (sc->ctx == ctx && sc->neg == neg)
  48. + return order;
  49. + }
  50. +
  51. sc = malloc(sizeof(struct sni_ctx) + len + 1);
  52. if (!sc)
  53. return order;
  54. - for (j = 0; j < len; j++)
  55. - sc->name.key[j] = tolower(name[j]);
  56. - sc->name.key[len] = 0;
  57. + memcpy(sc->name.key, trash.str, len + 1);
  58. sc->ctx = ctx;
  59. sc->order = order++;
  60. sc->neg = neg;
  61. --
  62. 2.7.3