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

Fix: Create a static copy of signatures as part of verification. #2287

Merged
merged 1 commit into from
Sep 27, 2022
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
10 changes: 10 additions & 0 deletions pkg/cosign/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ func verifySignatures(ctx context.Context, sigs oci.Signatures, h v1.Hash, co *C
validationErrs := []string{}

for _, sig := range sl {
sig, err := static.Copy(sig)
if err != nil {
validationErrs = append(validationErrs, err.Error())
continue
}
verified, err := VerifyImageSignature(ctx, sig, h, co)
bundleVerified = bundleVerified || verified
if err != nil {
Expand Down Expand Up @@ -702,6 +707,11 @@ func verifyImageAttestations(ctx context.Context, atts oci.Signatures, h v1.Hash

validationErrs := []string{}
for _, att := range sl {
att, err := static.Copy(att)
if err != nil {
validationErrs = append(validationErrs, err.Error())
continue
}
if err := func(att oci.Signature) error {
verifier := co.SigVerifier
if verifier == nil {
Expand Down
52 changes: 52 additions & 0 deletions pkg/oci/static/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,58 @@ func NewAttestation(payload []byte, opts ...Option) (oci.Signature, error) {
return NewSignature(payload, "", opts...)
}

// Copy constructs a new oci.Signature from the provided one.
func Copy(sig oci.Signature) (oci.Signature, error) {
payload, err := sig.Payload()
if err != nil {
return nil, err
}
b64sig, err := sig.Base64Signature()
if err != nil {
return nil, err
}
var opts []Option

mt, err := sig.MediaType()
if err != nil {
return nil, err
}
opts = append(opts, WithLayerMediaType(mt))

ann, err := sig.Annotations()
if err != nil {
return nil, err
}
opts = append(opts, WithAnnotations(ann))

bundle, err := sig.Bundle()
if err != nil {
return nil, err
}
opts = append(opts, WithBundle(bundle))

cert, err := sig.Cert()
if err != nil {
return nil, err
}
if cert != nil {
rawCert, err := cryptoutils.MarshalCertificateToPEM(cert)
if err != nil {
return nil, err
}
chain, err := sig.Chain()
if err != nil {
return nil, err
}
rawChain, err := cryptoutils.MarshalCertificatesToPEM(chain)
if err != nil {
return nil, err
}
opts = append(opts, WithCertChain(rawCert, rawChain))
}
return NewSignature(payload, b64sig, opts...)
}

type staticLayer struct {
b []byte
b64sig string
Expand Down