Skip to content

Commit 87d5571

Browse files
committed
Core/PacketIO: Reduce differences between branches
(cherry picked from commit bacc90b)
1 parent d21f6dd commit 87d5571

9 files changed

Lines changed: 103 additions & 20 deletions

File tree

src/common/Cryptography/Authentication/WorldPacketCrypt.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ WorldPacketCrypt::WorldPacketCrypt() : _initialized(false)
2525

2626
void WorldPacketCrypt::Init(SessionKey const& K)
2727
{
28-
uint8 ServerEncryptionKey[] = { 0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57 };
29-
_serverEncrypt.Init(Trinity::Crypto::HMAC_SHA1::GetDigestOf(ServerEncryptionKey, K));
30-
uint8 ServerDecryptionKey[] = { 0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE };
31-
_clientDecrypt.Init(Trinity::Crypto::HMAC_SHA1::GetDigestOf(ServerDecryptionKey, K));
28+
static constexpr std::array<uint8, 16> ServerEncryptionKey = { 0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57 };
29+
static constexpr std::array<uint8, 16> ServerDecryptionKey = { 0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE };
30+
31+
Init(K, ServerEncryptionKey, ServerDecryptionKey);
32+
}
33+
34+
void WorldPacketCrypt::Init(SessionKey const& K, std::span<uint8 const, 16> serverKey, std::span<uint8 const, 16> clientKey)
35+
{
36+
_serverEncrypt.Init(Trinity::Crypto::HMAC_SHA1::GetDigestOf(serverKey, K));
37+
_clientDecrypt.Init(Trinity::Crypto::HMAC_SHA1::GetDigestOf(clientKey, K));
3238

3339
// Drop first 1024 bytes, as WoW uses ARC4-drop1024.
3440
std::array<uint8, 1024> syncBuf;

src/common/Cryptography/Authentication/WorldPacketCrypt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020

2121
#include "ARC4.h"
2222
#include "AuthDefines.h"
23+
#include <span>
2324

2425
class TC_COMMON_API WorldPacketCrypt
2526
{
2627
public:
2728
WorldPacketCrypt();
2829

2930
void Init(SessionKey const& K);
31+
void Init(SessionKey const& K, std::span<uint8 const, 16> serverKey, std::span<uint8 const, 16> clientKey);
3032
void DecryptRecv(uint8* data, size_t len);
3133
void EncryptSend(uint8* data, size_t len);
3234

src/server/game/Server/Packets/AllPackets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef AllPackets_h__
1919
#define AllPackets_h__
2020

21+
#include "AuthenticationPackets.h"
2122
#include "BankPackets.h"
2223
#include "BattlegroundPackets.h"
2324
#include "CalendarPackets.h"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License as published by the
6+
* Free Software Foundation; either version 2 of the License, or (at your
7+
* option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12+
* more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include "AuthenticationPackets.h"
19+
20+
namespace WorldPackets::Auth
21+
{
22+
WorldPacket const* AuthChallenge::Write()
23+
{
24+
_worldPacket << uint32(DosZeroBits);
25+
_worldPacket.append(Challenge.data(), Challenge.size());
26+
_worldPacket.append(DosChallenge.data(), DosChallenge.size());
27+
28+
return &_worldPacket;
29+
}
30+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License as published by the
6+
* Free Software Foundation; either version 2 of the License, or (at your
7+
* option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12+
* more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef TRINITYCORE_AUTHENTICATION_PACKETS_H
19+
#define TRINITYCORE_AUTHENTICATION_PACKETS_H
20+
21+
#include "Packet.h"
22+
23+
namespace WorldPackets
24+
{
25+
namespace Auth
26+
{
27+
class AuthChallenge final : public ServerPacket
28+
{
29+
public:
30+
explicit AuthChallenge() : ServerPacket(SMSG_AUTH_CHALLENGE, 4 + 4 * 8 + 4) { }
31+
32+
WorldPacket const* Write() override;
33+
34+
std::array<uint8, 4> Challenge = { };
35+
std::array<uint32, 8> DosChallenge = { };
36+
uint32 DosZeroBits = 0;
37+
};
38+
}
39+
}
40+
41+
#endif // TRINITYCORE_AUTHENTICATION_PACKETS_H

src/server/game/Server/Protocol/Opcodes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,12 +1421,12 @@ void OpcodeTable::Initialize()
14211421
/*0x50A*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_CAMERA_SHAKE, STATUS_NEVER);
14221422
/*0x50B*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_SOCKET_GEMS_RESULT, STATUS_NEVER);
14231423
/*0x50C*/ DEFINE_HANDLER(CMSG_SET_CHARACTER_MODEL, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );
1424-
/*0x50D*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_REDIRECT_CLIENT, STATUS_NEVER);
1425-
/*0x50E*/ DEFINE_HANDLER(CMSG_REDIRECTION_FAILED, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );
1424+
/*0x50D*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_CONNECT_TO, STATUS_NEVER);
1425+
/*0x50E*/ DEFINE_HANDLER(CMSG_CONNECT_TO_FAILED, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );
14261426
/*0x50F*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_SUSPEND_COMMS, STATUS_NEVER);
14271427
/*0x510*/ DEFINE_HANDLER(CMSG_SUSPEND_COMMS_ACK, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );
1428-
/*0x511*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_FORCE_SEND_QUEUED_PACKETS, STATUS_NEVER);
1429-
/*0x512*/ DEFINE_HANDLER(CMSG_REDIRECTION_AUTH_PROOF, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );
1428+
/*0x511*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_RESUME_COMMS, STATUS_NEVER);
1429+
/*0x512*/ DEFINE_HANDLER(CMSG_AUTH_CONTINUED_SESSION, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );
14301430
/*0x513*/ DEFINE_HANDLER(CMSG_DROP_NEW_CONNECTION, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );
14311431
/*0x514*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_SEND_ALL_COMBAT_LOG, STATUS_NEVER);
14321432
/*0x515*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_OPEN_LFG_DUNGEON_FINDER, STATUS_NEVER);

src/server/game/Server/Protocol/Opcodes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,12 +1319,12 @@ enum Opcodes : uint16
13191319
SMSG_CAMERA_SHAKE = 0x50A, // uint32 SpellEffectCameraShakes.dbc index, uint32
13201320
SMSG_SOCKET_GEMS_RESULT = 0x50B,
13211321
CMSG_SET_CHARACTER_MODEL = 0x50C,
1322-
SMSG_REDIRECT_CLIENT = 0x50D, // uint32 ip, uint16 port, uint32 unk, uint8[20] hash (ip + port, seed=sessionkey)
1323-
CMSG_REDIRECTION_FAILED = 0x50E, // something with networking
1322+
SMSG_CONNECT_TO = 0x50D, // uint32 ip, uint16 port, uint32 unk, uint8[20] hash (ip + port, seed=sessionkey)
1323+
CMSG_CONNECT_TO_FAILED = 0x50E, // something with networking
13241324
SMSG_SUSPEND_COMMS = 0x50F,
13251325
CMSG_SUSPEND_COMMS_ACK = 0x510,
1326-
SMSG_FORCE_SEND_QUEUED_PACKETS = 0x511,
1327-
CMSG_REDIRECTION_AUTH_PROOF = 0x512,
1326+
SMSG_RESUME_COMMS = 0x511,
1327+
CMSG_AUTH_CONTINUED_SESSION = 0x512,
13281328
CMSG_DROP_NEW_CONNECTION = 0x513,
13291329
SMSG_SEND_ALL_COMBAT_LOG = 0x514,
13301330
SMSG_OPEN_LFG_DUNGEON_FINDER = 0x515,

src/server/game/Server/WorldSocket.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "WorldSocket.h"
19+
#include "AuthenticationPackets.h"
1920
#include "BigNumber.h"
2021
#include "ClientBuildInfo.h"
2122
#include "DatabaseEnv.h"
@@ -35,7 +36,6 @@
3536

3637
WorldSocket::WorldSocket(Trinity::Net::IoContextTcpSocket&& socket) : BaseSocket(std::move(socket)), _OverSpeedPings(0), _worldSession(nullptr), _authed(false), _sendBufferSize(4096)
3738
{
38-
Trinity::Crypto::GetRandomBytes(_authSeed);
3939
_headerBuffer.Resize(sizeof(ClientPktHeader));
4040
}
4141

@@ -122,13 +122,15 @@ bool WorldSocket::Update()
122122

123123
void WorldSocket::SendAuthSession()
124124
{
125-
WorldPacket packet(SMSG_AUTH_CHALLENGE, 40);
126-
packet << uint32(1); // 1...31
127-
packet.append(_authSeed);
125+
Trinity::Crypto::GetRandomBytes(_serverChallenge);
126+
Trinity::Crypto::GetRandomBytes(_dosChallenge);
128127

129-
packet.append(Trinity::Crypto::GetRandomBytes<32>()); // new encryption seeds
128+
WorldPackets::Auth::AuthChallenge challenge;
129+
challenge.Challenge = _serverChallenge;
130+
memcpy(challenge.DosChallenge.data(), _dosChallenge.data(), _dosChallenge.size());
131+
challenge.DosZeroBits = 1;
130132

131-
SendPacketAndLogOpcode(packet);
133+
SendPacketAndLogOpcode(*challenge.Write());
132134
}
133135

134136
void WorldSocket::OnClose()
@@ -514,7 +516,7 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<AuthSession> authSes
514516
sha.UpdateData(authSession->Account);
515517
sha.UpdateData(t);
516518
sha.UpdateData(authSession->LocalChallenge);
517-
sha.UpdateData(_authSeed);
519+
sha.UpdateData(_serverChallenge);
518520
sha.UpdateData(account.SessionKey);
519521
sha.Finalize();
520522

src/server/game/Server/WorldSocket.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ class TC_GAME_API WorldSocket final : public Trinity::Net::Socket<>
116116

117117
bool HandlePing(WorldPacket& recvPacket);
118118

119-
std::array<uint8, 4> _authSeed;
119+
std::array<uint8, 4> _serverChallenge;
120+
std::array<uint8, 32> _dosChallenge;
120121
WorldPacketCrypt _authCrypt;
121122

122123
TimePoint _LastPingTime;

0 commit comments

Comments
 (0)