Skip to content

Commit

Permalink
add verify-signature command. Fixes #1044 (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 authored Sep 3, 2024
1 parent e646982 commit 164eebd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import program from 'commander';
import leven from 'leven';
import { packageCommand, ls, Targets, generateManifest } from './package';
import { packageCommand, ls, Targets, generateManifest, verifySignature } from './package';
import { publish, unpublish } from './publish';
import { show } from './show';
import { search } from './search';
Expand Down Expand Up @@ -317,6 +317,14 @@ module.exports = function (argv: string[]): void {
.option('-o, --out <path>', 'Output the extension manifest to <path> location (defaults to <packagename>.manifest)')
.action(({ packagePath, out }) => main(generateManifest(packagePath, out)));

program
.command('verify-signature')
.description('Verifies the provided signature file against the provided VSIX package and manifest.')
.requiredOption('-i, --packagePath <path>', 'Path to the VSIX package')
.requiredOption('-m, --manifestPath <path>', 'Path to the Manifest file')
.requiredOption('-s, --signaturePath <path>', 'Path to the Signature file')
.action(({ packagePath, manifestPath, signaturePath }) => main(verifySignature(packagePath, manifestPath, signaturePath)));

program
.command('ls-publishers')
.description('Lists all known publishers')
Expand Down
13 changes: 13 additions & 0 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,19 @@ export function generateManifest(packageFile: string, outputFile?: string): Prom
return vsceSign.generateManifest(packageFile, outputFile);
}

export async function verifySignature(packageFile: string, manifestFile: string, signatureFile: string): Promise<void> {
const sigzipPath = await createSignatureArchive(manifestFile, signatureFile);
try {
const result = await vsceSign.verify(packageFile, sigzipPath, true);
console.log(`Signature verification result: ${result.code}`);
if (result.output) {
console.log(result.output)
}
} finally {
await fs.promises.unlink(sigzipPath);
}
}

// Create a signature zip file containing the manifest and signature file
export async function createSignatureArchive(manifestFile: string, signatureFile: string, outputFile?: string): Promise<string> {
return vsceSign.zip(manifestFile, signatureFile, outputFile)
Expand Down

0 comments on commit 164eebd

Please sign in to comment.