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.

147 lines
5.0 KiB

  1. diff --git a/folly/io/async/ssl/OpenSSLUtils.cpp b/folly/io/async/ssl/OpenSSLUtils.cpp
  2. index 0504cf8..a9c2775 100644
  3. --- a/folly/io/async/ssl/OpenSSLUtils.cpp
  4. +++ b/folly/io/async/ssl/OpenSSLUtils.cpp
  5. @@ -155,8 +155,12 @@ static std::unordered_map<uint16_t, std::string> getOpenSSLCipherNames() {
  6. SSL_CTX* ctx = nullptr;
  7. SSL* ssl = nullptr;
  8. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  9. const SSL_METHOD* meth = SSLv23_server_method();
  10. OpenSSL_add_ssl_algorithms();
  11. +#else
  12. + const SSL_METHOD* meth = TLS_server_method();
  13. +#endif
  14. if ((ctx = SSL_CTX_new(meth)) == nullptr) {
  15. return ret;
  16. diff --git a/folly/portability/OpenSSL.h b/folly/portability/OpenSSL.h
  17. index a4f4b04..427bf95 100644
  18. --- a/folly/portability/OpenSSL.h
  19. +++ b/folly/portability/OpenSSL.h
  20. @@ -27,6 +27,7 @@
  21. #include <openssl/asn1.h>
  22. #include <openssl/bio.h>
  23. +#include <openssl/bn.h>
  24. #include <openssl/crypto.h>
  25. #include <openssl/dh.h>
  26. #include <openssl/err.h>
  27. diff --git a/folly/ssl/OpenSSLCertUtils.cpp b/folly/ssl/OpenSSLCertUtils.cpp
  28. index 544bb4f..423dd2c 100644
  29. --- a/folly/ssl/OpenSSLCertUtils.cpp
  30. +++ b/folly/ssl/OpenSSLCertUtils.cpp
  31. @@ -155,12 +155,17 @@ folly::Optional<std::string> OpenSSLCertUtils::toString(X509& x509) {
  32. }
  33. }
  34. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  35. +#define X509_get0_notAfter X509_get_notAfter
  36. +#define X509_get0_notBefore X509_get_notBefore
  37. +#endif
  38. +
  39. std::string OpenSSLCertUtils::getNotAfterTime(X509& x509) {
  40. - return getDateTimeStr(X509_get_notAfter(&x509));
  41. + return getDateTimeStr(X509_get0_notAfter(&x509));
  42. }
  43. std::string OpenSSLCertUtils::getNotBeforeTime(X509& x509) {
  44. - return getDateTimeStr(X509_get_notBefore(&x509));
  45. + return getDateTimeStr(X509_get0_notBefore(&x509));
  46. }
  47. std::string OpenSSLCertUtils::getDateTimeStr(const ASN1_TIME* time) {
  48. diff --git a/folly/ssl/OpenSSLVersionFinder.h b/folly/ssl/OpenSSLVersionFinder.h
  49. index d0110d7..9d65580 100644
  50. --- a/folly/ssl/OpenSSLVersionFinder.h
  51. +++ b/folly/ssl/OpenSSLVersionFinder.h
  52. @@ -18,6 +18,12 @@
  53. #include <folly/Conv.h>
  54. #include <folly/portability/OpenSSL.h>
  55. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  56. +#define OPENSSL_VERSION SSLEAY_VERSION
  57. +#define OpenSSL_version SSLeay_version
  58. +#define OpenSSL_version_num SSLeay
  59. +#endif
  60. +
  61. // This is used to find the OpenSSL version at runtime. Just returning
  62. // OPENSSL_VERSION_NUMBER is insufficient as runtime version may be different
  63. // from the compile-time version
  64. @@ -25,7 +31,7 @@ namespace folly {
  65. namespace ssl {
  66. inline std::string getOpenSSLLongVersion() {
  67. #ifdef OPENSSL_VERSION_TEXT
  68. - return SSLeay_version(SSLEAY_VERSION);
  69. + return OpenSSL_version(OPENSSL_VERSION);
  70. #elif defined(OPENSSL_VERSION_NUMBER)
  71. return folly::format("0x{:x}", OPENSSL_VERSION_NUMBER).str();
  72. #else
  73. @@ -35,7 +41,7 @@ inline std::string getOpenSSLLongVersion() {
  74. inline uint64_t getOpenSSLNumericVersion() {
  75. #ifdef OPENSSL_VERSION_NUMBER
  76. - return SSLeay();
  77. + return OpenSSL_version_num();
  78. #else
  79. return 0;
  80. #endif
  81. diff --git a/folly/ssl/detail/OpenSSLThreading.cpp b/folly/ssl/detail/OpenSSLThreading.cpp
  82. index 3414fbd..ce345ab 100644
  83. --- a/folly/ssl/detail/OpenSSLThreading.cpp
  84. +++ b/folly/ssl/detail/OpenSSLThreading.cpp
  85. @@ -115,6 +115,7 @@ struct SSLLock {
  86. // SSLContext runs in such environments.
  87. // Instead of declaring a static member we "new" the static
  88. // member so that it won't be destructed on exit().
  89. +#if !FOLLY_SSL_DETAIL_OPENSSL_IS_110
  90. static std::unique_ptr<SSLLock[]>& locks() {
  91. static auto locksInst = new std::unique_ptr<SSLLock[]>();
  92. return *locksInst;
  93. @@ -128,8 +129,8 @@ static void callbackLocking(int mode, int n, const char*, int) {
  94. }
  95. }
  96. -static unsigned long callbackThreadID() {
  97. - return static_cast<unsigned long>(folly::getCurrentThreadID());
  98. +static void callbackThreadID(CRYPTO_THREADID *id) {
  99. + return CRYPTO_THREADID_set_numeric(id, folly::getCurrentThreadID());
  100. }
  101. static CRYPTO_dynlock_value* dyn_create(const char*, int) {
  102. @@ -150,28 +151,33 @@ dyn_lock(int mode, struct CRYPTO_dynlock_value* lock, const char*, int) {
  103. static void dyn_destroy(struct CRYPTO_dynlock_value* lock, const char*, int) {
  104. delete lock;
  105. }
  106. +#endif
  107. void installThreadingLocks() {
  108. +#if !FOLLY_SSL_DETAIL_OPENSSL_IS_110
  109. // static locking
  110. locks() = std::make_unique<SSLLock[]>(size_t(CRYPTO_num_locks()));
  111. for (auto it : lockTypes()) {
  112. locks()[size_t(it.first)].lockType = it.second;
  113. }
  114. - CRYPTO_set_id_callback(callbackThreadID);
  115. + CRYPTO_THREADID_set_callback(callbackThreadID);
  116. CRYPTO_set_locking_callback(callbackLocking);
  117. // dynamic locking
  118. CRYPTO_set_dynlock_create_callback(dyn_create);
  119. CRYPTO_set_dynlock_lock_callback(dyn_lock);
  120. CRYPTO_set_dynlock_destroy_callback(dyn_destroy);
  121. +#endif
  122. }
  123. void cleanupThreadingLocks() {
  124. - CRYPTO_set_id_callback(nullptr);
  125. +#if !FOLLY_SSL_DETAIL_OPENSSL_IS_110
  126. + CRYPTO_THREADID_set_callback(nullptr);
  127. CRYPTO_set_locking_callback(nullptr);
  128. CRYPTO_set_dynlock_create_callback(nullptr);
  129. CRYPTO_set_dynlock_lock_callback(nullptr);
  130. CRYPTO_set_dynlock_destroy_callback(nullptr);
  131. locks().reset();
  132. +#endif
  133. }
  134. } // namespace detail