x509-cert: CertificateBuilder: reject duplicate extensions - #2458
Open
yuxi-liu-wired wants to merge 1 commit into
Open
yuxi-liu-wired wants to merge 1 commit into
yuxi-liu-wired wants to merge 1 commit into
Conversation
RFC 5280 4.2: "A certificate MUST NOT include more than one instance of a
particular extension." `CertificateBuilder::finalize` appended the
profile's extensions to the ones added with `add_extension` without
checking, so adding an extension that the profile also adds produced a
certificate with two of them. For example, a `BasicConstraints` with a
`pathLenConstraint` on a `cabf::Root` certificate gives
extensions: 2.5.29.19, 2.5.29.15, 2.5.29.35, 2.5.29.19, 2.5.29.15, 2.5.29.14
pyca/cryptography refuses to load such a certificate's extensions
(`DuplicateExtension`), and other verifiers reject it.
Return a new `Error::DuplicateExtension { oid }` from `finalize` instead
(`Error` is `#[non_exhaustive]`).
This branch has not been deployed
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.
RFC 5280 4.2 says: "A certificate MUST NOT include more than one instance of a particular extension."
CertificateBuilder::finalizeappends the profile's extensions to the ones added withadd_extensionwithout checking. So adding an extension that the profile also adds produces a certificate with two of them.For example, giving a
cabf::Rootcertificate apathLenConstraint:Relying parties reject such certificates, and pyca/cryptography reports
DuplicateExtensionwhen reading their extensions.This PR makes
finalizereturn a newError::DuplicateExtension { oid }(Erroris#[non_exhaustive], so this isn't a breaking change). A follow-up could let user-supplied extensions replace the profile's defaults instead, but rejecting is the conservative fix.Test:
reject_duplicate_extensioninx509-cert/tests/builder.rs. On master the build succeeds with twoBasicConstraints.This PR was produced by AI agents (Claude) while fuzzing
x509-cert's builders against RFC 5280 rules and pyca/cryptography's parser.