Skip to content

Commit fbbf9e5

Browse files
bukkagithub-actions[bot]
authored andcommitted
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
1 parent 0b6102f commit fbbf9e5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

ext/openssl/tests/bug79589.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #65538: TLS unexpected EOF failure
3+
--EXTENSIONS--
4+
openssl
5+
--SKIPIF--
6+
<?php
7+
if (getenv("SKIP_ONLINE_TESTS")) die("skip online test");
8+
if (!defined("OPENSSL_KEYTYPE_EC")) die("skip EC disabled");
9+
?>
10+
--FILE--
11+
<?php
12+
13+
$release = file_get_contents(
14+
'https://chromedriver.storage.googleapis.com/LATEST_RELEASE',
15+
false,
16+
stream_context_create(['ssl' => ['verify_peer'=> false]])
17+
);
18+
echo gettype($release);
19+
20+
?>
21+
--EXPECT--
22+
string

ext/openssl/xp_ssl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,11 @@ int php_openssl_setup_crypto(php_stream *stream,
14951495
ssl_ctx_options &= ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
14961496
#endif
14971497

1498+
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
1499+
/* Only for OpenSSL 3+ to keep OpenSSL 1.1.1 behavior */
1500+
ssl_ctx_options |= SSL_OP_IGNORE_UNEXPECTED_EOF;
1501+
#endif
1502+
14981503
#if OPENSSL_VERSION_NUMBER >= 0x10000000L
14991504
if (!GET_VER_OPT("disable_compression") || zend_is_true(*val)) {
15001505
ssl_ctx_options |= SSL_OP_NO_COMPRESSION;

0 commit comments

Comments
 (0)