tlsSocket.authorized


如果对等证书是由创建 tls.TLSSocket 实例时指定的某个 CA 签署的,则此属性为 true,否则为 false

🌐 This property is true if the peer certificate was signed by one of the CAs specified when creating the tls.TLSSocket instance, otherwise false.

只有在完整的 TLS 握手期间才会验证对等证书。当通过恢复以前的会话建立连接时(见 会话恢复),不会重新进行验证。如果客户端在最初的握手中出示了证书,authorizedauthorizationError 会携带与会话一起存储的结果,包括任何验证错误。在 TLS 1.3 中,完全没有发送证书的客户端也可以恢复会话,并将 authorized 报告为 true,而 tls.TLSSocket.getPeerCertificate() 返回一个空对象。因此,通过 rejectUnauthorized: false 手动授权客户端的服务器也应该检查 tls.TLSSocket.isSessionReused(),并确保有对等证书存在。

🌐 The peer certificate is only verified during a full TLS handshake. When a connection is established by resuming a previous session (see Session Resumption), verification is not repeated. If the client presented a certificate in the original handshake, authorized and authorizationError carry the result stored with the session, including any verification error. On TLS 1.3, a client that sent no certificate at all can resume a session and report authorized as true, while tls.TLSSocket.getPeerCertificate() returns an empty object. Servers that authorize clients manually with rejectUnauthorized: false should therefore also check tls.TLSSocket.isSessionReused() and that a peer certificate is present.