@@ -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 ( ( ) =>
0 commit comments