2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// cAuthenticator.h
|
|
|
|
|
|
|
|
// Interfaces to the cAuthenticator class representing the thread that authenticates users against the official MC server
|
|
|
|
// Authentication prevents "hackers" from joining with an arbitrary username (possibly impersonating the server admins)
|
|
|
|
// For more info, see http://wiki.vg/Session#Server_operation
|
|
|
|
// In MCS, authentication is implemented as a single thread that receives queued auth requests and dispatches them one by one.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#ifndef CAUTHENTICATOR_H_INCLUDED
|
|
|
|
#define CAUTHENTICATOR_H_INCLUDED
|
|
|
|
|
2014-04-13 07:04:56 -04:00
|
|
|
#include "../OSSupport/IsThread.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fwd: "cRoot.h"
|
|
|
|
class cRoot;
|
|
|
|
|
2014-07-15 19:03:47 -04:00
|
|
|
namespace Json
|
|
|
|
{
|
|
|
|
class Value;
|
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cAuthenticator :
|
|
|
|
public cIsThread
|
|
|
|
{
|
|
|
|
typedef cIsThread super;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
|
|
|
cAuthenticator(void);
|
|
|
|
~cAuthenticator();
|
|
|
|
|
2014-04-13 07:04:56 -04:00
|
|
|
/** (Re-)read server and address from INI: */
|
2013-10-26 13:47:12 -04:00
|
|
|
void ReadINI(cIniFile & IniFile);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-04-13 07:04:56 -04:00
|
|
|
/** Queues a request for authenticating a user. If the auth fails, the user will be kicked */
|
2012-06-14 09:06:06 -04:00
|
|
|
void Authenticate(int a_ClientID, const AString & a_UserName, const AString & a_ServerHash);
|
|
|
|
|
2014-04-13 07:04:56 -04:00
|
|
|
/** Starts the authenticator thread. The thread may be started and stopped repeatedly */
|
2013-10-26 13:47:12 -04:00
|
|
|
void Start(cIniFile & IniFile);
|
2014-04-13 07:04:56 -04:00
|
|
|
|
|
|
|
/** Stops the authenticator thread. The thread may be started and stopped repeatedly */
|
2012-06-14 09:06:06 -04:00
|
|
|
void Stop(void);
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
class cUser
|
|
|
|
{
|
|
|
|
public:
|
2012-09-06 13:36:59 -04:00
|
|
|
int m_ClientID;
|
|
|
|
AString m_Name;
|
|
|
|
AString m_ServerID;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2012-09-06 13:36:59 -04:00
|
|
|
cUser(int a_ClientID, const AString & a_Name, const AString & a_ServerID) :
|
|
|
|
m_ClientID(a_ClientID),
|
|
|
|
m_Name(a_Name),
|
|
|
|
m_ServerID(a_ServerID)
|
|
|
|
{
|
|
|
|
}
|
2014-04-13 07:04:56 -04:00
|
|
|
};
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
typedef std::deque<cUser> cUserList;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cCriticalSection m_CS;
|
|
|
|
cUserList m_Queue;
|
|
|
|
cEvent m_QueueNonempty;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
AString m_Server;
|
|
|
|
AString m_Address;
|
2014-07-14 14:49:31 -04:00
|
|
|
AString m_PropertiesAddress;
|
2012-06-14 09:06:06 -04:00
|
|
|
bool m_ShouldAuthenticate;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
|
|
|
/** cIsThread override: */
|
2012-06-14 09:06:06 -04:00
|
|
|
virtual void Execute(void) override;
|
2014-04-13 07:04:56 -04:00
|
|
|
|
2014-07-15 19:03:47 -04:00
|
|
|
/** Connects to a hostname using SSL, sends given data, and sets the response, returning whether all was successful or not */
|
2014-07-16 06:23:26 -04:00
|
|
|
bool SecureGetFromAddress(const AString & a_CACerts, const AString & a_ExpectedPeerName, const AString & a_Request, AString & a_Response);
|
2014-07-14 14:49:31 -04:00
|
|
|
|
2014-07-16 06:21:02 -04:00
|
|
|
/** Returns true if the user authenticated okay, false on error
|
|
|
|
Sets the username, UUID, and properties (i.e. skin) fields
|
|
|
|
*/
|
|
|
|
bool AuthWithYggdrasil(AString & a_UserName, const AString & a_ServerId, AString & a_UUID, Json::Value & a_Properties);
|
2012-06-14 09:06:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CAUTHENTICATOR_H_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|