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

Updates to Timestamp signing and verification #2499

Merged
merged 8 commits into from Dec 7, 2022

Conversation

haydentherapper
Copy link
Contributor

@haydentherapper haydentherapper commented Nov 30, 2022

  • Switch to using the raw signature rather than base64 signature for OCI and blob signing
  • For blob signing, write only the timestamp to disk, not the LocalSignedPayload (since that's already written with the bundle. I want to avoid conflating the Rekor bundle with the TS)
  • For blob verification, expect only a timestamp in the file. If you don't pass a bundle, you'll need to also pass the signature by flag
  • Some nits from the previous PR

Signed-off-by: Hayden Blauzvern hblauzvern@google.com

Summary

Release Note

Documentation

@haydentherapper
Copy link
Contributor Author

Still working on e2e testing and some more unit tests, but just wanted to get this up early for feedback

@codecov-commenter
Copy link

codecov-commenter commented Nov 30, 2022

Codecov Report

Merging #2499 (a4eb7ba) into main (f7f7f3d) will increase coverage by 0.31%.
The diff coverage is 38.46%.

@@            Coverage Diff             @@
##             main    #2499      +/-   ##
==========================================
+ Coverage   29.62%   29.94%   +0.31%     
==========================================
  Files         139      139              
  Lines        8558     8557       -1     
==========================================
+ Hits         2535     2562      +27     
+ Misses       5666     5640      -26     
+ Partials      357      355       -2     
Impacted Files Coverage Δ
cmd/cosign/cli/options/signblob.go 0.00% <0.00%> (ø)
cmd/cosign/cli/options/verify.go 0.00% <0.00%> (ø)
cmd/cosign/cli/policy_init.go 1.25% <0.00%> (+<0.01%) ⬆️
cmd/cosign/cli/sign/sign_blob.go 0.00% <0.00%> (ø)
cmd/cosign/cli/verify.go 0.00% <0.00%> (ø)
pkg/cosign/bundle/tsa.go 100.00% <ø> (ø)
pkg/cosign/fetch.go 0.00% <ø> (ø)
internal/pkg/cosign/tsa/signer.go 51.42% <50.00%> (-2.31%) ⬇️
cmd/cosign/cli/verify/verify_blob.go 49.09% <55.55%> (+3.52%) ⬆️
pkg/cosign/verify.go 38.73% <70.83%> (+2.69%) ⬆️
... and 3 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@haydentherapper haydentherapper changed the title WIP: Updates to Timestamp signing and verification Updates to Timestamp signing and verification Nov 30, 2022
@haydentherapper
Copy link
Contributor Author

haydentherapper commented Nov 30, 2022

Now it should be good to go, would like to add some more tests in verify-blob for completeness, but might do that in a follow up.

@@ -552,6 +525,10 @@ func TestVerifyBlob(t *testing.T) {
expiredLeafPem, true)},
shouldErr: true,
},
// TODO: Add tests for TSA:
Copy link
Contributor

Choose a reason for hiding this comment

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

This basically removes tests that we had in place. I am not sure we want to change functionality and remove tests. How does it work if I only sign/verify a blob without using tlog ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I plan to add some more tests in, but the presence of the bundle is just a way to get the signature and/or other timestamp. If you don't use the tlog, then you must provide the cert/sig the same way you currently do, via --certificate/--signature flags.

This PR should only be adding in tests, and refactoring tests based on the proposed changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With these changes, it actually requires less tests since this is only an additional flag that affects verification, rather than modifying codepaths that read in the cert/signature.

@haydentherapper
Copy link
Contributor Author

Verified with a local TSA instance:

# Sign blob and upload to Rekor
cosign sign-blob --timestamp-server-url http://localhost:3000 --rfc3161-timestamp tsaresponse --tlog-upload=true --output-certificate=blob.cert --output-signature=blob.sig --bundle blob.bundle blob

# Verify with local Rekor bundle
cosign verify-blob --rfc3161-timestamp tsaresponse --bundle blob.bundle --timestamp-cert-chain tsacertchain blob

# Verify with skipping checking Rekor
cosign verify-blob --rfc3161-timestamp tsaresponse --timestamp-cert-chain tsacertchain --certificate blob.cert --signature blob.sig --insecure-skip-tlog-verify --offline blob

# Sign blob without Rekor upload
cosign sign-blob --timestamp-server-url http://localhost:3000 --rfc3161-timestamp tsaresponse --tlog-upload=false --output-certificate=blob.cert --output-signature=blob.sig  blob

An unrelated issue is if I skip tlog-upload, then I can't output a certificate (cosign sign-blob --timestamp-server-url http://localhost:3000 --rfc3161-timestamp tsaresponse --tlog-upload=false --output-certificate=blob.cert --output-signature=blob.sig blob fails to output a cert), so I can't verify. I'll fix this separately.

Copy link
Contributor

@hectorj2f hectorj2f left a comment

Choose a reason for hiding this comment

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

LGTM, I added some nit comments. Ideally, I'd like to see some tests to validate the usage of the rfc3161timestamp with blobs.

cmd/cosign/cli/options/verify.go Outdated Show resolved Hide resolved
cmd/cosign/cli/sign/sign_blob.go Show resolved Hide resolved
specs/SIGNATURE_SPEC.md Outdated Show resolved Hide resolved
cmd/cosign/cli/verify/verify_blob.go Show resolved Hide resolved
@haydentherapper haydentherapper mentioned this pull request Dec 5, 2022
3 tasks
Copy link
Contributor

@znewman01 znewman01 left a comment

Choose a reason for hiding this comment

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

Some nits but overall great changes

cmd/cosign/cli/sign/sign_blob.go Outdated Show resolved Hide resolved
internal/pkg/cosign/tsa/signer.go Show resolved Hide resolved
internal/pkg/cosign/tsa/signer.go Show resolved Hide resolved
pkg/cosign/verify.go Show resolved Hide resolved
znewman01
znewman01 previously approved these changes Dec 6, 2022
cmd/cosign/cli/verify/verify_blob.go Outdated Show resolved Hide resolved
cmd/cosign/cli/sign/sign_blob.go Outdated Show resolved Hide resolved
// TODO: Consider uploading RFC3161 TS to Rekor

if rfc3161Timestamp == nil {
return nil, fmt.Errorf("rfc3161 timestamp is nil")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do these checks before signing etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a just-in-case check, since TimestampToRFC3161Timestamp might return nil if respBytes is empty for some reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah. Maybe both wouldn't be a bad idea, up to you

znewman01
znewman01 previously approved these changes Dec 6, 2022
// TODO: Consider uploading RFC3161 TS to Rekor

if rfc3161Timestamp == nil {
return nil, fmt.Errorf("rfc3161 timestamp is nil")
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah. Maybe both wouldn't be a bad idea, up to you

* Switch to using the raw signature rather than base64 signature for OCI
  and blob signing
* For blob signing, write only the timestamp to disk, not the
  LocalSignedPayload (since that's already written with the bundle)
* For blob verification, expect only a timestamp in the file. If you
  don't pass a bundle, you'll need to also pass the signature by flag
* Some nits from the previous PR

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
Copy link
Contributor

@hectorj2f hectorj2f left a comment

Choose a reason for hiding this comment

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

lgtm

@hectorj2f hectorj2f merged commit e9e9cb2 into sigstore:main Dec 7, 2022
@github-actions github-actions bot added this to the v1.14.0 milestone Dec 7, 2022
@haydentherapper haydentherapper deleted the fix-tsa branch December 7, 2022 16:33
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.

None yet

5 participants