Advertisement
Guest User

Untitled

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