コード例 #1
0
        /// <summary>
        /// Determine if this is the correct Master Key, by testing with MasterKeyCheck and friends. If it is, keep the Master Key.
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public bool TryPasswordMasterKey(byte[] bytes)
        {
            if (string.IsNullOrEmpty(MasterKeyCheck) || string.IsNullOrEmpty(MasterKeyCheckIV))
            {
                return(false);
            }

            byte[] masterKeyCheckIV = Convert.FromBase64String(MasterKeyCheckIV);

            using (SecureBytesWrapper sbwPreHash = new SecureBytesWrapper())
            {
                byte[] plaintextBytes = Encoding.Unicode.GetBytes(MasterKeyCheckPlaintext);
                sbwPreHash.Bytes = new byte[masterKeyCheckIV.Length + plaintextBytes.Length + bytes.Length];

                System.Buffer.BlockCopy(masterKeyCheckIV, 0, sbwPreHash.Bytes, 0, masterKeyCheckIV.Length);
                System.Buffer.BlockCopy(plaintextBytes, 0, sbwPreHash.Bytes, masterKeyCheckIV.Length, plaintextBytes.Length);
                System.Buffer.BlockCopy(bytes, 0, sbwPreHash.Bytes, masterKeyCheckIV.Length + plaintextBytes.Length, bytes.Length);

                using (SHA256Managed sha = new SHA256Managed())
                {
                    // convert to Base64 and this is our check
                    if (!MasterKeyCheck.Equals(Convert.ToBase64String(sha.ComputeHash(sbwPreHash.Bytes))))
                    {
                        return(false);
                    }
                }
            }

            SetPasswordMasterKeyBytes(bytes);
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Using the Password Master Key, generate a hash that can be tested to check if we enter the correct Master Password
        /// </summary>
        void GenerateMasterKeyCheck()
        {
            using (RijndaelManaged rjmIVGenerator = new RijndaelManaged())
            {
                rjmIVGenerator.GenerateIV();
                MasterKeyCheckIV = Convert.ToBase64String(rjmIVGenerator.IV);

                using (SecureBytesWrapper sbwPreHash = new SecureBytesWrapper())
                {
                    byte[] plaintextBytes = Encoding.Unicode.GetBytes(MasterKeyCheckPlaintext);
                    using (SecureBytesWrapper sbwKey = new SecureBytesWrapper(App.Settings.PasswordMasterKey, true))
                    {
                        sbwPreHash.Bytes = new byte[rjmIVGenerator.IV.Length + plaintextBytes.Length + sbwKey.Bytes.Length];

                        System.Buffer.BlockCopy(rjmIVGenerator.IV, 0, sbwPreHash.Bytes, 0, rjmIVGenerator.IV.Length);
                        System.Buffer.BlockCopy(plaintextBytes, 0, sbwPreHash.Bytes, rjmIVGenerator.IV.Length, plaintextBytes.Length);
                        System.Buffer.BlockCopy(sbwKey.Bytes, 0, sbwPreHash.Bytes, rjmIVGenerator.IV.Length + plaintextBytes.Length, sbwKey.Bytes.Length);
                    }
                    using (SHA256Managed sha = new SHA256Managed())
                    {
                        // convert to Base64 and this is our check
                        MasterKeyCheck = Convert.ToBase64String(sha.ComputeHash(sbwPreHash.Bytes));
                    }
                }
            }
        }
コード例 #3
0
            Windows.COPYDATASTRUCT GetEncryptedMasterKeyTransmission()
            {
                byte[] encryptedMessage;
                byte[] iv;

                using (SecureBytesWrapper sbwKey = new SecureBytesWrapper(App.Settings.PasswordMasterKey, true))
                {
                    Encrypt(sbwKey.Bytes, out encryptedMessage, out iv);
                }
                Windows.COPYDATASTRUCT cds = new Windows.COPYDATASTRUCT();
                cds.cbData = sizeof(int) + iv.Length + encryptedMessage.Length;

                byte[] combinedMessage = new byte[cds.cbData];
                byte[] lengthBytes     = BitConverter.GetBytes(iv.Length);

                Buffer.BlockCopy(lengthBytes, 0, combinedMessage, 0, lengthBytes.Length);
                Buffer.BlockCopy(iv, 0, combinedMessage, lengthBytes.Length, iv.Length);
                Buffer.BlockCopy(encryptedMessage, 0, combinedMessage, lengthBytes.Length + iv.Length, encryptedMessage.Length);

                cds.lpData = Marshal.AllocHGlobal(cds.cbData);
                Marshal.Copy(combinedMessage, 0, cds.lpData, combinedMessage.Length);
                cds.dwData = new IntPtr(11);
                // caller needs to Marshal.FreeHGlobal(cds.lpData);
                return(cds);
            }
コード例 #4
0
        /// <summary>
        /// Using the provided Master Password, set the *new* Master Key. Populates Master Key Check, and encrypts+stores already-entered EVE Account passwords
        /// </summary>
        /// <param name="masterPassword"></param>
        public void SetPasswordMasterKey(System.Security.SecureString masterPassword)
        {
            ClearPasswordMasterKey();
            if (masterPassword == null || masterPassword.Length < 1)
            {
                return;
            }
            using (SHA256Managed sha = new SHA256Managed())
            {
                using (SecureStringWrapper ssw = new SecureStringWrapper(masterPassword))
                {
                    byte[] passwordBytes = ssw.ToByteArray();

                    using (SecureBytesWrapper sbw = new SecureBytesWrapper())
                    {
                        sbw.Bytes = new byte[MasterKeySalt.Length + passwordBytes.Length];

                        System.Buffer.BlockCopy(MasterKeySalt, 0, sbw.Bytes, 0, MasterKeySalt.Length);
                        System.Buffer.BlockCopy(passwordBytes, 0, sbw.Bytes, MasterKeySalt.Length, passwordBytes.Length);

                        sbw.Bytes = sha.ComputeHash(sbw.Bytes);

                        SetPasswordMasterKeyBytes(sbw.Bytes);
                    }
                }
            }
            GenerateMasterKeyCheck();
            foreach (EVEAccount account in Accounts)
            {
                account.EncryptPassword();
                account.EncryptCharacterName();
            }
            Store();
        }
コード例 #5
0
            public void ReceiveEncryptedMasterKeyTransmission(Windows.COPYDATASTRUCT cds)
            {
                byte[] combinedMessage = new byte[cds.cbData];
                Marshal.Copy(cds.lpData, combinedMessage, 0, cds.cbData);

                int ivLength = BitConverter.ToInt32(combinedMessage, 0);

                // validate length...
                if (ivLength > cds.cbData)
                {
                    // throw exception .. ?
                    throw new ApplicationException("Master Key transmission failed: Initialization Vector received incorrectly");
                }
                byte[] iv = new byte[ivLength];
                Buffer.BlockCopy(combinedMessage, sizeof(int), iv, 0, ivLength);

                byte[] encryptedMessage = new byte[cds.cbData - (ivLength + sizeof(int))];
                Buffer.BlockCopy(combinedMessage, sizeof(int) + ivLength, encryptedMessage, 0, encryptedMessage.Length);

                using (SecureBytesWrapper sbw = new SecureBytesWrapper())
                {
                    Decrypt(encryptedMessage, iv, sbw);
                    if (!App.Settings.TryPasswordMasterKey(sbw.Bytes))
                    {
                        throw new ApplicationException("Master Key transmission failed: Master Key received incorrectly");
                    }
                }
            }
コード例 #6
0
        /// <summary>
        /// Decrypts the currently EncryptedCharacterName if possible, populating SecureCharacterName (which can then be used to log in...)
        /// </summary>
        public void DecryptCharacterName(bool allowPopup)
        {
            if (string.IsNullOrEmpty(EncryptedCharacterName) || string.IsNullOrEmpty(EncryptedCharacterNameIV))
            {
                // no CharacterName stored to decrypt.
                return;
            }
            // CharacterName is indeed encrypted

            if (!App.Settings.HasPasswordMasterKey)
            {
                // Master CharacterName not yet entered
                if (!allowPopup)
                {
                    // can't ask for it right now
                    return;
                }

                // ok, ask for it
                if (!App.Settings.RequestMasterPassword())
                {
                    // not entered. can't decrypt.
                    return;
                }
            }
            using (RijndaelManaged rjm = new RijndaelManaged())
            {
                rjm.IV = Convert.FromBase64String(EncryptedCharacterNameIV);

                using (SecureBytesWrapper sbwKey = new SecureBytesWrapper(App.Settings.PasswordMasterKey, true))
                {
                    rjm.Key = sbwKey.Bytes;
                    using (ICryptoTransform decryptor = rjm.CreateDecryptor())
                    {
                        byte[] pass = Convert.FromBase64String(EncryptedCharacterName);

                        using (SecureBytesWrapper sbw = new SecureBytesWrapper())
                        {
                            sbw.Bytes = decryptor.TransformFinalBlock(pass, 0, pass.Length);

                            SecureCharacterName = new System.Security.SecureString();
                            foreach (char c in Encoding.Unicode.GetChars(sbw.Bytes))
                            {
                                SecureCharacterName.AppendChar(c);
                            }
                            SecureCharacterName.MakeReadOnly();
                        }
                    }
                }
            }
        }
コード例 #7
0
            public void Decrypt(byte[] encryptedMessage, byte[] iv, SecureBytesWrapper decryptedMessage)
            {
                using (Aes aes = new AesCryptoServiceProvider())
                {
                    aes.Key = LocalPrivateKey.Bytes;
                    aes.IV  = iv;

                    // Encrypt the message
                    using (MemoryStream ciphertext = new MemoryStream())
                    {
                        using (CryptoStream cs = new CryptoStream(ciphertext, aes.CreateDecryptor(), CryptoStreamMode.Write))
                        {
                            cs.Write(encryptedMessage, 0, encryptedMessage.Length);
                            cs.Close();
                            decryptedMessage.CopyBytes(ciphertext.ToArray());
                        }
                    }
                }
            }
コード例 #8
0
            public Session(IntPtr window, System.Diagnostics.Process process)
            {
                RemoteWindow = window;
                Process      = process;

                process.Exited += process_Exited;

                DH = new ECDiffieHellmanCng();

                DH.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash;
                DH.HashAlgorithm         = CngAlgorithm.Sha256;
                LocalPublicKey           = new SecureBytesWrapper()
                {
                    Bytes = DH.PublicKey.ToByteArray()
                };

                // this is generated using the remote public key, which we dont have yet
                LocalPrivateKey = new SecureBytesWrapper();
            }
コード例 #9
0
        /// <summary>
        /// Sets the encrypted CharacterName to the given SecureString, if possible
        /// </summary>
        /// <param name="CharacterName"></param>
        void SetEncryptedCharacterName(System.Security.SecureString CharacterName)
        {
            if (!App.Settings.UseMasterKey || CharacterName == null)
            {
                ClearEncryptedCharacterName();
                return;
            }

            if (!App.Settings.RequestMasterPassword())
            {
                System.Windows.MessageBox.Show("Your configured Master Password is required in order to save EVE Account Character Names and passwords. It can be reset or disabled by un-checking 'Save passwords (securely)', and then all currently saved EVE Account Character Names will be lost.");
                return;
            }

            using (RijndaelManaged rjm = new RijndaelManaged())
            {
                if (string.IsNullOrEmpty(EncryptedCharacterNameIV))
                {
                    rjm.GenerateIV();
                    EncryptedCharacterNameIV = Convert.ToBase64String(rjm.IV);
                }
                else
                {
                    rjm.IV = Convert.FromBase64String(EncryptedCharacterNameIV);
                }

                using (SecureBytesWrapper sbwKey = new SecureBytesWrapper(App.Settings.PasswordMasterKey, true))
                {
                    rjm.Key = sbwKey.Bytes;

                    using (ICryptoTransform encryptor = rjm.CreateEncryptor())
                    {
                        using (SecureStringWrapper ssw2 = new SecureStringWrapper(CharacterName, Encoding.Unicode))
                        {
                            byte[] inblock   = ssw2.ToByteArray();
                            byte[] encrypted = encryptor.TransformFinalBlock(inblock, 0, inblock.Length);
                            EncryptedCharacterName = Convert.ToBase64String(encrypted);
                        }
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Initialize with byte array via the SecureStringWrapper, but possibly convert from hex string...
        /// </summary>
        /// <param name="ssw"></param>
        /// <param name="convertFromHex"></param>
        public SecureBytesWrapper(SecureStringWrapper ssw, bool convertFromHex)
        {
            if (!convertFromHex)
            {
                CopyBytes(ssw.ToByteArray());
                return;
            }
            if (_hexTable == null)
            {
                _hexTable      = new byte[256];
                _hexTable['0'] = 0;
                _hexTable['1'] = 1;
                _hexTable['2'] = 2;
                _hexTable['3'] = 3;
                _hexTable['4'] = 4;
                _hexTable['5'] = 5;
                _hexTable['6'] = 6;
                _hexTable['7'] = 7;
                _hexTable['8'] = 8;
                _hexTable['9'] = 9;
                _hexTable['a'] = 10;
                _hexTable['b'] = 11;
                _hexTable['c'] = 12;
                _hexTable['d'] = 13;
                _hexTable['e'] = 14;
                _hexTable['f'] = 15;
            }

            using (SecureBytesWrapper temp = new SecureBytesWrapper(ssw, false))
            {
                _Bytes = new byte[temp.Bytes.Length / 2];
                for (int i = 0; i < temp.Bytes.Length; i += 2)
                {
                    byte b1 = temp.Bytes[i];
                    byte b2 = temp.Bytes[i + 1];
                    _Bytes[i / 2] = (byte)((_hexTable[b1] * 16) + _hexTable[b2]);
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Determine if the user has entered the correct Master Password, by testing with MasterKeyCheck and friends. If it is, keep the Master Key.
        /// </summary>
        /// <param name="masterPassword"></param>
        /// <returns></returns>
        public bool TryMasterPassword(System.Security.SecureString masterPassword)
        {
            if (masterPassword == null || masterPassword.Length < 1)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(MasterKeyCheck) || string.IsNullOrEmpty(MasterKeyCheckIV))
            {
                return(false);
            }

            using (SecureBytesWrapper sbwKey = new SecureBytesWrapper())
            {
                // first we need to create a key out of the password.
                using (SHA256Managed sha = new SHA256Managed())
                {
                    using (SecureStringWrapper ssw = new SecureStringWrapper(masterPassword))
                    {
                        byte[] passwordBytes = ssw.ToByteArray();

                        using (SecureBytesWrapper sbw = new SecureBytesWrapper())
                        {
                            sbw.Bytes = new byte[MasterKeySalt.Length + passwordBytes.Length];

                            System.Buffer.BlockCopy(MasterKeySalt, 0, sbw.Bytes, 0, MasterKeySalt.Length);
                            System.Buffer.BlockCopy(passwordBytes, 0, sbw.Bytes, MasterKeySalt.Length, passwordBytes.Length);


                            sbwKey.Bytes = sha.ComputeHash(sbw.Bytes);
                        }
                    }
                }

                return(TryPasswordMasterKey(sbwKey.Bytes));
            }
        }
コード例 #12
0
        public LoginResult GetCharacterChallenge(bool sisi, out Token accessToken)
        {
            // need SecureCharacterName.
            if (SecureCharacterName == null || SecureCharacterName.Length == 0)
            {
                DecryptCharacterName(true);
                if (SecureCharacterName == null || SecureCharacterName.Length == 0)
                {
                    Windows.CharacterChallengeWindow ccw = new Windows.CharacterChallengeWindow(this);
                    bool?result = ccw.ShowDialog();

                    if (string.IsNullOrWhiteSpace(ccw.CharacterName))
                    {
                        // CharacterName is required, sorry dude
                        accessToken = null;
                        //  SecurePassword = null;
                        SecureCharacterName = null;
                        return(LoginResult.InvalidCharacterChallenge);
                    }

                    SecureCharacterName = new System.Security.SecureString();
                    foreach (char c in ccw.CharacterName)
                    {
                        SecureCharacterName.AppendChar(c);
                    }
                    SecureCharacterName.MakeReadOnly();
                    EncryptCharacterName();
                    App.Settings.Store();
                }
            }

            string uri = "https://login.eveonline.com/Account/Challenge?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dtoken%26redirect_uri%3Dhttps%3A%2F%2Flogin.eveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken";

            if (sisi)
            {
                uri = "https://sisilogin.testeveonline.com/Account/Challenge?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dtoken%26redirect_uri%3Dhttps%3A%2F%2Fsisilogin.testeveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken";
            }

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);

            req.Timeout           = 30000;
            req.AllowAutoRedirect = true;
            if (!sisi)
            {
                req.Headers.Add("Origin", "https://login.eveonline.com");
            }
            else
            {
                req.Headers.Add("Origin", "https://sisilogin.testeveonline.com");
            }
            req.Referer         = uri;
            req.CookieContainer = Cookies;
            req.Method          = "POST";
            req.ContentType     = "application/x-www-form-urlencoded";
            using (SecureBytesWrapper body = new SecureBytesWrapper())
            {
                byte[] body1 = Encoding.ASCII.GetBytes(String.Format("RememberCharacterChallenge={0}&Challenge=", "true"));
                using (SecureStringWrapper ssw = new SecureStringWrapper(SecureCharacterName, Encoding.ASCII))
                {
                    using (SecureBytesWrapper escapedCharacterName = new SecureBytesWrapper())
                    {
                        escapedCharacterName.Bytes = System.Web.HttpUtility.UrlEncodeToBytes(ssw.ToByteArray());

                        body.Bytes = new byte[body1.Length + escapedCharacterName.Bytes.Length];
                        System.Buffer.BlockCopy(body1, 0, body.Bytes, 0, body1.Length);
                        System.Buffer.BlockCopy(escapedCharacterName.Bytes, 0, body.Bytes, body1.Length, escapedCharacterName.Bytes.Length);
                    }
                }

                req.ContentLength = body.Bytes.Length;
                try
                {
                    using (Stream reqStream = req.GetRequestStream())
                    {
                        reqStream.Write(body.Bytes, 0, body.Bytes.Length);
                    }
                }
                catch (System.Net.WebException e)
                {
                    switch (e.Status)
                    {
                    case WebExceptionStatus.Timeout:
                    {
                        accessToken = null;
                        return(LoginResult.Timeout);
                    }

                    default:
                        throw;
                    }
                }
            }
            return(GetAccessToken(sisi, req, out accessToken));
        }
コード例 #13
0
        public LoginResult GetAuthenticatorChallenge(bool sisi, out Token accessToken)
        {
            Windows.AuthenticatorChallengeWindow acw = new Windows.AuthenticatorChallengeWindow(this);
            acw.ShowDialog();
            if (!acw.DialogResult.HasValue || !acw.DialogResult.Value)
            {
                SecurePassword = null;
                accessToken    = null;
                return(LoginResult.InvalidAuthenticatorChallenge);
            }

            string uri = "https://login.eveonline.com/account/authenticator?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dtoken%26redirect_uri%3Dhttps%3A%2F%2Flogin.eveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken";

            if (sisi)
            {
                uri = "https://sisilogin.testeveonline.com/account/authenticator?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dtoken%26redirect_uri%3Dhttps%3A%2F%2Fsisilogin.testeveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken";
            }

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);

            req.Timeout           = 30000;
            req.AllowAutoRedirect = true;
            if (!sisi)
            {
                req.Headers.Add("Origin", "https://login.eveonline.com");
            }
            else
            {
                req.Headers.Add("Origin", "https://sisilogin.testeveonline.com");
            }
            req.Referer         = uri;
            req.CookieContainer = Cookies;
            req.Method          = "POST";
            req.ContentType     = "application/x-www-form-urlencoded";
            using (SecureBytesWrapper body = new SecureBytesWrapper())
            {
                body.Bytes = Encoding.ASCII.GetBytes(String.Format("Challenge={0}&RememberTwoFactor={1}&command={2}", Uri.EscapeDataString(acw.AuthenticatorCode), "true", "Continue"));

                req.ContentLength = body.Bytes.Length;
                try
                {
                    using (Stream reqStream = req.GetRequestStream())
                    {
                        reqStream.Write(body.Bytes, 0, body.Bytes.Length);
                    }
                }
                catch (System.Net.WebException e)
                {
                    switch (e.Status)
                    {
                    case WebExceptionStatus.Timeout:
                    {
                        accessToken = null;
                        return(LoginResult.Timeout);
                    }

                    default:
                        throw;
                    }
                }
            }
            LoginResult result = GetAccessToken(sisi, req, out accessToken);

            if (result == LoginResult.Success)
            {
                // successful authenticator challenge, make sure we save the cookies.
                App.Settings.Store();
            }
            return(result);
        }
コード例 #14
0
        public LoginResult GetEULAChallenge(bool sisi, string responseBody, out Token accessToken)
        {
            Windows.EVEEULAWindow eulaWindow = new Windows.EVEEULAWindow(responseBody);
            eulaWindow.ShowDialog();
            if (!eulaWindow.DialogResult.HasValue || !eulaWindow.DialogResult.Value)
            {
                SecurePassword = null;
                accessToken    = null;
                return(LoginResult.EULADeclined);
            }

            string uri = "https://login.eveonline.com/OAuth/Eula";

            if (sisi)
            {
                uri = "https://sisilogin.testeveonline.com/OAuth/Eula";
            }


            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);

            req.Timeout           = 30000;
            req.AllowAutoRedirect = true;
            if (!sisi)
            {
                req.Headers.Add("Origin", "https://login.eveonline.com");
            }
            else
            {
                req.Headers.Add("Origin", "https://sisilogin.testeveonline.com");
            }
            req.Referer         = uri;
            req.CookieContainer = Cookies;
            req.Method          = "POST";
            req.ContentType     = "application/x-www-form-urlencoded";
            using (SecureBytesWrapper body = new SecureBytesWrapper())
            {
                string eulaHash  = GetEulaHash(responseBody);
                string returnUrl = GetEulaReturnUrl(responseBody);

                string formattedString = String.Format("eulaHash={0}&returnUrl={1}&action={2}", Uri.EscapeDataString(eulaHash), Uri.EscapeDataString(returnUrl), "Accept");
                body.Bytes = Encoding.ASCII.GetBytes(formattedString);

                req.ContentLength = body.Bytes.Length;
                try
                {
                    using (Stream reqStream = req.GetRequestStream())
                    {
                        reqStream.Write(body.Bytes, 0, body.Bytes.Length);
                    }
                }
                catch (System.Net.WebException e)
                {
                    switch (e.Status)
                    {
                    case WebExceptionStatus.Timeout:
                    {
                        accessToken = null;
                        return(LoginResult.Timeout);
                    }

                    default:
                        throw;
                    }
                }
            }
            try
            {
                return(GetAccessToken(sisi, req, out accessToken));
            }
            catch (System.Net.WebException we)
            {
                return(GetAccessToken(sisi, out accessToken));
            }
        }
コード例 #15
0
        public LoginResult GetRefreshToken(bool sisi, out string refreshToken)
        {
            string checkToken = sisi ? SisiRefreshToken : TranquilityRefreshToken;

            if (!string.IsNullOrEmpty(checkToken))
            {
                refreshToken = checkToken;
                return(LoginResult.Success);
            }

            // need PlaintextPassword.
            if (SecurePassword == null || SecurePassword.Length == 0)
            {
                Windows.EVELogin el     = new Windows.EVELogin(this, false);
                bool?            result = el.ShowDialog();

                if (SecurePassword == null || SecurePassword.Length == 0)
                {
                    // password is required, sorry dude
                    refreshToken = null;
                    return(LoginResult.InvalidUsernameOrPassword);
                }
            }

            string uri = "https://login.eveonline.com/Account/LogOn?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dcode%26redirect_uri%3Dhttps%3A%2F%2Flogin.eveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken%2520user";

            if (sisi)
            {
                uri = "https://sisilogin.testeveonline.com/Account/LogOn?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dcode%26redirect_uri%3Dhttps%3A%2F%2Fsisilogin.testeveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken%2520user";
            }

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);

            req.Timeout           = 5000;
            req.AllowAutoRedirect = true;
            if (!sisi)
            {
                req.Headers.Add("Origin", "https://login.eveonline.com");
            }
            else
            {
                req.Headers.Add("Origin", "https://sisilogin.testeveonline.com");
            }
            req.Referer         = uri;
            req.CookieContainer = Cookies;
            req.Method          = "POST";
            req.ContentType     = "application/x-www-form-urlencoded";
            using (SecureBytesWrapper body = new SecureBytesWrapper())
            {
                byte[] body1 = Encoding.ASCII.GetBytes(String.Format("UserName={0}&Password="******"Invalid username / password"))
                {
                    refreshToken = null;
                    return(LoginResult.InvalidUsernameOrPassword);
                }


                /*
                 * <span id="ValidationContainer"><div class="validation-summary-errors"><span>Login failed. Possible reasons can be:</span>
                 * <ul><li>Invalid username / password</li>
                 * </ul></div></span>
                 */

                //                https://login.eveonline.com/launcher?client_id=eveLauncherTQ#access_token=l4nGki1CTUI7pCQZoIdnARcCLqL6ZGJM1X1tPf1bGKSJxEwP8lk_shS19w3sjLzyCbecYAn05y-Vbs-Jm1d1cw2&token_type=Bearer&expires_in=43200
                //accessToken = new Token(resp.ResponseUri);
                refreshCode = HttpUtility.ParseQueryString(resp.ResponseUri.Query).Get("code");

                // String expires_in = HttpUtility.ParseQueryString(fromUri.Fragment).Get("expires_in");
            }

            GetTokensFromCode(sisi, refreshCode);
            throw new NotImplementedException();

            if (!sisi)
            {
                TranquilityRefreshToken = refreshToken;
            }
            else
            {
                SisiRefreshToken = refreshToken;
            }

            return(LoginResult.Success);
        }
コード例 #16
0
        public LoginResult GetAccessToken(bool sisi, out Token accessToken)
        {
            Token checkToken = sisi ? SisiToken : TranquilityToken;

            if (checkToken != null && !checkToken.IsExpired)
            {
                accessToken = checkToken;
                return(LoginResult.Success);
            }

            // need SecurePassword.
            if (SecurePassword == null || SecurePassword.Length == 0)
            {
                DecryptPassword(true);
                if (SecurePassword == null || SecurePassword.Length == 0)
                {
                    Windows.EVELogin el     = new Windows.EVELogin(this, true);
                    bool?            result = el.ShowDialog();

                    if (SecurePassword == null || SecurePassword.Length == 0)
                    {
                        // password is required, sorry dude
                        accessToken = null;
                        return(LoginResult.InvalidUsernameOrPassword);
                    }

                    App.Settings.Store();
                }
            }

            string uri = "https://login.eveonline.com/Account/LogOn?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dtoken%26redirect_uri%3Dhttps%3A%2F%2Flogin.eveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken";

            if (sisi)
            {
                uri = "https://sisilogin.testeveonline.com/Account/LogOn?ReturnUrl=%2Foauth%2Fauthorize%2F%3Fclient_id%3DeveLauncherTQ%26lang%3Den%26response_type%3Dtoken%26redirect_uri%3Dhttps%3A%2F%2Fsisilogin.testeveonline.com%2Flauncher%3Fclient_id%3DeveLauncherTQ%26scope%3DeveClientToken";
            }

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);

            req.Timeout           = 30000;
            req.AllowAutoRedirect = true;
            if (!sisi)
            {
                req.Headers.Add("Origin", "https://login.eveonline.com");
            }
            else
            {
                req.Headers.Add("Origin", "https://sisilogin.testeveonline.com");
            }
            req.Referer         = uri;
            req.CookieContainer = Cookies;
            req.Method          = "POST";
            req.ContentType     = "application/x-www-form-urlencoded";
            using (SecureBytesWrapper body = new SecureBytesWrapper())
            {
                byte[] body1 = Encoding.ASCII.GetBytes(String.Format("UserName={0}&Password=", Uri.EscapeDataString(Username)));
                using (SecureStringWrapper ssw = new SecureStringWrapper(SecurePassword, Encoding.ASCII))
                {
                    using (SecureBytesWrapper escapedPassword = new SecureBytesWrapper())
                    {
                        escapedPassword.Bytes = System.Web.HttpUtility.UrlEncodeToBytes(ssw.ToByteArray());

                        body.Bytes = new byte[body1.Length + escapedPassword.Bytes.Length];
                        System.Buffer.BlockCopy(body1, 0, body.Bytes, 0, body1.Length);
                        System.Buffer.BlockCopy(escapedPassword.Bytes, 0, body.Bytes, body1.Length, escapedPassword.Bytes.Length);
                    }
                }

                req.ContentLength = body.Bytes.Length;
                try
                {
                    using (Stream reqStream = req.GetRequestStream())
                    {
                        reqStream.Write(body.Bytes, 0, body.Bytes.Length);
                    }
                }
                catch (System.Net.WebException e)
                {
                    switch (e.Status)
                    {
                    case WebExceptionStatus.Timeout:
                    {
                        accessToken = null;
                        return(LoginResult.Timeout);
                    }

                    default:
                        throw;
                    }
                }
            }
            return(GetAccessToken(sisi, req, out accessToken));
        }