fix: check priv_key_bits only for relevant private key types #19103
+64
−6
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.
Description
php_openssl_generate_private_key
currently applies theMIN_KEY_LENGTH
(384 bits) check across all key types, including EC (Elliptic Curve) keys. However, for EC key generation, theprivate_key_bits
parameter is not relevant—the security of EC keys is determined by the selected curve, not the bit length. As a result, applying this check to EC keys can cause developer confusion. For reference, see related discussions:Solution
This PR updates
php_openssl_generate_private_key
to enforce theMIN_KEY_LENGTH
check only for key types where thepriv_key_bits
parameter is meaningful—specifically RSA, DSA, and DH keys.Additional Notes
MIN_KEY_LENGTH
of 384 bits for RSA, DSA, and DH keys is not considered secure by modern standards. Ideally, this minimum should be raised (e.g., to 2048 bits for RSA), or the check reconsidered entirely.PHP-8.3
branch for bug fixes (as this is the lowest actively supported version). However, for extension changes, this branch lacks the involved source files. Please advise if a different branch is preferred for this PR.