private static string EncryptAES(string decrypted) { if (string.IsNullOrEmpty(decrypted)) { ASF.ArchiLogger.LogNullError(nameof(decrypted)); return(null); } try { byte[] key; using (SHA256 sha256 = SHA256.Create()) { key = sha256.ComputeHash(EncryptionKey); } byte[] encryptedData = Encoding.UTF8.GetBytes(decrypted); encryptedData = CryptoHelper.SymmetricEncrypt(encryptedData, key); return(Convert.ToBase64String(encryptedData)); } catch (Exception e) { ASF.ArchiLogger.LogGenericException(e); return(null); } }
internal bool Init(SteamClient steamClient, string webAPIUserNonce, string parentalPin) { if ((steamClient == null) || string.IsNullOrEmpty(webAPIUserNonce)) { Logging.LogNullError(nameof(steamClient) + " || " + nameof(webAPIUserNonce), Bot.BotName); return(false); } ulong steamID = steamClient.SteamID; if (steamID == 0) { return(false); } string sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(steamID.ToString())); // Generate an AES session key byte[] sessionKey = CryptoHelper.GenerateRandomBlock(32); // RSA encrypt it with the public key for the universe we're on byte[] cryptedSessionKey; using (RSACrypto rsa = new RSACrypto(KeyDictionary.GetPublicKey(steamClient.ConnectedUniverse))) { cryptedSessionKey = rsa.Encrypt(sessionKey); } // Copy our login key byte[] loginKey = new byte[webAPIUserNonce.Length]; Array.Copy(Encoding.ASCII.GetBytes(webAPIUserNonce), loginKey, webAPIUserNonce.Length); // AES encrypt the loginkey with our session key byte[] cryptedLoginKey = CryptoHelper.SymmetricEncrypt(loginKey, sessionKey); // Do the magic Logging.LogGenericInfo("Logging in to ISteamUserAuth...", Bot.BotName); KeyValue authResult; using (dynamic iSteamUserAuth = WebAPI.GetInterface("ISteamUserAuth")) { iSteamUserAuth.Timeout = Timeout; try { authResult = iSteamUserAuth.AuthenticateUser( steamid: steamID, sessionkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedSessionKey, 0, cryptedSessionKey.Length)), encrypted_loginkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedLoginKey, 0, cryptedLoginKey.Length)), method: WebRequestMethods.Http.Post, secure: !Program.GlobalConfig.ForceHttp ); } catch (Exception e) { Logging.LogGenericException(e, Bot.BotName); return(false); } } if (authResult == null) { Logging.LogNullError(nameof(authResult), Bot.BotName); return(false); } Logging.LogGenericInfo("Success!", Bot.BotName); WebBrowser.CookieContainer.Add(new Cookie("sessionid", sessionID, "/", "." + SteamCommunityHost)); string steamLogin = authResult["token"].Value; WebBrowser.CookieContainer.Add(new Cookie("steamLogin", steamLogin, "/", "." + SteamCommunityHost)); string steamLoginSecure = authResult["tokensecure"].Value; WebBrowser.CookieContainer.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", "." + SteamCommunityHost)); if (!UnlockParentalAccount(parentalPin).Result) { return(false); } LastSessionRefreshCheck = DateTime.Now; return(true); }
internal async Task <bool> Init(SteamClient steamClient, string webAPIUserNonce, string parentalPin) { if (steamClient == null || steamClient.SteamID == null || string.IsNullOrEmpty(webAPIUserNonce)) { return(false); } SteamID = steamClient.SteamID; string sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(SteamID.ToString())); // Generate an AES session key byte[] sessionKey = CryptoHelper.GenerateRandomBlock(32); // RSA encrypt it with the public key for the universe we're on byte[] cryptedSessionKey; using (RSACrypto rsa = new RSACrypto(KeyDictionary.GetPublicKey(steamClient.ConnectedUniverse))) { cryptedSessionKey = rsa.Encrypt(sessionKey); } // Copy our login key byte[] loginKey = new byte[webAPIUserNonce.Length]; Array.Copy(Encoding.ASCII.GetBytes(webAPIUserNonce), loginKey, webAPIUserNonce.Length); // AES encrypt the loginkey with our session key byte[] cryptedLoginKey = CryptoHelper.SymmetricEncrypt(loginKey, sessionKey); // Do the magic Logging.LogGenericInfo("Logging in to ISteamUserAuth...", Bot.BotName); KeyValue authResult; using (dynamic iSteamUserAuth = WebAPI.GetInterface("ISteamUserAuth")) { iSteamUserAuth.Timeout = Timeout; try { authResult = iSteamUserAuth.AuthenticateUser( steamid: SteamID, sessionkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedSessionKey, 0, cryptedSessionKey.Length)), encrypted_loginkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedLoginKey, 0, cryptedLoginKey.Length)), method: WebRequestMethods.Http.Post, secure: !Program.GlobalConfig.ForceHttp ); } catch (Exception e) { Logging.LogGenericException(e, Bot.BotName); return(false); } } if (authResult == null) { return(false); } Logging.LogGenericInfo("Success!", Bot.BotName); string steamLogin = authResult["token"].AsString(); string steamLoginSecure = authResult["tokensecure"].AsString(); Cookie["sessionid"] = sessionID; Cookie["steamLogin"] = steamLogin; Cookie["steamLoginSecure"] = steamLoginSecure; // The below is used for display purposes only Cookie["webTradeEligibility"] = "{\"allowed\":0,\"reason\":0,\"allowed_at_time\":0,\"steamguard_required_days\":0,\"sales_this_year\":0,\"max_sales_per_year\":0,\"forms_requested\":0}"; await UnlockParentalAccount(parentalPin).ConfigureAwait(false); return(true); }
internal async Task Init(SteamClient steamClient, string webAPIUserNonce, string vanityURL, string parentalPin) { if (steamClient == null || steamClient.SteamID == null || string.IsNullOrEmpty(webAPIUserNonce)) { return; } SteamID = steamClient.SteamID; VanityURL = vanityURL; string sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(SteamID.ToString(CultureInfo.InvariantCulture))); // Generate an AES session key byte[] sessionKey = CryptoHelper.GenerateRandomBlock(32); // RSA encrypt it with the public key for the universe we're on byte[] cryptedSessionKey = null; using (RSACrypto rsa = new RSACrypto(KeyDictionary.GetPublicKey(steamClient.ConnectedUniverse))) { cryptedSessionKey = rsa.Encrypt(sessionKey); } // Copy our login key byte[] loginKey = new byte[20]; Array.Copy(Encoding.ASCII.GetBytes(webAPIUserNonce), loginKey, webAPIUserNonce.Length); // AES encrypt the loginkey with our session key byte[] cryptedLoginKey = CryptoHelper.SymmetricEncrypt(loginKey, sessionKey); // Send the magic KeyValue authResult; Logging.LogGenericInfo(Bot.BotName, "Logging in to ISteamUserAuth..."); using (dynamic iSteamUserAuth = WebAPI.GetInterface("ISteamUserAuth")) { iSteamUserAuth.Timeout = Timeout; try { authResult = iSteamUserAuth.AuthenticateUser( steamid: SteamID, sessionkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedSessionKey, 0, cryptedSessionKey.Length)), encrypted_loginkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedLoginKey, 0, cryptedLoginKey.Length)), method: WebRequestMethods.Http.Post, secure: true ); } catch (Exception e) { Logging.LogGenericException(Bot.BotName, e); steamClient.Disconnect(); // We may get 403 if we use the same webAPIUserNonce twice return; } } if (authResult == null) { steamClient.Disconnect(); // Try again return; } Logging.LogGenericInfo(Bot.BotName, "Success!"); string steamLogin = authResult["token"].AsString(); string steamLoginSecure = authResult["tokensecure"].AsString(); SteamCookieDictionary.Clear(); SteamCookieDictionary.Add("sessionid", sessionID); SteamCookieDictionary.Add("steamLogin", steamLogin); SteamCookieDictionary.Add("steamLoginSecure", steamLoginSecure); SteamCookieDictionary.Add("birthtime", "-473356799"); // ( ͡° ͜ʖ ͡°) if (!string.IsNullOrEmpty(parentalPin) && !parentalPin.Equals("0")) { Logging.LogGenericInfo(Bot.BotName, "Unlocking parental account..."); Dictionary <string, string> postData = new Dictionary <string, string>() { { "pin", parentalPin } }; HttpResponseMessage response = await Utilities.UrlPostRequestWithResponse("https://steamcommunity.com/parental/ajaxunlock", postData, SteamCookieDictionary, "https://steamcommunity.com/").ConfigureAwait(false); if (response != null && response.IsSuccessStatusCode) { Logging.LogGenericInfo(Bot.BotName, "Success!"); var setCookieValues = response.Headers.GetValues("Set-Cookie"); foreach (string setCookieValue in setCookieValues) { if (setCookieValue.Contains("steamparental=")) { string setCookie = setCookieValue.Substring(setCookieValue.IndexOf("steamparental=") + 14); setCookie = setCookie.Substring(0, setCookie.IndexOf(';')); SteamCookieDictionary.Add("steamparental", setCookie); break; } } } else { Logging.LogGenericInfo(Bot.BotName, "Failed!"); } } Bot.Trading.CheckTrades(); }