Skip to content

Support verifying embedded SCTs - #84

Merged
woodruffw merged 40 commits into
mainfrom
alex/embedded-sct
Jun 3, 2022
Merged

woodruffw merged 40 commits into
mainfrom
alex/embedded-sct

Conversation

@tetsuo-cpp

@tetsuo-cpp tetsuo-cpp commented May 11, 2022 •

Copy link
Copy Markdown
Contributor

Closes #30
Closes #95

@tetsuo-cpp
tetsuo-cpp marked this pull request as draft May 11, 2022 15:11
Comment thread sigstore/_internal/sct.py Resolved
Comment thread sigstore/_internal/oidc/oauth.py Resolved
@Hayden-IO

Copy link
Copy Markdown
Contributor

I’d recommend continuing to support both detached and embedded SCTs. While the production environment will embed them, organizations may run their own instances of fulcio in a mode that only supports detached SCTs

@woodruffw

Copy link
Copy Markdown
Member

I’d recommend continuing to support both detached and embedded SCTs. While the production environment will embed them, organizations may run their own instances of fulcio in a mode that only supports detached SCTs

Makes sense. Any thoughts on a search priority between the two? In other words, should we check for the sidecar version first and only fall back on the embedded path if it's not present, or should we opportunistically search for the embedded SCT?

@Hayden-IO

Copy link
Copy Markdown
Contributor

Preferring embedded is probably the preferred approach since that'll be what's used in the community instance, and we haven't seen many examples of self-hosted Fulcio instances yet.

@woodruffw

Copy link
Copy Markdown
Member

Blocked on pyca/cryptography#7237 for SignedCertificateTimestamp.extensions and subsequent (not yet issued) PRs for TBS precert bytes.

@woodruffw

Copy link
Copy Markdown
Member

@tetsuo-cpp

tetsuo-cpp commented May 25, 2022 •

Copy link
Copy Markdown
Contributor Author

Still not sure what's going on. I've opened #7267 for visibility as well.

Firstly, I verified that the TBS precertificate with the SCT list extension generated by this code is identical to what is produced by certificate-transparency-go.

Then I generated the entire digitally signed struct (the payload for the signature) in certificate-transparency-go and found that it is also identical to what this code produces. I had to hardcode a few things in the Go code during testing so there's a chance that I've reproduced my mistake in Go, but it seems unlikely.

These are some possibilities for what is wrong:

  • The timestamp is in the wrong format. This seems unlikely but I did need to paste the timestamp integer into the Go code during my testing so if there's a problem with the format, my testing wouldn't have detected it. I think it's pretty straightforward though, just a milliseconds since epoch timestamp. My code does int(sct.timestamp.timestamp() * 1e3) which seems fine. timestamp() returns a float containing a "seconds since epoch" timestamp which we multiply by 1000 to get milliseconds. There doesn't appear to be an accuracy issue here as the seconds count has numbers after the decimal point.
  • I've chosen the wrong issuer for the issuer_key_hash part of the digitally signed struct. I got my Go code to read the signing cert, chain, etc that my Python code produced so if I chose the wrong cert as the issuer, I'd have the same problem in Go. Seems unlikely because I've tried the SCT verification using every cert in the chain and none of them have worked.
  • I'm using the wrong CTFE key. I got the key from https://storage.googleapis.com/tuf-root-staging which I think is correct.
  • My verification call is wrong. So perhaps the digitally signed payload is fine but I'm verifying incorrectly somehow. I'm using PKCS1v15 padding which matches what the IETF spec says.
  • The signature is in the wrong format. I've read through this article again and had a look at how some TLS and DER prefixes had to be stripped away from the signature. I don't think this should apply to us as we would have already decoded this in the Rust. And if I do a hexdump on the signature, I'm not seeing anything that matches those prefixes.

@Hayden-IO

Hayden-IO commented May 25, 2022 •

Copy link
Copy Markdown
Contributor

I've chosen the wrong issuer for the issuer_key_hash part of the digitally signed struct

I agree this is unlikely. The only reason that the issuer would differ between the precert and cert is in the case where the CA has issued a special signing certificate that only signs precerts. We don't use this, the same CA certificate signs both the precert and certificate.

I'm using the wrong CTFE key. I got the key from https://storage.googleapis.com/tuf-root-staging which I think is correct.

I'm assuming you're testing against fulcio.sigstage.dev, and if so, this would be correct.

PKCS1v15 padding

This could be a possibility. If you want to test if this is working with ECDSA signature instead, you could spin up your own local instance of Fulcio with docker-compose up, but there's a few more steps you'll need to follow to set up a signing backend that supports precertificate issuance. Lemme know if you're interested in this, I can write up instructions.

Some random guesses:

  • The order of the extensions has changed? I ran into this issue when I was removing the poison extension in the TBS cert, I shuffled the extensions around
  • Is the correct entry type specified?
  • Is the correct log ID included? It's the SHA1 hash of the public key in the subjectpublickeyinfo asn.1 structure.

@woodruffw

Copy link
Copy Markdown
Member
  • The order of the extensions has changed? I ran into this issue when I was removing the poison extension in the TBS cert, I shuffled the extensions around

This is a good candidate; I'll look into this 🙂

The entry type should be correct, since we're no longer hardcoding 0 and instead getting it directly from the SCT itself. I'll also check on the log ID.

@woodruffw woodruffw changed the title Switch to verifying embedded SCTs Support verifying embedded SCTs May 25, 2022
woodruffw added 2 commits May 25, 2022 16:37
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
@woodruffw

Copy link
Copy Markdown
Member

Just dumping for context: this is how I've added a development build of cryptography to my sigstore-python development environment:

LDFLAGS="-L$(brew --prefix [email protected])/lib" \
  CFLAGS="-I$(brew --prefix [email protected])/include" \
  pip install --editable git+https://github.com/trail-of-forks/cryptography.git@alex/tbs-precert#egg=cryptography

@woodruffw

Copy link
Copy Markdown
Member

The entry type should be correct, since we're no longer hardcoding 0 and instead getting it directly from the SCT itself. I'll also check on the log ID.

Confirmed this:

DEBUG:sigstore._internal.sct:packing SCT: sct.version=<Version.v1: 0> sct.entry_type=<LogEntryType.PRE_CERTIFICATE: 1>

Comment thread sigstore/_internal/sct.py Resolved
@woodruffw

Copy link
Copy Markdown
Member

Signed-off-by: William Woodruff <[email protected]>
@woodruffw

Copy link
Copy Markdown
Member

The order of the extensions has changed? I ran into this issue when I was removing the poison extension in the TBS cert, I shuffled the extensions around

I just dumped our reconstructed tbsCertificate, and the order of the extensions looks right, so I don't think this is it. I noticed that the tbsCertificate doesn't have an X.509 envelope (it's just the raw SEQUENCE), but IIUC that's correct (since it doesn't have a signature).

@tetsuo-cpp

Copy link
Copy Markdown
Contributor Author

The order of the extensions has changed? I ran into this issue when I was removing the poison extension in the TBS cert, I shuffled the extensions around

I just dumped our reconstructed tbsCertificate, and the order of the extensions looks right, so I don't think this is it. I noticed that the tbsCertificate doesn't have an X.509 envelope (it's just the raw SEQUENCE), but IIUC that's correct (since it doesn't have a signature).

Also if I run RemoveSCTList (or whatever the helper from certificate-transparency-go is called) on the TBS bytes, it produces the same thing as the tbs_precertificate_bytes property. So I think this should be ok.

@woodruffw

woodruffw commented May 26, 2022 •

Copy link
Copy Markdown
Member
  • Is the correct log ID included? It's the SHA1 hash of the public key in the subjectpublickeyinfo asn.1 structure.

Where should the log ID be included in the digitally-signed payload? I see it in the SCT structure, but not in the digitally-signed struct that the signature is computed over.

@tetsuo-cpp

tetsuo-cpp commented Jun 1, 2022 •

Copy link
Copy Markdown
Contributor Author

Yep, I can factor it out. And yeah, I’ll also look into unifying it with sigstore’s CLI. Sent from mobile. Please excuse my brevity.
…
On May 31, 2022, at 12:42 PM, Dustin Ingram @.***> wrote:  In order to keep things convenient, we've added the --staged flag to sigstore sign. Using that flag will switch all of the URLs (and baked in root cert) over to the staging instances/endpoints. Could we a) pull this out into a separate PR to discuss and b) potentially align this better with cosign's --rekor-url flag? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

I can remove this and redo it as part of #27 if that works for you. I think it's still useful to have a --staged flag for convenience but maybe it can just be shorthand for setting flags like --fulcio-url and --rekor-url.

@woodruffw

Copy link
Copy Markdown
Member

I can remove this and redo it as part of #27 if that works for you. I think it's still useful to have a --staged flag for convenience but maybe it can just be shorthand for setting flags like --fulcio-url and --rekor-url.

Sounds good! Let's prioritize the --rekor-url and --staging PRs so that we can rebase this on top of them.

@tetsuo-cpp

Copy link
Copy Markdown
Contributor Author

I'll resolve these conflicts in just a moment. Let's get the --staging flag in first.

@woodruffw woodruffw self-assigned this Jun 1, 2022
@woodruffw woodruffw added the upstream Requires upstream work or coordination label Jun 1, 2022
@woodruffw

Copy link
Copy Markdown
Member

Needs rebase, but otherwise the only thing blocking this is an upstream release of cryptography.

@woodruffw woodruffw removed the upstream Requires upstream work or coordination label Jun 3, 2022
@woodruffw

Copy link
Copy Markdown
Member

We've hacked around the upstream requirements, for now. I'm going to push up some more changes to properly mark each hack, so that we can easily undo them later.

@woodruffw
woodruffw marked this pull request as ready for review June 3, 2022 02:34
woodruffw
woodruffw previously approved these changes Jun 3, 2022

@woodruffw woodruffw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Provisionally approving, but @di and @tetsuo-cpp please review one last time!

(I've tested these changes locally and can confirm that sigstore sign and sigstore sign --staged both work. I don't know of a non-embedded SCT instance to test against any more, but these changes should work with one.)

Signed-off-by: William Woodruff <[email protected]>

@tetsuo-cpp tetsuo-cpp left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM! GH won't let me approve this since I opened the PR but the temporary changes you added look fine.

@woodruffw
woodruffw merged commit 59ae3fe into main Jun 3, 2022
@woodruffw
woodruffw deleted the alex/embedded-sct branch June 3, 2022 03:59
javanlacerda pushed a commit to javanlacerda/sigstore-python that referenced this pull request Feb 23, 2024
* Adding several bundle tests:

- Ensure production trust bundle that doesn't validate staging
- Ensure we can't swap in a signed entry timestamp from the future
- Ensure we can detect modifications to the message signature and digest

Signed-off-by: Zach Steindler <[email protected]>

* Fixing type errors from linter

Signed-off-by: Zach Steindler <[email protected]>

---------

Signed-off-by: Zach Steindler <[email protected]>
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.

Support other signature and hash types Switch to verifying embedded SCTs

6 participants