Fix X509::Certificate#dup dropping all extensions#356
Open
sferik wants to merge 1 commit intojruby:masterfrom
Open
Fix X509::Certificate#dup dropping all extensions#356sferik wants to merge 1 commit intojruby:masterfrom
sferik wants to merge 1 commit intojruby:masterfrom
Conversation
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenSSL::X509::Certificate#dupproduces an invalid copy. Historically,initialize_copychecked for identity and frozenness but never copied any certificate state from the source object, so the duplicate could lose its extensions, subject, issuer, serial, and other fields.As far as I can tell, this has been latent for a long time but was surfaced following the addition of
Certificate#tbs_bytesin ee7f0c8. That addition causedsigstore-rubyto enter a code path that dups a Fulcio-issued certificate and iterates its extensions, which were silently empty, causinggem pushwith Sigstore attestation to fail on JRuby:Here is an example of a Java-platform gem push failing in CI: https://github.com/sferik/multi_json/actions/runs/24221466355/job/70713680096
I was able to successfully work around this issue by using CRuby for the signing step.
Here is a minimal reproduction of this issue:
Expected: both lines print
["subjectKeyIdentifier"]Actual: duped prints
[]This patch fixes
Certificate#dupby copying the live certificate state instead of leaving the duplicate empty.For signed certificates, it now clones the underlying parsed certificate and also copies the current Ruby-side fields.
For unsigned certificates still under construction, it deep-copies mutable fields.
This patch also marks
extensions=as a mutating operation so the object’s state stays consistent after replacing extensions on an already-signed certificate.