|
@@ -31,7 +31,9 @@ uses
|
|
|
{$R Res\ISSigTool.versionandicon.res}
|
|
|
|
|
|
var
|
|
|
- KeyFilename: String;
|
|
|
+ Options: record
|
|
|
+ KeyFile: String;
|
|
|
+ end;
|
|
|
|
|
|
procedure RaiseFatalError(const Msg: String);
|
|
|
begin
|
|
@@ -58,31 +60,32 @@ begin
|
|
|
Result := SHA256Final(Context);
|
|
|
end;
|
|
|
|
|
|
-procedure CheckImportKeyResult(const AResult: TISSigImportKeyResult);
|
|
|
+procedure ImportKey(const AKey: TECDSAKey; const ANeedPrivateKey: Boolean);
|
|
|
begin
|
|
|
- case AResult of
|
|
|
- ikrSuccess:
|
|
|
- Exit;
|
|
|
- ikrMalformed:
|
|
|
- RaiseFatalError('Key file is malformed');
|
|
|
- ikrNotPrivateKey:
|
|
|
- RaiseFatalError('Key file must be a private key when signing');
|
|
|
+ const ImportResult = ISSigImportKeyText(AKey,
|
|
|
+ ISSigLoadTextFromFile(Options.KeyFile), ANeedPrivateKey);
|
|
|
+ if ImportResult <> ikrSuccess then begin
|
|
|
+ case ImportResult of
|
|
|
+ ikrMalformed:
|
|
|
+ RaiseFatalError('Key file is malformed');
|
|
|
+ ikrNotPrivateKey:
|
|
|
+ RaiseFatalError('Key file must be a private key when signing');
|
|
|
+ end;
|
|
|
+ RaiseFatalError('Unknown import key result');
|
|
|
end;
|
|
|
- RaiseFatalError('Unknown import key result');
|
|
|
end;
|
|
|
|
|
|
procedure CommandExportPublicKey(const AFilename: String);
|
|
|
begin
|
|
|
const Key = TECDSAKey.Create;
|
|
|
try
|
|
|
- CheckImportKeyResult(ISSigImportKeyText(Key,
|
|
|
- ISSigLoadTextFromFile(KeyFilename), True));
|
|
|
+ ImportKey(Key, False);
|
|
|
|
|
|
var PublicKeyText: String;
|
|
|
ISSigExportPublicKeyText(Key, PublicKeyText);
|
|
|
ISSigSaveTextToFile(AFilename, PublicKeyText);
|
|
|
|
|
|
- Writeln(AFilename, ': OK');
|
|
|
+ Writeln('Public key file created: ', AFilename);
|
|
|
finally
|
|
|
Key.Free;
|
|
|
end;
|
|
@@ -90,7 +93,7 @@ end;
|
|
|
|
|
|
procedure CommandGeneratePrivateKey;
|
|
|
begin
|
|
|
- if NewFileExists(KeyFilename) then
|
|
|
+ if NewFileExists(Options.KeyFile) then
|
|
|
RaiseFatalError('Key file already exists');
|
|
|
|
|
|
const Key = TECDSAKey.Create;
|
|
@@ -99,9 +102,9 @@ begin
|
|
|
|
|
|
var PrivateKeyText: String;
|
|
|
ISSigExportPrivateKeyText(Key, PrivateKeyText);
|
|
|
- ISSigSaveTextToFile(KeyFilename, PrivateKeyText);
|
|
|
+ ISSigSaveTextToFile(Options.KeyFile, PrivateKeyText);
|
|
|
|
|
|
- Writeln(KeyFilename, ': OK');
|
|
|
+ Writeln('Private key file created: ', Options.KeyFile);
|
|
|
finally
|
|
|
Key.Free;
|
|
|
end;
|
|
@@ -152,8 +155,7 @@ procedure CommandSign(const AFilenames: TStringList);
|
|
|
begin
|
|
|
const Key = TECDSAKey.Create;
|
|
|
try
|
|
|
- CheckImportKeyResult(ISSigImportKeyText(Key,
|
|
|
- ISSigLoadTextFromFile(KeyFilename), True));
|
|
|
+ ImportKey(Key, True);
|
|
|
|
|
|
for var CurFilename in AFilenames do
|
|
|
SignSingleFile(Key, CurFilename);
|
|
@@ -218,8 +220,7 @@ function CommandVerify(const AFilenames: TStringList): Boolean;
|
|
|
begin
|
|
|
const Key = TECDSAKey.Create;
|
|
|
try
|
|
|
- CheckImportKeyResult(ISSigImportKeyText(Key,
|
|
|
- ISSigLoadTextFromFile(KeyFilename), False));
|
|
|
+ ImportKey(Key, False);
|
|
|
|
|
|
Result := True;
|
|
|
for var CurFilename in AFilenames do
|
|
@@ -261,7 +262,7 @@ begin
|
|
|
while J < ArgList.Count do begin
|
|
|
const S = ArgList[J];
|
|
|
if S.StartsWith('--key-file=') then begin
|
|
|
- KeyFilename := S.Substring(Length('--key-file='));
|
|
|
+ Options.KeyFile := S.Substring(Length('--key-file='));
|
|
|
ArgList.Delete(J);
|
|
|
end else begin
|
|
|
if S.StartsWith('-') then
|
|
@@ -279,9 +280,9 @@ begin
|
|
|
const Command = ArgList[0];
|
|
|
ArgList.Delete(0);
|
|
|
|
|
|
- if KeyFilename = '' then begin
|
|
|
- KeyFilename := GetEnv('ISSIGTOOL_KEY_FILE');
|
|
|
- if KeyFilename = '' then
|
|
|
+ if Options.KeyFile = '' then begin
|
|
|
+ Options.KeyFile := GetEnv('ISSIGTOOL_KEY_FILE');
|
|
|
+ if Options.KeyFile = '' then
|
|
|
RaiseFatalError('"--key-file=" option must be specified, ' +
|
|
|
'or set the ISSIGTOOL_KEY_FILE environment variable');
|
|
|
end;
|