diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index 9368b2dc..2cbf526e 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -5,6 +5,7 @@ using System.Text; using SteamKit2; using System.Threading; using System.Collections.ObjectModel; +using System.IO; namespace DepotDownloader { @@ -77,9 +78,16 @@ namespace DepotDownloader this.callbacks.Register(new Callback(LogOnCallback)); this.callbacks.Register(new Callback(SessionTokenCallback)); this.callbacks.Register(new Callback(LicenseListCallback)); + this.callbacks.Register(new JobCallback(UpdateMachineAuthCallback)); Console.Write( "Connecting to Steam3..." ); + FileInfo fi = new FileInfo(String.Format("{0}.sentryFile", logonDetails.Username)); + if(fi.Exists && fi.Length > 0) + { + logonDetails.SentryFileHash = Util.SHAHash(File.ReadAllBytes(fi.FullName)); + } + Connect(); } @@ -285,5 +293,34 @@ namespace DepotDownloader Licenses = licenseList.LicenseList; } + + private void UpdateMachineAuthCallback(SteamUser.UpdateMachineAuthCallback machineAuth, ulong jobId) + { + byte[] hash = Util.SHAHash(machineAuth.Data); + Console.WriteLine("Got Machine Auth: {0} {1} {2} {3}", machineAuth.FileName, machineAuth.Offset, machineAuth.BytesToWrite, machineAuth.Data.Length, hash); + + File.WriteAllBytes( String.Format("{0}.sentryFile", logonDetails.Username), machineAuth.Data ); + 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 = jobId, // so we respond to the correct server job + }; + + // send off our response + steamUser.SendMachineAuthResponse( authResponse ); + } + + } } diff --git a/DepotDownloader/Util.cs b/DepotDownloader/Util.cs index 8fe1877b..9a787c7c 100644 --- a/DepotDownloader/Util.cs +++ b/DepotDownloader/Util.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.IO; using System.Runtime.InteropServices; +using System.Security.Cryptography; using Classless.Hasher; namespace DepotDownloader @@ -158,5 +159,16 @@ namespace DepotDownloader } return BitConverter.GetBytes(a | (b << 16)); } + + public static byte[] SHAHash( byte[] input ) + { + SHA1Managed sha = new SHA1Managed(); + + byte[] output = sha.ComputeHash( input ); + + sha.Clear(); + + return output; + } } }