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.

202 lines
5.8 KiB

  1. This patch has been tested with OpenSSL 1.0.2q, 1.1.0j and 1.1.1a
  2. with and without support for deprecated OpenSSL APIs.
  3. --- a/configure.ac
  4. +++ b/configure.ac
  5. @@ -860,26 +860,10 @@ then
  6. AC_SEARCH_LIBS([ERR_peek_error], [crypto], ,
  7. AC_MSG_ERROR([libcrypto not found]))
  8. - AC_SEARCH_LIBS([SSL_library_init], [ssl], ,
  9. - [
  10. - if test x"$enable_shared" = x"yes"
  11. - then
  12. - AC_MSG_ERROR([Cannot build shared opendkim
  13. - against static openssl libraries.
  14. - Configure with --disable-shared
  15. - to get this working or obtain a
  16. - shared libssl library for
  17. - opendkim to use.])
  18. - fi
  19. -
  20. - # avoid caching issue - last result of SSL_library_init
  21. - # shouldn't be cached for this next check
  22. - unset ac_cv_search_SSL_library_init
  23. - LIBCRYPTO_LIBS="$LIBCRYPTO_LIBS -ldl"
  24. - AC_SEARCH_LIBS([SSL_library_init], [ssl], ,
  25. - AC_MSG_ERROR([libssl not found]), [-ldl])
  26. - ]
  27. - )
  28. + od_have_ossl="no"
  29. + AC_CHECK_LIB(ssl, OPENSSL_init_ssl, [od_have_ossl="yes"])
  30. + AC_CHECK_LIB(ssl, SSL_library_init, [od_have_ossl="yes"])
  31. + AS_IF([test "x$od_have_ossl" = xno], [AC_MSG_ERROR([libssl not found])])
  32. AC_CHECK_DECL([SHA256_DIGEST_LENGTH],
  33. AC_DEFINE([HAVE_SHA256], 1,
  34. --- a/opendkim/opendkim-crypto.c
  35. +++ b/opendkim/opendkim-crypto.c
  36. @@ -139,6 +139,7 @@ static unsigned int nmutexes = 0;
  37. static unsigned long threadid = 0L;
  38. static pthread_mutex_t *mutexes = NULL;
  39. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  40. /*
  41. ** DKIMF_CRYPTO_LOCK_CALLBACK -- locking callback for libcrypto
  42. **
  43. @@ -166,6 +167,7 @@ dkimf_crypto_lock_callback(int mode, int
  44. assert(status == 0);
  45. }
  46. +#endif
  47. /*
  48. ** DKIMF_CRYPTO_GET_ID -- generate/retrieve thread ID
  49. @@ -208,21 +210,15 @@ dkimf_crypto_get_id(void)
  50. static void
  51. dkimf_crypto_free_id(void *ptr)
  52. {
  53. - /*
  54. - ** Trick dkimf_crypto_get_id(); the thread-specific pointer has
  55. - ** already been cleared at this point, but dkimf_crypto_get_id()
  56. - ** may be called by ERR_remove_state() which will then allocate a
  57. - ** new thread pointer if the thread-specific pointer is NULL. This
  58. - ** means a memory leak of thread IDs and, on Solaris, an infinite loop
  59. - ** because the destructor (indirectly) re-sets the thread-specific
  60. - ** pointer to something not NULL. See pthread_key_create(3).
  61. - */
  62. -
  63. if (ptr != NULL)
  64. {
  65. assert(pthread_setspecific(id_key, ptr) == 0);
  66. - ERR_remove_state(0);
  67. +#if OPENSSL_VERSION_NUMBER >= 0x10100000
  68. + OPENSSL_thread_stop();
  69. +#else
  70. + ERR_remove_thread_state(NULL);
  71. +#endif
  72. free(ptr);
  73. @@ -300,6 +296,7 @@ dkimf_crypto_dyn_destroy(struct CRYPTO_d
  74. ** None.
  75. */
  76. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  77. static void
  78. dkimf_crypto_dyn_lock(int mode, struct CRYPTO_dynlock_value *lock,
  79. /* UNUSED */ const char *file,
  80. @@ -316,6 +313,7 @@ dkimf_crypto_dyn_lock(int mode, struct C
  81. assert(status == 0);
  82. }
  83. +#endif
  84. /*
  85. ** DKIMF_CRYPTO_INIT -- set up openssl dependencies
  86. @@ -335,7 +333,12 @@ dkimf_crypto_init(void)
  87. int n;
  88. int status;
  89. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  90. n = CRYPTO_num_locks();
  91. +#else
  92. + // see openssl/crypto.h for more details
  93. + n = 1;
  94. +#endif
  95. mutexes = (pthread_mutex_t *) malloc(n * sizeof(pthread_mutex_t));
  96. if (mutexes == NULL)
  97. return errno;
  98. @@ -357,15 +360,22 @@ dkimf_crypto_init(void)
  99. if (status != 0)
  100. return status;
  101. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  102. SSL_load_error_strings();
  103. SSL_library_init();
  104. ERR_load_crypto_strings();
  105. +#else
  106. + OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
  107. + OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
  108. +#endif
  109. +#if OPENSSL_VERSION_NUMBER < 0x10000000
  110. CRYPTO_set_id_callback(&dkimf_crypto_get_id);
  111. CRYPTO_set_locking_callback(&dkimf_crypto_lock_callback);
  112. CRYPTO_set_dynlock_create_callback(&dkimf_crypto_dyn_create);
  113. CRYPTO_set_dynlock_lock_callback(&dkimf_crypto_dyn_lock);
  114. CRYPTO_set_dynlock_destroy_callback(&dkimf_crypto_dyn_destroy);
  115. +#endif
  116. #ifdef USE_OPENSSL_ENGINE
  117. if (!SSL_set_engine(NULL))
  118. @@ -392,11 +402,15 @@ dkimf_crypto_free(void)
  119. {
  120. if (crypto_init_done)
  121. {
  122. +#if OPENSSL_VERSION_NUMBER >= 0x10100000
  123. + OPENSSL_thread_stop();
  124. +#else
  125. CRYPTO_cleanup_all_ex_data();
  126. CONF_modules_free();
  127. EVP_cleanup();
  128. ERR_free_strings();
  129. - ERR_remove_state(0);
  130. + ERR_remove_thread_state(NULL);
  131. +#endif
  132. if (nmutexes > 0)
  133. {
  134. --- a/libopendkim/dkim.c
  135. +++ b/libopendkim/dkim.c
  136. @@ -4195,8 +4195,10 @@ dkim_init_openssl(void)
  137. {
  138. pthread_mutex_lock(&openssl_lock);
  139. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  140. if (openssl_refcount == 0)
  141. OpenSSL_add_all_algorithms();
  142. +#endif
  143. openssl_refcount++;
  144. pthread_mutex_unlock(&openssl_lock);
  145. @@ -4220,8 +4222,10 @@ dkim_close_openssl(void)
  146. pthread_mutex_lock(&openssl_lock);
  147. openssl_refcount--;
  148. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  149. if (openssl_refcount == 0)
  150. EVP_cleanup();
  151. +#endif
  152. pthread_mutex_unlock(&openssl_lock);
  153. }
  154. --- a/opendkim/opendkim-testkey.c
  155. +++ b/opendkim/opendkim-testkey.c
  156. @@ -452,7 +452,11 @@ main(int argc, char **argv)
  157. memset(err, '\0', sizeof err);
  158. #ifndef USE_GNUTLS
  159. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  160. ERR_load_crypto_strings();
  161. +#else
  162. + OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
  163. +#endif
  164. #endif /* ! USE_GNUTLS */
  165. /* process a KeyTable if specified and not overridden */
  166. --- a/opendkim/opendkim.c
  167. +++ b/opendkim/opendkim.c
  168. @@ -15540,7 +15540,11 @@ main(int argc, char **argv)
  169. printf("\tCompiled with GnuTLS %s\n", GNUTLS_VERSION);
  170. #else /* USE_GNUTLS */
  171. printf("\tCompiled with %s\n",
  172. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  173. SSLeay_version(SSLEAY_VERSION));
  174. +#else
  175. + OpenSSL_version(OPENSSL_VERSION));
  176. +#endif
  177. #endif /* USE_GNUTLS */
  178. printf("\tSMFI_VERSION 0x%x\n", SMFI_VERSION);
  179. #ifdef HAVE_SMFI_VERSION