Skip to content

Commit

Permalink
fix: Read newer attestation file format (#564)
Browse files Browse the repository at this point in the history
* Read newer attestation file format

Signed-off-by: Ian Lewis <ianlewis@google.com>

* Update error message

Signed-off-by: Ian Lewis <ianlewis@google.com>

* revert change

Signed-off-by: Ian Lewis <ianlewis@google.com>

* Update test data

Signed-off-by: Ian Lewis <ianlewis@google.com>

---------

Signed-off-by: Ian Lewis <ianlewis@google.com>
  • Loading branch information
ianlewis authored Apr 20, 2023
1 parent c0cadc0 commit 2e60ff0
Show file tree
Hide file tree
Showing 11 changed files with 782 additions and 760 deletions.
2 changes: 1 addition & 1 deletion cli/slsa-verifier/verify/verify_npm_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *VerifyNpmPackageCommand) Exec(ctx context.Context, tarballs []string) (
}

if c.AttestationsPath == "" {
fmt.Fprintf(os.Stderr, "Verifying npm package %s: FAILED: %v\n\n", tarball, err)
fmt.Fprintf(os.Stderr, "--attestations-path is required.\n\n")
return nil, err
}
provenanceOpts := &options.ProvenanceOpts{
Expand Down
10 changes: 7 additions & 3 deletions verifiers/internal/gha/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ NOTE: key available at https://registry.npmjs.org/-/npm/v1/keys
*/
var npmRegistryPublicKey = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE1Olb3zMAFFxXKHiIkQO5cJ3Yhl5i6UPp+IhuteBJbuHcA5UogKo0EWtlWwW6KSaKoTNEYL7JlCQiVnkhBktUgg=="

type attestationSet struct {
Attestations []attestation `json:"attestations"`
}

type attestation struct {
PredicateType string `json:"predicateType"`
BundleBytes BundleBytes `json:"bundle"`
Expand Down Expand Up @@ -74,12 +78,12 @@ func (n *Npm) ProvenanceLeafCertificate() *x509.Certificate {
}

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

prov, pub, err := extractAttestations(attestations)
prov, pub, err := extractAttestations(aSet.Attestations)
if err != nil {
return nil, err
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

170 changes: 86 additions & 84 deletions verifiers/internal/gha/testdata/npm-attestations.intoto.sigstore

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 2e60ff0

Please sign in to comment.