Skip to content

Commit

Permalink
finish multiengine and signature checks
Browse files Browse the repository at this point in the history
  • Loading branch information
DEATHB4DEFEAT committed Dec 23, 2024
1 parent a57afb9 commit 738efe8
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 25 deletions.
8 changes: 7 additions & 1 deletion SS14.Launcher/LauncherPaths.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -31,7 +32,12 @@ public static class LauncherPaths
public static readonly string PathClientMacLog = Path.Combine(DirLogs, ClientMacLogName);
public static readonly string PathClientStdoutLog = Path.Combine(DirLogs, ClientStdoutLogName);
public static readonly string PathClientStderrLog = Path.Combine(DirLogs, ClientStderrLogName);
public static readonly string PathPublicKey = Path.Combine(DirLauncherInstall, "signing_key");
public static readonly string PathPublicKey = Path.Combine(DirLauncherInstall, "signing_key_Robust"); // Used as a fallback
public static readonly Dictionary<string, string> PathPublicKeys = new()
{
{ "Robust", PathPublicKey },
{ "Multiverse", Path.Combine(DirLauncherInstall, "signing_key_Multiverse") },
};
public static readonly string PathContentDb = Path.Combine(DirLocalData, "content.db");
public static readonly string PathOverrideAssetsDb = Path.Combine(DirLocalData, "override_assets.db");

Expand Down
8 changes: 4 additions & 4 deletions SS14.Launcher/Models/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private async Task<ContentLaunchInfo> RunUpdateAsync(ServerInfo info, Cancellati
// Must have been set when retrieving build info (inferred to be automatic zipping).
Debug.Assert(info.BuildInformation != null, "info.BuildInformation != null");

var installation = await _updater.RunUpdateForLaunchAsync(info.BuildInformation, info.Engine, cancel);
var installation = await _updater.RunUpdateForLaunchAsync(info.BuildInformation, cancel);
if (installation == null)
{
throw new ConnectException(ConnectionStatus.UpdateError);
Expand Down Expand Up @@ -415,10 +415,10 @@ private async Task<ContentLaunchInfo> InstallContentBundleAsync(
IEnumerable<string> extraArgs,
List<(string, string)> env)
{
Log.Error("Launching client with engine {Engine}", engine);
Log.Fatal(string.Join(", ", launchInfo.ModuleInfo));
Log.Information("Launching client with engine {Engine}", engine);
Log.Debug($"Engine has modules {string.Join(", ", launchInfo.ModuleInfo)}");

var pubKey = LauncherPaths.PathPublicKey;
var pubKey = LauncherPaths.PathPublicKeys!.GetValueOrDefault(engine, null) ?? LauncherPaths.PathPublicKey;
var engineVersion = launchInfo.ModuleInfo.Single(x => x.Module == engine).Version;
var binPath = _engineManager.GetEnginePath(engineVersion);
var sig = _engineManager.GetEngineSignature(engineVersion);
Expand Down
1 change: 0 additions & 1 deletion SS14.Launcher/Models/ContentLaunchInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
/// Information loaded by the updater that we need to launch the game.
/// </summary>
public sealed record ContentLaunchInfo(long Version, (string Module, string Version)[] ModuleInfo, bool ServerGC = false);

Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ public sealed partial class EngineManagerDynamic
string engine)
{
// First, check if we have a cached copy of the manifest.
if (_cachedEngineVersionInfo.TryGetValue(engine, out var versionInfo) && versionInfo != null)
if (_cachedEngineVersionInfo.TryGetValue(engine, out var versionInfo)
&& versionInfo != null
&& _robustCacheValidUntil > _manifestStopwatch.Elapsed)
return FindVersionInfoInCached(version, followRedirects, engine);

if (_robustCacheValidUntil >= _manifestStopwatch.Elapsed)
return null;

// If we don't have a cached copy, or it's expired, we re-request the manifest.
await UpdateBuildManifest(cancel, engine);
return FindVersionInfoInCached(version, followRedirects, engine);

}

private async Task UpdateBuildManifest(CancellationToken cancel, string name)
Expand Down
8 changes: 4 additions & 4 deletions SS14.Launcher/Models/EngineManager/EngineManagerDynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public async Task<bool> DownloadModuleIfNecessary(
// Verify signature.
tempFile.Seek(0, SeekOrigin.Begin);

if (!VerifyModuleSignature(tempFile, platformData.Sig))
if (!VerifyModuleSignature(tempFile, moduleName, platformData.Sig))
{
#if DEBUG
if (_cfg.GetCVar(CVars.DisableSigning))
Expand Down Expand Up @@ -283,7 +283,7 @@ private static void ExtractModule(string moduleName, string moduleVersionDiskPat
}
}

private static unsafe bool VerifyModuleSignature(FileStream stream, string signature)
private static unsafe bool VerifyModuleSignature(FileStream stream, string module, string signature)
{
if (stream.Length > int.MaxValue)
throw new InvalidOperationException("Unable to handle files larger than 2 GiB");
Expand All @@ -307,7 +307,7 @@ private static unsafe bool VerifyModuleSignature(FileStream stream, string signa

var pubKey = PublicKey.Import(
SignatureAlgorithm.Ed25519,
File.ReadAllBytes(LauncherPaths.PathPublicKey),
File.ReadAllBytes(LauncherPaths.PathPublicKeys!.GetValueOrDefault(module, null) ?? LauncherPaths.PathPublicKey),
KeyBlobFormat.PkixPublicKeyText);

var sigBytes = Convert.FromHexString(signature);
Expand All @@ -323,7 +323,7 @@ private static unsafe bool VerifyModuleSignature(FileStream stream, string signa
public async Task<EngineModuleManifest> GetEngineModuleManifest(string engine, CancellationToken cancel = default)
{
if (!ConfigConstants.EngineBuildsUrl.TryGetValue(engine, out var urls))
throw new InvalidOperationException("No manifest URL for engine module"); //TODO: Tell the user
throw new InvalidOperationException("No manifest URL for engine module");

if (await urls.GetFromJsonAsync<EngineModuleManifest>(_http, cancel) is { } manifest)
return manifest;
Expand Down
1 change: 0 additions & 1 deletion SS14.Launcher/Models/ServerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public sealed class ServerInfo
public string? ConnectAddress { get; set; }

[JsonInclude, JsonPropertyName("build")] public ServerBuildInformation? BuildInformation;
[JsonInclude, JsonPropertyName("engine")] public string Engine { get; set; } = "Robust";
[JsonPropertyName("auth")] public ServerAuthInformation AuthInformation { get; set; } = default!;

[JsonPropertyName("desc")] public string? Desc { get; set; }
Expand Down
10 changes: 4 additions & 6 deletions SS14.Launcher/Models/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ public Updater()

public async Task<ContentLaunchInfo?> RunUpdateForLaunchAsync(
ServerBuildInformation buildInformation,
string engine,
CancellationToken cancel = default)
{
return await GuardUpdateAsync(() => RunUpdate(buildInformation, engine, cancel));
return await GuardUpdateAsync(() => RunUpdate(buildInformation, cancel));
}

public async Task<ContentLaunchInfo?> InstallContentBundleForLaunchAsync(
Expand Down Expand Up @@ -118,15 +117,14 @@ public Updater()

private async Task<ContentLaunchInfo> RunUpdate(
ServerBuildInformation buildInfo,
string engine,
CancellationToken cancel)
{
Status = UpdateStatus.CheckingClientUpdate;

// Both content downloading and engine downloading MAY need the manifest.
// So use a Lazy<Task<T>> to avoid loading it twice.
var moduleManifest =
new Lazy<Task<EngineModuleManifest>>(() => _engineManager.GetEngineModuleManifest(engine, cancel));
new Lazy<Task<EngineModuleManifest>>(() => _engineManager.GetEngineModuleManifest(buildInfo.Engine, cancel));

// ReSharper disable once UseAwaitUsing
using var con = ContentManager.GetSqliteConnection();
Expand All @@ -138,7 +136,7 @@ private async Task<ContentLaunchInfo> RunUpdate(

await Task.Run(() => { CullOldContentVersions(con); }, CancellationToken.None);

return await InstallEnginesForVersion(con, versionRowId, engine, cancel);
return await InstallEnginesForVersion(con, versionRowId, buildInfo.Engine, cancel);
}

private async Task<ContentLaunchInfo> InstallContentBundle(
Expand Down Expand Up @@ -528,7 +526,7 @@ SELECT ModuleName
FROM ContentEngineDependency
WHERE VersionId = @OldVersion AND ModuleName != @Engine", new
{
OldVersion = existingVersion.Id, buildInfo.Engine
OldVersion = existingVersion.Id, Engine = buildInfo.Engine,
}).ToArray();

if (oldDependencies.Length > 0)
Expand Down
8 changes: 6 additions & 2 deletions SS14.Launcher/SS14.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@
<RobustLinkAssemblies Include="TerraFX.Interop.Windows" />
</ItemGroup>
<ItemGroup>
<None Remove="signing_key" />
<Content Include="signing_key">
<None Remove="signing_key_Robust" />
<Content Include="signing_key_Robust">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Remove="signing_key_Multiverse" />
<Content Include="signing_key_Multiverse">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions SS14.Launcher/signing_key_Multiverse
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAM2YE9eSPVh+Z6yWGseQ8HdK4qLbwjfMd/CxlsjfQitM=
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEApQ9mAhMLbmhQqRH7itgNo75S5rCSMsMXvVRmMv1d9NQ=
-----END PUBLIC KEY-----

0 comments on commit 738efe8

Please sign in to comment.