PDO not working with SSL

2019-05-20 23:47发布

If I run this code requiring SSL it won't work (Access denied for user) but without SSL it works.

What might be happening at the server end to stop this? Obviously not password/user config and another connection to the server with SSL works fine so I know the server is accepting encrypted connections.

For info I have already checked out Connect to remote MySQL server with SSL from PHP.

$dbE = new PDO(
    'mysql:dbname=DB;host=IP',
    USER,
    PASS,
    array(
        PDO::MYSQL_ATTR_SSL_KEY => 'D:\ssl\mysql\client-key.pem',
        PDO::MYSQL_ATTR_SSL_CERT => 'D:\ssl\mysql\client-cert.pem',
        PDO::MYSQL_ATTR_SSL_CA => 'D:\ssl\mysql\ca-cert.pem'
    )
);

标签: php ssl pdo
1条回答
太酷不给撩
2楼-- · 2019-05-21 00:33

After a LOT of investigation, rebuilding certificates and head bashing I figured it out (ptl). The issue was (and I've not really found this anywhere) but the client certificates must be COPIED from the server to the client. The paths used in the PDO configs are paths to the CLIENTS copy of the ca/cert/key as opposed to the paths on the server. I hadn't appreciated this and I think it needed to be slightly clearer.

Even the example on http://dev.mysql.com/doc/refman/5.0/en/creating-ssl-certs.html implies the client keys reside on the server as opposed to the client. I hope this is helpful.

查看更多
登录 后发表回答