Skip to content

Commit 731d36a

Browse files
committed
Fix OpenSSL fetching of alias ciphers
This does not seem like an issue as the aliases seem to be already fetched most of the time. But there might be cases when it could be failing like it was failing for MD in GH-19369. It should be noted that the test does not fail without this change but it seems useful anyway so it is added as part of this change. I actually have not found the case where alias is not fetched for cipher but there might be some. Closes GH-19437
1 parent 066a977 commit 731d36a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ext/openssl/openssl_backend_v3.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,12 @@ static const char *php_openssl_cipher_names[] = {
775775

776776
const EVP_CIPHER *php_openssl_get_evp_cipher_by_name(const char *name)
777777
{
778+
const EVP_CIPHER *cp = (const EVP_CIPHER *) OBJ_NAME_get(name, OBJ_NAME_TYPE_CIPHER_METH);
779+
780+
if (cp != NULL) {
781+
return cp;
782+
}
783+
778784
return EVP_CIPHER_fetch(PHP_OPENSSL_LIBCTX, name, PHP_OPENSSL_PROPQ);
779785
}
780786

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
openssl_encrypt() CBC and its alias
3+
--EXTENSIONS--
4+
openssl
5+
--FILE--
6+
<?php
7+
var_dump(bin2hex(openssl_encrypt('data', 'AES-128-CBC', 'foo', 0, '0123456789abcdef')));
8+
var_dump(bin2hex(openssl_encrypt('data', 'aes128', 'foo', 0, '0123456789abcdef')));
9+
?>
10+
--EXPECTF--
11+
string(48) "7a654459353452676f6c6b6a446b75455a6c4c6b4f513d3d"
12+
string(48) "7a654459353452676f6c6b6a446b75455a6c4c6b4f513d3d"

0 commit comments

Comments
 (0)