From f778d5b848d7c43eff49386c98a3903d327ec143 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 30 Oct 2019 11:08:42 +0100 Subject: [PATCH] SEBWIN-312: Implemented mapping for configuration values of whitelisted applications. --- .../DataMapper.Applications.cs | 91 +++++++++++++++++-- .../ConfigurationData/Keys.cs | 20 +++- .../Applications/ApplicationMonitor.cs | 2 +- .../Applications/BlacklistApplication.cs | 2 +- .../Applications/WhitelistApplication.cs | 62 +++++++++++++ 5 files changed, 161 insertions(+), 16 deletions(-) diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Applications.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Applications.cs index 0c45fd62..25ea5fc3 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Applications.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Applications.cs @@ -22,26 +22,26 @@ namespace SafeExamBrowser.Configuration.ConfigurationData { if (item is IDictionary applicationData) { - var isActive = applicationData.TryGetValue(Keys.Applications.ApplicationActive, out var v) && v is bool active && active; - var isWindowsProcess = applicationData.TryGetValue(Keys.Applications.ApplicationOs, out v) && v is int os && os == Keys.WINDOWS; + var isActive = applicationData.TryGetValue(Keys.Applications.Active, out var v) && v is bool active && active; + var isWindowsProcess = applicationData.TryGetValue(Keys.Applications.OperatingSystem, out v) && v is int os && os == Keys.WINDOWS; if (isActive && isWindowsProcess) { var application = new BlacklistApplication(); - if (applicationData.TryGetValue(Keys.Applications.ApplicationAutoTerminate, out v) && v is bool autoTerminate) + if (applicationData.TryGetValue(Keys.Applications.AutoTerminate, out v) && v is bool autoTerminate) { application.AutoTerminate = autoTerminate; } - if (applicationData.TryGetValue(Keys.Applications.ApplicationExecutable, out v) && v is string executableName) + if (applicationData.TryGetValue(Keys.Applications.ExecutableName, out v) && v is string executableName) { application.ExecutableName = executableName; } - if (applicationData.TryGetValue(Keys.Applications.ApplicationOriginalName, out v) && v is string originalName) + if (applicationData.TryGetValue(Keys.Applications.OriginalName, out v) && v is string originalName) { - application.ExecutableOriginalName = originalName; + application.OriginalName = originalName; } settings.Applications.Blacklist.Add(application); @@ -57,14 +57,87 @@ namespace SafeExamBrowser.Configuration.ConfigurationData { foreach (var item in applications) { - if (item is IDictionary application) + if (item is IDictionary applicationData) { - var isActive = application.TryGetValue(Keys.Applications.ApplicationActive, out var v) && v is bool active && active; - var isWindowsProcess = application.TryGetValue(Keys.Applications.ApplicationOs, out v) && v is int os && os == Keys.WINDOWS; + var isActive = applicationData.TryGetValue(Keys.Applications.Active, out var v) && v is bool active && active; + var isWindowsProcess = applicationData.TryGetValue(Keys.Applications.OperatingSystem, out v) && v is int os && os == Keys.WINDOWS; if (isActive && isWindowsProcess) { + var application = new WhitelistApplication(); + if (applicationData.TryGetValue(Keys.Applications.AllowCustomPath, out v) && v is bool allowCustomPath) + { + application.AllowCustomPath = allowCustomPath; + } + + if (applicationData.TryGetValue(Keys.Applications.AllowRunning, out v) && v is bool allowRunning) + { + application.AllowRunning = allowRunning; + } + + if (applicationData.TryGetValue(Keys.Applications.Arguments, out v) && v is IList arguments) + { + foreach (var argumentItem in arguments) + { + if (argumentItem is IDictionary argumentData) + { + var argActive = argumentData.TryGetValue(Keys.Applications.Active, out v) && v is bool a && a; + + if (argActive && argumentData.TryGetValue(Keys.Applications.Argument, out v) && v is string argument) + { + application.Arguments.Add(argument); + } + } + } + } + + if (applicationData.TryGetValue(Keys.Applications.AutoStart, out v) && v is bool autoStart) + { + application.AutoStart = autoStart; + } + + if (applicationData.TryGetValue(Keys.Applications.AutoTerminate, out v) && v is bool autoTerminate) + { + application.AutoTerminate = autoTerminate; + } + + if (applicationData.TryGetValue(Keys.Applications.DisplayName, out v) && v is string displayName) + { + application.DisplayName = displayName; + } + + if (applicationData.TryGetValue(Keys.Applications.ExecutableName, out v) && v is string executableName) + { + application.ExecutableName = executableName; + } + + if (applicationData.TryGetValue(Keys.Applications.ExecutablePath, out v) && v is string executablePath) + { + application.ExecutablePath = executablePath; + } + + if (applicationData.TryGetValue(Keys.Applications.Identifier, out v) && v is string identifier) + { + application.Identifier = identifier; + } + + if (applicationData.TryGetValue(Keys.Applications.OriginalName, out v) && v is string originalName) + { + application.OriginalName = originalName; + } + + if (applicationData.TryGetValue(Keys.Applications.RendererName, out v) && v is string rendererName) + { + application.RendererName = rendererName; + } + + if (applicationData.TryGetValue(Keys.Applications.ShowInShell, out v) && v is bool showInShell) + { + application.ShowInShell = showInShell; + } + + settings.Applications.Whitelist.Add(application); } } } diff --git a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs index f114624b..8a4643cb 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs @@ -18,12 +18,22 @@ namespace SafeExamBrowser.Configuration.ConfigurationData internal static class Applications { - internal const string ApplicationActive = "active"; - internal const string ApplicationAutoTerminate = "strongKill"; - internal const string ApplicationExecutable = "executable"; - internal const string ApplicationOriginalName = "originalName"; - internal const string ApplicationOs = "os"; + internal const string Active = "active"; + internal const string AllowCustomPath = "allowUserToChooseApp"; + internal const string AllowRunning = "runInBackground"; + internal const string Argument = "argument"; + internal const string Arguments = "arguments"; + internal const string AutoStart = "autostart"; + internal const string AutoTerminate = "strongKill"; internal const string Blacklist = "prohibitedProcesses"; + internal const string DisplayName = "title"; + internal const string ExecutableName = "executable"; + internal const string ExecutablePath = "path"; + internal const string Identifier = "identifier"; + internal const string OperatingSystem = "os"; + internal const string OriginalName = "originalName"; + internal const string RendererName = "windowHandlingProcess"; + internal const string ShowInShell = "iconInTaskbar"; internal const string Whitelist = "permittedProcesses"; } diff --git a/SafeExamBrowser.Monitoring/Applications/ApplicationMonitor.cs b/SafeExamBrowser.Monitoring/Applications/ApplicationMonitor.cs index 4365c796..efe07c5b 100644 --- a/SafeExamBrowser.Monitoring/Applications/ApplicationMonitor.cs +++ b/SafeExamBrowser.Monitoring/Applications/ApplicationMonitor.cs @@ -234,7 +234,7 @@ namespace SafeExamBrowser.Monitoring.Applications private bool BelongsToApplication(IProcess process, BlacklistApplication application) { var sameName = process.Name.Equals(application.ExecutableName, StringComparison.OrdinalIgnoreCase); - var sameOriginalName = process.OriginalName?.Equals(application.ExecutableOriginalName, StringComparison.OrdinalIgnoreCase) == true; + var sameOriginalName = process.OriginalName?.Equals(application.OriginalName, StringComparison.OrdinalIgnoreCase) == true; return sameName || sameOriginalName; } diff --git a/SafeExamBrowser.Settings/Applications/BlacklistApplication.cs b/SafeExamBrowser.Settings/Applications/BlacklistApplication.cs index 1993c6a7..409d4cce 100644 --- a/SafeExamBrowser.Settings/Applications/BlacklistApplication.cs +++ b/SafeExamBrowser.Settings/Applications/BlacklistApplication.cs @@ -29,6 +29,6 @@ namespace SafeExamBrowser.Settings.Applications /// /// The original file name of the main executable of the application, if available. /// - public string ExecutableOriginalName { get; set; } + public string OriginalName { get; set; } } } diff --git a/SafeExamBrowser.Settings/Applications/WhitelistApplication.cs b/SafeExamBrowser.Settings/Applications/WhitelistApplication.cs index 3a0d2fef..4d162450 100644 --- a/SafeExamBrowser.Settings/Applications/WhitelistApplication.cs +++ b/SafeExamBrowser.Settings/Applications/WhitelistApplication.cs @@ -7,6 +7,7 @@ */ using System; +using System.Collections.Generic; namespace SafeExamBrowser.Settings.Applications { @@ -16,9 +17,70 @@ namespace SafeExamBrowser.Settings.Applications [Serializable] public class WhitelistApplication { + /// + /// Determines whether the user may choose a custom path if the main executable cannot be found under . + /// + public bool AllowCustomPath { get; set; } + + /// + /// Determines whether the application may already be running when initializing a session. If true, will be ignored. + /// + public bool AllowRunning { get; set; } + + /// + /// The list of arguments to be used when starting the application. + /// + public IList Arguments { get; } + + /// + /// Determines whether the application will be automatically started when initializing a session. + /// + public bool AutoStart { get; set; } + + /// + /// Specifies whether the application may be automatically terminated when starting a session. Is ignored if is set. + /// + public bool AutoTerminate { get; set; } + + /// + /// The display name to be used for the application (e.g. in the shell). + /// + public string DisplayName { get; set; } + /// /// The name of the main executable of the application. /// public string ExecutableName { get; set; } + + /// + /// The path where the main executable of the application is located. + /// + public string ExecutablePath { get; set; } + + /// + /// Used to identify an application by its main window title. + /// + /// TODO: Rename? + public string Identifier { get; set; } + + /// + /// The original file name of the main executable of the application, if available. + /// + public string OriginalName { get; set; } + + /// + /// The name of the executable responsible for rendering the user interface. + /// + public string RendererName { get; set; } + + /// + /// Determines whether the user will be able to access the application via the shell. + /// + public bool ShowInShell { get; set; } + + public WhitelistApplication() + { + Arguments = new List(); + } } }