Skip to content

Switch to verifying embedded SCTs #30

Closed

Description

@tetsuo-cpp

As mentioned at #24 (comment), Fulcio will soon be supporting embedded SCTs. We should switch over to using them at some point.

Activity

  1. added
    enhancement
    on Apr 22, 2022
  2. added
    component:verification
    upstream
    on Apr 22, 2022
  3. Hayden-IO commented on May 3, 2022

    @Hayden-IO
    Contributor

    Just wanted to ping this bug - Is this something that you're planning to add soon? We're planning to update prod Fulcio soon and I'd like to avoid breaking any clients.

    If you want to test against a live instance, staging Fulcio uses embedded SCTs now. It's accessible at fulcio.sigstage.dev, and verification key material is accessible on GCS, gs://tuf-root-staging.

  4. self-assigned this
    on May 3, 2022
  5. woodruffw commented on May 3, 2022

    @woodruffw
    Member

    Just wanted to ping this bug - Is this something that you're planning to add soon? We're planning to update prod Fulcio soon and I'd like to avoid breaking any clients.

    Yes, we can prioritize it now. @tetsuo-cpp I saw you self-assigned, feel free to pri and I'll take over #62 🙂.

  6. woodruffw commented on May 5, 2022

    @woodruffw
    Member
  7. tetsuo-cpp commented on May 8, 2022

    @tetsuo-cpp
    ContributorAuthor

    I think I have the necessary changes for cryptography. My issue right now is that the staging Fulcio is signing with an RSA key as opposed to an ECDSA one like prod. I see some changes that went into cosign recently to support different key types so that explains why.

    The verify method exposed by cryptography's key types takes different arguments for different key types so it's not possible to just call verify blindly without knowing what kind of key it is. This compared with this.

    I think I'm going to follow up with a separate PR for the different key types.

  8. Hayden-IO commented on May 8, 2022

    @Hayden-IO
    Contributor

    This is unfortunately something I've taken for granted in Go vs. other languages, the cryto.PublicKey abstraction layer. We were previously assuming ECDSA keys in all of the infrastructure, but when staging was set up with an RSA key (which is a valid configuration for a CT log), we removed the remaining assumptions around ECDSA keys.

    It's also worth noting that Fulcio accepts ECDSA, RSA, or ED25519 keys in its issued certificates also.

  9. tetsuo-cpp commented on May 9, 2022

    @tetsuo-cpp
    ContributorAuthor

    Leaving an update on how this is going. At the moment, I'm trying to put together the digitally signed portion and get SCT verification to pass again.

    The less straightforward part of that is that the signing certificate has to be manipulated before being DER encoded. So the CT poison extension has to be removed and I believe the issuer has to be changed (still figuring out why/how this works). The Go equivalent is here.

    We'll need to get another change into cryptography in order for this to work. So at the moment, certificates have a property called tbs_certificate_bytes that give the DER encoding of the TBS certificate. But we'll also need a property to access the one with the extension removed, issuer changed, etc. Not sure how easy that will be to get in. The code that does this manipulation to the TBS certificate can't be in our application as it's the Rust internals that have access to this information.

  10. Hayden-IO commented on May 9, 2022

    @Hayden-IO
    Contributor

    For the issuer, this is the key hash of the issuer public key - https://datatracker.ietf.org/doc/html/rfc6962#section-3.2

    This is just for embedded SCTs, since the precertificate is what's included in the transparency log, and the client has to reconstruct the original merkle tree leaf that was included in the log.

  11. woodruffw commented on May 10, 2022

    @woodruffw
    Member

    For the issuer, this is the key hash of the issuer public key - https://datatracker.ietf.org/doc/html/rfc6962#section-3.2

    This might be a misreading on my part, but 6962 seems to say that the hash of the issuer's pubkey is adjacent to the TBSCertificate, not embedded within it:

    "issuer_key_hash" is the SHA-256 hash of the certificate issuer's
    public key, calculated over the DER encoding of the key represented
    as SubjectPublicKeyInfo. This is needed to bind the issuer to the
    final certificate.

    "tbs_certificate" is the DER-encoded TBSCertificate (see [RFC5280])
    component of the Precertificate -- that is, without the signature and
    the poison extension. If the Precertificate is not signed with the
    CA certificate that will issue the final certificate, then the
    TBSCertificate also has its issuer changed to that of the CA that
    will issue the final certificate. Note that it is also possible to
    reconstruct this TBSCertificate from the final certificate by
    extracting the TBSCertificate from it and deleting the SCT extension.
    Also note that since the TBSCertificate contains an
    AlgorithmIdentifier that must match both the Precertificate signature
    algorithm and final certificate signature algorithm, they must be
    signed with the same algorithm and parameters. If the Precertificate
    is issued using a Precertificate Signing Certificate and an Authority
    Key Identifier extension is present in the TBSCertificate, the
    corresponding extension must also be present in the Precertificate
    Signing Certificate -- in this case, the TBSCertificate also has its
    Authority Key Identifier changed to match the final issuer.

  12. Hayden-IO commented on May 10, 2022

    @Hayden-IO
    Contributor

    Yes, it's for rebuilding the merkle tree leaf.

  13. woodruffw commented on May 10, 2022

    @woodruffw
    Member

    Gotcha -- so in that case the TBSCertificate itself doesn't need to have its issuer rewritten, right? It only needs to have its extensions filtered?

  14. Hayden-IO commented on May 10, 2022

    @Hayden-IO
    Contributor

    Correct!

  15. tetsuo-cpp commented on May 11, 2022

    @tetsuo-cpp
    ContributorAuthor

    It's not ready yet, but I've pushed up #84 just for visibility. To my knowledge, I've covered everything but something isn't right.

    Again, I'm hitting SCT verification errors so I'm at that stage where I'm poring over the relevant RFCs and comparing with the Go source trying to spot the difference. Will continue fiddling around with this and hopefully figure it out.

  16. tetsuo-cpp commented on May 12, 2022

    @tetsuo-cpp
    ContributorAuthor

    Haven't noticed anything wrong with the digitally signed payload yet. Tried fiddling around with the format, tried different certificates in the chain as the issuer, etc... but no luck. At the moment, I'm trying to build a test program that uses certificate-transparency-go so I can compare it to what sigstore-python is assembling.

    The TBS certificate is probably the most suspicious part since we're having to do some manipulation on the extensions. So I'm planning to dump the issuing certificate from sigstore-python into a file, get the defanged TBS from the Go libs and then compare it to what we got from cryptography.

  17. woodruffw commented on May 12, 2022

    @woodruffw
    Member

    @tetsuo-cpp For debugging, you might ascii2der and der2ascii helpful as well: https://github.com/google/der-ascii

    (Thanks to @reaperhulk for showing me these.)

  18. woodruffw commented on May 16, 2022

    @woodruffw
    Member

    The code for this has landed upstream: pyca/cryptography#7207

    We just need a release on their side. In the mean time, we can probably use pip's git support on the development branch.

  19. tetsuo-cpp commented on May 20, 2022

    @tetsuo-cpp
    ContributorAuthor

    I have a Go program using certificate-transparency-go to try to generate the TBS PreCert. I seem to be hitting this line because the PreCert Poison doesn't appear in the extension list. At the very least, this made me realise that I put the Rust code in the wrong spot so I need to fix that too.

    If I remove that call, it produces the same DER encoded TBS PreCert as sigstore-python so that's good. I'm assuming that I'm misunderstanding how the Go code works though because I'm assuming that cosign doesn't hit this error. Will investigate more over the weekend.

  20. Hayden-IO commented on May 20, 2022

    @Hayden-IO
    Contributor

    You'll want to construct the TBS Certificate like in this function - The other function builds the merkle tree leaf from the precertificate before appending to the tree, so it must remove the poison extension. Whereas at this point, you have a valid certificate with an SCT list - The SCT list must be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

component:verificationenhancementupstream

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions