From a142eb9f7a9683f98fe1e9153f6958f80d374c9d Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 30 Apr 2014 20:16:08 +0200 Subject: Core/Auth: Battle.net stuff --- src/server/authserver/Main.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/server/authserver/Main.cpp') diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp index d1b2b614037..0e23dd99ba8 100644 --- a/src/server/authserver/Main.cpp +++ b/src/server/authserver/Main.cpp @@ -151,7 +151,8 @@ extern int main(int argc, char** argv) } // Launch the listening network socket - RealmAcceptor acceptor; + RealmAcceptor acceptor; + RealmAcceptor bnetacceptor; int32 rmport = sConfigMgr->GetIntDefault("RealmServerPort", 3724); if (rmport < 0 || rmport > 0xFFFF) @@ -170,6 +171,13 @@ extern int main(int argc, char** argv) return 1; } + bind_addr.set_port_number(1119); + if (bnetacceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1) + { + TC_LOG_ERROR("server.authserver", "Auth server can not bind to %s:%d", bind_ip.c_str(), 1119); + return 1; + } + // Initialize the signal handlers AuthServerSignalHandler SignalINT, SignalTERM; @@ -179,24 +187,24 @@ extern int main(int argc, char** argv) Handler.register_handler(SIGTERM, &SignalTERM); #if defined(_WIN32) || defined(__linux__) - + ///- Handle affinity for multiple processors and process priority uint32 affinity = sConfigMgr->GetIntDefault("UseProcessors", 0); bool highPriority = sConfigMgr->GetBoolDefault("ProcessPriority", false); #ifdef _WIN32 // Windows - + HANDLE hProcess = GetCurrentProcess(); if (affinity > 0) { ULONG_PTR appAff; ULONG_PTR sysAff; - + if (GetProcessAffinityMask(hProcess, &appAff, &sysAff)) { // remove non accessible processors ULONG_PTR currentAffinity = affinity & appAff; - + if (!currentAffinity) TC_LOG_ERROR("server.authserver", "Processors marked in UseProcessors bitmask (hex) %x are not accessible for the authserver. Accessible processors bitmask (hex): %x", affinity, appAff); else if (SetProcessAffinityMask(hProcess, currentAffinity)) @@ -205,7 +213,7 @@ extern int main(int argc, char** argv) TC_LOG_ERROR("server.authserver", "Can't set used processors (hex): %x", currentAffinity); } } - + if (highPriority) { if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS)) @@ -213,9 +221,9 @@ extern int main(int argc, char** argv) else TC_LOG_ERROR("server.authserver", "Can't set authserver process priority class."); } - + #else // Linux - + if (affinity > 0) { cpu_set_t mask; @@ -242,7 +250,7 @@ extern int main(int argc, char** argv) else TC_LOG_INFO("server.authserver", "authserver process priority class set to %i", getpriority(PRIO_PROCESS, 0)); } - + #endif #endif -- cgit v1.2.3 From fea9d275fa0ed8f5b43dc54979cdd5a58afc993b Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 30 Apr 2014 23:02:01 +0200 Subject: Verify received components --- src/server/authserver/Main.cpp | 2 + src/server/authserver/Server/BattlenetBitStream.h | 2 + src/server/authserver/Server/BattlenetManager.cpp | 61 ++++++++++++++++++++++ src/server/authserver/Server/BattlenetManager.h | 62 +++++++++++++++++++++++ src/server/authserver/Server/BattlenetPackets.cpp | 43 ++++++++++++---- src/server/authserver/Server/BattlenetPackets.h | 20 ++++---- src/server/authserver/Server/BattlenetSocket.cpp | 36 ++++++++++--- src/server/authserver/Server/BattlenetSocket.h | 3 ++ 8 files changed, 202 insertions(+), 27 deletions(-) create mode 100644 src/server/authserver/Server/BattlenetManager.cpp create mode 100644 src/server/authserver/Server/BattlenetManager.h (limited to 'src/server/authserver/Main.cpp') diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp index 0e23dd99ba8..be2e6a11d4f 100644 --- a/src/server/authserver/Main.cpp +++ b/src/server/authserver/Main.cpp @@ -254,6 +254,8 @@ extern int main(int argc, char** argv) #endif #endif + sBattlenetMgr->Load(); + // maximum counter for next ping uint32 numLoops = (sConfigMgr->GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000)); uint32 loopCounter = 0; diff --git a/src/server/authserver/Server/BattlenetBitStream.h b/src/server/authserver/Server/BattlenetBitStream.h index fa09b24b204..4b6c7f882d4 100644 --- a/src/server/authserver/Server/BattlenetBitStream.h +++ b/src/server/authserver/Server/BattlenetBitStream.h @@ -178,6 +178,8 @@ namespace Battlenet size_t GetSize() const { return _buffer.size(); } + void FinishReading() { _readPos = _numBits; } + private: std::vector _buffer; uint32 _numBits; diff --git a/src/server/authserver/Server/BattlenetManager.cpp b/src/server/authserver/Server/BattlenetManager.cpp new file mode 100644 index 00000000000..b7df889809e --- /dev/null +++ b/src/server/authserver/Server/BattlenetManager.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2008-2014 TrinityCore + * + * 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 . + */ + +#include "BattlenetManager.h" +#include "DatabaseEnv.h" + +void BattlenetMgr::Load() +{ + LoadComponents(); + LoadModules(); +} + +void BattlenetMgr::LoadComponents() +{ + QueryResult result = LoginDatabase.Query("SELECT Program, Platform, Build FROM battlenet_components"); + if (result) + { + do + { + Field* fields = result->Fetch(); + Battlenet::Component* component = new Battlenet::Component(); + component->Program = fields[0].GetString(); + component->Platform = fields[1].GetString(); + component->Build = fields[2].GetUInt32(); + + _components.insert(component); + _programs.insert(component->Program); + _platforms.insert(component->Platform); + _builds.insert(component->Build); + + } while (result->NextRow()); + } +} + +void BattlenetMgr::LoadModules() +{ + +} + +bool BattlenetMgr::HasComponent(Battlenet::Component const* component) const +{ + for (Battlenet::Component const* c : _components) + if (component->Program == c->Program && component->Platform == c->Platform && component->Build == c->Build) + return true; + + return false; +} diff --git a/src/server/authserver/Server/BattlenetManager.h b/src/server/authserver/Server/BattlenetManager.h new file mode 100644 index 00000000000..d3962a32c0d --- /dev/null +++ b/src/server/authserver/Server/BattlenetManager.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2008-2014 TrinityCore + * + * 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 . + */ + +#ifndef __BATTLENETMANAGER_H__ +#define __BATTLENETMANAGER_H__ + +#include "Define.h" +#include +#include +#include +#include + +namespace Battlenet +{ + struct Component + { + std::string Program; + std::string Platform; + uint32 Build; + }; +} + +class BattlenetMgr +{ + friend class ACE_Singleton; + BattlenetMgr() { } + ~BattlenetMgr() { } + +public: + void Load(); + bool HasComponent(Battlenet::Component const* component) const; + bool HasProgram(std::string const& program) const { return _programs.count(program); } + bool HasPlatform(std::string const& platform) const { return _platforms.count(platform); } + bool HasBuild(uint32 build) const { return _builds.count(build); } + +private: + void LoadComponents(); + void LoadModules(); + + std::set _components; + std::set _programs; + std::set _platforms; + std::set _builds; +}; + +#define sBattlenetMgr ACE_Singleton::instance() + +#endif // __BATTLENETMANAGER_H__ diff --git a/src/server/authserver/Server/BattlenetPackets.cpp b/src/server/authserver/Server/BattlenetPackets.cpp index 37040fa6d6e..80213a0ba33 100644 --- a/src/server/authserver/Server/BattlenetPackets.cpp +++ b/src/server/authserver/Server/BattlenetPackets.cpp @@ -15,9 +15,8 @@ * with this program. If not, see . */ -#include "Common.h" -#include "BattlenetBitStream.h" #include "BattlenetPackets.h" +#include "Common.h" #include "Util.h" #include #include @@ -58,14 +57,17 @@ void Battlenet::AuthChallenge::Read() if (_stream.Read(1)) Login = _stream.ReadString(9, 3); + + if (GetHeader().Opcode == CMSG_AUTH_CHALLENGE_NEW) + _stream.FinishReading(); } std::string Battlenet::AuthChallenge::ToString() const { std::ostringstream stream; stream << "Battlenet::AuthChallenge Program: " << Program << ", Platform: " << Platform << ", Locale: " << Locale; - for (uint32 i = 0; i < Components.size(); ++i) - stream << std::endl << "Battlenet::AuthChallenge::Component Program: " << Components[i].Program << ", Platform: " << Components[i].Platform << ", Build: " << Components[i].Build; + for (Component const& component : Components) + stream << std::endl << "Battlenet::AuthChallenge::Component Program: " << component.Program << ", Platform: " << component.Platform << ", Build: " << component.Build; if (!Login.empty()) stream << std::endl << "Battlenet::AuthChallenge Login: " << Login; @@ -87,6 +89,16 @@ void Battlenet::ProofRequest::Write() } } +std::string Battlenet::ProofRequest::ToString() const +{ + std::ostringstream stream; + stream << "Battlenet::ProofRequest modules " << Modules.size(); + for (ModuleInfo const& module : Modules) + stream << std::endl << "Locale " << module.Locale << "ModuleId " << ByteArrayToHexStr(module.ModuleId, 32) << "BlobSize " << module.BlobSize; + + return stream.str(); +} + Battlenet::ProofResponse::~ProofResponse() { for (size_t i = 0; i < Modules.size(); ++i) @@ -108,10 +120,10 @@ std::string Battlenet::ProofResponse::ToString() const { std::ostringstream stream; stream << "Battlenet::ProofResponse Modules " << Modules.size(); - for (size_t i = 0; i < Modules.size(); ++i) + for (ModuleData const& module : Modules) { - std::string hexStr = ByteArrayToHexStr(Modules[i].Data, Modules[i].Size); - stream << std::endl << "Battlenet::ProofResponse::ModuleData Size: " << Modules[i].Size << ", Data: " << hexStr; + std::string hexStr = ByteArrayToHexStr(module.Data, module.Size); + stream << std::endl << "Battlenet::ProofResponse::ModuleData Size: " << module.Size << ", Data: " << hexStr; } return stream.str(); @@ -119,8 +131,8 @@ std::string Battlenet::ProofResponse::ToString() const void Battlenet::AuthComplete::Write() { - _stream.Write(AuthResult != 0, 1); - if (AuthResult == 0) + _stream.Write(Result != 0, 1); + if (Result == 0) { _stream.Write(Modules.size(), 3); for (size_t i = 0; i < Modules.size(); ++i) @@ -163,8 +175,19 @@ void Battlenet::AuthComplete::Write() _stream.Write(ErrorType, 2); if (ErrorType == 1) { - _stream.Write(AuthResult, 16); + _stream.Write(Result, 16); _stream.Write(0, 32); } } } + +std::string Battlenet::AuthComplete::ToString() const +{ + return "Battlenet::AuthComplete"; +} + +void Battlenet::AuthComplete::SetAuthResult(AuthResult result) +{ + ErrorType = result != AUTH_OK ? 1 : 0; + Result = result; +} diff --git a/src/server/authserver/Server/BattlenetPackets.h b/src/server/authserver/Server/BattlenetPackets.h index 23625e30d2b..86dcb99a4da 100644 --- a/src/server/authserver/Server/BattlenetPackets.h +++ b/src/server/authserver/Server/BattlenetPackets.h @@ -18,6 +18,9 @@ #ifndef __BATTLENETPACKETS_H__ #define __BATTLENETPACKETS_H__ +#include "AuthCodes.h" +#include "BattlenetBitStream.h" +#include "BattlenetManager.h" #include "Define.h" #include "Errors.h" #include @@ -39,6 +42,7 @@ namespace Battlenet { CMSG_AUTH_CHALLENGE = 0x0, CMSG_AUTH_PROOF_RESPONSE = 0x2, + CMSG_AUTH_CHALLENGE_NEW = 0x9, // MoP SMSG_AUTH_COMPLETE = 0x0, SMSG_AUTH_PROOF_REQUEST = 0x2, @@ -116,16 +120,9 @@ namespace Battlenet public: AuthChallenge(PacketHeader const& header, BitStream& stream) : ClientPacket(header, stream) { - ASSERT(header == PacketHeader(CMSG_AUTH_CHALLENGE, AUTHENTICATION) && "Invalid packet header for AuthChallenge"); + ASSERT(header.Channel == AUTHENTICATION && (header.Opcode == CMSG_AUTH_CHALLENGE || header.Opcode == CMSG_AUTH_CHALLENGE_NEW) && "Invalid packet header for AuthChallenge"); } - struct Component - { - std::string Program; - std::string Platform; - uint32 Build; - }; - void Read() override; std::string ToString() const override; @@ -151,6 +148,7 @@ namespace Battlenet ProofRequest() : ServerPacket(PacketHeader(SMSG_AUTH_PROOF_REQUEST, AUTHENTICATION)) { } void Write() override; + std::string ToString() const override; std::vector Modules; }; @@ -181,14 +179,16 @@ namespace Battlenet { public: AuthComplete() : ServerPacket(PacketHeader(SMSG_AUTH_COMPLETE, AUTHENTICATION)), - AuthResult(0), ErrorType(0), PingTimeout(120000), Threshold(1000000), Rate(1000) + Result(AUTH_OK), ErrorType(0), PingTimeout(120000), Threshold(1000000), Rate(1000) { } void Write() override; + std::string ToString() const override; - uint32 AuthResult; std::vector Modules; + void SetAuthResult(AuthResult result); + AuthResult Result; uint32 ErrorType; int32 PingTimeout; diff --git a/src/server/authserver/Server/BattlenetSocket.cpp b/src/server/authserver/Server/BattlenetSocket.cpp index fb9ca008e8b..04005e30878 100644 --- a/src/server/authserver/Server/BattlenetSocket.cpp +++ b/src/server/authserver/Server/BattlenetSocket.cpp @@ -17,7 +17,6 @@ #include "AuthCodes.h" #include "BattlenetBitStream.h" -#include "BattlenetPackets.h" #include "BattlenetSocket.h" #include @@ -26,13 +25,29 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac AuthChallenge info(header, packet); info.Read(); + for (Component const& component : info.Components) + { + if (!sBattlenetMgr->HasComponent(&component)) + { + AuthComplete complete; + if (!sBattlenetMgr->HasProgram(component.Program)) + complete.SetAuthResult(AUTH_INVALID_PROGRAM); + else if (!sBattlenetMgr->HasPlatform(component.Platform)) + complete.SetAuthResult(AUTH_INVALID_OS); + else if (!sBattlenetMgr->HasBuild(component.Build)) + complete.SetAuthResult(AUTH_REGION_BAD_VERSION); + + Send(complete); + return true; + } + } + printf("%s\n", info.ToString().c_str()); _accountName = info.Login; ProofRequest request; - request.Write(); - _socket.send((char const*)request.GetData(), request.GetSize()); + Send(request); return true; } @@ -44,10 +59,8 @@ bool Battlenet::Socket::HandleAuthProofResponse(PacketHeader& header, BitStream& printf("%s\n", response.ToString().c_str()); AuthComplete complete; - complete.ErrorType = 1; - complete.AuthResult = AUTH_USE_GRUNT_LOGON; - complete.Write(); - _socket.send((char const*)complete.GetData(), complete.GetSize()); + complete.SetAuthResult(AUTH_USE_GRUNT_LOGON); + Send(complete); return true; } @@ -56,6 +69,7 @@ std::map InitHandlers std::map handlers; handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_CHALLENGE, Battlenet::AUTHENTICATION)] = &Battlenet::Socket::HandleAuthChallenge; + handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_CHALLENGE_NEW, Battlenet::AUTHENTICATION)] = &Battlenet::Socket::HandleAuthChallenge; handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_PROOF_RESPONSE, Battlenet::AUTHENTICATION)] = &Battlenet::Socket::HandleAuthProofResponse; return handlers; @@ -122,3 +136,11 @@ void Battlenet::Socket::OnClose() { printf("Battlenet::Socket::OnClose\n"); } + +void Battlenet::Socket::Send(ServerPacket& packet) +{ + printf("Battlenet::Socket::Send %s\n", packet.ToString().c_str()); + + packet.Write(); + _socket.send(reinterpret_cast(packet.GetData()), packet.GetSize()); +} diff --git a/src/server/authserver/Server/BattlenetSocket.h b/src/server/authserver/Server/BattlenetSocket.h index f7cc59d7e97..7507f090a7f 100644 --- a/src/server/authserver/Server/BattlenetSocket.h +++ b/src/server/authserver/Server/BattlenetSocket.h @@ -19,6 +19,7 @@ #define _BATTLENETSOCKET_H #include "RealmSocket.h" +#include "BattlenetPackets.h" #include "BattlenetPacketCrypt.h" namespace Battlenet @@ -40,6 +41,8 @@ namespace Battlenet void OnAccept() override; void OnClose() override; + void Send(ServerPacket& packet); + private: RealmSocket& _socket; uint32 _currentChannel; -- cgit v1.2.3