sigstore: Local Cert verify not working for Azure KMS

Description

Using cosign with Azure KMS results in different behavior for validation with KMS and local pub cert.

cosign  --insecure-ignore-tlog=true verify -key azurekms://keyvault-xyz.vault.azure.net/cosign registryXYZ.azurecr.io/example-func:1.0.0
WARNING: Skipping tlog verification is an insecure practice that lacks of transparency and auditability verification for the signature.

Verification for registryXYZ.azurecr.io/example-func:1.0.0 --
The following checks were performed on each of these signatures:
  - The cosign claims were validated
  - The signatures were verified against the specified public key

But when I use the created public certificate, the result is as follows:

cosign  --insecure-ignore-tlog=true verify -key cosign.pub registryXYZ.azurecr.io/example-func:1.0.0
WARNING: Skipping tlog verification is an insecure practice that lacks of transparency and auditability verification for the signature.
Error: no matching signatures: crypto/rsa: verification error
main.go:69: error during command execution: no matching signatures: crypto/rsa: verification error

I also exported the key again and tried to reproduce, with the same result:

cosign public-key -key azurekms://ckeyvaultXYZ.azure.net/cosign > cosign-new.pub
cosign verify -key cosign-new.pub registryXYZ.azurecr.io/example-func:1.0.0
WARNING: Skipping tlog verification is an insecure practice that lacks of transparency and auditability verification for the signature.
Error: no matching signatures: crypto/rsa: verification error
main.go:69: error during command execution: no matching signatures: crypto/rsa: verification error

Is there anything I did wrong or is there a bug in the verification? –>

Version cosign version GitVersion: v2.2.0 GitCommit: 546f1c5b91ef58d6b034a402d0211d980184a0e5 GitTreeState: clean BuildDate: 2023-08-31T18:52:52Z GoVersion: go1.21.0 Compiler: gc Platform: linux/amd64 –>

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 19 (8 by maintainers)

Most upvoted comments

@malancas I have no idea about GO and only a little bit about cryptography, but as far as I can see, when verified locally, the error is thrown here: https://github.com/golang/go/blob/master/src/crypto/rsa/pkcs1v15.go#L351. Because k = 512 and len(sig) = 524

When verifying against Azure directly, it never reaches this function in this class. I don’t know why. I think the same key should end up in the same description algorithm; it doesn’t matter if it’s stored in a different location. I don’t Know if this helps somehow.

Thanks for the information here, I will look into this code and debug.

I’ve identified the cause of the bug and am currently working on a solution

@malancas I have no idea about GO and only a little bit about cryptography, but as far as I can see, when verified locally, the error is thrown here: https://github.com/golang/go/blob/master/src/crypto/rsa/pkcs1v15.go#L351. Because k = 512 and len(sig) = 524

When verifying against Azure directly, it never reaches this function in this class. I don’t know why. I think the same key should end up in the same description algorithm; it doesn’t matter if it’s stored in a different location. I don’t Know if this helps somehow.

I took a look at this and I think it’s related to the way the azure signer verifier is implemented. The signer ASN.1 encodes the sig payload returned from AKV as an ASN.1 format. I’m not an expert in this but from the code comments it seems that this is part of ECDSA format. This is likely the reason for why RSA verifier throws the length mismatch error? https://github.com/sigstore/sigstore/blob/8b208f7d608b80a7982b2a66358b8333b1eec542/pkg/signature/kms/azure/signer.go#L117

Verifying without downloading the Public Key from AKV uses the azure signer verifiers verify method assumes the sig will be ASN.1 encoded, which is probably why it works.

@malancas Ok, thanks. Yes:

GitVersion: 2.2.2 GitCommit: bf6b57bc3edf8deb7e225e4dbd2d26c0d432979b GitTreeState: “clean” BuildDate: 2023-12-05T18:59:25Z GoVersion: go1.21.4 Compiler: gc Platform: darwin/arm64