Update Safe Exam Browser Patch to 3.10.0.826
This commit is contained in:
@@ -40,6 +40,20 @@ namespace SafeExamBrowser.Client.Responsibilities
|
||||
}
|
||||
}
|
||||
|
||||
protected bool IsValidQuitPassword(string password)
|
||||
{
|
||||
var actual = Context.HashAlgorithm.GenerateHashFor(password);
|
||||
var expected = Settings.Security.QuitPasswordHash;
|
||||
var valid = expected.Equals(actual, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (valid)
|
||||
{
|
||||
Context.QuitPasswordValidated = true;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
protected void PrepareShutdown()
|
||||
{
|
||||
Context.Responsibilities.Delegate(ClientTask.PrepareShutdown_Wave1);
|
||||
@@ -56,72 +70,30 @@ namespace SafeExamBrowser.Client.Responsibilities
|
||||
|
||||
protected LockScreenResult ShowLockScreen(string message, string title, IEnumerable<LockScreenOption> options)
|
||||
{
|
||||
var hasQuitPassword = !string.IsNullOrEmpty(Settings.Security.QuitPasswordHash);
|
||||
var result = default(LockScreenResult);
|
||||
|
||||
Context.LockScreen = Context.UserInterfaceFactory.CreateLockScreen(message, title, options, Settings.UserInterface.LockScreen);
|
||||
Logger.Info("Showing lock screen...");
|
||||
|
||||
PauseActivators();
|
||||
Context.LockScreen = Context.UserInterfaceFactory.CreateLockScreen(message, title, options, Settings.UserInterface.LockScreen);
|
||||
Context.LockScreen.Show();
|
||||
|
||||
if (Settings.SessionMode == SessionMode.Server)
|
||||
{
|
||||
var response = Context.Server.LockScreen(message);
|
||||
|
||||
if (!response.Success)
|
||||
{
|
||||
Logger.Error($"Failed to send lock screen notification to server! Message: {response.Message}.");
|
||||
}
|
||||
SendLockScreenNotification(message);
|
||||
}
|
||||
|
||||
for (var unlocked = false; !unlocked;)
|
||||
{
|
||||
result = Context.LockScreen.WaitForResult();
|
||||
|
||||
if (result.Canceled)
|
||||
{
|
||||
Logger.Info("The lock screen has been automaticaly canceled.");
|
||||
unlocked = true;
|
||||
}
|
||||
else if (hasQuitPassword)
|
||||
{
|
||||
var passwordHash = Context.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.");
|
||||
Context.MessageBox.Show(TextKey.MessageBox_InvalidUnlockPassword, TextKey.MessageBox_InvalidUnlockPasswordTitle, icon: MessageBoxIcon.Warning, parent: Context.LockScreen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Warn($"No unlock password is defined, allowing user to resume session!");
|
||||
unlocked = true;
|
||||
}
|
||||
}
|
||||
var result = WaitForLockScreenResolution();
|
||||
|
||||
Context.LockScreen.Close();
|
||||
Context.LockScreen = default;
|
||||
ResumeActivators();
|
||||
|
||||
Logger.Info("Closed lock screen.");
|
||||
|
||||
if (Settings.SessionMode == SessionMode.Server)
|
||||
{
|
||||
var response = Context.Server.ConfirmLockScreen();
|
||||
|
||||
if (!response.Success)
|
||||
{
|
||||
Logger.Error($"Failed to send lock screen confirm notification to server! Message: {response.Message}.");
|
||||
}
|
||||
SendLockScreenConfirmation();
|
||||
}
|
||||
|
||||
Logger.Info("Closed lock screen.");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -139,5 +111,65 @@ namespace SafeExamBrowser.Client.Responsibilities
|
||||
|
||||
return communication.Success;
|
||||
}
|
||||
|
||||
private void SendLockScreenConfirmation()
|
||||
{
|
||||
var response = Context.Server.ConfirmLockScreen();
|
||||
|
||||
if (!response.Success)
|
||||
{
|
||||
Logger.Error($"Failed to send lock screen confirmation to server! Message: {response.Message}.");
|
||||
}
|
||||
}
|
||||
|
||||
private void SendLockScreenNotification(string message)
|
||||
{
|
||||
var response = Context.Server.LockScreen(message);
|
||||
|
||||
if (!response.Success)
|
||||
{
|
||||
Logger.Error($"Failed to send lock screen notification to server! Message: {response.Message}.");
|
||||
}
|
||||
}
|
||||
|
||||
private LockScreenResult WaitForLockScreenResolution()
|
||||
{
|
||||
var hasQuitPassword = !string.IsNullOrEmpty(Settings.Security.QuitPasswordHash);
|
||||
var result = default(LockScreenResult);
|
||||
|
||||
for (var unlocked = false; !unlocked;)
|
||||
{
|
||||
result = Context.LockScreen.WaitForResult();
|
||||
|
||||
if (result.Canceled)
|
||||
{
|
||||
Logger.Info("The lock screen has been canceled automatically.");
|
||||
unlocked = true;
|
||||
}
|
||||
else if (hasQuitPassword)
|
||||
{
|
||||
var passwordHash = Context.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 a wrong unlock password.");
|
||||
Context.MessageBox.Show(TextKey.MessageBox_InvalidUnlockPassword, TextKey.MessageBox_InvalidUnlockPasswordTitle, icon: MessageBoxIcon.Warning, parent: Context.LockScreen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Warn($"No unlock password is defined, allowing user to resume session!");
|
||||
unlocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Win32;
|
||||
using SafeExamBrowser.Client.Contracts;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
@@ -251,23 +252,29 @@ namespace SafeExamBrowser.Client.Responsibilities
|
||||
}
|
||||
}
|
||||
|
||||
private void Sentinel_SessionChanged()
|
||||
private void Sentinel_SessionChanged(SessionSwitchReason reason)
|
||||
{
|
||||
var allow = !Settings.Service.IgnoreService && (!Settings.Service.DisableUserLock || !Settings.Service.DisableUserSwitch);
|
||||
var disable = Settings.Security.DisableSessionChangeLockScreen;
|
||||
|
||||
if (allow || disable)
|
||||
var allowed = !Settings.Service.IgnoreService && (!Settings.Service.DisableUserLock || !Settings.Service.DisableUserSwitch);
|
||||
var disabled = Settings.Security.DisableSessionChangeLockScreen;
|
||||
var ignore = Settings.Service.IgnoreService && (reason == SessionSwitchReason.SessionLock || reason == SessionSwitchReason.SessionUnlock);
|
||||
|
||||
if (allowed || disabled)
|
||||
{
|
||||
Logger.Info($"Detected user session change, but {(allow ? "session locking and/or switching is allowed" : "lock screen is deactivated")}.");
|
||||
Logger.Info($"Detected user session change ({reason}), but {(allowed ? "session locking and/or switching is allowed" : "lock screen is disabled")}.");
|
||||
}
|
||||
else if (ignore)
|
||||
{
|
||||
Logger.Info($"Ignoring user session change ({reason}).");
|
||||
}
|
||||
else
|
||||
{
|
||||
var message = text.Get(TextKey.LockScreen_UserSessionMessage);
|
||||
var message = text.Get(Settings.Service.IgnoreService ? TextKey.LockScreen_UserSwitchMessage : TextKey.LockScreen_UserSessionMessage);
|
||||
var title = text.Get(TextKey.LockScreen_Title);
|
||||
var continueOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_UserSessionContinueOption) };
|
||||
var terminateOption = new LockScreenOption { Text = text.Get(TextKey.LockScreen_UserSessionTerminateOption) };
|
||||
|
||||
Logger.Warn("User session changed! Attempting to show lock screen...");
|
||||
Logger.Warn($"User session changed ({reason})! Attempting to show lock screen...");
|
||||
|
||||
if (coordinator.RequestSessionLock())
|
||||
{
|
||||
|
@@ -7,21 +7,33 @@
|
||||
*/
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Proctoring.Contracts;
|
||||
using SafeExamBrowser.Proctoring.Contracts.Events;
|
||||
using SafeExamBrowser.UserInterface.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Proctoring;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Proctoring.Events;
|
||||
|
||||
namespace SafeExamBrowser.Client.Responsibilities
|
||||
{
|
||||
internal class ProctoringResponsibility : ClientResponsibility
|
||||
{
|
||||
private readonly IMessageBox messageBox;
|
||||
private readonly IUserInterfaceFactory uiFactory;
|
||||
|
||||
private bool cancel;
|
||||
|
||||
private IProctoringController Proctoring => Context.Proctoring;
|
||||
|
||||
public ProctoringResponsibility(ClientContext context, ILogger logger, IUserInterfaceFactory uiFactory) : base(context, logger)
|
||||
public ProctoringResponsibility(
|
||||
ClientContext context,
|
||||
ILogger logger,
|
||||
IMessageBox messageBox,
|
||||
IUserInterfaceFactory uiFactory) : base(context, logger)
|
||||
{
|
||||
this.messageBox = messageBox;
|
||||
this.uiFactory = uiFactory;
|
||||
}
|
||||
|
||||
@@ -37,8 +49,10 @@ namespace SafeExamBrowser.Client.Responsibilities
|
||||
{
|
||||
if (Proctoring != default && Proctoring.HasRemainingWork())
|
||||
{
|
||||
var dialog = uiFactory.CreateProctoringFinalizationDialog();
|
||||
var handler = new RemainingWorkUpdatedEventHandler((args) => dialog.Update(args));
|
||||
var dialog = uiFactory.CreateProctoringFinalizationDialog(!Context.QuitPasswordValidated);
|
||||
var handler = new RemainingWorkUpdatedEventHandler((args) => Proctoring_RemainingWorkUpdated(dialog, args));
|
||||
|
||||
dialog.CancellationRequested += new CancellationRequestedEventHandler(() => Dialog_CancellationRequested(dialog));
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
@@ -50,5 +64,28 @@ namespace SafeExamBrowser.Client.Responsibilities
|
||||
dialog.Show();
|
||||
}
|
||||
}
|
||||
|
||||
private void Dialog_CancellationRequested(IProctoringFinalizationDialog dialog)
|
||||
{
|
||||
var alreadyValidated = Context.QuitPasswordValidated;
|
||||
|
||||
if (alreadyValidated || IsValidQuitPassword(dialog.QuitPassword))
|
||||
{
|
||||
cancel = true;
|
||||
Logger.Info($"The user {(alreadyValidated ? "already " : "")}entered the correct quit password, cancelling remaining work...");
|
||||
}
|
||||
else
|
||||
{
|
||||
cancel = false;
|
||||
Logger.Info("The user entered the wrong quit password, remaining work will continue.");
|
||||
messageBox.Show(TextKey.MessageBox_InvalidQuitPassword, TextKey.MessageBox_InvalidQuitPasswordTitle, icon: MessageBoxIcon.Warning, parent: dialog);
|
||||
}
|
||||
}
|
||||
|
||||
private void Proctoring_RemainingWorkUpdated(IProctoringFinalizationDialog dialog, RemainingWorkUpdatedEventArgs args)
|
||||
{
|
||||
dialog.Update(args);
|
||||
args.CancellationRequested = cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using SafeExamBrowser.Configuration.Contracts.Cryptography;
|
||||
@@ -134,14 +133,14 @@ namespace SafeExamBrowser.Client.Responsibilities
|
||||
{
|
||||
var hasQuitPassword = !string.IsNullOrEmpty(Settings.Security.QuitPasswordHash);
|
||||
var initiateShutdown = hasQuitPassword ? TryValidateQuitPassword() : TryConfirmShutdown();
|
||||
var succes = false;
|
||||
var success = false;
|
||||
|
||||
if (initiateShutdown)
|
||||
{
|
||||
succes = TryRequestShutdown();
|
||||
success = TryRequestShutdown();
|
||||
}
|
||||
|
||||
return succes;
|
||||
return success;
|
||||
}
|
||||
|
||||
private bool TryConfirmShutdown()
|
||||
@@ -161,26 +160,20 @@ namespace SafeExamBrowser.Client.Responsibilities
|
||||
{
|
||||
var dialog = uiFactory.CreatePasswordDialog(TextKey.PasswordDialog_QuitPasswordRequired, TextKey.PasswordDialog_QuitPasswordRequiredTitle);
|
||||
var result = dialog.Show();
|
||||
var success = false;
|
||||
|
||||
if (result.Success)
|
||||
if (result.Success && IsValidQuitPassword(result.Password))
|
||||
{
|
||||
var passwordHash = hashAlgorithm.GenerateHashFor(result.Password);
|
||||
var isCorrect = Settings.Security.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;
|
||||
success = true;
|
||||
Logger.Info("The user entered the correct quit password, the application will now terminate.");
|
||||
}
|
||||
else if (result.Success)
|
||||
{
|
||||
Logger.Info("The user entered the wrong quit password.");
|
||||
messageBox.Show(TextKey.MessageBox_InvalidQuitPassword, TextKey.MessageBox_InvalidQuitPasswordTitle, icon: MessageBoxIcon.Warning);
|
||||
}
|
||||
|
||||
return false;
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user