{
  "source": "tls.markdown",
  "modules": [
    {
      "textRaw": "TLS (SSL)",
      "name": "tls_(ssl)",
      "desc": "<pre><code>稳定度: 3 - 稳定</code></pre>\n<p>Use <code>require(&apos;tls&apos;)</code> to access this module.\n\n</p>\n<p>使用 <code>require(&apos;tls&apos;)</code> 来访问此模块。\n\n</p>\n<p>The <code>tls</code> module uses OpenSSL to provide Transport Layer Security and/or\nSecure Socket Layer: encrypted stream communication.\n\n</p>\n<p><code>tls</code> 模块使用 OpenSSL 来提供传输层安全协议（Transport Layer Security）和/或安全套接层（Secure Socket Layer）：加密过的流通讯。\n\n</p>\n<p>TLS/SSL is a public/private key infrastructure. Each client and each\nserver must have a private key. A private key is created like this\n\n</p>\n<p>TLS/SSL 是一种公钥/私钥架构。每个客户端和服务器都必有一个私钥。一个私钥使用类似的方式创建：\n\n</p>\n<pre><code>openssl genrsa -out ryans-key.pem 1024</code></pre>\n<p>All severs and some clients need to have a certificate. Certificates are public\nkeys signed by a Certificate Authority or self-signed. The first step to\ngetting a certificate is to create a &quot;Certificate Signing Request&quot; (CSR)\nfile. This is done with:\n\n</p>\n<p>所有服务器和某些客户端需要具备证书。证书是证书办法机构签发或自签发的公钥。获取证书的第一步是创建一个“证书签发申请”（CSR）文件。使用这条命令完成：\n\n</p>\n<pre><code>openssl req -new -key ryans-key.pem -out ryans-csr.pem</code></pre>\n<p>To create a self-signed certificate with the CSR, do this:\n\n</p>\n<p>像这样使用 CSR 创建一个自签名证书：\n\n</p>\n<pre><code>openssl x509 -req -in ryans-csr.pem -signkey ryans-key.pem -out ryans-cert.pem</code></pre>\n<p>Alternatively you can send the CSR to a Certificate Authority for signing.\n\n</p>\n<p>又或者你可以将 CSR 发送给一个数字证书认证机构请求签名。\n\n</p>\n<p>(TODO: docs on creating a CA, for now interested users should just look at\n<code>test/fixtures/keys/Makefile</code> in the Node source code)\n\n</p>\n<p>To create .pfx or .p12, do this:\n\n</p>\n<p>像这样创建 .pfx 或 .p12：\n\n</p>\n<pre><code>openssl pkcs12 -export -in agent5-cert.pem -inkey agent5-key.pem \\\n    -certfile ca-cert.pem -out agent5.pfx</code></pre>\n<ul>\n<li><code>in</code>:  certificate</li>\n<li><code>inkey</code>: private key</li>\n<li><p><code>certfile</code>: all CA certs concatenated in one file like\n<code>cat ca1-cert.pem ca2-cert.pem &gt; ca-cert.pem</code></p>\n</li>\n<li><p><code>in</code>:  certificate</p>\n</li>\n<li><code>inkey</code>: private key</li>\n<li><code>certfile</code>: all CA certs concatenated in one file like\n<code>cat ca1-cert.pem ca2-cert.pem &gt; ca-cert.pem</code></li>\n</ul>\n",
      "miscs": [
        {
          "textRaw": "Client-initiated renegotiation attack mitigation",
          "name": "Client-initiated renegotiation attack mitigation",
          "type": "misc",
          "desc": "<p>The TLS protocol lets the client renegotiate certain aspects of the TLS session.\nUnfortunately, session renegotiation requires a disproportional amount of\nserver-side resources, which makes it a potential vector for denial-of-service\nattacks.\n\n</p>\n<p>TLS协议会令客户端可以重新协商TLS会话的某些方面。但是，会话的重新协商是需要相应量的服务器端资源的，所以导致其变成一个阻断服务攻击（denial-of-service）的潜在媒介。\n\n</p>\n<p>To mitigate this, renegotiations are limited to three times every 10 minutes. An\nerror is emitted on the [tls.TLSSocket][] instance when the threshold is\nexceeded. The limits are configurable:\n\n</p>\n<p>为了减低这种情况的发生，重新协商被限制在每10分钟三次。如果超过这个数目，那么在[tls.TLSSocket][]实例上就会分发一个错误。这个限制是可设置的：\n\n</p>\n<ul>\n<li><p><code>tls.CLIENT_RENEG_LIMIT</code>: renegotiation limit, default is 3.</p>\n</li>\n<li><p><code>tls.CLIENT_RENEG_LIMIT</code>: 重新协商的次数限制，默认为3。</p>\n</li>\n<li><p><code>tls.CLIENT_RENEG_WINDOW</code>: renegotiation window in seconds, default is\n10 minutes.</p>\n</li>\n<li><p><code>tls.CLIENT_RENEG_WINDOW</code>: 重新协商窗口的秒数，默认为600（10分钟）。</p>\n</li>\n</ul>\n<p>Don&apos;t change the defaults unless you know what you are doing.\n\n</p>\n<p>除非你完全理解整个机制和清楚自己要干什么，否则不要改变这个默认值。\n\n</p>\n<p>To test your server, connect to it with <code>openssl s_client -connect address:port</code>\nand tap <code>R&lt;CR&gt;</code> (that&apos;s the letter <code>R</code> followed by a carriage return) a few\ntimes.\n\n</p>\n<p>要测试你的服务器的话，用命令 <code>openssl s_client -connect 地址:端口</code>连接上服务器，然后敲击<code>R&lt;CR&gt;</code>（字母键<code>R</code>加回车键）几次。\n\n</p>\n"
        },
        {
          "textRaw": "NPN 和 SNI",
          "name": "NPN 和 SNI",
          "type": "misc",
          "desc": "<p>NPN (Next Protocol Negotiation) and SNI (Server Name Indication) are TLS\nhandshake extensions allowing you:\n\n</p>\n<ul>\n<li>NPN - to use one TLS server for multiple protocols (HTTP, SPDY)</li>\n<li>SNI - to use one TLS server for multiple hostnames with different SSL\ncertificates.</li>\n</ul>\n"
        }
      ],
      "methods": [
        {
          "textRaw": "tls.getCiphers()",
          "type": "method",
          "name": "getCiphers",
          "desc": "<p>Returns an array with the names of the supported SSL ciphers.\n\n</p>\n<p>返回一个数组，其中包含了所支持的SSL加密器的名字。\n\n</p>\n<p>Example:\n\n</p>\n<p>示例：\n\n</p>\n<pre><code>var ciphers = tls.getCiphers();\nconsole.log(ciphers); // [&apos;AES128-SHA&apos;, &apos;AES256-SHA&apos;, ...]</code></pre>\n",
          "signatures": [
            {
              "params": []
            }
          ]
        },
        {
          "textRaw": "tls.createServer(options, [secureConnectionListener])",
          "type": "method",
          "name": "createServer",
          "desc": "<p>Creates a new [tls.Server][].  The <code>connectionListener</code> argument is\nautomatically set as a listener for the [secureConnection][] event.  The\n<code>options</code> object has these possibilities:\n\n</p>\n<p>新建一个新的 [tls.Server][].  The <code>connectionListener</code> 参数会自动设置为 [secureConnection][] 事件的监听器. 这个 <code>options</code> 对象有这些可能性:\n\n</p>\n<ul>\n<li><p><code>pfx</code>: A string or <code>Buffer</code> containing the private key, certificate and\nCA certs of the server in PFX or PKCS12 format. (Mutually exclusive with\nthe <code>key</code>, <code>cert</code> and <code>ca</code> options.)</p>\n</li>\n<li><p><code>pfx</code>: 一个String 或<code>Buffer</code>包含了私钥, 证书和CA certs, 一般是 PFX 或者 PKCS12 格式. (Mutually exclusive with\nthe <code>key</code>, <code>cert</code> and <code>ca</code> options.)</p>\n</li>\n<li><p><code>key</code>: A string or <code>Buffer</code> containing the private key of the server in\nPEM format. (Required)</p>\n</li>\n<li><p><code>key</code>: 一个字符串或 <code>Buffer</code>对象，其中包含了PEF格式的服务器的私钥。 (必需)</p>\n</li>\n<li><p><code>passphrase</code>: A string of passphrase for the private key or pfx.</p>\n</li>\n<li><p><code>passphrase</code>: 私钥或pfx密码的字符串。</p>\n</li>\n<li><p><code>cert</code>: A string or <code>Buffer</code> containing the certificate key of the server in\nPEM format. (Required)</p>\n</li>\n<li><p><code>ca</code>: An array of strings or <code>Buffer</code>s of trusted certificates. If this is\nomitted several well known &quot;root&quot; CAs will be used, like VeriSign.\nThese are used to authorize connections.</p>\n</li>\n<li><p><code>crl</code> : Either a string or list of strings of PEM encoded CRLs (Certificate\nRevocation List)</p>\n</li>\n<li><p><code>ciphers</code>: A string describing the ciphers to use or exclude.</p>\n<p><strong>NOTE</strong>: Previous revisions of this section suggested <code>AES256-SHA</code> as an\nacceptable cipher. Unfortunately, <code>AES256-SHA</code> is a CBC cipher and therefore\nsusceptible to BEAST attacks. Do <em>not</em> use it.</p>\n</li>\n<li><p><code>handshakeTimeout</code>: Abort the connection if the SSL/TLS handshake does not\nfinish in this many milliseconds. The default is 120 seconds.</p>\n<p>A <code>&apos;clientError&apos;</code> is emitted on the <code>tls.Server</code> object whenever a handshake\ntimes out.</p>\n</li>\n<li><p><code>honorCipherOrder</code> : When choosing a cipher, use the server&apos;s preferences\ninstead of the client preferences.</p>\n<p>Although, this option is disabled by default, it is <em>recommended</em> that you\nuse this option in conjunction with the <code>ciphers</code> option to mitigate\nBEAST attacks.</p>\n</li>\n<li><p><code>requestCert</code>: If <code>true</code> the server will request a certificate from\nclients that connect and attempt to verify that certificate. Default:\n<code>false</code>.</p>\n</li>\n<li><p><code>rejectUnauthorized</code>: If <code>true</code> the server will reject any connection\nwhich is not authorized with the list of supplied CAs. This option only\nhas an effect if <code>requestCert</code> is <code>true</code>. Default: <code>false</code>.</p>\n</li>\n<li><p><code>NPNProtocols</code>: An array or <code>Buffer</code> of possible NPN protocols. (Protocols\nshould be ordered by their priority).</p>\n</li>\n<li><p><code>SNICallback(servername, cb)</code>: A function that will be called if client\nsupports SNI TLS extension. Two argument will be passed to it: <code>servername</code>,\nand <code>cb</code>. <code>SNICallback</code> should invoke <code>cb(null, ctx)</code>, where <code>ctx</code> is a\nSecureContext instance.\n(You can use <code>crypto.createCredentials(...).context</code> to get proper\nSecureContext). If <code>SNICallback</code> wasn&apos;t provided - default callback with\nhigh-level API will be used (see below).</p>\n</li>\n<li><p><code>sessionTimeout</code>: An integer specifying the seconds after which TLS\nsession identifiers and TLS session tickets created by the server are\ntimed out. See [SSL_CTX_set_timeout] for more details.</p>\n</li>\n<li><p><code>sessionIdContext</code>: A string containing a opaque identifier for session\nresumption. If <code>requestCert</code> is <code>true</code>, the default is MD5 hash value\ngenerated from command-line. Otherwise, the default is not provided.</p>\n</li>\n<li><p><code>secureProtocol</code>: The SSL method to use, e.g. <code>SSLv3_method</code> to force\nSSL version 3. The possible values depend on your installation of\nOpenSSL and are defined in the constant [SSL_METHODS][].</p>\n</li>\n</ul>\n<p>Here is a simple example echo server:\n\n</p>\n<p>这是一个简单的应答服务器例子：\n\n</p>\n<pre><code>var server = tls.createServer(options, function(socket) {\n  console.log(&apos;服务器已连接&apos;,\n              socket.authorized ? &apos;已授权&apos; : &apos;未授权&apos;);\n  socket.write(&quot;欢迎！\\n&quot;);\n  socket.setEncoding(&apos;utf8&apos;);\n  socket.pipe(socket);\n});\nserver.listen(8000, function() {\n  console.log(&apos;server bound&apos;);\n});</code></pre>\n<p>Or\n\n</p>\n<p>或者\n\n</p>\n<pre><code>};\n\nvar server = tls.createServer(options, function(socket) {\n  console.log(&apos;server connected&apos;,\n              socket.authorized ? &apos;authorized&apos; : &apos;unauthorized&apos;);\n  socket.write(&quot;welcome!\\n&quot;);\n  socket.setEncoding(&apos;utf8&apos;);\n  socket.pipe(socket);\n});\nserver.listen(8000, function() {\n  console.log(&apos;server bound&apos;);\n});</code></pre>\n<p>You can test this server by connecting to it with <code>openssl s_client</code>:\n\n</p>\n<pre><code>var server = tls.createServer(options, function(socket) {\n  console.log(&apos;服务器已连接&apos;,\n              socket.authorized ? &apos;已授权&apos; : &apos;未授权&apos;);\n  socket.write(&quot;欢迎！\\n&quot;);\n  socket.setEncoding(&apos;utf8&apos;);\n  socket.pipe(socket);\n});\nserver.listen(8000, function() {\n  console.log(&apos;服务器已绑定&apos;);\n});</code></pre>\n<p>您可以使用 <code>openssl s_client</code> 连接这个服务器来测试：\n\n</p>\n<pre><code>openssl s_client -connect 127.0.0.1:8000</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "options"
                },
                {
                  "name": "secureConnectionListener",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "tls.connect(options, [callback])",
          "type": "method",
          "name": "connect",
          "desc": "<p>Creates a new client connection to the given <code>port</code> and <code>host</code> (old API) or\n<code>options.port</code> and <code>options.host</code>. (If <code>host</code> is omitted, it defaults to\n<code>localhost</code>.) <code>options</code> should be an object which specifies:\n\n</p>\n<ul>\n<li><p><code>host</code>: Host the client should connect to</p>\n</li>\n<li><p><code>port</code>: Port the client should connect to</p>\n</li>\n<li><p><code>socket</code>: Establish secure connection on a given socket rather than\ncreating a new socket. If this option is specified, <code>host</code> and <code>port</code>\nare ignored.</p>\n</li>\n<li><p><code>pfx</code>: A string or <code>Buffer</code> containing the private key, certificate and\nCA certs of the server in PFX or PKCS12 format.</p>\n</li>\n<li><p><code>key</code>: A string or <code>Buffer</code> containing the private key of the client in\nPEM format.</p>\n</li>\n<li><p><code>passphrase</code>: A string of passphrase for the private key or pfx.</p>\n</li>\n<li><p><code>passphrase</code>: 私钥或pfx密码的字符串。</p>\n</li>\n<li><p><code>cert</code>: A string or <code>Buffer</code> containing the certificate key of the client in\nPEM format.</p>\n</li>\n<li><p><code>ca</code>: An array of strings or <code>Buffer</code>s of trusted certificates. If this is\nomitted several well known &quot;root&quot; CAs will be used, like VeriSign.\nThese are used to authorize connections.</p>\n</li>\n<li><p><code>rejectUnauthorized</code>: If <code>true</code>, the server certificate is verified against\nthe list of supplied CAs. An <code>&apos;error&apos;</code> event is emitted if verification\nfails. Default: <code>true</code>.</p>\n</li>\n<li><p><code>NPNProtocols</code>: An array of string or <code>Buffer</code> containing supported NPN\nprotocols. <code>Buffer</code> should have following format: <code>0x05hello0x05world</code>,\nwhere first byte is next protocol name&apos;s length. (Passing array should\nusually be much simpler: <code>[&apos;hello&apos;, &apos;world&apos;]</code>.)</p>\n</li>\n<li><p><code>servername</code>: Servername for SNI (Server Name Indication) TLS extension.</p>\n</li>\n<li><p><code>secureProtocol</code>: The SSL method to use, e.g. <code>SSLv3_method</code> to force\nSSL version 3. The possible values depend on your installation of\nOpenSSL and are defined in the constant [SSL_METHODS][].</p>\n</li>\n</ul>\n<p>The <code>callback</code> parameter will be added as a listener for the\n[&apos;secureConnect&apos;][] event.\n\n</p>\n<p><code>callback</code>参数会被作为监听器添加到[&apos;secureConnect&apos;][]事件。\n\n</p>\n<p><code>tls.connect()</code> returns a [tls.TLSSocket][] object.\n\n</p>\n<p><code>tls.connect()</code>返回一个[tls.TLSSocket][]对象。\n\n</p>\n<p>Here is an example of a client of echo server as described previously:\n\n</p>\n<p>下面是一个上述应答服务器的客户端的例子：\n\n</p>\n<pre><code>var socket = tls.connect(8000, options, function() {\n  console.log(&apos;client connected&apos;,\n              socket.authorized ? &apos;authorized&apos; : &apos;unauthorized&apos;);\n  process.stdin.pipe(socket);\n  process.stdin.resume();\n});\nsocket.setEncoding(&apos;utf8&apos;);\nsocket.on(&apos;data&apos;, function(data) {\n  console.log(data);\n});\nsocket.on(&apos;end&apos;, function() {\n  server.close();\n});</code></pre>\n<p>Or\n\n</p>\n<p>或者\n\n</p>\n<pre><code>var socket = tls.connect(8000, options, function() {\n  console.log(&apos;client connected&apos;,\n              socket.authorized ? &apos;authorized&apos; : &apos;unauthorized&apos;);\n  process.stdin.pipe(socket);\n  process.stdin.resume();\n});\nsocket.setEncoding(&apos;utf8&apos;);\nsocket.on(&apos;data&apos;, function(data) {\n  console.log(data);\n});\nsocket.on(&apos;end&apos;, function() {\n  server.close();\n});</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "port"
                },
                {
                  "name": "host",
                  "optional": true
                },
                {
                  "name": "options",
                  "optional": true
                },
                {
                  "name": "callback",
                  "optional": true
                }
              ]
            },
            {
              "params": [
                {
                  "name": "options"
                },
                {
                  "name": "callback",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "tls.connect(port, [host], [options], [callback])",
          "type": "method",
          "name": "connect",
          "desc": "<p>Creates a new client connection to the given <code>port</code> and <code>host</code> (old API) or\n<code>options.port</code> and <code>options.host</code>. (If <code>host</code> is omitted, it defaults to\n<code>localhost</code>.) <code>options</code> should be an object which specifies:\n\n</p>\n<ul>\n<li><p><code>host</code>: Host the client should connect to</p>\n</li>\n<li><p><code>port</code>: Port the client should connect to</p>\n</li>\n<li><p><code>socket</code>: Establish secure connection on a given socket rather than\ncreating a new socket. If this option is specified, <code>host</code> and <code>port</code>\nare ignored.</p>\n</li>\n<li><p><code>pfx</code>: A string or <code>Buffer</code> containing the private key, certificate and\nCA certs of the server in PFX or PKCS12 format.</p>\n</li>\n<li><p><code>key</code>: A string or <code>Buffer</code> containing the private key of the client in\nPEM format.</p>\n</li>\n<li><p><code>passphrase</code>: A string of passphrase for the private key or pfx.</p>\n</li>\n<li><p><code>passphrase</code>: 私钥或pfx密码的字符串。</p>\n</li>\n<li><p><code>cert</code>: A string or <code>Buffer</code> containing the certificate key of the client in\nPEM format.</p>\n</li>\n<li><p><code>ca</code>: An array of strings or <code>Buffer</code>s of trusted certificates. If this is\nomitted several well known &quot;root&quot; CAs will be used, like VeriSign.\nThese are used to authorize connections.</p>\n</li>\n<li><p><code>rejectUnauthorized</code>: If <code>true</code>, the server certificate is verified against\nthe list of supplied CAs. An <code>&apos;error&apos;</code> event is emitted if verification\nfails. Default: <code>true</code>.</p>\n</li>\n<li><p><code>NPNProtocols</code>: An array of string or <code>Buffer</code> containing supported NPN\nprotocols. <code>Buffer</code> should have following format: <code>0x05hello0x05world</code>,\nwhere first byte is next protocol name&apos;s length. (Passing array should\nusually be much simpler: <code>[&apos;hello&apos;, &apos;world&apos;]</code>.)</p>\n</li>\n<li><p><code>servername</code>: Servername for SNI (Server Name Indication) TLS extension.</p>\n</li>\n<li><p><code>secureProtocol</code>: The SSL method to use, e.g. <code>SSLv3_method</code> to force\nSSL version 3. The possible values depend on your installation of\nOpenSSL and are defined in the constant [SSL_METHODS][].</p>\n</li>\n</ul>\n<p>The <code>callback</code> parameter will be added as a listener for the\n[&apos;secureConnect&apos;][] event.\n\n</p>\n<p><code>callback</code>参数会被作为监听器添加到[&apos;secureConnect&apos;][]事件。\n\n</p>\n<p><code>tls.connect()</code> returns a [tls.TLSSocket][] object.\n\n</p>\n<p><code>tls.connect()</code>返回一个[tls.TLSSocket][]对象。\n\n</p>\n<p>Here is an example of a client of echo server as described previously:\n\n</p>\n<p>下面是一个上述应答服务器的客户端的例子：\n\n</p>\n<pre><code>var socket = tls.connect(8000, options, function() {\n  console.log(&apos;client connected&apos;,\n              socket.authorized ? &apos;authorized&apos; : &apos;unauthorized&apos;);\n  process.stdin.pipe(socket);\n  process.stdin.resume();\n});\nsocket.setEncoding(&apos;utf8&apos;);\nsocket.on(&apos;data&apos;, function(data) {\n  console.log(data);\n});\nsocket.on(&apos;end&apos;, function() {\n  server.close();\n});</code></pre>\n<p>Or\n\n</p>\n<p>或者\n\n</p>\n<pre><code>var socket = tls.connect(8000, options, function() {\n  console.log(&apos;client connected&apos;,\n              socket.authorized ? &apos;authorized&apos; : &apos;unauthorized&apos;);\n  process.stdin.pipe(socket);\n  process.stdin.resume();\n});\nsocket.setEncoding(&apos;utf8&apos;);\nsocket.on(&apos;data&apos;, function(data) {\n  console.log(data);\n});\nsocket.on(&apos;end&apos;, function() {\n  server.close();\n});</code></pre>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "port"
                },
                {
                  "name": "host",
                  "optional": true
                },
                {
                  "name": "options",
                  "optional": true
                },
                {
                  "name": "callback",
                  "optional": true
                }
              ]
            }
          ]
        },
        {
          "textRaw": "new tls.TLSSocket(socket, options)",
          "type": "method",
          "name": "TLSSocket",
          "desc": "<p>Construct a new TLSSocket object from existing TCP socket.\n\n</p>\n<p><code>socket</code> is an instance of [net.Socket][]\n\n</p>\n<p><code>socket</code>是一个[net.Socket][]示例。\n\n</p>\n<p><code>options</code> is an object that might contain following properties:\n\n</p>\n<p><code>options</code>是一个可能包含以下属性的对象：\n\n</p>\n<ul>\n<li><p><code>credentials</code>: An optional credentials object from\n <code>crypto.createCredentials( ... )</code></p>\n</li>\n<li><p><code>isServer</code>: If true - TLS socket will be instantiated in server-mode</p>\n</li>\n<li><p><code>server</code>: An optional [net.Server][] instance</p>\n</li>\n<li><p><code>server</code>: 一个可选的[net.Server][]实例</p>\n</li>\n<li><p><code>requestCert</code>: Optional, see [tls.createSecurePair][]</p>\n</li>\n<li><p><code>requestCert</code>: 可选的，见[tls.createSecurePair][]</p>\n</li>\n<li><p><code>rejectUnauthorized</code>: Optional, see [tls.createSecurePair][]</p>\n</li>\n<li><p><code>rejectUnauthorized</code>: 可选的，见[tls.createSecurePair][]</p>\n</li>\n<li><p><code>NPNProtocols</code>: Optional, see [tls.createServer][]</p>\n</li>\n<li><p><code>NPNProtocols</code>: 可选的，见[tls.createServer][]</p>\n</li>\n<li><p><code>SNICallback</code>: Optional, see [tls.createServer][]</p>\n</li>\n<li><p><code>SNICallback</code>: 可选的，见[tls.createServer][]</p>\n</li>\n</ul>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "socket"
                },
                {
                  "name": "options"
                }
              ]
            }
          ]
        },
        {
          "textRaw": "tls.createSecurePair([credentials], [isServer], [requestCert], [rejectUnauthorized])",
          "type": "method",
          "name": "createSecurePair",
          "desc": "<pre><code>稳定性: 0 - 已废弃。使用 tls.TLSSocket 替代。</code></pre>\n<p>Creates a new secure pair object with two streams, one of which reads/writes\nencrypted data, and one reads/writes cleartext data.\nGenerally the encrypted one is piped to/from an incoming encrypted data stream,\nand the cleartext one is used as a replacement for the initial encrypted stream.\n\n</p>\n<ul>\n<li><p><code>credentials</code>: A credentials object from crypto.createCredentials( ... )</p>\n</li>\n<li><p><code>isServer</code>: A boolean indicating whether this tls connection should be\nopened as a server or a client.</p>\n</li>\n<li><p><code>requestCert</code>: A boolean indicating whether a server should request a\ncertificate from a connecting client. Only applies to server connections.</p>\n</li>\n<li><p><code>rejectUnauthorized</code>: A boolean indicating whether a server should\nautomatically reject clients with invalid certificates. Only applies to\nservers with <code>requestCert</code> enabled.</p>\n</li>\n</ul>\n<p><code>tls.createSecurePair()</code> returns a SecurePair object with <code>cleartext</code> and\n<code>encrypted</code> stream properties.\n\n</p>\n<p>NOTE: <code>cleartext</code> has the same APIs as [tls.TLSSocket][]\n\n</p>\n",
          "signatures": [
            {
              "params": [
                {
                  "name": "credentials",
                  "optional": true
                },
                {
                  "name": "isServer",
                  "optional": true
                },
                {
                  "name": "requestCert",
                  "optional": true
                },
                {
                  "name": "rejectUnauthorized",
                  "optional": true
                }
              ]
            }
          ]
        }
      ],
      "properties": [
        {
          "textRaw": "类: tls.TLSSocket",
          "name": "TLSSocket",
          "desc": "<p>Wrapper for instance of [net.Socket][], replaces internal socket read/write\nroutines to perform transparent encryption/decryption of incoming/outgoing data.\n\n</p>\n"
        },
        {
          "textRaw": "类: tls.Server",
          "name": "Server",
          "desc": "<p>This class is a subclass of <code>net.Server</code> and has the same methods on it.\nInstead of accepting just raw TCP connections, this accepts encrypted\nconnections using TLS or SSL.\n\n</p>\n",
          "modules": [
            {
              "textRaw": "事件: 'secureConnection'",
              "name": "事件:_'secureconnection'",
              "desc": "<p><code>function (tlsSocket) {}</code>\n\n</p>\n<p><code>function (tlsSocket) {}</code>\n\n</p>\n<p>This event is emitted after a new connection has been successfully\nhandshaked. The argument is a instance of [tls.TLSSocket][]. It has all the\ncommon stream methods and events.\n\n</p>\n<p><code>socket.authorized</code> is a boolean value which indicates if the\nclient has verified by one of the supplied certificate authorities for the\nserver. If <code>socket.authorized</code> is false, then\n<code>socket.authorizationError</code> is set to describe how authorization\nfailed. Implied but worth mentioning: depending on the settings of the TLS\nserver, you unauthorized connections may be accepted.\n<code>socket.npnProtocol</code> is a string containing selected NPN protocol.\n<code>socket.servername</code> is a string containing servername requested with\nSNI.\n\n</p>\n",
              "type": "module",
              "displayName": "事件: 'secureConnection'"
            },
            {
              "textRaw": "事件: 'newSession'",
              "name": "事件:_'newsession'",
              "desc": "<p><code>function (sessionId, sessionData) { }</code>\n\n</p>\n<p><code>function (sessionId, sessionData) { }</code>\n\n</p>\n<p>Emitted on creation of TLS session. May be used to store sessions in external\nstorage.\n\n</p>\n<p>NOTE: adding this event listener will have an effect only on connections\nestablished after addition of event listener.\n\n</p>\n",
              "type": "module",
              "displayName": "事件: 'newSession'"
            },
            {
              "textRaw": "事件: 'resumeSession'",
              "name": "事件:_'resumesession'",
              "desc": "<p><code>function (sessionId, callback) { }</code>\n\n</p>\n<p><code>function (sessionId, callback) { }</code>\n\n</p>\n<p>Emitted when client wants to resume previous TLS session. Event listener may\nperform lookup in external storage using given <code>sessionId</code>, and invoke\n<code>callback(null, sessionData)</code> once finished. If session can&apos;t be resumed\n(i.e. doesn&apos;t exist in storage) one may call <code>callback(null, null)</code>. Calling\n<code>callback(err)</code> will terminate incoming connection and destroy socket.\n\n</p>\n<p>NOTE: adding this event listener will have an effect only on connections\nestablished after addition of event listener.\n\n</p>\n",
              "type": "module",
              "displayName": "事件: 'resumeSession'"
            }
          ],
          "events": [
            {
              "textRaw": "Event: 'clientError'",
              "type": "event",
              "name": "clientError",
              "desc": "<p><code>function (exception, tlsSocket) { }</code>\n\n</p>\n<p><code>function (exception, tlsSocket) { }</code>\n\n</p>\n<p>When a client connection emits an &apos;error&apos; event before secure connection is\nestablished - it will be forwarded here.\n\n</p>\n<p><code>tlsSocket</code> is the [tls.TLSSocket][] that the error originated from.\n\n</p>\n",
              "params": []
            }
          ],
          "methods": [
            {
              "textRaw": "server.listen(port, [host], [callback])",
              "type": "method",
              "name": "listen",
              "desc": "<p>Begin accepting connections on the specified <code>port</code> and <code>host</code>.  If the\n<code>host</code> is omitted, the server will accept connections directed to any\nIPv4 address (<code>INADDR_ANY</code>).\n\n</p>\n<p>This function is asynchronous. The last parameter <code>callback</code> will be called\nwhen the server has been bound.\n\n</p>\n<p>See <code>net.Server</code> for more information.\n\n</p>\n<p>更多信息见<code>net.Server</code>。\n\n</p>\n",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "port"
                    },
                    {
                      "name": "host",
                      "optional": true
                    },
                    {
                      "name": "callback",
                      "optional": true
                    }
                  ]
                }
              ]
            },
            {
              "textRaw": "server.close()",
              "type": "method",
              "name": "close",
              "desc": "<p>Stops the server from accepting new connections. This function is\nasynchronous, the server is finally closed when the server emits a <code>&apos;close&apos;</code>\nevent.\n\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "server.address()",
              "type": "method",
              "name": "address",
              "desc": "<p>Returns the bound address, the address family name and port of the\nserver as reported by the operating system.  See [net.Server.address()][] for\nmore information.\n\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "server.addContext(hostname, credentials)",
              "type": "method",
              "name": "addContext",
              "desc": "<p>Add secure context that will be used if client request&apos;s SNI hostname is\nmatching passed <code>hostname</code> (wildcards can be used). <code>credentials</code> can contain\n<code>key</code>, <code>cert</code> and <code>ca</code>.\n\n</p>\n",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "hostname"
                    },
                    {
                      "name": "credentials"
                    }
                  ]
                }
              ]
            }
          ],
          "properties": [
            {
              "textRaw": "server.maxConnections",
              "name": "maxConnections",
              "desc": "<p>Set this property to reject connections when the server&apos;s connection count\ngets high.\n\n</p>\n"
            },
            {
              "textRaw": "server.connections",
              "name": "connections",
              "desc": "<p>The number of concurrent connections on the server.\n\n</p>\n<p>服务器的并发连接数.\n\n</p>\n"
            }
          ]
        },
        {
          "textRaw": "类: tls.TLSSocket",
          "name": "TLSSocket",
          "desc": "<p>This is a wrapped version of [net.Socket][] that does transparent encryption\nof written data and all required TLS negotiation.\n\n</p>\n<p>This instance implements a duplex [Stream][] interfaces.  It has all the\ncommon stream methods and events.\n\n</p>\n",
          "modules": [
            {
              "textRaw": "事件: 'secureConnect'",
              "name": "事件:_'secureconnect'",
              "desc": "<p>This event is emitted after a new connection has been successfully handshaked.\nThe listener will be called no matter if the server&apos;s certificate was\nauthorized or not. It is up to the user to test <code>tlsSocket.authorized</code>\nto see if the server certificate was signed by one of the specified CAs.\nIf <code>tlsSocket.authorized === false</code> then the error can be found in\n<code>tlsSocket.authorizationError</code>. Also if NPN was used - you can check\n<code>tlsSocket.npnProtocol</code> for negotiated protocol.\n\n</p>\n",
              "type": "module",
              "displayName": "事件: 'secureConnect'"
            }
          ],
          "properties": [
            {
              "textRaw": "tlsSocket.authorized",
              "name": "authorized",
              "desc": "<p>A boolean that is <code>true</code> if the peer certificate was signed by one of the\nspecified CAs, otherwise <code>false</code>\n\n</p>\n"
            },
            {
              "textRaw": "tlsSocket.authorizationError",
              "name": "authorizationError",
              "desc": "<p>The reason why the peer&apos;s certificate has not been verified. This property\nbecomes available only when <code>tlsSocket.authorized === false</code>.\n\n</p>\n"
            },
            {
              "textRaw": "tlsSocket.remoteAddress",
              "name": "remoteAddress",
              "desc": "<p>The string representation of the remote IP address. For example,\n<code>&apos;74.125.127.100&apos;</code> or <code>&apos;2001:4860:a005::68&apos;</code>.\n\n</p>\n<p>远程IP地址的字符串表示。例如，<code>&apos;74.125.127.100&apos;</code>或 <code>&apos;2001:4860:a005::68&apos;</code>。\n\n</p>\n"
            },
            {
              "textRaw": "tlsSocket.remotePort",
              "name": "remotePort",
              "desc": "<p>The numeric representation of the remote port. For example, <code>443</code>.\n\n</p>\n<p>远程端口的数值表示。例如， <code>443</code>。\n\n</p>\n"
            },
            {
              "textRaw": "tlsSocket.localAddress",
              "name": "localAddress",
              "desc": "<p>The string representation of the local IP address.\n\n</p>\n<p>本地IP地址的字符串表达。\n\n</p>\n"
            },
            {
              "textRaw": "tlsSocket.localPort",
              "name": "localPort",
              "desc": "<p>The numeric representation of the local port.\n\n</p>\n<p>本地端口的数值表示。\n\n</p>\n"
            }
          ],
          "methods": [
            {
              "textRaw": "tlsSocket.getPeerCertificate()",
              "type": "method",
              "name": "getPeerCertificate",
              "desc": "<p>Returns an object representing the peer&apos;s certificate. The returned object has\nsome properties corresponding to the field of the certificate.\n\n</p>\n<p>Example:\n\n</p>\n<p>示例：\n\n</p>\n<pre><code>{ subject: \n   { C: &apos;UK&apos;,\n     ST: &apos;Acknack Ltd&apos;,\n     L: &apos;Rhys Jones&apos;,\n     O: &apos;node.js&apos;,\n     OU: &apos;Test TLS Certificate&apos;,\n     CN: &apos;localhost&apos; },\n  issuer: \n   { C: &apos;UK&apos;,\n     ST: &apos;Acknack Ltd&apos;,\n     L: &apos;Rhys Jones&apos;,\n     O: &apos;node.js&apos;,\n     OU: &apos;Test TLS Certificate&apos;,\n     CN: &apos;localhost&apos; },\n  valid_from: &apos;Nov 11 09:52:22 2009 GMT&apos;,\n  valid_to: &apos;Nov  6 09:52:22 2029 GMT&apos;,\n  fingerprint: &apos;2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF&apos; }</code></pre>\n<p>If the peer does not provide a certificate, it returns <code>null</code> or an empty\nobject.\n\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "tlsSocket.getCipher()",
              "type": "method",
              "name": "getCipher",
              "desc": "<p>Returns an object representing the cipher name and the SSL/TLS\nprotocol version of the current connection.\n\n</p>\n<p>Example:\n{ name: &apos;AES256-SHA&apos;, version: &apos;TLSv1/SSLv3&apos; }\n\n</p>\n<p>Example:\n{ name: &apos;AES256-SHA&apos;, version: &apos;TLSv1/SSLv3&apos; }\n\n</p>\n<p>See SSL_CIPHER_get_name() and SSL_CIPHER_get_version() in\n<a href=\"http://www.openssl.org/docs/ssl/ssl.html#DEALING_WITH_CIPHERS\">http://www.openssl.org/docs/ssl/ssl.html#DEALING_WITH_CIPHERS</a> for more\ninformation.\n\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "tlsSocket.renegotiate(options, callback)",
              "type": "method",
              "name": "renegotiate",
              "desc": "<p>Initiate TLS renegotiation process. The <code>options</code> may contain the following\nfields: <code>rejectUnauthorized</code>, <code>requestCert</code> (See [tls.createServer][]\nfor details). <code>callback(err)</code> will be executed with <code>null</code> as <code>err</code>,\nonce the renegotiation is successfully completed.\n\n</p>\n<p>NOTE: Can be used to request peer&apos;s certificate after the secure connection\nhas been established.\n\n</p>\n<p>ANOTHER NOTE: When running as the server, socket will be destroyed\nwith an error after <code>handshakeTimeout</code> timeout.\n\n</p>\n",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    },
                    {
                      "name": "callback"
                    }
                  ]
                }
              ]
            },
            {
              "textRaw": "tlsSocket.address()",
              "type": "method",
              "name": "address",
              "desc": "<p>Returns the bound address, the address family name and port of the\nunderlying socket as reported by the operating system. Returns an\nobject with three properties, e.g.\n<code>{ port: 12346, family: &apos;IPv4&apos;, address: &apos;127.0.0.1&apos; }</code>\n\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            }
          ]
        }
      ],
      "modules": [
        {
          "textRaw": "类: SecurePair",
          "name": "类:_securepair",
          "desc": "<p>Returned by tls.createSecurePair.\n\n</p>\n<p>由tls.createSecurePair返回。\n\n</p>\n",
          "modules": [
            {
              "textRaw": "事件: 'secure'",
              "name": "事件:_'secure'",
              "desc": "<p>The event is emitted from the SecurePair once the pair has successfully\nestablished a secure connection.\n\n</p>\n<p>Similarly to the checking for the server &apos;secureConnection&apos; event,\npair.cleartext.authorized should be checked to confirm whether the certificate\nused properly authorized.\n\n</p>\n",
              "type": "module",
              "displayName": "事件: 'secure'"
            }
          ],
          "type": "module",
          "displayName": "类: SecurePair"
        },
        {
          "textRaw": "类: CryptoStream",
          "name": "类:_cryptostream",
          "desc": "<pre><code>稳定性: 0 - 已废弃。使用 tls.TLSSocket 替代。</code></pre>\n<p>This is an encrypted stream.\n\n</p>\n<p>这是一个被加密的流。\n\n</p>\n",
          "properties": [
            {
              "textRaw": "cryptoStream.bytesWritten",
              "name": "bytesWritten",
              "desc": "<p>A proxy to the underlying socket&apos;s bytesWritten accessor, this will return\nthe total bytes written to the socket, <em>including the TLS overhead</em>.\n\n</p>\n"
            }
          ],
          "type": "module",
          "displayName": "类: CryptoStream"
        }
      ],
      "type": "module",
      "displayName": "TLS (SSL)"
    }
  ]
}