mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 04:24:54 +02:00
Move RSA class to Crypt
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "inputmessage.h"
|
||||
#include <framework/util/rsa.h>
|
||||
#include <framework/util/crypt.h>
|
||||
|
||||
InputMessage::InputMessage()
|
||||
{
|
||||
@@ -86,13 +86,10 @@ std::string InputMessage::getString()
|
||||
return std::string(v, stringLength);
|
||||
}
|
||||
|
||||
bool InputMessage::decryptRsa(int size, const std::string& key, const std::string& p, const std::string& q, const std::string& d)
|
||||
bool InputMessage::decryptRsa(int size)
|
||||
{
|
||||
checkRead(size);
|
||||
g_rsa.setPublic(key.c_str(), "65537");
|
||||
g_rsa.setPrivate(p.c_str(), q.c_str(), d.c_str());
|
||||
g_rsa.check();
|
||||
g_rsa.decrypt((unsigned char*)m_buffer + m_readPos, size);
|
||||
g_crypt.rsaDecrypt((unsigned char*)m_buffer + m_readPos, size);
|
||||
return (getU8() == 0x00);
|
||||
}
|
||||
|
||||
|
@@ -52,7 +52,7 @@ public:
|
||||
uint32 peekU32() { uint32 v = getU32(); m_readPos-=4; return v; }
|
||||
uint64 peekU64() { uint64 v = getU64(); m_readPos-=8; return v; }
|
||||
|
||||
bool decryptRsa(int size, const std::string& key, const std::string& p, const std::string& q, const std::string& d);
|
||||
bool decryptRsa(int size);
|
||||
|
||||
int getReadSize() { return m_readPos - m_headerPos; }
|
||||
int getReadPos() { return m_readPos; }
|
||||
|
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
#include <framework/net/outputmessage.h>
|
||||
#include <framework/util/rsa.h>
|
||||
#include <framework/util/crypt.h>
|
||||
|
||||
OutputMessage::OutputMessage()
|
||||
{
|
||||
@@ -89,13 +89,12 @@ void OutputMessage::addPaddingBytes(int bytes, uint8 byte)
|
||||
m_messageSize += bytes;
|
||||
}
|
||||
|
||||
void OutputMessage::encryptRsa(int size, const std::string& key)
|
||||
void OutputMessage::encryptRsa(int size)
|
||||
{
|
||||
if(m_messageSize < size)
|
||||
throw stdext::exception("insufficient bytes in buffer to encrypt");
|
||||
|
||||
g_rsa.setPublic(key.c_str(), "65537");
|
||||
g_rsa.encrypt((unsigned char*)m_buffer + m_writePos - size, size);
|
||||
g_crypt.rsaEncrypt((unsigned char*)m_buffer + m_writePos - size, size);
|
||||
}
|
||||
|
||||
void OutputMessage::writeChecksum()
|
||||
|
@@ -49,7 +49,7 @@ public:
|
||||
void addString(const std::string& buffer);
|
||||
void addPaddingBytes(int bytes, uint8 byte = 0);
|
||||
|
||||
void encryptRsa(int size, const std::string& key);
|
||||
void encryptRsa(int size);
|
||||
|
||||
uint16 getMessageSize() { return m_messageSize; }
|
||||
|
||||
|
@@ -35,15 +35,23 @@ ServerPtr Server::create(int port)
|
||||
return ServerPtr(new Server(port));
|
||||
}
|
||||
|
||||
void Server::close()
|
||||
{
|
||||
m_isOpen = false;
|
||||
m_acceptor.cancel();
|
||||
m_acceptor.close();
|
||||
}
|
||||
|
||||
void Server::acceptNext()
|
||||
{
|
||||
ConnectionPtr connection = ConnectionPtr(new Connection);
|
||||
connection->m_connecting = true;
|
||||
auto self = static_self_cast<Server>();
|
||||
m_acceptor.async_accept(connection->m_socket, [=](const boost::system::error_code& error) {
|
||||
if(!error) {
|
||||
connection->m_connected = true;
|
||||
connection->m_connecting = false;
|
||||
}
|
||||
callLuaField("onAccept", connection, error.message(), error.value());
|
||||
self->callLuaField("onAccept", connection, error.message(), error.value());
|
||||
});
|
||||
}
|
||||
|
@@ -28,15 +28,16 @@
|
||||
|
||||
class Server : public LuaObject
|
||||
{
|
||||
typedef std::function<void(ConnectionPtr, const boost::system::error_code&)> AcceptCallback;
|
||||
|
||||
public:
|
||||
Server(int port);
|
||||
static ServerPtr create(int port);
|
||||
bool isOpen() { return m_isOpen; }
|
||||
void close();
|
||||
|
||||
void acceptNext();
|
||||
|
||||
private:
|
||||
stdext::boolean<true> m_isOpen;
|
||||
asio::ip::tcp::acceptor m_acceptor;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user