From d0898ed336b303403cfb1e4068f08b4351631d7f Mon Sep 17 00:00:00 2001 From: lotodore Date: Sat, 8 Sep 2007 11:00:46 +0000 Subject: [PATCH] Now using openssl on windows instead of ms crypto api. Can't stand all these handles for the crypto api, openssl will be required later anyway. MD5 sums will be used when transfering avatars for efficient caching - avatars are identified by their MD5 sum. Sorry for making it even harder to compile on windows... --- pokerth_game.pro | 6 +-- pokerth_lib.pro | 2 +- pokerth_server.pro | 5 +-- src/core/linux/rand.cpp | 34 --------------- src/core/rand.h | 7 ---- src/core/win32/rand.cpp | 63 ---------------------------- src/engine/local_engine/tools.cpp | 16 +++++-- src/engine/local_engine/tools.h | 2 - src/net/common/servergamestate.cpp | 1 - src/net/common/serverlobbythread.cpp | 9 +++- 10 files changed, 26 insertions(+), 119 deletions(-) delete mode 100644 src/core/linux/rand.cpp delete mode 100644 src/core/rand.h delete mode 100644 src/core/win32/rand.cpp diff --git a/pokerth_game.pro b/pokerth_game.pro index fdae01e7..1e1a1374 100644 --- a/pokerth_game.pro +++ b/pokerth_game.pro @@ -81,7 +81,6 @@ HEADERS += \ src/playerdata.h \ src/gamedata.h \ src/config/configfile.h \ - src/core/rand.h \ src/core/thread.h \ src/engine/boardinterface.h \ src/engine/enginefactory.h \ @@ -213,14 +212,15 @@ TRANSLATIONS = \ win32{ DEPENDPATH += src/net/win32/ src/core/win32 INCLUDEPATH += ../boost/ ../SDL/include ../SDL_mixer - INCLUDEPATH += ../SDL/include/SDL ../SDL_mixer/include - LIBPATH += ../boost/stage/lib + INCLUDEPATH += ../SDL/include/SDL ../SDL_mixer/include ../OpenSSL/include + LIBPATH += ../boost/stage/lib ../OpenSSL/lib #LIBPATH += Release/lib ../SDL/VisualC/SDL/Release ../SDL/VisualC/SDLmain/Release ../SDL_mixer/VisualC/Release LIBPATH += Debug/lib ../SDL/VisualC/SDL/Debug ../SDL/VisualC/SDLmain/Debug ../SDL_mixer/VisualC/Debug LIBPATH += ../SDL/lib ../SDL_mixer/lib LIBS += -lpokerth_lib + LIBS += -lssleay32MT LIBS += -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lole32 -luuid -luser32 -lmsimg32 -lshell32 -lkernel32 -lws2_32 -ladvapi32 -lsdl -lsdlmain -lsdl_mixer exists( ../boost/stage/lib/libboost_thread-mgw34-mt-1_34_1.a ){ LIBS += -lboost_thread-mgw34-mt-1_34_1 diff --git a/pokerth_lib.pro b/pokerth_lib.pro index 3a196ed2..d89d8461 100644 --- a/pokerth_lib.pro +++ b/pokerth_lib.pro @@ -161,7 +161,7 @@ win32{ SOURCES += src/core/win32/rand.cpp \ src/net/win32/socket_helper.cpp \ src/net/win32/socket_startup.cpp - INCLUDEPATH += ../boost/ ../SDL/include ../SDL_mixer + INCLUDEPATH += ../boost/ ../OpenSSL/include } !win32{ DEPENDPATH += src/net/linux/ src/core/linux diff --git a/pokerth_server.pro b/pokerth_server.pro index feb895b7..ec088da4 100644 --- a/pokerth_server.pro +++ b/pokerth_server.pro @@ -43,7 +43,6 @@ HEADERS += \ src/playerdata.h \ src/gamedata.h \ src/config/configfile.h \ - src/core/rand.h \ src/core/thread.h \ src/engine/boardinterface.h \ src/engine/enginefactory.h \ @@ -94,8 +93,8 @@ SOURCES += \ win32{ DEPENDPATH += src/net/win32/ src/core/win32 - INCLUDEPATH += ../boost/ - LIBPATH += ../boost/stage/lib + INCLUDEPATH += ../boost/ ../OpenSSL/include + LIBPATH += ../boost/stage/lib ../OpenSSL/lib #LIBPATH += Release/lib LIBPATH += Debug/lib diff --git a/src/core/linux/rand.cpp b/src/core/linux/rand.cpp deleted file mode 100644 index 0de6886f..00000000 --- a/src/core/linux/rand.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Lothar May * - * * - * 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 2 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, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifdef _WIN32 -#error This source code is not for Win32. -#endif - -#include -#include - -void -RandomBytes(unsigned char *buf, unsigned size) -{ - if(!RAND_bytes(buf, size)) - { - RAND_pseudo_bytes(buf, size); - } -} - diff --git a/src/core/rand.h b/src/core/rand.h deleted file mode 100644 index 593bab92..00000000 --- a/src/core/rand.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef RAND_H -#define RAND_H - -void RandomBytes(unsigned char *buf, unsigned size); - -#endif - diff --git a/src/core/win32/rand.cpp b/src/core/win32/rand.cpp deleted file mode 100644 index 4468f902..00000000 --- a/src/core/win32/rand.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Lothar May * - * * - * 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 2 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, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef _WIN32 -#error This source code is Win32 only. -#endif - -#include -#include - -#include - -class CryptData -{ -public: - CryptData() - { - if (!::CryptAcquireContext( - &cryptProvider, - NULL, - NULL, - PROV_RSA_FULL, - CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) - { - cryptProvider = 0; - } - } - ~CryptData() - { - if (cryptProvider) - CryptReleaseContext(cryptProvider, 0); - } - - HCRYPTPROV cryptProvider; -}; - -static CryptData g_cryptData; - -void -RandomBytes(unsigned char *buf, unsigned size) -{ - HCRYPTPROV provider = g_cryptData.cryptProvider; - - if (provider) - ::CryptGenRandom(provider, size, buf); -} - - diff --git a/src/engine/local_engine/tools.cpp b/src/engine/local_engine/tools.cpp index c48a1ed2..7a3f84a1 100755 --- a/src/engine/local_engine/tools.cpp +++ b/src/engine/local_engine/tools.cpp @@ -17,8 +17,12 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#define NOMINMAX // for Windows + #include "tools.h" -#include +#include + +#include using namespace std; @@ -34,7 +38,10 @@ void Tools::getRandNumber(int start, int end, int howMany, int* randArray, bool for (i=0; i - class Tools{ public: diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 29efe9bd..091651d1 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index af36256e..81667440 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include @@ -490,7 +490,12 @@ ServerLobbyThread::HandleNewConnection(boost::shared_ptr connData) // Create a random session id. // This id can be used to reconnect to the server if the connection was lost. unsigned sessionId; - RandomBytes((unsigned char *)&sessionId, sizeof(sessionId)); // TODO: check for collisions. + + // TODO: check for collisions. + if(!RAND_bytes((unsigned char *)&sessionId, sizeof(sessionId))) + { + RAND_pseudo_bytes((unsigned char *)&sessionId, sizeof(sessionId)); + } // Create a new session. boost::shared_ptr sessionData(new SessionData(connData->ReleaseSocket(), sessionId));