More work on gsasl authentication.

This commit is contained in:
lotodore
2009-10-11 12:07:56 +00:00
parent 1f7f045d15
commit cfc11f7f89
8 changed files with 89 additions and 18 deletions
+8 -11
View File
@@ -111,14 +111,14 @@ public:
// TODO
}
virtual void PlayerLoginSuccess(unsigned requestId, DB_id dbPlayerId)
virtual void PlayerLoginSuccess(unsigned requestId, DB_id dbPlayerId, const std::string &secret)
{
m_server.AuthenticationSuccess(requestId, dbPlayerId);
m_server.UserValid(requestId, dbPlayerId, secret);
}
virtual void PlayerLoginFailed(unsigned requestId)
{
m_server.AuthenticationFailure(requestId);
m_server.UserInvalid(requestId);
}
virtual void CreateGameSuccess(unsigned requestId, DB_id gameId)
@@ -707,11 +707,8 @@ ServerLobbyThread::InitAuthContext()
void
ServerLobbyThread::ClearAuthContext()
{
if (m_authContext)
{
gsasl_done(m_authContext);
m_authContext = NULL;
}
gsasl_done(m_authContext);
m_authContext = NULL;
}
void
@@ -1294,17 +1291,17 @@ void
ServerLobbyThread::AuthenticatePlayer(SessionWrapper session, const std::string &password)
{
assert(session.playerData);
m_database->AsyncPlayerLogin(session.playerData->GetUniqueId(), session.playerData->GetName(), password);
m_database->AsyncPlayerLogin(session.playerData->GetUniqueId(), session.playerData->GetName());
}
void
ServerLobbyThread::AuthenticationSuccess(unsigned playerId, DB_id dbPlayerId)
ServerLobbyThread::UserValid(unsigned playerId, DB_id dbPlayerId, const string &dbSecret)
{
InitAfterLogin(m_sessionManager.GetSessionByUniquePlayerId(playerId, true));
}
void
ServerLobbyThread::AuthenticationFailure(unsigned playerId)
ServerLobbyThread::UserInvalid(unsigned playerId)
{
SessionError(m_sessionManager.GetSessionByUniquePlayerId(playerId, true), ERR_NET_INVALID_PASSWORD);
}
+64 -1
View File
@@ -18,16 +18,21 @@
***************************************************************************/
#include <net/sessiondata.h>
#include <gsasl.h>
using namespace std;
SessionData::SessionData(boost::shared_ptr<boost::asio::ip::tcp::socket> sock, SessionId id, SessionDataCallback &cb)
: m_socket(sock), m_id(id), m_gameId(0), m_state(SessionData::Init), m_readyFlag(false),
m_wantsLobbyMsg(true), m_activityTimeoutNoticeSent(false), m_callback(cb)
m_wantsLobbyMsg(true), m_activityTimeoutNoticeSent(false), m_callback(cb),
m_authSession(NULL), m_curAuthStep(0)
{
}
SessionData::~SessionData()
{
m_callback.SignalSessionTerminated(m_id);
InternalClearAuthSession();
}
SessionId
@@ -71,6 +76,64 @@ SessionData::GetAsioSocket()
return m_socket;
}
bool
SessionData::CreateAuthSession(Gsasl *context, bool server, const string &userName, const string &password)
{
bool retVal = false;
boost::mutex::scoped_lock lock(m_dataMutex);
InternalClearAuthSession();
int errorCode;
if (server)
errorCode = gsasl_server_start(context, "SCRAM-SHA-1", &m_authSession);
else
errorCode = gsasl_client_start(context, "SCRAM-SHA-1", &m_authSession);
if (errorCode == GSASL_OK)
{
gsasl_property_set(m_authSession, GSASL_AUTHID, userName.c_str());
gsasl_property_set(m_authSession, GSASL_PASSWORD, password.c_str());
retVal = true;
}
return retVal;
}
bool
SessionData::AuthStep(int stepNum, const std::string &inData, std::string &outData)
{
bool retVal = false;
boost::mutex::scoped_lock lock(m_dataMutex);
if (m_authSession && stepNum == m_curAuthStep + 1)
{
m_curAuthStep = stepNum;
char *tmpOut;
size_t tmpOutSize;
int errorCode = gsasl_step(m_authSession, inData.c_str(), inData.length(), &tmpOut, &tmpOutSize);
if (errorCode == GSASL_NEEDS_MORE)
{
outData = string(tmpOut, tmpOutSize);
retVal = true;
}
else if (errorCode == GSASL_OK && stepNum != 1)
{
outData = string(tmpOut, tmpOutSize);
retVal = true;
InternalClearAuthSession();
}
gsasl_free(tmpOut);
}
return retVal;
}
void
SessionData::InternalClearAuthSession()
{
if (m_authSession)
{
gsasl_finish(m_authSession);
m_authSession = NULL;
m_curAuthStep = 0;
}
}
void
SessionData::SetReadyFlag()
{