Beispiel #1
0
 private void Lock(bool isDbLocking, string dbPath, CompositeKey databaseMasterKey)
 {
     try
     {
         if (!isDbLocking && Settings.Instance.GetAuthCacheType() == AuthCacheType.Local)
         {
             _keyStorage.Remove(dbPath);
         }
         else if (Settings.Instance.Enabled)
         {
             _keyStorage.AddOrUpdate(dbPath, ProtectedKey.Create(databaseMasterKey, _keyCipher));
         }
     }
     catch (AuthProviderKeyNotFoundException ex)
     {
         // It's expected not to throw exceptions
         ClaimCurrentCacheType(AuthCacheType.Local);
         ErrorHandler.ShowError(ex, "Credential Manager storage has been turned off. Use Options dialog to turn it on.");
     }
     catch (AuthProviderInvalidKeyException ex)
     {
         // It's expected not to throw exceptions
         ClaimCurrentCacheType(AuthCacheType.Local);
         ErrorHandler.ShowError(ex,
                                "For security reasons Credential Manager storage has been turned off. Use Options dialog to turn it on.");
     }
     catch (AuthProviderUserCancelledException)
     {
         // it's OK
     }
 }
Beispiel #2
0
        public void OnDBClosing(object sender, FileClosingEventArgs e)
        {
            if (e == null)
            {
                Debug.Fail("Event is null");
                return;
            }

            if (e.Cancel || e.Database == null || e.Database.MasterKey == null || e.Database.IOConnectionInfo == null)
            {
                return;
            }

            try
            {
                string dbPath = e.Database.IOConnectionInfo.Path;
                if (!IsDBLocking(e) && Settings.Instance.GetAuthCacheType() == AuthCacheType.Local)
                {
                    _keyStorage.Remove(dbPath);
                }
                else if (Settings.Instance.Enabled)
                {
                    _keyStorage.AddOrUpdate(dbPath, ProtectedKey.Create(e.Database.MasterKey, _keyCipher));
                }
            }
            catch (AuthProviderInvalidKeyException ex)
            {
                // It's expected not to throw exceptions
                ClaimCurrentCacheType(AuthCacheType.Local);
                ErrorHandler.ShowError(ex, "For security reasons Credential Manager storage has been turned off. Use Options dialog to turn it on.");
            }
            catch (AuthProviderUserCancelledException)
            {
                // it's OK
            }
            catch (Exception ex)
            {
                ErrorHandler.ShowError(ex);
            }
        }