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

@@ -66,8 +66,6 @@ GameFormatCreatureName = 22
GameSpellList = 23
GameClientPing = 24
GameExtendedClientPing = 25
GameUpdater = 26
GameLoginLocale = 27
GameDoubleHealth = 28
GameDoubleSkills = 29
GameChangeMapAwareRange = 30
@@ -78,7 +76,6 @@ GameDiagonalAnimatedText = 34
GameLoginPending = 35
GameNewSpeedLaw = 36
GameForceFirstAutoWalkStep = 37
GameLoginUUID = 38
TextColors = {
red = '#f55e5e', --'#c83200'

View File

@@ -5,6 +5,7 @@ function g_game.getRsa()
end
function g_game.chooseRsa(host)
if currentRsa ~= CIPSOFT_RSA and currentRsa ~= OTSERV_RSA then return end
if string.ends(host, '.tibia.com') or string.ends(host, '.cipsoft.com') then
g_game.setRsa(CIPSOFT_RSA)
@@ -21,11 +22,10 @@ function g_game.chooseRsa(host)
end
end
function g_game.setRsa(rsa)
if currentRsa ~= rsa then
currentRsa = rsa
g_crypt.rsaSetPublicKey(currentRsa, '65537')
end
function g_game.setRsa(rsa, e)
e = e or '65537'
g_crypt.rsaSetPublicKey(rsa, e)
currentRsa = rsa
end
function g_game.isOfficialTibia()

View File

@@ -8,7 +8,7 @@ LoginServerUpdateNeeded = 30
LoginServerCharacterList = 100
LoginServerExtendedCharacterList = 101
function ProtocolLogin:login(host, port, accountName, accountPassword, locale)
function ProtocolLogin:login(host, port, accountName, accountPassword)
if string.len(host) == 0 or port == nil or port == 0 then
signalcall(self.onError, self, tr("You must enter a valid server address and port."))
return
@@ -17,7 +17,6 @@ function ProtocolLogin:login(host, port, accountName, accountPassword, locale)
self.accountName = accountName
self.accountPassword = accountPassword
self.connectCallback = sendLoginPacket
self.locale = locale
self:connect(host, port)
end
@@ -26,21 +25,11 @@ function ProtocolLogin:cancelLogin()
self:disconnect()
end
function ProtocolLogin:sendLoginPacket()
function ProtocolLogin:sendLoginPacket(extended)
local msg = OutputMessage.create()
msg:addU8(ClientOpcodes.ClientEnterAccount)
msg:addU16(g_game.getOs())
if g_game.getFeature(GameUpdater) then
msg:addString(g_app.getOs())
msg:addString(g_game.getUpdaterSignature())
end
if g_game.getFeature(GameLoginLocale) then
msg:addString(self.locale)
end
msg:addU16(g_game.getProtocolVersion())
if g_game.getProtocolVersion() >= 971 then
@@ -55,9 +44,10 @@ function ProtocolLogin:sendLoginPacket()
msg:addU8(0) -- clientType
end
local paddingBytes = 128
msg:addU8(0) -- first RSA byte must be 0
paddingBytes = paddingBytes - 1
local offset = msg:getMessageSize()
-- first RSA byte must be 0
msg:addU8(0)
-- xtea key
self:generateXteaKey()
@@ -66,25 +56,29 @@ function ProtocolLogin:sendLoginPacket()
msg:addU32(xteaKey[2])
msg:addU32(xteaKey[3])
msg:addU32(xteaKey[4])
paddingBytes = paddingBytes - 16
if g_game.getFeature(GameAccountNames) then
msg:addString(self.accountName)
else
msg:addU32(tonumber(self.accountName))
end
msg:addString(self.accountPassword)
if self.getLoginExtendedData then
local data = self:getLoginExtendedData()
msg:addString(data)
end
local paddingBytes = g_crypt.rsaGetSize() - (msg:getMessageSize() - offset)
assert(paddingBytes >= 0)
msg:addPaddingBytes(paddingBytes, 0)
msg:encryptRsa()
if g_game.getFeature(GameProtocolChecksum) then
self:enableChecksum()
end
if g_game.getFeature(GameAccountNames) then
msg:addString(self.accountName)
msg:addString(self.accountPassword)
paddingBytes = paddingBytes - (4 + string.len(self.accountName) + string.len(self.accountPassword))
else
msg:addU32(tonumber(self.accountName))
msg:addString(self.accountPassword)
paddingBytes = paddingBytes - (6 + string.len(self.accountPassword))
end
msg:addPaddingBytes(paddingBytes, 0)
msg:encryptRsa(128)
self:send(msg)
self:enableXteaEncryption()
self:recv()