Exemple #1
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();
        }
Exemple #2
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);
                        }
                    }
                }
            }
        }
        /// <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]);
                }
            }
        }
Exemple #4
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));
            }
        }
Exemple #5
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));
        }
Exemple #6
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);
        }
Exemple #7
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));
        }