From 03775fcdc5a118eb336d80d012a140f060053ab7 Mon Sep 17 00:00:00 2001 From: William Elwood Date: Sat, 3 Sep 2016 14:23:12 +0100 Subject: [PATCH] Fix compile errors caused by OpenSSL 1.1 --- modules/schat.cpp | 16 ++++++++-------- src/main.cpp | 10 +++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/modules/schat.cpp b/modules/schat.cpp index 703cf844..328e096f 100644 --- a/modules/schat.cpp +++ b/modules/schat.cpp @@ -25,6 +25,12 @@ #include #include +#if !defined(OPENSSL_VERSION_NUMBER) || defined(LIBRESSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100007 +/* SSL_SESSION was made opaque in OpenSSL 1.1.0, cipher accessor was added 2 weeks before the public release. +See openssl/openssl@e92813234318635639dba0168c7ef5568757449b. */ +# define SSL_SESSION_get0_cipher(pSession) ((pSession)->cipher) +#endif + using std::pair; using std::stringstream; using std::map; @@ -226,9 +232,7 @@ public: Table.SetCell("Host", pSock->GetRemoteIP()); Table.SetCell("Port", CString(pSock->GetRemotePort())); SSL_SESSION *pSession = pSock->GetSSLSession(); - if (pSession && pSession->cipher && pSession->cipher->name) - Table.SetCell("Cipher", pSession->cipher->name); - + Table.SetCell("Cipher", SSL_CIPHER_get_name(pSession ? SSL_SESSION_get0_cipher(pSession) : NULL)); } else { Table.SetCell("Status", "Waiting"); Table.SetCell("Port", CString(pSock->GetLocalPort())); @@ -286,11 +290,7 @@ public: Table.SetCell("RemoteIP:Port", pSock->GetRemoteIP() + ":" + CString(pSock->GetRemotePort())); SSL_SESSION *pSession = pSock->GetSSLSession(); - if (pSession && pSession->cipher && pSession->cipher->name) - Table.SetCell("Cipher", pSession->cipher->name); - else - Table.SetCell("Cipher", "None"); - + Table.SetCell("Cipher", SSL_CIPHER_get_name(pSession ? SSL_SESSION_get0_cipher(pSession) : NULL)); } else { Table.SetCell("Type", "Listener"); Table.SetCell("LocalIP:Port", pSock->GetLocalIP() + diff --git a/src/main.cpp b/src/main.cpp index 09b2c9cd..6d89e78a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,7 +17,15 @@ #include #include -#if defined(HAVE_LIBSSL) && defined(HAVE_PTHREAD) +#if defined(HAVE_LIBSSL) && defined(HAVE_PTHREAD) && ( !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100004 ) +/* Starting with version 1.1.0-pre4, OpenSSL has a new threading implementation that doesn't need locking callbacks. + "OpenSSL now uses a new threading API. It is no longer necessary to + set locking callbacks to use OpenSSL in a multi-threaded environment. There + are two supported threading models: pthreads and windows threads. It is + also possible to configure OpenSSL at compile time for "no-threads". The + old threading API should no longer be used. The functions have been + replaced with "no-op" compatibility macros." +See openssl/openssl@2e52e7df518d80188c865ea3f7bb3526d14b0c08. */ #include #include #include