Missing files + start working on offline patcher

This commit is contained in:
2025-06-23 13:42:14 +02:00
parent 058d48196a
commit 2d36fecb45
70 changed files with 11475 additions and 12 deletions

View File

@@ -0,0 +1,90 @@
/*
* Copyright (c) 2025 ETH Zürich, IT Services
*
* 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/.
*/
using System;
using System.Linq;
using System.Text;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Modes;
using Org.BouncyCastle.Crypto.Parameters;
using SafeExamBrowser.Settings.Proctoring;
namespace SafeExamBrowser.Proctoring.ScreenProctoring
{
internal class Encryptor
{
private const int IV_BYTES = 16;
private const int MAC_BITS = 128;
private readonly Lazy<byte[]> encryptionSecret;
internal Encryptor(ScreenProctoringSettings settings)
{
encryptionSecret = new Lazy<byte[]>(() => Encoding.UTF8.GetBytes(settings.EncryptionSecret));
}
internal byte[] Decrypt(byte[] data)
{
var (iv, encrypted) = Split(data);
var cipher = new GcmBlockCipher(new AesEngine());
var key = new KeyParameter(encryptionSecret.Value);
var parameters = new AeadParameters(key, MAC_BITS, iv);
cipher.Init(false, parameters);
var outputSize = cipher.GetOutputSize(encrypted.Length);
var decrypted = new byte[outputSize];
var offset = cipher.ProcessBytes(encrypted, 0, encrypted.Length, decrypted, 0);
cipher.DoFinal(decrypted, offset);
return decrypted;
}
internal byte[] Encrypt(byte[] data)
{
var cipher = new GcmBlockCipher(new AesEngine());
var iv = GenerateInitializationVector();
var key = new KeyParameter(encryptionSecret.Value);
var parameters = new AeadParameters(key, MAC_BITS, iv);
cipher.Init(true, parameters);
var outputSize = cipher.GetOutputSize(data.Length);
var encrypted = new byte[outputSize];
var offset = cipher.ProcessBytes(data, 0, data.Length, encrypted, 0);
cipher.DoFinal(encrypted, offset);
return Merge(iv, encrypted);
}
private byte[] GenerateInitializationVector()
{
var vector = new byte[IV_BYTES];
var random = new Random();
random.NextBytes(vector);
return vector;
}
private byte[] Merge(byte[] iv, byte[] encrypted)
{
return iv.Concat(encrypted).ToArray();
}
private (byte[] iv, byte[] encrypted) Split(byte[] data)
{
var iv = data.Take(IV_BYTES).ToArray();
var encrypted = data.Skip(IV_BYTES).ToArray();
return (iv, encrypted);
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) 2025 ETH Zürich, IT Services
*
* 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/.
*/
using System;
using System.Reflection;
namespace SafeExamBrowser.Proctoring.ScreenProctoring.Service
{
internal class Sanitizer
{
internal Uri Sanitize(string serviceUrl)
{
return new Uri(serviceUrl.EndsWith("/") ? serviceUrl : $"{serviceUrl}/");
}
internal void Sanitize(Api api)
{
foreach (var property in api.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
var value = property.GetValue(api) as string;
var sanitized = value.TrimStart('/');
property.SetValue(api, sanitized);
}
}
}
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="KGySoft.CoreLibraries" publicKeyToken="b45eba277439ddfe" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.3.0.0" newVersion="8.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="KGySoft.Drawing.Core" publicKeyToken="b45eba277439ddfe" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.2.0.0" newVersion="8.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>