Commit Graph

1836 Commits

Author SHA1 Message Date
Pierrick Charron
6fd2b39397
Indent with TAB in .h files generated by gen_stub 2022-06-13 08:55:54 -04:00
twosee
b7a1633ecd
Remove unused server_name variable
Closes GH-8760.
2022-06-13 13:14:08 +02:00
Tim Düsterhus
c311ab7ef7 Mark parameter in ext/openssl as sensitive 2022-06-13 11:09:12 +02:00
Jakub Zelenka
13e46a0cb1
Merge branch 'PHP-8.1' 2022-06-09 23:03:37 +01:00
Jakub Zelenka
56382493eb
Merge branch 'PHP-8.0' into PHP-8.1 2022-06-09 23:02:50 +01:00
Jakub Zelenka
2f78c1f9d9 Fix and improve OpenSSL VCWD path checking test for bug #50293 2022-06-09 23:01:52 +01:00
Jakub Zelenka
03b9dbc9ce
Merge branch 'PHP-8.1' 2022-06-09 20:10:28 +01:00
Jakub Zelenka
95f6984216
Merge branch 'PHP-8.0' into PHP-8.1 2022-06-09 20:09:57 +01:00
Jakub Zelenka
cb9a48a0c5
Pass signature to openssl_verify in bug81713 test 2022-06-09 20:09:08 +01:00
Jakub Zelenka
a6387fa383
Merge branch 'PHP-8.1' 2022-06-09 19:57:08 +01:00
Jakub Zelenka
976cbba76e Merge branch 'PHP-8.0' into PHP-8.1 2022-06-09 19:55:46 +01:00
Jakub Zelenka
b765d4cd41 Fix bug #50293 and #81713: file path checking in OpenSSL functions
It introduces a single function to check file paths passed to OpenSSL
functions. It expands the path, check null bytes and finally does
an open basedir check.
2022-06-09 19:49:59 +01:00
Remi Collet
3670fa3b32
Merge branch 'PHP-8.1'
* PHP-8.1:
  use sha256 in openssl test suite
2022-06-01 11:46:59 +02:00
Remi Collet
03a4ccd912
use sha256 in openssl test suite 2022-06-01 11:46:47 +02:00
George Peter Banyard
2ecd46f48f
Initialise zend_stat_t to fix MSAN build 2022-05-22 16:06:27 +01:00
Jakub Zelenka
834e32e59b
Merge branch 'PHP-8.1' 2022-05-15 16:52:59 +01:00
Jakub Zelenka
74f75db0c3
Fix bug #79589: ssl3_read_n:unexpected eof while reading
The unexpected EOF failure was introduced in OpenSSL 3.0 to prevent
truncation attack. However there are many non complaint servers and
it is causing break for many users including potential majority
of those where the truncation attack is not applicable. For that reason
we try to keep behavior consitent with older OpenSSL versions which is
also the path chosen by some other languages and web servers.

Closes GH-8369
2022-05-15 16:52:12 +01:00
Christoph M. Becker
8233e06109
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix openssl_csr_export() stub
2022-04-13 15:23:41 +02:00
Christoph M. Becker
c821886777
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix openssl_csr_export() stub
2022-04-13 15:23:09 +02:00
Mikko Pesari
16bf8331e0
Fix openssl_csr_export() stub
Closes GH-8362.
2022-04-13 15:20:58 +02:00
Christoph M. Becker
973c4d406b
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix openssl_x509_checkpurpose_basic.phpt
2021-12-12 14:28:49 +01:00
Christoph M. Becker
f19250a3a1
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix openssl_x509_checkpurpose_basic.phpt
2021-12-12 14:28:16 +01:00
Christoph M. Becker
2c2b0abd4a
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix openssl_x509_checkpurpose_basic.phpt
2021-12-12 14:27:07 +01:00
Christoph M. Becker
98175fc7f1
Fix openssl_x509_checkpurpose_basic.phpt
This test fails because san-cert.pem and san-ca.pem have expired.  We
fix that by using the CertificateGenerator to generate temporary certs
during the test run.  Since san-cert.pem and san-ca.pem have been
identical, we only generate one certificate.

Closes GH-7763.
2021-12-12 14:26:17 +01:00
Christoph M. Becker
b29e85a0da
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #75725: ./configure: detecting RAND_egd
2021-11-22 14:13:52 +01:00
Дилян Палаузов
60fe575ce3
Fix #75725: ./configure: detecting RAND_egd
Closes GH-7668.
2021-11-22 14:11:07 +01:00
Nikita Popov
c94db599b2 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed bug #81502
2021-10-08 14:08:56 +02:00
Nikita Popov
7f0d3f5413 Fixed bug #81502
Allow $tag to be null. This is the value that openssl_encrypt()
sets it to for non-AEAD ciphers, so we should also accept this
as an input to openssl_decrypt().

Prior to PHP 8.1, null was accepted in weak mode due to the special
treatment of null arguments to internal functions.
2021-10-08 14:07:05 +02:00
Nikita Popov
bce040ddf2 Merge branch 'PHP-8.1'
* PHP-8.1:
  Set opline before calling undef op helper
  Add more specific array return type hints for various extensions - part 6 (#7474)
2021-10-07 14:40:48 +02:00
Máté Kocsis
d9e5e63032
Add more specific array return type hints for various extensions - part 6 (#7474) 2021-10-07 14:29:29 +02:00
Jakub Zelenka
560a6166a1 Merge branch 'PHP-8.1' 2021-09-12 20:31:21 +01:00
Jakub Zelenka
43f0141d74
Make OpenSSL tests less dependent on system config
It fixes dependencies on system config if running tests with OpenSSL 3.0
2021-09-12 20:30:02 +01:00
Remi Collet
4914ead292
Merge branch 'PHP-8.1'
* PHP-8.1:
  fix [-Wmaybe-uninitialized] build warnings
2021-09-10 15:58:12 +02:00
Remi Collet
6ee96f095a
fix [-Wmaybe-uninitialized] build warnings 2021-09-10 15:57:56 +02:00
twosee
0ac60d6055
Micro optimizations for xp_ssl.c (#7447)
If certfile/private_key points to a file that doesn't exist, it throw a warning and return failure now.
Also fixed sni_server tests.

Co-authored-by: Nikita Popov <nikita.ppv@googlemail.com>
2021-09-03 09:37:42 +08:00
twosee
aa893c4a71
Simplify SSL_set_mode() calls (#7444)
SSL_set_mode() adds the mode set via bitmask in mode to ssl.
2021-09-01 16:33:19 +08:00
Nikita Popov
7b34db0659 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.
2021-08-16 12:31:48 +02:00
Remi Collet
c51af22fef
implement openssl_256 and openssl_512 for phar singatures 2021-08-11 14:13:57 +02:00
Nikita Popov
7d2a2c7dc0 Fix openssl memory leaks
Some leaks that snuck in during refactorings.
2021-08-11 10:11:12 +02:00
Nikita Popov
ef787bae24 Switch dh_param handling to EVP_PKEY API 2021-08-10 12:17:17 +02:00
Nikita Popov
e5f53e1ca1 Fork openssl_error_string() test for OpenSSL
The used error code differ signficantly, so use a separate test
file.

openssl_encrypt() no longer throws an error for invalid key length,
which looks like an upstream bug.
2021-08-10 11:50:18 +02:00
Nikita Popov
3724b49aa9 Use param API to create RSA key
Instead of deprecated low-level API.

A caveat here is that when using the high-level API, OpenSSL 3
requires that if the prime factors are set, the CRT parameters
are also set. See https://github.com/openssl/openssl/issues/16271.

As such, add CRT parameters to the manual construction test.

This fixes the last deprecation warnings in openssl.c, but there
are more elsewhere.
2021-08-09 17:02:17 +02:00
Nikita Popov
ff2a39e6fc Add missing unsigned qualifier
This previously got lost in the deprecation warning noise.
2021-08-09 14:37:07 +02:00
Nikita Popov
6db2c2dbe7 Use param API for openssl_pkey_get_details()
Now that the DSA/DH/EC keys are not created using the legacy API,
we can fetch the details using the param API as well, and not
run into buggy priv_key handling.
2021-08-09 14:37:07 +02:00
Nikita Popov
26a51e8d7a Extract public key portion via PEM roundtrip
The workaround with cloning the X509_REQ no longer works in
OpenSSL 3. Instead extract the public key portion by round
tripping through PEM.
2021-08-09 14:19:33 +02:00
Nikita Popov
f9e701cde8 Use param API for creating EC keys
Rather than the deprecated low level APIs.
2021-08-09 12:22:57 +02:00
Nikita Popov
246698671f Test calculation of EC public key from private key 2021-08-09 12:01:35 +02:00
Nikita Popov
14d7c7e9ae Extract EC key initialization 2021-08-09 12:00:13 +02:00
Jakub Zelenka
c90c9c7545
Make CertificateGenerator not dependent on external config in OpenSSL 3.0 2021-08-08 20:54:46 +01:00
Nikita Popov
94bc5fce26
Use OpenSSL NCONF APIs (#7337) 2021-08-08 16:39:06 +01:00
Remi Collet
a0972deb0f
minimal fix for openssl 3.0 (#7002) 2021-08-08 16:38:30 +01:00
Nikita Popov
2bf316fdfc Switch manual DSA key generation to param API
This is very similar to the DH case, with the primary difference
that priv_key is ignored if pub_key is not given, rather than
generating pub_key from priv_key. Would be nice if these worked
the same (in which case we should probably also unify the keygen
for FFC algorithms, as it's very similar).
2021-08-06 17:17:07 +02:00
Nikita Popov
a7740a0bf0 Switch manual DH key generation to param API
Instead of using the deprecated low-level interface.

This should also avoid issues with fetching parameters from
legacy keys, cf. https://github.com/openssl/openssl/issues/16247.
2021-08-06 16:55:24 +02:00
Nikita Popov
f2d3e75933 Do not special case export of EC keys
All other private keys are exported in PKCS#8 format, while EC
keys use traditional format. Switch them to use PKCS#8 format as
well.

As the OpenSSL docs say:

> PEM_write_bio_PrivateKey_traditional() writes out a private key
> in the "traditional" format with a simple private key marker and
> should only be used for compatibility with legacy programs.
2021-08-06 11:25:44 +02:00
Nikita Popov
5843ba518c Generate pkcs12_read test inputs on the fly
The old p12_with_extra_certs.p12 file uses an unsupported something.
2021-08-06 10:48:03 +02:00
Nikita Popov
a2c201351b Use different cipher in one more CMS test
Followup to ec4d926a80 -- I failed
to squash in this commit.
2021-08-06 10:23:23 +02:00
Nikita Popov
d23a8b33ab Skip some tests if cipher not available 2021-08-06 10:22:39 +02:00
Nikita Popov
1cf4fb739f Use larger key size for DSA/DH tests
OpenSSL 3 validates allowed sizes strictly, pick minimum sizes
that are supported.
2021-08-05 17:47:56 +02:00
Nikita Popov
ec4d926a80 Use different algorithm in cms tests
Same as with pkcs7, switch these tests to use an algorithm that
OpenSSL 3 supports out of the box.

Once again, we should consider changing the default or making it
required.
2021-08-05 16:32:27 +02:00
Nikita Popov
563b3e3472 Use different algorithm in pkcs7 tests
The default of OPENSSL_CIPHER_RC2_40 is no longer (non-legacy)
supported in OpenSSL 3, specify a newer cipher instead.

We should probably either change the default (if acceptable) or
make the parameter required.
2021-08-05 16:16:58 +02:00
Nikita Popov
cb48260fdd Avoid DH_compute_key() with OpenSSL 3
Instead construct a proper EVP_PKEY for the public key and
perform a derive operation.

Unfortunately we can't use a common code path here, because
EVP_PKEY_set1_encoded_public_key() formerly known as
EVP_PKEY_set1_tls_encodedpoint() does not appear to work with
DH keys prior to OpenSSL 3.
2021-08-05 16:03:07 +02:00
Nikita Popov
c6542b2a1e Extract php_openssl_pkey_derive() function
To allow sharing it with the openssl_dh_compute_key() implementation.
2021-08-05 15:50:25 +02:00
Nikita Popov
7168f71e00 Add test for openssl_dh_compute_key()
This function was not tested at all :(
2021-08-05 15:49:35 +02:00
Nikita Popov
f878bbd96b Store whether pkey object contains private key
Rather than querying whether the EVP_PKEY contains private key
information, determine this at time of construction and store it
in the PHP object.

OpenSSL doesn't provide an API for this purpose, and seems
somewhat reluctant to add one, see
https://github.com/openssl/openssl/issues/9467.

To avoid using deprecated low-level APIs to determine whether
something is a private key ourselves, remember it at the point
of construction.
2021-08-05 12:59:13 +02:00
Nikita Popov
cd8bf0b6bd Relax error check
The precise error is version-dependent, just check that there
is some kind of error reported.
2021-08-05 11:50:11 +02:00
Nikita Popov
13313d9b1b Use EVP_PKEY APIs for key generation
Use high level API instead of deprecated low level API.
2021-08-05 11:17:13 +02:00
Christoph M. Becker
86bc48c9e7
Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #81327: Error build openssl extension on php 7.4.22
2021-08-04 18:45:56 +02:00
Christoph M. Becker
5628afb782
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #81327: Error build openssl extension on php 7.4.22
2021-08-04 18:44:06 +02:00
Christoph M. Becker
6724d5d4c2
Fix #81327: Error build openssl extension on php 7.4.22
The recent fix for bug 52093 is not compatible with LibreSSL ≥ 2.7.0,
which we recognize as mostly OpenSSL 1.1.0 compatible, but they still
do not support `ASN1_INTEGER_set_int64()`.

Closes GH-7339.
2021-08-04 18:41:04 +02:00
Nikita Popov
384ad6e224 Use EVP_PKEY APIs for openssl_private_encrypt/public_decrypt
Use high level APIs instead of deprecated low level APIs.
2021-08-04 16:58:41 +02:00
Nikita Popov
0233afae27 Use EVP_PKEY API for openssl_public_encrypt/private_decrypt
Use the high level API instead of the deprecated low level API.
2021-08-04 16:44:29 +02:00
Nikita Popov
503146aa87 Avoid RC4 use in another test 2021-08-04 12:57:15 +02:00
Nikita Popov
a80ae97d31 Only report provided ciphers in openssl_get_cipher_methods()
With OpenSSL 3 ciphers may be registered, but not provided. Make
sure that openssl_get_cipher_methods() only returns provided
ciphers, so that "in_array openssl_get_cipher_methods" style
checks continue working as expected.
2021-08-04 12:56:32 +02:00
Nikita Popov
9695936341 Don't test legacy algorithms in SPKI tests
MD4 and RMD160 may not be available on newer OpenSSL versions.
2021-08-04 12:02:58 +02:00
Nikita Popov
046b36bcf8 Use different cipher in openssl_seal() test
RC4 is insecure and not supported in newer versions.
2021-08-04 12:02:57 +02:00
Nikita Popov
0a530d7650 Adjust some tests for whitespace differences in OpenSSL 3
A trailing newline is no longer present in OpenSSL 3.
2021-08-04 10:01:19 +02:00
Nikita Popov
3ea57cf838 Reduce security level in some OpenSSL tests
This allows tests using older protocols and algorithms to work
under OpenSSL 3.

Also account for minor changes in error reporting.
2021-08-04 10:00:40 +02:00
Nikita Popov
6249172ae3 Optimize openssl memory leak test
Just do one call and check whether memory usage changes. Looping
this 100000 times is extremely slow with debug builds of openssl.
2021-08-04 10:00:28 +02:00
Kamil Tekiela
cd0cd3d31e
Fix typos (#7327) 2021-08-01 18:03:30 +01:00
Joe Watkins
570d9b63e9
Not serializable flag permeation 2021-07-20 12:28:35 +02:00
Máté Kocsis
fc0d8983d3
Fix some smaller formatting inconsistencies in stubs 2021-07-20 00:52:26 +02:00
Christoph M. Becker
58ca47a06f
Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #52093: openssl_csr_sign truncates $serial
2021-07-01 15:46:07 +02:00
Christoph M. Becker
5b0a46908c
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #52093: openssl_csr_sign truncates $serial
2021-07-01 15:43:52 +02:00
Christoph M. Becker
334387bb70
Fix #52093: openssl_csr_sign truncates $serial
We use `ASN1_INTEGER_set_int64()` if supported[1], to avoid the
truncation of the integer.

[1] <https://www.openssl.org/docs/man1.1.0/man3/ASN1_INTEGER_set_int64.html#HISTORY>

Closes GH-7209.
2021-07-01 15:42:02 +02:00
Nikita Popov
6600ad6067 Add some missing EXTENSIONS sections to misc tests 2021-06-14 14:52:44 +02:00
Christoph M. Becker
4633a90202
Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix test wrt. OPENSSL_CONF
2021-06-13 16:56:02 +02:00
Christoph M. Becker
876bf8800a
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix test wrt. OPENSSL_CONF
2021-06-13 16:54:52 +02:00
Christoph M. Becker
d15e10d7ab
Fix test wrt. OPENSSL_CONF
This test is supposed to verify the path of the default OpenSSL config
file; it will fail, though, if OPENSSL_CONF is explicitly set, so we
explicitly unset this environment variable for this test.
2021-06-13 16:53:45 +02:00
Nikita Popov
39131219e8
Migrate more SKIPIF -> EXTENSIONS (#7139)
This is a mix of more automated and manual migration. It should remove all applicable extension_loaded() checks outside of skipif.inc files.
2021-06-11 12:58:44 +02:00
Nikita Popov
7485978339
Migrate SKIPIF -> EXTENSIONS (#7138)
This is an automated migration of most SKIPIF extension_loaded checks.
2021-06-11 11:57:42 +02:00
George Peter Banyard
b6958bb847
Implement "Deprecate implicit non-integer-compatible float to int conversions" RFC. (#6661)
RFC: https://wiki.php.net/rfc/implicit-float-int-deprecate

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-05-31 15:48:45 +01:00
Christoph M. Becker
509d34955c
Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #76694: native Windows cert verification uses CN as sever name
2021-05-31 14:37:55 +02:00
Christoph M. Becker
108105b2c6
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #76694: native Windows cert verification uses CN as sever name
2021-05-31 14:36:57 +02:00
Christoph M. Becker
7fd48264de
Fix #76694: native Windows cert verification uses CN as sever name
This is not guaranteed to work, since the actual server name may only
be given as SAN.  Since we're doing the peer verification later anyway
(using the respective context options as appropriate), there is no need
to even supply a server name when verifying against the Windows cert
store.

Closes GH-7060.
2021-05-31 14:35:17 +02:00
Nikita Popov
8c73dfe062 Remove silly code from openssl_pkey_free() test
W A T
2021-05-29 15:48:58 +02:00
Nikita Popov
840c78b2d8 Check RAND_egd after setting up openssl
Noticed this by accident: We should check functions in the library
only after setting it up.
2021-05-14 12:02:28 +02:00
George Peter Banyard
c40231afbf
Mark various functions with void arguments.
This fixes a bunch of [-Wstrict-prototypes] warning,
because in C func() and func(void) have different semantics.
2021-05-12 14:55:53 +01:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
Nikita Popov
c15dc63ad2 Merge branch 'PHP-8.0'
* PHP-8.0:
  openssl_pkcs7_read: input is data not filename
2021-05-05 09:50:11 +02:00
Vincent JARDIN
bb0107b63d openssl_pkcs7_read: input is data not filename
The argument should be an input string and not a filename.

Fix: https://github.com/php/doc-en/pull/559
Suggested-by: George Peter Banyard <girgias@php.net>

Closes GH-6942.
2021-05-05 09:49:53 +02:00