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
2.6 KiB

  1. From 28e247dbc53b95acf9cb716f99f13aadc4d38651 Mon Sep 17 00:00:00 2001
  2. From: Bruno Silvestre <bruno.silvestre@gmail.com>
  3. Date: Mon, 2 Jul 2018 10:31:45 -0300
  4. Subject: [PATCH 3/3] Removing deprecated methods to select the protocol
  5. Using TLS_method(), SSL_set_min_proto_version() and
  6. SSL_set_max_proto_version().
  7. ---
  8. src/context.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
  9. 1 file changed, 44 insertions(+), 2 deletions(-)
  10. diff --git a/src/context.c b/src/context.c
  11. index d8fc8b6..d1377f1 100644
  12. --- a/src/context.c
  13. +++ b/src/context.c
  14. @@ -59,11 +59,46 @@ static int set_option_flag(const char *opt, unsigned long *flag)
  15. return 0;
  16. }
  17. +#if (OPENSSL_VERSION_NUMBER >= 0x1010000fL)
  18. +
  19. /**
  20. * Find the protocol.
  21. */
  22. -static const SSL_METHOD* str2method(const char *method)
  23. +static const SSL_METHOD* str2method(const char *method, int *vmin, int *vmax)
  24. {
  25. + if (!strcmp(method, "any") || !strcmp(method, "sslv23")) {
  26. + *vmin = TLS1_VERSION;
  27. + *vmax = TLS1_2_VERSION;
  28. + return TLS_method();
  29. + }
  30. + else if (!strcmp(method, "tlsv1")) {
  31. + *vmin = TLS1_VERSION;
  32. + *vmax = TLS1_VERSION;
  33. + return TLS_method();
  34. + }
  35. + else if (!strcmp(method, "tlsv1_1")) {
  36. + *vmin = TLS1_1_VERSION;
  37. + *vmax = TLS1_1_VERSION;
  38. + return TLS_method();
  39. + }
  40. + else if (!strcmp(method, "tlsv1_2")) {
  41. + *vmin = TLS1_2_VERSION;
  42. + *vmax = TLS1_2_VERSION;
  43. + return TLS_method();
  44. + }
  45. +
  46. + return NULL;
  47. +}
  48. +
  49. +#else
  50. +
  51. +/**
  52. + * Find the protocol.
  53. + */
  54. +static const SSL_METHOD* str2method(const char *method, int *vmin, int *vmax)
  55. +{
  56. + (void)vmin;
  57. + (void)vmax;
  58. if (!strcmp(method, "any")) return SSLv23_method();
  59. if (!strcmp(method, "sslv23")) return SSLv23_method(); // deprecated
  60. if (!strcmp(method, "tlsv1")) return TLSv1_method();
  61. @@ -74,6 +109,8 @@ static const SSL_METHOD* str2method(const char *method)
  62. return NULL;
  63. }
  64. +#endif
  65. +
  66. /**
  67. * Prepare the SSL handshake verify flag.
  68. */
  69. @@ -279,9 +316,10 @@ static int create(lua_State *L)
  70. p_context ctx;
  71. const char *str_method;
  72. const SSL_METHOD *method;
  73. + int vmin, vmax;
  74. str_method = luaL_checkstring(L, 1);
  75. - method = str2method(str_method);
  76. + method = str2method(str_method, &vmin, &vmax);
  77. if (!method) {
  78. lua_pushnil(L);
  79. lua_pushfstring(L, "invalid protocol (%s)", str_method);
  80. @@ -301,6 +339,10 @@ static int create(lua_State *L)
  81. ERR_reason_error_string(ERR_get_error()));
  82. return 2;
  83. }
  84. +#if (OPENSSL_VERSION_NUMBER >= 0x1010000fL)
  85. + SSL_CTX_set_min_proto_version(ctx->context, vmin);
  86. + SSL_CTX_set_max_proto_version(ctx->context, vmax);
  87. +#endif
  88. ctx->mode = LSEC_MODE_INVALID;
  89. ctx->L = L;
  90. luaL_getmetatable(L, "SSL:Context");
  91. --
  92. 2.19.1