简体   繁体   English

使用Node的HTTPS / TLS与OpenSSL s_client时的不同证书链顺序

[英]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_clientSSLLabs分析中所见

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.

相关问题 Node.js 说当 minVersion 设置为 1.3 并使用 1.3 与客户端连接时,它使用 tls1.2 - Node.js says it's using tls1.2 when minVersion set to 1.3 and connecting with a client using 1.3 使用 Let&#39;s Encrypt 证书通过 HTTPS 访问 CouchDB 时,节点无法验证第一个证书 - Node unable to verify the first certificate when accessing CouchDB through HTTPS with a Let's Encrypt certificate 如何使用基本身份验证和tls pfx证书的https客户端修复服务器连接? - How to fix server connection using https client with basic auth and tls pfx certificate? node.js和express-使用多个中间件与回调-最佳实践是什么? - node.js and express - using multiple middlewares vs. callbacks - what's the best practice? 在Node.js模块中使用“导出”与“此”有什么区别? - What's the difference between using “exports” vs. “this” in Node.js modules? 文件大小为0时从未调用Node.js https.request客户端的req.end() - Node.js https.request client's req.end() never called when the file size is 0 来自使用客户端证书的节点服务器的https请求报告已过期的证书 - https request from node server using client certificate reports expired certificate 如何在节点中使用客户端证书进行 HTTPS GET - How to do HTTPS GET with client certificate in node 使用RapidSSL证书时,Node.js HTTPS服务器未响应 - Node.js HTTPS server not responding when using RapidSSL certificate 我怎么知道从我的node.js接收到TLS请求的HTTPS端点正在使用指定的SSL证书? - How can I know that a HTTPS endpoint receiving a TLS request from my node.js is using a specified SSL certificate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM