From 4ec5f4eae9194ada480f9fa525353c317cbd18e4 Mon Sep 17 00:00:00 2001 From: lotodore Date: Tue, 8 Mar 2011 18:42:57 +0000 Subject: [PATCH] Removing dependency to gnutls, only gcrypt is required now. --- pokerth_game.pro | 9 +++++---- pokerth_server.pro | 4 ++-- src/core/common/crypthelper.cpp | 19 ++++++++++++++++--- src/core/openssl_wrapper.h | 4 +--- src/engine/local_engine/tools.cpp | 8 ++++++++ src/net/common/socket_startup.cpp | 14 ++++++++------ 6 files changed, 40 insertions(+), 18 deletions(-) diff --git a/pokerth_game.pro b/pokerth_game.pro index 37f0b322..0bf619c8 100644 --- a/pokerth_game.pro +++ b/pokerth_game.pro @@ -323,7 +323,9 @@ win32 { -lSDLmain \ -ltinyxml \ -lz \ - -lgnutls-openssl -lgnutls -lgcrypt -lgpg-error -lgsasl -lidn + -lgcrypt \ + -lgsasl \ + -lidn debug:LIBPATH += debug/lib release:LIBPATH += release/lib win32-g++-cross { @@ -446,14 +448,13 @@ unix:!mac { -lSDL_mixer \ -lgsasl !isEmpty( BSD ):isEmpty( kFreeBSD ):LIBS += -lcrypto - else:LIBS += -lgnutls-openssl \ - -lgcrypt + else:LIBS += -lgcrypt TARGETDEPS += ./lib/libpokerth_lib.a \ ./lib/libpokerth_db.a \ ./lib/libpokerth_protocol.a # #### My release static libs - # LIBS += -lgcrypt_static -lgpg-error_static -lgnutls-openssl_static -lgnutls_static -lSDL_mixer_static -lSDL -lmikmod -lcurl + # LIBS += -lgcrypt_static -lSDL_mixer_static -lSDL -lmikmod -lcurl # ### INSTALL #### binary.path += $${PREFIX}/bin/ binary.files += pokerth diff --git a/pokerth_server.pro b/pokerth_server.pro index 8572fb7f..edbedfa1 100644 --- a/pokerth_server.pro +++ b/pokerth_server.pro @@ -126,7 +126,7 @@ win32 { debug:LIBPATH += debug/lib release:LIBPATH += release/lib - LIBS += -lgnutls-openssl -lgnutls -lgcrypt -lgpg-error -lgsasl -lidn -ltinyxml + LIBS += -lgcrypt -lgsasl -lidn -ltinyxml win32-g++-cross { LIBS += -lsqlite3 LIBS += -lntlm @@ -269,7 +269,7 @@ unix : !mac { !isEmpty( BSD ): isEmpty( kFreeBSD ){ LIBS += -lcrypto -liconv } else { - LIBS += -lgnutls-openssl -lgcrypt + LIBS += -lgcrypt } TARGETDEPS += ./lib/libpokerth_lib.a \ diff --git a/src/core/common/crypthelper.cpp b/src/core/common/crypthelper.cpp index 27c01e14..5599125a 100644 --- a/src/core/common/crypthelper.cpp +++ b/src/core/common/crypthelper.cpp @@ -165,16 +165,29 @@ CryptHelper::MD5Sum(const std::string &fileName, MD5Buf &buf) if (file) { // Calculate MD5 sum of file. - unsigned char readBuf[8192]; - MD5_CTX context; + unsigned char *readBuf = new unsigned char[8192]; int numBytes; +#ifdef HAVE_OPENSSL + MD5_CTX context; MD5_Init(&context); - while ((numBytes = fread(readBuf, 1, sizeof(readBuf), file)) > 0) + while ((numBytes = fread(readBuf, 1, sizeof(readBuf), file)) > 0) { MD5_Update(&context, readBuf, numBytes); + } MD5_Final(buf.GetData(), &context); +#else + gcry_md_hd_t hash; + gcry_md_open(&hash, GCRY_MD_MD5, 0); + while ((numBytes = fread(readBuf, 1, sizeof(readBuf), file)) > 0) { + gcry_md_write(hash, readBuf, numBytes); + } + memcpy(buf.GetData(), gcry_md_read(hash, GCRY_MD_MD5), MD5_DATA_SIZE); + gcry_md_close(hash); +#endif + retVal = ferror(file) == 0; + delete[] readBuf; fclose(file); } return retVal; diff --git a/src/core/openssl_wrapper.h b/src/core/openssl_wrapper.h index e6decad3..0bc2a28a 100644 --- a/src/core/openssl_wrapper.h +++ b/src/core/openssl_wrapper.h @@ -67,10 +67,8 @@ typedef int pid_t; #include #include #else -// For all other systems, we use GnuTLS. -#include +// For all other systems, we use gcrypt. #include -#define PKTH_USE_GNUTLS #endif #endif diff --git a/src/engine/local_engine/tools.cpp b/src/engine/local_engine/tools.cpp index a3b50c60..94fa53cc 100755 --- a/src/engine/local_engine/tools.cpp +++ b/src/engine/local_engine/tools.cpp @@ -109,9 +109,13 @@ void Tools::getRandNumber(int start, int end, int howMany, int* randArray, bool int counter(0); while(counter < howMany) { +#ifdef HAVE_OPENSSL if(!RAND_bytes(rand_buf, 4)) { LOG_MSG("RAND_bytes failed!"); } +#else + gcry_randomize(rand_buf, 4, GCRY_VERY_STRONG_RANDOM); +#endif randNumber = 0; for(i=0; i<4; i++) { @@ -138,9 +142,13 @@ void Tools::getRandNumber(int start, int end, int howMany, int* randArray, bool int counter(0); while (counter < howMany) { +#ifdef HAVE_OPENSSL if(!RAND_bytes(rand_buf, 4)) { LOG_MSG("RAND_bytes failed!"); } +#else + gcry_randomize(rand_buf, 4, GCRY_VERY_STRONG_RANDOM); +#endif randNumber = 0; for(i=0; i<4; i++) { diff --git a/src/net/common/socket_startup.cpp b/src/net/common/socket_startup.cpp index a7ba4f35..f688db0b 100644 --- a/src/net/common/socket_startup.cpp +++ b/src/net/common/socket_startup.cpp @@ -23,9 +23,7 @@ #include #include -#ifdef PKTH_USE_GNUTLS - -#include +#ifndef HAVE_OPENSSL extern "C" { @@ -60,16 +58,20 @@ extern "C" { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; } -#endif // PKTH_USE_GNUTLS +#endif // not HAVE_OPENSSL bool socket_startup() { -#ifdef PKTH_USE_GNUTLS +#ifdef HAVE_OPENSSL + return SSL_library_init() == 1; +#else + gcry_check_version(NULL); gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_boost); gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0); + gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); + return true; #endif - return SSL_library_init() == 1; } void