Bläddra i källkod

Make TrustFunc more generic since it's in Components. Can't be moved to Projects\Src instead because Components\ScintInt needs it.

Martijn Laan 5 månader sedan
förälder
incheckning
203ffa67a5
2 ändrade filer med 21 tillägg och 5 borttagningar
  1. 7 1
      Components/TrustFunc.AllowedPublicKeys.inc
  2. 14 4
      Components/TrustFunc.pas

+ 7 - 1
Components/TrustFunc.AllowedPublicKeys.inc

@@ -1,3 +1,9 @@
+{ Inno Setup build: the second key in this file should be replaced by your
+  own.
+  
+  Other builds: if you need only one key you can set AllowedPublicKey2Text To
+  an empty string. }
+
 AllowedPublicKey1Text := '''
 format issig-public-key
 key-id def0147c3bbc17ab99bf7b7a9c2de1390283f38972152418d7c2a4a7d7131a38
@@ -12,4 +18,4 @@ key-id def020edee3c4835fd54d85eff8b66d4d899b22a777353ca4a114b652e5e7a28
 public-x 515dc7d6c16d4a46272ceb3d158c5630a96466ab4d948e72c2029d737c823097
 public-y f3c21f6b5156c52a35f6f28016ee3e31a3ded60c325b81fb7b1f88c221081a61
 
-''';
+''';

+ 14 - 4
Components/TrustFunc.pas

@@ -5,6 +5,8 @@ unit TrustFunc;
   Copyright (C) 1997-2025 Jordan Russell
   Portions by Martijn Laan
   For conditions of distribution and use, see LICENSE.TXT.
+
+  Trust support functons using ISSigFunc and key texts from TrustFunc.AllowedPublicKeys.inc
 }
 
 {.$DEFINE TRUSTALL}
@@ -33,16 +35,24 @@ begin
         Key1 := TECDSAKey.Create;
         if ISSigImportKeyText(Key1, AllowedPublicKey1Text, False) <> ikrSuccess then
           raise Exception.Create('ISSigImportKeyText failed');
-        Key2 := TECDSAKey.Create;
-        if ISSigImportKeyText(Key2, AllowedPublicKey2Text, False) <> ikrSuccess then
-          raise Exception.Create('ISSigImportKeyText failed');
+        if AllowedPublicKey2Text <> '' then begin
+          Key2 := TECDSAKey.Create;
+          if ISSigImportKeyText(Key2, AllowedPublicKey2Text, False) <> ikrSuccess then
+            raise Exception.Create('ISSigImportKeyText failed');
+        end;
+
+        var AllowedKeys: array of TECDSAKey;
+        if Key2 <> nil then
+          AllowedKeys := [Key1, Key2]
+        else
+          AllowedKeys := [Key1];
 
         const SigFileName = FileName + '.issig';
         const SigText = ISSigLoadTextFromFile(SigFileName);
 
         var ExpectedFileSize: Int64;
         var ExpectedFileHash: TSHA256Digest;
-        if ISSigVerifySignatureText([Key1, Key2], SigText, ExpectedFileSize,
+        if ISSigVerifySignatureText(AllowedKeys, SigText, ExpectedFileSize,
            ExpectedFileHash) <> vsrSuccess then
           raise Exception.CreateFmt('Signature file "%s" is not valid',
             [SigFileName]);