Skip to content

Commit b251485

Browse files
committed
fix: check priv_key_bits only for relevant private key types
1 parent a64cdd6 commit b251485

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

ext/openssl/openssl_backend_common.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,17 +1437,16 @@ static const char *php_openssl_get_evp_pkey_name(int key_type) {
14371437

14381438
EVP_PKEY *php_openssl_generate_private_key(struct php_x509_request * req)
14391439
{
1440-
if (req->priv_key_bits < MIN_KEY_LENGTH) {
1441-
php_error_docref(NULL, E_WARNING, "Private key length must be at least %d bits, configured to %d",
1442-
MIN_KEY_LENGTH, req->priv_key_bits);
1443-
return NULL;
1444-
}
1445-
14461440
int type = php_openssl_get_evp_pkey_type(req->priv_key_type);
14471441
if (type < 0) {
14481442
php_error_docref(NULL, E_WARNING, "Unsupported private key type");
14491443
return NULL;
14501444
}
1445+
if ((type == EVP_PKEY_RSA || type == EVP_PKEY_DSA || type == EVP_PKEY_DH) && req->priv_key_bits < MIN_KEY_LENGTH) {
1446+
php_error_docref(NULL, E_WARNING, "Private key length must be at least %d bits, configured to %d",
1447+
MIN_KEY_LENGTH, req->priv_key_bits);
1448+
return NULL;
1449+
}
14511450
const char *name = php_openssl_get_evp_pkey_name(req->priv_key_type);
14521451

14531452
int egdsocket, seeded;

0 commit comments

Comments
 (0)