1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

1036 Commits

Author SHA1 Message Date
ndossche
a6a7b3923a Merge branch 'PHP-8.5'
* PHP-8.5:
  openssl: Fix missing error propagation for BIO_printf() calls
2026-03-21 10:36:04 +01:00
ndossche
0d7ce4c037 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  openssl: Fix missing error propagation for BIO_printf() calls
2026-03-21 10:35:59 +01:00
ndossche
f92d54b6b5 openssl: Fix missing error propagation for BIO_printf() calls
Since these go through a file, this can fail.
For some of these, the error is already checked but not propagated to
userland, causing a "true" return value but an incomplete file.
For others, the error is not checked and can also lead to an incomplete
file.
Solve this by always propagating failure, especially as the other write
calls are already checked for failure.

Closes GH-21360.
2026-03-21 10:35:34 +01:00
Ilia Alshanetsky
7950482562 Fix GH-21083: Skip private_key_bits validation for EC/curve-based keys
openssl_pkey_new() checks private_key_bits >= 384 before generating any
key. For EC, X25519, ED25519, X448, and ED448 the size is inherent to
the curve or algorithm, so this check doesn't apply and causes failures
when default_bits is missing from openssl.cnf (which is the case in
OpenSSL 3.6's default config).

Skip the minimum-bits check for key types that don't use private_key_bits.

Closes GH-21387.
2026-03-12 21:53:22 +01:00
Alexandre Daubois
11a95749b1 Convert more zend_parse_parameters_none() to fast ZPP (#21330) 2026-03-04 14:07:46 +01:00
ndossche
5a608bb1ba Merge branch 'PHP-8.5'
* PHP-8.5:
  Update NEWS for OpenSSL changes
  Fix memory leaks in openssl_cms_encrypt() when push fails
  Fix memory leaks in openssl_pkcs7_encrypt() when push fails
  Fix missing error propagation when php_array_to_X509_sk() fails
  Fix memory leaks in php_array_to_X509_sk() when push fails
  Fix memory leak in php_openssl_load_all_certs_from_file() when push fails
2026-02-17 21:47:55 +01:00
ndossche
e8a274e3dd Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Update NEWS for OpenSSL changes
  Fix memory leaks in openssl_cms_encrypt() when push fails
  Fix memory leaks in openssl_pkcs7_encrypt() when push fails
  Fix missing error propagation when php_array_to_X509_sk() fails
  Fix memory leaks in php_array_to_X509_sk() when push fails
  Fix memory leak in php_openssl_load_all_certs_from_file() when push fails

Closes GH-20986.
2026-02-17 21:46:49 +01:00
ndossche
f6887f04f6 Fix memory leaks in openssl_cms_encrypt() when push fails 2026-02-17 21:39:51 +01:00
ndossche
556ec77951 Fix memory leaks in openssl_pkcs7_encrypt() when push fails 2026-02-17 21:39:51 +01:00
ndossche
ef54becb3e Fix missing error propagation when php_array_to_X509_sk() fails
Execution shouldn't continue if this fails because it can give the wrong
results.
2026-02-17 21:39:51 +01:00
ndossche
01d598aea3 Fix memory leaks in php_array_to_X509_sk() when push fails 2026-02-17 21:39:50 +01:00
ndossche
4b9e80eae9 Fix memory leak in php_openssl_load_all_certs_from_file() when push fails 2026-02-17 21:39:50 +01:00
Niels Dossche
fb5d4784fe Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix crash in openssl_x509_parse() when X509_NAME_oneline() fails
  Fix crash when in openssl_x509_parse() when i2s_ASN1_INTEGER() fails
2026-01-23 15:00:22 +01:00
Niels Dossche
2c08d9a627 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix crash in openssl_x509_parse() when X509_NAME_oneline() fails
  Fix crash when in openssl_x509_parse() when i2s_ASN1_INTEGER() fails
2026-01-23 14:59:35 +01:00
Niels Dossche
62afc7a2fa Fix crash in openssl_x509_parse() when X509_NAME_oneline() fails
The X509_NAME_oneline() function can return NULL, which will cause a
crash when the string length is computed via add_assoc_string().

Closes GH-21010.
2026-01-23 14:59:08 +01:00
Niels Dossche
c2eadb4922 Fix crash when in openssl_x509_parse() when i2s_ASN1_INTEGER() fails
The X509_NAME_oneline() function can return NULL,
which will cause a crash when the string length is computed via add_assoc_string().

Closes GH-21011.
2026-01-23 14:58:39 +01:00
Niels Dossche
61845cc016 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix memory leaks when sk_X509_new_null() fails
2026-01-22 22:47:51 +01:00
Niels Dossche
7d4e430435 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix memory leaks when sk_X509_new_null() fails
2026-01-22 22:47:35 +01:00
Niels Dossche
7754eafb1f Fix memory leaks when sk_X509_new_null() fails
In a lot of places the return value is not checked, and when the
function fails the code continues execution. However, this means that
operations on the stack fail and will cause memory leaks on the objects
that weren't pushed.

We also notice an inconsistency in how these failures are handled.
For example, in one place we explicitly have a fatal error
`php_error_docref(NULL, E_ERROR, "Memory allocation failure");`
but this is the only place to do so.

Closes GH-20957.
2026-01-22 22:37:14 +01:00
Steve Wall
c1d2875a82 Implement GH-20310: No critical extension indication in openssl_x509_parse() output
This add criticalExtensions field to openssl_x509_parse() output that
provides name of all critical extensions.

Closes #20310
Closes #20311
2026-01-14 22:59:10 +01:00
Jakub Zelenka
040ea4ab5f Revert "Fix GH-7737: openssl_seal/openssl_open do not handle tagged algorithm…" (#20698)
This reverts commit 2ee5e6b432.
2025-12-13 11:42:10 +01:00
Sara Golemon
2ee5e6b432 Fix GH-7737: openssl_seal/openssl_open do not handle tagged algorithms (#20687)
This commit adds a seventh parameter to both two OpenSSL functions:
* openssl_seal(): The new parameter is by-ref and is populated with the computed tag.
* openssl_open(): The new parameter is by-value to provide the computed tag.

Closes GH-7737
2025-12-12 14:06:01 -06:00
Tim Düsterhus
6da93a86f2 zend_API: Remove CHECK*NULL_PATH (#20155)
* tree-wide: Replace `CHECK_NULL_PATH()` by `zend_char_has_nul_byte()`

The former is a direct alias of the latter with a more explicit name and the
former is explicitly documented as a “compatibility” alias.

* tree-wide: Replace `CHECK_ZVAL_NULL_PATH()` by its definition

The former is explicitly documented as a “compatibility” alias.

* zend_API: Remove `CHECK*NULL_PATH`

The `CHECK_ZVAL_NULL_PATH()` macro is unsafe, because it implicitly assumes
that the given `zval*` is `IS_STRING`.

Based on a GitHub search there does not seem to be any user outside of PHP, all
hits were just forks / copies of php-src.
2025-10-15 10:24:22 +02:00
Tim Düsterhus
2ab04924aa openssl: Use true / false instead of 1 / 0 when assigning to bool
Changes done with Coccinelle:

    @@
    bool b;
    @@

    - b = 0
    + b = false

    @@
    bool b;
    @@

    - b = 1
    + b = true
2025-09-24 18:51:40 +02:00
Jakub Zelenka
dcc4b0ff07 Fix build when --with-openssl-legacy-provider set
It was missing proper backend init split.

Closes GH-19930
2025-09-23 12:26:04 +02:00
Jakub Zelenka
2e9cdb2c5a Fix missing OpenSSL libctx name fetch conversions (#19830) 2025-09-13 22:51:07 +02:00
Jakub Zelenka
20c8c12d9e Fix #81724: openssl_cms_encrypt only allows specific ciphers
The allows cipher_algo to be specified as a string. It means the not
only predefined ID ciphers are available which means that also auth
enveloped data can be created using AES GCM.

Closes GH-19459
2025-08-12 15:52:09 +02:00
Jakub Zelenka
c5f79b8cf9 Use OpenSSL libctx for various BIO readers (#19448)
This converts mostly PEM readers but also DER for CMS
2025-08-11 18:21:38 +02:00
Jakub Zelenka
702d18de99 Implement #80495: Enable to set padding in openssl_(sign|verify)
This adds support for RSA PSS padding.

Closes GH-19432
2025-08-11 13:11:10 +02:00
Gina Peter Banyard
284e622506 ext/openssl: Deprecate $key_length parameter of openssl_pkey_derive() (#19421)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_key_length_parameter_of_openssl_pkey_derive
2025-08-09 22:55:53 +01:00
Jakub Zelenka
f52a59ff4f Merge branch 'PHP-8.3' into PHP-8.4 2025-08-09 17:44:25 +02:00
Jakub Zelenka
9e2aa658a8 Fix GH-19428: openssl_pkey_derive segfaults for DH derive with low key_length
This happens only for OpenSSL 1.1.1 because key_length is ignored for
DH. It means that the provided string is overwritten with longer buffer.
2025-08-09 17:43:04 +02:00
Jakub Zelenka
ce6e7a2786 Integrate OpenSSL libctx to pwhash (#19236)
This allows using OpenSSL Argon2 password hashing on ZTS.

Closes GH-19236
2025-07-29 15:06:34 +02:00
Jakub Zelenka
b1fce8a98c Add digest algo param to public encrypt and private decrypt
Specifically, it is added to openssl_public_encrypt() and
openssl_private_decrypt() functions. The purpose is to specify digest
algorithm for OEAP padding. It currently defaults to SHA1 for some
OpenSSL versions which is not preferred for modern setup and causes
problems in compatibility with web crypto.

Closes GH-19223
2025-07-25 12:56:47 +02:00
Niels Dossche
0f731b455c Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix error return check of EVP_CIPHER_CTX_ctrl()
  Fix memleak on failure in collator_get_sort_key()
2025-07-15 20:38:22 +02:00
Niels Dossche
cd8722304c Fix error return check of EVP_CIPHER_CTX_ctrl()
OpenSSL can return -1 on error [1, 2], and OpenBSD's docs confirm this
[3]. Change all checks to <= 0.

[1] b3161bd9a9/crypto/evp/evp_enc.c (L1530-L1531)
[2] b3161bd9a9/crypto/evp/evp_enc.c (L1611)
[3] https://man.openbsd.org/EVP_CIPHER_CTX_ctrl.3

Closes GH-18987.
2025-07-15 20:37:33 +02:00
Niels Dossche
f938f356cb Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18986: OpenSSL backend: incorrect RAND_{load,write}_file() return value check
2025-07-15 18:50:46 +02:00
Niels Dossche
a8086be81c Fix GH-18986: OpenSSL backend: incorrect RAND_{load,write}_file() return value check
As noted by the LibreSSL maintainer, these functions return -1 on error.
This is further confirmed by my static analyzer that inferred the same
thing for OpenSSL.

Closes GH-19013.
2025-07-15 18:50:19 +02:00
Jakub Zelenka
d0c0a9abfd Introduce OpenSSL INI for selecting libctx (#18768)
Closes GH-18768

Co-authored-by: Gina Peter Banyard <girgias@php.net>
2025-07-14 15:16:14 +02:00
Niels Dossche
dbabbe180b Remove dead code from openssl_spki_new() implementation (#18752)
If s is not NULL, the length can't be <= 0 because we at least append
`spkac` in the string, which is non-empty.
I noticed this condition because if it were actually possible to
execute, then it would leak memory.
2025-06-10 22:35:56 +02:00
Jakub Zelenka
2f5ef4d2b7 Use custom OpenSSL libctx in md and cipher handling code (#18516) 2025-06-04 18:46:00 +02:00
Niels Dossche
87ff5479fc Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix memory leak of X509_STORE in php_openssl_setup_verify() on failure
2025-06-03 23:46:21 +02:00
Niels Dossche
08a9579883 Fix memory leak of X509_STORE in php_openssl_setup_verify() on failure
Closes GH-18750.
2025-06-03 23:45:51 +02:00
Jakub Zelenka
cb4bafa4c0 Init OpenSSL libctx and use it for pkey (#18282) 2025-05-06 20:14:55 +02:00
Niels Dossche
8c685faa64 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix potential leaks when writing to BIO fails
2025-04-11 21:04:24 +02:00
Niels Dossche
8a927c284d Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix potential leaks when writing to BIO fails
2025-04-11 21:02:59 +02:00
Niels Dossche
29f96fb1f1 Fix potential leaks when writing to BIO fails
When the BIO is created but writing fails, these can leak.

Closes GH-18186.
2025-04-11 21:02:37 +02:00
Jakub Zelenka
2194ad81f4 Make further OpenSSL 1.0.2 clean up
Closes GH-18133
2025-04-08 18:06:56 +02:00
Niels Dossche
5a19e25347 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix inverted call to php_openssl_store_errors()
  Fix openssl_random_pseudo_bytes() always setting strong_result to true
2025-04-02 20:30:44 +02:00
Niels Dossche
a6e76ac010 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix inverted call to php_openssl_store_errors()
  Fix openssl_random_pseudo_bytes() always setting strong_result to true
2025-04-02 20:25:32 +02:00