[英]Different certificate chain order when using Node's HTTPS/TLS vs. OpenSSL s_client
I'm trying to parse the certificate chain using Node's HTTPS request. 我正在尝试使用Node的HTTPS请求解析证书链。 I'm testing it on npmjs.com (not www.npmjs.com).
我在npmjs.com上测试它(不是www.npmjs.com)。 When I test it on OpenSSL, it shows me that the chain is in the incorrect order.
当我在OpenSSL上测试它时,它向我显示链的顺序不正确。
openssl s_client -connect npmjs.com:443 -showcerts
OpenSSL Response First Certificate OpenSSL响应第一证书
subject: /OU=GT40876434/OU=See www.rapidssl.com/resources/cps (c)14/OU=Domain Control Validated - RapidSSL(R)/CN=*.npmjs.com
issuer: /C=US/O=GeoTrust Inc./CN=RapidSSL SHA256 CA - G3
Next Certificate -> 下一个证书 - >
subject: /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
issuer: /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Next Certificate -> 下一个证书 - >
subject: /C=US/O=GeoTrust Inc./CN=RapidSSL SHA256 CA - G3
issuer: /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
However, when I go to step through the certificate chain using my Node's HTTPS request, when the socket is emitted and I do 但是,当我使用我的Node的HTTPS请求逐步浏览证书链时,在发出套接字时我会这样做
socket.getPeerCertificate(true)
the chain is in the correct order and I'm getting one different certificate on the Node request than I am on the openssl request. 链的顺序是正确的,我在Node请求上得到的证书与openssl请求上的证书不同。
Node's Response First Certificate: 节点的响应第一证书:
subject
{ OU:
[ 'GT40876434',
'See www.rapidssl.com/resources/cps (c)14',
'Domain Control Validated - RapidSSL(R)' ],
CN: '*.npmjs.com' }
issuer
{ C: 'US', O: 'GeoTrust Inc.', CN: 'RapidSSL SHA256 CA - G3' }
Next Certificate -> 下一个证书 - >
subject
{ C: 'US', O: 'GeoTrust Inc.', CN: 'RapidSSL SHA256 CA - G3' }
issuer
{ C: 'US', O: 'GeoTrust Inc.', CN: 'GeoTrust Global CA' }
Next Certificate -> 下一个证书 - >
subject
{ C: 'US', O: 'GeoTrust Inc.', CN: 'GeoTrust Global CA' }
issuer
{ C: 'US', O: 'GeoTrust Inc.', CN: 'GeoTrust Global CA' }
Why is this happening? 为什么会这样?
It looks like node is reordering the certificates for returning in getPeerCertificates so that they reflect the correct order in the trust chain (*). 看起来节点正在重新排序证书以便在getPeerCertificates中返回,以便它们反映信任链(*)中的正确顺序。 But in reality the certificates are in the wrong order, as can be seen by
openssl s_client
and also in the analysis of SSLLabs : 但实际上证书的顺序是错误的,正如
openssl s_client
和SSLLabs分析中所见 :
Chain issues Incorrect order
(*) the relevant code in node-4.5.0 (LTS) is in src/node_crypto.cc
function void SSLWrap<Base>::GetPeerCertificate
. (*)node-4.5.0(LTS)中的相关代码位于
src/node_crypto.cc
函数void SSLWrap<Base>::GetPeerCertificate
。 There it retrieves the leaf certificate and the original peer certificates from the openssl library using SSL_get_peer_certificate
(leaf certificate) and SSL_get_peer_cert_chain
(chain). 在那里,它使用
SSL_get_peer_certificate
(叶证书)和SSL_get_peer_cert_chain
(链)从openssl库中检索叶证书和原始对等证书。 It then does not return the certificates in the original chain order but scans through the chain and adds the certificates in the order how they are depend on each other by checking with X509_check_issued
. 然后它不返回原始链顺序中的证书,而是扫描链并通过检查
X509_check_issued
按照它们彼此依赖的顺序添加证书。
This way it returns the certificates in proper dependency order instead of the original order as send by the peer. 这样,它以适当的依赖顺序返回证书,而不是由对等方发送的原始顺序。 It also automatically skips any certificates which don't belong in the chain.
它还会自动跳过任何不属于链的证书。
It will also add the issuer of the certificate even if it is not contained it the chain (which it usually isn't). 它也会添加证书的颁发者,即使它不包含在链中(通常不包含)。 This way you not only get a different order of certificates as seen in your example but actually different certificates.
这样,您不仅可以获得不同的证书顺序,如示例中所示,而且实际上是不同的证书。 The server sends the following certificates in this order:
服务器按此顺序发送以下证书:
[A] /OU=GT40876434/OU=See www.rapidssl.com/resources/cps (c)14/OU=Domain Control Validated - RapidSSL(R)/CN=*.npmjs.com
[B] /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA, issued by Equifax
[C] /C=US/O=GeoTrust Inc./CN=RapidSSL SHA256 CA - G3
But getPeerCertificate
returns the following: 但
getPeerCertificate
返回以下内容:
[A] /OU=GT40876434/OU=See www.rapidssl.com/resources/cps (c)14/OU=Domain Control Validated - RapidSSL(R)/CN=*.npmjs.com
[C] /C=US/O=GeoTrust Inc./CN=RapidSSL SHA256 CA - G3
[R] CA/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA, self-signed
Thus certificate [B] will not be included but instead certificate [R] which is the root certificate contained in the trust store. 因此,证书[B]将不包括在内,而是作为信任存储中包含的根证书的证书[R]。 Both have the same subject and key, but are signed by different entities.
两者都有相同的主题和密钥,但由不同的实体签名。 [B] is signed by Equifax while [R] is self-signed.
[B]由Equifax签署,而[R]是自签名的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.