Esempio n. 1
0
        public async Task <UserConsentVerifierAvailability> GetUserConsentAvailabilityAsync()
        {
            UserConsentVerifierAvailability consentAvailability =
                await UserConsentVerifier.CheckAvailabilityAsync();

            return(consentAvailability);
        }
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
        /// <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;
            }
        }
 public bool isPinOrFingerprintSetSync()
 {
     try
     {
         var ucvAvailability = await UserConsentVerifier.CheckAvailabilityAsync();
         return ucvAvailability == UserConsentVerifierAvailability.Available;
     }
     catch (Exception ex)
     {
         return false;
     }
 }
Esempio n. 5
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. 7
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;
            }
        }
Esempio n. 8
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);
            }
        }
        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. 10
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. 12
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. 13
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. 14
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. 15
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. 16
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);
        }
        public override async Task <FingerprintAvailability> GetAvailabilityAsync(bool allowAlternativeAuthentication = false)
        {
            var uwpAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

            switch (uwpAvailability)
            {
            case UserConsentVerifierAvailability.Available:
                return(FingerprintAvailability.Available);

            case UserConsentVerifierAvailability.DeviceNotPresent:
                return(FingerprintAvailability.NoSensor);

            case UserConsentVerifierAvailability.NotConfiguredForUser:
                return(FingerprintAvailability.NoFingerprint);

            case UserConsentVerifierAvailability.DisabledByPolicy:
                return(FingerprintAvailability.NoPermission);

            case UserConsentVerifierAvailability.DeviceBusy:
            default:
                return(FingerprintAvailability.Unknown);
            }
        }
Esempio n. 18
0
        private async void CheckAvailability_Click(object sender, RoutedEventArgs e)
        {
            CheckAvailabilityButton.IsEnabled = false;

            // Check the availability of Windows Hello authentication through User Consent Verifier.
            UserConsentVerifierAvailability consentAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

            switch (consentAvailability)
            {
            case UserConsentVerifierAvailability.Available:
                rootPage.NotifyUser("User consent verification available!", NotifyType.StatusMessage);
                break;

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

            default:
                rootPage.NotifyUser("User consent verification is currently unavailable.", NotifyType.ErrorMessage);
                break;
            }

            CheckAvailabilityButton.IsEnabled = true;
        }
        /// <summary>
        /// Checks the availability of the UserConsentVerifier.
        /// </summary>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public static async Task <bool> CheckAvailabilityAsync()
        {
            var available = await UserConsentVerifier.CheckAvailabilityAsync();

            return(available == Windows.Security.Credentials.UI.UserConsentVerifierAvailability.Available);
        }
 /// <summary>
 /// Determines whether the app is currently capable of validating identity.
 /// </summary>
 /// <returns>A task representing whether identity can be verified at this time.</returns>
 public async Task <UserConsentVerifierAvailability> CheckVerifierAvailabilityAsync()
 {
     return(await UserConsentVerifier.CheckAvailabilityAsync());
 }
Esempio n. 21
0
        private bool CheckAvailability()
        {
            var availability = UserConsentVerifier.CheckAvailabilityAsync().AsTask().Result;

            return(availability == UserConsentVerifierAvailability.Available);
        }
Esempio n. 22
0
        public async Task <bool> IsAvailable()
        {
            var uc = await UserConsentVerifier.CheckAvailabilityAsync();

            return(uc == UserConsentVerifierAvailability.Available);
        }
Esempio n. 23
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            PasswordVault vault = new PasswordVault();

            try
            {
                var creds = vault.FindAllByResource(App.RL.GetString("CredResName"));
                if (creds.Count > 0)
                {
                    SetLoading();

                    var idVerificationPossible = await UserConsentVerifier.CheckAvailabilityAsync();

                    var localSettings = ApplicationData.Current.LocalSettings.Values;

                    bool goodToGo = true;

                    if (idVerificationPossible == UserConsentVerifierAvailability.Available && (bool)(localSettings[App.RL.GetString("VerifyIdSettingString")] ?? false))
                    {
                        var verified =
                            await
                            UserConsentVerifier.RequestVerificationAsync(
                                "Just need to double check that it's you before we login :)");

                        goodToGo = verified == UserConsentVerificationResult.Verified;

                        if (verified == UserConsentVerificationResult.RetriesExhausted)
                        {
                            foreach (var cred in creds)
                            {
                                vault.Remove(cred);
                            }
                            await
                            new MessageDialog("For your safety, we've removed your saved login data.",
                                              "Too Many Failed Attempts").ShowAsync();
                        }

                        if (!goodToGo)
                        {
                            await new MessageDialog("Because you enabled identity verification, you will not be able to start the app without verification.", "We Couldn't Verify Your Identity").ShowAsync();
                            App.Current.Exit();
                        }
                    }

                    var connector = new MUConnector(creds.First());
                    if (await connector.Login())
                    {
                        App.MainViewModel.connector   = connector;
                        App.MainViewModel.SignOnSaved = true;
                        Frame.Navigate(typeof(FoodTile.Views.MainPage));
                    }
                    else
                    {
                        vault.Remove(creds.First());
                        await new MessageDialog(App.RL.GetString("SavedLoginFailMsg"), App.RL.GetString("SavedLoginFailTitle")).ShowAsync();
                    }


                    UnsetLoading();
                }
            }
            catch
            {
                //Used to handle the case when no credentials are found - safe to move on
            }

            base.OnNavigatedTo(e);
        }
Esempio n. 24
0
        private async void PinPageHelper(LaunchActivatedEventArgs e)
        {
            if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("cbExtLinks"))
            {
                UtilityData.isFirstAppRun = true;
                rootFrame.Navigate(typeof(OOBE), e.Arguments);
                return;
            }
            bool isWindows = false;

            try
            {
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("WindowsHello"))
                {
                    if ((bool)ApplicationData.Current.LocalSettings.Values["WindowsHello"] == true)
                    {
                        var result = await UserConsentVerifier.CheckAvailabilityAsync();

                        if (result == UserConsentVerifierAvailability.Available)
                        {
                            var verifiedResult = await UserConsentVerifier.RequestVerificationAsync("Just checking that you are really you :)");

                            if (verifiedResult == UserConsentVerificationResult.Verified)
                            {
                                rootFrame.Navigate(typeof(MainPage), e.Arguments);
                                isWindows = true;
                            }
                            else if (verifiedResult == UserConsentVerificationResult.Canceled)
                            {
                                Application.Current.Exit();
                            }
                        }
                    }
                }
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("defaultPin") && !isWindows)
                {
                    if ((bool)ApplicationData.Current.LocalSettings.Values["defaultPin"] == true)
                    {
                        string pinString = "";
                        try
                        {
                            if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("Password"))
                            {
                                StorageFile sampleFile = await ApplicationData.Current.LocalFolder.GetFileAsync("data.txt");

                                ApplicationData.Current.LocalSettings.Values["Password"] = await FileIO.ReadTextAsync(sampleFile);
                            }
                            pinString = ApplicationData.Current.LocalSettings.Values["Password"].ToString();
                        }
                        catch (Exception)
                        {
                        }
                        if (pinString != "")
                        {
                            rootFrame.Navigate(typeof(PinUI), e.Arguments);
                        }
                        else
                        {
                            rootFrame.Navigate(typeof(MainPage), e.Arguments);
                        }
                    }
                    else
                    {
                        rootFrame.Navigate(typeof(MainPage), e.Arguments);
                    }
                }
                else
                {
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
            }
            catch (Exception)
            {
                rootFrame.Navigate(typeof(MainPage), e?.Arguments);
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Checks the availability of the UserConsentVerifier.
        /// </summary>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public static async Task <bool> CheckAvailabilityAsync()
        {
            var available = await UserConsentVerifier.CheckAvailabilityAsync();

            return(available == UserConsentVerifierAvailability.Available);
        }