From 3f7ee8aa9c32ab67400e712ba7d62772555c68f6 Mon Sep 17 00:00:00 2001 From: Tony Theodore Date: Thu, 1 Mar 2018 17:40:15 +1100 Subject: [PATCH] boost: fix openssl1.1 use asio from boost 1.62 --- src/boost-1-fixes.patch | 495 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 494 insertions(+), 1 deletion(-) diff --git a/src/boost-1-fixes.patch b/src/boost-1-fixes.patch index 7d89cf9a..4816ef40 100644 --- a/src/boost-1-fixes.patch +++ b/src/boost-1-fixes.patch @@ -5,7 +5,7 @@ Contains ad hoc patches for cross building. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: xantares Date: Mon, 28 Sep 2015 08:21:42 +0000 -Subject: [PATCH 1/1] Fix {make,jump}_fcontext visibility with mingw +Subject: [PATCH 1/2] Fix {make,jump}_fcontext visibility with mingw taken from: https://github.com/boostorg/context/pull/22 @@ -53,3 +53,496 @@ index 1111111..2222222 100644 + +.section .drectve +.ascii " -export:\"make_fcontext\"" + +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Tony Theodore +Date: Wed, 28 Feb 2018 19:43:45 +1100 +Subject: [PATCH 2/2] fast-forward asio/ssl from 1.62 release + + +diff --git a/boost/asio/ssl/detail/impl/engine.ipp b/boost/asio/ssl/detail/impl/engine.ipp +index 1111111..2222222 100644 +--- a/boost/asio/ssl/detail/impl/engine.ipp ++++ b/boost/asio/ssl/detail/impl/engine.ipp +@@ -203,23 +203,21 @@ const boost::system::error_code& engine::map_error_code( + // If there's data yet to be read, it's an error. + if (BIO_wpending(ext_bio_)) + { +- ec = boost::system::error_code( +- ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ), +- boost::asio::error::get_ssl_category()); ++ ec = boost::asio::ssl::error::stream_truncated; + return ec; + } + + // SSL v2 doesn't provide a protocol-level shutdown, so an eof on the + // underlying transport is passed through. ++#if (OPENSSL_VERSION_NUMBER < 0x10100000L) + if (ssl_->version == SSL2_VERSION) + return ec; ++#endif // (OPENSSL_VERSION_NUMBER < 0x10100000L) + + // Otherwise, the peer should have negotiated a proper shutdown. + if ((::SSL_get_shutdown(ssl_) & SSL_RECEIVED_SHUTDOWN) == 0) + { +- ec = boost::system::error_code( +- ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ), +- boost::asio::error::get_ssl_category()); ++ ec = boost::asio::ssl::error::stream_truncated; + } + + return ec; +diff --git a/boost/asio/ssl/detail/impl/openssl_init.ipp b/boost/asio/ssl/detail/impl/openssl_init.ipp +index 1111111..2222222 100644 +--- a/boost/asio/ssl/detail/impl/openssl_init.ipp ++++ b/boost/asio/ssl/detail/impl/openssl_init.ipp +@@ -40,11 +40,15 @@ public: + ::SSL_load_error_strings(); + ::OpenSSL_add_all_algorithms(); + ++#if (OPENSSL_VERSION_NUMBER < 0x10100000L) + mutexes_.resize(::CRYPTO_num_locks()); + for (size_t i = 0; i < mutexes_.size(); ++i) + mutexes_[i].reset(new boost::asio::detail::mutex); + ::CRYPTO_set_locking_callback(&do_init::openssl_locking_func); ++#endif // (OPENSSL_VERSION_NUMBER < 0x10100000L) ++#if (OPENSSL_VERSION_NUMBER < 0x10000000L) + ::CRYPTO_set_id_callback(&do_init::openssl_id_func); ++#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L) + + #if !defined(SSL_OP_NO_COMPRESSION) \ + && (OPENSSL_VERSION_NUMBER >= 0x00908000L) +@@ -61,20 +65,33 @@ public: + #endif // !defined(SSL_OP_NO_COMPRESSION) + // && (OPENSSL_VERSION_NUMBER >= 0x00908000L) + ++#if (OPENSSL_VERSION_NUMBER < 0x10000000L) + ::CRYPTO_set_id_callback(0); ++#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L) ++#if (OPENSSL_VERSION_NUMBER < 0x10100000L) + ::CRYPTO_set_locking_callback(0); + ::ERR_free_strings(); +-#if (OPENSSL_VERSION_NUMBER >= 0x10000000L) +- ::ERR_remove_thread_state(NULL); +-#else // (OPENSSL_VERSION_NUMBER >= 0x10000000L) +- ::ERR_remove_state(0); +-#endif // (OPENSSL_VERSION_NUMBER >= 0x10000000L) + ::EVP_cleanup(); + ::CRYPTO_cleanup_all_ex_data(); ++#endif // (OPENSSL_VERSION_NUMBER < 0x10100000L) ++#if (OPENSSL_VERSION_NUMBER < 0x10000000L) ++ ::ERR_remove_state(0); ++#elif (OPENSSL_VERSION_NUMBER < 0x10100000L) ++ ::ERR_remove_thread_state(NULL); ++#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L) ++#if (OPENSSL_VERSION_NUMBER >= 0x10002000L) \ ++ && (OPENSSL_VERSION_NUMBER < 0x10100000L) ++ ::SSL_COMP_free_compression_methods(); ++#endif // (OPENSSL_VERSION_NUMBER >= 0x10002000L) ++ // && (OPENSSL_VERSION_NUMBER < 0x10100000L) ++#if !defined(OPENSSL_IS_BORINGSSL) + ::CONF_modules_unload(1); +-#if !defined(OPENSSL_NO_ENGINE) ++#endif // !defined(OPENSSL_IS_BORINGSSL) ++#if !defined(OPENSSL_NO_ENGINE) \ ++ && (OPENSSL_VERSION_NUMBER < 0x10100000L) + ::ENGINE_cleanup(); + #endif // !defined(OPENSSL_NO_ENGINE) ++ // && (OPENSSL_VERSION_NUMBER < 0x10100000L) + } + + #if !defined(SSL_OP_NO_COMPRESSION) \ +@@ -87,19 +104,20 @@ public: + // && (OPENSSL_VERSION_NUMBER >= 0x00908000L) + + private: ++#if (OPENSSL_VERSION_NUMBER < 0x10000000L) + static unsigned long openssl_id_func() + { + #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) + return ::GetCurrentThreadId(); + #else // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) +- void* id = instance()->thread_id_; +- if (id == 0) +- instance()->thread_id_ = id = &id; // Ugh. ++ void* id = &errno; + BOOST_ASIO_ASSERT(sizeof(unsigned long) >= sizeof(void*)); + return reinterpret_cast(id); + #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) + } ++#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L) + ++#if (OPENSSL_VERSION_NUMBER < 0x10100000L) + static void openssl_locking_func(int mode, int n, + const char* /*file*/, int /*line*/) + { +@@ -112,11 +130,7 @@ private: + // Mutexes to be used in locking callbacks. + std::vector > mutexes_; +- +-#if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) +- // The thread identifiers to be used by openssl. +- boost::asio::detail::tss_ptr thread_id_; +-#endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) ++#endif // (OPENSSL_VERSION_NUMBER < 0x10100000L) + + #if !defined(SSL_OP_NO_COMPRESSION) \ + && (OPENSSL_VERSION_NUMBER >= 0x00908000L) +diff --git a/boost/asio/ssl/detail/openssl_types.hpp b/boost/asio/ssl/detail/openssl_types.hpp +index 1111111..2222222 100644 +--- a/boost/asio/ssl/detail/openssl_types.hpp ++++ b/boost/asio/ssl/detail/openssl_types.hpp +@@ -21,7 +21,9 @@ + #if !defined(OPENSSL_NO_ENGINE) + # include + #endif // !defined(OPENSSL_NO_ENGINE) ++#include + #include ++#include + #include + #include + +diff --git a/boost/asio/ssl/error.hpp b/boost/asio/ssl/error.hpp +index 1111111..2222222 100644 +--- a/boost/asio/ssl/error.hpp ++++ b/boost/asio/ssl/error.hpp +@@ -26,6 +26,7 @@ namespace error { + + enum ssl_errors + { ++ // Error numbers are those produced by openssl. + }; + + extern BOOST_ASIO_DECL +@@ -35,6 +36,29 @@ static const boost::system::error_category& ssl_category + = boost::asio::error::get_ssl_category(); + + } // namespace error ++namespace ssl { ++namespace error { ++ ++enum stream_errors ++{ ++#if defined(GENERATING_DOCUMENTATION) ++ /// The underlying stream closed before the ssl stream gracefully shut down. ++ stream_truncated ++#elif (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL) ++ stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ) ++#else ++ stream_truncated = 1 ++#endif ++}; ++ ++extern BOOST_ASIO_DECL ++const boost::system::error_category& get_stream_category(); ++ ++static const boost::system::error_category& stream_category ++ = boost::asio::ssl::error::get_stream_category(); ++ ++} // namespace error ++} // namespace ssl + } // namespace asio + } // namespace boost + +@@ -46,6 +70,11 @@ template<> struct is_error_code_enum + static const bool value = true; + }; + ++template<> struct is_error_code_enum ++{ ++ static const bool value = true; ++}; ++ + } // namespace system + } // namespace boost + +@@ -60,6 +89,17 @@ inline boost::system::error_code make_error_code(ssl_errors e) + } + + } // namespace error ++namespace ssl { ++namespace error { ++ ++inline boost::system::error_code make_error_code(stream_errors e) ++{ ++ return boost::system::error_code( ++ static_cast(e), get_stream_category()); ++} ++ ++} // namespace error ++} // namespace ssl + } // namespace asio + } // namespace boost + +diff --git a/boost/asio/ssl/impl/context.ipp b/boost/asio/ssl/impl/context.ipp +index 1111111..2222222 100644 +--- a/boost/asio/ssl/impl/context.ipp ++++ b/boost/asio/ssl/impl/context.ipp +@@ -71,7 +71,8 @@ context::context(context::method m) + + switch (m) + { +-#if defined(OPENSSL_NO_SSL2) ++#if defined(OPENSSL_NO_SSL2) \ ++ || (OPENSSL_VERSION_NUMBER >= 0x10100000L) + case context::sslv2: + case context::sslv2_client: + case context::sslv2_server: +@@ -79,6 +80,7 @@ context::context(context::method m) + boost::asio::error::invalid_argument, "context"); + break; + #else // defined(OPENSSL_NO_SSL2) ++ // || (OPENSSL_VERSION_NUMBER >= 0x10100000L) + case context::sslv2: + handle_ = ::SSL_CTX_new(::SSLv2_method()); + break; +@@ -89,6 +91,7 @@ context::context(context::method m) + handle_ = ::SSL_CTX_new(::SSLv2_server_method()); + break; + #endif // defined(OPENSSL_NO_SSL2) ++ // || (OPENSSL_VERSION_NUMBER >= 0x10100000L) + #if defined(OPENSSL_NO_SSL3) + case context::sslv3: + case context::sslv3_client: +@@ -107,6 +110,7 @@ context::context(context::method m) + handle_ = ::SSL_CTX_new(::SSLv3_server_method()); + break; + #endif // defined(OPENSSL_NO_SSL3) ++#if (OPENSSL_VERSION_NUMBER < 0x10100000L) + case context::tlsv1: + handle_ = ::SSL_CTX_new(::TLSv1_method()); + break; +@@ -116,6 +120,7 @@ context::context(context::method m) + case context::tlsv1_server: + handle_ = ::SSL_CTX_new(::TLSv1_server_method()); + break; ++#endif // (OPENSSL_VERSION_NUMBER < 0x10100000L) + case context::sslv23: + handle_ = ::SSL_CTX_new(::SSLv23_method()); + break; +@@ -125,6 +130,7 @@ context::context(context::method m) + case context::sslv23_server: + handle_ = ::SSL_CTX_new(::SSLv23_server_method()); + break; ++#if (OPENSSL_VERSION_NUMBER < 0x10100000L) + #if defined(SSL_TXT_TLSV1_1) + case context::tlsv11: + handle_ = ::SSL_CTX_new(::TLSv1_1_method()); +@@ -161,6 +167,23 @@ context::context(context::method m) + boost::asio::error::invalid_argument, "context"); + break; + #endif // defined(SSL_TXT_TLSV1_2) ++#else // (OPENSSL_VERSION_NUMBER < 0x10100000L) ++ case context::tlsv1: ++ case context::tlsv11: ++ case context::tlsv12: ++ handle_ = ::SSL_CTX_new(::TLS_method()); ++ break; ++ case context::tlsv1_client: ++ case context::tlsv11_client: ++ case context::tlsv12_client: ++ handle_ = ::SSL_CTX_new(::TLS_client_method()); ++ break; ++ case context::tlsv1_server: ++ case context::tlsv11_server: ++ case context::tlsv12_server: ++ handle_ = ::SSL_CTX_new(::TLS_server_method()); ++ break; ++#endif // (OPENSSL_VERSION_NUMBER < 0x10100000L) + default: + handle_ = ::SSL_CTX_new(0); + break; +@@ -205,13 +228,22 @@ context::~context() + { + if (handle_) + { +- if (handle_->default_passwd_callback_userdata) ++#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ void* cb_userdata = ::SSL_CTX_get_default_passwd_cb_userdata(handle_); ++#else // (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ void* cb_userdata = handle_->default_passwd_callback_userdata; ++#endif // (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ if (cb_userdata) + { + detail::password_callback_base* callback = + static_cast( +- handle_->default_passwd_callback_userdata); ++ cb_userdata); + delete callback; ++#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ ::SSL_CTX_set_default_passwd_cb_userdata(handle_, 0); ++#else // (OPENSSL_VERSION_NUMBER >= 0x10100000L) + handle_->default_passwd_callback_userdata = 0; ++#endif // (OPENSSL_VERSION_NUMBER >= 0x10100000L) + } + + if (SSL_CTX_get_app_data(handle_)) +@@ -546,10 +578,17 @@ boost::system::error_code context::use_certificate_chain( + bio_cleanup bio = { make_buffer_bio(chain) }; + if (bio.p) + { ++#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ pem_password_cb* callback = ::SSL_CTX_get_default_passwd_cb(handle_); ++ void* cb_userdata = ::SSL_CTX_get_default_passwd_cb_userdata(handle_); ++#else // (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ pem_password_cb* callback = handle_->default_passwd_callback; ++ void* cb_userdata = handle_->default_passwd_callback_userdata; ++#endif // (OPENSSL_VERSION_NUMBER >= 0x10100000L) + x509_cleanup cert = { + ::PEM_read_bio_X509_AUX(bio.p, 0, +- handle_->default_passwd_callback, +- handle_->default_passwd_callback_userdata) }; ++ callback, ++ cb_userdata) }; + if (!cert.p) + { + ec = boost::system::error_code(ERR_R_PEM_LIB, +@@ -577,8 +616,8 @@ boost::system::error_code context::use_certificate_chain( + #endif // (OPENSSL_VERSION_NUMBER >= 0x10002000L) + + while (X509* cacert = ::PEM_read_bio_X509(bio.p, 0, +- handle_->default_passwd_callback, +- handle_->default_passwd_callback_userdata)) ++ callback, ++ cb_userdata)) + { + if (!::SSL_CTX_add_extra_chain_cert(handle_, cacert)) + { +@@ -643,6 +682,14 @@ boost::system::error_code context::use_private_key( + { + ::ERR_clear_error(); + ++#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ pem_password_cb* callback = ::SSL_CTX_get_default_passwd_cb(handle_); ++ void* cb_userdata = ::SSL_CTX_get_default_passwd_cb_userdata(handle_); ++#else // (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ pem_password_cb* callback = handle_->default_passwd_callback; ++ void* cb_userdata = handle_->default_passwd_callback_userdata; ++#endif // (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ + bio_cleanup bio = { make_buffer_bio(private_key) }; + if (bio.p) + { +@@ -654,8 +701,8 @@ boost::system::error_code context::use_private_key( + break; + case context_base::pem: + evp_private_key.p = ::PEM_read_bio_PrivateKey( +- bio.p, 0, handle_->default_passwd_callback, +- handle_->default_passwd_callback_userdata); ++ bio.p, 0, callback, ++ cb_userdata); + break; + default: + { +@@ -702,6 +749,14 @@ boost::system::error_code context::use_rsa_private_key( + { + ::ERR_clear_error(); + ++#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ pem_password_cb* callback = ::SSL_CTX_get_default_passwd_cb(handle_); ++ void* cb_userdata = ::SSL_CTX_get_default_passwd_cb_userdata(handle_); ++#else // (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ pem_password_cb* callback = handle_->default_passwd_callback; ++ void* cb_userdata = handle_->default_passwd_callback_userdata; ++#endif // (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ + bio_cleanup bio = { make_buffer_bio(private_key) }; + if (bio.p) + { +@@ -713,8 +768,8 @@ boost::system::error_code context::use_rsa_private_key( + break; + case context_base::pem: + rsa_private_key.p = ::PEM_read_bio_RSAPrivateKey( +- bio.p, 0, handle_->default_passwd_callback, +- handle_->default_passwd_callback_userdata); ++ bio.p, 0, callback, ++ cb_userdata); + break; + default: + { +@@ -933,11 +988,17 @@ int context::verify_callback_function(int preverified, X509_STORE_CTX* ctx) + boost::system::error_code context::do_set_password_callback( + detail::password_callback_base* callback, boost::system::error_code& ec) + { +- if (handle_->default_passwd_callback_userdata) +- delete static_cast( +- handle_->default_passwd_callback_userdata); +- ++#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ void* old_callback = ::SSL_CTX_get_default_passwd_cb_userdata(handle_); ++ ::SSL_CTX_set_default_passwd_cb_userdata(handle_, callback); ++#else // (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ void* old_callback = handle_->default_passwd_callback_userdata; + handle_->default_passwd_callback_userdata = callback; ++#endif // (OPENSSL_VERSION_NUMBER >= 0x10100000L) ++ ++ if (old_callback) ++ delete static_cast( ++ old_callback); + + SSL_CTX_set_default_passwd_cb(handle_, &context::password_callback_function); + +diff --git a/boost/asio/ssl/impl/error.ipp b/boost/asio/ssl/impl/error.ipp +index 1111111..2222222 100644 +--- a/boost/asio/ssl/impl/error.ipp ++++ b/boost/asio/ssl/impl/error.ipp +@@ -24,7 +24,6 @@ + namespace boost { + namespace asio { + namespace error { +- + namespace detail { + + class ssl_category : public boost::system::error_category +@@ -51,6 +50,50 @@ const boost::system::error_category& get_ssl_category() + } + + } // namespace error ++namespace ssl { ++namespace error { ++ ++#if (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL) ++ ++const boost::system::error_category& get_stream_category() ++{ ++ return boost::asio::error::get_ssl_category(); ++} ++ ++#else ++ ++namespace detail { ++ ++class stream_category : public boost::system::error_category ++{ ++public: ++ const char* name() const BOOST_ASIO_ERROR_CATEGORY_NOEXCEPT ++ { ++ return "asio.ssl.stream"; ++ } ++ ++ std::string message(int value) const ++ { ++ switch (value) ++ { ++ case stream_truncated: return "stream truncated"; ++ default: return "asio.ssl.stream error"; ++ } ++ } ++}; ++ ++} // namespace detail ++ ++const boost::system::error_category& get_stream_category() ++{ ++ static detail::stream_category instance; ++ return instance; ++} ++ ++#endif ++ ++} // namespace error ++} // namespace ssl + } // namespace asio + } // namespace boost +