SEBWIN-312: Implemented mapping for configuration values of whitelisted applications.

This commit is contained in:
dbuechel 2019-10-30 11:08:42 +01:00
parent cf28a7f172
commit f778d5b848
5 changed files with 161 additions and 16 deletions

View file

@ -22,26 +22,26 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
{
if (item is IDictionary<string, object> 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<string, object> application)
if (item is IDictionary<string, object> 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<object> arguments)
{
foreach (var argumentItem in arguments)
{
if (argumentItem is IDictionary<string, object> 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);
}
}
}

View file

@ -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";
}

View file

@ -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;
}

View file

@ -29,6 +29,6 @@ namespace SafeExamBrowser.Settings.Applications
/// <summary>
/// The original file name of the main executable of the application, if available.
/// </summary>
public string ExecutableOriginalName { get; set; }
public string OriginalName { get; set; }
}
}

View file

@ -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
{
/// <summary>
/// Determines whether the user may choose a custom path if the main executable cannot be found under <see cref="ExecutablePath"/>.
/// </summary>
public bool AllowCustomPath { get; set; }
/// <summary>
/// Determines whether the application may already be running when initializing a session. If <c>true</c>, <see cref="AutoTerminate"/> will be ignored.
/// </summary>
public bool AllowRunning { get; set; }
/// <summary>
/// The list of arguments to be used when starting the application.
/// </summary>
public IList<string> Arguments { get; }
/// <summary>
/// Determines whether the application will be automatically started when initializing a session.
/// </summary>
public bool AutoStart { get; set; }
/// <summary>
/// Specifies whether the application may be automatically terminated when starting a session. Is ignored if <see cref="AllowRunning"/> is set.
/// </summary>
public bool AutoTerminate { get; set; }
/// <summary>
/// The display name to be used for the application (e.g. in the shell).
/// </summary>
public string DisplayName { get; set; }
/// <summary>
/// The name of the main executable of the application.
/// </summary>
public string ExecutableName { get; set; }
/// <summary>
/// The path where the main executable of the application is located.
/// </summary>
public string ExecutablePath { get; set; }
/// <summary>
/// Used to identify an application by its main window title.
/// </summary>
/// TODO: Rename?
public string Identifier { get; set; }
/// <summary>
/// The original file name of the main executable of the application, if available.
/// </summary>
public string OriginalName { get; set; }
/// <summary>
/// The name of the executable responsible for rendering the user interface.
/// </summary>
public string RendererName { get; set; }
/// <summary>
/// Determines whether the user will be able to access the application via the shell.
/// </summary>
public bool ShowInShell { get; set; }
public WhitelistApplication()
{
Arguments = new List<string>();
}
}
}