Exemple #1
0
        public static WinHelloProvider CreateInstance(AuthCacheType authCacheType)
        {
            EnsureWinHelloAvailability();

            lock (_mutex)
            {
                WinHelloProvider winHelloProvider = null;
                if (_instance != null && (winHelloProvider = _instance.Target as WinHelloProvider) != null)
                {
                    if (winHelloProvider.CurrentCacheType == authCacheType)
                    {
                        return(winHelloProvider);
                    }
                    else
                    {
                        throw new AuthProviderException("Incompatible cache type with existing instance.");
                    }
                }

                winHelloProvider = new WinHelloProvider(authCacheType);
                _instance        = new WeakReference(winHelloProvider);

                return(winHelloProvider);
            }
        }
Exemple #2
0
        private WinHelloProvider(AuthCacheType authCacheType)
        {
            CurrentCacheType = authCacheType;

            if (authCacheType == AuthCacheType.Local)
            {
                DeletePersistentKey();
            }
            else
            {
                System.Diagnostics.Debug.Assert(authCacheType == AuthCacheType.Persistent);

                SafeNCryptKeyHandle ngcKeyHandle;
                if (!TryOpenPersistentKey(out ngcKeyHandle))
                {
                    throw new AuthProviderKeyNotFoundException("Persistent key does not exist.");
                }

                using (ngcKeyHandle)
                {
                    if (!VerifyPersistentKeyIntegrity(ngcKeyHandle))
                    {
                        ngcKeyHandle.Close();
                        DeletePersistentKey();
                        throw new AuthProviderInvalidKeyException(InvalidatedKeyMessage);
                    }
                }
            }
        }
Exemple #3
0
 public void ClaimCurrentCacheType(AuthCacheType authCacheType)
 {
     _keyCipher.AuthProvider.ClaimCurrentCacheType(authCacheType);
     _keyStorage.Clear();
     _keyStorage = KeyStorageFactory.Create(_keyCipher.AuthProvider);
     if (authCacheType == AuthCacheType.Local)
     {
         Settings.Instance.WinStorageEnabled = false;
     }
     // todo migrate
 }
        public static IAuthProvider GetInstance(IntPtr keePassWindowHandle, AuthCacheType authCacheType)
        {
#if DEBUG
            var provider = new XorProvider(authCacheType);
#else
            var provider = WinHelloProvider.CreateInstance(authCacheType);
#endif
            if (UAC.IsCurrentProcessElevated)
            {
                return(new WinHelloProviderForegroundDecorator(provider, keePassWindowHandle));
            }
            else
            {
                return(provider);
            }
        }
Exemple #5
0
        public void ClaimCurrentCacheType(AuthCacheType authCacheType)
        {
            if (CurrentCacheType == authCacheType)
            {
                return;
            }

            lock (_mutex)
            {
                if (authCacheType == AuthCacheType.Local)
                {
                    DeletePersistentKey();
                }
                else
                {
                    Debug.Assert(authCacheType == AuthCacheType.Persistent);

                    SafeNCryptKeyHandle ngcKeyHandle;
                    if (TryOpenPersistentKey(out ngcKeyHandle))
                    {
                        try
                        {
                            if (!VerifyPersistentKeyIntegrity(ngcKeyHandle))
                            {
                                throw new AuthProviderInvalidKeyException(InvalidatedKeyMessage);
                            }
                            ngcKeyHandle.Dispose();
                        }
                        catch
                        {
                            ngcKeyHandle.Dispose();
                            DeletePersistentKey();
                            throw;
                        }
                    }
                    else
                    {
                        CreatePersistentKey(false).Dispose();
                    }
                }

                CurrentCacheType = authCacheType;
            }
        }
        }                                                           // TDB

        public void ClaimCurrentCacheType(AuthCacheType newType)
        {
            CurrentCacheType = newType;

            if (newType == AuthCacheType.Persistent)
            {
                string message   = "Default message for persistent auth type";
                var    uiContext = AuthProviderUIContext.Current;
                if (uiContext != null)
                {
                    message = uiContext.Message;
                }

                var dlgRslt = MessageBox.Show(uiContext, message, "Test cache type change", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dlgRslt != DialogResult.OK)
                {
                    throw new AuthProviderUserCancelledException();
                }
            }
            else
            {
                MessageBox.Show(AuthProviderUIContext.Current, "Switched to local.", "Keys removed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 public void ClaimCurrentCacheType(AuthCacheType newType)
 {
     _winHelloProvider.ClaimCurrentCacheType(newType);
 }
 public XorProvider(AuthCacheType authCacheType)
 {
     CurrentCacheType = authCacheType;
 }