diff --git a/Reality/Source/AuthServer.cpp b/Reality/Source/AuthServer.cpp index d7dd870..7066d62 100644 --- a/Reality/Source/AuthServer.cpp +++ b/Reality/Source/AuthServer.cpp @@ -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 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 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 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 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); diff --git a/Reality/Source/AuthServer.h b/Reality/Source/AuthServer.h index 4658e37..9caf648 100644 --- a/Reality/Source/AuthServer.h +++ b/Reality/Source/AuthServer.h @@ -62,12 +62,15 @@ private: CryptoPP::AutoSeededRandomPool randPool; - shared_ptr rsaDecryptor; - shared_ptr rsaEncryptor; - shared_ptr signer1024bit; - shared_ptr verifier1024bit; - shared_ptr signer2048bit; - shared_ptr 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 pubKeySignature; diff --git a/Reality/Source/AuthSocket.cpp b/Reality/Source/AuthSocket.cpp index 79ab7c0..0f45ad1 100644 --- a/Reality/Source/AuthSocket.cpp +++ b/Reality/Source/AuthSocket.cpp @@ -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; diff --git a/Reality/Source/AuthSocket.h b/Reality/Source/AuthSocket.h index 0abe20e..255528b 100644 --- a/Reality/Source/AuthSocket.h +++ b/Reality/Source/AuthSocket.h @@ -47,7 +47,6 @@ private: TwofishCryptEngine m_tfEngine; uint32 matrixVersion; - static const byte blankIV[16]; byte challenge[16]; byte finalChallenge[16]; diff --git a/Reality/Source/Common.h b/Reality/Source/Common.h index 82d118f..a440cbf 100644 --- a/Reality/Source/Common.h +++ b/Reality/Source/Common.h @@ -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 -using boost::shared_ptr; -using boost::dynamic_pointer_cast; -#include -using boost::make_shared; -#include -using boost::scoped_ptr; -#include -using boost::lexical_cast; -#include -using boost::format; - #include #include #include @@ -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 +using std::tr1::shared_ptr; +using std::tr1::make_shared; +using std::tr1::dynamic_pointer_cast; +#else +#include +using boost::shared_ptr; +using boost::dynamic_pointer_cast; +#include +using boost::make_shared; +#endif + +#include +using boost::scoped_ptr; +#include +using boost::lexical_cast; +#include +using boost::format; #if PLATFORM == PLATFORM_WIN32 #include diff --git a/Reality/Source/GameClient.cpp b/Reality/Source/GameClient.cpp index 4a59592..ebd64c1 100644 --- a/Reality/Source/GameClient.cpp +++ b/Reality/Source/GameClient.cpp @@ -35,12 +35,8 @@ #include "GameSocket.h" #include "EncryptedPacket.h" -#pragma pack(1) - -GameClient::GameClient(shared_ptr 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 ) diff --git a/Reality/Source/GameClient.h b/Reality/Source/GameClient.h index 44e2e76..f2c652c 100644 --- a/Reality/Source/GameClient.h +++ b/Reality/Source/GameClient.h @@ -30,18 +30,18 @@ #include "PlayerObject.h" #include "MessageTypes.h" #include "Log.h" -#include +#include class GameClient { public: - GameClient(shared_ptr 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 m_address; + Ipv4Address m_address; uint32 m_lastActivity; uint32 m_lastPacketReceivedMS; uint32 m_lastOrderedFlush; diff --git a/Reality/Source/GameSocket.cpp b/Reality/Source/GameSocket.cpp index a7f1ba6..969ef1a 100644 --- a/Reality/Source/GameSocket.cpp +++ b/Reality/Source/GameSocket.cpp @@ -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 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()); diff --git a/Reality/Source/MarginSocket.cpp b/Reality/Source/MarginSocket.cpp index 2c34aec..2fd5e6e 100644 --- a/Reality/Source/MarginSocket.cpp +++ b/Reality/Source/MarginSocket.cpp @@ -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)); diff --git a/Reality/Source/MarginSocket.h b/Reality/Source/MarginSocket.h index 5e94997..f6ea70e 100644 --- a/Reality/Source/MarginSocket.h +++ b/Reality/Source/MarginSocket.h @@ -73,7 +73,6 @@ private: uint32 sessionId; uint64 charId; - static const byte blankIV[16]; byte challenge[16]; byte weirdSequenceOfBytes[16]; string soeChatString; diff --git a/Reality/Source/PlayerObject.cpp b/Reality/Source/PlayerObject.cpp index 0ff8806..63cdb84 100644 --- a/Reality/Source/PlayerObject.cpp +++ b/Reality/Source/PlayerObject.cpp @@ -183,7 +183,7 @@ void PlayerObject::saveDataToDB() else { m_savedPos = m_pos; - m_parent.QueueCommand(boost::make_shared( (format("Character data for %1% has been written to the database.") % m_handle).str() )); + m_parent.QueueCommand(make_shared( (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((format("You said %1%") % theMessage).str())); - sGame.AnnounceCommand(&m_parent,boost::make_shared(m_handle,theMessage)); + m_parent.QueueCommand(make_shared((format("You said %1%") % theMessage).str())); + sGame.AnnounceCommand(&m_parent,make_shared(m_handle,theMessage)); return; } diff --git a/Reality/Source/Threading/ThreadPool.cpp b/Reality/Source/Threading/ThreadPool.cpp index d0a993e..0d3b785 100644 --- a/Reality/Source/Threading/ThreadPool.cpp +++ b/Reality/Source/Threading/ThreadPool.cpp @@ -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(;;)