private async void RequestConsent_Click(object sender, RoutedEventArgs e)
        {
            RequestConsentButton.IsEnabled = false;

            // Request the user's consent using Windows Hello via biometric verification or a PIN.
            string message = "Please confirm your identity to complete this (pretend) in-app purchase.";
            UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync(message);

            switch (consentResult)
            {
            case UserConsentVerificationResult.Verified:
                rootPage.NotifyUser("Pretend in-app purchase was successful.", NotifyType.StatusMessage);
                break;

            case UserConsentVerificationResult.DeviceNotPresent:
                rootPage.NotifyUser("No PIN or biometric found, please set one up.", NotifyType.ErrorMessage);
                break;

            case UserConsentVerificationResult.Canceled:
                rootPage.NotifyUser("User consent verification canceled.", NotifyType.ErrorMessage);
                break;

            default:
                rootPage.NotifyUser("User consent verification is currently unavailable.", NotifyType.ErrorMessage);
                break;
            }
            RequestConsentButton.IsEnabled = true;
        }
Esempio n. 2
0
        public static async Task <bool> VerifyAsync(string setting, string displayReason)
        {
            if ((DateTimeOffset.Now - App.RoamingSettings.Read("LastVerified", DateTimeOffset.MinValue)) <= App.RoamingSettings.Read(AUTHENTICATION_TIME, TimeSpan.FromMinutes(5)))
            {
                return(true);
            }

            if (!App.RoamingSettings.Read(setting, false))
            {
                return(true);
            }

            var available = await UserConsentVerifier.CheckAvailabilityAsync();

            if (available == UserConsentVerifierAvailability.Available)
            {
                var consentResult = await UserConsentVerifier.RequestVerificationAsync(displayReason);

                if (consentResult == UserConsentVerificationResult.Verified)
                {
                    App.RoamingSettings.Save("LastVerified", DateTimeOffset.Now);
                    return(true);
                }
            }
            else
            {
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        public async Task <UserConsentVerificationResult> GetRequestUserConsentVerificationAsync(string message)
        {
            UserConsentVerificationResult consentResult =
                await UserConsentVerifier.RequestVerificationAsync(message);

            return(consentResult);
        }
Esempio n. 4
0
        private async Task <bool> AuthenticateAsync()
        {
            ErrorMessage.Visibility = Visibility.Collapsed;
            FirstErrorMessage       = string.Empty;

            try
            {
                var res = await UserConsentVerifier.RequestVerificationAsync("tSecret");

                switch (res)
                {
                case UserConsentVerificationResult.Verified:
                    ConfigUtil.Set("LoginUtc", DateTime.UtcNow.ToString());
                    this.Frame.Navigate(typeof(NoteListPage), null, new SlideNavigationTransitionInfo
                    {
                        Effect = SlideNavigationTransitionEffect.FromRight,
                    });
                    return(true);

                default:
                    ErrorMessage.Text       = "Authentication error";
                    ErrorMessage.Visibility = Visibility.Visible;
                    return(false);
                }
            }
            catch (Exception)
            {
                ErrorMessage.Text       = "ERROR: Cannot use tSecret on this platform";
                ErrorMessage.Visibility = Visibility.Visible;
                StartButton.IsEnabled   = false;
                return(false);
            }
        }
Esempio n. 5
0
        public async Task <UserConsentVerifierAvailability> GetUserConsentAvailabilityAsync()
        {
            UserConsentVerifierAvailability consentAvailability =
                await UserConsentVerifier.CheckAvailabilityAsync();

            return(consentAvailability);
        }
Esempio n. 6
0
        /// <summary>
        /// Verifies the user's identity and retrieves the selected profile's passphrase
        /// </summary>
        /// <param name="profileId"></param>
        private async Task PromptForConsent(ProfileModel profile)
        {
            // Create instance to credential locker
            var locker    = new PasswordVault();
            var profileId = profile.Id.ToString();

            try
            {
                // Find the saved passphrase for the selected profile
                var login = GetSavedCredential(locker, profileId);
                if (login != null)
                {
                    // We have a stored passphrase, verify the user's identity before releasing it.
                    var consentResult = await UserConsentVerifier.RequestVerificationAsync(ResourceHelper.GetString("WindowsHelloConsentMessage"));

                    if (consentResult == UserConsentVerificationResult.Verified)
                    {
                        // Verified. Get the passphrase.
                        login.RetrievePassword();

                        // Enter the profile with the saved passphrase
                        await EnterProfile(profile, login.Password);

                        return;
                    }
                }
            }
            catch { /* Nothing to see here */ }
        }
        /// <summary>
        /// Request for user's consent with prompt given.
        /// </summary>
        /// <param name="prompt">The prompt which is shown during verification.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public static async Task <bool> RequestUserConsent(string prompt)
        {
            // If verification is not available, always return true.
            if (!await CheckAvailabilityAsync())
            {
                return(true);
            }

            var app = Application.Current as App;

            if (app == null)
            {
                return(false);
            }

            var resourceLoader = app.Container.Resolve <IResourceLoader>();

            if (string.IsNullOrEmpty(prompt))
            {
                prompt = resourceLoader.GetString(ResourceConstants.VerificationService_Prompt);
            }

            try
            {
                var consentResult = await UserConsentVerifier.RequestVerificationAsync(prompt);

                return(consentResult == UserConsentVerificationResult.Verified);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// This is the click handler for the 'Check Availability' button. It checks the availability of User consent requisition
        /// via registered fingerprints.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void CheckAvailability_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            b.IsEnabled = false;
            try
            {
                // Check the availability of User Consent with fingerprints facility
                UserConsentVerifierAvailability consentAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

                switch (consentAvailability)
                {
                case UserConsentVerifierAvailability.Available:
                {
                    rootPage.NotifyUser("User consent requisition facility is available.", NotifyType.StatusMessage);
                    break;
                }

                case UserConsentVerifierAvailability.DeviceBusy:
                {
                    rootPage.NotifyUser("Biometric device is busy.", NotifyType.ErrorMessage);
                    break;
                }

                case UserConsentVerifierAvailability.DeviceNotPresent:
                {
                    rootPage.NotifyUser("No biometric device found.", NotifyType.ErrorMessage);
                    break;
                }

                case UserConsentVerifierAvailability.DisabledByPolicy:
                {
                    rootPage.NotifyUser("Biometrics is disabled by policy.", NotifyType.ErrorMessage);
                    break;
                }

                case UserConsentVerifierAvailability.NotConfiguredForUser:
                {
                    rootPage.NotifyUser("User has no fingeprints registered.", NotifyType.ErrorMessage);
                    break;
                }

                default:
                {
                    rootPage.NotifyUser("Consent verification with fingerprints is currently unavailable.", NotifyType.ErrorMessage);
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Checking the availability of Consent feature failed with exception. Operation: CheckAvailabilityAsync, Exception: " + ex.ToString(), NotifyType.ErrorMessage);
            }
            finally
            {
                b.IsEnabled = true;
            }
        }
        /// <summary>
        /// Verifies the user's identity.
        /// </summary>
        /// <returns>True if identity was verified, else false.</returns>
        public async Task <bool> VerifyIdentityAsync()
        {
            UserConsentVerificationResult result =
                await UserConsentVerifier.RequestVerificationAsync(
                    this.resourceProvider.GetString(PromptResourceKey)
                    );

            return(result == UserConsentVerificationResult.Verified);
        }
Esempio n. 10
0
        private async Task verify()
        {
            string info    = null;
            var    succeed = false;
            var    result  = await UserConsentVerifier.RequestVerificationAsync(Strings.Resources.Verify.Dialog.Content);

            switch (result)
            {
            case UserConsentVerificationResult.Verified:
                succeed = true;
                break;

            case UserConsentVerificationResult.DeviceNotPresent:
                info = Strings.Resources.Verify.DeviceNotPresent;
                break;

            case UserConsentVerificationResult.NotConfiguredForUser:
                info = Strings.Resources.Verify.NotConfigured;
                break;

            case UserConsentVerificationResult.DisabledByPolicy:
                info = Strings.Resources.Verify.Disabled;
                break;

            case UserConsentVerificationResult.DeviceBusy:
                info = Strings.Resources.Verify.DeviceBusy;
                break;

            case UserConsentVerificationResult.RetriesExhausted:
                info = Strings.Resources.Verify.RetriesExhausted;
                break;

            case UserConsentVerificationResult.Canceled:
                info = Strings.Resources.Verify.Canceled;
                break;

            default:
                info = Strings.Resources.Verify.OtherFailure;
                break;
            }
            if (!succeed)
            {
                if (info != null)
                {
                    var dialog = new MyContentDialog
                    {
                        Title           = Strings.Resources.Verify.FailedDialogTitle,
                        Content         = info,
                        CloseButtonText = Strings.Resources.General.Exit,
                    };
                    await dialog.ShowAsync();
                }
                Application.Current.Exit();
            }
        }
 public bool isPinOrFingerprintSetSync()
 {
     try
     {
         var ucvAvailability = await UserConsentVerifier.CheckAvailabilityAsync();
         return ucvAvailability == UserConsentVerifierAvailability.Available;
     }
     catch (Exception ex)
     {
         return false;
     }
 }
Esempio n. 12
0
        public async void isPinOrFingerprintSet(ICallback actionCallback)
        {
            try
            {
                var ucvAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

                actionCallback.Invoke(ucvAvailability == UserConsentVerifierAvailability.Available);
            }
            catch (Exception ex)
            {
                actionCallback.Invoke(false);
            }
        }
        private async Task <bool> isPinOrFingerprint()
        {
            try
            {
                var ucvAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

                return(ucvAvailability == UserConsentVerifierAvailability.Available);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 14
0
        public async Task <bool> Authenticate()
        {
            var res = await UserConsentVerifier.RequestVerificationAsync("tSecret");

            switch (res)
            {
            case UserConsentVerificationResult.Verified:
                return(true);

            default:
                return(false);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Method which requests user authentication with Windows Hello if any athentication device
        /// is available.
        /// </summary>
        /// <returns>The authentication status</returns>
        internal async static Task <bool> Authenticate()
        {
            UserConsentVerifierAvailability userConsentVerifierAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

            switch (userConsentVerifierAvailability)
            {
            // TODO: Implement other UserConsentVerifierAvailability cases
            case UserConsentVerifierAvailability.Available:
                return(await UserConsentVerifier.RequestVerificationAsync("WindowsHelloMessage".GetLocalized()) == UserConsentVerificationResult.Verified);

            default:
                return(false);
            }
        }
Esempio n. 16
0
        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            args.Cancel = true;
            var ucvAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

            if (ucvAvailability == UserConsentVerifierAvailability.Available)
            {
                var consentResult = await UserConsentVerifier.RequestVerificationAsync(this.Title.ToString());

                this.Success = (consentResult == UserConsentVerificationResult.Verified);
                this.Hide();
                return;
            }
        }
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            var available = await UserConsentVerifier.CheckAvailabilityAsync();

            if (available != UserConsentVerifierAvailability.Available)
            {
                unavailableText.Visibility = Visibility.Visible;
                settingsContent.IsEnabled  = false;
            }
            else
            {
                unavailableText.Visibility = Visibility.Collapsed;
                settingsContent.IsEnabled  = true;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Verify login with Windows Hello
        /// </summary>
        private async void WindowsHelloLogin()
        {
            UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync(Resources.WindowsHelloLoginMessage);

            if (consentResult.Equals(UserConsentVerificationResult.Verified))
            {
                var dbHash = await App.Repository.Password.GetAsync();

                var secretService = App.Current.Container.Resolve <ISecretService>();
                //TODO check if this is a problem
                if (!await CheckNavigationRequest(secretService.Helper.ReadSecret(Constants.ContainerName, dbHash.Hash)))
                {
                    ShowLoginError();
                }
            }
        }
Esempio n. 19
0
        private async void buttonRequestConsent_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync("我要做一些操作,您同意吗?");

                switch (consentResult)
                {
                case UserConsentVerificationResult.Verified:     // 验证通过
                    lblMsg.Text += "UserConsentVerificationResult.Verified";
                    break;

                case UserConsentVerificationResult.DeviceBusy:
                    lblMsg.Text += "UserConsentVerificationResult.DeviceBusy";
                    break;

                case UserConsentVerificationResult.DeviceNotPresent:
                    lblMsg.Text += "UserConsentVerificationResult.DeviceNotPresent";
                    break;

                case UserConsentVerificationResult.DisabledByPolicy:
                    lblMsg.Text += "UserConsentVerificationResult.DisabledByPolicy";
                    break;

                case UserConsentVerificationResult.NotConfiguredForUser:
                    lblMsg.Text += "UserConsentVerificationResult.NotConfiguredForUser";
                    break;

                case UserConsentVerificationResult.RetriesExhausted:
                    lblMsg.Text += "UserConsentVerificationResult.RetriesExhausted";
                    break;

                case UserConsentVerificationResult.Canceled:     // 验证取消
                    lblMsg.Text += "UserConsentVerificationResult.Canceled";
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text += ex.ToString();
            }

            lblMsg.Text += "\n";
        }
Esempio n. 20
0
        private async void CreateAccountButton_Click(object sender, RoutedEventArgs e)
        {
            if (personalInfo == null)
            {
                var uri = new Uri(@"https://app.n26.com/register");
                await Windows.System.Launcher.LaunchUriAsync(uri);
            }
            else
            {
                UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync("Please authenticate to log in!");

                if (consentResult.Equals(UserConsentVerificationResult.Verified))
                {
                    SendLogin(GetCredentialFromLocker().UserName, GetCredentialFromLocker().Password);
                }
            }
        }
        public static IAsyncOperation <UserConsentVerificationResult> RequestVerificationForWindowAsync(IntPtr hWnd, string Message)
        {
            //Use WinRT's GuidGenerator to get the correct guid
            var guid = GuidGenerator.CreateIID(typeof(IAsyncOperation <UserConsentVerificationResult>));

            //leverage winrt .As<> operator to cast winrt type to its interop interface
            IUserConsentVerifierInterop userConsentVerifierInterop = UserConsentVerifier.As <IUserConsentVerifierInterop>();

            //Handle marshalling the string to WinRT's HString
            var marshalStr = MarshalString.CreateMarshaler(Message);

            //Call the Interop api that pops a dialog, passing in the hWnd parameter
            IntPtr outPtr;

            userConsentVerifierInterop.RequestVerificationForWindowAsync(hWnd, MarshalString.GetAbi(marshalStr), ref guid, out outPtr);

            //Marshal the return object as an IAsyncOperation<>
            return((IAsyncOperation <UserConsentVerificationResult>)IInspectable.FromAbi(outPtr));
        }
Esempio n. 22
0
        public async Task <FingerprintAuthenticationResult> AuthenticateAsync(string reason, CancellationToken cancellationToken)
        {
            var result = new FingerprintAuthenticationResult();

            try
            {
                var verificationResult = await UserConsentVerifier.RequestVerificationAsync(reason);

                switch (verificationResult)
                {
                case UserConsentVerificationResult.Verified:
                    result.Status = FingerprintAuthenticationResultStatus.Succeeded;
                    break;

                case UserConsentVerificationResult.DeviceBusy:
                case UserConsentVerificationResult.DeviceNotPresent:
                case UserConsentVerificationResult.DisabledByPolicy:
                case UserConsentVerificationResult.NotConfiguredForUser:
                    result.Status = FingerprintAuthenticationResultStatus.NotAvailable;
                    break;

                case UserConsentVerificationResult.RetriesExhausted:
                    result.Status = FingerprintAuthenticationResultStatus.Failed;
                    break;

                case UserConsentVerificationResult.Canceled:
                    result.Status = FingerprintAuthenticationResultStatus.Canceled;
                    break;

                default:
                    result.Status = FingerprintAuthenticationResultStatus.NotAvailable;
                    break;
                }
            }
            catch (Exception ex)
            {
                result.Status       = FingerprintAuthenticationResultStatus.UnknownError;
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }
Esempio n. 23
0
        private void DeviceAuthentication(StoryNode cut)
        {
            var t1 = UserConsentVerifier.CheckAvailabilityAsync().AsTask();

            t1.ContinueWith(delegate
            {
                var available = t1.Result;
                if (available == UserConsentVerifierAvailability.Available)
                {
                    _ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        var t2 = UserConsentVerifier.RequestVerificationAsync("tSecret").AsTask();
                        t2.ContinueWith(delegate
                        {
                            if (t2.Result == UserConsentVerificationResult.Verified)
                            {
                                ConfigUtil.Set("LoginUtc", DateTime.UtcNow.ToString());
                                cut.TaskResult = true;
                            }
                            else
                            {
                                cut.MessageBuffer.WriteLine($"PIN Authentication stopped : {t2.Result}");
                                cut.TaskResult = false;
                            }
                        });
                    });
                }
                else
                {
                    cut.MessageBuffer.WriteLine($"PIN Authentication is not available.");
                    cut.MessageBuffer.WriteLine($"(E902)");
                    cut.TaskResult = false;
                }
            });
            //        catch (Exception ex)
            //        {
            //            cut.MessageBuffer.WriteLine($"Local Authentication exception");
            //            cut.MessageBuffer.WriteLine($"(E901-2)");
            //            cut.MessageBuffer.WriteLine(ex.Message);
            //            cut.TaskResult = false;
            //        }
        }
        public async Task <bool> ConfirmUserConsent()
        {
            if (ApiInformation.IsTypePresent("Windows.Security.Credentials.UI.UserConsentVerifier"))
            {
                var ucvAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

                if (ucvAvailability == UserConsentVerifierAvailability.Available)
                {
                    var ucvResult = await UserConsentVerifier.RequestVerificationAsync($"You are about to enter edit mode. Are you sure?");

                    return(ucvResult == UserConsentVerificationResult.Verified);
                }
            }
            else
            {
                return(true);
            }

            return(true);
        }
Esempio n. 25
0
        public static async Task <bool> ChallengeWindowsHelloAsync()
        {
            if (await UserConsentVerifier.CheckAvailabilityAsync() == UserConsentVerifierAvailability.Available)
            {
                var consentResult = await UserConsentVerifier.RequestVerificationAsync("Let's make sure you're authorized to make changes");

                if (consentResult == UserConsentVerificationResult.Verified)
                {
                    return(true);
                }
            }


            // Fallback
            var dialog = new MessageDialog("Make sure Windows Hello has been already set up first.", "You are not authorized");

            await dialog.ShowAsync();

            return(false);
        }
Esempio n. 26
0
        // Add reference to Windows.winmd, typically c:\program files (x86)\windows kits\10\UnionMetadata\{version}
        // Add reference to System.Runtime.WindowsRuntime.dll, typically C:\Windows\Microsoft.NET\Framework\v4.0.30319
        public async Task <bool> WindowsHelloSignInAsync()
        {
            // Check the availability of Windows Hello authentication through User Consent Verifier.
            UserConsentVerifierAvailability consentAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

            if (consentAvailability == UserConsentVerifierAvailability.Available)
            {
                // Request the user's consent using Windows Hello via biometric verification or a PIN.
                string message = "Please confirm your identity to login to this app";
                UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync(message);

                switch (consentResult)
                {
                case UserConsentVerificationResult.Verified:
                    System.Diagnostics.Debug.WriteLine("User verified");
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 27
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            try
            {
                UserConsentVerifierAvailability verifierAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

                switch (verifierAvailability)
                {
                case UserConsentVerifierAvailability.Available:     // 验证器可用
                    lblMsg.Text = "UserConsentVerifierAvailability.Available";
                    break;

                case UserConsentVerifierAvailability.DeviceBusy:
                    lblMsg.Text = "UserConsentVerifierAvailability.DeviceBusy";
                    break;

                case UserConsentVerifierAvailability.DeviceNotPresent:
                    lblMsg.Text = "UserConsentVerifierAvailability.DeviceNotPresent";
                    break;

                case UserConsentVerifierAvailability.DisabledByPolicy:
                    lblMsg.Text = "UserConsentVerifierAvailability.DisabledByPolicy";
                    break;

                case UserConsentVerifierAvailability.NotConfiguredForUser:
                    lblMsg.Text = "UserConsentVerifierAvailability.NotConfiguredForUser";
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.ToString();
            }

            lblMsg.Text += "\n";
        }
Esempio n. 28
0
        public async Task <bool> CheckUserConsentAvailabilityAsync()
        {
            try
            {
                UserConsentVerifierAvailability consentAvailability =
                    await UserConsentVerifier.CheckAvailabilityAsync();

                if (consentAvailability == UserConsentVerifierAvailability.Available)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 29
0
        public static async Task <bool> ChallengeWindowsHelloAsync()
        {
            if (await UserConsentVerifier.CheckAvailabilityAsync() == UserConsentVerifierAvailability.Available)
            {
                var consentResult = await UserConsentVerifier.RequestVerificationAsync("DeviceSecurity_ChallengeWindowsHelloRequest/Description".GetLocalized());

                if (consentResult == UserConsentVerificationResult.Verified)
                {
                    return(true);
                }
            }


            // Fallback
            var dialog = new MessageDialog("DeviceSecurity_ChallengeWindowsHelloError/Description".GetLocalized(),
                                           "DeviceSecurity_ChallengeWindowsHelloError/Title".GetLocalized());

            await dialog.ShowAsync();

            return(false);
        }
Esempio n. 30
0
        public async Task <bool> RequestUserConsentVerificationAsync(string message)
        {
            try
            {
                UserConsentVerificationResult consentResult =
                    await UserConsentVerifier.RequestVerificationAsync(message);

                if (consentResult == UserConsentVerificationResult.Verified)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }