Isso não é erro é um código na source chamado RSA Key, Configurado pra só funcionar com o cliente original do servidor, você não vai conseguir acessar o servidor sem o cliente correto mais se você tiver á source do servidor é só alterar o RSA la.
- Fórum
- OTServ
- Suporte
- Resolvidos
- [Resolvido] Erro Rsa
Editado Fevereiro 22 por Error404
info
Grupo: Campones
Registrado: 07/02/17
Posts: 1
Reputação: 0
tbm estou com esse erro... se alguem poder ajudar-nos ficaria agradecido
info
Grupo: Conde
Registrado: 21/04/16
Posts: 831
Reputação: +271
Gênero: Masculino

Em 22/02/2017 at 16:00, Error404 disse:Isso não é erro é um código na source chamado RSA Key, Configurado pra só funcionar com o cliente original do servidor, você não vai conseguir acessar o servidor sem o cliente correto mais se você tiver á source do servidor é só alterar o RSA la.
Sim contenho as souces do Jogo
Minha Protocol.cpp
////////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
////////////////////////////////////////////////////////////////////////
// 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 3 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 "otpch.h"
#if defined WINDOWS
#include <winerror.h>
#endif
#include "protocol.h"
#include "scheduler.h"
#include "connection.h"
#include "outputmessage.h"
#include "tools.h"
#include "rsa.h"
extern RSA g_RSA;
void Protocol::onSendMessage(OutputMessage_ptr msg)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Protocol::onSendMessage" << std::endl;
#endif
if(!m_rawMessages)
{
msg->writeMessageLength();
if(m_encryptionEnabled)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Protocol::onSendMessage - encrypt" << std::endl;
#endif
XTEA_encrypt(*msg);
}
if(m_checksumEnabled)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Protocol::onSendMessage - crypto header" << std::endl;
#endif
msg->addCryptoHeader(m_checksumEnabled);
}
}
if(msg == m_outputBuffer)
m_outputBuffer.reset();
}
void Protocol::onRecvMessage(NetworkMessage& msg)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Protocol::onRecvMessage" << std::endl;
#endif
if(m_encryptionEnabled)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Protocol::onRecvMessage - decrypt" << std::endl;
#endif
XTEA_decrypt(msg);
}
parsePacket(msg);
}
OutputMessage_ptr Protocol::getOutputBuffer()
{
if(m_outputBuffer)
return m_outputBuffer;
if(m_connection)
{
m_outputBuffer = OutputMessagePool::getInstance()->getOutputMessage(this);
return m_outputBuffer;
}
return OutputMessage_ptr();
}
void Protocol::releaseProtocol()
{
if(m_refCount > 0)
Scheduler::getInstance().addEvent(createSchedulerTask(SCHEDULER_MINTICKS, boost::bind(&Protocol::releaseProtocol, this)));
else
deleteProtocolTask();
}
void Protocol::deleteProtocolTask()
{
//dispather thread
assert(!m_refCount);
setConnection(Connection_ptr());
delete this;
}
void Protocol::XTEA_encrypt(OutputMessage& msg)
{
uint32_t k[4];
for(uint8_t i = 0; i < 4; i++)
k = m_key;
int32_t messageLength = msg.getMessageLength();
//add bytes until reach 8 multiple
uint32_t n;
if((messageLength %
!= 0)
{
n = 8 - (messageLength % 8);
msg.AddPaddingBytes(n);
messageLength = messageLength + n;
}
int32_t readPos = 0;
uint32_t* buffer = (uint32_t*)msg.getOutputBuffer();
while(readPos < messageLength / 4)
{
uint32_t v0 = buffer[readPos], v1 = buffer[readPos + 1], delta = 0x61C88647, sum = 0;
for(int32_t i = 0; i < 32; i++)
{
v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]);
sum -= delta;
v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum>>11 & 3]);
}
buffer[readPos] = v0;
buffer[readPos + 1] = v1;
readPos += 2;
}
}
bool Protocol::XTEA_decrypt(NetworkMessage& msg)
{
if((msg.getMessageLength() - 6) % 8 != 0)
{
std::cout << "[Failure - Protocol::XTEA_decrypt] Not valid encrypted message size";
int32_t ip = getIP();
if(ip)
std::cout << " (IP: " << convertIPAddress(ip) << ")";
std::cout << std::endl;
return false;
}
uint32_t k[4];
for(uint8_t i = 0; i < 4; i++)
k = m_key;
int32_t messageLength = msg.getMessageLength() - 6, readPos = 0;
uint32_t* buffer = (uint32_t*)(msg.getBuffer() + msg.getReadPos());
while(readPos < messageLength / 4)
{
uint32_t v0 = buffer[readPos], v1 = buffer[readPos + 1], delta = 0x61C88647, sum = 0xC6EF3720;
for(int32_t i = 0; i < 32; i++)
{
v1 -= ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum>>11 & 3]);
sum += delta;
v0 -= ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]);
}
buffer[readPos] = v0;
buffer[readPos + 1] = v1;
readPos += 2;
}
//
int32_t tmp = msg.GetU16();
if(tmp > msg.getMessageLength() - ![]()
{
std::cout << "[Failure - Protocol::XTEA_decrypt] Not valid unencrypted message size";
uint32_t ip = getIP();
if(ip)
std::cout << " (IP: " << convertIPAddress(ip) << ")";
std::cout << std::endl;
return false;
}
msg.setMessageLength(tmp);
return true;
}
bool Protocol::RSA_decrypt(NetworkMessage& msg)
{
return RSA_decrypt(&g_RSA, msg);
}
bool Protocol::RSA_decrypt(RSA* rsa, NetworkMessage& msg)
{
if(msg.getMessageLength() - msg.getReadPos() != 128)
{
std::cout << "[Warning - Protocol::RSA_decrypt] Not valid packet size" << std::endl;
return false;
}
rsa->decrypt((char*)(msg.getBuffer() + msg.getReadPos()), 128);
if(!msg.GetByte())
return true;
std::cout << "[Warning - Protocol::RSA_decrypt] First byte != 0" << std::endl;
return true;
}
uint32_t Protocol::getIP() const
{
if(getConnection())
return getConnection()->getIP();
return 0;
}
RSA.CPP
////////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
////////////////////////////////////////////////////////////////////////
// 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 3 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 "otpch.h"
#include "rsa.h"
RSA::RSA()
{
m_keySet = false;
mpz_init2(m_p, 1024);
mpz_init2(m_q, 1024);
mpz_init2(m_d, 1024);
mpz_init2(m_u, 1024);
mpz_init2(m_dp, 1024);
mpz_init2(m_dq, 1024);
mpz_init2(m_mod, 1024);
}
RSA::~RSA()
{
mpz_clear(m_p);
mpz_clear(m_q);
mpz_clear(m_d);
mpz_clear(m_u);
mpz_clear(m_dp);
mpz_clear(m_dq);
mpz_clear(m_mod);
}
bool RSA::setKey(const std::string& file)
{
//loads p, q and d from a file
FILE* f = fopen(file.c_str(), "r");
if(!f)
return false;
char p[512], q[512], d[512];
delete fgets(p, 512, f);
delete fgets(q, 512, f);
delete fgets(d, 512, f);
setKey(p, q, d);
return true;
}
void RSA::setKey(const char* p, const char* q, const char* d)
{
boost::recursive_mutex::scoped_lock lockClass(rsaLock);
mpz_set_str(m_p, p, 10);
mpz_set_str(m_q, q, 10);
mpz_set_str(m_d, d, 10);
mpz_t pm1,qm1;
mpz_init2(pm1, 520);
mpz_init2(qm1, 520);
mpz_sub_ui(pm1, m_p, 1);
mpz_sub_ui(qm1, m_q, 1);
mpz_invert(m_u, m_p, m_q);
mpz_mod(m_dp, m_d, pm1);
mpz_mod(m_dq, m_d, qm1);
mpz_mul(m_mod, m_p, m_q);
mpz_clear(pm1);
mpz_clear(qm1);
}
void RSA::decrypt(char* msg, int32_t size)
{
boost::recursive_mutex::scoped_lock lockClass(rsaLock);
mpz_t c,v1,v2,u2,tmp;
mpz_init2(c, 1024);
mpz_init2(v1, 1024);
mpz_init2(v2, 1024);
mpz_init2(u2, 1024);
mpz_init2(tmp, 1024);
mpz_import(c, 128, 1, 1, 0, 0, msg);
mpz_mod(tmp, c, m_p);
mpz_powm(v1, tmp, m_dp, m_p);
mpz_mod(tmp, c, m_q);
mpz_powm(v2, tmp, m_dq, m_q);
mpz_sub(u2, v2, v1);
mpz_mul(tmp, u2, m_u);
mpz_mod(u2, tmp, m_q);
if(mpz_cmp_si(u2, 0) < 0)
{
mpz_add(tmp, u2, m_q);
mpz_set(u2, tmp);
}
mpz_mul(tmp, u2, m_p);
mpz_set_ui(c, 0);
mpz_add(c, v1, tmp);
size_t count = (mpz_sizeinbase(c, 2) + 7)/8;
memset(msg, 0, 128 - count);
mpz_export(&msg[128 - count], NULL, 1, 1, 0, 0, c);
mpz_clear©;
mpz_clear(v1);
mpz_clear(v2);
mpz_clear(u2);
mpz_clear(tmp);
}
int32_t RSA::getKeySize()
{
return (mpz_sizeinbase(m_mod, 2) + 7) / 8;
}
void RSA::getPublicKey(char* buffer)
{
size_t count = (mpz_sizeinbase(m_mod, 2) + 7) / 8;
memset(buffer, 0, 128 - count);
mpz_export(&buffer[128 - count], NULL, 1, 1, 0, 0, m_mod);
}
Editado Fevereiro 24 por BrendoGraphics0
1 hora atrás, BrendoGraphics0 disse:Sim contenho as souces do Jogo
Minha Protocol.cpp
////////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
////////////////////////////////////////////////////////////////////////
// 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 3 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 "otpch.h"
#if defined WINDOWS
#include <winerror.h>
#endif
#include "protocol.h"
#include "scheduler.h"
#include "connection.h"
#include "outputmessage.h"
#include "tools.h"
#include "rsa.h"
extern RSA g_RSA;
void Protocol::onSendMessage(OutputMessage_ptr msg)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Protocol::onSendMessage" << std::endl;
#endif
if(!m_rawMessages)
{
msg->writeMessageLength();
if(m_encryptionEnabled)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Protocol::onSendMessage - encrypt" << std::endl;
#endif
XTEA_encrypt(*msg);
}
if(m_checksumEnabled)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Protocol::onSendMessage - crypto header" << std::endl;
#endif
msg->addCryptoHeader(m_checksumEnabled);
}
}
if(msg == m_outputBuffer)
m_outputBuffer.reset();
}
void Protocol::onRecvMessage(NetworkMessage& msg)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Protocol::onRecvMessage" << std::endl;
#endif
if(m_encryptionEnabled)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Protocol::onRecvMessage - decrypt" << std::endl;
#endif
XTEA_decrypt(msg);
}
parsePacket(msg);
}
OutputMessage_ptr Protocol::getOutputBuffer()
{
if(m_outputBuffer)
return m_outputBuffer;
if(m_connection)
{
m_outputBuffer = OutputMessagePool::getInstance()->getOutputMessage(this);
return m_outputBuffer;
}
return OutputMessage_ptr();
}
void Protocol::releaseProtocol()
{
if(m_refCount > 0)
Scheduler::getInstance().addEvent(createSchedulerTask(SCHEDULER_MINTICKS, boost::bind(&Protocol::releaseProtocol, this)));
else
deleteProtocolTask();
}
void Protocol::deleteProtocolTask()
{
//dispather thread
assert(!m_refCount);
setConnection(Connection_ptr());
delete this;
}
void Protocol::XTEA_encrypt(OutputMessage& msg)
{
uint32_t k[4];
for(uint8_t i = 0; i < 4; i++)
k = m_key;
int32_t messageLength = msg.getMessageLength();
//add bytes until reach 8 multiple
uint32_t n;
if((messageLength %
!= 0)
{
n = 8 - (messageLength % 8);
msg.AddPaddingBytes(n);
messageLength = messageLength + n;
}
int32_t readPos = 0;
uint32_t* buffer = (uint32_t*)msg.getOutputBuffer();
while(readPos < messageLength / 4)
{
uint32_t v0 = buffer[readPos], v1 = buffer[readPos + 1], delta = 0x61C88647, sum = 0;
for(int32_t i = 0; i < 32; i++)
{
v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]);
sum -= delta;
v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum>>11 & 3]);
}
buffer[readPos] = v0;
buffer[readPos + 1] = v1;
readPos += 2;
}
}
bool Protocol::XTEA_decrypt(NetworkMessage& msg)
{
if((msg.getMessageLength() - 6) % 8 != 0)
{
std::cout << "[Failure - Protocol::XTEA_decrypt] Not valid encrypted message size";
int32_t ip = getIP();
if(ip)
std::cout << " (IP: " << convertIPAddress(ip) << ")";
std::cout << std::endl;
return false;
}
uint32_t k[4];
for(uint8_t i = 0; i < 4; i++)
k = m_key;
int32_t messageLength = msg.getMessageLength() - 6, readPos = 0;
uint32_t* buffer = (uint32_t*)(msg.getBuffer() + msg.getReadPos());
while(readPos < messageLength / 4)
{
uint32_t v0 = buffer[readPos], v1 = buffer[readPos + 1], delta = 0x61C88647, sum = 0xC6EF3720;
for(int32_t i = 0; i < 32; i++)
{
v1 -= ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum>>11 & 3]);
sum += delta;
v0 -= ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]);
}
buffer[readPos] = v0;
buffer[readPos + 1] = v1;
readPos += 2;
}
//
int32_t tmp = msg.GetU16();
if(tmp > msg.getMessageLength() -
{
std::cout << "[Failure - Protocol::XTEA_decrypt] Not valid unencrypted message size";
uint32_t ip = getIP();
if(ip)
std::cout << " (IP: " << convertIPAddress(ip) << ")";
std::cout << std::endl;
return false;
}
msg.setMessageLength(tmp);
return true;
}
bool Protocol::RSA_decrypt(NetworkMessage& msg)
{
return RSA_decrypt(&g_RSA, msg);
}
bool Protocol::RSA_decrypt(RSA* rsa, NetworkMessage& msg)
{
if(msg.getMessageLength() - msg.getReadPos() != 128)
{
std::cout << "[Warning - Protocol::RSA_decrypt] Not valid packet size" << std::endl;
return false;
}
rsa->decrypt((char*)(msg.getBuffer() + msg.getReadPos()), 128);
if(!msg.GetByte())
return true;
std::cout << "[Warning - Protocol::RSA_decrypt] First byte != 0" << std::endl;
return true;
}
uint32_t Protocol::getIP() const
{
if(getConnection())
return getConnection()->getIP();
return 0;
}
RSA.CPP
////////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
////////////////////////////////////////////////////////////////////////
// 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 3 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 "otpch.h"
#include "rsa.h"
RSA::RSA()
{
m_keySet = false;
mpz_init2(m_p, 1024);
mpz_init2(m_q, 1024);
mpz_init2(m_d, 1024);
mpz_init2(m_u, 1024);
mpz_init2(m_dp, 1024);
mpz_init2(m_dq, 1024);
mpz_init2(m_mod, 1024);
}
RSA::~RSA()
{
mpz_clear(m_p);
mpz_clear(m_q);
mpz_clear(m_d);
mpz_clear(m_u);
mpz_clear(m_dp);
mpz_clear(m_dq);
mpz_clear(m_mod);
}
bool RSA::setKey(const std::string& file)
{
//loads p, q and d from a file
FILE* f = fopen(file.c_str(), "r");
if(!f)
return false;
char p[512], q[512], d[512];
delete fgets(p, 512, f);
delete fgets(q, 512, f);
delete fgets(d, 512, f);
setKey(p, q, d);
return true;
}
void RSA::setKey(const char* p, const char* q, const char* d)
{
boost::recursive_mutex::scoped_lock lockClass(rsaLock);
mpz_set_str(m_p, p, 10);
mpz_set_str(m_q, q, 10);
mpz_set_str(m_d, d, 10);
mpz_t pm1,qm1;
mpz_init2(pm1, 520);
mpz_init2(qm1, 520);
mpz_sub_ui(pm1, m_p, 1);
mpz_sub_ui(qm1, m_q, 1);
mpz_invert(m_u, m_p, m_q);
mpz_mod(m_dp, m_d, pm1);
mpz_mod(m_dq, m_d, qm1);
mpz_mul(m_mod, m_p, m_q);
mpz_clear(pm1);
mpz_clear(qm1);
}
void RSA::decrypt(char* msg, int32_t size)
{
boost::recursive_mutex::scoped_lock lockClass(rsaLock);
mpz_t c,v1,v2,u2,tmp;
mpz_init2(c, 1024);
mpz_init2(v1, 1024);
mpz_init2(v2, 1024);
mpz_init2(u2, 1024);
mpz_init2(tmp, 1024);
mpz_import(c, 128, 1, 1, 0, 0, msg);
mpz_mod(tmp, c, m_p);
mpz_powm(v1, tmp, m_dp, m_p);
mpz_mod(tmp, c, m_q);
mpz_powm(v2, tmp, m_dq, m_q);
mpz_sub(u2, v2, v1);
mpz_mul(tmp, u2, m_u);
mpz_mod(u2, tmp, m_q);
if(mpz_cmp_si(u2, 0) < 0)
{
mpz_add(tmp, u2, m_q);
mpz_set(u2, tmp);
}
mpz_mul(tmp, u2, m_p);
mpz_set_ui(c, 0);
mpz_add(c, v1, tmp);
size_t count = (mpz_sizeinbase(c, 2) + 7)/8;
memset(msg, 0, 128 - count);
mpz_export(&msg[128 - count], NULL, 1, 1, 0, 0, c);
mpz_clear©;
mpz_clear(v1);
mpz_clear(v2);
mpz_clear(u2);
mpz_clear(tmp);
}
int32_t RSA::getKeySize()
{
return (mpz_sizeinbase(m_mod, 2) + 7) / 8;
}
void RSA::getPublicKey(char* buffer)
{
size_t count = (mpz_sizeinbase(m_mod, 2) + 7) / 8;
memset(buffer, 0, 128 - count);
mpz_export(&buffer[128 - count], NULL, 1, 1, 0, 0, m_mod);
}
Não é em nenhum desses arquivos posta o seu OTSERV.CPP pelo hastebin aqui
info
Grupo: Conde
Registrado: 21/04/16
Posts: 831
Reputação: +271
Gênero: Masculino

Agora, Error404 disse:Não é em nenhum desses arquivos posta o seu OTSERV.CPP pelo hastebin aqui
17 minutos atrás, BrendoGraphics0 disse:
Pronto basta substituir o código por esse:
https://hastebin.com/wamejopelo.php
Basta Compilar á source novamente e problema resolvido, se ajudei marque como melhor resposta e me repute.
info
Grupo: Herói
Registrado: 07/03/16
Posts: 1.4k
Reputação: +385
Gênero: Masculino

Dúvida sanada. Tópico movido para Suporte - Resolvidos.
Caso o usuário necessite, solicite a reabertura do tópico.




info
Grupo: Conde
Registrado: 21/04/16
Posts: 831
Reputação: +271
Gênero: Masculino
Estou Com Erro de RSA No meu servidor tento logar com newclient e fica dando esse erro aki algeum pode me ajuadr??