Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Check the installer's signature off the UI thread; name a failed revocation check

KnifeLemon3ebc862b733e
diff --git a/src/Filee.App/Services/UpdateService.cs b/src/Filee.App/Services/UpdateService.cs
index 339ebe2f..c681f6d3 100644
--- a/src/Filee.App/Services/UpdateService.cs
+++ b/src/Filee.App/Services/UpdateService.cs
@@ -279,7 +279,8 @@ public sealed partial class UpdateService : ObservableObject
{
var progress = new Progress<int>(percent => DownloadPercent = percent);
installer = await DownloadInstallerAsync(Path.Combine(Path.GetTempPath(), "Filee-update"), progress);
- CheckPublisher(installer);
+ // WinVerifyTrust hashes the whole installer and may ask the certificate authority about revocation.
+ await Task.Run(() => CheckPublisher(installer));
}
catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException or IOException
or InvalidDataException or UnauthorizedAccessException)
@@ -373,9 +374,14 @@ public sealed partial class UpdateService : ObservableObject
var signer = SignerOf(installer, true);
if (signer == publisher)
return;
+ // A signature that holds without the revocation check failed only that check: the certificate authority
+ // could not be reached (offline, a proxy or a firewall) or the certificate was revoked.
+ var reason = signer is null && SignerOf(installer, false) == publisher
+ ? $"is signed by {publisher}, but the revocation check failed (the certificate authority could not be " +
+ "reached, or the certificate was revoked)"
+ : $"is signed by {signer ?? "no publisher Windows trusts"}, not by {publisher}";
TryDelete(installer);
- throw new InvalidDataException(
- $"{Path.GetFileName(installer)} is signed by {signer ?? "no publisher Windows trusts"}, not by {publisher}");
+ throw new InvalidDataException($"{Path.GetFileName(installer)} {reason}");
}
private async Task DownloadAsync(ReleaseFile file, string path, IProgress<int>? progress, CancellationToken cancellationToken)
diff --git a/tests/Filee.App.Tests/UpdateServiceTests.cs b/tests/Filee.App.Tests/UpdateServiceTests.cs
index 40e9f10a..31c0ecd4 100644
--- a/tests/Filee.App.Tests/UpdateServiceTests.cs
+++ b/tests/Filee.App.Tests/UpdateServiceTests.cs
@@ -209,6 +209,25 @@ public class UpdateServiceTests
Assert.False(File.Exists(path));
}
+ [Fact]
+ public void Failed_revocation_check_is_named_in_the_error()
+ {
+ // Offline or behind a proxy, the signature is fine but the certificate authority can't be asked: the
+ // installer is still thrown away, and the log says why instead of blaming the publisher.
+ var path = Path.Combine(TempFolder(), "Filee-9.9.9-win-Setup.exe");
+ File.WriteAllText(path, "setup");
+ var updates = new UpdateService(NullLogger<UpdateService>.Instance, new FakeNetwork("no network"))
+ {
+ OwnProgram = "Filee.exe",
+ SignerOf = (file, revocation) => file == "Filee.exe" || !revocation ? Publisher : null,
+ };
+
+ var error = Assert.Throws<InvalidDataException>(() => updates.CheckPublisher(path));
+
+ Assert.Contains("revocation check failed", error.Message);
+ Assert.False(File.Exists(path));
+ }
+
[Fact]
public void Installer_is_checked_for_revocation_but_this_copy_is_not()
{