From ceff78a8212a9ee03b7d20d5ab4ff18d48589a8b Mon Sep 17 00:00:00 2001 From: mcflurrybaby Date: Sat, 2 Dec 2023 12:39:52 +0200 Subject: [PATCH 1/2] Restore ability to login with microsoft broken after yggdrasil login implementation --- MinecraftClient/Protocol/Handlers/Protocol16.cs | 3 ++- MinecraftClient/Protocol/Handlers/Protocol18.cs | 4 ++-- MinecraftClient/Protocol/Session/SessionToken.cs | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/Protocol16.cs b/MinecraftClient/Protocol/Handlers/Protocol16.cs index 411fae2e..39695e82 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol16.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol16.cs @@ -538,7 +538,8 @@ namespace MinecraftClient.Protocol.Handlers if (needCheckSession) { - if ((type == LoginType.mojang && ProtocolHandler.SessionCheck(uuid, sessionID, serverHash)) || (type == LoginType.yggdrasil && ProtocolHandler.YggdrasilSessionCheck(uuid, sessionID, serverHash))) + bool notYggdrasil = type == LoginType.mojang || type == LoginType.microsoft; + if ((notYggdrasil && ProtocolHandler.SessionCheck(uuid, sessionID, serverHash)) || (type == LoginType.yggdrasil && ProtocolHandler.YggdrasilSessionCheck(uuid, sessionID, serverHash))) { session.ServerIDhash = serverIDhash; session.ServerPublicKey = serverPublicKey; diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index ba942269..37114cde 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -2619,8 +2619,8 @@ namespace MinecraftClient.Protocol.Handlers if (needCheckSession) { string serverHash = CryptoHandler.GetServerHash(serverIDhash, serverPublicKey, secretKey); - - if ((type == LoginType.mojang && ProtocolHandler.SessionCheck(uuid, sessionID, serverHash) )|| (type == LoginType.yggdrasil && ProtocolHandler.YggdrasilSessionCheck(uuid, sessionID, serverHash))) + bool notYggdrasil = type == LoginType.mojang || type == LoginType.microsoft; + if ((notYggdrasil && ProtocolHandler.SessionCheck(uuid, sessionID, serverHash) )|| (type == LoginType.yggdrasil && ProtocolHandler.YggdrasilSessionCheck(uuid, sessionID, serverHash))) { session.ServerIDhash = serverIDhash; session.ServerPublicKey = serverPublicKey; diff --git a/MinecraftClient/Protocol/Session/SessionToken.cs b/MinecraftClient/Protocol/Session/SessionToken.cs index 66bcb568..ff965b70 100644 --- a/MinecraftClient/Protocol/Session/SessionToken.cs +++ b/MinecraftClient/Protocol/Session/SessionToken.cs @@ -39,7 +39,8 @@ namespace MinecraftClient.Protocol.Session return false; Crypto.CryptoHandler.ClientAESPrivateKey ??= Crypto.CryptoHandler.GenerateAESPrivateKey(); string serverHash = Crypto.CryptoHandler.GetServerHash(ServerIDhash, ServerPublicKey, Crypto.CryptoHandler.ClientAESPrivateKey); - if (type == LoginType.mojang && ProtocolHandler.SessionCheck(PlayerID, ID, serverHash)) + bool notYggdrasil = type == LoginType.mojang || type == LoginType.microsoft; + if (notYggdrasil && ProtocolHandler.SessionCheck(PlayerID, ID, serverHash)) return true; if (type == LoginType.yggdrasil && ProtocolHandler.YggdrasilSessionCheck(PlayerID, ID, serverHash)) return true; From e19de8eb0b446e218e5afe8838fac4103a207d6e Mon Sep 17 00:00:00 2001 From: mcflurrybaby Date: Sat, 2 Dec 2023 13:15:46 +0200 Subject: [PATCH 2/2] refactored session checks for better readability --- .../Protocol/Handlers/Protocol16.cs | 3 +-- .../Protocol/Handlers/Protocol18.cs | 3 +-- MinecraftClient/Protocol/ProtocolHandler.cs | 19 ++++++------------- .../Protocol/Session/SessionToken.cs | 5 +---- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/Protocol16.cs b/MinecraftClient/Protocol/Handlers/Protocol16.cs index 39695e82..7910cf56 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol16.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol16.cs @@ -538,8 +538,7 @@ namespace MinecraftClient.Protocol.Handlers if (needCheckSession) { - bool notYggdrasil = type == LoginType.mojang || type == LoginType.microsoft; - if ((notYggdrasil && ProtocolHandler.SessionCheck(uuid, sessionID, serverHash)) || (type == LoginType.yggdrasil && ProtocolHandler.YggdrasilSessionCheck(uuid, sessionID, serverHash))) + if (ProtocolHandler.SessionCheck(uuid, sessionID, serverHash, type)) { session.ServerIDhash = serverIDhash; session.ServerPublicKey = serverPublicKey; diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 37114cde..57467a04 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -2619,8 +2619,7 @@ namespace MinecraftClient.Protocol.Handlers if (needCheckSession) { string serverHash = CryptoHandler.GetServerHash(serverIDhash, serverPublicKey, secretKey); - bool notYggdrasil = type == LoginType.mojang || type == LoginType.microsoft; - if ((notYggdrasil && ProtocolHandler.SessionCheck(uuid, sessionID, serverHash) )|| (type == LoginType.yggdrasil && ProtocolHandler.YggdrasilSessionCheck(uuid, sessionID, serverHash))) + if (ProtocolHandler.SessionCheck(uuid, sessionID, serverHash, type)) { session.ServerIDhash = serverIDhash; session.ServerPublicKey = serverPublicKey; diff --git a/MinecraftClient/Protocol/ProtocolHandler.cs b/MinecraftClient/Protocol/ProtocolHandler.cs index 84b0880c..fc254efe 100644 --- a/MinecraftClient/Protocol/ProtocolHandler.cs +++ b/MinecraftClient/Protocol/ProtocolHandler.cs @@ -881,26 +881,19 @@ namespace MinecraftClient.Protocol /// Username /// Session ID /// Server ID + /// LoginType /// TRUE if session was successfully checked - public static bool SessionCheck(string uuid, string accesstoken, string serverhash) + public static bool SessionCheck(string uuid, string accesstoken, string serverhash, LoginType type) { try { string result = ""; string json_request = "{\"accessToken\":\"" + accesstoken + "\",\"selectedProfile\":\"" + uuid + "\",\"serverId\":\"" + serverhash + "\"}"; - int code = DoHTTPSPost("sessionserver.mojang.com",443, "/session/minecraft/join", json_request, ref result); - return (code >= 200 && code < 300); - } - catch { return false; } - } + string host = type == LoginType.yggdrasil ? Config.Main.General.AuthServer.Host : "sessionserver.mojang.com"; + int port = type == LoginType.yggdrasil ? Config.Main.General.AuthServer.Port : 443; + string endpoint = type == LoginType.yggdrasil ? "/api/yggdrasil/sessionserver/session/minecraft/join" : "/session/minecraft/join"; - public static bool YggdrasilSessionCheck(string uuid, string accesstoken, string serverhash) - { - try - { - string result = ""; - string json_request = "{\"accessToken\":\"" + accesstoken + "\",\"selectedProfile\":\"" + uuid + "\",\"serverId\":\"" + serverhash + "\"}"; - int code = DoHTTPSPost(Config.Main.General.AuthServer.Host, Config.Main.General.AuthServer.Port, "/api/yggdrasil/sessionserver/session/minecraft/join", json_request, ref result); + int code = DoHTTPSPost(host, port, endpoint, json_request, ref result); return (code >= 200 && code < 300); } catch { return false; } diff --git a/MinecraftClient/Protocol/Session/SessionToken.cs b/MinecraftClient/Protocol/Session/SessionToken.cs index ff965b70..1df31146 100644 --- a/MinecraftClient/Protocol/Session/SessionToken.cs +++ b/MinecraftClient/Protocol/Session/SessionToken.cs @@ -39,10 +39,7 @@ namespace MinecraftClient.Protocol.Session return false; Crypto.CryptoHandler.ClientAESPrivateKey ??= Crypto.CryptoHandler.GenerateAESPrivateKey(); string serverHash = Crypto.CryptoHandler.GetServerHash(ServerIDhash, ServerPublicKey, Crypto.CryptoHandler.ClientAESPrivateKey); - bool notYggdrasil = type == LoginType.mojang || type == LoginType.microsoft; - if (notYggdrasil && ProtocolHandler.SessionCheck(PlayerID, ID, serverHash)) - return true; - if (type == LoginType.yggdrasil && ProtocolHandler.YggdrasilSessionCheck(PlayerID, ID, serverHash)) + if (ProtocolHandler.SessionCheck(PlayerID, ID, serverHash, type)) return true; return false; }