private void ApplicationMonitor_TerminationFailed(IEnumerable <RunningApplication> applications)
        {
            var applicationList = string.Join(Environment.NewLine, applications.Select(a => $"- {a.Name}"));
            var message         = $"{text.Get(TextKey.LockScreen_Message)}{Environment.NewLine}{Environment.NewLine}{applicationList}";
            var title           = text.Get(TextKey.LockScreen_Title);
            var hasQuitPassword = !string.IsNullOrEmpty(Settings.Security.QuitPasswordHash);
            var allowOption     = new LockScreenOption {
                Text = text.Get(TextKey.LockScreen_AllowOption)
            };
            var terminateOption = new LockScreenOption {
                Text = text.Get(TextKey.LockScreen_TerminateOption)
            };
            var lockScreen = uiFactory.CreateLockScreen(message, title, new [] { allowOption, terminateOption });
            var result     = default(LockScreenResult);

            logger.Warn("Showing lock screen due to failed termination of blacklisted application(s)!");
            PauseActivators();
            lockScreen.Show();

            for (var unlocked = false; !unlocked;)
            {
                result = lockScreen.WaitForResult();

                if (hasQuitPassword)
                {
                    var passwordHash = hashAlgorithm.GenerateHashFor(result.Password);
                    var isCorrect    = Settings.Security.QuitPasswordHash.Equals(passwordHash, StringComparison.OrdinalIgnoreCase);

                    if (isCorrect)
                    {
                        logger.Info("The user entered the correct unlock password.");
                        unlocked = true;
                    }
                    else
                    {
                        logger.Info("The user entered the wrong unlock password.");
                        messageBox.Show(TextKey.MessageBox_InvalidUnlockPassword, TextKey.MessageBox_InvalidUnlockPasswordTitle, icon: MessageBoxIcon.Warning, parent: lockScreen);
                    }
                }
                else
                {
                    logger.Warn($"No unlock password is defined, allowing user to resume session!");
                    unlocked = true;
                }
            }

            lockScreen.Close();
            ResumeActivators();
            logger.Info("Closed lock screen.");

            if (result.OptionId == allowOption.Id)
            {
                logger.Info($"The blacklisted application(s) {string.Join(", ", applications.Select(a => $"'{a.Name}'"))} will be temporarily allowed.");
            }
            else if (result.OptionId == terminateOption.Id)
            {
                logger.Info("Attempting to shutdown as requested by the user...");
                TryRequestShutdown();
            }
        }
        private bool IsRequiredToAuthenticateForClientConfiguration(PasswordParameters passwordParams, string currentPassword = default(string))
        {
            var mustAuthenticate = currentPassword != default(string);

            if (mustAuthenticate)
            {
                var nextPassword        = Context.Next.Settings.Security.AdminPasswordHash;
                var hasSettingsPassword = passwordParams.Password != null;
                var sameAdminPassword   = currentPassword.Equals(nextPassword, StringComparison.OrdinalIgnoreCase);

                if (sameAdminPassword)
                {
                    mustAuthenticate = false;
                }
                else if (hasSettingsPassword)
                {
                    var settingsPassword   = passwordParams.IsHash ? passwordParams.Password : hashAlgorithm.GenerateHashFor(passwordParams.Password);
                    var knowsAdminPassword = currentPassword.Equals(settingsPassword, StringComparison.OrdinalIgnoreCase);

                    mustAuthenticate = !knowsAdminPassword;
                }
            }

            return(mustAuthenticate);
        }
        private bool TryValidateQuitPassword()
        {
            var dialog = uiFactory.CreatePasswordDialog(TextKey.PasswordDialog_QuitPasswordRequired, TextKey.PasswordDialog_QuitPasswordRequiredTitle);
            var result = dialog.Show();

            if (result.Success)
            {
                var passwordHash = hashAlgorithm.GenerateHashFor(result.Password);
                var isCorrect    = Settings.QuitPasswordHash.Equals(passwordHash, StringComparison.OrdinalIgnoreCase);

                if (isCorrect)
                {
                    logger.Info("The user entered the correct quit password, the application will now terminate.");
                }
                else
                {
                    logger.Info("The user entered the wrong quit password.");
                    messageBox.Show(TextKey.MessageBox_InvalidQuitPassword, TextKey.MessageBox_InvalidQuitPasswordTitle, icon: MessageBoxIcon.Warning);
                }

                return(isCorrect);
            }

            return(false);
        }
示例#4
0
        private LockScreenResult ShowLockScreen(string message, string title, IEnumerable <LockScreenOption> options)
        {
            var hasQuitPassword = !string.IsNullOrEmpty(Settings.Security.QuitPasswordHash);
            var lockScreen      = uiFactory.CreateLockScreen(message, title, options);
            var result          = default(LockScreenResult);

            logger.Info("Showing lock screen...");
            PauseActivators();
            lockScreen.Show();

            for (var unlocked = false; !unlocked;)
            {
                result = lockScreen.WaitForResult();

                if (hasQuitPassword)
                {
                    var passwordHash = hashAlgorithm.GenerateHashFor(result.Password);
                    var isCorrect    = Settings.Security.QuitPasswordHash.Equals(passwordHash, StringComparison.OrdinalIgnoreCase);

                    if (isCorrect)
                    {
                        logger.Info("The user entered the correct unlock password.");
                        unlocked = true;
                    }
                    else
                    {
                        logger.Info("The user entered the wrong unlock password.");
                        messageBox.Show(TextKey.MessageBox_InvalidUnlockPassword, TextKey.MessageBox_InvalidUnlockPasswordTitle, icon: MessageBoxIcon.Warning, parent: lockScreen);
                    }
                }
                else
                {
                    logger.Warn($"No unlock password is defined, allowing user to resume session!");
                    unlocked = true;
                }
            }

            lockScreen.Close();
            ResumeActivators();
            logger.Info("Closed lock screen.");

            return(result);
        }
示例#5
0
        private PasswordParameters DetermineEncryptionParametersFor(string prefix, PasswordParameters password)
        {
            var parameters = new PasswordParameters();

            if (prefix == BinaryBlock.PasswordConfigureClient)
            {
                parameters.Password = password.IsHash ? password.Password : hashAlgorithm.GenerateHashFor(password.Password);
                parameters.IsHash   = true;
            }
            else
            {
                parameters.Password = password.Password;
                parameters.IsHash   = password.IsHash;
            }

            return(parameters);
        }
        private void HomeNavigationRequested()
        {
            if (isMainInstance && (settings.UseStartUrlAsHomeUrl || !string.IsNullOrWhiteSpace(settings.HomeUrl)))
            {
                var navigate = false;
                var url      = settings.UseStartUrlAsHomeUrl ? settings.StartUrl : settings.HomeUrl;

                if (settings.HomeNavigationRequiresPassword && !string.IsNullOrWhiteSpace(settings.HomePasswordHash))
                {
                    var message = text.Get(TextKey.PasswordDialog_BrowserHomePasswordRequired);
                    var title   = !string.IsNullOrWhiteSpace(settings.HomeNavigationMessage) ? settings.HomeNavigationMessage : text.Get(TextKey.PasswordDialog_BrowserHomePasswordRequiredTitle);
                    var dialog  = uiFactory.CreatePasswordDialog(message, title);
                    var result  = dialog.Show(window);

                    if (result.Success)
                    {
                        var passwordHash = hashAlgorithm.GenerateHashFor(result.Password);

                        if (settings.HomePasswordHash.Equals(passwordHash, StringComparison.OrdinalIgnoreCase))
                        {
                            navigate = true;
                        }
                        else
                        {
                            messageBox.Show(TextKey.MessageBox_InvalidHomePassword, TextKey.MessageBox_InvalidHomePasswordTitle, icon: MessageBoxIcon.Warning, parent: window);
                        }
                    }
                }
                else
                {
                    var message = text.Get(TextKey.MessageBox_BrowserHomeQuestion);
                    var title   = !string.IsNullOrWhiteSpace(settings.HomeNavigationMessage) ? settings.HomeNavigationMessage : text.Get(TextKey.MessageBox_BrowserHomeQuestionTitle);
                    var result  = messageBox.Show(message, title, MessageBoxAction.YesNo, MessageBoxIcon.Question, window);

                    navigate = result == MessageBoxResult.Yes;
                }

                if (navigate)
                {
                    control.NavigateTo(url);
                }
            }
        }