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.

131 lines
2.9 KiB

  1. From c4c8aa5ba0ec6bf4c6d74c4807b66edfbd91be7c Mon Sep 17 00:00:00 2001
  2. From: Rosen Penev <rosenp@gmail.com>
  3. Date: Mon, 11 Jan 2021 01:51:58 -0800
  4. Subject: [PATCH] fix compilation without deprecated OpenSSL APIs
  5. (De)initialization is deprecated under OpenSSL 1.0 and above.
  6. [TT: Some simplifications, and additional edits.]
  7. Signed-off-by: Rosen Penev <rosenp@gmail.com>
  8. ---
  9. libfetch/common.c | 12 ++++--------
  10. src/apk.c | 26 +-------------------------
  11. src/apk_openssl.h | 27 +++++++++++++++++++++++++++
  12. 3 files changed, 32 insertions(+), 33 deletions(-)
  13. --- a/libfetch/common.c
  14. +++ b/libfetch/common.c
  15. @@ -499,15 +499,11 @@ static int fetch_ssl_setup_client_certif
  16. int
  17. fetch_ssl(conn_t *conn, const struct url *URL, int verbose)
  18. {
  19. - /* Init the SSL library and context */
  20. - if (!SSL_library_init()){
  21. - fprintf(stderr, "SSL library init failed\n");
  22. - return (-1);
  23. - }
  24. -
  25. - SSL_load_error_strings();
  26. -
  27. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  28. conn->ssl_meth = SSLv23_client_method();
  29. +#else
  30. + conn->ssl_meth = TLS_client_method();
  31. +#endif
  32. conn->ssl_ctx = SSL_CTX_new(conn->ssl_meth);
  33. SSL_CTX_set_mode(conn->ssl_ctx, SSL_MODE_AUTO_RETRY);
  34. --- a/src/apk.c
  35. +++ b/src/apk.c
  36. @@ -20,11 +20,6 @@
  37. #include <unistd.h>
  38. #include <sys/stat.h>
  39. -#include <openssl/crypto.h>
  40. -#ifndef OPENSSL_NO_ENGINE
  41. -#include <openssl/engine.h>
  42. -#endif
  43. -
  44. #include <fetch.h>
  45. #include "apk_defines.h"
  46. @@ -385,25 +380,6 @@ static int parse_options(int argc, char
  47. return 0;
  48. }
  49. -static void fini_openssl(void)
  50. -{
  51. - EVP_cleanup();
  52. -#ifndef OPENSSL_NO_ENGINE
  53. - ENGINE_cleanup();
  54. -#endif
  55. - CRYPTO_cleanup_all_ex_data();
  56. -}
  57. -
  58. -static void init_openssl(void)
  59. -{
  60. - atexit(fini_openssl);
  61. - OpenSSL_add_all_algorithms();
  62. -#ifndef OPENSSL_NO_ENGINE
  63. - ENGINE_load_builtin_engines();
  64. - ENGINE_register_all_complete();
  65. -#endif
  66. -}
  67. -
  68. static void on_sigwinch(int s)
  69. {
  70. apk_reset_screen_width();
  71. @@ -484,7 +460,7 @@ int main(int argc, char **argv)
  72. apk_force |= applet->forced_force;
  73. }
  74. - init_openssl();
  75. + apk_openssl_init();
  76. setup_automatic_flags();
  77. fetchConnectionCacheInit(32, 4);
  78. --- a/src/apk_openssl.h
  79. +++ b/src/apk_openssl.h
  80. @@ -11,7 +11,11 @@
  81. #define APK_SSL_COMPAT_H
  82. #include <openssl/opensslv.h>
  83. +#include <openssl/crypto.h>
  84. #include <openssl/evp.h>
  85. +#ifndef OPENSSL_NO_ENGINE
  86. +#include <openssl/engine.h>
  87. +#endif
  88. #if OPENSSL_VERSION_NUMBER < 0x1010000fL || (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL)
  89. @@ -25,6 +29,29 @@ static inline void EVP_MD_CTX_free(EVP_M
  90. return EVP_MD_CTX_destroy(mdctx);
  91. }
  92. +static inline void apk_openssl_cleanup(void)
  93. +{
  94. + EVP_cleanup();
  95. +#ifndef OPENSSL_NO_ENGINE
  96. + ENGINE_cleanup();
  97. +#endif
  98. + CRYPTO_cleanup_all_ex_data();
  99. +}
  100. +
  101. +static inline void apk_openssl_init(void)
  102. +{
  103. + atexit(apk_openssl_cleanup);
  104. + OpenSSL_add_all_algorithms();
  105. +#ifndef OPENSSL_NO_ENGINE
  106. + ENGINE_load_builtin_engines();
  107. + ENGINE_register_all_complete();
  108. +#endif
  109. +}
  110. +
  111. +#else
  112. +
  113. +static inline void apk_openssl_init(void) {}
  114. +
  115. #endif
  116. #endif