Core/Misc: ported cryptography updates and all that entrails from 335/master and killed bnetserver

This commit is contained in:
Ovahlord committed 2025-07-21 19:04:56 +02:00
1 parent a576c8328b
commit 64b77e359d
413 files changed
+8953 -56006

No files matched your search

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -16,72 +16,24 @@
*/
#include "AuthCodes.h"
#include <cstddef>
#include "ClientBuildInfo.h"
namespace AuthHelper
{
static RealmBuildInfo const PostBcAcceptedClientBuilds[] =
{
{15595, 4, 3, 4, ' '},
{14545, 4, 2, 2, ' '},
{13623, 4, 0, 6, 'a'},
{13930, 3, 3, 5, 'a'}, // 3.3.5a China Mainland build
{12340, 3, 3, 5, 'a'},
{11723, 3, 3, 3, 'a'},
{11403, 3, 3, 2, ' '},
{11159, 3, 3, 0, 'a'},
{10505, 3, 2, 2, 'a'},
{9947, 3, 1, 3, ' '},
{8606, 2, 4, 3, ' '},
{0, 0, 0, 0, ' '} // terminator
};
constexpr static uint32 MAX_PRE_BC_CLIENT_BUILD = 6141;
static RealmBuildInfo const PreBcAcceptedClientBuilds[] =
bool IsPreBCAcceptedClientBuild(uint32 build)
{
{6141, 1, 12, 3, ' '},
{6005, 1, 12, 2, ' '},
{5875, 1, 12, 1, ' '},
{0, 0, 0, 0, ' '} // terminator
};
bool IsPreBCAcceptedClientBuild(int build)
{
for (int i = 0; PreBcAcceptedClientBuilds[i].Build; ++i)
if (PreBcAcceptedClientBuilds[i].Build == build)
return true;
return false;
return build <= MAX_PRE_BC_CLIENT_BUILD && ClientBuild::GetBuildInfo(build);
}
bool IsPostBCAcceptedClientBuild(int build)
bool IsPostBCAcceptedClientBuild(uint32 build)
{
for (int i = 0; PostBcAcceptedClientBuilds[i].Build; ++i)
if (PostBcAcceptedClientBuilds[i].Build == build)
return true;
return false;
return build > MAX_PRE_BC_CLIENT_BUILD && ClientBuild::GetBuildInfo(build);
}
bool IsAcceptedClientBuild(int build)
bool IsAcceptedClientBuild(uint32 build)
{
return (IsPostBCAcceptedClientBuild(build) || IsPreBCAcceptedClientBuild(build));
}
RealmBuildInfo const* GetBuildInfo(int build)
{
for (int i = 0; PostBcAcceptedClientBuilds[i].Build; ++i)
if (PostBcAcceptedClientBuilds[i].Build == build)
return &PostBcAcceptedClientBuilds[i];
for (int i = 0; PreBcAcceptedClientBuilds[i].Build; ++i)
if (PreBcAcceptedClientBuilds[i].Build == build)
return &PreBcAcceptedClientBuilds[i];
return nullptr;
}
bool IsBuildSupportingBattlenet(int build)
{
return build >= 15595;
return ClientBuild::GetBuildInfo(build) != nullptr;
}
}
@@ -1,6 +1,5 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -19,6 +18,9 @@
#ifndef _AUTHCODES_H
#define _AUTHCODES_H
#include "Define.h"
#include <array>
enum AuthResult
{
WOW_SUCCESS = 0x00,
@@ -70,40 +72,6 @@ enum LoginResult
LOGIN_LOCKED_ENFORCED = 0x10
};
enum GameAccountFlags
{
GAMEACCOUNT_FLAG_GM = 0x00000001,
GAMEACCOUNT_FLAG_NOKICK = 0x00000002,
GAMEACCOUNT_FLAG_COLLECTOR = 0x00000004,
GAMEACCOUNT_FLAG_WOW_TRIAL = 0x00000008,
GAMEACCOUNT_FLAG_CANCELLED = 0x00000010,
GAMEACCOUNT_FLAG_IGR = 0x00000020,
GAMEACCOUNT_FLAG_WHOLESALER = 0x00000040,
GAMEACCOUNT_FLAG_PRIVILEGED = 0x00000080,
GAMEACCOUNT_FLAG_EU_FORBID_ELV = 0x00000100,
GAMEACCOUNT_FLAG_EU_FORBID_BILLING = 0x00000200,
GAMEACCOUNT_FLAG_WOW_RESTRICTED = 0x00000400,
GAMEACCOUNT_FLAG_REFERRAL = 0x00000800,
GAMEACCOUNT_FLAG_BLIZZARD = 0x00001000,
GAMEACCOUNT_FLAG_RECURRING_BILLING = 0x00002000,
GAMEACCOUNT_FLAG_NOELECTUP = 0x00004000,
GAMEACCOUNT_FLAG_KR_CERTIFICATE = 0x00008000,
GAMEACCOUNT_FLAG_EXPANSION_COLLECTOR = 0x00010000,
GAMEACCOUNT_FLAG_DISABLE_VOICE = 0x00020000,
GAMEACCOUNT_FLAG_DISABLE_VOICE_SPEAK = 0x00040000,
GAMEACCOUNT_FLAG_REFERRAL_RESURRECT = 0x00080000,
GAMEACCOUNT_FLAG_EU_FORBID_CC = 0x00100000,
GAMEACCOUNT_FLAG_OPENBETA_DELL = 0x00200000,
GAMEACCOUNT_FLAG_PROPASS = 0x00400000,
GAMEACCOUNT_FLAG_PROPASS_LOCK = 0x00800000,
GAMEACCOUNT_FLAG_PENDING_UPGRADE = 0x01000000,
GAMEACCOUNT_FLAG_RETAIL_FROM_TRIAL = 0x02000000,
GAMEACCOUNT_FLAG_EXPANSION2_COLLECTOR = 0x04000000,
GAMEACCOUNT_FLAG_OVERMIND_LINKED = 0x08000000,
GAMEACCOUNT_FLAG_DEMOS = 0x10000000,
GAMEACCOUNT_FLAG_DEATH_KNIGHT_OK = 0x20000000,
};
enum ExpansionFlags
{
POST_BC_EXP_FLAG = 0x2,
@@ -111,22 +79,13 @@ enum ExpansionFlags
NO_VALID_EXP_FLAG = 0x0
};
struct RealmBuildInfo
{
int Build;
int MajorVersion;
int MinorVersion;
int BugfixVersion;
int HotfixVersion;
};
struct RealmBuildInfo;
namespace AuthHelper
{
RealmBuildInfo const* GetBuildInfo(int build);
bool IsAcceptedClientBuild(int build);
bool IsPostBCAcceptedClientBuild(int build);
bool IsPreBCAcceptedClientBuild(int build);
bool IsBuildSupportingBattlenet(int build);
bool IsAcceptedClientBuild(uint32 build);
bool IsPostBCAcceptedClientBuild(uint32 build);
bool IsPreBCAcceptedClientBuild(uint32 build);
}
#endif
@@ -1,95 +0,0 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TOTP.h"
#include <cstring>
int base32_decode(char const* encoded, char* result, int bufSize)
{
// Base32 implementation
// Copyright 2010 Google Inc.
// Author: Markus Gutschke
// Licensed under the Apache License, Version 2.0
int buffer = 0;
int bitsLeft = 0;
int count = 0;
for (const char *ptr = encoded; count < bufSize && *ptr; ++ptr)
{
char ch = *ptr;
if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '-')
continue;
buffer <<= 5;
// Deal with commonly mistyped characters
if (ch == '0')
ch = 'O';
else if (ch == '1')
ch = 'L';
else if (ch == '8')
ch = 'B';
// Look up one base32 digit
if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
ch = (ch & 0x1F) - 1;
else if (ch >= '2' && ch <= '7')
ch -= '2' - 26;
else
return -1;
buffer |= ch;
bitsLeft += 5;
if (bitsLeft >= 8)
{
result[count++] = buffer >> (bitsLeft - 8);
bitsLeft -= 8;
}
}
if (count < bufSize)
result[count] = '\000';
return count;
}
#define HMAC_RES_SIZE 20
namespace TOTP
{
unsigned int GenerateToken(char const* b32key)
{
size_t keySize = strlen(b32key);
int bufsize = (keySize + 7)/8*5;
char* encoded = new char[bufsize];
memset(encoded, 0, bufsize);
unsigned int hmacResSize = HMAC_RES_SIZE;
unsigned char hmacRes[HMAC_RES_SIZE];
unsigned long timestamp = time(nullptr)/30;
unsigned char challenge[8];
for (int i = 8; i--;timestamp >>= 8)
challenge[i] = timestamp;
base32_decode(b32key, encoded, bufsize);
HMAC(EVP_sha1(), encoded, bufsize, challenge, 8, hmacRes, &hmacResSize);
unsigned int offset = hmacRes[19] & 0xF;
unsigned int truncHash = (hmacRes[offset] << 24) | (hmacRes[offset+1] << 16 )| (hmacRes[offset+2] << 8) | (hmacRes[offset+3]);
truncHash &= 0x7FFFFFFF;
delete[] encoded;
return truncHash % 1000000;
}
}
@@ -1,29 +0,0 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TOTP_H
#define _TOTP_H
#include "openssl/hmac.h"
#include "openssl/evp.h"
namespace TOTP
{
unsigned int GenerateToken(char const* b32key);
}
#endif
+3 -2
View File
@@ -1,6 +1,5 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -37,6 +36,7 @@
#include "IPLocation.h"
#include "MySQLThreading.h"
#include "ProcessPriority.h"
#include "SharedDefines.h"
#include "Util.h"
#include <boost/asio/signal_set.hpp>
#include <boost/program_options.hpp>
@@ -79,6 +79,7 @@ variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, s
int main(int argc, char** argv)
{
Trinity::Impl::CurrentServerProcessHolder::_type = SERVER_PROCESS_AUTHSERVER;
signal(SIGABRT, &Trinity::AbortHandler);
auto configFile = fs::absolute(_TRINITY_REALM_CONFIG);
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -1,6 +1,5 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -17,6 +16,7 @@
*/
#include "GruntRealmList.h"
#include "ClientBuildInfo.h"
#include "DatabaseEnv.h"
#include "DeadlineTimer.h"
#include "IoContext.h"
@@ -46,6 +46,7 @@ void GruntRealmList::Initialize(Trinity::Asio::IoContext& ioContext, uint32 upda
_updateTimer = Trinity::make_unique<Trinity::Asio::DeadlineTimer>(ioContext);
_resolver = Trinity::make_unique<Trinity::Asio::Resolver>(ioContext);
ClientBuild::LoadBuildInfo();
// Get the content of the realmlist table in the database
UpdateRealms(boost::system::error_code());
}
@@ -1,6 +1,5 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
File diff suppressed because it is too large. Load diff
+39 -44
View File
@@ -1,37 +1,39 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __AUTHSESSION_H__
#define __AUTHSESSION_H__
#include "AsyncCallbackProcessor.h"
#include "DatabaseEnvFwd.h"
#include "Common.h"
#include "BigNumber.h"
#include "CryptoHash.h"
#include "DatabaseEnvFwd.h"
#include "DeadlineTimer.h"
#include "Duration.h"
#include "Optional.h"
#include "Socket.h"
#include "SRP6.h"
#include <boost/asio/ip/tcp.hpp>
#include <memory>
#include <span>
using boost::asio::ip::tcp;
class AuthHandlerTable;
class ByteBuffer;
class Field;
struct AuthHandler;
enum AuthStatus
{
@@ -40,6 +42,7 @@ enum AuthStatus
STATUS_RECONNECT_PROOF,
STATUS_AUTHED,
STATUS_WAITING_FOR_REALM_LIST,
STATUS_XFER,
STATUS_CLOSED
};
@@ -56,7 +59,6 @@ struct AccountInfo
bool IsBanned = false;
bool IsPermanenetlyBanned = false;
AccountTypes SecurityLevel = SEC_PLAYER;
std::string TokenKey;
};
class AuthSession : public Socket<AuthSession>
@@ -64,8 +66,6 @@ class AuthSession : public Socket<AuthSession>
typedef Socket<AuthSession> AuthSocket;
public:
static std::unordered_map<uint8, AuthHandler> InitHandlers();
AuthSession(tcp::socket&& socket);
void Start() override;
@@ -77,45 +77,40 @@ protected:
void ReadHandler() override;
private:
friend AuthHandlerTable;
bool HandleLogonChallenge();
bool HandleLogonProof();
bool HandleReconnectChallenge();
bool HandleReconnectProof();
bool HandleRealmList();
bool HandleXferAccept();
bool HandleXferResume();
bool HandleXferCancel();
void CheckIpCallback(PreparedQueryResult result);
void LogonChallengeCallback(PreparedQueryResult result);
void ReconnectChallengeCallback(PreparedQueryResult result);
void RealmListCallback(PreparedQueryResult result);
void SetVSFields(const std::string& rI);
bool VerifyVersion(std::span<uint8 const> a, Trinity::Crypto::SHA1::Digest const& versionProof, bool isReconnect);
void SetTimeout();
BigNumber N, s, g, v;
BigNumber b, B;
BigNumber K;
BigNumber _reconnectProof;
Optional<Trinity::Crypto::SRP6> _srp6;
SessionKey _sessionKey = {};
std::array<uint8, 16> _reconnectProof = {};
Trinity::Asio::DeadlineTimer _timeout;
AuthStatus _status;
AccountInfo _accountInfo;
std::string _tokenKey;
std::string _localizationName;
std::string _os;
std::string _ipCountry;
Optional<std::vector<uint8>> _totpSecret;
LocaleConstant _locale;
uint32 _os;
std::string_view _ipCountry;
uint16 _build;
uint8 _expversion;
Minutes _timezoneOffset;
QueryCallbackProcessor _queryProcessor;
};
#pragma pack(push, 1)
struct AuthHandler
{
AuthStatus status;
size_t packetSize;
bool (AuthSession::*handler)();
};
#pragma pack(pop)
#endif
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the