Bug #78775 [Com]: TLS issues from HTTP request affecting encrypted MySQL connections
| From: | lcobucci@php.net | Date: | Mon, 04 Nov 2019 17:41:14 +0000 |
| Subject: | Bug #78775 [Com]: TLS issues from HTTP request affecting encrypted MySQL connections | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-223561@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78775&edit=1
ID: 78775
Comment by: lcobucci@php.net
Reported by: lcobucci@php.net
Summary: TLS issues from HTTP request affecting encrypted
MySQL connections
Status: Open
Type: Bug
Package: OpenSSL related
Operating System: Debian
PHP Version: 7.2.24
Block user comment: N
Private report: N
New Comment:
Volker Dusch managed to reproduce this by using sockets and cURL only (also affects the latest PHP
7.4 RC):
Test script:
-------------
$sock = fsockopen("tls://google.com", 443);
var_dump($sock);
$handle = curl_init('https://self-signed.badssl.com/');
curl_setopt_array(
$handle,
[
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
]
);
var_dump(curl_exec($handle));
curl_close($handle);
fwrite($sock, "GET / HTTP/1.0\n\n");
var_dump(fread($sock, 8));
Expected result:
----------------
resource(4) of type (stream)
bool(false)
string(8) "HTTP/1.0"
Actual result:
--------------
resource(4) of type (stream)
bool(false)
Warning: fread(): SSL operation failed with code 1. OpenSSL Error messages:
error:140E0197:SSL routines:SSL_shutdown:shutdown while in init in /app/aa.php on line 19
string(0) ""
Previous Comments:
------------------------------------------------------------------------
[2019-11-03 20:25:35] lcobucci@php.net
Description:
------------
While setting up TLS for the DB in a development environment, I've found out that handshake
issues during cURL requests using URIs with a self-signed certificate were affecting completely
valid encrypted MySQL connections using both MySQLi and PDO MySQL.
I observed this because it was only happening on certain endpoints because they send this HTTP
request to another service.
It's quite an edge-case (and low priority IMHO). However, it got me crazy since the error
messages are all about the DB connection.
My idea was to create a better way to test this, but couldn't find any good example for
TLS+MySQLnd (via PDO or MySQLi)...
Test script:
---------------
$conn = new PDO(
'mysql:host=my-mysql-server;charset=utf8mb4',
'root',
'password',
[
PDO::MYSQL_ATTR_SSL_CA => '/local-tls-certificates/ca.pem',
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]
);
var_dump($conn->query('SELECT 1')->fetchAll(PDO::FETCH_ASSOC));
$handle = curl_init('https://self-signed.badssl.com/');
curl_setopt_array(
$handle,
[
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
]
);
var_dump(curl_exec($handle));
curl_close($handle);
var_dump($conn->query('SELECT 1')->fetchAll(PDO::FETCH_ASSOC));
Expected result:
----------------
array(1) {
[0]=>
array(1) {
[1]=>
string(1) "1"
}
}
bool(false)
array(1) {
[0]=>
array(1) {
[1]=>
string(1) "1"
}
}
Actual result:
--------------
array(1) {
[0]=>
array(1) {
[1]=>
string(1) "1"
}
}
bool(false)
[01-Nov-2019 17:03:02 UTC] PHP Warning: PDO::query(): SSL operation failed with code 1. OpenSSL
Error messages:
error:140E0197:SSL routines:SSL_shutdown:shutdown while in init in /app/aa.php on line 32
Warning: PDO::query(): SSL operation failed with code 1. OpenSSL Error messages:
error:140E0197:SSL routines:SSL_shutdown:shutdown while in init in /app/aa.php on line 32
[01-Nov-2019 17:03:02 UTC] PHP Warning: PDO::query(): MySQL server has gone away in /app/aa.php on
line 32
Warning: PDO::query(): MySQL server has gone away in /app/aa.php on line 32
[01-Nov-2019 17:03:02 UTC] PHP Warning: PDO::query(): Error reading result set's header in
/app/aa.php on line 32
Warning: PDO::query(): Error reading result set's header in /app/aa.php on line 32
[01-Nov-2019 17:03:02 UTC] PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error:
2006 MySQL server has gone away in /app/aa.php:32
Stack trace:
#0 /app/aa.php(32): PDO->query('SELECT 1')
#1 {main}
thrown in /app/aa.php on line 32
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
in /app/aa.php:32
Stack trace:
#0 /app/aa.php(32): PDO->query('SELECT 1')
#1 {main}
thrown in /app/aa.php on line 32
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78775&edit=1