More gsasl changes.

This commit is contained in:
lotodore
2009-10-13 21:52:10 +00:00
parent a6319bf7d8
commit 88659e69ce
4 changed files with 33 additions and 12 deletions
+1 -1
View File
@@ -678,7 +678,7 @@ ClientStateStartSession::Enter(boost::shared_ptr<ClientThread> client)
AuthenticatedLogin_t *authLogin = &netInit->login.choice.authenticatedLogin;
// TODO
boost::shared_ptr<SessionData> tmpSession = context.GetSessionData();
tmpSession->CreateAuthSession(client->GetAuthContext(), false, context.GetPlayerName(), context.GetPassword());
tmpSession->CreateClientAuthSession(client->GetAuthContext(), context.GetPlayerName(), context.GetPassword());
string outUserData;
tmpSession->AuthStep(1, "", outUserData);
OCTET_STRING_fromBuf(&authLogin->clientUserData,
+6 -4
View File
@@ -905,7 +905,6 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
}
string playerName;
string authData;
MD5Buf avatarMD5;
bool guestUser = false;
if (initMessage.login.present == login_PR_anonymousLogin)
@@ -915,12 +914,15 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
}
else if (initMessage.login.present == login_PR_authenticatedLogin)
{
string inAuthData;
string outRequestData;
const AuthenticatedLogin_t *authLogin = &initMessage.login.choice.authenticatedLogin;
authData = string((const char *)authLogin->clientUserData.buf, authLogin->clientUserData.size);
inAuthData = string((const char *)authLogin->clientUserData.buf, authLogin->clientUserData.size);
if (authLogin->avatar)
memcpy(avatarMD5.data, authLogin->avatar->buf, MD5_DATA_SIZE);
// TODO
playerName = "testuser";
session.sessionData->CreateServerAuthSession(m_authContext);
session.sessionData->AuthStep(1, inAuthData, outRequestData);
playerName = session.sessionData->AuthGetUser();
}
else
SessionError(session, ERR_NET_INVALID_PASSWORD);
+23 -6
View File
@@ -76,17 +76,24 @@ SessionData::GetAsioSocket()
return m_socket;
}
bool
SessionData::CreateAuthSession(Gsasl *context, bool server, const string &userName, const string &password)
bool CreateServerAuthSession(Gsasl *context)
{
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);
errorCode = gsasl_server_start(context, "SCRAM-SHA-1", &m_authSession);
return errorCode == GSASL_OK;
}
bool
SessionData::CreateClientAuthSession(Gsasl *context, const string &userName, const string &password)
{
bool retVal = false;
boost::mutex::scoped_lock lock(m_dataMutex);
InternalClearAuthSession();
int errorCode;
errorCode = gsasl_client_start(context, "SCRAM-SHA-1", &m_authSession);
if (errorCode == GSASL_OK)
{
gsasl_property_set(m_authSession, GSASL_AUTHID, userName.c_str());
@@ -123,6 +130,16 @@ SessionData::AuthStep(int stepNum, const std::string &inData, std::string &outDa
return retVal;
}
string
SessionData::AuthGetUser()
{
string retStr;
if (m_authSession)
{
retStr = gsasl_property_fast(m_authSession, GSASL_AUTHID);
}
}
void
SessionData::InternalClearAuthSession()
{
+3 -1
View File
@@ -57,8 +57,10 @@ public:
boost::shared_ptr<boost::asio::ip::tcp::socket> GetAsioSocket();
bool CreateAuthSession(Gsasl *context, bool server, const std::string &userName, const std::string &password);
bool CreateServerAuthSession(Gsasl *context);
bool CreateClientAuthSession(Gsasl *context, const std::string &userName, const std::string &password);
bool AuthStep(int stepNum, const std::string &inData, std::string &outData);
string AuthGetUser();
void SetReadyFlag();
void ResetReadyFlag();