From bf0f89fed0111a796d9d502c295453d30c8b71e9 Mon Sep 17 00:00:00 2001 From: Antoine Rybacki <15911822+Lifeismana@users.noreply.github.com> Date: Wed, 15 Nov 2023 15:12:57 +0100 Subject: [PATCH] Remove Deprecated SentryData and add GuardData --- DepotDownloader/AccountSettingsStore.cs | 10 +++-- DepotDownloader/Steam3Session.cs | 49 +++++-------------------- 2 files changed, 16 insertions(+), 43 deletions(-) diff --git a/DepotDownloader/AccountSettingsStore.cs b/DepotDownloader/AccountSettingsStore.cs index 8bed9622..d2ea417d 100644 --- a/DepotDownloader/AccountSettingsStore.cs +++ b/DepotDownloader/AccountSettingsStore.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; @@ -11,8 +11,7 @@ namespace DepotDownloader [ProtoContract] class AccountSettingsStore { - [ProtoMember(1, IsRequired = false)] - public Dictionary SentryData { get; private set; } + // Member 1 was a Dictionary for SentryData. [ProtoMember(2, IsRequired = false)] public ConcurrentDictionary ContentServerPenalty { get; private set; } @@ -22,13 +21,16 @@ namespace DepotDownloader [ProtoMember(4, IsRequired = false)] public Dictionary LoginTokens { get; private set; } + [ProtoMember(5, IsRequired = false)] + public Dictionary GuardData { get; private set; } + string FileName; AccountSettingsStore() { - SentryData = new Dictionary(); ContentServerPenalty = new ConcurrentDictionary(); LoginTokens = new Dictionary(); + GuardData = new Dictionary(); } static bool Loaded diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index 206b3b56..cd53e3a5 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -112,22 +112,17 @@ namespace DepotDownloader this.callbacks.Subscribe(LogOnCallback); this.callbacks.Subscribe(SessionTokenCallback); this.callbacks.Subscribe(LicenseListCallback); - this.callbacks.Subscribe(UpdateMachineAuthCallback); Console.Write("Connecting to Steam3..."); if (details.Username != null) { - var fi = new FileInfo(String.Format("{0}.sentryFile", logonDetails.Username)); - if (AccountSettingsStore.Instance.SentryData != null && AccountSettingsStore.Instance.SentryData.ContainsKey(logonDetails.Username)) + // Reused what was done for sentryFile but does this has any use ? + var fi = new FileInfo(String.Format("{0}.guardDataFile", logonDetails.Username)); + if (AccountSettingsStore.Instance.GuardData != null && !AccountSettingsStore.Instance.GuardData.ContainsKey(logonDetails.Username) && fi.Exists && fi.Length > 0) { - logonDetails.SentryFileHash = Util.SHAHash(AccountSettingsStore.Instance.SentryData[logonDetails.Username]); - } - else if (fi.Exists && fi.Length > 0) - { - var sentryData = File.ReadAllBytes(fi.FullName); - logonDetails.SentryFileHash = Util.SHAHash(sentryData); - AccountSettingsStore.Instance.SentryData[logonDetails.Username] = sentryData; + var guardData = File.ReadAllText(fi.FullName); + AccountSettingsStore.Instance.GuardData[logonDetails.Username] = guardData; AccountSettingsStore.Save(); } } @@ -508,11 +503,14 @@ namespace DepotDownloader { try { + string guarddata = null; + _ = AccountSettingsStore.Instance.GuardData.TryGetValue(logonDetails.Username, out guarddata); authSession = await steamClient.Authentication.BeginAuthSessionViaCredentialsAsync(new SteamKit2.Authentication.AuthSessionDetails { Username = logonDetails.Username, Password = logonDetails.Password, IsPersistentSession = ContentDownloader.Config.RememberPassword, + GuardData = guarddata, Authenticator = new UserConsoleAuthenticator(), }); } @@ -576,6 +574,8 @@ namespace DepotDownloader logonDetails.Password = null; logonDetails.AccessToken = result.RefreshToken; + // Should i check if guardData is null ? + AccountSettingsStore.Instance.GuardData[result.AccountName] = result.NewGuardData; AccountSettingsStore.Instance.LoginTokens[result.AccountName] = result.RefreshToken; AccountSettingsStore.Save(); } @@ -749,35 +749,6 @@ namespace DepotDownloader } } - private void UpdateMachineAuthCallback(SteamUser.UpdateMachineAuthCallback machineAuth) - { - var hash = Util.SHAHash(machineAuth.Data); - Console.WriteLine("Got Machine Auth: {0} {1} {2} {3}", machineAuth.FileName, machineAuth.Offset, machineAuth.BytesToWrite, machineAuth.Data.Length); - - AccountSettingsStore.Instance.SentryData[logonDetails.Username] = machineAuth.Data; - AccountSettingsStore.Save(); - - var authResponse = new SteamUser.MachineAuthDetails - { - BytesWritten = machineAuth.BytesToWrite, - FileName = machineAuth.FileName, - FileSize = machineAuth.BytesToWrite, - Offset = machineAuth.Offset, - - SentryFileHash = hash, // should be the sha1 hash of the sentry file we just wrote - - OneTimePassword = machineAuth.OneTimePassword, // not sure on this one yet, since we've had no examples of steam using OTPs - - LastError = 0, // result from win32 GetLastError - Result = EResult.OK, // if everything went okay, otherwise ~who knows~ - - JobID = machineAuth.JobID, // so we respond to the correct server job - }; - - // send off our response - steamUser.SendMachineAuthResponse(authResponse); - } - private static void DisplayQrCode(string challengeUrl) { // Encode the link as a QR code