Trying to make gsasl authentication work...

This commit is contained in:
lotodore
2009-10-13 21:03:32 +00:00
parent cfc11f7f89
commit b61d43859e
5 changed files with 68 additions and 28 deletions
+8
View File
@@ -42,6 +42,7 @@ class Game;
class NetPacket;
class AvatarManager;
class QtToolsInterface;
struct Gsasl;
class ClientThread : public Thread, public boost::enable_shared_from_this<ClientThread>
{
@@ -91,6 +92,8 @@ public:
ServerStats GetStatData() const;
unsigned GetGameId() const;
Gsasl *GetAuthContext();
ClientCallback &GetCallback();
GuiInterface &GetGui();
AvatarManager &GetAvatarManager();
@@ -106,6 +109,9 @@ protected:
virtual void Main();
void RegisterTimers();
void CancelTimers();
void InitAuthContext();
void ClearAuthContext();
void InitGame();
void SendSessionPacket(boost::shared_ptr<NetPacket> packet);
@@ -194,6 +200,8 @@ private:
boost::shared_ptr<boost::asio::io_service> m_ioService;
boost::shared_ptr<ClientSenderCallback> m_senderCallback;
Gsasl *m_authContext;
NetPacketList m_outPacketList;
boost::shared_ptr<ClientContext> m_context;
+7 -7
View File
@@ -677,13 +677,13 @@ ClientStateStartSession::Enter(boost::shared_ptr<ClientThread> client)
netInit->login.present = login_PR_authenticatedLogin;
AuthenticatedLogin_t *authLogin = &netInit->login.choice.authenticatedLogin;
// TODO
/* OCTET_STRING_fromBuf(&authLogin->playerName,
context.GetPlayerName().c_str(),
context.GetPlayerName().length());
OCTET_STRING_fromBuf(&authLogin->password,
context.GetPassword().c_str(),
context.GetPassword().length());*/
//context.GetPassword();
boost::shared_ptr<SessionData> tmpSession = context.GetSessionData();
tmpSession->CreateAuthSession(client->GetAuthContext(), false, context.GetPlayerName(), context.GetPassword());
string outUserData;
tmpSession->AuthStep(1, "", outUserData);
OCTET_STRING_fromBuf(&authLogin->clientUserData,
outUserData.c_str(),
outUserData.length());
string avatarFile = client->GetQtToolsInterface().stringFromUtf8(context.GetAvatarFile());
if (!avatarFile.empty())
{
+38 -6
View File
@@ -37,6 +37,7 @@
#include <sstream>
#include <memory>
#include <cassert>
#include <gsasl.h>
#define TEMP_AVATAR_FILENAME "avatar.tmp"
#define CLIENT_AVATAR_LOOP_MSEC 100
@@ -440,16 +441,17 @@ ClientThread::GetAvatarManager()
void
ClientThread::Main()
{
// Start sub-threads.
m_avatarDownloader.reset(new DownloaderThread);
m_avatarDownloader->Run();
SetState(CLIENT_INITIAL_STATE::Instance());
RegisterTimers();
// Main loop.
boost::asio::io_service::work ioWork(*m_ioService);
try
{
InitAuthContext();
// Start sub-threads.
m_avatarDownloader.reset(new DownloaderThread);
m_avatarDownloader->Run();
SetState(CLIENT_INITIAL_STATE::Instance());
RegisterTimers();
boost::asio::io_service::work ioWork(*m_ioService);
m_ioService->run(); // Will only be aborted asynchronously.
@@ -468,6 +470,8 @@ ClientThread::Main()
// Terminate sub-threads.
m_avatarDownloader->SignalTermination();
m_avatarDownloader->Join(DOWNLOADER_THREAD_TERMINATE_TIMEOUT);
ClearAuthContext();
}
void
@@ -486,6 +490,27 @@ ClientThread::CancelTimers()
m_avatarTimer.cancel();
}
void
ClientThread::InitAuthContext()
{
int res = gsasl_init(&m_authContext);
if (res != GSASL_OK)
throw ClientException(__FILE__, __LINE__, ERR_NET_GSASL_INIT_FAILED, 0);
if (!gsasl_server_support_p(m_authContext, "SCRAM-SHA-1"))
{
gsasl_done(m_authContext);
throw ClientException(__FILE__, __LINE__, ERR_NET_GSASL_NO_SCRAM, 0);
}
}
void
ClientThread::ClearAuthContext()
{
gsasl_done(m_authContext);
m_authContext = NULL;
}
void
ClientThread::InitGame()
{
@@ -893,6 +918,13 @@ ClientThread::SetGameId(unsigned id)
m_curGameId = id;
}
Gsasl *
ClientThread::GetAuthContext()
{
assert(m_authContext);
return m_authContext;
}
const GameData &
ClientThread::GetGameData() const
{
+10 -10
View File
@@ -693,15 +693,15 @@ ServerLobbyThread::CancelTimers()
void
ServerLobbyThread::InitAuthContext()
{
int res = gsasl_init(&m_authContext);
if (res != GSASL_OK)
throw ServerException(__FILE__, __LINE__, ERR_NET_GSASL_INIT_FAILED, 0);
if (!gsasl_server_support_p(m_authContext, "SCRAM-SHA-1"))
{
gsasl_done(m_authContext);
throw ServerException(__FILE__, __LINE__, ERR_NET_GSASL_NO_SCRAM, 0);
}
int res = gsasl_init(&m_authContext);
if (res != GSASL_OK)
throw ServerException(__FILE__, __LINE__, ERR_NET_GSASL_INIT_FAILED, 0);
if (!gsasl_server_support_p(m_authContext, "SCRAM-SHA-1"))
{
gsasl_done(m_authContext);
throw ServerException(__FILE__, __LINE__, ERR_NET_GSASL_NO_SCRAM, 0);
}
}
void
@@ -969,7 +969,7 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
if (guestUser)
InitAfterLogin(session);
else
AuthenticatePlayer(session, authData);
AuthenticatePlayer(session, /*authData*/"testuser");
}
void
+5 -5
View File
@@ -87,11 +87,11 @@ SessionData::CreateAuthSession(Gsasl *context, bool server, const string &userNa
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;
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;
}