コード例 #1
0
        private bool SendMultiConfirmationAjax(Confirmation[] confs, string op)
        {
            const string Url = ApiEndpoints.CommunityBase + "/mobileconf/multiajaxop";

            var query = "op=" + op + "&" + this.GenerateConfirmationQueryParams(op);

            foreach (var conf in confs)
            {
                query += "&cid[]=" + conf.ID + "&ck[]=" + conf.Key;
            }

            var cookies = new CookieContainer();

            this.Session.AddCookies(cookies);
            var referer = this.GenerateConfirmationURL();

            var response = SteamWeb.Request(Url, "POST", query, cookies, referer: referer, proxy: this.Proxy);

            if (response == null)
            {
                return(false);
            }

            var confResponse = JsonConvert.DeserializeObject <SendConfirmationResponse>(response);

            return(confResponse.Success);
        }
コード例 #2
0
        private bool SendConfirmationAjax(Confirmation conf, string op)
        {
            var url         = ApiEndpoints.CommunityBase + "/mobileconf/ajaxop";
            var queryString = "?op=" + op + "&";

            queryString += this.GenerateConfirmationQueryParams(op);
            queryString += "&cid=" + conf.ID + "&ck=" + conf.Key;
            url         += queryString;

            var cookies = new CookieContainer();

            this.Session.AddCookies(cookies);
            var referer = this.GenerateConfirmationURL();

            var response = SteamWeb.Request(url, "GET", string.Empty, cookies, null, referer, proxy: this.Proxy);

            if (response == null)
            {
                return(false);
            }

            var confResponse = JsonConvert.DeserializeObject <SendConfirmationResponse>(response);

            return(confResponse.Success);
        }
コード例 #3
0
        public Confirmation[] FetchConfirmations()
        {
            var url = this.GenerateConfirmationURL();

            var cookies = new CookieContainer();

            this.Session.AddCookies(cookies);

            var response = SteamWeb.Request(url, "GET", string.Empty, cookies, proxy: this.Proxy);

            var confRegex = new Regex(
                "<div class=\"mobileconf_list_entry\" id=\"conf[0-9]+\" data-confid=\"(\\d+)\" data-key=\"(\\d+)\" data-type=\"(\\d+)\" data-creator=\"(\\d+)\"");

            if (response == null || !confRegex.IsMatch(response))
            {
                if (response != null && response.Contains(
                        "It looks like your Steam Guard Mobile Authenticator is providing incorrect Steam Guard codes"))
                {
                    throw new SteamException("Invalid authenticator");
                }

                if (response == null || !response.Contains("<div>Nothing to confirm</div>"))
                {
                    throw new SteamException("Error on confirmation fetch! Steam response is empty");
                }

                return(new Confirmation[0]);
            }

            var confirmations = confRegex.Matches(response);

            var ret = new List <Confirmation>();

            foreach (Match confirmation in confirmations)
            {
                if (confirmation.Groups.Count != 5)
                {
                    continue;
                }

                if (!ulong.TryParse(confirmation.Groups[1].Value, out var confID) ||
                    !ulong.TryParse(confirmation.Groups[2].Value, out var confKey) ||
                    !int.TryParse(confirmation.Groups[3].Value, out var confType) || !ulong.TryParse(
                        confirmation.Groups[4].Value,
                        out var confCreator))
                {
                    continue;
                }

                ret.Add(new Confirmation(confID, confKey, confType, confCreator));
            }

            return(ret.ToArray());
        }
コード例 #4
0
 public static void AlignTime()
 {
     while (_aligned == false)
     {
         try
         {
             var response = SteamWeb.Request(ApiEndpoints.TwoFactorTimeQuery, "POST", dataString: null);
             var query    = JsonConvert.DeserializeObject <TimeQuery>(response);
             _timeDifference = (int)(query.Response.ServerTime - Util.GetSystemUnixTime());
             _aligned        = true;
         }
         catch (Exception ex)
         {
             Logger.Log.Error($"Error on steam time align - {ex.Message}.", ex);
         }
     }
 }
コード例 #5
0
        /// <summary>
        /// Refreshes the Steam session. Necessary to perform confirmations if your session has expired or changed.
        /// </summary>
        /// <returns></returns>
        public bool RefreshSession()
        {
            var postData = new NameValueCollection {
                { "access_token", this.Session.OAuthToken }
            };

            string response;

            try
            {
                response = SteamWeb.Request(ApiEndpoints.MobileAuthGetWgToken, "POST", postData, proxy: this.Proxy);
            }
            catch (WebException)
            {
                return(false);
            }

            if (response == null)
            {
                return(false);
            }

            try
            {
                var refreshResponse = JsonConvert.DeserializeObject <RefreshSessionDataResponse>(response);
                if (refreshResponse?.Response == null || string.IsNullOrEmpty(refreshResponse.Response.Token))
                {
                    return(false);
                }

                var token       = this.Session.SteamID + "%7C%7C" + refreshResponse.Response.Token;
                var tokenSecure = this.Session.SteamID + "%7C%7C" + refreshResponse.Response.TokenSecure;

                this.Session.SteamLogin       = token;
                this.Session.SteamLoginSecure = tokenSecure;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #6
0
        private ConfirmationDetailsResponse GetConfirmationDetails(Confirmation conf)
        {
            var url         = ApiEndpoints.CommunityBase + "/mobileconf/details/" + conf.ID + "?";
            var queryString = this.GenerateConfirmationQueryParams("details");

            url += queryString;

            var cookies = new CookieContainer();

            this.Session.AddCookies(cookies);
            var referer = this.GenerateConfirmationURL();

            var response = SteamWeb.Request(url, "GET", string.Empty, cookies, null, proxy: this.Proxy, referer: referer);

            if (string.IsNullOrEmpty(response))
            {
                return(null);
            }

            var confResponse = JsonConvert.DeserializeObject <ConfirmationDetailsResponse>(response);

            return(confResponse);
        }
コード例 #7
0
        public LoginResult DoLogin()
        {
            var postData = new NameValueCollection();
            var cookies  = this._cookies;

            if (cookies.Count == 0)
            {
                // Generate a SessionID
                cookies.Add(new Cookie("mobileClientVersion", "0 (2.1.3)", "/", ".steamcommunity.com"));
                cookies.Add(new Cookie("mobileClient", "android", "/", ".steamcommunity.com"));
                cookies.Add(new Cookie("Steam_Language", "english", "/", ".steamcommunity.com"));

                var headers = new NameValueCollection
                {
                    { "X-Requested-With", "com.valvesoftware.android.steam.community" }
                };

                SteamWeb.MobileLoginRequest(
                    "https://steamcommunity.com/login?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client",
                    "GET",
                    null,
                    cookies,
                    headers,
                    this.proxy);
            }

            postData.Add("donotcache", (TimeAligner.GetSteamTime() * 1000).ToString());
            postData.Add("username", this.Username);
            string response = SteamWeb.MobileLoginRequest(
                ApiEndpoints.CommunityBase + "/login/getrsakey",
                "POST",
                postData,
                cookies,
                proxy: this.proxy);

            if (response == null || response.Contains("<BODY>\nAn error occurred while processing your request."))
            {
                return(LoginResult.GeneralFailure);
            }

            var rsaResponse = JsonConvert.DeserializeObject <RSAResponse>(response);

            if (!rsaResponse.Success)
            {
                return(LoginResult.BadRSA);
            }

            Thread.Sleep(350); // Sleep for a bit to give Steam a chance to catch up??

            byte[] encryptedPasswordBytes;
            using (var rsaEncryptor = new RSACryptoServiceProvider())
            {
                var passwordBytes = Encoding.ASCII.GetBytes(this.Password);
                var rsaParameters = rsaEncryptor.ExportParameters(false);
                rsaParameters.Exponent = Util.HexStringToByteArray(rsaResponse.Exponent);
                rsaParameters.Modulus  = Util.HexStringToByteArray(rsaResponse.Modulus);
                rsaEncryptor.ImportParameters(rsaParameters);
                encryptedPasswordBytes = rsaEncryptor.Encrypt(passwordBytes, false);
            }

            var encryptedPassword = Convert.ToBase64String(encryptedPasswordBytes);

            postData.Clear();
            postData.Add("donotcache", (TimeAligner.GetSteamTime() * 1000).ToString());

            postData.Add("password", encryptedPassword);
            postData.Add("username", this.Username);
            postData.Add("twofactorcode", this.TwoFactorCode ?? string.Empty);

            postData.Add("emailauth", this.RequiresEmail ? this.EmailCode : string.Empty);
            postData.Add("loginfriendlyname", string.Empty);
            postData.Add("captchagid", this.RequiresCaptcha ? this.CaptchaGID : "-1");
            postData.Add("captcha_text", this.RequiresCaptcha ? this.CaptchaText : string.Empty);
            postData.Add(
                "emailsteamid",
                (this.Requires2FA || this.RequiresEmail) ? this.SteamID.ToString() : string.Empty);

            postData.Add("rsatimestamp", rsaResponse.Timestamp);
            postData.Add("remember_login", "true");
            postData.Add("oauth_client_id", "DE45CD61");
            postData.Add("oauth_scope", "read_profile write_profile read_client write_client");

            response = SteamWeb.MobileLoginRequest(
                ApiEndpoints.CommunityBase + "/login/dologin",
                "POST",
                postData,
                cookies,
                proxy: this.proxy);
            if (response == null)
            {
                return(LoginResult.GeneralFailure);
            }

            var loginResponse = JsonConvert.DeserializeObject <LoginResponse>(response);

            if (loginResponse.Message != null && loginResponse.Message.Contains("Incorrect login"))
            {
                return(LoginResult.BadCredentials);
            }

            if (loginResponse.CaptchaNeeded)
            {
                this.RequiresCaptcha = true;
                this.CaptchaGID      = loginResponse.CaptchaGID;
                return(LoginResult.NeedCaptcha);
            }

            if (loginResponse.EmailAuthNeeded)
            {
                this.RequiresEmail = true;
                this.SteamID       = loginResponse.EmailSteamID;
                return(LoginResult.NeedEmail);
            }

            if (loginResponse.TwoFactorNeeded && !loginResponse.Success)
            {
                this.Requires2FA = true;
                return(LoginResult.Need2FA);
            }

            if (loginResponse.Message != null && loginResponse.Message.Contains("too many login failures"))
            {
                return(LoginResult.TooManyFailedLogins);
            }

            if (loginResponse.OAuthData == null || loginResponse.OAuthData.OAuthToken == null ||
                loginResponse.OAuthData.OAuthToken.Length == 0)
            {
                return(LoginResult.GeneralFailure);
            }

            if (!loginResponse.LoginComplete)
            {
                return(LoginResult.BadCredentials);
            }

            var readableCookies = cookies.GetCookies(new Uri("https://steamcommunity.com"));
            var oAuthData       = loginResponse.OAuthData;

            var session = new SessionData {
                OAuthToken = oAuthData.OAuthToken, SteamID = oAuthData.SteamID
            };

            session.SteamLogin       = session.SteamID + "%7C%7C" + oAuthData.SteamLogin;
            session.SteamLoginSecure = session.SteamID + "%7C%7C" + oAuthData.SteamLoginSecure;
            session.WebCookie        = oAuthData.Webcookie;
            session.SessionID        = readableCookies["sessionid"]?.Value;
            this.Session             = session;
            this.LoggedIn            = true;
            return(LoginResult.LoginOkay);
        }