From 3cdde0f425971dc586b2a0f7de68a2fe0ca6e6d1 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 27 Aug 2016 00:35:28 +0900 Subject: [PATCH] Compile with openssl 1.1.0 We moved @CPPUNIT_LIBS@ to later position. This is because in my development environment, it adds linker search directory which contains system default openssl, while I'd like to use my custom openssl installation. This fix is not universal, since other libraries can do the same thing. It is a bit hard to fix this properly because we mix -L and -l in a same variable. --- src/LibsslMessageDigestImpl.cc | 6 ++--- src/LibsslTLSSession.cc | 14 ++++++++--- src/LibsslTLSSession.h | 1 + src/libssl_compat.h | 43 ++++++++++++++++++++++++++++++++++ test/Makefile.am | 2 +- 5 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 src/libssl_compat.h diff --git a/src/LibsslMessageDigestImpl.cc b/src/LibsslMessageDigestImpl.cc index 15ebccbe..11c107f6 100644 --- a/src/LibsslMessageDigestImpl.cc +++ b/src/LibsslMessageDigestImpl.cc @@ -38,10 +38,11 @@ #include #include "Adler32MessageDigestImpl.h" +#include "libssl_compat.h" namespace aria2 { -#if defined(LIBRESSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100001L +#if !OPENSSL_101_API namespace { EVP_MD_CTX* EVP_MD_CTX_new() { return EVP_MD_CTX_create(); } } // namespace @@ -57,8 +58,7 @@ int EVP_MD_CTX_reset(EVP_MD_CTX* ctx) return 1; } } // namespace -#endif // defined(LIBRESSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < - // 0x10100001L +#endif // !OPENSSL_101_API template class MessageDigestBase : public MessageDigestImpl { diff --git a/src/LibsslTLSSession.cc b/src/LibsslTLSSession.cc index 1014c3ca..f7024b1c 100644 --- a/src/LibsslTLSSession.cc +++ b/src/LibsslTLSSession.cc @@ -44,6 +44,15 @@ namespace aria2 { +#if !OPENSSL_101_API +namespace { +const unsigned char* ASN1_STRING_get0_data(ASN1_STRING* x) +{ + return ASN1_STRING_data(x); +} +} // namespace +#endif // !OPENSSL_101_API + TLSSession* TLSSession::make(TLSContext* ctx) { return new OpenSSLTLSSession(static_cast(ctx)); @@ -253,8 +262,7 @@ int OpenSSLTLSSession::tlsConnect(const std::string& hostname, for (size_t i = 0; i < n; ++i) { const GENERAL_NAME* altName = sk_GENERAL_NAME_value(altNames, i); if (altName->type == GEN_DNS) { - const char* name = - reinterpret_cast(ASN1_STRING_data(altName->d.ia5)); + auto name = ASN1_STRING_get0_data(altName->d.ia5); if (!name) { continue; } @@ -268,7 +276,7 @@ int OpenSSLTLSSession::tlsConnect(const std::string& hostname, continue; } } - dnsNames.push_back(std::string(name, len)); + dnsNames.push_back(std::string(name, name + len)); } else if (altName->type == GEN_IPADD) { const unsigned char* ipAddr = altName->d.iPAddress->data; diff --git a/src/LibsslTLSSession.h b/src/LibsslTLSSession.h index 5964aa21..7bc5a50c 100644 --- a/src/LibsslTLSSession.h +++ b/src/LibsslTLSSession.h @@ -42,6 +42,7 @@ #include "LibsslTLSContext.h" #include "TLSSession.h" #include "a2netcompat.h" +#include "libssl_compat.h" namespace aria2 { diff --git a/src/libssl_compat.h b/src/libssl_compat.h new file mode 100644 index 00000000..fa8e6f65 --- /dev/null +++ b/src/libssl_compat.h @@ -0,0 +1,43 @@ +/* */ +#ifndef LIBSSL_COMPAT_H +#define LIBSSL_COMPAT_H + +#include + +#define OPENSSL_101_API \ + (!defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x1010000fL) + +#endif // LIBSSL_COMPAT_H diff --git a/test/Makefile.am b/test/Makefile.am index 2315882f..48a962ec 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -243,7 +243,6 @@ endif # ENABLE_LIBARIA2 aria2c_LDADD = \ ../src/libaria2.la \ @LIBINTL@ \ - @CPPUNIT_LIBS@ \ @EXTRALIBS@ \ @ZLIB_LIBS@ \ @LIBUV_LIBS@ \ @@ -259,6 +258,7 @@ aria2c_LDADD = \ @LIBSSH2_LIBS@ \ @LIBCARES_LIBS@ \ @WSLAY_LIBS@ \ + @CPPUNIT_LIBS@ \ @TCMALLOC_LIBS@ \ @JEMALLOC_LIBS@