使用 open_ssl 显示整个信任链

使用 open_ssl 显示整个信任链

我正在使用以下命令来显示整个证书链:

openssl s_client \
  -servername myServer.com \
  -connect myServer.com:443 \
  -prexit \
  -showcerts

它工作正常,但没有显示属于 CA 的证书(-----开始证书----------开始证书-----)。只显示属于叶子和中间 CA 的那些。您能告诉我如何检索 pem 吗?

我感兴趣的是巴尔的摩 Cyber​​Trust Root。

谢谢。

答案1

s_client -showcerts显示所有证书服务器发送;这可以省略根证书,并且通常会省略,具体取决于服务器软件和/或配置。请参阅rfc5246

certificate_list

  This is a sequence (chain) of certificates.  The sender's
  certificate MUST come first in the list.  Each following
  certificate MUST directly certify the one preceding it.  Because
  certificate validation requires that root keys be distributed
  independently, the self-signed certificate that specifies the root
  certificate authority MAY be omitted from the chain, under the
  assumption that the remote end must already possess it in order to
  validate it in any case.

稍微放松rfc8446

... The sender's certificate MUST come in the first
CertificateEntry in the list.  Each following certificate SHOULD
directly certify the one immediately preceding it.  Because
certificate validation requires that trust anchors be distributed
independently, a certificate that specifies a trust anchor MAY be
omitted from the chain, provided that supported peers are known to
possess any omitted certificates.

因此通常 SSL-now-TLS 客户端应该已经包含要使用的根证书(或可能的其他锚点)的信任库。OpenSSL 代码将使用如果提供,则提供“CA 文件”和/或“CA 目录”,如果您未另行指定(您没有指定),则包括系统默认的证书,但 OpenSSL 上游不提供此类证书。许多版本或软件包都提供此类证书,例如,我使用过的所有 Unix 发行版都提供软件包ca-certs或类似软件包,并配置 openssl 以使用它(还配置其他软件,如 Firefox/NSS 和 Java 以使用相同的 ca 证书)。curl 项目发布Mozilla/Firefox 信任库的移植转换为我使用的 PEM/OpenSSL 格式,其中包含“Baltimore Cyber​​Trust Root”。我的 Windows 系统和 Firefox 也有它,并且可以导出 PEM。您通常使用下级证书(此处为中间 CA 证书)中的颁发者名称和/或 AuthorityKeyIdentifier 从信任库中选择根证书。

X.509/PKIX 格式支持扩展字段,即 AuthorityInformationAccess 中的 caIssuer(又名 AIA),它提供了一个 URL,CA 承诺在该 URL 上提供父证书的下载。直到最近,AIA/caIssuer 还很少提供,但现在它已变得越来越普遍(CABforum 使其成为“应该”);我对 Cyber​​Trust(不再是 Baltimore,现在是 Digicert)不太了解。

选择最后发送的证书(您所说的第二个),通过剪切粘贴或类似方法,openssl s_client -showcerts ... | awk '/-----BEGIN CERT/{x++} x==2' >file然后openssl x509 -text -noout <file查找 AuthorityInformationAccess 扩展。

请注意,这并不安全;如果您的连接被拦截,攻击者可以向您发送带有假 caIssuer 的假证书,当您使用它时会获得假根。为了防止这种情况,您需要使用根密钥验证中间 CA 证书,但要做到这一点,您必须已经拥有根,因此没有理由获取它。

如果您尚未将根证书放入信任库中,而中间证书未向您提供证书颁发者,则需要进行搜索,但自从“证书透明度”流行以来,搜索变得更加容易;现在,您无需让 Google(或 DDG 等)为您提供多个网站,只需查看一个或多个精选的公共日志即可。我喜欢https://crt.sh作为前端(还有其他),它会立即找到https://crt.sh/?id=76并提供了下载链接(看左栏)。

相关内容