private static IAuthProvider GetAuthProvider(IntPtr keePassWindowHandle) { var authCacheType = Settings.Instance.GetAuthCacheType(); try { return(AuthProviderFactory.GetInstance(keePassWindowHandle, authCacheType)); } catch (AuthProviderKeyNotFoundException ex) { if (authCacheType == AuthCacheType.Local) { throw; } Settings.Instance.WinStorageEnabled = false; authCacheType = Settings.Instance.GetAuthCacheType(); ErrorHandler.ShowError(ex, "Credential Manager storage has been turned off. Use Options dialog to turn it on."); return(AuthProviderFactory.GetInstance(keePassWindowHandle, authCacheType)); } catch (AuthProviderInvalidKeyException ex) { if (authCacheType == AuthCacheType.Local) { throw; } Settings.Instance.WinStorageEnabled = false; authCacheType = Settings.Instance.GetAuthCacheType(); ErrorHandler.ShowError(ex, "For security reasons Credential Manager storage has been turned off. Use Options dialog to turn it on."); return(AuthProviderFactory.GetInstance(keePassWindowHandle, authCacheType)); } }
public KeyCipher(string message, IntPtr windowHandle) { _randomSeedBits = 256; _encryptionIV = CryptoRandom.Instance.GetRandomBytes(16); _cipherEngine = CipherPool.GlobalPool.GetCipher(StandardAesEngine.AesUuid); _cryptProvider = AuthProviderFactory.GetInstance(message, windowHandle); }
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; } string dbPath = e.Database.IOConnectionInfo.Path; if (!IsDBLocking(e)) { _keyStorage.Remove(dbPath); } else if (AuthProviderFactory.IsAvailable() && Settings.Instance.Enabled) { _keyStorage.AddOrUpdate(dbPath, ProtectedKey.Create(e.Database.MasterKey, _keyCipher)); } }