php - 仅使用 SSL 服务器证书连接到 MySQL
问题描述
我必须从旧的 PHP 5.3.3 应用程序连接到 MySQL 8。我无权升级 PHP 版本。
要求是连接必须通过 SSL 但不能使用 SSL 身份验证。MySQL 服务器配置为使用密码进行连接,但根本不需要客户端提供任何 SSL 身份验证证书。
我使用控制台命令来验证 SSL 连接从我的机器到服务器是否有效:
mysql -u username -p -h domain.com --ssl-mode=REQUIRED
mysql> \s
SSL: Cipher in use is DHE-RSA-AES128-GCM-SHA256
mysql> SHOW STATUS LIKE 'Ssl_cipher';
+---------------+---------------------------+
| Variable_name | Value |
+---------------+---------------------------+
| Ssl_cipher | DHE-RSA-AES128-GCM-SHA256 |
+---------------+---------------------------+
1 row in set (0.05 sec)
因此,当前连接使用服务器证书加密,并在没有任何 CA 验证的情况下静默接受它。
然后我尝试使用 mysqli 在 PHP 中重现它:
$mysqli = mysqli_init();
// I've no idea how to tell PHP to ignore all certificates but still use SSL as provided by the server;
// even passing random crap to ssl_set() doesn't change anything at all - not even failed connection
$mysqli->ssl_set(null, null, null, null, null);
$mysqli->real_connect($mysqliDomain, "username", "pass", "db", "3306", null, MYSQLI_CLIENT_SSL);
// Not sure about MYSQLI_CLIENT_SSL - PHP doc says it shouldn't be used from application side; but it doesn't work anyway, no matter if I use it or not.
// In addtion, disabling server cert verification MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT
// is not supported in PHP 5.3.3
$res = $mysqli->query("SHOW STATUS LIKE 'Ssl_cipher';");
while ( $row = $res->fetch_array() ) {
print_r($row);
}
无论我尝试什么,结果都是空密码值,这意味着连接未加密:
Array ( [0] => Ssl_cipher [Variable_name] => Ssl_cipher [1] => [Value] => )
如何解决这个问题?
解决方案
推荐阅读
- ios - 如何防止ios通用链接在用户点击子域A页面中的url时打开APP,而url链接到子域B
- python - 你好,我的代码有问题,我做对了吗?
- python - 在python中合并和排序元组列表的有效方法
- javascript - 如何使用 JSON Schema 声明至少一个属性的模式不为空?
- javascript - js:TypeError:无法读取未定义的属性“替换”使用
- linux - 如何在 nginx/1.18.0 ubuntu 中将 http 重定向到 https
- reactjs - 如何在 React js 中更改推荐人策略
- java - 指出未满足行格式错误的条件
- c++ - 为什么这种声明可以在 C++ 中工作?
- powerbi - 如何在 Power BI 中使用 DAX 中的筛选器计算百分比?