PHP  
 PHP_7_1
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

Test Failure Report for ext/openssl/tests/bug74159.phpt ('Bug #74159: Writing a large buffer to non-blocking encrypted streams fails')

Script

1: <?php
2:
// the server code is doing many readings in a short interval which is
3: // not really reliable on more powerful machine but cover different
4: // scenarios which might be useful. More reliable test is bug72333.phpt
5:
$serverCode = <<<'CODE'
6:
    $serverUri = "ssl://127.0.0.1:10012";
7:     $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
8:     $serverCtx = stream_context_create(['ssl' => [
9:         'local_cert' => __DIR__ . '/bug54992.pem',
10:         'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER,
11:     ]]);
12:
13:     $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
14:     phpt_notify();
15:
16:     $client = stream_socket_accept($server, 1);
17:
18:     if (!$client) {
19:         exit();
20:     }
21:
22:     $data = '';
23:     while (strlen($data) < 0xfffff) {
24:         $buffer = fread($client, 8192);
25:         if (empty($buffer)) {
26:             exit();
27:         }
28:         $data .= $buffer;
29:         usleep(100);
30:     }
31:
32:     fclose($client);
33:
CODE;
34:
35:
$clientCode = <<<'CODE'
36:
    function streamRead($stream) : int {
37:         return strlen(fread($stream, 8192));
38:     }
39:
40:     function streamWrite($stream, $data) : int {
41:         return fwrite($stream, $data);
42:     }
43:
44:     function waitForWrite(...$streams) : bool {
45:         $read = null;
46:         $except = null;
47:         while($streams && !($n = stream_select($read, $streams, $except, 1)));
48:         return $n > 0;
49:     }
50:
51:     function waitForRead(...$streams) : bool {
52:         $write = null;
53:         $except = null;
54:         while ($streams && !($n = stream_select($streams, $write, $except, 1)));
55:         return $n > 0;
56:     }
57:
58:     set_error_handler(function ($errno, $errstr) {
59:         exit("$errstr\n");
60:     });
61:
62:     $serverUri = "tcp://127.0.0.1:10012";
63:     $clientFlags = STREAM_CLIENT_CONNECT;
64:     $clientCtx = stream_context_create(['ssl' => [
65:         'verify_peer' => true,
66:         'cafile' => __DIR__ . '/bug54992-ca.pem',
67:         'peer_name' => 'bug54992.local',
68:     ]]);
69:
70:     phpt_wait();
71:
72:     $fp = stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx);
73:
74:     stream_set_blocking($fp, false);
75:     while (0 === ($n = stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT)));
76:
77:     $data = str_repeat("a", 0xfffff);
78:     $written = 0;
79:     $total = $written;
80:     while(!empty($data)) {
81:         $written = streamWrite($fp, $data);
82:         $total += $written;
83:         $data = substr($data, $written);
84:         waitForWrite($fp);
85:     }
86:     printf("Written %d bytes\n", $total);
87:
88:     while(waitForRead($fp)) {
89:         streamRead($fp);
90:         if (feof($fp)) {
91:             break;
92:         }
93:     }
94:
95:     exit("DONE\n");
96:
CODE;
97:
98: include 
'ServerClientTestCase.inc';
99:
ServerClientTestCase::getInstance()->run($clientCode$serverCode);
100:
?>
101:

Expected

Written 1048575 bytes
DONE

Output

stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Diff

001+ stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
002+ error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
001- Written 1048575 bytes
002- DONE

 

Generated at Wed, 08 Dec 2021 19:17:21 +0000 (7 hours ago)

Copyright © 2005-2021 The PHP Group
All rights reserved.