Move checksum check a bit above

It's pointless to let user waste bandwidth on the full ASF asset if checksum is not available right away
This commit is contained in:
Archi
2021-11-23 11:58:12 +01:00
parent 8b0e71e72d
commit b64ad59eff
3 changed files with 25 additions and 14 deletions

View File

@@ -266,6 +266,21 @@ public static class ASF {
return null;
}
ArchiLogger.LogGenericInfo(Strings.FetchingChecksumFromRemoteServer);
string? remoteChecksum = await ArchiNet.FetchBuildChecksum(newVersion, SharedInfo.BuildInfo.Variant).ConfigureAwait(false);
switch (remoteChecksum) {
case null:
// Timeout or error, refuse to update as a security measure
return null;
case "":
// Unknown checksum, release too new or actual malicious build published, no need to scare the user as it's 99.99% the first
ArchiLogger.LogGenericWarning(Strings.ChecksumMissing);
return SharedInfo.Version;
}
if (!string.IsNullOrEmpty(releaseResponse.ChangelogPlainText)) {
ArchiLogger.LogGenericInfo(releaseResponse.ChangelogPlainText!);
}
@@ -290,19 +305,6 @@ public static class ASF {
ArchiLogger.LogGenericInfo(Strings.VerifyingChecksumWithRemoteServer);
string? remoteChecksum = await ArchiNet.FetchBuildChecksum(newVersion, SharedInfo.BuildInfo.Variant).ConfigureAwait(false);
switch (remoteChecksum) {
case null:
// Timeout or error, refuse to update as a security measure
return null;
case "":
// Unknown checksum, release too new or actual malicious build published, no need to scare the user as it's 99.99% the first
ArchiLogger.LogGenericWarning(Strings.ChecksumMissing);
return SharedInfo.Version;
}
byte[] responseBytes = response.Content as byte[] ?? response.Content.ToArray();
string checksum = Convert.ToHexString(SHA512.HashData(responseBytes));

View File

@@ -1179,6 +1179,12 @@ namespace ArchiSteamFarm.Localization {
}
}
public static string FetchingChecksumFromRemoteServer {
get {
return ResourceManager.GetString("FetchingChecksumFromRemoteServer", resourceCulture);
}
}
public static string VerifyingChecksumWithRemoteServer {
get {
return ResourceManager.GetString("VerifyingChecksumWithRemoteServer", resourceCulture);

View File

@@ -729,8 +729,11 @@ Process uptime: {1}</value>
<data name="WarningRunningInUnsupportedEnvironment" xml:space="preserve">
<value>You're running ASF in unsupported environment, supplying --ignore-unsupported-environment argument. Please note that we do not offer any kind of support for this scenario and you're doing it entirely at your own risk. You've been warned.</value>
</data>
<data name="FetchingChecksumFromRemoteServer" xml:space="preserve">
<value>Fetching checksum from the remote server...</value>
</data>
<data name="VerifyingChecksumWithRemoteServer" xml:space="preserve">
<value>Verifying checksum of the downloaded binary with ASF's remote server...</value>
<value>Verifying checksum of the downloaded binary against the one from the remote server...</value>
</data>
<data name="ChecksumMissing" xml:space="preserve">
<value>Remote server doesn't know anything about the release we're updating to. This situation is possible if the release was published recently - refusing to proceed with the update procedure right away as an additional security measure.</value>