|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-06-04 14:10 UTC] laird_ngrps at dodo dot com dot au
Description:
------------
When the CN_match stream context option is specified for an SSL stream opened
with stream_socket_client(), if the CN supplied does not match, then the stream
connection does not fail and does not return an error as it should.
After the supplied patch was applied, the stream socket returned an error as
expected; the output then was (I haven't delved deep enough into the code to
work out how to set a meaningful error message and error number with the patch;
all values in square brackets are my edits for privacy; line 17 is that of the
call to stream_socket_client()):
Warning: stream_socket_client(): Peer certificate CN=`TempCert' did not match
expected CN=`TempCert.bad' in [filepath] on line 17
Warning: stream_socket_client(): Failed to enable crypto in [filepath] on line
17
Warning: stream_socket_client(): unable to connect to ssl://[ipaddress]:[port]
(Unknown error) in [filepath] on line 17
SSL socket connection error: "" (0)
--------
I've checked and this bug seems to also apply to the current versions of the PHP
source in the subversion repositories.
Test script:
---------------
/* First set $server, $port and $cafile */
$context = stream_context_create(array('ssl' => array(
'verify_peer' => true,
'cafile' => $cafile,
'CN_match' => 'TempCert.bad',
)));
$sock = stream_socket_client("ssl://$server:$port", $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context);
if ($sock === false) die("SSL socket connection error: \"$errstr\" ($errno)\n");
$msg = "A test message";
if (fputs($sock, "$msg<EOF>\n") === false) echo "fputs returned false\n";
else {
echo "SENT:: $msg\n";
$line = fgets($sock);
echo "RCVD:: $line\n";
}
fclose($sock);
Expected result:
----------------
SSL socket connection error: "[some error message indicating that the CN failed
to match]" ([some error number])
Actual result:
--------------
Warning: stream_socket_client(): Peer certificate CN=`TempCert' did not match
expected CN=`TempCert.bad' in [filepath] on line 17
SENT:: A test message
RCVD:: [a bunch of random characters, different each time]
Patchesxp_ssl_patch (last revision 2011-06-04 12:11 UTC by laird_ngrps at dodo dot com dot au)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 10:00:01 2025 UTC |
if ( ! $sock ) die ("Connection error");if ( ! $sock ) die ("Connection error");