public void Format() { const string password = "******"; GetRsaKeyResponse getRsaKeyResponse = new GetRsaKeyResponse(); getRsaKeyResponse.PublicKeyMod = "b57ab169e7cff1db44eba0da7e1effab9d62ba371a4c144d5371cc78e80d1c9588c8f9036ff4a36b093b80f555a6c8fb4d3a0ee862581a4ee3d4165094269e39477497873e0740e0b6ad602f10d0aa4afe4acb211ac43dbe2de78f69a400124b78f0c4994f88447a0890fe058b3124a4c87672e5604ea07314ae44603cec455edd502da0bada4de46dec9b1094cbd1412e4326e64be222ef95a10e914e00e957762a938bee96bbf649bec12e68fe734206d35c79443095cb300f7d230d20739d0e040eeb492372cc1ed09f5327c2f17bae46e85f52ec1d33bcf37079345dacf131a02db9b387fa1a75b001561a4e1cd1ef3f975b6dcf0f6a62e2f6976a37daa9"; getRsaKeyResponse.PublicKeyExp = "010001"; var encryptedPassword = EncryptPasswordFactory.Create(getRsaKeyResponse, password); Assert.Contains("=", encryptedPassword); }
private GetRsaKeyResponse GetRsaKey(string username) { var postContent = PostDataFactory.CreateGetRsaKeyData(username); GetRsaKeyResponse getRsaKeyResponse = null; var response = _requestFactory.Create(HttpMethod.POST, Uris.SteamCommunitySecureBase, SteamCommunityEndpoints.GetRsaKey, Accept.All, HttpHeaderValues.AcceptLanguageOne, false, true, true, true, false, postContent); string responseContent = response.Content.ReadAsStringAsync().Result; getRsaKeyResponse = JsonConvert.DeserializeObject <GetRsaKeyResponse>(responseContent); return(getRsaKeyResponse); }
internal static string Create(GetRsaKeyResponse getRsaKeyResponse, string password) { var encryptPasswordModel = new EncryptPasswordModel { PublicKeyExp = getRsaKeyResponse.PublicKeyExp, PublicKeyMod = getRsaKeyResponse.PublicKeyMod, Password = password }; var encrypted = string.Empty; while (encrypted.Length < 2 || encrypted.Substring(encrypted.Length - 2) != "==") { encrypted = EncryptPassword(encryptPasswordModel); } return(encrypted); }
private DoLoginResponse DoLogin(GetRsaKeyResponse getRsaKeyResponse, string username, string password, string sharedSecret) { DoLoginResponse doLoginResponse = null; var encryptedPassword = EncryptPasswordFactory.Create(getRsaKeyResponse, password); var content = PostDataFactory.CreateDoLoginData(username, encryptedPassword, getRsaKeyResponse.Timestamp, TwoFactorCodeFactory.Create(sharedSecret)); var response = _requestFactory.Create(HttpMethod.POST, Uris.SteamCommunitySecureBase, SteamCommunityEndpoints.DoLogin, Accept.All, HttpHeaderValues.AcceptLanguageOne, false, true, true, true, false, content); string responseContent = response.Content.ReadAsStringAsync().Result; doLoginResponse = JsonConvert.DeserializeObject <DoLoginResponse>(responseContent); return(doLoginResponse); }
async Task <bool> doLogin() { // Assume validity checks have been done // 1. Get RSA key GetRsaKeyResponse rsaResponse = await loginClient.GetRsaKeyAsync(usernameTextBox.Text); if (!rsaResponse.Success) { setMessage(!string.IsNullOrEmpty(rsaResponse.Message) ? rsaResponse.Message : "Can't get RSA key for sending login info."); return(false); } // 2. Encrypt password string encryptedPassword; using (var rsa = new RSACryptoServiceProvider()) { rsa.ImportParameters(new RSAParameters { Modulus = hexToBytes(rsaResponse.PublicKeyMod), Exponent = hexToBytes(rsaResponse.PublicKeyExp) }); // Filter password to ASCII characters (the login script does this) string password = System.Text.RegularExpressions.Regex.Replace(passwordTextBox.Text, "[^\u0000-\u007F]", string.Empty); byte[] passwordBlob = Encoding.UTF8.GetBytes(password); byte[] crypted = rsa.Encrypt(passwordBlob, false); encryptedPassword = Convert.ToBase64String(crypted); } // 3. Send request to server DoLoginRequest request = new DoLoginRequest { Password = encryptedPassword, Username = usernameTextBox.Text, TwoFactorCode = mobileAuthTextBox.Text, EmailAuth = emailAuthTextBox.Text, LoginFriendlyName = friendlyNameTextBox.Text, CaptchaText = captchaTextBox.Text, RsaTimeStamp = rsaResponse.Timestamp, RememberLogin = true }; if (loginResponse != null) { request.CaptchaGid = loginResponse.CaptchaGid; request.EmailSteamId = loginResponse.EmailSteamId; } else { request.CaptchaGid = -1; } loginResponse = await loginClient.DoLoginAsync(request); if (loginResponse == null) { return(false); } return(loginResponse.Success && loginResponse.LoginComplete); }
private SkadiLoginResponse ExecuteUntilLogin(SkadiLoginData skadiLoginData) { GetSession(); GetRsaKeyResponse rsaKey = new GetRsaKeyResponse(); DoLoginResponse doLoginResponse = new DoLoginResponse(); var doLoginSuccessful = false; do { try { rsaKey = GetRsaKey(skadiLoginData.Username); doLoginResponse = DoLogin(rsaKey, skadiLoginData.Username, skadiLoginData.Password, skadiLoginData.SharedSecret); if (!DoLoginResponseValidator.IsValid(doLoginResponse)) { if (doLoginResponse.CaptchaNeeded) { // TODO: Get exact time for cooldown of captcha! Task.Delay(TimeSpan.FromMinutes(25)); } rsaKey = null; doLoginResponse = null; } else { doLoginSuccessful = true; } } catch (Exception) { Task.Delay( TimeSpan.FromSeconds( _skadiLoginConfiguration.WaitTimeEachError)).Wait(); } }while (doLoginSuccessful == false); bool errorInTransfer = false; do { try { Transfer(doLoginResponse); } catch (Exception) { errorInTransfer = true; Task.Delay(TimeSpan.FromSeconds(5)).Wait(); } } while (errorInTransfer); SkadiLoginResponse skadiLoginResponse = null; do { try { skadiLoginResponse = SetSession(); } catch (Exception) { Task.Delay(TimeSpan.FromSeconds(5)).Wait(); } } while (skadiLoginResponse == null); return(skadiLoginResponse); }