Esempio n. 1
0
        private void setCredentialByTagToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String tagName = this.TreeView.SelectedNode.Name;

            string input = "Set Credential by Tag\r\n\r\nThis will replace the credential used for all Favorites within this tag.\r\n\r\nUse at your own risk!";

            if (InputBox.Show(ref input, "Change Credential" + " - " + tagName) == DialogResult.OK)
            {
                CredentialSet credentialSet = StoredCredentials.GetByName(input);

                if (credentialSet == null)
                {
                    MessageBox.Show("The credential you specified does not exist.");
                    return;
                }

                this.GetMainForm().Cursor = Cursors.WaitCursor;
                Application.DoEvents();

                List <FavoriteConfigurationElement> selectedFavorites = this.GetSelectedFavorites();
                Settings.ApplyCredentialsForAllSelectedFavorites(selectedFavorites, credentialSet.Name);

                this.GetMainForm().Cursor = Cursors.Default;
                Application.DoEvents();
                MessageBox.Show("Set Credential by Tag Complete.");
            }
        }
Esempio n. 2
0
        private static void LoadSettings(string settingsResourcePartialName = "settings.json")
        {
            SetDefaults();

            var storedSettings = GetStoredSettings(settingsResourcePartialName);

            if (storedSettings == null)
            {
                return;
            }

            try
            {
                var ic = new ImmutableCredentials(storedSettings.AccessKeyId, storedSettings.SecretAccessKey, storedSettings.SessionToken);
                Credentials = new StoredCredentials(ic);
            }
            catch (Exception e)
            {
                Console.WriteError("Unable to parse get credentials from settings file, defaulting to anonymous credentials. Exception: {0}", e.ToString());
                Credentials = new AnonymousAWSCredentials();
            }

            try
            {
                RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(storedSettings.RegionEndpoint);
            }
            catch (Exception e)
            {
                Console.WriteError("Unable to parse RegionEndpoint from settings file, defaulting to {0}. Exception: {1}", DefaultRegion, e.ToString());
                RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(DefaultRegion);
            }
            ResultsBucket = storedSettings.ResultsBucket;
            ResultsTopic  = storedSettings.ResultsTopic;
        }
        private void LblPasswordDoubleClick(object sender, EventArgs e)
        {
            if (this.txtPassword.PasswordChar == '\0')
            {
                this.ResetLastString();
            }
            else
            {
                this.lastString = this.txtPassword.Text;

                if (this.lastString == CredentialPanel.HIDDEN_PASSWORD)
                {
                    this.txtPassword.Text = StoredCredentials.GetByName(this.editedCredentialName).SecretKey;

                    if (!string.IsNullOrEmpty(StoredCredentials.GetByName(this.editedCredentialName).SecretKey))
                    {
                        Clipboard.SetText(StoredCredentials.GetByName(this.editedCredentialName).SecretKey);
                    }
                }

                this.txtPassword.PasswordChar = '\0';
                this.reset          = true;
                this.timer          = new Timer();
                this.timer.Tick    += delegate { this.ResetLastString(); };
                this.timer.Interval = 3000;
                this.timer.Enabled  = true;
                this.timer.Start();
            }
        }
Esempio n. 4
0
        private static void LoadSettings(string settingsResourcePartialName = "settings.json")
        {
            SetDefaults();

            var storedSettings = GetStoredSettings(settingsResourcePartialName);
            if (storedSettings == null)
                return;

            try
            {
                var ic = new ImmutableCredentials(storedSettings.AccessKeyId, storedSettings.SecretAccessKey, storedSettings.SessionToken);
                Credentials = new StoredCredentials(ic);
            }
            catch(Exception e)
            {
                Console.WriteError("Unable to parse get credentials from settings file, defaulting to anonymous credentials. Exception: {0}", e.ToString());
                Credentials = new AnonymousAWSCredentials();
            }

            try
            {
                RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(storedSettings.RegionEndpoint);
            }
            catch(Exception e)
            {
                Console.WriteError("Unable to parse RegionEndpoint from settings file, defaulting to {0}. Exception: {1}", DefaultRegion, e.ToString());
                RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(DefaultRegion);
            }
            ResultsBucket = storedSettings.ResultsBucket;
            ResultsTopic = storedSettings.ResultsTopic;
        }
Esempio n. 5
0
        public ActionResult Signout()
        {
            String userId = Session["userId"] as String;

            if (!String.IsNullOrEmpty(userId))
            {
                StoredCredentialsDBContext db = new StoredCredentialsDBContext();
                StoredCredentials          sc =
                    db.StoredCredentialSet.FirstOrDefault(x => x.UserId == userId);

                if (sc != null)
                {
                    // Revoke the token.
                    UriBuilder builder = new UriBuilder(OAUTH2_REVOKE_ENDPOINT);
                    builder.Query = "token=" + sc.RefreshToken;

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(builder.Uri);
                    request.GetResponse();

                    db.StoredCredentialSet.Remove(sc);
                }
                Session.Remove("userId");
            }
            return(Redirect(Url.Action("Index", "Main")));
        }
Esempio n. 6
0
        /// <summary>
        ///     During this procedure, the old master key material should be still present.
        ///     This finds all stored passwords and updates them to reflect new key material.
        /// </summary>
        private static void UpdateAllFavoritesPasswords(TerminalsConfigurationSection configSection, string newMasterPassword)
        {
            string newKeyMaterial = GetKeyMaterial(newMasterPassword);

            configSection.UpdatePasswordsByNewKeyMaterial(newKeyMaterial);
            UpdateFavoritePasswordsByNewKeyMaterial(newKeyMaterial);
            StoredCredentials.UpdatePasswordsByNewKeyMaterial(newKeyMaterial);
        }
Esempio n. 7
0
 internal Factory(Groups groups, Favorites favorites, StoredCredentials credentials,
     PersistenceSecurity persistenceSecurity, DataDispatcher dispatcher)
 {
     this.groups = groups;
     this.favorites = favorites;
     this.credentials = credentials;
     this.persistenceSecurity = persistenceSecurity;
     this.dispatcher = dispatcher;
 }
Esempio n. 8
0
        private CredentialSet GetSelectedItemCredentials()
        {
            if (this.CredentialsListView.SelectedItems != null && this.CredentialsListView.SelectedItems.Count > 0)
            {
                string name = this.CredentialsListView.SelectedItems[0].Text;
                return(StoredCredentials.GetByName(name));
            }

            return(null);
        }
Esempio n. 9
0
        private void connectAsCred_Click(object sender, EventArgs e)
        {
            FavoriteConfigurationElement fav = this.TreeView.SelectedFavorite;

            if (fav != null)
            {
                this.GetMainForm().Connect(fav.Name, this.consoleToolStripMenuItem.Checked,
                                           this.newWindowToolStripMenuItem.Checked, fav.IsDatabaseFavorite,
                                           StoredCredentials.GetByName(sender.ToString()), true);
            }
        }
Esempio n. 10
0
 internal static DbFavorite CreateFavorite(PersistenceSecurity persistenceSecurity, Groups groups,
     StoredCredentials credentials, DataDispatcher dispatcher)
 {
     var favorite = new DbFavorite();
     favorite.Display = new DbDisplayOptions();
     favorite.Security = new DbSecurityOptions();
     favorite.ExecuteBeforeConnect = new DbBeforeConnectExecute();
     favorite.AssignStores(groups, credentials, persistenceSecurity, dispatcher);
     favorite.MarkAsNewlyCreated();
     return favorite;
 }
Esempio n. 11
0
 private void UpdateOldOrCreateNew(CredentialSet oldItem)
 {
     if (oldItem == null || this.editedCredentialName != this.txtName.Text)
     {
         CredentialSet newCredential = this.CreateNewCredential();
         StoredCredentials.Add(newCredential);
     }
     else
     {
         this.UpdateFromControls(oldItem);
     }
 }
Esempio n. 12
0
        private bool UpdateCredential()
        {
            CredentialSet conflicting = StoredCredentials.GetByName(this.txtName.Text);
            CredentialSet oldItem     = StoredCredentials.GetByName(this.editedCredentialName);

            if (conflicting != null && this.editedCredentialName != this.txtName.Text)
            {
                return(this.UpdateConflicting(conflicting, oldItem));
            }

            this.UpdateOldOrCreateNew(oldItem);
            return(true);
        }
        /// <summary>
        /// Retrieved stored credentials for the provided user ID.
        /// </summary>
        /// <param name="userId">User's ID.</param>
        /// <returns>Stored GoogleAccessProtectedResource if found, null otherwise.</returns>
        static IAuthorizationState GetStoredCredentials(String userId)
        {
            StoredCredentialsDBContext db = new StoredCredentialsDBContext();
            StoredCredentials          sc = db.StoredCredentialSet.FirstOrDefault(x => x.UserId == userId);

            if (sc != null)
            {
                return(new AuthorizationState()
                {
                    AccessToken = sc.AccessToken, RefreshToken = sc.RefreshToken
                });
            }
            return(null);
        }
Esempio n. 14
0
        private void SaveCredentials(Dictionary <string, vRDConfigurationFileCredentialsFolderCredentials> credentials)
        {
            foreach (string guid in credentials.Keys)
            {
                vRDConfigurationFileCredentialsFolderCredentials toImport = credentials[guid];
                //will store the last one if the same credential name
                CredentialSet destination = StoredCredentials.GetByName(toImport.Name);
                if (destination == null)
                {
                    destination = new CredentialSet();
                    StoredCredentials.Add(destination);
                }

                UpdateFromvrDCredentials(toImport, destination);
            }

            StoredCredentials.Save();
        }
Esempio n. 15
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            CredentialSet toRemove = this.GetSelectedItemCredentials();

            if (toRemove != null)
            {
                if (
                    MessageBox.Show(
                        string.Format("Are you sure you want to delete credential {0}?",
                                      toRemove.Name), "Credential manager", MessageBoxButtons.YesNo) ==
                    DialogResult.Yes)
                {
                    StoredCredentials.Remove(toRemove);
                    StoredCredentials.Save();
                    this.BindList();
                }
            }
        }
        /// <summary>
        /// Store OAuth 2.0 credentials in the application's database.
        /// </summary>
        /// <param name="userId">User's ID.</param>
        /// <param name="credentials">The OAuth 2.0 credentials to store.</param>
        static void StoreCredentials(String userId, IAuthorizationState credentials)
        {
            StoredCredentialsDBContext db = new StoredCredentialsDBContext();
            StoredCredentials          sc = db.StoredCredentialSet.FirstOrDefault(x => x.UserId == userId);

            if (sc != null)
            {
                sc.AccessToken  = credentials.AccessToken;
                sc.RefreshToken = credentials.RefreshToken;
            }
            else
            {
                db.StoredCredentialSet.Add(new StoredCredentials {
                    UserId = userId, AccessToken = credentials.AccessToken, RefreshToken = credentials.RefreshToken
                });
            }
            db.SaveChanges();
        }
Esempio n. 17
0
        private Account()
        {
            // Load stored twitter credentials if we have them
            if (IsolatedStorageSettings.ApplicationSettings.Contains(kTwitterCredential))
            {
                Stored = (StoredCredentials)IsolatedStorageSettings.ApplicationSettings[kTwitterCredential];
            }

            if (Stored == null)
            {
                Stored = new StoredCredentials();
            }

            // Load configuration information

            try
            {
                if (ApiKey == null)
                {
                    ApiKey = SecretKeys.Api;
                }

                if (ConsumerKey == null)
                {
                    ConsumerKey = SecretKeys.Consumer;
                }

                if (ConsumerKeySecret == null)
                {
                    ConsumerKeySecret = SecretKeys.ConsumerSecret;
                }

                if (CallbackUrl == null)
                {
                    CallbackUrl = SecretKeys.CallbackUrl;
                }
            }
            catch (Exception) { }

            if ((ApiKey == null) || (ConsumerKey == null) || (ConsumerKeySecret == null) || (CallbackUrl == null))
            {
                throw new Exception("Twitter: Invalid configuration file");
            }
        }
Esempio n. 18
0
        private void ResetLastString()
        {
            this.txtPassword.PasswordChar = CredentialPanel.HIDDEN_PASSWORD_CHAR;

            this.reset = false;

            if (this.timer != null)
            {
                this.timer.Stop();
                this.timer = null;
            }

            if (string.IsNullOrEmpty(this.lastString))
            {
                this.lastString = StoredCredentials.GetByName(this.editedCredentialName).SecretKey;
            }

            this.txtPassword.Text = this.lastString;
        }
Esempio n. 19
0
        private bool UpdateConflicting(CredentialSet conflicting, CredentialSet oldItem)
        {
            DialogResult result =
                MessageBox.Show("The credential name you entered already exists.\nDo you want to overwrite it?",
                                "Credential manager",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result != DialogResult.Yes)
            {
                return(false);
            }

            if (oldItem != null)
            {
                StoredCredentials.Remove(oldItem);
            }

            this.UpdateFromControls(conflicting);
            return(true);
        }
Esempio n. 20
0
        /// <summary>
        /// Store OAuth 2.0 credentials in the application's database.
        /// </summary>
        /// <param name="userId">User's ID.</param>
        /// <param name="credentials">The OAuth 2.0 credentials to store.</param>
        void StoreCredentials(String userId, IAuthorizationState credentials)
        {
            var o = new StoredCredentials {
                UserId = userId, AccessToken = credentials.AccessToken, RefreshToken = credentials.RefreshToken
            };
            string json = JsonConvert.SerializeObject(o);

            System.IO.File.WriteAllText("AuthorizationState.json", json);

            //StoredCredentialsDBContext db = new StoredCredentialsDBContext();
            //StoredCredentials sc = db.StoredCredentialSet.FirstOrDefault(x => x.UserId == userId);
            //if (sc != null)
            //{
            //    sc.AccessToken = credentials.AccessToken;
            //    sc.RefreshToken = credentials.RefreshToken;
            //}
            //else
            //{
            //    db.StoredCredentialSet.Add(new StoredCredentials { UserId = userId, AccessToken = credentials.AccessToken, RefreshToken = credentials.RefreshToken });
            //}
            //db.SaveChanges();
        }
Esempio n. 21
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtName.Text) || string.IsNullOrEmpty(this.txtUserName.Text))
            {
                MessageBox.Show("You must enter both a name and a user name for the credential.",
                                "Credential manager",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.txtName.Focus();
                return;
            }

            if (this.reset)
            {
                this.ResetLastString();
            }

            if (this.UpdateCredential())
            {
                StoredCredentials.Save();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Esempio n. 22
0
 /// <summary>
 ///     Because filewatcher is created before the main form in GUI thread.
 ///     This lets to fire the file system watcher events in GUI thread.
 /// </summary>
 public static void AssignSynchronizationObject(ISynchronizeInvoke synchronizer)
 {
     Settings.Settings.AssignSynchronizationObject(synchronizer);
     ConnectionHistory.Instance.AssignSynchronizationObject(synchronizer);
     StoredCredentials.AssignSynchronizationObject(synchronizer);
 }
Esempio n. 23
0
        /// <summary>
        /// Authenticates with the server. Does not create all the components unlike <see cref="Authenticate"/>.
        /// </summary>
        /// <param name="credentials"><see cref="Spotify.LoginCredentials"/></param>
        /// <param name="removeLock">Whether <see cref="authLockEventWaitHandle"/> should be released or not.
        /// <code>false</code> for <see cref="Authenticate"/>
        /// <code>true</code> for <see cref="Reconnect"/></param>
        private void AuthenticatePartial(
            [NotNull] Spotify.LoginCredentials credentials,
            bool removeLock)
        {
            GuardAgainst.ArgumentBeingNull(recvCipher);
            GuardAgainst.ArgumentBeingNull(sendCipher);

            var clientResponseEncrypted = new ClientResponseEncrypted
            {
                LoginCredentials = credentials,
                SystemInfo       = new SystemInfo
                {
                    Os        = Os.Windows,
                    CpuFamily = CpuFamily.CpuX86,
                    SystemInformationString = "1",
                    DeviceId = inner.DeviceId
                },
                VersionString = "1.0"
            };

            SendUnchecked(MercuryPacket.Type.Login, clientResponseEncrypted.ToByteArray(), closedToken);

            var packet = Receive(conn.Result.NetworkStream, closedToken);

            switch (packet.Cmd)
            {
            case MercuryPacket.Type.APWelcome:
            {
                apWelcome = APWelcome.Parser.ParseFrom(packet.Payload);
                var bytes0X0F = new byte[20];
                (new Random()).NextBytes(bytes0X0F);
                SendUnchecked(MercuryPacket.Type.Unknown_0x0f, bytes0X0F, closedToken);

                using var preferredLocale = new MemoryStream(18 + 5);
                preferredLocale.WriteByte((byte)0x0);
                preferredLocale.WriteByte((byte)0x0);
                preferredLocale.WriteByte((byte)0x10);
                preferredLocale.WriteByte((byte)0x0);
                preferredLocale.WriteByte((byte)0x02);
                preferredLocale.Write("preferred-locale");
                preferredLocale.Write(inner.PreferredLocale);
                SendUnchecked(MercuryPacket.Type.PreferredLocale, preferredLocale.ToArray(), closedToken);
                if (removeLock)
                {
                    using (authLock.Lock())
                    {
                        authLockEventWaitHandle.Set();
                    }
                }

                try
                {
                    if (inner.Conf.StoreCredentials)
                    {
                        var jsonObj = new StoredCredentials
                        {
                            AuthenticationType = apWelcome.ReusableAuthCredentialsType,
                            Base64Credentials  = apWelcome.ReusableAuthCredentials.ToBase64(),
                            Username           = apWelcome.CanonicalUsername
                        };
                        inner.Conf.StoreCredentialsFunction(jsonObj);
                        //  ApplicationData.Current.LocalSettings.Values["auth_data"] =
                        // JsonConvert.SerializeObject(jsonObj);
                    }
                }
                catch (Exception x)
                {
                    Debug.WriteLine(x.ToString());
                    throw;
                }

                break;
            }

            case MercuryPacket.Type.AuthFailure:
                throw new SpotifyAuthenticatedException(APLoginFailed.Parser.ParseFrom(packet.Payload));

            default:
                throw new Exception("Unknown CMD 0x" + packet.Cmd);
            }
        }