|
| 1 | +--TEST-- |
| 2 | +feof() is true after a TLS close_notify even if an earlier read left errno set to EAGAIN |
| 3 | +--EXTENSIONS-- |
| 4 | +openssl |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +if (!function_exists("proc_open")) die("skip no proc_open"); |
| 8 | +?> |
| 9 | +--FILE-- |
| 10 | +<?php |
| 11 | +$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'stream_eof_after_close_notify.pem.tmp'; |
| 12 | + |
| 13 | +$serverCode = <<<'CODE' |
| 14 | + $serverCtx = stream_context_create(['ssl' => ['local_cert' => '%s']]); |
| 15 | + $sock = stream_socket_server("tls://127.0.0.1:0", $errno, $errstr, |
| 16 | + STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $serverCtx); |
| 17 | + phpt_notify_server_start($sock); |
| 18 | +
|
| 19 | + $link = stream_socket_accept($sock); |
| 20 | + /* Let the client block in fread() first, so its SSL_read() sees WANT_READ */ |
| 21 | + phpt_wait(); |
| 22 | + usleep(100000); |
| 23 | + fwrite($link, "data"); |
| 24 | + /* close_notify only, the TCP connection stays open */ |
| 25 | + stream_socket_enable_crypto($link, false); |
| 26 | + phpt_wait(); |
| 27 | + fclose($link); |
| 28 | +CODE; |
| 29 | +$serverCode = sprintf($serverCode, $certFile); |
| 30 | + |
| 31 | +$clientCode = <<<'CODE' |
| 32 | + $clientCtx = stream_context_create(['ssl' => [ |
| 33 | + 'verify_peer' => false, |
| 34 | + 'verify_peer_name' => false, |
| 35 | + ]]); |
| 36 | + $sock = stream_socket_client("tls://{{ ADDR }}", $errno, $errstr, 2, STREAM_CLIENT_CONNECT, $clientCtx); |
| 37 | +
|
| 38 | + phpt_notify(); |
| 39 | + var_dump(fread($sock, 4)); |
| 40 | + var_dump(fread($sock, 4)); |
| 41 | + var_dump(feof($sock)); |
| 42 | + phpt_notify(); |
| 43 | +CODE; |
| 44 | + |
| 45 | +include 'CertificateGenerator.inc'; |
| 46 | +(new CertificateGenerator())->saveNewCertAsFileWithKey('stream_eof_after_close_notify', $certFile); |
| 47 | + |
| 48 | +include 'ServerClientTestCase.inc'; |
| 49 | +ServerClientTestCase::getInstance()->run($clientCode, $serverCode); |
| 50 | +?> |
| 51 | +--CLEAN-- |
| 52 | +<?php |
| 53 | +@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'stream_eof_after_close_notify.pem.tmp'); |
| 54 | +?> |
| 55 | +--EXPECT-- |
| 56 | +string(4) "data" |
| 57 | +string(0) "" |
| 58 | +bool(true) |
0 commit comments