Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ PHP NEWS
`session_new_cb`. (DanielEScherzer)
. Fixed bug GH-20920 (LibreSSL build regression with PHP 8.5).
(Eugene Gvozdetsky, Theo Buehler, Jakub Zelenka)
. Fixed bug GH-25667 (LibreSSL build broken since PHP 8.6). (Jakub Zelenka)

- PDO_Firebird:
. Fixed stack buffer overflow with long connection user names, passwords,
Expand Down
4 changes: 4 additions & 0 deletions ext/openssl/tests/gh25172.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ GH-25172: TLS session reuse must not share callbacks with a persistent stream
openssl
--CREDITS--
cxxz16
--SKIPIF--
<?php
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support PSK");
?>
--FILE--
<?php
function reuse_on_persistent(array $options, int $method): void {
Expand Down
1 change: 1 addition & 0 deletions ext/openssl/tests/session_resumption_client_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support TLS 1.3 session resumption");
?>
--FILE--
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support TLS 1.3 session resumption");
?>
--FILE--
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support TLS 1.3 session resumption");
?>
--FILE--
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support TLS 1.3 session resumption");
?>
--FILE--
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support TLS 1.3 session resumption");
?>
--FILE--
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support TLS 1.3 session resumption");
?>
--FILE--
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support TLS 1.3 session resumption");
?>
--FILE--
<?php
Expand Down
1 change: 1 addition & 0 deletions ext/openssl/tests/tls_early_data_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ openssl
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (!defined('STREAM_CRYPTO_METHOD_TLSv1_3_SERVER')) die("skip TLS 1.3 not available");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support TLS 1.3 early data");
?>
--FILE--
<?php
Expand Down
1 change: 1 addition & 0 deletions ext/openssl/tests/tls_early_data_large.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ openssl
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (!defined('STREAM_CRYPTO_METHOD_TLSv1_3_SERVER')) die("skip TLS 1.3 not available");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support TLS 1.3 early data");
?>
--FILE--
<?php
Expand Down
1 change: 1 addition & 0 deletions ext/openssl/tests/tls_early_data_unsupported.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ openssl
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (!defined('STREAM_CRYPTO_METHOD_TLSv1_3_SERVER')) die("skip TLS 1.3 not available");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support TLS 1.3 early data");
?>
--FILE--
<?php
Expand Down
1 change: 1 addition & 0 deletions ext/openssl/tests/tls_psk_callback_not_callable.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support PSK");
?>
--FILE--
<?php
Expand Down
1 change: 1 addition & 0 deletions ext/openssl/tests/tls_psk_callback_wrong_type.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support PSK");
?>
--FILE--
<?php
Expand Down
1 change: 1 addition & 0 deletions ext/openssl/tests/tls_psk_client_callback_throws.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support PSK");
?>
--FILE--
<?php
Expand Down
1 change: 1 addition & 0 deletions ext/openssl/tests/tls_psk_client_no_identity.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ openssl
--SKIPIF--
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support PSK");
?>
--FILE--
<?php
Expand Down
1 change: 1 addition & 0 deletions ext/openssl/tests/tls_psk_oversized_identity.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ openssl
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (OPENSSL_VERSION_NUMBER < 0x10101000) die("skip OpenSSL >= 1.1.1 required");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support PSK");
?>
--FILE--
<?php
Expand Down
1 change: 1 addition & 0 deletions ext/openssl/tests/tls_psk_tls12_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ openssl
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (OPENSSL_VERSION_NUMBER < 0x10101000) die("skip OpenSSL >= 1.1.1 required");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support PSK");
?>
--FILE--
<?php
Expand Down
1 change: 1 addition & 0 deletions ext/openssl/tests/tls_psk_tls13_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ openssl
<?php
if (!function_exists("proc_open")) die("skip no proc_open");
if (!defined('STREAM_CRYPTO_METHOD_TLSv1_3_SERVER')) die("skip TLS 1.3 not available");
if (str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip LibreSSL does not support PSK");
?>
--FILE--
<?php
Expand Down
30 changes: 30 additions & 0 deletions ext/openssl/tests/tls_psk_unsupported.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
PSK callbacks fail when the SSL library does not support PSK
--EXTENSIONS--
openssl
--SKIPIF--
<?php
if (!str_contains(OPENSSL_VERSION_TEXT, 'LibreSSL')) die("skip only for SSL libraries without PSK support");
?>
--FILE--
<?php
function try_psk(string $option, bool $server): void {
$listener = stream_socket_server('tcp://127.0.0.1:0');
$client = stream_socket_client('tcp://' . stream_socket_get_name($listener, false));
$peer = stream_socket_accept($listener);
$stream = $server ? $peer : $client;
stream_context_set_option($stream, 'ssl', $option, fn() => null);
stream_set_blocking($stream, false);
var_dump(stream_socket_enable_crypto($stream, true,
$server ? STREAM_CRYPTO_METHOD_TLS_SERVER : STREAM_CRYPTO_METHOD_TLS_CLIENT));
}

try_psk('psk_client_cb', false);
try_psk('psk_server_cb', true);
?>
--EXPECTF--
Warning: stream_socket_enable_crypto(): psk_client_cb is not supported by the SSL library against which PHP is linked in %s on line %d
bool(false)

Warning: stream_socket_enable_crypto(): psk_server_cb is not supported by the SSL library against which PHP is linked in %s on line %d
bool(false)
33 changes: 30 additions & 3 deletions ext/openssl/xp_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@
#define HAVE_SEC_LEVEL 1
#endif

/* LibreSSL implements neither TLS 1.3 external PSK nor early data (0-RTT) */
#if defined(HAVE_TLS13) && !defined(LIBRESSL_VERSION_NUMBER)
#define HAVE_TLS13_PSK 1
#define HAVE_TLS13_EARLY_DATA 1
#endif

#if !defined(OPENSSL_NO_PSK) || defined(HAVE_TLS13_PSK)
#define HAVE_TLS_PSK 1
#endif

#if OPENSSL_VERSION_NUMBER < 0x40000000L && !defined(OPENSSL_NO_SSL3)
#define HAVE_SSL3 1
#define PHP_OPENSSL_MIN_PROTO_VERSION STREAM_CRYPTO_METHOD_SSLv3
Expand Down Expand Up @@ -178,8 +188,10 @@ typedef struct _php_openssl_alpn_ctx_t {
#endif

/* TLS 1.3 PSK ciphersuite IDs */
#ifdef HAVE_TLS13_PSK
static const unsigned char php_openssl_tls13_aes128gcmsha256_id[] = { 0x13, 0x01 };
static const unsigned char php_openssl_tls13_aes256gcmsha384_id[] = { 0x13, 0x02 };
#endif

/* Holds PSK callbacks */
typedef struct _php_openssl_psk_callbacks_t {
Expand Down Expand Up @@ -1670,6 +1682,7 @@ static int php_openssl_get_ctx_stream_data_index(void)
return ctx_data_index;
}

#ifdef HAVE_TLS13_PSK
/**
* Build a SSL_SESSION suitable for use as an external PSK in TLS 1.3.
*/
Expand Down Expand Up @@ -1703,18 +1716,17 @@ static SSL_SESSION *php_openssl_psk_build_session(SSL *ssl,
return NULL;
}

#ifdef HAVE_TLS13
/* Allow 0-RTT for PSK sessions (0 on the client, so a no-op there) */
uint32_t max_early_data = SSL_get_max_early_data(ssl);
if (max_early_data > 0) {
SSL_SESSION_set_max_early_data(sess, max_early_data);
}
#endif

return sess;
}
#endif /* HAVE_TLS13_PSK */


#ifdef HAVE_TLS_PSK
/**
* Invoke a user PHP callback (psk_client_cb or psk_server_cb).
*/
Expand Down Expand Up @@ -1896,6 +1908,7 @@ static unsigned int php_openssl_psk_server_cb(SSL *ssl, const char *identity,
}
#endif /* OPENSSL_NO_PSK */

#ifdef HAVE_TLS13_PSK
/* TLS 1.3 PSK callbacks */

static int php_openssl_psk_use_session_cb(SSL *ssl, const EVP_MD *md,
Expand Down Expand Up @@ -2029,6 +2042,8 @@ static int php_openssl_psk_find_session_cb(SSL *ssl, const unsigned char *identi
*sess = session;
return 1;
}
#endif /* HAVE_TLS13_PSK */
#endif /* HAVE_TLS_PSK */

/* PSK setup */

Expand All @@ -2038,6 +2053,11 @@ static zend_result php_openssl_validate_and_allocate_psk_callback(
bool is_client, bool is_persistent)
{
const char *callback_name = is_client ? "psk_client_cb" : "psk_server_cb";
#ifndef HAVE_TLS_PSK
php_stream_warn(stream, ProtocolUnsupported,
"%s is not supported by the SSL library against which PHP is linked", callback_name);
return FAILURE;
#else
if (is_persistent) {
php_stream_warn(stream, PersistentNotSupported,
"%s is not supported for persistent streams", callback_name);
Expand Down Expand Up @@ -2070,6 +2090,7 @@ static zend_result php_openssl_validate_and_allocate_psk_callback(
}

return SUCCESS;
#endif
}

static zend_result php_openssl_setup_client_psk(php_stream *stream,
Expand All @@ -2089,7 +2110,9 @@ static zend_result php_openssl_setup_client_psk(php_stream *stream,
#ifndef OPENSSL_NO_PSK
SSL_CTX_set_psk_client_callback(sslsock->ctx, php_openssl_psk_client_cb);
#endif
#ifdef HAVE_TLS13_PSK
SSL_CTX_set_psk_use_session_callback(sslsock->ctx, php_openssl_psk_use_session_cb);
#endif

return SUCCESS;
}
Expand All @@ -2111,7 +2134,9 @@ static zend_result php_openssl_setup_server_psk(php_stream *stream,
#ifndef OPENSSL_NO_PSK
SSL_CTX_set_psk_server_callback(sslsock->ctx, php_openssl_psk_server_cb);
#endif
#ifdef HAVE_TLS13_PSK
SSL_CTX_set_psk_find_session_callback(sslsock->ctx, php_openssl_psk_find_session_cb);
#endif

if (!GET_VER_OPT("session_id_context")) {
static const unsigned char default_psk_sid_ctx[] = "PHP_PSK";
Expand Down Expand Up @@ -2192,8 +2217,10 @@ static zend_result php_openssl_setup_server_early_data(php_stream *stream,

if (max_early_data > 0) {
SSL_CTX_set_max_early_data(sslsock->ctx, (uint32_t) max_early_data);
#ifdef HAVE_TLS13_EARLY_DATA
/* Accept as much as we advertise (recv limit defaults to 16 KB otherwise) */
SSL_CTX_set_recv_max_early_data(sslsock->ctx, (uint32_t) max_early_data);
#endif
/* 0-RTT requires resumption, so ensure the server cache is not left off */
if (SSL_CTX_get_session_cache_mode(sslsock->ctx) == SSL_SESS_CACHE_OFF) {
SSL_CTX_set_session_cache_mode(sslsock->ctx, SSL_SESS_CACHE_SERVER);
Expand Down
Loading