From:
Operating system: Linux
PHP version: 5.3.6
Package: Streams related
Bug Type: Bug
Bug description:Stream not closed and error not returned when SSL CN_match fails
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]
--
Edit bug report at http://bugs.php.net/bug.php?id=54992&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=54992&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=54992&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=54992&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=54992&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=54992&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=54992&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=54992&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=54992&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=54992&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=54992&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=54992&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=54992&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=54992&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=54992&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54992&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54992&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=54992&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=54992&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=54992&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=54992&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=54992&r=mysqlcfg