new tls.TLSSocket(socket[, options])


  • socket <net.Socket> | <stream.Duplex> 在服务器端,任何 Duplex 流。 在客户端,任何 net.Socket 实例(对于客户端的通用 Duplex 流支持,必须使用 tls.connect())。
  • options <Object>
    • enableTrace: 参见 tls.createServer()
    • isServer: SSL/TLS 协议是不对称的,TLSSockets 必须知道它们是作为服务器还是客户端运行。 如果 true TLS 套接字将被实例化为服务器。 默认值: false
    • server <net.Server> net.Server 实例。
    • requestCert: 是否通过请求证书来验证远程对等体。 客户端总是请求服务器证书。 服务器(isServer 为真)可以将 requestCert 设置为真以请求客户端证书。
    • rejectUnauthorized: 参见 tls.createServer()
    • ALPNProtocols: 参见 tls.createServer()
    • SNICallback: 参见 tls.createServer()
    • session <Buffer> 包含 TLS 会话的 Buffer 实例。
    • requestOCSP <boolean> 如果为 true, 则指定将 OCSP 状态请求扩展添加到客户端 hello 并在建立安全通信之前在套接字上触发 'OCSPResponse' 事件
    • secureContext: 使用 tls.createSecureContext() 创建的 TLS 上下文对象。 如果 secureContext 未提供,则将通过将整个 options 对象传给 tls.createSecureContext() 来创建。
    • ...: 如果缺少 secureContext 选项,则使用 tls.createSecureContext() 选项。 否则,它们将被忽略。

从现有的 TCP 套接字构造新的 tls.TLSSocket 对象。

  • socket <net.Socket> | <stream.Duplex> On the server side, any Duplex stream. On the client side, any instance of net.Socket (for generic Duplex stream support on the client side, tls.connect() must be used).
  • options <Object>
    • enableTrace: See tls.createServer()
    • isServer: The SSL/TLS protocol is asymmetrical, TLSSockets must know if they are to behave as a server or a client. If true the TLS socket will be instantiated as a server. Default: false.
    • server <net.Server> A net.Server instance.
    • requestCert: Whether to authenticate the remote peer by requesting a certificate. Clients always request a server certificate. Servers (isServer is true) may set requestCert to true to request a client certificate.
    • rejectUnauthorized: See tls.createServer()
    • ALPNProtocols: See tls.createServer()
    • SNICallback: See tls.createServer()
    • session <Buffer> A Buffer instance containing a TLS session.
    • requestOCSP <boolean> If true, specifies that the OCSP status request extension will be added to the client hello and an 'OCSPResponse' event will be emitted on the socket before establishing a secure communication
    • secureContext: TLS context object created with tls.createSecureContext(). If a secureContext is not provided, one will be created by passing the entire options object to tls.createSecureContext().
    • ...: tls.createSecureContext() options that are used if the secureContext option is missing. Otherwise, they are ignored.

Construct a new tls.TLSSocket object from an existing TCP socket.