ソースを参照

Allow optional KeyID parameter allowing the script write to catch mistakes early.

Martijn Laan 4 ヶ月 前
コミット
a7a5b2c4ab

+ 17 - 0
Components/ISSigFunc.pas

@@ -37,7 +37,9 @@ procedure ISSigExportPublicKeyText(const AKey: TECDSAKey;
 function ISSigImportKeyText(const AKey: TECDSAKey; const AText: String;
   const ANeedPrivateKey: Boolean): TISSigImportKeyResult;
 
+procedure ISSigCheckValidKeyID(const KeyID: String);
 procedure ISSigCheckValidPublicXOrY(const PublicXOrY: String);
+function ISSigIsValidKeyIDForPublicXY(const KeyID, PublicX, PublicY: String): Boolean;
 
 function ISSigCalcStreamHash(const AStream: TStream): TSHA256Digest;
 
@@ -315,11 +317,26 @@ begin
   Result := ikrSuccess;
 end;
 
+procedure ISSigCheckValidKeyID(const KeyID: String);
+begin
+  SHA256DigestFromString(KeyID);
+end;
+
 procedure ISSigCheckValidPublicXOrY(const PublicXOrY: String);
 begin
   ECDSAInt256FromString(PublicXOrY);
 end;
 
+function ISSigIsValidKeyIDForPublicXY(const KeyID, PublicX, PublicY: String): Boolean;
+begin
+  var PublicKey: TECDSAPublicKey;
+  PublicKey.Public_x := ECDSAInt256FromString(PublicX);
+  PublicKey.Public_y := ECDSAInt256FromString(PublicY);
+
+  Result := SHA256DigestsEqual(SHA256DigestFromString(KeyID),
+     CalcKeyID(PublicKey));
+end;
+
 function ISSigCalcStreamHash(const AStream: TStream): TSHA256Digest;
 var
   Buf: array[0..$FFFF] of Byte;

+ 1 - 0
Projects/Src/Compiler.Messages.pas

@@ -241,6 +241,7 @@ const
   SCompilerComponentsInvalidLevel = 'Component cannot be more than one level below the preceding component';
   SCompilerTasksInvalidLevel = 'Task cannot be more than one level below the preceding task'; 
   SCompilerLanguagesOrISSigKeysBadName = 'Parameter "Name" includes invalid characters.' + SNewLine2 + 'It may only include alphanumeric characters and/or underscores, and may not start with a number. Names ''not'', ''and'' and ''or'' are reserved';
+  SCompilerISSigKeysBadKeyID = 'Value of parameter "KeyID" is not valid for given "PublicX" and "PublicY" values.';
 
   { [Languages] }
   SCompilerParamUnknownLanguage = 'Parameter "%s" includes an unknown language';

+ 16 - 2
Projects/Src/Compiler.SetupCompiler.pas

@@ -4457,13 +4457,15 @@ end;
 
 procedure TSetupCompiler.EnumISSigKeysProc(const Line: PChar; const Ext: Integer);
 type
-  TParam = (paName, paPublicX, paPublicY);
+  TParam = (paName, paKeyID, paPublicX, paPublicY);
 const
   ParamISSigKeysName = 'Name';
+  ParamISSigKeysKeyID = 'KeyID';
   ParamISSigKeysPublicX = 'PublicX';
   ParamISSigKeysPublicY = 'PublicY';
   ParamInfo: array[TParam] of TParamInfo = (
     (Name: ParamISSigKeysName; Flags: [piRequired, piNoEmpty]),
+    (Name: ParamISSigKeysKeyID; Flags: [piNoEmpty]),
     (Name: ParamISSigKeysPublicX; Flags: [piRequired, piNoEmpty]),
     (Name: ParamISSigKeysPublicY; Flags: [piRequired, piNoEmpty]));
 var
@@ -4481,7 +4483,7 @@ begin
       Name := LowerCase(Values[paName].Data);
 
       { PublicX & PublicY }
-      PublicX := LowerCase(Values[paPublicX].Data);
+      PublicX := Values[paPublicX].Data;
       try
         ISSigCheckValidPublicXOrY(PublicX);
       except
@@ -4493,6 +4495,18 @@ begin
       except
         AbortCompileFmt(SCompilerParamInvalidWithError, [ParamISSigKeysPublicY, GetExceptMessage]);
       end;
+
+      { KeyID }
+      var KeyID := Values[paKeyID].Data;
+      if KeyID <> '' then begin
+        try
+          ISSigCheckValidKeyID(KeyID);
+        except
+          AbortCompileFmt(SCompilerParamInvalidWithError, [ParamISSigKeysKeyID, GetExceptMessage]);
+        end;
+        if not ISSigIsValidKeyIDForPublicXY(KeyID, PublicX, PublicY) then
+          AbortCompile(SCompilerISSigKeysBadKeyID);
+      end;
     end;
   except
     SEFreeRec(NewISSigKeyEntry, SetupISSigKeyEntryStrings, SetupISSigKeyEntryAnsiStrings);

+ 1 - 1
Projects/Src/IDE.ScintStylerInnoSetup.pas

@@ -235,7 +235,7 @@ const
   ];
 
   ISSigKeysSectionParameters: array of TScintRawString = [
-    'Name', 'PublicX', 'PublicY'
+    'Name', 'KeyID', 'PublicX', 'PublicY'
   ];
 
   FilesSectionParameters: array of TScintRawString = [