事件:'OCSPRequest'


🌐 Event: 'OCSPRequest'

当客户端发送证书状态请求时,会触发 'OCSPRequest' 事件。调用监听器回调时会传入三个参数:

🌐 The 'OCSPRequest' event is emitted when the client sends a certificate status request. The listener callback is passed three arguments when called:

  • certificate <Buffer> 服务器证书
  • issuer <Buffer> 发行人的证书
  • callback <Function> 必须调用的回调函数,以提供 OCSP 请求的结果。

服务器当前的证书可以解析以获取 OCSP URL 和证书 ID;在获取 OCSP 响应后,会调用 callback(null, resp),其中 resp 是包含 OCSP 响应的 Buffer 实例。certificate 和 issuer 都是主证书和颁发者证书的 Buffer DER 表示形式。这些可以用来获取 OCSP 证书 ID 和 OCSP 端点 URL。

🌐 The server's current certificate can be parsed to obtain the OCSP URL and certificate ID; after obtaining an OCSP response, callback(null, resp) is then invoked, where resp is a Buffer instance containing the OCSP response. Both certificate and issuer are Buffer DER-representations of the primary and issuer's certificates. These can be used to obtain the OCSP certificate ID and OCSP endpoint URL.

或者,可以调用 callback(null, null),表示没有 OCSP 响应。

🌐 Alternatively, callback(null, null) may be called, indicating that there was no OCSP response.

调用 callback(err) 将导致执行 socket.destroy(err)。

🌐 Calling callback(err) will result in a socket.destroy(err) call.

OCSP 请求的典型流程如下:

🌐 The typical flow of an OCSP request is as follows:

  1. 客户端连接到服务器并发送一个 'OCSPRequest'(通过 ClientHello 中的状态信息扩展)。
  2. 服务器接收请求并触发 'OCSPRequest' 事件,如果已注册监听器则调用它。
  3. 服务器从 certificate 或 issuer 中提取 OCSP URL,并向 CA 执行 OCSP请求。
  4. 服务器从 CA 接收 'OCSPResponse' 并通过 callback 参数将其发送回客户端
  5. 客户端验证响应,然后要么销毁套接字,要么执行握手。

issuer 可以为 null,如果证书是自签名的或发行者不在根证书列表中。(在建立 TLS 连接时,可以通过 ca 选项提供发行者。)

🌐 The issuer can be null if the certificate is either self-signed or the issuer is not in the root certificates list. (An issuer may be provided via the ca option when establishing the TLS connection.)

监听此事件只会对在添加事件监听器之后建立的连接产生影响。

🌐 Listening for this event will have an effect only on connections established after the addition of the event listener.

可以使用像 asn1.js 这样的 npm 模块来解析证书。

🌐 An npm module like asn1.js may be used to parse the certificates.