From 4f570e5d08d0338ac16aace81865c04b0605b0a5 Mon Sep 17 00:00:00 2001 From: Treeston Date: Sun, 26 Jul 2020 05:20:41 +0200 Subject: [PATCH] Core/Authserver: Auth cleanup phase 1b, the "I didn't hit Stage All" commit. Sorry. (5e36bf7 follow-up) --- src/common/Cryptography/BigNumber.cpp | 2 +- src/common/Utilities/Util.h | 14 ++++++++++++++ src/server/game/Server/WorldSocket.cpp | 2 +- src/server/shared/Realm/RealmList.cpp | 4 ++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/common/Cryptography/BigNumber.cpp b/src/common/Cryptography/BigNumber.cpp index a8da6e88f03..5b4e2942453 100644 --- a/src/common/Cryptography/BigNumber.cpp +++ b/src/common/Cryptography/BigNumber.cpp @@ -209,7 +209,7 @@ void BigNumber::GetBytes(uint8* buf, size_t bufsize, bool littleEndian) const std::reverse(buf, buf + bufsize); #else int res = littleEndian ? BN_bn2lebinpad(_bn, buf, bufsize) : BN_bn2binpad(_bn, buf, bufsize); - ASSERT(res > 0, "Buffer of size %zu is too small to hold bignum with %zu bytes.\n", bufsize, BN_num_bytes(_bn)); + ASSERT(res > 0, "Buffer of size %zu is too small to hold bignum with %d bytes.\n", bufsize, BN_num_bytes(_bn)); #endif } diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index b22295e95a8..59d7d53bce9 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -21,6 +21,7 @@ #include "Define.h" #include "Errors.h" +#include #include #include #include @@ -308,6 +309,19 @@ TC_COMMON_API std::string ByteArrayToHexStr(uint8 const* bytes, size_t length, b template std::string ByteArrayToHexStr(Container const& c, bool reverse = false) { return ByteArrayToHexStr(std::data(c), std::size(c), reverse); } TC_COMMON_API void HexStrToByteArray(std::string const& str, uint8* out, bool reverse = false); +template +void HexStrToByteArray(std::string const& str, std::array& buf, bool reverse = false) +{ + ASSERT(str.size() == (2 * Size)); + HexStrToByteArray(str, buf.data(), reverse); +} +template +std::array HexStrToByteArray(std::string const& str, bool reverse = false) +{ + std::array arr; + HexStrToByteArray(str, arr, reverse); + return arr; +} TC_COMMON_API bool StringToBool(std::string const& str); diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index 6dac06165c8..79f461eaad9 100644 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -270,7 +270,7 @@ struct AccountInfo // LEFT JOIN account r ON a.id = r.recruiter // WHERE a.username = ? ORDER BY aa.RealmID DESC LIMIT 1 Id = fields[0].GetUInt32(); - HexStrToByteArray(fields[1].GetCString(), SessionKey.data()); + HexStrToByteArray(fields[1].GetCString(), SessionKey); LastIP = fields[2].GetString(); IsLockedToIP = fields[3].GetBool(); LockCountry = fields[4].GetString(); diff --git a/src/server/shared/Realm/RealmList.cpp b/src/server/shared/Realm/RealmList.cpp index 522c0faeebb..a59af781352 100644 --- a/src/server/shared/Realm/RealmList.cpp +++ b/src/server/shared/Realm/RealmList.cpp @@ -77,11 +77,11 @@ void RealmList::LoadBuildInfo() build.Build = fields[4].GetUInt32(); std::string windowsHash = fields[5].GetString(); if (windowsHash.length() == build.WindowsHash.size() * 2) - HexStrToByteArray(windowsHash, build.WindowsHash.data()); + HexStrToByteArray(windowsHash, build.WindowsHash); std::string macHash = fields[6].GetString(); if (macHash.length() == build.MacHash.size() * 2) - HexStrToByteArray(macHash, build.MacHash.data()); + HexStrToByteArray(macHash, build.MacHash); } while (result->NextRow()); }