mirror of
https://github.com/rajkosto/mxoemu
synced 2026-08-14 02:26:05 -04:00
More cleanup
This commit is contained in:
parent
98595b080d
commit
4a9b589eab
12 changed files with 68 additions and 94 deletions
|
|
@ -90,11 +90,8 @@ void AuthServer::LoadSignKeys()
|
|||
CryptoPP::StringSource pkeySource(signPrivStr,true);
|
||||
params.BERDecodePrivateKey(pkeySource,false,pkeySource.MaxRetrievable());
|
||||
|
||||
CryptoPP::RSA::PrivateKey privateKey( params );
|
||||
CryptoPP::RSA::PublicKey publicKey( params );
|
||||
|
||||
signer2048bit.reset(new CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Signer(privateKey));
|
||||
verifier2048bit.reset(new CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Verifier(publicKey));
|
||||
signer2048bit.AccessKey() = CryptoPP::RSA::PrivateKey(params);
|
||||
verifier2048bit.AccessKey() = CryptoPP::RSA::PublicKey(params);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -108,10 +105,8 @@ void AuthServer::LoadSignKeys()
|
|||
CryptoPP::InvertibleRSAFunction params;
|
||||
CryptoPP::StringSource pkeySource(outPrivate,true);
|
||||
params.BERDecodePrivateKey(pkeySource,false,pkeySource.MaxRetrievable());
|
||||
CryptoPP::RSA::PrivateKey privateKey( params );
|
||||
CryptoPP::RSA::PublicKey publicKey( params );
|
||||
signer2048bit.reset(new CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Signer(privateKey));
|
||||
verifier2048bit.reset(new CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Verifier(publicKey));
|
||||
signer2048bit.AccessKey() = CryptoPP::RSA::PrivateKey(params);
|
||||
verifier2048bit.AccessKey() = CryptoPP::RSA::PublicKey(params);
|
||||
|
||||
//write to file
|
||||
fileStream.open("signPriv.dat",ios::binary | ios::trunc);
|
||||
|
|
@ -167,8 +162,8 @@ void AuthServer::GenerateCryptoKeys( string &privKeyOut, string &pubKeyOut )
|
|||
//generate signature
|
||||
ByteBuffer signMe = MessageFromPublicKey(publicKey);
|
||||
vector<byte> signature;
|
||||
signature.resize(signer2048bit->MaxSignatureLength());
|
||||
size_t actualSignatureSize = signer2048bit->SignMessage(randPool,(byte*)signMe.contents(),signMe.size(),&signature[0]);
|
||||
signature.resize(signer2048bit.MaxSignatureLength());
|
||||
size_t actualSignatureSize = signer2048bit.SignMessage(randPool,(byte*)signMe.contents(),signMe.size(),&signature[0]);
|
||||
signature.resize(actualSignatureSize);
|
||||
|
||||
//cache for later retrieval
|
||||
|
|
@ -184,11 +179,6 @@ void AuthServer::GenerateCryptoKeys( string &privKeyOut, string &pubKeyOut )
|
|||
|
||||
void AuthServer::LoadCryptoKeys()
|
||||
{
|
||||
if (signer2048bit == NULL || verifier2048bit == NULL)
|
||||
{
|
||||
LoadSignKeys();
|
||||
}
|
||||
|
||||
bool invalidKeys = false;
|
||||
|
||||
ifstream f_privateKey;
|
||||
|
|
@ -237,7 +227,7 @@ void AuthServer::LoadCryptoKeys()
|
|||
else
|
||||
{
|
||||
vector <byte> derEncodedPubKey;
|
||||
derEncodedPubKey.resize( pubKeyBuf.size() - pubKeyBuf.rpos() - sizeof(uint8) - verifier2048bit->MaxSignatureLength() );
|
||||
derEncodedPubKey.resize( pubKeyBuf.size() - pubKeyBuf.rpos() - sizeof(uint8) - verifier2048bit.MaxSignatureLength() );
|
||||
pubKeyBuf.read(&derEncodedPubKey[0],derEncodedPubKey.size());
|
||||
uint8 zeroSeparator;
|
||||
pubKeyBuf >> zeroSeparator;
|
||||
|
|
@ -249,7 +239,7 @@ void AuthServer::LoadCryptoKeys()
|
|||
else
|
||||
{
|
||||
vector<byte> signature;
|
||||
signature.resize(verifier2048bit->MaxSignatureLength());
|
||||
signature.resize(verifier2048bit.MaxSignatureLength());
|
||||
pubKeyBuf.read(&signature[0],signature.size());
|
||||
|
||||
string pubKeyString = string((const char*)&derEncodedPubKey[0],derEncodedPubKey.size());
|
||||
|
|
@ -268,7 +258,7 @@ void AuthServer::LoadCryptoKeys()
|
|||
{
|
||||
ByteBuffer verifyMe = MessageFromPublicKey(publicKey);
|
||||
|
||||
bool messageCorrect = verifier2048bit->VerifyMessage(
|
||||
bool messageCorrect = verifier2048bit.VerifyMessage(
|
||||
(byte*)verifyMe.contents(),
|
||||
verifyMe.size(),
|
||||
&signature[0],
|
||||
|
|
@ -296,10 +286,10 @@ void AuthServer::LoadCryptoKeys()
|
|||
|
||||
if (invalidKeys == false)
|
||||
{
|
||||
rsaDecryptor.reset(new CryptoPP::RSAES_OAEP_SHA_Decryptor(privateKey));
|
||||
rsaEncryptor.reset(new CryptoPP::RSAES_OAEP_SHA_Encryptor(publicKey));
|
||||
signer1024bit.reset(new CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Signer(privateKey));
|
||||
verifier1024bit.reset(new CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Verifier(publicKey));
|
||||
rsaDecryptor.AccessKey() = privateKey;
|
||||
rsaEncryptor.AccessKey() = publicKey;
|
||||
signer1024bit.AccessKey() = privateKey;
|
||||
verifier1024bit.AccessKey() = publicKey;
|
||||
pubKeyModulus = publicKey.GetModulus();
|
||||
}
|
||||
}
|
||||
|
|
@ -323,10 +313,10 @@ void AuthServer::LoadCryptoKeys()
|
|||
CryptoPP::RSA::PrivateKey privateKey( params );
|
||||
CryptoPP::RSA::PublicKey publicKey( params );
|
||||
|
||||
rsaDecryptor.reset(new CryptoPP::RSAES_OAEP_SHA_Decryptor(privateKey));
|
||||
rsaEncryptor.reset(new CryptoPP::RSAES_OAEP_SHA_Encryptor(publicKey));
|
||||
signer1024bit.reset(new CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Signer(privateKey));
|
||||
verifier1024bit.reset(new CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Verifier(publicKey));
|
||||
rsaDecryptor.AccessKey() = privateKey;
|
||||
rsaEncryptor.AccessKey() = publicKey;
|
||||
signer1024bit.AccessKey() = privateKey;
|
||||
verifier1024bit.AccessKey() = publicKey;
|
||||
pubKeyModulus = publicKey.GetModulus();
|
||||
|
||||
//write to file
|
||||
|
|
@ -347,14 +337,14 @@ void AuthServer::LoadCryptoKeys()
|
|||
string AuthServer::Encrypt(string input)
|
||||
{
|
||||
string output;
|
||||
CryptoPP::StringSource(input,true, new CryptoPP::PK_EncryptorFilter(randPool, *rsaEncryptor, new CryptoPP::StringSink(output)));
|
||||
CryptoPP::StringSource(input,true, new CryptoPP::PK_EncryptorFilter(randPool, rsaEncryptor, new CryptoPP::StringSink(output)));
|
||||
return output;
|
||||
}
|
||||
|
||||
string AuthServer::Decrypt(string input)
|
||||
{
|
||||
string output;
|
||||
CryptoPP::StringSource(input,true, new CryptoPP::PK_DecryptorFilter(randPool, *rsaDecryptor, new CryptoPP::StringSink(output)));
|
||||
CryptoPP::StringSource(input,true, new CryptoPP::PK_DecryptorFilter(randPool, rsaDecryptor, new CryptoPP::StringSink(output)));
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
@ -363,8 +353,8 @@ ByteBuffer AuthServer::SignWith1024Bit( byte *message,size_t messageLen )
|
|||
//generate signature
|
||||
ByteBuffer signMe(message,messageLen);
|
||||
vector<byte> signature;
|
||||
signature.resize(signer1024bit->MaxSignatureLength());
|
||||
size_t actualSignatureSize = signer1024bit->SignMessage(randPool,(byte*)signMe.contents(),signMe.size(),&signature[0]);
|
||||
signature.resize(signer1024bit.MaxSignatureLength());
|
||||
size_t actualSignatureSize = signer1024bit.SignMessage(randPool,(byte*)signMe.contents(),signMe.size(),&signature[0]);
|
||||
signature.resize(actualSignatureSize);
|
||||
|
||||
return ByteBuffer(signature);
|
||||
|
|
@ -372,7 +362,7 @@ ByteBuffer AuthServer::SignWith1024Bit( byte *message,size_t messageLen )
|
|||
|
||||
bool AuthServer::VerifyWith1024Bit( byte *message,size_t messageLen,byte *signature,size_t signatureLen )
|
||||
{
|
||||
return verifier1024bit->VerifyMessage(message,messageLen,signature,signatureLen);
|
||||
return verifier1024bit.VerifyMessage(message,messageLen,signature,signatureLen);
|
||||
}
|
||||
|
||||
ByteBuffer AuthServer::GetPubKeyData()
|
||||
|
|
@ -407,6 +397,7 @@ AuthServer::~AuthServer()
|
|||
|
||||
void AuthServer::Start()
|
||||
{
|
||||
LoadSignKeys();
|
||||
LoadCryptoKeys();
|
||||
|
||||
int Port = sConfig.GetIntDefault("AuthServer.Port",11000);
|
||||
|
|
|
|||
|
|
@ -62,12 +62,15 @@ private:
|
|||
|
||||
CryptoPP::AutoSeededRandomPool randPool;
|
||||
|
||||
shared_ptr<CryptoPP::RSAES_OAEP_SHA_Decryptor> rsaDecryptor;
|
||||
shared_ptr<CryptoPP::RSAES_OAEP_SHA_Encryptor> rsaEncryptor;
|
||||
shared_ptr<CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Signer> signer1024bit;
|
||||
shared_ptr<CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Verifier> verifier1024bit;
|
||||
shared_ptr<CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Signer> signer2048bit;
|
||||
shared_ptr<CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Verifier> verifier2048bit;
|
||||
CryptoPP::RSAES_OAEP_SHA_Decryptor rsaDecryptor;
|
||||
CryptoPP::RSAES_OAEP_SHA_Encryptor rsaEncryptor;
|
||||
|
||||
typedef CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Signer RSASigner;
|
||||
typedef CryptoPP::Weak::RSASSA_PKCS1v15_MD5_Verifier RSAVerifier;
|
||||
RSASigner signer1024bit;
|
||||
RSAVerifier verifier1024bit;
|
||||
RSASigner signer2048bit;
|
||||
RSAVerifier verifier2048bit;
|
||||
|
||||
CryptoPP::Integer pubKeyModulus;
|
||||
vector<byte> pubKeySignature;
|
||||
|
|
|
|||
|
|
@ -30,8 +30,6 @@
|
|||
#include "Database/DatabaseEnv.h"
|
||||
#include "SignedDataStruct.h"
|
||||
|
||||
const byte AuthSocket::blankIV[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
AuthSocket::AuthSocket(ISocketHandler& h) : TCPVarLenSocket(h)
|
||||
{
|
||||
matrixVersion = 0;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ private:
|
|||
TwofishCryptEngine m_tfEngine;
|
||||
|
||||
uint32 matrixVersion;
|
||||
static const byte blankIV[16];
|
||||
byte challenge[16];
|
||||
byte finalChallenge[16];
|
||||
|
||||
|
|
|
|||
|
|
@ -178,18 +178,6 @@ static inline void xchg32 (void *a, void *b)
|
|||
#define BITS_TO_BYTES(x) (((x)+7)>>3)
|
||||
#define BYTES_TO_BITS(x) ((x)<<3)
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using boost::shared_ptr;
|
||||
using boost::dynamic_pointer_cast;
|
||||
#include <boost/make_shared.hpp>
|
||||
using boost::make_shared;
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
using boost::scoped_ptr;
|
||||
#include <boost/lexical_cast.hpp>
|
||||
using boost::lexical_cast;
|
||||
#include <boost/format.hpp>
|
||||
using boost::format;
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
|
@ -231,8 +219,25 @@ using std::list;
|
|||
using std::map;
|
||||
using std::string;
|
||||
|
||||
#undef FD_SETSIZE
|
||||
#define FD_SETSIZE 200 // 200 per thread should be plenty :p
|
||||
#if COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1600 && _HAS_TR1
|
||||
#include <memory>
|
||||
using std::tr1::shared_ptr;
|
||||
using std::tr1::make_shared;
|
||||
using std::tr1::dynamic_pointer_cast;
|
||||
#else
|
||||
#include <boost/shared_ptr.hpp>
|
||||
using boost::shared_ptr;
|
||||
using boost::dynamic_pointer_cast;
|
||||
#include <boost/make_shared.hpp>
|
||||
using boost::make_shared;
|
||||
#endif
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
using boost::scoped_ptr;
|
||||
#include <boost/lexical_cast.hpp>
|
||||
using boost::lexical_cast;
|
||||
#include <boost/format.hpp>
|
||||
using boost::format;
|
||||
|
||||
#if PLATFORM == PLATFORM_WIN32
|
||||
#include <winsock2.h>
|
||||
|
|
|
|||
|
|
@ -35,12 +35,8 @@
|
|||
#include "GameSocket.h"
|
||||
#include "EncryptedPacket.h"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
GameClient::GameClient(shared_ptr<SocketAddress> address, GameSocket *sock)
|
||||
GameClient::GameClient(sockaddr_in inc_addr, GameSocket *sock):m_address(inc_addr),m_sock(sock)
|
||||
{
|
||||
m_sock = sock;
|
||||
m_address = address;
|
||||
m_serverSequence = 0;
|
||||
m_serverCommandsSent = 0;
|
||||
m_clientCommandsReceived = 0;
|
||||
|
|
@ -152,7 +148,7 @@ void GameClient::HandlePacket( const char *pData, uint16 nLength )
|
|||
}
|
||||
beatPacket << uint16(swap16(numberOfBeats));
|
||||
|
||||
m_sock->SendToBuf(*m_address, beatPacket.contents(), beatPacket.size(), 0);
|
||||
m_sock->SendToBuf(m_address, beatPacket.contents(), beatPacket.size(), 0);
|
||||
}
|
||||
|
||||
//notify margin that udp session is established
|
||||
|
|
@ -170,7 +166,7 @@ void GameClient::HandlePacket( const char *pData, uint16 nLength )
|
|||
|
||||
if (m_worldLoaded == true && pData[0] != 0x01) // Ping...just reply with the same thing
|
||||
{
|
||||
m_sock->SendToBuf(*m_address, pData, nLength, 0);
|
||||
m_sock->SendToBuf(m_address, pData, nLength, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -354,7 +350,7 @@ void GameClient::SendEncrypted(SequencedPacket withSequences)
|
|||
sendMe << uint8(1);
|
||||
sendMe.append(withEncryption.toCipherText(m_tfEngine));
|
||||
|
||||
m_sock->SendToBuf(*m_address, sendMe.contents(), sendMe.size(), 0);
|
||||
m_sock->SendToBuf(m_address, sendMe.contents(), sendMe.size(), 0);
|
||||
}
|
||||
|
||||
void GameClient::PSSChanged( uint8 oldPSS,uint8 newPSS )
|
||||
|
|
|
|||
|
|
@ -30,18 +30,18 @@
|
|||
#include "PlayerObject.h"
|
||||
#include "MessageTypes.h"
|
||||
#include "Log.h"
|
||||
#include <Sockets/SocketAddress.h>
|
||||
#include <Sockets/IpV4Address.h>
|
||||
|
||||
class GameClient
|
||||
{
|
||||
public:
|
||||
GameClient(shared_ptr<SocketAddress> address, class GameSocket *sock);
|
||||
GameClient(sockaddr_in inc_addr, class GameSocket *sock);
|
||||
~GameClient();
|
||||
|
||||
inline uint32 LastActive() { return m_lastActivity; }
|
||||
inline bool IsValid() { return m_validClient; }
|
||||
void Invalidate() { m_validClient=false;}
|
||||
string Address() { return m_address->Convert(true); }
|
||||
string Address() { return m_address.Convert(true); }
|
||||
uint32 GetSessionId()
|
||||
{
|
||||
if (m_encryptionInitialized == true)
|
||||
|
|
@ -261,7 +261,7 @@ private:
|
|||
|
||||
// Master Sock handle, client's address structure, last received packet
|
||||
class GameSocket *m_sock;
|
||||
shared_ptr<SocketAddress> m_address;
|
||||
Ipv4Address m_address;
|
||||
uint32 m_lastActivity;
|
||||
uint32 m_lastPacketReceivedMS;
|
||||
uint32 m_lastOrderedFlush;
|
||||
|
|
|
|||
|
|
@ -17,15 +17,14 @@ GameSocket::~GameSocket()
|
|||
|
||||
void GameSocket::OnRawData( const char *pData,size_t len,struct sockaddr *sa_from,socklen_t sa_len )
|
||||
{
|
||||
stringstream IP;
|
||||
struct sockaddr_in inc_addr;
|
||||
memcpy(&inc_addr,sa_from,sa_len);
|
||||
shared_ptr<SocketAddress> theAddr(new Ipv4Address(inc_addr));
|
||||
Ipv4Address theAddr(inc_addr);
|
||||
|
||||
if (theAddr->IsValid() == false)
|
||||
if (theAddr.IsValid() == false)
|
||||
return;
|
||||
|
||||
string IPStr = theAddr->Convert(true);
|
||||
string IPStr = theAddr.Convert(true);
|
||||
GClientList::iterator it = m_clients.find(IPStr);
|
||||
if (it != m_clients.end())
|
||||
{
|
||||
|
|
@ -43,7 +42,7 @@ void GameSocket::OnRawData( const char *pData,size_t len,struct sockaddr *sa_fro
|
|||
}
|
||||
else
|
||||
{
|
||||
m_clients[IPStr] = new GameClient(theAddr, this);
|
||||
m_clients[IPStr] = new GameClient(inc_addr, this);
|
||||
DEBUG_LOG(format ("Client connected [%1%], now have [%2%] clients")
|
||||
% IPStr % Clients_Connected());
|
||||
|
||||
|
|
|
|||
|
|
@ -36,10 +36,6 @@
|
|||
#include "GameServer.h"
|
||||
#include "EncryptedPacket.h"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
const byte MarginSocket::blankIV[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
MarginSocket::MarginSocket(ISocketHandler& h) : TCPVarLenSocket(h)
|
||||
{
|
||||
memset(challenge,0,sizeof(challenge));
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ private:
|
|||
uint32 sessionId;
|
||||
uint64 charId;
|
||||
|
||||
static const byte blankIV[16];
|
||||
byte challenge[16];
|
||||
byte weirdSequenceOfBytes[16];
|
||||
string soeChatString;
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ void PlayerObject::saveDataToDB()
|
|||
else
|
||||
{
|
||||
m_savedPos = m_pos;
|
||||
m_parent.QueueCommand(boost::make_shared<SystemChatMsg>( (format("Character data for %1% has been written to the database.") % m_handle).str() ));
|
||||
m_parent.QueueCommand(make_shared<SystemChatMsg>( (format("Character data for %1% has been written to the database.") % m_handle).str() ));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -412,8 +412,8 @@ void PlayerObject::HandleCommand( ByteBuffer &srcCmd )
|
|||
string theMessage((const char*)&messageBuf[0],messageBuf.size()-1);
|
||||
|
||||
INFO_LOG(format("%1% says %2%") % m_handle % theMessage);
|
||||
m_parent.QueueCommand(boost::make_shared<SystemChatMsg>((format("You said %1%") % theMessage).str()));
|
||||
sGame.AnnounceCommand(&m_parent,boost::make_shared<PlayerChatMsg>(m_handle,theMessage));
|
||||
m_parent.QueueCommand(make_shared<SystemChatMsg>((format("You said %1%") % theMessage).str()));
|
||||
sGame.AnnounceCommand(&m_parent,make_shared<PlayerChatMsg>(m_handle,theMessage));
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,17 +118,7 @@ void CThreadPool::ExecuteTask(ThreadContext * ExecutionTarget)
|
|||
}
|
||||
|
||||
// add the thread to the active set
|
||||
stringstream outMsg;
|
||||
using namespace std;
|
||||
|
||||
#ifdef __LP64__
|
||||
#define ptrIntType uint64
|
||||
#else
|
||||
#define ptrIntType uint32
|
||||
#endif
|
||||
|
||||
outMsg << "Thread " << t->ControlInterface.GetId() << " is now executing task at 0x" << setw(sizeof(ExecutionTarget)*2) << setfill('0') << hex << ptrIntType(ExecutionTarget) << dec << ".";
|
||||
DEBUG_LOG(outMsg.str());
|
||||
DEBUG_LOG(format("Thread %u is now executing task at %p.") % t->ControlInterface.GetId() % ExecutionTarget);
|
||||
m_activeThreads.insert(t);
|
||||
_mutex.Release();
|
||||
}
|
||||
|
|
@ -328,9 +318,7 @@ static void * thread_proc(void * param)
|
|||
{
|
||||
ThreadStruct * t = (ThreadStruct*)param;
|
||||
t->SetupMutex.Acquire();
|
||||
stringstream strBuf;
|
||||
strBuf << "ThreadPool::Thread " << t->ControlInterface.GetId() << " started.";
|
||||
DEBUG_LOG(strBuf.str());
|
||||
DEBUG_LOG(format("ThreadPool::Thread %1% started.") % t->ControlInterface.GetId());
|
||||
t->SetupMutex.Release();
|
||||
|
||||
for(;;)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue