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 verification of signatures produced with pki11 #142

Merged

Conversation

flavio
Copy link
Member

@flavio flavio commented Oct 12, 2022

The cosign tool can produce signatures using a PKCS11 token. These signatures feature a certificate annotation inside of their OCI layer.

However, when COSIGN_EXPERIMENTAL is not enabled, the layer will not feature a Rekor bundle.

Prior to this commit, the code assumed signature layers could have a certificate annotation only when using the Fulcio integration. Because of that, layers with a certificate but without a Rekor bundle were discarded. That was done to ensure the robustness of keyless verification.

This commit changes the code that creates SignatureLayer objects to not raise errors when an embedded certificate cannot be verified. Be it because it has been forged/invalid/etc or because the Rekor bundle is not found inside of the layer.

The resulting SignatureLayer will not be discarded, but it will have its certificate_signature attribute set to None.

Note: SignatureLayer::certificate_signature was already a Option before of this commit.

The verification constraints implementing keyless verification will discard these kind of layers because they do not have a certificate_signature.

However, the public key based verifier will be able to verify the signature stored inside of the layer.

This solves the following scenario:

Given Alice signed a container image using a PKCS11 token but without having cosign's Rekor integration enabled
When verifying the container image signature using the public key associated with the certificate stored on her PKCS11 token
Then the container image will be reported as successfully verified

Fixes #135

The documentation of the `SignatureLayer::new` method was mentioning
a parameter that no longer exists.

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
The `cosign` tool can produce signatures using a PKCS11 token. These
signatures feature a `certificate` annotation inside of their OCI layer.

However, when `COSIGN_EXPERIMENTAL` is not enabled, the layer will not
feature a Rekor bundle.

Prior to this commit, the code assumed signature layers could have a
`certificate` annotation only when using the Fulcio integration. Because
of that, layers with a `certificate` but without a Rekor bundle were
discarded. That was done to ensure the robustness of keyless
verification.

This commit changes the code that creates `SignatureLayer` objects to not
raise errors when an embedded certificate cannot be verified. Be it
because it has been forged/invalid/etc or because the Rekor bundle is
not found inside of the layer.

The resulting `SignatureLayer` will not be discarded, but it will have
its `certificate_signature` attribute set to `None`.

> **Note:** `SignatureLayer::certificate_signature` was already a `Option`
> before of this commit.

The verification constraints implementing keyless verification will
discard these kind of layers because they do not have a
`certificate_signature`.

However, the public key based verifier will be able to verify the
signature stored inside of the layer.

This solves the following scenario:

> Given Alice signed a container image using a PKCS11 token but without having cosign's Rekor integration enabled
> When verifying the container image signature using the public key associated with the certificate stored on her PKCS11 token
> Then the container image will be reported as successfully verified

Fixes sigstore#135

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
@flavio flavio force-pushed the fix-verification-of-signatures-produced-with-pki11 branch from 523650e to 5b1fae7 Compare October 12, 2022 15:38
Address clippy and rustfmt warnings

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
@flavio flavio force-pushed the fix-verification-of-signatures-produced-with-pki11 branch from b337376 to 51fcde8 Compare October 12, 2022 15:53
SigstoreError::SigstoreFulcioCertificatesNotProvidedError
));
);
assert!(cert.is_none());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test functions should be renamed now, e.g:

get_certificate_signature_from_annotations_fails_when_no_bundle_is_given()
get_certificate_signature_from_annotations_fails_when_no_fulcio_pub_key_is_given()

should be renamed to [...]_returns_none()

Copy link
Collaborator

@viccuad viccuad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! just a minor nit.

@raulcabello
Copy link
Contributor

I like this approach. This PR fix #135 by not failing if the certificate in the dev.sigstore.cosign/certificate annotation is present when there is no rekor bundle, which is a valid scenario as explained above.
Public key will still be verified in the PublicKeyVerifier.
Keyless verification will keep working as expected as rekor bundle should be present. If it is not present verification will fail because the certificate_signature will be None in the CertSubjectEmailVerifier or CertSubjectUrlVerifier

@flavio flavio merged commit 77db1bb into sigstore:main Oct 13, 2022
@flavio flavio deleted the fix-verification-of-signatures-produced-with-pki11 branch October 13, 2022 15:11
flavio added a commit to flavio/sigstore-rs that referenced this pull request Oct 13, 2022
Fixes
=====

* fix verification of signatures produced with PKI11 (sigstore#142)

Others
======

* Update rsa dependency to stable version 0.7.0 (sigstore#141)
* Bump actions/checkout from 3.0.2 to 3.1.0 (sigstore#140)

Contributors
============

* Flavio Castelli (@flavio)
* Xynnn (@Xynnn007)

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Verify not working if the certificate annotation is present and there is no bundle annotation
3 participants