Encrypt own cards which are sent at the beginning of the hand - only applicable to registered users.

This commit is contained in:
lotodore
2010-09-04 11:56:40 +00:00
parent daf99deac3
commit c2ba56aba9
89 changed files with 675 additions and 285 deletions
+1
View File
@@ -24,6 +24,7 @@
#include <core/loghelper.h>
#include <third_party/asn1/ChatCleanerMessage.h>
#include <sstream>
using namespace std;
using boost::asio::ip::tcp;
+36 -2
View File
@@ -1684,8 +1684,42 @@ ClientStateWaitHand::InternalHandlePacket(boost::shared_ptr<ClientThread> client
// These are the cards. Good luck.
HandStartMessage_t *netHandStart = &tmpPacket->GetMsg()->choice.handStartMessage;
int myCards[2];
myCards[0] = (int)netHandStart->yourCard1;
myCards[1] = (int)netHandStart->yourCard2;
string userPassword(client->GetContext().GetPassword());
if (netHandStart->yourCards.present == yourCards_PR_plainCards
&& userPassword.empty())
{
PlainCards_t *plainCards = &netHandStart->yourCards.choice.plainCards;
myCards[0] = (int)plainCards->plainCard1;
myCards[1] = (int)plainCards->plainCard2;
}
else if (netHandStart->yourCards.present == yourCards_PR_encryptedCards
&& !userPassword.empty())
{
EncryptedCards_t *encryptedCards = &netHandStart->yourCards.choice.encryptedCards;
string plainCards;
if (!CryptHelper::AES128Decrypt((const unsigned char *)userPassword.c_str(),
(unsigned)userPassword.size(),
encryptedCards->encryptedCards.buf,
encryptedCards->encryptedCards.size,
plainCards))
{
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
}
istringstream cardDataStream(plainCards);
unsigned tmpPlayerId, tmpGameId;
int tmpHandNum;
cardDataStream >> tmpPlayerId;
cardDataStream >> tmpGameId;
cardDataStream >> tmpHandNum;
if (tmpPlayerId != client->GetGuiPlayerId()
|| tmpGameId != client->GetGameId()
|| tmpHandNum != client->GetGame()->getCurrentHandID())
{
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
}
cardDataStream >> myCards[0];
cardDataStream >> myCards[1];
}
client->GetGame()->getSeatsList()->front()->setMyCards(myCards);
client->GetGame()->initHand();
client->GetGame()->getCurrentHand()->setSmallBlind(netHandStart->smallBlind);
+45 -6
View File
@@ -502,7 +502,7 @@ ServerGameStateInit::InternalProcessPacket(boost::shared_ptr<ServerGame> server,
if (session.playerData->IsGameAdmin()
&& netStartEvent->gameId == server->GetId()
&& (server->GetGameData().gameType != GAME_TYPE_RANKING // ranking games need to be full
|| server->GetGameData().maxNumberOfPlayers == server->GetCurNumberOfPlayers()))
|| server->GetGameData().maxNumberOfPlayers == (int)server->GetCurNumberOfPlayers()))
{
SendStartEvent(*server, netStartEvent->fillWithComputerPlayers);
}
@@ -1062,19 +1062,58 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
{
// also send to inactive players, but not to disconnected players.
boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
if (tmpPlayer->getNetSessionData().get())
if (tmpPlayer->getNetSessionData())
{
int cards[2];
bool errorFlag = false;
tmpPlayer->getMyCards(cards);
boost::shared_ptr<NetPacket> notifyCards(new NetPacket(NetPacket::Alloc));
notifyCards->GetMsg()->present = PokerTHMessage_PR_handStartMessage;
HandStartMessage_t *netHandStart = &notifyCards->GetMsg()->choice.handStartMessage;
netHandStart->gameId = server->GetId();
netHandStart->yourCard1 = cards[0];
netHandStart->yourCard2 = cards[1];
netHandStart->smallBlind = curGame.getCurrentHand()->getSmallBlind();
server->GetLobbyThread().GetSender().Send(tmpPlayer->getNetSessionData(), notifyCards);
string tmpPassword(tmpPlayer->getNetSessionData()->AuthGetPassword());
if (tmpPassword.empty()) // encrypt only if password is present
{
netHandStart->yourCards.present = yourCards_PR_plainCards;
PlainCards_t *plainCards = &netHandStart->yourCards.choice.plainCards;
plainCards->plainCard1 = cards[0];
plainCards->plainCard2 = cards[1];
}
else
{
ostringstream cardDataStream;
vector<unsigned char> tmpCipher;
cardDataStream
<< tmpPlayer->getMyUniqueID() << " "
<< server->GetId() << " "
<< curGame.getCurrentHandID() << " "
<< cards[0] << " "
<< cards[1];
if (CryptHelper::AES128Encrypt((const unsigned char *)tmpPassword.c_str(),
(unsigned)tmpPassword.size(),
cardDataStream.str(),
tmpCipher)
&& !tmpCipher.empty())
{
netHandStart->yourCards.present = yourCards_PR_encryptedCards;
EncryptedCards_t *encryptedCards = &netHandStart->yourCards.choice.encryptedCards;
OCTET_STRING_fromBuf(
&encryptedCards->encryptedCards,
(const char *)&tmpCipher[0],
(int)tmpCipher.size());
}
else
{
server->RemovePlayer(tmpPlayer->getMyUniqueID(), ERR_SOCK_INVALID_STATE);
errorFlag = true;
}
}
if (!errorFlag)
{
netHandStart->smallBlind = curGame.getCurrentHand()->getSmallBlind();
server->GetLobbyThread().GetSender().Send(tmpPlayer->getNetSessionData(), notifyCards);
}
}
++i;
}
-1
View File
@@ -1463,7 +1463,6 @@ ServerLobbyThread::AuthChallenge(SessionWrapper session, const string &secret)
{
if (session.sessionData && session.playerData && session.sessionData->AuthGetCurStepNum() == 1)
{
session.playerData->SetPassword(secret); // For later encryption of data.
session.sessionData->AuthSetPassword(secret); // For this auth session.
string outChallenge(session.sessionData->AuthGetNextOutMsg());
+7
View File
@@ -149,6 +149,13 @@ SessionData::AuthSetPassword(const std::string &password)
{
if (m_authSession)
gsasl_property_set(m_authSession, GSASL_PASSWORD, password.c_str());
m_password = password;
}
string
SessionData::AuthGetPassword() const
{
return m_password;
}
string
+2 -2
View File
@@ -27,8 +27,8 @@
#include <third_party/asn1/PokerTHMessage.h>
#include <gamedata.h>
#define NET_VERSION_MAJOR 5
#define NET_VERSION_MINOR 2
#define NET_VERSION_MAJOR 6
#define NET_VERSION_MINOR 0
#define MAX_FILE_DATA_SIZE 256
#define MAX_PACKET_SIZE 384
+2
View File
@@ -62,6 +62,7 @@ public:
bool AuthStep(int stepNum, const std::string &inData);
std::string AuthGetUser() const;
void AuthSetPassword(const std::string &password);
std::string AuthGetPassword() const;
std::string AuthGetNextOutMsg() const;
int AuthGetCurStepNum() const;
@@ -102,6 +103,7 @@ private:
Gsasl_session *m_authSession;
int m_curAuthStep;
std::string m_nextGsaslMsg;
std::string m_password;
mutable boost::mutex m_dataMutex;
};