Add more robust parameter processing: DH#15016
Merged
Merged
Conversation
reaperhulk
approved these changes
Jun 12, 2026
garbusbeach
reviewed
Jun 15, 2026
| let g = utils::py_int_to_bn(py, numbers.g.bind(py))?; | ||
|
|
||
| let dh = openssl::dh::Dh::from_pqg(p, q, g)?; | ||
| check_dh_parameters(&dh)?; |
reaperhulk
pushed a commit
that referenced
this pull request
Jun 15, 2026
A PKCS#3 "DH PARAMETERS" structure may carry an optional trailing INTEGER, privateValueLength. The loader parsed every DH parameters blob with the X9.42-shaped struct (p, g, q?), so it misread privateValueLength as the subprime q. Since #15016 added a check_key() validation, this now fails with "Invalid DH parameters". Route the PEM loader by tag: "DH PARAMETERS" (PKCS#3) ignores privateValueLength, while "X9.42 DH PARAMETERS" keeps q. The DER loader stays X9.42-permissive since DER carries no tag to disambiguate and the existing rfc5114 DER vectors require q to be parsed. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
This PR adds more robust key processing for DH by extending existing heuristic checks on parameter well-formedness to the PEM and DER load paths.
See #14992 and #15015 for related changes to DSA and RSA processing.