Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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 = null;
            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: true
                        );
                } 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;

            await UnlockParentalAccount(parentalPin).ConfigureAwait(false);

            return(true);
        }
Exemplo n.º 3
0
        internal bool Init(SteamClient steamClient, string webAPIUserNonce, string parentalPin)
        {
            if (steamClient == null || steamClient.SteamID == null || string.IsNullOrEmpty(webAPIUserNonce))
            {
                return(false);
            }

            ulong 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}";

            if (!UnlockParentalAccount(parentalPin).Result)
            {
                return(false);
            }

            LastSessionRefreshCheck = DateTime.Now;
            return(true);
        }