Skip to content

Commit

Permalink
add --trusted-root flag to conformance CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Brian DeHamer <[email protected]>
  • Loading branch information
bdehamer committed Dec 15, 2023
1 parent 57bec90 commit e06953a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-apricots-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sigstore/conformance": minor
---

Updates the `verify-bundle` subcommand with support for a new `--trusted-root` flag
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/conformance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
},
"dependencies": {
"@oclif/core": "^3",
"@sigstore/bundle": "^2.1.0",
"@sigstore/protobuf-specs": "^0.2.1",
"@sigstore/verify": "^0.0.0",
"sigstore": "^2.0.0"
},
"devDependencies": {
Expand Down
36 changes: 31 additions & 5 deletions packages/conformance/src/commands/verify-bundle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Args, Command, Flags } from '@oclif/core';
import { bundleFromJSON } from '@sigstore/bundle';
import { TrustedRoot } from '@sigstore/protobuf-specs';
import { Verifier, toSignedEntity, toTrustMaterial } from '@sigstore/verify';
import fs from 'fs/promises';
import * as sigstore from 'sigstore';

Expand All @@ -17,6 +20,10 @@ export default class VerifyBundle extends Command {
description: 'the expected OIDC issuer for the signing certificate',
required: true,
}),
'trusted-root': Flags.string({
description: 'path to trusted root',
required: false,
}),
};

static override args = {
Expand All @@ -34,12 +41,31 @@ export default class VerifyBundle extends Command {
.readFile(flags.bundle)
.then((data) => JSON.parse(data.toString()));
const artifact = await fs.readFile(args.file);
const trustedRootPath = flags['trusted-root'];

if (!trustedRootPath) {
const options: Parameters<typeof sigstore.verify>[2] = {
certificateIdentityURI: flags['certificate-identity'],
certificateIssuer: flags['certificate-oidc-issuer'],
};

const options: Parameters<typeof sigstore.verify>[2] = {
certificateIdentityURI: flags['certificate-identity'],
certificateIssuer: flags['certificate-oidc-issuer'],
};
sigstore.verify(bundle, artifact, options);
} else {
// Need to assemble the Verifier manually to pass in the trusted root
const trustedRoot = await fs
.readFile(trustedRootPath)
.then((data) => JSON.parse(data.toString()));
const trustMaterial = toTrustMaterial(TrustedRoot.fromJSON(trustedRoot));
const signedEntity = toSignedEntity(bundleFromJSON(bundle), artifact);
const policy = {
subjectAlternativeName: flags['certificate-identity'],
extensions: {
issuer: flags['certificate-oidc-issuer'],
},
};

sigstore.verify(bundle, artifact, options);
const verifier = new Verifier(trustMaterial);
verifier.verify(signedEntity, policy);
}
}
}

0 comments on commit e06953a

Please sign in to comment.