2017-07-05 11:41:19 +02:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2017-07-28 14:52:15 +02:00
|
|
|
|
*
|
2017-07-05 11:41:19 +02:00
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-01-17 14:08:39 +01:00
|
|
|
|
using System;
|
2017-07-21 12:05:31 +02:00
|
|
|
|
using System.Collections.Generic;
|
2019-12-20 17:06:28 +01:00
|
|
|
|
using SafeExamBrowser.Communication.Contracts;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Communication.Hosts;
|
|
|
|
|
using SafeExamBrowser.Communication.Proxies;
|
2017-07-20 14:16:47 +02:00
|
|
|
|
using SafeExamBrowser.Configuration;
|
2019-12-20 17:06:28 +01:00
|
|
|
|
using SafeExamBrowser.Configuration.Contracts;
|
2018-12-14 09:50:10 +01:00
|
|
|
|
using SafeExamBrowser.Configuration.Cryptography;
|
|
|
|
|
using SafeExamBrowser.Configuration.DataCompression;
|
2018-11-08 09:39:52 +01:00
|
|
|
|
using SafeExamBrowser.Configuration.DataFormats;
|
2018-12-14 09:50:10 +01:00
|
|
|
|
using SafeExamBrowser.Configuration.DataResources;
|
2022-07-18 21:37:04 +02:00
|
|
|
|
using SafeExamBrowser.Configuration.Integrity;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Core.Contracts.OperationModel;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Core.OperationModel;
|
|
|
|
|
using SafeExamBrowser.Core.Operations;
|
|
|
|
|
using SafeExamBrowser.I18n;
|
2019-12-20 17:06:28 +01:00
|
|
|
|
using SafeExamBrowser.I18n.Contracts;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Logging;
|
2019-12-20 17:06:28 +01:00
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2021-05-30 20:04:44 +02:00
|
|
|
|
using SafeExamBrowser.Monitoring.Display;
|
2024-07-24 20:31:08 +02:00
|
|
|
|
using SafeExamBrowser.Monitoring.System;
|
2018-02-06 15:12:11 +01:00
|
|
|
|
using SafeExamBrowser.Runtime.Communication;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Runtime.Operations;
|
2020-07-13 22:57:19 +02:00
|
|
|
|
using SafeExamBrowser.Server;
|
2019-12-20 17:06:28 +01:00
|
|
|
|
using SafeExamBrowser.Settings.Logging;
|
2019-01-23 15:57:49 +01:00
|
|
|
|
using SafeExamBrowser.SystemComponents;
|
2019-12-20 17:06:28 +01:00
|
|
|
|
using SafeExamBrowser.SystemComponents.Contracts;
|
2022-12-21 05:37:03 +01:00
|
|
|
|
using SafeExamBrowser.SystemComponents.Registry;
|
2019-01-11 15:32:47 +01:00
|
|
|
|
using SafeExamBrowser.UserInterface.Desktop;
|
2017-07-27 11:46:31 +02:00
|
|
|
|
using SafeExamBrowser.WindowsApi;
|
2023-10-04 14:48:08 +02:00
|
|
|
|
using SafeExamBrowser.WindowsApi.Desktops;
|
|
|
|
|
using SafeExamBrowser.WindowsApi.Processes;
|
2017-07-05 17:21:52 +02:00
|
|
|
|
|
2018-01-18 08:16:20 +01:00
|
|
|
|
namespace SafeExamBrowser.Runtime
|
2017-07-05 11:41:19 +02:00
|
|
|
|
{
|
2017-07-07 15:46:32 +02:00
|
|
|
|
internal class CompositionRoot
|
2017-07-05 11:41:19 +02:00
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
private AppConfig appConfig;
|
2018-11-08 09:39:52 +01:00
|
|
|
|
private IConfigurationRepository configuration;
|
2018-01-23 15:33:54 +01:00
|
|
|
|
private ILogger logger;
|
|
|
|
|
private ISystemInfo systemInfo;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
private IText text;
|
2018-01-23 15:33:54 +01:00
|
|
|
|
|
2020-03-16 13:38:25 +01:00
|
|
|
|
internal RuntimeController RuntimeController { get; private set; }
|
2017-07-13 08:51:00 +02:00
|
|
|
|
|
2018-02-21 14:01:21 +01:00
|
|
|
|
internal void BuildObjectGraph(Action shutdown)
|
2017-07-06 10:56:03 +02:00
|
|
|
|
{
|
2018-10-02 08:02:48 +02:00
|
|
|
|
const int FIVE_SECONDS = 5000;
|
2019-03-28 09:05:18 +01:00
|
|
|
|
const int THIRTY_SECONDS = 30000;
|
2018-03-21 15:28:59 +01:00
|
|
|
|
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger = new Logger();
|
2017-07-06 10:56:03 +02:00
|
|
|
|
|
2018-11-08 09:39:52 +01:00
|
|
|
|
InitializeConfiguration();
|
2018-01-19 14:04:12 +01:00
|
|
|
|
InitializeLogging();
|
2018-08-31 10:06:27 +02:00
|
|
|
|
InitializeText();
|
2017-07-31 20:22:53 +02:00
|
|
|
|
|
2020-03-09 17:35:48 +01:00
|
|
|
|
var nativeMethods = new NativeMethods();
|
2023-09-01 12:28:03 +02:00
|
|
|
|
var registry = new Registry(ModuleLogger(nameof(Registry)));
|
2020-02-14 15:04:33 +01:00
|
|
|
|
var uiFactory = new UserInterfaceFactory(text);
|
2022-01-14 13:33:35 +01:00
|
|
|
|
var userInfo = new UserInfo(ModuleLogger(nameof(UserInfo)));
|
|
|
|
|
|
2023-09-01 12:28:03 +02:00
|
|
|
|
systemInfo = new SystemInfo(registry);
|
|
|
|
|
|
2022-01-14 13:33:35 +01:00
|
|
|
|
var args = Environment.GetCommandLineArgs();
|
2022-11-24 14:50:25 +01:00
|
|
|
|
var integrityModule = new IntegrityModule(appConfig, ModuleLogger(nameof(IntegrityModule)));
|
2019-02-19 15:54:11 +01:00
|
|
|
|
var desktopFactory = new DesktopFactory(ModuleLogger(nameof(DesktopFactory)));
|
2021-04-16 19:12:56 +02:00
|
|
|
|
var desktopMonitor = new DesktopMonitor(ModuleLogger(nameof(DesktopMonitor)));
|
2021-05-30 20:04:44 +02:00
|
|
|
|
var displayMonitor = new DisplayMonitor(ModuleLogger(nameof(DisplayMonitor)), nativeMethods, systemInfo);
|
2019-02-19 15:54:11 +01:00
|
|
|
|
var explorerShell = new ExplorerShell(ModuleLogger(nameof(ExplorerShell)), nativeMethods);
|
2020-07-27 15:58:30 +02:00
|
|
|
|
var fileSystem = new FileSystem();
|
2023-03-02 23:48:11 +01:00
|
|
|
|
var keyGenerator = new KeyGenerator(appConfig, integrityModule, ModuleLogger(nameof(KeyGenerator)));
|
2022-01-14 13:33:35 +01:00
|
|
|
|
var messageBox = new MessageBoxFactory(text);
|
2019-02-19 15:54:11 +01:00
|
|
|
|
var processFactory = new ProcessFactory(ModuleLogger(nameof(ProcessFactory)));
|
2019-06-18 10:18:56 +02:00
|
|
|
|
var proxyFactory = new ProxyFactory(new ProxyObjectFactory(), ModuleLogger(nameof(ProxyFactory)));
|
2020-12-04 15:21:51 +01:00
|
|
|
|
var remoteSessionDetector = new RemoteSessionDetector(ModuleLogger(nameof(RemoteSessionDetector)));
|
2019-02-19 15:54:11 +01:00
|
|
|
|
var runtimeHost = new RuntimeHost(appConfig.RuntimeAddress, new HostObjectFactory(), ModuleLogger(nameof(RuntimeHost)), FIVE_SECONDS);
|
2020-02-14 15:04:33 +01:00
|
|
|
|
var runtimeWindow = uiFactory.CreateRuntimeWindow(appConfig);
|
2024-07-24 20:31:08 +02:00
|
|
|
|
var sentinel = new SystemSentinel(ModuleLogger(nameof(SystemSentinel)), nativeMethods, registry);
|
2023-03-02 23:48:11 +01:00
|
|
|
|
var server = new ServerProxy(appConfig, keyGenerator, ModuleLogger(nameof(ServerProxy)), systemInfo, userInfo);
|
2019-06-18 10:18:56 +02:00
|
|
|
|
var serviceProxy = new ServiceProxy(appConfig.ServiceAddress, new ProxyObjectFactory(), ModuleLogger(nameof(ServiceProxy)), Interlocutor.Runtime);
|
2018-10-12 11:16:59 +02:00
|
|
|
|
var sessionContext = new SessionContext();
|
2020-02-14 15:04:33 +01:00
|
|
|
|
var splashScreen = uiFactory.CreateSplashScreen(appConfig);
|
2023-07-17 16:40:33 +02:00
|
|
|
|
var vmDetector = new VirtualMachineDetector(ModuleLogger(nameof(VirtualMachineDetector)), registry, systemInfo);
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-02-08 13:32:48 +01:00
|
|
|
|
var bootstrapOperations = new Queue<IOperation>();
|
2018-10-10 09:19:03 +02:00
|
|
|
|
var sessionOperations = new Queue<IRepeatableOperation>();
|
2018-02-08 13:32:48 +01:00
|
|
|
|
|
2020-03-09 17:35:48 +01:00
|
|
|
|
bootstrapOperations.Enqueue(new I18nOperation(logger, text));
|
2018-09-28 11:05:49 +02:00
|
|
|
|
bootstrapOperations.Enqueue(new CommunicationHostOperation(runtimeHost, logger));
|
2022-12-21 05:37:03 +01:00
|
|
|
|
bootstrapOperations.Enqueue(new ApplicationIntegrityOperation(integrityModule, logger));
|
2017-07-21 12:05:31 +02:00
|
|
|
|
|
2020-08-27 20:10:15 +02:00
|
|
|
|
sessionOperations.Enqueue(new SessionInitializationOperation(configuration, fileSystem, logger, runtimeHost, sessionContext));
|
2020-01-29 10:07:28 +01:00
|
|
|
|
sessionOperations.Enqueue(new ConfigurationOperation(args, configuration, new FileSystem(), new HashAlgorithm(), logger, sessionContext));
|
2020-07-27 15:58:30 +02:00
|
|
|
|
sessionOperations.Enqueue(new ServerOperation(args, configuration, fileSystem, logger, sessionContext, server));
|
2023-07-03 15:25:31 +02:00
|
|
|
|
sessionOperations.Enqueue(new VersionRestrictionOperation(logger, sessionContext, text));
|
2021-06-24 12:08:15 +02:00
|
|
|
|
sessionOperations.Enqueue(new DisclaimerOperation(logger, sessionContext));
|
2020-12-04 15:21:51 +01:00
|
|
|
|
sessionOperations.Enqueue(new RemoteSessionOperation(remoteSessionDetector, logger, sessionContext));
|
2024-07-24 20:31:08 +02:00
|
|
|
|
sessionOperations.Enqueue(new SessionIntegrityOperation(logger, sentinel, sessionContext));
|
2020-01-06 15:11:57 +01:00
|
|
|
|
sessionOperations.Enqueue(new VirtualMachineOperation(vmDetector, logger, sessionContext));
|
2021-06-29 17:34:05 +02:00
|
|
|
|
sessionOperations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, sessionContext, text));
|
2019-07-04 09:12:28 +02:00
|
|
|
|
sessionOperations.Enqueue(new ServiceOperation(logger, runtimeHost, serviceProxy, sessionContext, THIRTY_SECONDS, userInfo));
|
2019-06-12 08:46:10 +02:00
|
|
|
|
sessionOperations.Enqueue(new ClientTerminationOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, THIRTY_SECONDS));
|
2021-04-16 19:12:56 +02:00
|
|
|
|
sessionOperations.Enqueue(new KioskModeOperation(desktopFactory, desktopMonitor, explorerShell, logger, processFactory, sessionContext));
|
2019-03-29 16:02:05 +01:00
|
|
|
|
sessionOperations.Enqueue(new ClientOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, THIRTY_SECONDS));
|
2018-10-12 11:16:59 +02:00
|
|
|
|
sessionOperations.Enqueue(new SessionActivationOperation(logger, sessionContext));
|
2018-02-02 09:18:35 +01:00
|
|
|
|
|
2018-03-21 10:23:15 +01:00
|
|
|
|
var bootstrapSequence = new OperationSequence(logger, bootstrapOperations);
|
2018-10-10 09:19:03 +02:00
|
|
|
|
var sessionSequence = new RepeatableOperationSequence(logger, sessionOperations);
|
2018-02-02 09:18:35 +01:00
|
|
|
|
|
2019-03-06 16:10:00 +01:00
|
|
|
|
RuntimeController = new RuntimeController(
|
|
|
|
|
appConfig,
|
|
|
|
|
logger,
|
|
|
|
|
messageBox,
|
|
|
|
|
bootstrapSequence,
|
|
|
|
|
sessionSequence,
|
|
|
|
|
runtimeHost,
|
2020-02-14 15:04:33 +01:00
|
|
|
|
runtimeWindow,
|
2019-03-06 16:10:00 +01:00
|
|
|
|
serviceProxy,
|
|
|
|
|
sessionContext,
|
|
|
|
|
shutdown,
|
2020-02-14 15:04:33 +01:00
|
|
|
|
splashScreen,
|
2019-03-06 16:10:00 +01:00
|
|
|
|
text,
|
|
|
|
|
uiFactory);
|
2018-01-23 15:33:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void LogStartupInformation()
|
2022-02-23 13:59:36 +01:00
|
|
|
|
{
|
2019-08-13 10:02:05 +02:00
|
|
|
|
logger.Log($"/* {appConfig.ProgramTitle}, Version {appConfig.ProgramInformationalVersion}, Build {appConfig.ProgramBuildVersion}");
|
2018-06-29 09:50:20 +02:00
|
|
|
|
logger.Log($"/* {appConfig.ProgramCopyright}");
|
2018-02-20 15:15:26 +01:00
|
|
|
|
logger.Log($"/* ");
|
|
|
|
|
logger.Log($"/* Please visit https://www.github.com/SafeExamBrowser for more information.");
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger.Log(string.Empty);
|
2022-02-23 13:59:36 +01:00
|
|
|
|
logger.Log($"# Application started at {appConfig.ApplicationStartTime:yyyy-MM-dd HH:mm:ss.fff}");
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger.Log($"# Running on {systemInfo.OperatingSystemInfo}");
|
2019-12-20 17:06:28 +01:00
|
|
|
|
logger.Log($"# Computer '{systemInfo.Name}' is a {systemInfo.Model} manufactured by {systemInfo.Manufacturer}");
|
2018-06-29 09:50:20 +02:00
|
|
|
|
logger.Log($"# Runtime-ID: {appConfig.RuntimeId}");
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger.Log(string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void LogShutdownInformation()
|
|
|
|
|
{
|
2022-02-23 13:59:36 +01:00
|
|
|
|
logger?.Log($"# Application terminated at {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}");
|
2018-01-17 14:08:39 +01:00
|
|
|
|
}
|
2018-01-17 08:26:44 +01:00
|
|
|
|
|
2018-11-08 09:39:52 +01:00
|
|
|
|
private void InitializeConfiguration()
|
2018-09-04 10:58:56 +02:00
|
|
|
|
{
|
2019-02-22 10:02:34 +01:00
|
|
|
|
var certificateStore = new CertificateStore(ModuleLogger(nameof(CertificateStore)));
|
2019-02-19 15:54:11 +01:00
|
|
|
|
var compressor = new GZipCompressor(ModuleLogger(nameof(GZipCompressor)));
|
|
|
|
|
var passwordEncryption = new PasswordEncryption(ModuleLogger(nameof(PasswordEncryption)));
|
2019-02-22 10:02:34 +01:00
|
|
|
|
var publicKeyEncryption = new PublicKeyEncryption(certificateStore, ModuleLogger(nameof(PublicKeyEncryption)));
|
|
|
|
|
var symmetricEncryption = new PublicKeySymmetricEncryption(certificateStore, ModuleLogger(nameof(PublicKeySymmetricEncryption)), passwordEncryption);
|
2019-02-19 15:54:11 +01:00
|
|
|
|
var repositoryLogger = ModuleLogger(nameof(ConfigurationRepository));
|
2020-01-30 15:20:05 +01:00
|
|
|
|
var xmlParser = new XmlParser(compressor, ModuleLogger(nameof(XmlParser)));
|
2019-02-20 08:47:30 +01:00
|
|
|
|
var xmlSerializer = new XmlSerializer(ModuleLogger(nameof(XmlSerializer)));
|
2018-11-08 09:39:52 +01:00
|
|
|
|
|
2022-04-19 18:21:29 +02:00
|
|
|
|
configuration = new ConfigurationRepository(certificateStore, repositoryLogger);
|
2018-11-08 09:39:52 +01:00
|
|
|
|
appConfig = configuration.InitializeAppConfig();
|
2018-09-04 10:58:56 +02:00
|
|
|
|
|
2019-03-06 16:10:00 +01:00
|
|
|
|
configuration.Register(new BinaryParser(
|
|
|
|
|
compressor,
|
|
|
|
|
new HashAlgorithm(),
|
|
|
|
|
ModuleLogger(nameof(BinaryParser)),
|
|
|
|
|
passwordEncryption,
|
|
|
|
|
publicKeyEncryption,
|
|
|
|
|
symmetricEncryption, xmlParser));
|
|
|
|
|
configuration.Register(new BinarySerializer(
|
|
|
|
|
compressor,
|
|
|
|
|
ModuleLogger(nameof(BinarySerializer)),
|
|
|
|
|
passwordEncryption,
|
|
|
|
|
publicKeyEncryption,
|
|
|
|
|
symmetricEncryption,
|
|
|
|
|
xmlSerializer));
|
2020-01-30 15:20:05 +01:00
|
|
|
|
configuration.Register(new XmlParser(compressor, ModuleLogger(nameof(XmlParser))));
|
2019-02-19 15:54:11 +01:00
|
|
|
|
configuration.Register(new XmlSerializer(ModuleLogger(nameof(XmlSerializer))));
|
|
|
|
|
configuration.Register(new FileResourceLoader(ModuleLogger(nameof(FileResourceLoader))));
|
|
|
|
|
configuration.Register(new FileResourceSaver(ModuleLogger(nameof(FileResourceSaver))));
|
2018-12-21 11:36:20 +01:00
|
|
|
|
configuration.Register(new NetworkResourceLoader(appConfig, new ModuleLogger(logger, nameof(NetworkResourceLoader))));
|
2018-09-04 10:58:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-19 14:04:12 +01:00
|
|
|
|
private void InitializeLogging()
|
2018-01-17 14:08:39 +01:00
|
|
|
|
{
|
2019-06-06 15:44:03 +02:00
|
|
|
|
var logFileWriter = new LogFileWriter(new DefaultLogFormatter(), appConfig.RuntimeLogFilePath);
|
2018-01-17 08:26:44 +01:00
|
|
|
|
|
2018-01-17 14:08:39 +01:00
|
|
|
|
logFileWriter.Initialize();
|
2019-01-23 08:12:15 +01:00
|
|
|
|
logger.LogLevel = LogLevel.Debug;
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger.Subscribe(logFileWriter);
|
2017-07-06 10:56:03 +02:00
|
|
|
|
}
|
2018-08-31 10:06:27 +02:00
|
|
|
|
|
|
|
|
|
private void InitializeText()
|
|
|
|
|
{
|
2020-03-09 17:35:48 +01:00
|
|
|
|
text = new Text(ModuleLogger(nameof(Text)));
|
2018-08-31 10:06:27 +02:00
|
|
|
|
}
|
2019-02-19 15:54:11 +01:00
|
|
|
|
|
|
|
|
|
private IModuleLogger ModuleLogger(string moduleInfo)
|
|
|
|
|
{
|
|
|
|
|
return new ModuleLogger(logger, moduleInfo);
|
|
|
|
|
}
|
2017-07-05 11:41:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|