From e4c152883f90a311049a854cd84f5a33484fe457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Grzywacz?= Date: Fri, 8 Sep 2023 10:07:39 +0200 Subject: [PATCH] fix(manifest verify): certificate file and signature file presence is checked JST-387 --- src/lib/file.ts | 9 +++++++-- src/manifest/manifest-sign.action.ts | 2 +- src/manifest/manifest-verify.action.ts | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/file.ts b/src/lib/file.ts index 8627852..40a1de2 100644 --- a/src/lib/file.ts +++ b/src/lib/file.ts @@ -22,12 +22,17 @@ export async function checkFileOverwrite( } } -export async function assertFileExists(name: string, path: string): Promise { +export async function assertFileExists(name: string, path: string, extraHelp?: string): Promise { 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); } } diff --git a/src/manifest/manifest-sign.action.ts b/src/manifest/manifest-sign.action.ts index f364ecf..36e9abd 100644 --- a/src/manifest/manifest-sign.action.ts +++ b/src/manifest/manifest-sign.action.ts @@ -7,7 +7,7 @@ import { assertFileExists } from "../lib/file"; export async function manifestSignAction(options: ManifestSignOptions): Promise { // 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); diff --git a/src/manifest/manifest-verify.action.ts b/src/manifest/manifest-verify.action.ts index 68f2219..7d2eea9 100644 --- a/src/manifest/manifest-verify.action.ts +++ b/src/manifest/manifest-verify.action.ts @@ -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");