Repository navigation
Implement SCT verification - #24
Conversation
|
This PR is based off the branch implementing the sign command. Unfortunately I can't point this PR at the sign branch and show the changes in isolation because the sign branch belongs to a fork. At the moment, I can't seem to get the verification to work and am trying to figure out why (it's not very debuggable since it just throws a signature mismatch). I assume I'm somehow misconstructing the digitally signed part. I've actually tried hacking https://github.com/pierky/sct-verify to use the SCT, certificate, etc from a Fulcio example but I can't even get that to verify correctly. So whatever mistake I'm making, I'm reproducing it there too. I'll continue investigating this... |
c2cacb0 to
69e472a
Compare
69e472a to
0ec1a69
Compare
|
Have you taken a look at https://pypi.org/project/ctutlz/ or https://github.com/theno/ctutlz? Digging through the code a bit, this should provide the utilities that you need to verify SCTs. See for example https://github.com/theno/ctutlz/blob/db8efcf785efb4dcc7324ddba629d49e743890be/ctutlz/scripts/verify_scts.py#L94-L109, which handles verification of embedded SCTs. Something to note: Fulcio is currently returning SCTs detached, not embedded in the certificate. I'm actively working on changing Fulcio to generate certificates with embedded SCTs. If you want to test against the live instance of Fulcio, you might have to hack around |
|
If you're seeing signature validation errors, it's likely that the bits that you're verifying are not the same bits that the CT log signed. For example, you need to consider that CT entry signature is generated over the TBS (to-be-signed) portion of the certificate (no cert signature), and it excludes the CT log extension. Additionally when reconstructing the merkle leaf to verify the signature, you will need to include the hash of the public key of the issuing certificate.
|
|
Thanks for the information @haydentherapper. Sorry for the late reply, I've only just been able to revisit this now.
I was looking at
This is the way that Regarding the point about "excluding the CT log extension", does that mean that the extension length should not go at the end of the data to be signed? The structure looks like this, but I'm continuing to investigate. |
There's two ways to verify an SCT. One is by verifying a detached SCT, where the SCT is presented alongside the certificate - The signature input is generated here, what you linked above. The other way is by verifying an SCT that's embedded in the certificate, meaning you don't have to store the SCT alongside the certificate since the SCT is embedded in an X.509 extension. That's constructed here. When I mentioned "excluding the CT log extension", this is referring to the construction of the signature input for embedded SCT verification. The lengths are still included. There are certain extensions (here] that are excluded when building the input. Note that Fulcio currently only supports detached SCTs, but in the coming weeks, will support both. I'd recommend preferring the latter, embedded SCTs, because it allows you to verify the SCT any time you use the certificate. Looking again at the first case, a detached SCT, I'm a bit confused why the ctutlz library doesn't use the TBS portion of the signature here when constructing the input. The DER encoding is not the same as the TBS portion. This could be the issue? |
|
Thanks for explaining.
I've talked to @di about this recently and our plan at the moment is to begin by supporting detached SCTs and then move to supporting embedded SCTs later. The reason is that we're intending to demo this functionality soon.
From looking at the RFC, it only specifies to use the TBS portion for the PreCert case. It isn't clear to me whether that's how it works for the ASN.1 case but I just assumed because |
I have no idea why this works.
|
It looks like there are a few flags preceding the signature that are added here. The code comment refers an RFC describing TLS encoding here. If I inspect an SCT that I recorded like this, I can see the flag values: The first two bytes contain sensible values for the type of signature we're getting so I believe we're interpreting that correctly. The only question remaining for me is why we have to discard 4 bytes instead of 2. I can't see Fulcio putting anything else into the signature and the RFC describing TLS encoding doesn't say anything about padding between values. |
|
I think you may have just found this, but we are actually sending a slightly different struct back to the client - https://github.com/sigstore/fulcio/blob/main/pkg/api/grpc_server.go#L135 This was not intentional, but when I found this, I didn’t want to break existing clients, so we left the struct as is. The embedded SCT will be in the correct format. |
|
Thanks for pointing that out! So, to clarify: the |
|
That's correct, the embedded SCT will be the SignedCertificateTimestampList as defined in https://datatracker.ietf.org/doc/html/rfc6962#section-3.3. Given this confusion, I'm considering just changing the detached SCT to the proper value, a |
* Remove Docker infrastructure * Create initial `sigstore-conformance` GitHub Action * Code documentation * Fix test comment * Add variable for debug logging * Add linting to CI * Add selftest to conformance test `sigstore-python` * Make `action.py` executable * Check in missing init file * Rename selftest job * Use mypy and fix errors * Make mypy ignore the pytest import * Reword entrypoint documentation * Move token permissions into selftest job * Remove explicit workspace param * Add more assertions to basic test * It's a method not a property * The client parameterization doesn't need to be a dynamic fixture
Closes #22