阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js tls.createSecureContext

      Node.js tls.createSecureContext([options])

      版本历史

      版本变更
      v10.0.0The ecdhCurve cannot be set to false anymore due to a change in OpenSSL.
      v9.3.0The options parameter can now include clientCertEngine.
      v7.3.0If the key option is an array, individual entries do not need a passphrase property anymore. Array entries can also just be strings or Buffers now.
      v5.2.0The ca option can now be a single string containing multiple CA certificates.
      v0.11.13新增于: v0.11.13
      • options < Object>

        • ca < string> | < string[]> | < Buffer> | < Buffer[]> Optionally override the trusted CA certificates. Default is to trust the well-known CAs curated by Mozilla. Mozilla’s CAs are completely replaced when CAs are explicitly specified using this option. The value can be a string or Buffer, or an Array of strings and/or Buffers. Any string or Buffer can contain multiple PEM CAs concatenated together. The peer’s certificate must be chainable to a CA trusted by the server for the connection to be authenticated. When using certificates that are not chainable to a well-known CA, the certificate’s CA must be explicitly specified as a trusted or the connection will fail to authenticate. If the peer uses a certificate that doesn’t match or chain to one of the default CAs, use the ca option to provide a CA certificate that the peer’s certificate can match or chain to. For self-signed certificates, the certificate is its own CA, and must be provided.
        • cert < string> | < string[]> | < Buffer> | < Buffer[]> Cert chains in PEM format. One cert chain should be provided per private key. Each cert chain should consist of the PEM formatted certificate for a provided private key, followed by the PEM formatted intermediate certificates (if any), in order, and not including the root CA (the root CA must be pre-known to the peer, see ca). When providing multiple cert chains, they do not have to be in the same order as their private keys in key. If the intermediate certificates are not provided, the peer will not be able to validate the certificate, and the handshake will fail.
        • ciphers < string> Cipher suite specification, replacing the default. For more information, see modifying the default cipher suite.
        • clientCertEngine < string> Name of an OpenSSL engine which can provide the client certificate.
        • crl < string> | < string[]> | < Buffer> | < Buffer[]> PEM formatted CRLs (Certificate Revocation Lists).
        • dhparam < string> | < Buffer> Diffie Hellman parameters, required for Perfect Forward Secrecy. Use openssl dhparam to create the parameters. The key length must be greater than or equal to 1024 bits, otherwise an error will be thrown. It is strongly recommended to use 2048 bits or larger for stronger security. If omitted or invalid, the parameters are silently discarded and DHE ciphers will not be available.
        • ecdhCurve < string> A string describing a named curve or a colon separated list of curve NIDs or names, for example P-521:P-384:P-256, to use for ECDH key agreement. Set to auto to select the curve automatically. Use crypto.getCurves() to obtain a list of available curve names. On recent releases, openssl ecparam -list_curves will also display the name and description of each available elliptic curve. Default: tls.DEFAULT_ECDH_CURVE.
        • honorCipherOrder < boolean> Attempt to use the server’s cipher suite preferences instead of the client’s. When true, causes SSL_OP_CIPHER_SERVER_PREFERENCE to be set in secureOptions, see OpenSSL Options for more information.
        • key < string> | < string[]> | < Buffer> | < Buffer[]> | <Object[]> Private keys in PEM format. PEM allows the option of private keys being encrypted. Encrypted keys will be decrypted with options.passphrase. Multiple keys using different algorithms can be provided either as an array of unencrypted key strings or buffers, or an array of objects in the form {pem: < string|buffer>[, passphrase: < string>]}. The object form can only occur in an array. object.passphrase is optional. Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.
        • passphrase < string> Shared passphrase used for a single private key and/or a PFX.
        • pfx < string> | < string[]> | < Buffer> | < Buffer[]> | <Object[]> PFX or PKCS12 encoded private key and certificate chain. pfx is an alternative to providing key and cert individually. PFX is usually encrypted, if it is, passphrase will be used to decrypt it. Multiple PFX can be provided either as an array of unencrypted PFX buffers, or an array of objects in the form {buf: < string|buffer>[, passphrase: < string>]}. The object form can only occur in an array. object.passphrase is optional. Encrypted PFX will be decrypted with object.passphrase if provided, or options.passphrase if it is not.
        • secureOptions < number> Optionally affect the OpenSSL protocol behavior, which is not usually necessary. This should be used carefully if at all! Value is a numeric bitmask of the SSL_OP_* options from OpenSSL Options.
        • secureProtocol < string> SSL method to use. The possible values are listed as SSL_METHODS, use the function names as strings. For example, ‘TLSv1_2_method’ to force TLS version 1.2. Default: ‘TLS_method’.
        • sessionIdContext < string> Opaque identifier used by servers to ensure session state is not shared between applications. Unused by clients.

      tls.createServer() sets the default value of the honorCipherOrder option to true, other APIs that create secure contexts leave it unset.

      tls.createServer() uses a 128 bit truncated SHA1 hash value generated from process.argv as the default value of the sessionIdContext option, other APIs that create secure contexts have no default value.

      The tls.createSecureContext() method creates a credentials object.

      A key is required for ciphers that make use of certificates. Either key or pfx can be used to provide it.

      If the ‘ca’ option is not given, then Node.js will use the default publicly trusted list of CAs as given in https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt.


      更多内容请参考:Node.js tls 安全传输层,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录