Skip to content

Commit ab15615

Browse files
committed
release: Reopen certificate store only when installing certificate.
1 parent 736a321 commit ab15615

3 files changed

Lines changed: 28 additions & 16 deletions

File tree

src/Flarial.Launcher.Installer.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<PropertyGroup>
2121
<ApplicationIcon>Resources/app.ico</ApplicationIcon>
22-
<ApplicationManifest>Resources/app.manifest</ApplicationManifest>
22+
<ApplicationManifest>Resources/app.manifest</ApplicationManifest>
2323
</PropertyGroup>
2424

2525
<ItemGroup>
@@ -35,7 +35,7 @@
3535
</ItemGroup>
3636

3737
<PropertyGroup>
38-
<AssemblyVersion>1.1.0.0</AssemblyVersion>
38+
<AssemblyVersion>1.1.1.0</AssemblyVersion>
3939
<AssemblyTitle>Flarial Launcher Installer</AssemblyTitle>
4040

4141
<Company>Flarial</Company>

src/InstallerService.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,36 @@ static class InstallerService
2424
const string LauncherCertificateUri = "https://cdn.flarial.xyz/launcher/Flarial.Launcher.cer";
2525
const string LauncherCertificateThumbprint = "080862035B63C6B01A1F7F5E2A286939808F502ADCA100BDCB6F805FB0DD4171";
2626

27-
internal static Task InstallCertificateAsync() => Task.Run(static async () =>
27+
static bool IsCertificateInstalled
2828
{
29-
using X509Store certificateStore = new(StoreName.TrustedPeople, StoreLocation.LocalMachine);
30-
certificateStore.Open(OpenFlags.ReadWrite);
31-
32-
foreach (var installedCertificate in certificateStore.Certificates)
29+
get
3330
{
34-
var installedCertificateThumbprint = installedCertificate.GetCertHashString(HashAlgorithmName.SHA256);
35-
if (LauncherCertificateThumbprint.Equals(installedCertificateThumbprint, OrdinalIgnoreCase)) return;
31+
using X509Store store = new(StoreName.TrustedPeople, StoreLocation.LocalMachine);
32+
store.Open(OpenFlags.ReadOnly);
33+
34+
foreach (var certificate in store.Certificates)
35+
{
36+
var thumbprint = certificate.GetCertHashString(HashAlgorithmName.SHA256);
37+
if (LauncherCertificateThumbprint.Equals(thumbprint, OrdinalIgnoreCase)) return true;
38+
}
39+
40+
return false;
3641
}
42+
}
3743

38-
using X509Certificate2 launcherCertificate = new(await HttpService.GetBytesAsync(LauncherCertificateUri));
39-
var launcherCertificateFingerprint = launcherCertificate.GetCertHashString(HashAlgorithmName.SHA256);
44+
internal static Task InstallCertificateAsync() => Task.Run(static async () =>
45+
{
46+
if (!IsCertificateInstalled)
47+
{
48+
using X509Certificate2 certificate = new(await HttpService.GetBytesAsync(LauncherCertificateUri));
49+
var thumbprint = certificate.GetCertHashString(HashAlgorithmName.SHA256);
4050

41-
if (!launcherCertificateFingerprint.Equals(LauncherCertificateThumbprint, OrdinalIgnoreCase))
42-
throw new("The launcher's remote thumbprint doesn't match the installer's local thumbprint.");
51+
if (!thumbprint.Equals(LauncherCertificateThumbprint, OrdinalIgnoreCase))
52+
throw new SecurityException("The launcher's remote thumbprint doesn't match the installer's local thumbprint.");
4353

44-
certificateStore.Add(launcherCertificate);
54+
using X509Store store = new(StoreName.TrustedPeople, StoreLocation.LocalMachine);
55+
store.Open(OpenFlags.ReadWrite); store.Add(certificate);
56+
}
4557
});
4658

4759
internal static Task InstallPackageAsync(Action<int> callback) => Task.Run(() =>

src/MainWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ await InstallerService.InstallPackageAsync(value => Dispatcher.Invoke(() =>
7777

7878
using (Process.Start(new ProcessStartInfo
7979
{
80-
UseShellExecute= true,
81-
FileName= @"shell:appsFolder\Flarial.Launcher_0jrgakbnj75vr!App"
80+
UseShellExecute = true,
81+
FileName = @"shell:appsFolder\Flarial.Launcher_0jrgakbnj75vr!App"
8282
})) { }
8383

8484
Environment.Exit(0);

0 commit comments

Comments
 (0)