1--TEST-- 2Testing peer fingerprint on connection 3--SKIPIF-- 4<?php 5if (!extension_loaded("openssl")) die("skip openssl not loaded"); 6if (!function_exists("proc_open")) die("skip no proc_open"); 7?> 8--FILE-- 9<?php 10$serverCode = <<<'CODE' 11 $serverUri = "ssl://127.0.0.1:64321"; 12 $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; 13 $serverCtx = stream_context_create(['ssl' => [ 14 'local_cert' => __DIR__ . '/bug54992.pem' 15 ]]); 16 17 $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx); 18 phpt_notify(); 19 20 @stream_socket_accept($server, 1); 21 @stream_socket_accept($server, 1); 22CODE; 23 24$clientCode = <<<'CODE' 25 $serverUri = "ssl://127.0.0.1:64321"; 26 $clientFlags = STREAM_CLIENT_CONNECT; 27 $clientCtx = stream_context_create(['ssl' => [ 28 'verify_peer' => true, 29 'cafile' => __DIR__ . '/bug54992-ca.pem', 30 'capture_peer_cert' => true, 31 'peer_name' => 'bug54992.local', 32 ]]); 33 34 phpt_wait(); 35 36 // Run the following to get actual md5 (from sources root): 37 // openssl x509 -noout -fingerprint -md5 -inform pem -in ext/openssl/tests/bug54992.pem | cut -d '=' -f 2 | tr -d ':' | tr 'A-F' 'a-f' 38 // Currently it's 4edbbaf40a6a4b6af22b6d6d9818378f 39 // One below is intentionally broken (compare the last character): 40 stream_context_set_option($clientCtx, 'ssl', 'peer_fingerprint', '4edbbaf40a6a4b6af22b6d6d98183780'); 41 var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx)); 42 43 // Run the following to get actual sha256 (from sources root): 44 // openssl x509 -noout -fingerprint -sha256 -inform pem -in ext/openssl/tests/bug54992.pem | cut -d '=' -f 2 | tr -d ':' | tr 'A-F' 'a-f' 45 stream_context_set_option($clientCtx, 'ssl', 'peer_fingerprint', [ 46 'sha256' => 'b1d480a2f83594fa243d26378cf611f334d369e59558d87e3de1abe8f36cb997', 47 ]); 48 var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx)); 49CODE; 50 51include 'ServerClientTestCase.inc'; 52ServerClientTestCase::getInstance()->run($clientCode, $serverCode); 53?> 54--EXPECTF-- 55Warning: stream_socket_client(): peer_fingerprint match failure in %s on line %d 56 57Warning: stream_socket_client(): Failed to enable crypto in %s on line %d 58 59Warning: stream_socket_client(): unable to connect to ssl://127.0.0.1:64321 (Unknown error) in %s on line %d 60bool(false) 61resource(%d) of type (stream) 62