Skip to content

Commit

Permalink
Merge pull request #18 from golemfactory/bugfix/JST-387/Manifest-veri…
Browse files Browse the repository at this point in the history
…fy-fix

Bugfix/jst 387/manifest verify fix
  • Loading branch information
grisha87 authored Sep 8, 2023
2 parents feadc8d + e4c1528 commit 9746d0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/lib/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ export async function checkFileOverwrite(
}
}

export async function assertFileExists(name: string, path: string): Promise<void> {
export async function assertFileExists(name: string, path: string, extraHelp?: string): Promise<void> {
try {
await stat(path);
} catch (e) {
// File does not exist, that's fine.
console.error(`Error: ${name} "${path}" not found.`);
let message = `Error: ${name} "${path}" not found.`;
if (extraHelp) {
message += ` ${extraHelp}`;
}

console.error(message);
process.exit(1);
}
}
2 changes: 1 addition & 1 deletion src/manifest/manifest-sign.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { assertFileExists } from "../lib/file";
export async function manifestSignAction(options: ManifestSignOptions): Promise<void> {
// Read and validate the manifest.
await readManifest(options.manifest);
await assertFileExists("Private key file", options.keyFile);
await assertFileExists("Private key file", options.keyFile, "Check --key-file option.");

// Read manifest buffer.
const manifestBuffer = await readFile(options.manifest);
Expand Down
4 changes: 4 additions & 0 deletions src/manifest/manifest-verify.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import { ManifestVerifyOptions } from "./manifest-verify.options";
import { X509Certificate } from "node:crypto";
import { readFile } from "fs/promises";
import { createVerify } from "crypto";
import { assertFileExists } from "../lib/file";

export async function manifestVerifyAction(options: ManifestVerifyOptions) {
// Read and validate the manifest.
await readManifest(options.manifest);

await assertFileExists("Certificate file", options.certificateFile, "Check --certificate-file option.");
await assertFileExists("Signature file", options.signatureFile, "Check --signature-file option.");

// Read manifest buffer.
const manifestBuffer = await readFile(options.manifest);
const manifestBase64 = manifestBuffer.toString("base64");
Expand Down

0 comments on commit 9746d0c

Please sign in to comment.