Bug #80001 [Fbk->Asn]: SSL connection error is not reported via mysqli::$connect_error

From: Date: Wed, 02 Jun 2021 15:06:32 +0000
Subject: Bug #80001 [Fbk->Asn]: SSL connection error is not reported via mysqli::$connect_error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234175@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80001&edit=1

 ID:                 80001
 User updated by:    morozov at tut dot by
 Reported by:        morozov at tut dot by
 Summary:            SSL connection error is not reported via
                     mysqli::$connect_error
-Status:             Feedback
+Status:             Assigned
 Type:               Bug
 Package:            MySQLi related
 Operating System:   Linux
 PHP Version:        7.4.9
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

No, it returns false.


Previous Comments:
------------------------------------------------------------------------
[2021-06-02 10:51:27] cmb@php.net

Would that error be reported by openssl_error_string()?

------------------------------------------------------------------------
[2020-08-20 06:01:42] morozov at tut dot by

Description:
------------
According to the documentation, mysqli::$connect_error returns the last error message string from
the last call to mysqli_connect(). NULL is returned if no error occurred.


However, if the underlying connection error is related to SSL, mysqli::$connect_error remains NULL
which is incorrect.

The reproduction script tries to connect to a MySQL server running in a https://hub.docker.com/_/mysql container and relies on the
fact that the CN in the autogenerated server certificate doesn't match its hostname.

The same problem is reproducible with literally any SSL error.

Test script:
---------------
<?php

$conn = mysqli_init();

$conn->ssl_set('client-key.pem', 'client-cert.pem', 'ca.pem',
'', '');

if (!$conn->real_connect('127.0.0.1', 'root', '',
'mysql')) {
    var_dump($conn->connect_error);
    exit(1);
}


Expected result:
----------------
$conn->connect_error contains a string with an error message.

Actual result:
--------------
Warning: mysqli::real_connect(): Peer certificate
CN=MySQL_Server_8.0.18_Auto_Generated_Server_Certificate' did not match expected
CN=127.0.0.1' in /home/morozov/mysqi-tls.php on line 7

Warning: mysqli::real_connect(): Cannot connect to MySQL by using SSL in /home/morozov/mysqi-tls.php
on line 7

Warning: mysqli::real_connect(): [2002]  (trying to connect via (null)) in
/home/morozov/mysqi-tls.php on line 7

Warning: mysqli::real_connect(): (HY000/2002):  in /home/morozov/mysqi-tls.php on line 7
NULL


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80001&edit=1


Thread (6 messages)

« previous php.bugs (#234175) next »