Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the DSSE wrapped private. #966

Merged
merged 1 commit into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions cmd/cosign/cli/verify/verify_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/sigstore/cosign/pkg/cosign/cue"
"github.com/sigstore/cosign/pkg/cosign/pivkey"
sigs "github.com/sigstore/cosign/pkg/signature"
"github.com/sigstore/sigstore/pkg/signature"
)

// VerifyAttestationCommand verifies a signature on a supplied container image
Expand Down Expand Up @@ -80,9 +79,8 @@ func (c *VerifyAttestationCommand) Exec(ctx context.Context, images []string) (e
keyRef := c.KeyRef

// Keys are optional!
var pubKey signature.Verifier
if keyRef != "" {
pubKey, err = sigs.PublicKeyFromKeyRef(ctx, keyRef)
co.SigVerifier, err = sigs.PublicKeyFromKeyRef(ctx, keyRef)
if err != nil {
return errors.Wrap(err, "loading public key")
}
Expand All @@ -92,17 +90,11 @@ func (c *VerifyAttestationCommand) Exec(ctx context.Context, images []string) (e
return errors.Wrap(err, "opening piv token")
}
defer sk.Close()
pubKey, err = sk.Verifier()
co.SigVerifier, err = sk.Verifier()
if err != nil {
return errors.Wrap(err, "initializing piv token verifier")
}
}
if pubKey != nil {
// TODO(vaikas): Should this be private and cosign just figures out
// how to wrap things. This would mean we need to pass more context, so
// just making it like this for now.
co.SigVerifier = cosign.NewReverseDSSEVerifier(pubKey)
}

for _, imageRef := range images {
ref, err := name.ParseReference(imageRef)
Expand Down
12 changes: 10 additions & 2 deletions pkg/cosign/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type reverseDSSEVerifier struct {
signature.Verifier
}

func NewReverseDSSEVerifier(v signature.Verifier) signature.Verifier {
func newReverseDSSEVerifier(v signature.Verifier) signature.Verifier {
return &reverseDSSEVerifier{
Verifier: dsse.WrapVerifier(v),
}
Expand Down Expand Up @@ -164,6 +164,14 @@ func Verify(ctx context.Context, signedImgRef name.Reference, accessor Accessor,
if err != nil {
return err
}

// The fact that there's no signature (or empty rather), implies
// that this is an Attestation that we're verifying. So, we need
// to construct a Verifier that grabs the signature from the
// payload instead of the Signatures annotations.
if len(signature) == 0 {
co.SigVerifier = newReverseDSSEVerifier(co.SigVerifier)
}
if err := co.SigVerifier.VerifySignature(bytes.NewReader(signature), bytes.NewReader(payload), options.WithContext(ctx)); err != nil {
return err
}
Expand Down Expand Up @@ -193,7 +201,7 @@ func Verify(ctx context.Context, signedImgRef name.Reference, accessor Accessor,
// to construct a Verifier that grabs the signature from the
// payload instead of the Signatures annotations.
if len(signature) == 0 {
pub = NewReverseDSSEVerifier(pub)
pub = newReverseDSSEVerifier(pub)
}
if err := pub.VerifySignature(bytes.NewReader(signature), bytes.NewReader(payload), options.WithContext(ctx)); err != nil {
return err
Expand Down