【问题标题】:Can I use openssl s_client to retrieve the CA certificate for MySQL?我可以使用 openssl s_client 来检索 MySQL 的 CA 证书吗?
【发布时间】:2016-06-18 17:53:42
【问题描述】:

我可以使用openssl s_client 来检索 MySQL 的 CA 证书吗?

我可以使用以下方式访问远程数据库服务器

mysql -u theuser -h thehost --ssl --ssl-cipher=DHE-RSA-AES256-SHA -p thedatabase

现在我想使用 JDBC 连接到它。

我意识到我需要insert the public certificate into my Java key store。但是,我无法弄清楚如何检索公共证书。我意识到它位于/etc/mysql/ca.pem 或类似位置的远程服务器上。但是,我没有权限将该文件甚至ssh 读入机器。

我试过了

openssl s_client -cipher DHE-RSA-AES256-SHA  -connect thehost:3306

还有一些变化。我总是出错。例如

CONNECTED(00000003)
30495:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:/BuildRoot/
Library/Caches/com.apple.xbs/Sources/OpenSSL098/OpenSSL098-59/src/ssl/s23_clnt.c:618:

【问题讨论】:

  • 为什么服务器没有CA签名的证书?
  • SSL23_GET_SERVER_HELLO:unknown protocol... - OpenSSL 0.9.8 不支持 TLS 1.2。

标签: mysql macos ssl openssl


【解决方案1】:

我可以使用 openssl s_client 来检索 MySQL 的 CA 证书吗?

你可能做不到。

配置良好的服务器将发送服务器证书和所有中间证书,以构建到根 CA 的路径。您必须已经拥有根 CA 证书。


例如:

$ openssl s_client -connect www.cryptopp.com:443 -tls1 -servername www.cryptopp.com
CONNECTED(00000003)
depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Certification Authority
verify error:num=20:unable to get local issuer certificate
---
Certificate chain
 0 s:/OU=Domain Control Validated/OU=COMODO SSL Unified Communications
   i:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Domain Validation Secure Server CA
 1 s:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Domain Validation Secure Server CA
   i:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
 2 s:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority
   i:/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root
---
...

服务器发送了服务器的证书。上面显示为 0 s:/OU=Domain Control Validated/OU=COMODO SSL Unified CommunicationsS 表示其主题,而 I 表示其发行者。

服务器在 12 发送了两个中间证书。但是,我们需要在本地拥有证书 2 的颁发者来构建验证路径。证书 2 的颁发者使用 Common Name “AddTrust External CA Root”

“AddTrust External CA Root”可以从 Comodo 的网站[Root] AddTrust External CA Root 下载

如果服务器发送了根 CA,那么坏人可能会篡改链,而客户端也不会更聪明。他们可以换入自己的 CA 并使用邪恶的链。


我们可以通过获取根 CA 来清除 verify error:num=20:unable to get local issuer certificate,然后使用 -CAfile

$ openssl s_client -connect www.cryptopp.com:443 -tls1 -servername www.cryptopp.com \
  -CAfile addtrustexternalcaroot.pem

这将导致 Verify Ok (0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    • 2010-10-16
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 2018-04-06
    • 2019-12-19
    相关资源
    最近更新 更多