Skip to content

Commit 7b34db0

Browse files
committed
Switch default PKCS7/CMS cipher to AES-128-CBC
Switch default cipher for openssl_pkcs7_encrypt() and openssl_cms_encrypt() from RC2-40 to AES-128-CBC. The RC2-40 cipher is considered insecure and is not loaded by default in OpenSSL 3, which means that these functions will always fail with default arguments. As the used algorithm is embedded in the result (which makes this different from the openssl_encrypt() case) changing the default algorithm should be safe. Closes GH-7357.
1 parent 8755976 commit 7b34db0

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

UPGRADING

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ PHP 8.1 UPGRADE NOTES
115115
- OpenSSL:
116116
. EC private keys will now be exported in PKCS#8 format rather than
117117
traditional format, just like all other keys.
118+
. openssl_pkcs7_encrypt() and openssl_cms_encrypt() will now default to
119+
using AES-128-CBC rather than RC2-40. The RC2-40 cipher is considered
120+
insecure and not enabled by default in OpenSSL 3.
118121

119122
- PDO:
120123
. PDO::ATTR_STRINGIFY_FETCHES now also stringifies values of type bool to
@@ -573,6 +576,9 @@ PHP 8.1 UPGRADE NOTES
573576

574577
- OpenSSL:
575578
. The OpenSSL extension now requires at least OpenSSL version 1.0.2.
579+
. OpenSSL 3.0 is now supported. Be aware that many ciphers are no longer
580+
enabled by default (part of the legacy provider), and that parameter
581+
validation (e.g. minimum key sizes) is stricter now.
576582

577583
- Phar:
578584
. Use SHA256 by default for signature.

ext/openssl/openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ enum php_openssl_cipher_type {
119119
PHP_OPENSSL_CIPHER_AES_192_CBC,
120120
PHP_OPENSSL_CIPHER_AES_256_CBC,
121121

122-
PHP_OPENSSL_CIPHER_DEFAULT = PHP_OPENSSL_CIPHER_RC2_40
122+
PHP_OPENSSL_CIPHER_DEFAULT = PHP_OPENSSL_CIPHER_AES_128_CBC
123123
};
124124

125125
/* Add some encoding rules. This is normally handled through filters

ext/openssl/openssl.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function openssl_pbkdf2(string $password, string $salt, int $key_length, int $it
120120
function openssl_pkcs7_verify(string $input_filename, int $flags, ?string $signers_certificates_filename = null, array $ca_info = [], ?string $untrusted_certificates_filename = null, ?string $content = null, ?string $output_filename = null): bool|int {}
121121

122122
/** @param OpenSSLCertificate|array|string $certificate */
123-
function openssl_pkcs7_encrypt(string $input_filename, string $output_filename, $certificate, ?array $headers, int $flags = 0, int $cipher_algo = OPENSSL_CIPHER_RC2_40): bool {}
123+
function openssl_pkcs7_encrypt(string $input_filename, string $output_filename, $certificate, ?array $headers, int $flags = 0, int $cipher_algo = OPENSSL_CIPHER_AES_128_CBC): bool {}
124124

125125
/** @param OpenSSLAsymmetricKey|OpenSSLCertificate|array|string $private_key */
126126
function openssl_pkcs7_sign(string $input_filename, string $output_filename, OpenSSLCertificate|string $certificate, $private_key, ?array $headers, int $flags = PKCS7_DETACHED, ?string $untrusted_certificates_filename = null): bool {}
@@ -137,7 +137,7 @@ function openssl_pkcs7_read(string $data, &$certificates): bool {}
137137
function openssl_cms_verify(string $input_filename, int $flags = 0, ?string $certificates = null, array $ca_info = [], ?string $untrusted_certificates_filename = null, ?string $content = null, ?string $pk7 = null, ?string $sigfile = null, int $encoding = OPENSSL_ENCODING_SMIME): bool {}
138138

139139
/** @param OpenSSLCertificate|array|string $certificate */
140-
function openssl_cms_encrypt(string $input_filename, string $output_filename, $certificate, ?array $headers, int $flags = 0, int $encoding = OPENSSL_ENCODING_SMIME, int $cipher_algo = OPENSSL_CIPHER_RC2_40): bool {}
140+
function openssl_cms_encrypt(string $input_filename, string $output_filename, $certificate, ?array $headers, int $flags = 0, int $encoding = OPENSSL_ENCODING_SMIME, int $cipher_algo = OPENSSL_CIPHER_AES_128_CBC): bool {}
141141

142142
/** @param OpenSSLAsymmetricKey|OpenSSLCertificate|array|string $private_key */
143143
function openssl_cms_sign(string $input_filename, string $output_filename, OpenSSLCertificate|string $certificate, $private_key, ?array $headers, int $flags = 0, int $encoding = OPENSSL_ENCODING_SMIME, ?string $untrusted_certificates_filename = null): bool {}

ext/openssl/openssl_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 1eac784acca52fab0a38852b18503b072f780ff4 */
2+
* Stub hash: b0d7811060ba2499a0c2908aad8ab160cd604043 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_openssl_x509_export_to_file, 0, 2, _IS_BOOL, 0)
55
ZEND_ARG_OBJ_TYPE_MASK(0, certificate, OpenSSLCertificate, MAY_BE_STRING, NULL)
@@ -174,7 +174,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_openssl_pkcs7_encrypt, 0, 4, _IS
174174
ZEND_ARG_INFO(0, certificate)
175175
ZEND_ARG_TYPE_INFO(0, headers, IS_ARRAY, 1)
176176
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
177-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cipher_algo, IS_LONG, 0, "OPENSSL_CIPHER_RC2_40")
177+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cipher_algo, IS_LONG, 0, "OPENSSL_CIPHER_AES_128_CBC")
178178
ZEND_END_ARG_INFO()
179179

180180
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_openssl_pkcs7_sign, 0, 5, _IS_BOOL, 0)
@@ -218,7 +218,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_openssl_cms_encrypt, 0, 4, _IS_B
218218
ZEND_ARG_TYPE_INFO(0, headers, IS_ARRAY, 1)
219219
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
220220
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_LONG, 0, "OPENSSL_ENCODING_SMIME")
221-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cipher_algo, IS_LONG, 0, "OPENSSL_CIPHER_RC2_40")
221+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cipher_algo, IS_LONG, 0, "OPENSSL_CIPHER_AES_128_CBC")
222222
ZEND_END_ARG_INFO()
223223

224224
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_openssl_cms_sign, 0, 5, _IS_BOOL, 0)

0 commit comments

Comments
 (0)