From: butesa at freenet dot de
Operating system: Ubuntu 12.04 x64
PHP version: 5.5.3
Package: Network related
Bug Type: Bug
Bug description:stream_socket_client() does not set $errstr
Description:
------------
stream_socket_client() leaves $errno and $errstr empty, when the
certificate check for ssl fails.
The manual says "If the value returned in errno is 0 and the function
returned FALSE, it is an indication that the error occurred before the
connect() call."
But connect() must have been successful to perform a certificate check.
Also, stream_socket_client() throws 3 warnings, but only the first one
gives you a hint what went wrong. $php_errormsg gives only the last
warning. So the only way to fetch a useful error string is using a custom
error handler.
Test script:
---------------
<?php
ini_set('php_track_errors','1');
$address = 'ssl://j-matschke.de:443';
$errno = 0;
$errstr = '';
$opt = array(
'ssl' => array(
'verify_peer' => true,
'cafile' => '/etc/ssl/certs/ca-certificates.crt',
'CN_match' => 'j-matschke.de',
),
);
$context = stream_context_create($opt);
$conn = stream_socket_client($address, $errno, $errstr, 5,
STREAM_CLIENT_CONNECT, $context);
var_dump($conn);
var_dump($errno);
var_dump($errstr);
var_dump($php_errormsg);
?>
Expected result:
----------------
Only one warning should be thrown. This warning should also be used as
$errstr.
Actual result:
--------------
Warning: stream_socket_client(): Peer certificate CN=`*.kasserver.com' did
not match expected CN=`j-matschke.de' in
/mnt/Daten/home/Code/PHP/Web/servercheck3/buggy/ssl.php on line 14
Warning: stream_socket_client(): Failed to enable crypto in
/mnt/Daten/home/Code/PHP/Web/servercheck3/buggy/ssl.php on line 14
Warning: stream_socket_client(): unable to connect to
ssl://j-matschke.de:443 (Unknown error) in
/mnt/Daten/home/Code/PHP/Web/servercheck3/buggy/ssl.php on line 14
bool(false)
int(0)
string(0) ""
string(84) "stream_socket_client(): unable to connect to
ssl://j-matschke.de:443 (Unknown error)"
--
Edit bug report at https://bugs.php.net/bug.php?id=65679&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=65679&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=65679&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=65679&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65679&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65679&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65679&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65679&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65679&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65679&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65679&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=65679&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=65679&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65679&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65679&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65679&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65679&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65679&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65679&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65679&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65679&r=mysqlcfg