Skip to content

Commit 2e60ff0

Browse files
author
Ian Lewis
authored
fix: Read newer attestation file format (#564)
* Read newer attestation file format Signed-off-by: Ian Lewis <[email protected]> * Update error message Signed-off-by: Ian Lewis <[email protected]> * revert change Signed-off-by: Ian Lewis <[email protected]> * Update test data Signed-off-by: Ian Lewis <[email protected]> --------- Signed-off-by: Ian Lewis <[email protected]>
1 parent c0cadc0 commit 2e60ff0

11 files changed

+782
-760
lines changed

cli/slsa-verifier/verify/verify_npm_package.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (c *VerifyNpmPackageCommand) Exec(ctx context.Context, tarballs []string) (
5454
}
5555

5656
if c.AttestationsPath == "" {
57-
fmt.Fprintf(os.Stderr, "Verifying npm package %s: FAILED: %v\n\n", tarball, err)
57+
fmt.Fprintf(os.Stderr, "--attestations-path is required.\n\n")
5858
return nil, err
5959
}
6060
provenanceOpts := &options.ProvenanceOpts{

verifiers/internal/gha/npm.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ NOTE: key available at https://registry.npmjs.org/-/npm/v1/keys
4444
*/
4545
var npmRegistryPublicKey = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE1Olb3zMAFFxXKHiIkQO5cJ3Yhl5i6UPp+IhuteBJbuHcA5UogKo0EWtlWwW6KSaKoTNEYL7JlCQiVnkhBktUgg=="
4646

47+
type attestationSet struct {
48+
Attestations []attestation `json:"attestations"`
49+
}
50+
4751
type attestation struct {
4852
PredicateType string `json:"predicateType"`
4953
BundleBytes BundleBytes `json:"bundle"`
@@ -74,12 +78,12 @@ func (n *Npm) ProvenanceLeafCertificate() *x509.Certificate {
7478
}
7579

7680
func NpmNew(ctx context.Context, root *TrustedRoot, attestationBytes []byte) (*Npm, error) {
77-
var attestations []attestation
78-
if err := json.Unmarshal(attestationBytes, &attestations); err != nil {
81+
var aSet attestationSet
82+
if err := json.Unmarshal(attestationBytes, &aSet); err != nil {
7983
return nil, fmt.Errorf("%w: json.Unmarshal: %v", errrorInvalidAttestations, err)
8084
}
8185

82-
prov, pub, err := extractAttestations(attestations)
86+
prov, pub, err := extractAttestations(aSet.Attestations)
8387
if err != nil {
8488
return nil, err
8589
}

verifiers/internal/gha/testdata/npm-att-mismatch-prov-payloadtype.intoto.sigstore

+86-84
Large diffs are not rendered by default.

verifiers/internal/gha/testdata/npm-att-mismatch-prov-predicatetype.intoto.sigstore

+86-84
Large diffs are not rendered by default.

verifiers/internal/gha/testdata/npm-att-mismatch-pub-payloadtype.intoto.sigstore

+86-84
Large diffs are not rendered by default.

verifiers/internal/gha/testdata/npm-att-mismatch-pub-predicatetype.intoto.sigstore

+86-84
Large diffs are not rendered by default.

verifiers/internal/gha/testdata/npm-attestations.intoto.sigstore

+86-84
Large diffs are not rendered by default.

verifiers/internal/gha/testdata/npm-stmt-mismatch-prov-predicatetype.intoto.sigstore

+86-84
Large diffs are not rendered by default.

verifiers/internal/gha/testdata/npm-stmt-mismatch-prov-type.intoto.sigstore

+86-84
Large diffs are not rendered by default.

verifiers/internal/gha/testdata/npm-stmt-mismatch-pub-predicatetype.intoto.sigstore

+86-84
Large diffs are not rendered by default.

verifiers/internal/gha/testdata/npm-stmt-mismatch-pub-type.intoto.sigstore

+86-84
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)