Botcraft 26.3
Loading...
Searching...
No Matches
Authentifier.hpp
Go to the documentation of this file.
1#pragma once
2#include <array>
3#include <optional>
4#include <string>
5#include <vector>
6
7#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
8#include <random>
9#endif
10#if PROTOCOL_VERSION > 759 /* > 1.19 */
12#endif
13
14#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
15struct rsa_st;
16typedef struct rsa_st RSA;
17#endif
18
19namespace Botcraft
20{
22 {
23 public:
26
27 /// @brief Authentication using a Microsoft account, storing the credentials in the cache file
28 /// @param cache_key used as key to identify the credentials in cache file
29 /// @return True if successfully authenticated, false otherwise
30 bool AuthMicrosoft(const std::string& cache_key);
31
32 /// @brief Authentication using a minecraft token
33 /// @param mc_token Minecraft token, must be valid
34 /// @return True if successfully authenticated, false otherwise
35 bool AuthMCToken(const std::string& mc_token);
36
37 // Join a server after encryption request
38 bool JoinServer(const std::string& server_id, const std::vector<unsigned char>& shared_secret, const std::vector<unsigned char>& server_public_key) const;
39
40 const std::string& GetPlayerDisplayName() const;
41 const std::array<unsigned char, 16>& GetPlayerUUID() const;
42
43#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
44 RSA* GetPrivateKey() const;
45 const std::string& GetPublicKey() const;
46 const std::string& GetKeySignature() const;
47 long long int GetKeyTimestamp() const;
48
49#if PROTOCOL_VERSION == 759 /* 1.19 */
50 /// @brief Compute the signature of a message
51 /// @param message Message to send
52 /// @param salt Output salt used to generate the signature
53 /// @param timestamp Output timestamp in ms used to generate the signature
54 /// @return The message signature
55 std::vector<unsigned char> GetMessageSignature(const std::string& message, long long int& salt, long long int& timestamp);
56#elif PROTOCOL_VERSION == 760 /* 1.19.1/2 */
57 /// @brief Compute the signature of a message
58 /// @param message Message to send
59 /// @param previous_signature Signature of the previous message sent
60 /// @param last_seen Vector of previously received messages from players
61 /// @param salt Output salt used to generate the signature
62 /// @param timestamp Output timestamp in ms used to generate the signature
63 /// @return The message signature
64 std::vector<unsigned char> GetMessageSignature(const std::string& message,
65 const std::vector<unsigned char>& previous_signature, const std::vector<ProtocolCraft::LastSeenMessagesEntry>& last_seen,
66 long long int& salt, long long int& timestamp);
67#else
68 /// @brief Compute the signature of a message
69 /// @param message Message to send
70 /// @param message_sent_index Index of the message in this message chain
71 /// @param chat_session_uuid UUID of the chat session, as sent in ServerboundChatSessionUpdatePacket
72 /// @param last_seen Vector of signatures of previously received messages
73 /// @param salt Output salt used to generate the signature
74 /// @param timestamp Output timestamp in ms used to generate the signature
75 /// @return The message signature
76 std::vector<unsigned char> GetMessageSignature(const std::string& message,
77 const int message_sent_index, const ProtocolCraft::UUID& chat_session_uuid,
78 const std::vector<std::vector<unsigned char>>& last_seen,
79 long long int& salt, long long int& timestamp);
80#endif
81#endif
82
83 private:
84 /// @brief Compute the UUID bytes from the string one
85 void UpdateUUIDBytes();
86
87#ifdef USE_ENCRYPTION
88#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
89 /// @brief Get player certificates using the Minecraft token, throw if failed
91#endif
92#endif
93
94 private:
96 std::string mc_access_token;
97 std::string mc_player_uuid;
98 std::array<unsigned char, 16> mc_player_uuid_bytes;
99
100#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
101 RSA* private_key = nullptr;
102 std::string public_key;
103 std::string key_signature;
104 long long int key_timestamp;
105
106 std::mt19937 rnd;
107#endif
108
109 };
110}
struct rsa_st RSA
bool JoinServer(const std::string &server_id, const std::vector< unsigned char > &shared_secret, const std::vector< unsigned char > &server_public_key) const
bool AuthMicrosoft(const std::string &cache_key)
Authentication using a Microsoft account, storing the credentials in the cache file.
std::string player_display_name
const std::string & GetPlayerDisplayName() const
long long int key_timestamp
void UpdateUUIDBytes()
Compute the UUID bytes from the string one.
void GetPlayerCertificates()
Get player certificates using the Minecraft token, throw if failed.
const std::string & GetKeySignature() const
const std::array< unsigned char, 16 > & GetPlayerUUID() const
RSA * GetPrivateKey() const
std::array< unsigned char, 16 > mc_player_uuid_bytes
const std::string & GetPublicKey() 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.
bool AuthMCToken(const std::string &mc_token)
Authentication using a minecraft token.
long long int GetKeyTimestamp() const
std::array< unsigned char, 16 > UUID