简体   繁体   English

SSL自签名证书,用于与Mysql连接

[英]SSL self-signed certifications to connect with Mysql with PHP

Summary: PHP gives an error when using self-signed certificates as provided by Google Cloud SQL. 简介:使用Google Cloud SQL提供的自签名证书时,PHP会出错。

Details: I am trying to connect to Google Cloud SQL's mysql instance using PHP's mysqli library. 详细信息:我正在尝试使用PHP的mysqli库连接到Google Cloud SQL的mysql实例。

$db = mysqli_init();
mysqli_options ($db, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
$db->ssl_set('client-key.pem', 'client-cert.pem', 'server-ca.pem', NULL, NULL);
$query = mysqli_real_connect ($db, $host, $user, $pass, $dbname, 3306, NULL, MYSQLI_CLIENT_SSL);

As I understand Google cloud allows self-signed certificates, from where I downloaded the client-key.pem, client-cert.pem, server-ca.pem files. 据我所知,Google云允许自签名证书,我从那里下载了client-key.pem,client-cert.pem,server-ca.pem文件。

I get the following error from PHP when validating the certificate: 验证证书时,我从PHP收到以下错误:

mysqli_real_connect(): Peer certificate CN=`<project_name>' did not match expected CN=`<db_IP>'

Based on my research so far, it seems I need a way to disable Verify_Peer check, which apparently PHP doesn't allow. 根据我到目前为止的研究,似乎我需要一种方法来禁用Verify_Peer检查,这显然是PHP不允许的。 Can you please validate this and/or offer a way to use SSL with Google Cloud SQL from PHP? 您能否验证这一点和/或提供一种方法来使用SSL中的Google Cloud SQL SSL?

Thank you. 谢谢。

看起来PHP中的2个相关错误仍未完全解决: #68344#71003

Unfortunately, this is not possible yet. 不幸的是,这还不可能。 PHP does a lookup and the result will not match the self-signed certificate. PHP执行查找,结果与自签名证书不匹配。 One will contain the name and the other will contain the IP. 一个将包含名称,另一个将包含IP。

There is no way [currently] to have PHP ignore this, therefor connecting in this instance, via SSL, is not possible. [目前]没有办法让PHP忽略这一点,因此在这种情况下通过SSL连接是不可能的。

you need to Replace 你需要替换

$query = mysqli_real_connect ($db, $host, $user, $pass, $dbname, 3306, NULL, MYSQLI_CLIENT_SSL);

With

$query = mysqli_real_connect ($db, $host, $user, $pass, $dbname, 3306, NULL, MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);

it is Like MYSQLI_CLIENT_SSL, but disables validation of the provided SSL certificate. 它与MYSQLI_CLIENT_SSL类似,但禁用所提供SSL证书的验证。 This is only for installations using MySQL Native Driver and MySQL 5.6 or later. 这仅适用于使用MySQL Native Driver和MySQL 5.6或更高版本的安装。

Hope it will help. 希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM