Encrypt own cards which are sent at the beginning of the hand - only applicable to registered users.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include <core/loghelper.h>
|
||||
#include <third_party/asn1/ChatCleanerMessage.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 = ¬ifyCards->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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user