option to use only the openssl's sha1 implementation (#845)

separated ssl and crypto build options
This commit is contained in:
Alden Torres 2016-06-23 13:20:35 -04:00 committed by Arvid Norberg
parent ce00ebf723
commit 436b781003
10 changed files with 97 additions and 39 deletions

View File

@ -212,6 +212,7 @@ if (encryption)
FIND_PACKAGE(OpenSSL REQUIRED) FIND_PACKAGE(OpenSSL REQUIRED)
endif() endif()
add_definitions(-DTORRENT_USE_OPENSSL) add_definitions(-DTORRENT_USE_OPENSSL)
add_definitions(-DTORRENT_USE_LIBCRYPTO)
include_directories(${OPENSSL_INCLUDE_DIR}) include_directories(${OPENSSL_INCLUDE_DIR})
else() else()
add_definitions(-DTORRENT_DISABLE_ENCRYPTION) add_definitions(-DTORRENT_DISABLE_ENCRYPTION)

View File

@ -1,3 +1,4 @@
* separated ssl and crypto options in build
* remove lazy-bitfield feature * remove lazy-bitfield feature
* simplified suggest-read-cache feature to not depend on disk threads * simplified suggest-read-cache feature to not depend on disk threads
* removed option to disable contiguous receive buffers * removed option to disable contiguous receive buffers

50
Jamfile
View File

@ -56,16 +56,24 @@ rule linking ( properties * )
{ {
local result ; local result ;
# ssl=openssl => crypto=libcrypto
# this match the previous behavior
if <ssl>openssl in $(properties)
&& ! <crypto>libcrypto in $(properties)
{
ECHO "with ssl=openssl the value for crypto must be libcrypto" ;
result += <build>no ;
}
# openssl libraries, if enabled # openssl libraries, if enabled
if <crypto>openssl in $(properties) if <ssl>openssl in $(properties)
{ {
# exclude gcc from a regular windows build to make mingw # exclude gcc from a regular windows build to make mingw
# link against the regular unix library name # link against the regular unix library name
if <target-os>windows in $(properties) if <target-os>windows in $(properties)
&& ! <toolset>gcc in $(properties) && ! <toolset>gcc in $(properties)
{ {
result += <library>ssleay32 result += <library>ssleay32
<library>libeay32
<library>advapi32 <library>advapi32
<library>user32 <library>user32
<library>shell32 <library>shell32
@ -74,7 +82,28 @@ rule linking ( properties * )
} }
else else
{ {
result += <library>crypto <library>ssl ; result += <library>ssl ;
}
}
if <crypto>libcrypto in $(properties)
{
# exclude gcc from a regular windows build to make mingw
# link against the regular unix library name
if <target-os>windows in $(properties)
&& ! <toolset>gcc in $(properties)
{
# it should be possible to cleanup this list, but this is safe for now
result += <library>libeay32
<library>advapi32
<library>user32
<library>shell32
<library>gdi32
;
}
else
{
result += <library>crypto ;
} }
} }
@ -95,7 +124,7 @@ rule linking ( properties * )
} }
# gcrypt libraries, if enabled # gcrypt libraries, if enabled
if <crypto>gcrypt in $(properties) if <crypto>libgcrypt in $(properties)
{ {
# on mac os x, adding the /opt/local/include path # on mac os x, adding the /opt/local/include path
# would include openssl headers incompatible with # would include openssl headers incompatible with
@ -455,9 +484,12 @@ feature.compose <encryption>off : <define>TORRENT_DISABLE_ENCRYPTION ;
feature mutable-torrents : on off : composite propagated link-incompatible ; feature mutable-torrents : on off : composite propagated link-incompatible ;
feature.compose <mutable-torrents>off : <define>TORRENT_DISABLE_MUTABLE_TORRENTS ; feature.compose <mutable-torrents>off : <define>TORRENT_DISABLE_MUTABLE_TORRENTS ;
feature crypto : built-in openssl gcrypt : composite propagated ; feature crypto : built-in libcrypto libgcrypt : composite propagated ;
feature.compose <crypto>openssl : <define>TORRENT_USE_OPENSSL <define>OPENSSL_NO_SSL2 ; feature.compose <crypto>libcrypto : <define>TORRENT_USE_LIBCRYPTO ;
feature.compose <crypto>gcrypt : <define>TORRENT_USE_GCRYPT ; feature.compose <crypto>libgcrypt : <define>TORRENT_USE_LIBGCRYPT ;
feature ssl : off openssl : composite propagated ;
feature.compose <ssl>openssl : <define>TORRENT_USE_OPENSSL <define>OPENSSL_NO_SSL2 ;
feature character-set : unicode ansi : composite propagated link-incompatible ; feature character-set : unicode ansi : composite propagated link-incompatible ;
feature.compose <character-set>unicode : <define>_UNICODE <define>UNICODE ; feature.compose <character-set>unicode : <define>_UNICODE <define>UNICODE ;
@ -494,7 +526,7 @@ variant test_release : release
<inlining>off <inlining>off
; ;
variant test_debug : debug variant test_debug : debug
: <crypto>openssl <logging>on <disk-stats>on : <ssl>openssl <crypto>libcrypto <logging>on <disk-stats>on
<allocator>debug <allocator>debug
<invariant-checks>full <boost-link>shared <invariant-checks>full <boost-link>shared
<export-extra>on <debug-iterators>on <threading>multi <asserts>on <export-extra>on <debug-iterators>on <threading>multi <asserts>on

View File

@ -386,7 +386,7 @@ AS_CASE(["$ARG_ENABLE_ENCRYPTION"],
AX_CHECK_OPENSSL([ AX_CHECK_OPENSSL([
AC_DEFINE([TORRENT_USE_OPENSSL],[1],[Define to use OpenSSL support.]) AC_DEFINE([TORRENT_USE_OPENSSL],[1],[Define to use OpenSSL support.])
COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DTORRENT_USE_OPENSSL " COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DTORRENT_USE_OPENSSL -DTORRENT_USE_LIBCRYPTO "
], [ ], [
AC_MSG_ERROR([OpenSSL library not found. Try using --with-openssl=DIR or disabling encryption at all.]) AC_MSG_ERROR([OpenSSL library not found. Try using --with-openssl=DIR or disabling encryption at all.])
]) ])

View File

@ -277,11 +277,18 @@ Build features:
| | * ``off`` - mutable torrents are not supported. | | | * ``off`` - mutable torrents are not supported. |
+--------------------------+----------------------------------------------------+ +--------------------------+----------------------------------------------------+
| ``crypto`` | * ``built-in`` - (default) uses built-in SHA-1 | | ``crypto`` | * ``built-in`` - (default) uses built-in SHA-1 |
| | implementation. | | | implementation. In macOS/iOS it uses |
| | * ``openssl`` - links against openssl and | | | CommonCrypto SHA-1 implementation. |
| | libcrypto to use for SHA-1 hashing. | | | * ``libcrypto`` - links against libcrypto |
| | * ``gcrypt`` - links against libgcrypt to use for | | | to use the SHA-1 implementation. |
| | SHA-1 hashing. | | | * ``libgcrypt`` - links against libgcrypt |
| | to use the SHA-1 implementation. |
+--------------------------+----------------------------------------------------+
| ``ssl`` | * ``off`` - (default) disable torrents over ssl |
| | feature. |
| | * ``openssl`` - links against openssl to enable |
| | torrents over ssl feature. Requires |
| | the option crypto=libcrypto. |
+--------------------------+----------------------------------------------------+ +--------------------------+----------------------------------------------------+
| ``allocator`` | * ``pool`` - default, uses pool allocators for | | ``allocator`` | * ``pool`` - default, uses pool allocators for |
| | send buffers. | | | send buffers. |
@ -566,8 +573,8 @@ defines you can use to control the build.
| | encrypted supported by clients such as | | | encrypted supported by clients such as |
| | uTorrent, Azureus and KTorrent. | | | uTorrent, Azureus and KTorrent. |
| | If this is not defined, either | | | If this is not defined, either |
| | ``TORRENT_USE_OPENSSL`` or | | | ``TORRENT_USE_LIBCRYPTO`` or |
| | ``TORRENT_USE_GCRYPT`` must be defined. | | | ``TORRENT_USE_LIBGCRYPT`` must be defined. |
+----------------------------------------+-------------------------------------------------+ +----------------------------------------+-------------------------------------------------+
| ``TORRENT_DISABLE_EXTENSIONS`` | When defined, libtorrent plugin support is | | ``TORRENT_DISABLE_EXTENSIONS`` | When defined, libtorrent plugin support is |
| | disabled along with support for the extension | | | disabled along with support for the extension |

View File

@ -136,7 +136,7 @@ POSSIBILITY OF SUCH DAMAGE.
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
// on OSX, use the built-in common crypto for built-in // on OSX, use the built-in common crypto for built-in
# if !defined TORRENT_USE_OPENSSL && !defined TORRENT_USE_GCRYPT # if !defined TORRENT_USE_LIBCRYPTO && !defined TORRENT_USE_LIBGCRYPT
# define TORRENT_USE_COMMONCRYPTO 1 # define TORRENT_USE_COMMONCRYPTO 1
# endif // TORRENT_USE_OPENSSL # endif // TORRENT_USE_OPENSSL
#endif // MAC_OS_X_VERSION_MIN_REQUIRED #endif // MAC_OS_X_VERSION_MIN_REQUIRED

View File

@ -39,14 +39,14 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cstdint> #include <cstdint>
#ifdef TORRENT_USE_GCRYPT #ifdef TORRENT_USE_LIBGCRYPT
#include <gcrypt.h> #include <gcrypt.h>
#elif TORRENT_USE_COMMONCRYPTO #elif TORRENT_USE_COMMONCRYPTO
#include <CommonCrypto/CommonDigest.h> #include <CommonCrypto/CommonDigest.h>
#elif defined TORRENT_USE_OPENSSL #elif defined TORRENT_USE_LIBCRYPTO
extern "C" extern "C"
{ {
@ -85,7 +85,7 @@ namespace libtorrent
// ``update(data, len)``. // ``update(data, len)``.
hasher(const char* data, int len); hasher(const char* data, int len);
#ifdef TORRENT_USE_GCRYPT #ifdef TORRENT_USE_LIBGCRYPT
hasher(hasher const& h); hasher(hasher const& h);
hasher& operator=(hasher const& h); hasher& operator=(hasher const& h);
#endif #endif
@ -105,11 +105,11 @@ namespace libtorrent
private: private:
#ifdef TORRENT_USE_GCRYPT #ifdef TORRENT_USE_LIBGCRYPT
gcry_md_hd_t m_context; gcry_md_hd_t m_context;
#elif TORRENT_USE_COMMONCRYPTO #elif TORRENT_USE_COMMONCRYPTO
CC_SHA1_CTX m_context; CC_SHA1_CTX m_context;
#elif defined TORRENT_USE_OPENSSL #elif defined TORRENT_USE_LIBCRYPTO
SHA_CTX m_context; SHA_CTX m_context;
#else #else
sha_ctx m_context; sha_ctx m_context;

View File

@ -190,7 +190,7 @@ namespace libtorrent
// see proxy_type. // see proxy_type.
proxy_hostname, proxy_hostname,
// when using a proxy, these are the credentials (if any) to use whne // when using a proxy, these are the credentials (if any) to use when
// connecting to it. see proxy_type // connecting to it. see proxy_type
proxy_username, proxy_username,
proxy_password, proxy_password,

View File

@ -31,17 +31,16 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "libtorrent/hasher.hpp" #include "libtorrent/hasher.hpp"
#include "libtorrent/sha1.hpp"
namespace libtorrent namespace libtorrent
{ {
hasher::hasher() hasher::hasher()
{ {
#ifdef TORRENT_USE_GCRYPT #ifdef TORRENT_USE_LIBGCRYPT
gcry_md_open(&m_context, GCRY_MD_SHA1, 0); gcry_md_open(&m_context, GCRY_MD_SHA1, 0);
#elif TORRENT_USE_COMMONCRYPTO #elif TORRENT_USE_COMMONCRYPTO
CC_SHA1_Init(&m_context); CC_SHA1_Init(&m_context);
#elif defined TORRENT_USE_OPENSSL #elif defined TORRENT_USE_LIBCRYPTO
SHA1_Init(&m_context); SHA1_Init(&m_context);
#else #else
SHA1_init(&m_context); SHA1_init(&m_context);
@ -52,13 +51,13 @@ namespace libtorrent
{ {
TORRENT_ASSERT(data != 0); TORRENT_ASSERT(data != 0);
TORRENT_ASSERT(len > 0); TORRENT_ASSERT(len > 0);
#ifdef TORRENT_USE_GCRYPT #ifdef TORRENT_USE_LIBGCRYPT
gcry_md_open(&m_context, GCRY_MD_SHA1, 0); gcry_md_open(&m_context, GCRY_MD_SHA1, 0);
gcry_md_write(m_context, data, len); gcry_md_write(m_context, data, len);
#elif TORRENT_USE_COMMONCRYPTO #elif TORRENT_USE_COMMONCRYPTO
CC_SHA1_Init(&m_context); CC_SHA1_Init(&m_context);
CC_SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len); CC_SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
#elif defined TORRENT_USE_OPENSSL #elif defined TORRENT_USE_LIBCRYPTO
SHA1_Init(&m_context); SHA1_Init(&m_context);
SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len); SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
#else #else
@ -67,7 +66,7 @@ namespace libtorrent
#endif #endif
} }
#ifdef TORRENT_USE_GCRYPT #ifdef TORRENT_USE_LIBGCRYPT
hasher::hasher(hasher const& h) hasher::hasher(hasher const& h)
{ {
gcry_md_copy(&m_context, h.m_context); gcry_md_copy(&m_context, h.m_context);
@ -85,11 +84,11 @@ namespace libtorrent
{ {
TORRENT_ASSERT(data != 0); TORRENT_ASSERT(data != 0);
TORRENT_ASSERT(len > 0); TORRENT_ASSERT(len > 0);
#ifdef TORRENT_USE_GCRYPT #ifdef TORRENT_USE_LIBGCRYPT
gcry_md_write(m_context, data, len); gcry_md_write(m_context, data, len);
#elif TORRENT_USE_COMMONCRYPTO #elif TORRENT_USE_COMMONCRYPTO
CC_SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len); CC_SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
#elif defined TORRENT_USE_OPENSSL #elif defined TORRENT_USE_LIBCRYPTO
SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len); SHA1_Update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
#else #else
SHA1_update(&m_context, reinterpret_cast<unsigned char const*>(data), len); SHA1_update(&m_context, reinterpret_cast<unsigned char const*>(data), len);
@ -100,12 +99,12 @@ namespace libtorrent
sha1_hash hasher::final() sha1_hash hasher::final()
{ {
sha1_hash digest; sha1_hash digest;
#ifdef TORRENT_USE_GCRYPT #ifdef TORRENT_USE_LIBGCRYPT
gcry_md_final(m_context); gcry_md_final(m_context);
digest.assign((const char*)gcry_md_read(m_context, 0)); digest.assign((const char*)gcry_md_read(m_context, 0));
#elif TORRENT_USE_COMMONCRYPTO #elif TORRENT_USE_COMMONCRYPTO
CC_SHA1_Final(digest.begin(), &m_context); CC_SHA1_Final(digest.begin(), &m_context);
#elif defined TORRENT_USE_OPENSSL #elif defined TORRENT_USE_LIBCRYPTO
SHA1_Final(digest.begin(), &m_context); SHA1_Final(digest.begin(), &m_context);
#else #else
SHA1_final(digest.begin(), &m_context); SHA1_final(digest.begin(), &m_context);
@ -115,11 +114,11 @@ namespace libtorrent
void hasher::reset() void hasher::reset()
{ {
#ifdef TORRENT_USE_GCRYPT #ifdef TORRENT_USE_LIBGCRYPT
gcry_md_reset(m_context); gcry_md_reset(m_context);
#elif TORRENT_USE_COMMONCRYPTO #elif TORRENT_USE_COMMONCRYPTO
CC_SHA1_Init(&m_context); CC_SHA1_Init(&m_context);
#elif defined TORRENT_USE_OPENSSL #elif defined TORRENT_USE_LIBCRYPTO
SHA1_Init(&m_context); SHA1_Init(&m_context);
#else #else
SHA1_init(&m_context); SHA1_init(&m_context);
@ -128,7 +127,7 @@ namespace libtorrent
hasher::~hasher() hasher::~hasher()
{ {
#ifdef TORRENT_USE_GCRYPT #ifdef TORRENT_USE_LIBGCRYPT
gcry_md_close(m_context); gcry_md_close(m_context);
#endif #endif
} }

View File

@ -124,7 +124,7 @@ const rlim_t rlim_infinity = RLIM_INFINITY;
#endif // TORRENT_DISABLE_LOGGING #endif // TORRENT_DISABLE_LOGGING
#ifdef TORRENT_USE_GCRYPT #ifdef TORRENT_USE_LIBGCRYPT
extern "C" { extern "C" {
GCRY_THREAD_OPTION_PTHREAD_IMPL; GCRY_THREAD_OPTION_PTHREAD_IMPL;
@ -146,7 +146,7 @@ namespace
} gcrypt_global_constructor; } gcrypt_global_constructor;
} }
#endif // TORRENT_USE_GCRYPT #endif // TORRENT_USE_LIBGCRYPT
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
@ -1840,6 +1840,24 @@ namespace aux {
int const port = m_listen_interfaces[i].port; int const port = m_listen_interfaces[i].port;
bool const ssl = m_listen_interfaces[i].ssl; bool const ssl = m_listen_interfaces[i].ssl;
#ifndef TORRENT_USE_OPENSSL
if (ssl)
{
#ifndef TORRENT_DISABLE_LOGGING
session_log("attempted to listen ssl with no library support on device: \"%s\""
, device.c_str());
#endif
if (m_alerts.should_post<listen_failed_alert>())
{
m_alerts.emplace_alert<listen_failed_alert>(device
, listen_failed_alert::open
, boost::asio::error::operation_not_supported
, listen_failed_alert::tcp_ssl);
}
continue;
}
#endif
// now we have a device to bind to. This device may actually just be an // now we have a device to bind to. This device may actually just be an
// IP address or a device name. In case it's a device name, we want to // IP address or a device name. In case it's a device name, we want to
// (potentially) end up binding a socket for each IP address associated // (potentially) end up binding a socket for each IP address associated