Skip to content

Commit 2e6c4b8

Browse files
authored
Add additional verification for OpenSSL environment variable. (#850)
1 parent f6be60a commit 2e6c4b8

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

NWN.Anvil/src/main/AnvilCore.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Anvil
2020
/// </summary>
2121
public sealed partial class AnvilCore
2222
{
23+
private const string ExpectedOpenSslEnvironmentValue = "1.1";
2324
private const int ExpectedOpenSslVersion = 269488463;
2425

2526
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
@@ -131,6 +132,14 @@ private void CheckOpenSslVersion()
131132
}
132133

133134
Log.Info("Checking OpenSSL version. If the server crashes, see this page for troubleshooting: https://github.com/nwn-dotnet/Anvil/wiki/Troubleshooting-OpenSSL-Issues");
135+
136+
if (EnvironmentConfig.OpenSslVersionOverride != ExpectedOpenSslEnvironmentValue)
137+
{
138+
const string message = "Environment variable 'DOTNET_OPENSSL_VERSION_OVERRIDE' is not set. Please see the OpenSSL troubleshooting page for more info.";
139+
Log.Fatal(message);
140+
throw new Exception(message);
141+
}
142+
134143
LogManager.Flush();
135144

136145
long version = SafeEvpPKeyHandle.OpenSslVersion;

NWN.Anvil/src/main/Internal/EnvironmentConfig.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@ public static class EnvironmentConfig
1212
{
1313
private static readonly string[] VariablePrefixes = ["ANVIL_", "NWM_"];
1414

15+
public static readonly string? OpenSslVersionOverride = Environment.GetEnvironmentVariable("DOTNET_OPENSSL_VERSION_OVERRIDE");
16+
1517
public static readonly string AnvilHome = GetAnvilVariableString("HOME", "./anvil");
1618
public static readonly string Encoding = GetAnvilVariableString("ENCODING", "windows-1252");
19+
1720
public static readonly LogMode LogMode = GetAnvilVariableEnum("LOG_MODE", LogMode.Default);
21+
1822
public static readonly bool NativePrelinkEnabled = GetAnvilVariableBool("PRELINK_ENABLED", true);
1923
public static readonly bool PreventStartNoPlugin = GetAnvilVariableBool("PREVENT_START_NO_PLUGIN");
2024
public static readonly bool ReloadEnabled = GetAnvilVariableBool("RELOAD_ENABLED");
21-
public static readonly string[] AdditionalPluginPaths = GetAnvilVariableArrayString("ADD_PLUGIN_PATHS");
2225

23-
static EnvironmentConfig()
24-
{
25-
ValidateUnset("NLOG_CONFIG");
26-
ValidateUnset("PLUGIN_PATH");
27-
}
26+
public static readonly string[] AdditionalPluginPaths = GetAnvilVariableArrayString("ADD_PLUGIN_PATHS");
2827

2928
public static bool GetIsPluginDisabled(string pluginName)
3029
{
@@ -65,13 +64,5 @@ private static string[] GetAnvilVariableArrayString(string key, string[]? defaul
6564

6665
return value != null ? value.Split(Path.PathSeparator) : defaultValue;
6766
}
68-
69-
private static void ValidateUnset(string key)
70-
{
71-
if (Environment.GetEnvironmentVariable(key) != null)
72-
{
73-
throw new Exception($"Unsupported environment variable {key}. Please see the changelog for more information.");
74-
}
75-
}
7667
}
7768
}

0 commit comments

Comments
 (0)