Add flexibility in login packets

* It's now possible to add custom data in the login packet
* Add utility funciton to generate RSA keys
* Make the protocol able to use RSA keys with 2048 bits or more
This commit is contained in:
Eduardo Bart
2013-01-28 20:52:03 -02:00
parent 6c7a163197
commit b7eef97239
17 changed files with 84 additions and 103 deletions

View File

@@ -337,8 +337,6 @@ namespace Otc
GameSpellList = 23,
GameClientPing = 24,
GameExtendedClientPing = 25,
GameUpdater = 26,
GameLoginLocale = 27,
GameDoubleHealth = 28,
GameDoubleSkills = 29,
GameChangeMapAwareRange = 30,
@@ -349,7 +347,6 @@ namespace Otc
GameLoginPending = 35,
GameNewSpeedLaw = 36,
GameForceFirstAutoWalkStep = 37,
GameLoginUUID = 38,
// 51-100 reserved to be defined in lua
LastGameFeature = 101
};

View File

@@ -473,7 +473,7 @@ void Game::processWalkCancel(Otc::Direction direction)
m_localPlayer->cancelWalk(direction);
}
void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldName, const std::string& worldHost, int worldPort, const std::string& characterName, const std::string& locale)
void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldName, const std::string& worldHost, int worldPort, const std::string& characterName)
{
if(m_protocolGame || isOnline())
stdext::throw_exception("Unable to login into a world while already online or logging.");
@@ -488,7 +488,7 @@ void Game::loginWorld(const std::string& account, const std::string& password, c
m_localPlayer->setName(characterName);
m_protocolGame = ProtocolGamePtr(new ProtocolGame);
m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName, locale);
m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName);
m_characterName = characterName;
m_worldName = worldName;
}

View File

@@ -135,7 +135,7 @@ protected:
public:
// login related
void loginWorld(const std::string& account, const std::string& password, const std::string& worldName, const std::string& worldHost, int worldPort, const std::string& characterName, const std::string& locale);
void loginWorld(const std::string& account, const std::string& password, const std::string& worldName, const std::string& worldHost, int worldPort, const std::string& characterName);
void cancelLogin();
void forceLogout();
void safeLogout();
@@ -270,9 +270,6 @@ public:
void setCustomOs(int os) { m_clientCustomOs = os; }
int getOs();
void setUpdaterSignature(const std::string& sig) { m_clientSignature = sig; }
std::string getUpdaterSignature() { return m_clientSignature; }
bool canPerformGameAction();
bool checkBotProtection();

View File

@@ -238,8 +238,6 @@ void Client::registerLuaFunctions()
g_lua.bindSingletonFunction("g_game", "setProtocolVersion", &Game::setProtocolVersion, &g_game);
g_lua.bindSingletonFunction("g_game", "getClientVersion", &Game::getClientVersion, &g_game);
g_lua.bindSingletonFunction("g_game", "setClientVersion", &Game::setClientVersion, &g_game);
g_lua.bindSingletonFunction("g_game", "setUpdaterSignature", &Game::setUpdaterSignature, &g_game);
g_lua.bindSingletonFunction("g_game", "getUpdaterSignature", &Game::getUpdaterSignature, &g_game);
g_lua.bindSingletonFunction("g_game", "setCustomOs", &Game::setCustomOs, &g_game);
g_lua.bindSingletonFunction("g_game", "getOs", &Game::getOs, &g_game);
g_lua.bindSingletonFunction("g_game", "getCharacterName", &Game::getCharacterName, &g_game);

View File

@@ -26,12 +26,11 @@
#include "item.h"
#include "localplayer.h"
void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, const std::string& host, uint16 port, const std::string& characterName, const std::string& locale)
void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, const std::string& host, uint16 port, const std::string& characterName)
{
m_accountName = accountName;
m_accountPassword = accountPassword;
m_characterName = characterName;
m_locale = locale;
connect(host, port);
}

View File

@@ -31,7 +31,7 @@
class ProtocolGame : public Protocol
{
public:
void login(const std::string& accountName, const std::string& accountPassword, const std::string& host, uint16 port, const std::string& characterName, const std::string& locale);
void login(const std::string& accountName, const std::string& accountPassword, const std::string& host, uint16 port, const std::string& characterName);
void send(const OutputMessagePtr& outputMessage);
void sendExtendedOpcode(uint8 opcode, const std::string& buffer);
@@ -235,7 +235,6 @@ private:
std::string m_accountName;
std::string m_accountPassword;
std::string m_characterName;
std::string m_locale;
stdext::timer m_pingTimer;
LocalPlayerPtr m_localPlayer;
};

View File

@@ -53,17 +53,7 @@ void ProtocolGame::sendLoginPacket(uint challengeTimestamp, uint8 challengeRando
OutputMessagePtr msg(new OutputMessage);
msg->addU8(Proto::ClientPendingGame);
msg->addU16(g_game.getOs());
if(g_game.getFeature(Otc::GameUpdater)) {
msg->addString(g_app.getOs());
msg->addString(g_game.getUpdaterSignature());
}
if(g_game.getFeature(Otc::GameLoginLocale))
msg->addString(m_locale);
msg->addU16(g_game.getProtocolVersion());
if(g_game.getProtocolVersion() >= 971) {
@@ -71,9 +61,9 @@ void ProtocolGame::sendLoginPacket(uint challengeTimestamp, uint8 challengeRando
msg->addU8(0); // clientType
}
int paddingBytes = 128;
int offset = msg->getMessageSize();
msg->addU8(0); // first RSA byte must be 0
paddingBytes -= 1;
// xtea key
generateXteaKey();
@@ -82,46 +72,34 @@ void ProtocolGame::sendLoginPacket(uint challengeTimestamp, uint8 challengeRando
msg->addU32(m_xteaKey[2]);
msg->addU32(m_xteaKey[3]);
msg->addU8(0); // is gm set?
paddingBytes -= 17;
if(g_game.getFeature(Otc::GameProtocolChecksum))
enableChecksum();
if(g_game.getFeature(Otc::GameAccountNames)) {
if(g_game.getFeature(Otc::GameAccountNames))
msg->addString(m_accountName);
msg->addString(m_characterName);
msg->addString(m_accountPassword);
paddingBytes -= 6 + m_accountName.length() + m_characterName.length() + m_accountPassword.length();
} else {
else
msg->addU32(stdext::from_string<uint32>(m_accountName));
msg->addString(m_characterName);
msg->addString(m_accountPassword);
paddingBytes -= 8 + m_characterName.length() + m_accountPassword.length();
}
if(g_game.getFeature(Otc::GameLoginUUID)) {
std::string uuid = g_crypt.getMachineUUID();
msg->addString(uuid);
paddingBytes -= 2 + uuid.length();
}
msg->addString(m_characterName);
msg->addString(m_accountPassword);
if(g_game.getFeature(Otc::GameChallengeOnLogin)) {
msg->addU32(challengeTimestamp);
msg->addU8(challengeRandom);
paddingBytes -= 5;
}
if(paddingBytes < 0) {
g_game.processLoginError("AccountName or Password or CharacterName are too big!\nPlease contact game support.");
g_game.processDisconnect();
return;
}
std::string extended = callLuaField<std::string>("getLoginExtendedData");
if(!extended.empty())
msg->addString(extended);
// complete the 128 bytes for rsa encryption with zeros
// complete the bytes for rsa encryption with zeros
int paddingBytes = g_crypt.rsaGetSize() - (msg->getMessageSize() - offset);
assert(paddingBytes >= 0);
msg->addPaddingBytes(paddingBytes);
// encrypt with RSA
msg->encryptRsa(128);
msg->encryptRsa();
if(g_game.getFeature(Otc::GameProtocolChecksum))
enableChecksum();
send(msg);