Merge branch 'PHP-8.3'

This commit is contained in:
Jakub Zelenka 2024-03-29 16:33:44 +00:00
commit 09f5e7921e
No known key found for this signature in database
GPG key ID: 1C0779DC5C0A9DE4
2 changed files with 41 additions and 11 deletions

View file

@ -26,6 +26,35 @@ function phpt_has_sslv3() {
return $result;
}
function phpt_extract_tls_records($rawData) {
$records = [];
$offset = 0;
$dataLength = strlen($rawData);
while ($offset < $dataLength) {
// Ensure there's enough data left for the header.
if ($offset + 5 > $dataLength) {
break;
}
// Extract the length of the current record.
$length = unpack("n", substr($rawData, $offset + 3, 2))[1];
// Check if the total length is within the bounds of the rawData.
if ($offset + 5 + $length > $dataLength) {
break;
}
// Extract the record and add it to the records array.
$records[] = substr($rawData, $offset, 5 + $length);
// Move the offset past the current record.
$offset += 5 + $length;
}
return $records;
}
/**
* This is a singleton to let the wait/notify functions work
* I know it's horrible, but it's a means to an end

View file

@ -63,25 +63,26 @@ $proxyCode = <<<'CODE'
$read = [$upstream, $conn];
$applicationData = false;
$i = 1;
while (stream_select($read, $write, $except, 1)) {
foreach ($read as $fp) {
$data = stream_get_contents($fp);
if ($fp === $conn) {
fwrite($upstream, $data);
} else {
if ($data !== '' && $data[0] === chr(23)) {
if (!$applicationData) {
$applicationData = true;
fwrite($conn, $data[0]);
phpt_notify();
sleep(1);
fwrite($conn, substr($data, 1));
foreach (phpt_extract_tls_records($data) as $record) {
if ($record !== '' && $record[0] === chr(23)) {
if (!$applicationData) {
$applicationData = true;
fwrite($conn, $record[0]);
phpt_notify();
sleep(1);
fwrite($conn, substr($record, 1));
} else {
fwrite($conn, $record);
}
} else {
fwrite($conn, $data);
fwrite($conn, $record);
}
} else {
fwrite($conn, $data);
}
}
}