From ca7b441512d5b2a67ecfa3f602a16729b7c100d9 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sat, 5 Feb 2022 23:54:49 -0300 Subject: OpenSSL is now required to build. Implement a SHA256 interface. Log chat as SHA256. --- configure.ac | 19 +++++++++++++++++++ src/common/md5calc.c | 26 ++++++++++++++++++++++++++ src/common/md5calc.h | 7 +++++++ src/map/log.c | 9 ++++++--- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index ec9e35cfe..7b3f89b9e 100644 --- a/configure.ac +++ b/configure.ac @@ -1749,5 +1749,24 @@ AC_CHECK_PROG([HAVE_DOXYGEN],[doxygen],[yes],[no]) AC_CHECK_PROG([HAVE_PERL],[perl],[yes],[no]) +# +# OpenSSL library +# + +AC_MSG_CHECKING([OpenSSL library]) +dnl Order matters! +if test "$PORTNAME" != "win32"; then + AC_CHECK_LIB(crypto, CRYPTO_new_ex_data, [], [AC_MSG_ERROR([library 'crypto' is required for OpenSSL])]) + FOUND_SSL_LIB="no" + AC_CHECK_LIB(ssl, OPENSSL_init_ssl, [FOUND_SSL_LIB="yes"]) + AC_CHECK_LIB(ssl, SSL_library_init, [FOUND_SSL_LIB="yes"]) + AS_IF([test "x$FOUND_SSL_LIB" = xno], [AC_MSG_ERROR([library 'ssl' is required for OpenSSL])]) +else + AC_SEARCH_LIBS(CRYPTO_new_ex_data, eay32 crypto, [], [AC_MSG_ERROR([library 'eay32' or 'crypto' is required for OpenSSL])]) + FOUND_SSL_LIB="no" + AC_SEARCH_LIBS(OPENSSL_init_ssl, ssleay32 ssl, [FOUND_SSL_LIB="yes"]) + AC_SEARCH_LIBS(SSL_library_init, ssleay32 ssl, [FOUND_SSL_LIB="yes"]) + AS_IF([test "x$FOUND_SSL_LIB" = xno], [AC_MSG_ERROR([library 'ssleay32' or 'ssl' is required for OpenSSL])]) +fi ############################################################################### AC_OUTPUT diff --git a/src/common/md5calc.c b/src/common/md5calc.c index 3f9ccdc41..bbace132b 100644 --- a/src/common/md5calc.c +++ b/src/common/md5calc.c @@ -29,6 +29,7 @@ #include #include #include +#include /** @file * Implementation of the md5 interface. @@ -259,6 +260,29 @@ static void md5_salt(int len, char *output) } +/*******************************************************************************/ +// SHA256 wrappers [TMW2] +void sha256_hash_string (unsigned char hash[SHA256_DIGEST_LENGTH], char outputBuffer[65]) +{ + int i = 0; + + for(i = 0; i < SHA256_DIGEST_LENGTH; i++) + { + sprintf(outputBuffer + (i * 2), "%02x", hash[i]); + } + + outputBuffer[64] = 0; +} + +void sha256_hash (const char* message, char* outputBuffer) +{ + unsigned char obuf[SHA256_DIGEST_LENGTH]; + SHA256((const unsigned char*)(message), strlen(message), obuf); + sha256_hash_string(obuf, outputBuffer); +} + +/*******************************************************************************/ + /** * Interface base initialization. */ @@ -268,4 +292,6 @@ void md5_defaults(void) md5->binary = md5_buf2binary; md5->string = md5_string; md5->salt = md5_salt; + md5->sha256 = sha256_hash; } + diff --git a/src/common/md5calc.h b/src/common/md5calc.h index bd06f1fbc..26e4fa567 100644 --- a/src/common/md5calc.h +++ b/src/common/md5calc.h @@ -55,6 +55,13 @@ struct md5_interface { * @param[out] output The output buffer (at least len bytes available). */ void (*salt) (int len, char *output); + + /** + * Generates a sha256 hash + */ + void (*sha256) (const char* message, char* outputBuffer); + + }; #ifdef HERCULES_CORE diff --git a/src/map/log.c b/src/map/log.c index 85cdac84a..5676730dc 100644 --- a/src/map/log.c +++ b/src/map/log.c @@ -486,10 +486,13 @@ static void log_chat(e_log_chat_type type, int type_id, int src_charid, int src_ if (dst_charname == NULL) dst_charname = ""; - // Hash the message, we don't care with it + // Hash the message, we don't care with it (FIXME) + //unsigned char obuf[SHA256_DIGEST_LENGTH]; + //SHA256((const unsigned char*)(message), strlen(message), obuf); char *md5str; - md5str = (char *)aMalloc((32+1)*sizeof(char)); - md5->string(message, md5str); + md5str = (char *)aMalloc((64+1)*sizeof(char)); + md5->sha256(message, md5str); + //md5str = (char *)obuf; logs->chat_sub(type,type_id,src_charid,src_accid,mapname,x,y,dst_charname,md5str); } -- cgit v1.2.3-60-g2f50