From: lcobucci
Operating system: Debian
PHP version: 7.2.24
Package: OpenSSL related
Bug Type: Bug
Bug description:TLS issues from HTTP request affecting encrypted MySQL connections
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 bug report at https://bugs.php.net/bug.php?id=78775&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78775&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78775&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78775&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78775&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78775&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78775&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78775&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78775&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78775&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78775&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78775&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78775&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78775&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78775&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78775&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78775&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78775&r=mysqlcfg