SEBWIN-510: Made lazy initialization of BEK thread-safe.

This commit is contained in:
Damian Büchel 2022-07-20 20:38:13 +02:00
parent d82d62f35f
commit 20ff39493d

View file

@ -19,6 +19,8 @@ namespace SafeExamBrowser.Configuration.Cryptography
{
public class KeyGenerator : IKeyGenerator
{
private readonly object @lock = new object();
private readonly SHA256Managed algorithm;
private readonly AppConfig appConfig;
private readonly IIntegrityModule integrityModule;
@ -59,6 +61,12 @@ namespace SafeExamBrowser.Configuration.Cryptography
var configurationKey = settings.Browser.ConfigurationKey;
var salt = settings.Browser.BrowserExamKeySalt;
lock (@lock)
{
if (browserExamKey == default)
{
logger.Debug("Initializing browser exam key...");
if (configurationKey == default)
{
configurationKey = "";
@ -87,6 +95,8 @@ namespace SafeExamBrowser.Configuration.Cryptography
browserExamKey = key;
}
}
}
}
return browserExamKey;
}