diff --git a/ProjectLighthouse/Startup/Startup.cs b/ProjectLighthouse/Startup/Startup.cs index 87b7a598..8cb5b1a6 100644 --- a/ProjectLighthouse/Startup/Startup.cs +++ b/ProjectLighthouse/Startup/Startup.cs @@ -97,6 +97,7 @@ public class Startup { bool computeDigests = true; string serverDigestKey = ServerSettings.Instance.ServerDigestKey; + string alternateDigestKey = ServerSettings.Instance.AlternateDigestKey; if (string.IsNullOrEmpty(serverDigestKey)) { Logger.Log @@ -175,12 +176,20 @@ public class Startup // Check the digest we've just calculated against the X-Digest-A header if the game set the header. They should match. if (context.Request.Headers.TryGetValue("X-Digest-A", out StringValues sentDigest)) + { if (clientRequestDigest != sentDigest) { - context.Response.StatusCode = 403; - context.Abort(); - return; + // If we got here, the normal ServerDigestKey failed to validate. Lets try again with the alternate digest key. + clientRequestDigest = await HashHelper.ComputeDigest(digestPath, authCookie, body, alternateDigestKey); + if (clientRequestDigest != sentDigest) + { + // We still failed to validate. Abort the request. + context.Response.StatusCode = 403; + context.Abort(); + return; + } } + } context.Response.Headers.Add("X-Digest-B", clientRequestDigest); context.Request.Body.Position = 0; diff --git a/ProjectLighthouse/Types/Settings/ServerSettings.cs b/ProjectLighthouse/Types/Settings/ServerSettings.cs index 820bb240..96e63599 100644 --- a/ProjectLighthouse/Types/Settings/ServerSettings.cs +++ b/ProjectLighthouse/Types/Settings/ServerSettings.cs @@ -12,7 +12,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings; [Serializable] public class ServerSettings { - public const int CurrentConfigVersion = 21; // MUST BE INCREMENTED FOR EVERY CONFIG CHANGE! + public const int CurrentConfigVersion = 22; // MUST BE INCREMENTED FOR EVERY CONFIG CHANGE! private static FileSystemWatcher fileWatcher; static ServerSettings() { @@ -114,6 +114,7 @@ public class ServerSettings public string ExternalUrl { get; set; } = "http://localhost:10060"; public string ServerDigestKey { get; set; } + public string AlternateDigestKey { get; set; } public bool UseExternalAuth { get; set; } public bool CheckForUnsafeFiles { get; set; } = true;