Botcraft 26.3
Loading...
Searching...
No Matches
Botcraft::Authentifier Class Reference

#include <Authentifier.hpp>

Public Member Functions

 Authentifier ()
 
 ~Authentifier ()
 
bool AuthMicrosoft (const std::string &cache_key)
 Authentication using a Microsoft account, storing the credentials in the cache file.
 
bool AuthMCToken (const std::string &mc_token)
 Authentication using a minecraft token.
 
bool JoinServer (const std::string &server_id, const std::vector< unsigned char > &shared_secret, const std::vector< unsigned char > &server_public_key) const
 
const std::string & GetPlayerDisplayName () const
 
const std::array< unsigned char, 16 > & GetPlayerUUID () const
 
RSA * GetPrivateKey () const
 
const std::string & GetPublicKey () const
 
const std::string & GetKeySignature () const
 
long long int GetKeyTimestamp () const
 
std::vector< unsigned char > GetMessageSignature (const std::string &message, const int message_sent_index, const ProtocolCraft::UUID &chat_session_uuid, const std::vector< std::vector< unsigned char > > &last_seen, long long int &salt, long long int &timestamp)
 Compute the signature of a message.
 

Private Member Functions

void UpdateUUIDBytes ()
 Compute the UUID bytes from the string one.
 
void GetPlayerCertificates ()
 Get player certificates using the Minecraft token, throw if failed.
 

Private Attributes

std::string player_display_name
 
std::string mc_access_token
 
std::string mc_player_uuid
 
std::array< unsigned char, 16 > mc_player_uuid_bytes
 
RSA * private_key = nullptr
 
std::string public_key
 
std::string key_signature
 
long long int key_timestamp
 
std::mt19937 rnd
 

Detailed Description

Definition at line 21 of file Authentifier.hpp.

Constructor & Destructor Documentation

◆ Authentifier()

Botcraft::Authentifier::Authentifier ( )

Definition at line 73 of file Authentifier.cpp.

References key_timestamp, mc_player_uuid_bytes, and rnd.

◆ ~Authentifier()

Botcraft::Authentifier::~Authentifier ( )

Definition at line 82 of file Authentifier.cpp.

References private_key.

Member Function Documentation

◆ AuthMCToken()

bool Botcraft::Authentifier::AuthMCToken ( const std::string &  mc_token)

Authentication using a minecraft token.

Parameters
mc_tokenMinecraft token, must be valid
Returns
True if successfully authenticated, false otherwise

Definition at line 162 of file Authentifier.cpp.

References GetPlayerCertificates(), LOG_ERROR, LOG_INFO, mc_access_token, mc_player_uuid, player_display_name, and UpdateUUIDBytes().

◆ AuthMicrosoft()

bool Botcraft::Authentifier::AuthMicrosoft ( const std::string &  cache_key)

Authentication using a Microsoft account, storing the credentials in the cache file.

Parameters
cache_keyused as key to identify the credentials in cache file
Returns
True if successfully authenticated, false otherwise

Definition at line 95 of file Authentifier.cpp.

References ProtocolCraft::Json::Value::contains(), ProtocolCraft::Json::Value::get_object(), ProtocolCraft::Json::Value::get_string(), GetPlayerCertificates(), ProtocolCraft::Json::Value::is_number(), ProtocolCraft::Json::Value::is_string(), LOG_ERROR, LOG_INFO, LOG_WARNING, mc_access_token, mc_player_uuid, player_display_name, and UpdateUUIDBytes().

◆ GetKeySignature()

const std::string & Botcraft::Authentifier::GetKeySignature ( ) const

Definition at line 301 of file Authentifier.cpp.

References key_signature.

◆ GetKeyTimestamp()

long long int Botcraft::Authentifier::GetKeyTimestamp ( ) const

Definition at line 306 of file Authentifier.cpp.

References key_timestamp.

◆ GetMessageSignature()

std::vector< unsigned char > Botcraft::Authentifier::GetMessageSignature ( const std::string &  message,
const int  message_sent_index,
const ProtocolCraft::UUID &  chat_session_uuid,
const std::vector< std::vector< unsigned char > > &  last_seen,
long long int &  salt,
long long int &  timestamp 
)

Compute the signature of a message.

Parameters
messageMessage to send
message_sent_indexIndex of the message in this message chain
chat_session_uuidUUID of the chat session, as sent in ServerboundChatSessionUpdatePacket
last_seenVector of signatures of previously received messages
saltOutput salt used to generate the signature
timestampOutput timestamp in ms used to generate the signature
Returns
The message signature

Definition at line 318 of file Authentifier.cpp.

References LOG_ERROR.

◆ GetPlayerCertificates()

void Botcraft::Authentifier::GetPlayerCertificates ( )
private

Get player certificates using the Minecraft token, throw if failed.

Definition at line 449 of file Authentifier.cpp.

References Botcraft::CheckJsonResponse(), ProtocolCraft::Json::Value::get_string(), key_signature, key_timestamp, LOG_INFO, mc_access_token, Botcraft::POSTRequest(), private_key, and public_key.

Referenced by AuthMCToken(), and AuthMicrosoft().

◆ GetPlayerDisplayName()

const std::string & Botcraft::Authentifier::GetPlayerDisplayName ( ) const

Definition at line 280 of file Authentifier.cpp.

References player_display_name.

◆ GetPlayerUUID()

const std::array< unsigned char, 16 > & Botcraft::Authentifier::GetPlayerUUID ( ) const

Definition at line 285 of file Authentifier.cpp.

References mc_player_uuid_bytes.

◆ GetPrivateKey()

RSA * Botcraft::Authentifier::GetPrivateKey ( ) const

Definition at line 291 of file Authentifier.cpp.

References private_key.

◆ GetPublicKey()

const std::string & Botcraft::Authentifier::GetPublicKey ( ) const

Definition at line 296 of file Authentifier.cpp.

References public_key.

◆ JoinServer()

bool Botcraft::Authentifier::JoinServer ( const std::string &  server_id,
const std::vector< unsigned char > &  shared_secret,
const std::vector< unsigned char > &  server_public_key 
) const

◆ UpdateUUIDBytes()

void Botcraft::Authentifier::UpdateUUIDBytes ( )
private

Compute the UUID bytes from the string one.

Definition at line 438 of file Authentifier.cpp.

References mc_player_uuid, and mc_player_uuid_bytes.

Referenced by AuthMCToken(), and AuthMicrosoft().

Member Data Documentation

◆ key_signature

std::string Botcraft::Authentifier::key_signature
private

Definition at line 103 of file Authentifier.hpp.

Referenced by GetKeySignature(), and GetPlayerCertificates().

◆ key_timestamp

long long int Botcraft::Authentifier::key_timestamp
private

Definition at line 104 of file Authentifier.hpp.

Referenced by Authentifier(), GetKeyTimestamp(), and GetPlayerCertificates().

◆ mc_access_token

std::string Botcraft::Authentifier::mc_access_token
private

Definition at line 96 of file Authentifier.hpp.

Referenced by AuthMCToken(), AuthMicrosoft(), GetPlayerCertificates(), and JoinServer().

◆ mc_player_uuid

std::string Botcraft::Authentifier::mc_player_uuid
private

Definition at line 97 of file Authentifier.hpp.

Referenced by AuthMCToken(), AuthMicrosoft(), JoinServer(), and UpdateUUIDBytes().

◆ mc_player_uuid_bytes

std::array<unsigned char, 16> Botcraft::Authentifier::mc_player_uuid_bytes
private

Definition at line 98 of file Authentifier.hpp.

Referenced by Authentifier(), GetPlayerUUID(), and UpdateUUIDBytes().

◆ player_display_name

std::string Botcraft::Authentifier::player_display_name
private

Definition at line 95 of file Authentifier.hpp.

Referenced by AuthMCToken(), AuthMicrosoft(), and GetPlayerDisplayName().

◆ private_key

RSA* Botcraft::Authentifier::private_key = nullptr
private

Definition at line 101 of file Authentifier.hpp.

Referenced by GetPlayerCertificates(), GetPrivateKey(), and ~Authentifier().

◆ public_key

std::string Botcraft::Authentifier::public_key
private

Definition at line 102 of file Authentifier.hpp.

Referenced by GetPlayerCertificates(), and GetPublicKey().

◆ rnd

std::mt19937 Botcraft::Authentifier::rnd
private

Definition at line 106 of file Authentifier.hpp.

Referenced by Authentifier().


The documentation for this class was generated from the following files: