cosign icon indicating copy to clipboard operation
cosign copied to clipboard

cosigned: allow configuring hash algorithm for signature verification

Open nsmith5 opened this issue 2 years ago • 5 comments

Description

The cosign CLI allows setting --signature-digest-algorithm to one of sha224|sha256|sha384|sha512 to accommodate the many hash algorithms that might have been used with elliptical KMS keys. The current ClusterImagePolicy API doesn't have a way to specify the hashing algorithm for verification so it defaults to sha256 and incorrectly rejects signatures with a different hash function.

nsmith5 avatar Apr 19 '22 16:04 nsmith5

@nsmith5 Good catch!

hectorj2f avatar Apr 19 '22 16:04 hectorj2f

FYI I think there's also some major complications around using non-sha256 when you're doing a keyless signature (uploading a rekor entry sort-of-requires that the sig was based off sha256, since we can't get the hash algorithm info that was used from a SignerVerifier right now)

https://github.com/sigstore/cosign/blob/80fe5a31a398c45395d09d23e237c676ddad709f/pkg/cosign/tlog.go#L187-L189

asraa avatar Apr 19 '22 17:04 asraa

Ah ok, my use-case doesn't use Rekor so I didn't hit that. Is that something we can / should change in Rekor ( allow other hash algorithms) or in cosign (restrict to SHA256 only)?

nsmith5 avatar Apr 19 '22 17:04 nsmith5

Ah ok, my use-case doesn't use Rekor so I didn't hit that.

Gotcha! Hmmm I think ideally this is fixed through SignerVerifier exposing the correct SHA, then making cosign pull that info in when creating the rekor entry. Rekor would also need to actually use a customize-able SHA here (https://github.com/sigstore/rekor/blob/c39c0beb340273f0d729f1b853b49691b6445eae/pkg/pki/x509/x509.go#L75) when verifying.

I guess currently we should drop an error that we can't upload if someone uses --signature-digest-algorith

asraa avatar Apr 19 '22 20:04 asraa

It sounds like a plan, then I assume we have to add this functionality to both rekor and cosigned.

hectorj2f avatar Apr 19 '22 21:04 hectorj2f