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.

180 lines
4.9 KiB

  1. --- a/src/context.c
  2. +++ b/src/context.c
  3. @@ -24,7 +24,7 @@
  4. #include "context.h"
  5. #include "options.h"
  6. -#ifndef OPENSSL_NO_ECDH
  7. +#ifndef OPENSSL_NO_EC
  8. #include <openssl/ec.h>
  9. #include "ec.h"
  10. #endif
  11. @@ -35,10 +35,6 @@ typedef const SSL_METHOD LSEC_SSL_METHOD
  12. typedef SSL_METHOD LSEC_SSL_METHOD;
  13. #endif
  14. -#if OPENSSL_VERSION_NUMBER>=0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
  15. -#define SSLv23_method() TLS_method()
  16. -#endif
  17. -
  18. /*-- Compat - Lua 5.1 --------------------------------------------------------*/
  19. #if (LUA_VERSION_NUM == 501)
  20. @@ -304,7 +300,7 @@ static int verify_cb(int preverify_ok, X
  21. return (verify & LSEC_VERIFY_CONTINUE ? 1 : preverify_ok);
  22. }
  23. -#ifndef OPENSSL_NO_ECDH
  24. +#ifndef OPENSSL_NO_EC
  25. static EC_KEY *find_ec_key(const char *str)
  26. {
  27. p_ec ptr;
  28. @@ -565,7 +561,7 @@ static int set_dhparam(lua_State *L)
  29. /**
  30. * Set elliptic curve.
  31. */
  32. -#ifdef OPENSSL_NO_ECDH
  33. +#ifdef OPENSSL_NO_EC
  34. static int set_curve(lua_State *L)
  35. {
  36. lua_pushboolean(L, 0);
  37. --- a/src/ssl.c
  38. +++ b/src/ssl.c
  39. @@ -31,6 +31,13 @@
  40. #include "context.h"
  41. #include "ssl.h"
  42. +
  43. +#if defined(LIBRESSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER<0x10100000L
  44. +#define SSL_is_server(s) (s->server)
  45. +#define X509_up_ref(c) CRYPTO_add(&c->references, 1, CRYPTO_LOCK_X509)
  46. +#endif
  47. +
  48. +
  49. /**
  50. * Underline socket error.
  51. */
  52. @@ -406,7 +413,9 @@ static int meth_want(lua_State *L)
  53. */
  54. static int meth_compression(lua_State *L)
  55. {
  56. -#if !defined(OPENSSL_NO_COMP)
  57. +#ifdef OPENSSL_NO_COMP
  58. + const void *comp;
  59. +#else
  60. const COMP_METHOD *comp;
  61. #endif
  62. p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
  63. @@ -415,15 +424,11 @@ static int meth_compression(lua_State *L
  64. lua_pushstring(L, "closed");
  65. return 2;
  66. }
  67. -#if !defined(OPENSSL_NO_COMP)
  68. comp = SSL_get_current_compression(ssl->ssl);
  69. if (comp)
  70. lua_pushstring(L, SSL_COMP_get_name(comp));
  71. else
  72. lua_pushnil(L);
  73. -#else
  74. - lua_pushnil(L);
  75. -#endif
  76. return 1;
  77. }
  78. @@ -461,7 +466,7 @@ static int meth_getpeercertificate(lua_S
  79. /* In a server-context, the stack doesn't contain the peer cert,
  80. * so adjust accordingly.
  81. */
  82. - if (ssl->ssl->server)
  83. + if (SSL_is_server(ssl->ssl))
  84. --n;
  85. certs = SSL_get_peer_cert_chain(ssl->ssl);
  86. if (n >= sk_X509_num(certs)) {
  87. @@ -471,7 +476,7 @@ static int meth_getpeercertificate(lua_S
  88. cert = sk_X509_value(certs, n);
  89. /* Increment the reference counting of the object. */
  90. /* See SSL_get_peer_certificate() source code. */
  91. - CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
  92. + X509_up_ref(cert);
  93. lsec_pushx509(L, cert);
  94. return 1;
  95. }
  96. @@ -493,7 +498,7 @@ static int meth_getpeerchain(lua_State *
  97. return 2;
  98. }
  99. lua_newtable(L);
  100. - if (ssl->ssl->server) {
  101. + if (SSL_is_server(ssl->ssl)) {
  102. lsec_pushx509(L, SSL_get_peer_certificate(ssl->ssl));
  103. lua_rawseti(L, -2, idx++);
  104. }
  105. @@ -503,7 +508,7 @@ static int meth_getpeerchain(lua_State *
  106. cert = sk_X509_value(certs, i);
  107. /* Increment the reference counting of the object. */
  108. /* See SSL_get_peer_certificate() source code. */
  109. - CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
  110. + X509_up_ref(cert);
  111. lsec_pushx509(L, cert);
  112. lua_rawseti(L, -2, idx++);
  113. }
  114. --- a/src/x509.c
  115. +++ b/src/x509.c
  116. @@ -32,6 +32,17 @@
  117. #include "x509.h"
  118. +
  119. +/*
  120. + * ASN1_STRING_data is deprecated in OpenSSL 1.1.0
  121. + */
  122. +#if OPENSSL_VERSION_NUMBER>=0x1010000fL && !defined(LIBRESSL_VERSION_NUMBER)
  123. +#define LSEC_ASN1_STRING_data(x) ASN1_STRING_get0_data(x)
  124. +#else
  125. +#define LSEC_ASN1_STRING_data(x) ASN1_STRING_data(x)
  126. +#endif
  127. +
  128. +
  129. static const char* hex_tab = "0123456789abcdef";
  130. /**
  131. @@ -146,7 +157,7 @@ static void push_asn1_string(lua_State*
  132. }
  133. switch (encode) {
  134. case LSEC_AI5_STRING:
  135. - lua_pushlstring(L, (char*)ASN1_STRING_data(string),
  136. + lua_pushlstring(L, (char*)LSEC_ASN1_STRING_data(string),
  137. ASN1_STRING_length(string));
  138. break;
  139. case LSEC_UTF8_STRING:
  140. @@ -182,7 +193,7 @@ static void push_asn1_ip(lua_State *L, A
  141. {
  142. int af;
  143. char dst[INET6_ADDRSTRLEN];
  144. - unsigned char *ip = ASN1_STRING_data(string);
  145. + unsigned char *ip = (unsigned char*)LSEC_ASN1_STRING_data(string);
  146. switch(ASN1_STRING_length(string)) {
  147. case 4:
  148. af = AF_INET;
  149. @@ -293,11 +304,11 @@ int meth_extensions(lua_State* L)
  150. break;
  151. /* Push ret[oid] */
  152. - push_asn1_objname(L, extension->object, 1);
  153. + push_asn1_objname(L, X509_EXTENSION_get_object(extension), 1);
  154. push_subtable(L, -2);
  155. /* Set ret[oid].name = name */
  156. - push_asn1_objname(L, extension->object, 0);
  157. + push_asn1_objname(L, X509_EXTENSION_get_object(extension), 0);
  158. lua_setfield(L, -2, "name");
  159. n_general_names = sk_GENERAL_NAME_num(values);
  160. @@ -404,7 +415,7 @@ static int meth_pubkey(lua_State* L)
  161. bytes = BIO_get_mem_data(bio, &data);
  162. if (bytes > 0) {
  163. lua_pushlstring(L, data, bytes);
  164. - switch(EVP_PKEY_type(pkey->type)) {
  165. + switch(EVP_PKEY_base_id(pkey)) {
  166. case EVP_PKEY_RSA:
  167. lua_pushstring(L, "RSA");
  168. break;