Global

Members

log :util.DebugLoggerFunction|util.DebugLogger

Source:
Type:
  • util.DebugLoggerFunction | util.DebugLogger

Methods

connect(options, secureListeneropt) → {tls.TLSSocket}

Create a client connection to a listening server.
Source:
Parameters:
Name Type Attributes Description
options SocketConnectOpts | number Port to connect to.
secureListener function <optional>
If specified, function is registered for the 'secure' event.
Returns:
Type:
tls.TLSSocket
Socket.

connect(options, connectListeneropt) → {stream.Duplex}

Initiate a connection to a given server port.
Source:
Parameters:
Name Type Attributes Description
options number | SocketConnectOpts The server port to connect to. Must already be listening.
connectListener SocketCallback <optional>
Event listener for the 'connect' event.
Throws:
Invalid type for port.
Type
TypeError
Returns:
Type:
stream.Duplex
The client side HalfSocket.

createServer(optsopt, connectionListeneropt) → {Server}

Creates an instance of Server.
Source:
Parameters:
Name Type Attributes Description
opts ServerOpts | SocketCallback <optional>
Options for the server.
connectionListener SocketCallback <optional>
Register this as the event listener for the 'listening' event, if provided.
Returns:
Type:
Server
The created Server.

extendedError(message, opts) → {Error}

Create an extended Error, by assigning all of the properties in opts.
Source:
Parameters:
Name Type Description
message string Error text.
opts object Extra properties for error (e.g. {code: 'EADDRINUSE'}).
Returns:
Type:
Error
The extended error.

getServer(options) → {Server}

Get the Server associated with a port.
Source:
Parameters:
Name Type Description
options SocketConnectOpts | number Port to look up.
Returns:
Type:
Server
The server that was found, or null if none found.

normalizeArgs(optionsopt, listeneropt) → {object}

Normalize arguments for functions that take one of these three things for the first arg: port (number), options (object), listener (function).
Source:
Parameters:
Name Type Attributes Description
options object | number | function <optional>
Options.
listener Object.<string, function()> <optional>
Callback.
Throws:
No callback allowed for this function.
Type
TypeError
Returns:
Type:
object
The normalized options.

select(obj, args) → {Array.<object>}

Select some properties from an object into multiple other objects.
Source:
Parameters:
Name Type Description
obj object The source object.
args Array.<Array.<string>> Arrays of strings to select into the result objects.
Returns:
Type:
Array.<object>
One object for each of args, plus an extra one for everything that was left over.

Type Definitions

CertOpts

Properties:
Name Type Attributes Default Description
notafter Date <optional>
'Now + 5m' Certificate not valid after this date.
notbefore Date <optional>
'Now - 1s' Certificate not valid before this date.
subject string <optional>
Subject Distinguished Name (DN).
names Array.<string> <optional>
['localhost'] DNS Subject Alternative Names for the cert. Ignored for the CA cert.
Source:
Type:
  • object

CountCallback(erropt, countopt) → {void}

Source:
Parameters:
Name Type Attributes Description
err Error <optional>
If not null, an error occurred.
count number <optional>
The number of connected clients.
Returns:
Type:
void

ListenOptions

Properties:
Name Type Description
port number The port to listen on.
secureConnectionListener function If it exists, installed as a listener for the 'secureConnection' event.
Source:
Type:
  • object

ListenOptions

Properties:
Name Type Description
port number The port to listen on.
listeningListener function If it exists, installed as a listener for the 'listening' event.
Source:
Type:
  • object

PlainCallback() → {void}

Source:
Returns:
Type:
void

PSKCallback(hintopt) → {tls.PSKCallbackNegotation|null}

Source:
Parameters:
Name Type Attributes Description
hint string <optional>
Optional message sent from the server to help client decide which identity to use during negotiation. Always null if TLS 1.3 is used.
Returns:
Type:
tls.PSKCallbackNegotation | null
Or null to stop the negotiation process. PSK must be compatible with the selected cipher's digest.

SecureConnectionCallback(sock) → {void}

Source:
Parameters:
Name Type Description
sock tls.TLSSocket The server side of the socket that was connected.
Returns:
Type:
void

SecureContextCallback(erroropt, contextopt) → {void}

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
An error ocurred.
context tls.SecureContext <optional>
The context to use, if desired.
Returns:
Type:
void

ServerOpts

Properties:
Name Type Attributes Default Description
authority CertificateAuthority <optional>
A CA instance to use. If you are creating lots of servers, create one CA to pass into each of them, so that certs don't need to be created from scratch for each.
secureConnectionListener SecureConnectionCallback <optional>
Installed as a listener for the 'secureConnection' event.
notafter Date <optional>
'Now + 5m' Certificate not valid after this date.
notbefore Date <optional>
'Now - 1s' Certificate not valid before this date.
subject string <optional>
Subject Distinguished Name (DN).
names Array.<string> <optional>
['localhost'] DNS Subject Alternative Names for the cert. Ignored for the CA cert.
allowHalfOpen boolean <optional>
false If set to false, then the socket will automatically end the writable side when the readable side ends.
requestCert boolean 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 boolean See tls.createServer().
ALPNProtocols Array.<string> | Array.<Buffer> | Array.<DataView> | Buffer | DataView <optional>
An array of strings, Buffers or DataViews, or a single Buffer or DataView containing the supported ALPN protocols. Buffers should have the format [len][name][len][name]... E.g. '\x08http/1.1\x08http/1.0', where the len byte is the length of the next protocol name. Passing an array is usually much simpler, e.g. ['http/1.1', 'http/1.0']. Protocols earlier in the list have higher preference than those later.
SNICallback SNICallback See tls.createServer().
session Buffer <optional>
A Buffer instance, containing 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.SecureContext <optional>
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().
ca Array.<string> | string | Array.<Buffer> | Buffer <optional>
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.
cert Array.<string> | string | Array.<Buffer> | Buffer <optional>
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.
sigalgs string <optional>
Colon-separated list of supported signature algorithms. The list can contain digest algorithms (SHA256, MD5 etc.), public key algorithms (RSA-PSS, ECDSA etc.), combination of both ('RSA+SHA384') or TLS v1.3 scheme names (rsa_pss_pss_sha512). See OpenSSL man pages for more info.
ciphers string <optional>
Cipher suite specification, replacing the default. Cipher names are separated by colons, and must be uppercased in order for OpenSSL to accept them.
clientCertEngine string <optional>
Name of an OpenSSL engine which can provide the client certificate.
crl string | Array.<string> | Buffer | Array.<Buffer> <optional>
PEM formatted CRLs (Certificate Revocation Lists).
dhparam string | Buffer <optional>
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 or else an error will be thrown. Although 1024 bits is permissible, 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 <optional>
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 <optional>
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 | Array.<string> | Buffer | Array.<Buffer> | Array.<object> <optional>
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. Passphrase is optional. Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.
privateKeyEngine string <optional>
Name of an OpenSSL engine to get private key from. Should be used together with privateKeyIdentifier.
privateKeyIdentifier string <optional>
Identifier of a private key managed by an OpenSSL engine. Should be used together with privateKeyEngine. Should not be set together with key, because both options define a private key in different ways.
maxVersion string <optional>
tls.DEFAULT_MAX_VERSION Optionally set the maximum TLS version to allow. One of 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. Cannot be specified along with the secureProtocol option; use one or the other.
minVersion string <optional>
tls.DEFAULT_MIN_VERSION Optionally set the minimum TLS version to allow. One of 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. Cannot be specified along with the secureProtocol option; use one or the other. Avoid setting to less than TLSv1.2, but it may be required for interoperability.
passphrase string <optional>
Shared passphrase used for a single private key and/or a PFX.
pfx string | Array.<string> | Buffer | Array.<Buffer> | Array.<object> <optional>
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.
secureOptions number <optional>
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 <optional>
Legacy mechanism to select the TLS protocol version to use, it does not support independent control of the minimum and maximum version, and does not support limiting the protocol to TLSv1.3. Use minVersion and maxVersion instead. The possible values are listed as SSL_METHODS, use the function names as strings. For example, use 'TLSv1_1_method' to force TLS version 1.1, or 'TLS_method' to allow any TLS protocol version up to TLSv1.3. It is not recommended to use TLS versions less than 1.2, but it may be required for interoperability. Default: none, see minVersion.
sessionIdContext string <optional>
Opaque identifier used by servers to ensure session state is not shared between applications. Unused by clients.
ticketKeys Buffer <optional>
48-bytes of cryptographically strong pseudorandom data. See Session Resumption for more information.
sessionTimeout number <optional>
300 The number of seconds after which a TLS session created by the server will no longer be resumable. See Session Resumption for more information.
Source:
Type:
  • object

ServerOpts

Properties:
Name Type Attributes Default Description
allowHalfOpen boolean <optional>
false If set to false, then the socket will automatically end the writable side when the readable side ends.
Source:
Type:
  • object

ServerProperties

Properties:
Name Type Description
cert string PEM-encoded server certificate.
key string PEM-encoded server private key.
ca string PEM-encoded CA certificate.
Source:
Type:
  • object

SNICallback(serverName, callback) → {void}

Source:
Parameters:
Name Type Description
serverName string The name passed by the client.
callback SecureContextCallback Choose a security context for this connection.
Returns:
Type:
void

SocketCallback(socket)

Source:
Parameters:
Name Type Description
socket stream.Duplex Server side of socket that was just connected.

SocketConnectOpts

All of the options that can be passed in to connect(), with text copied from the Node docs.
Properties:
Name Type Attributes Default Description
port number Listening server port to connect to.
allowHalfOpen boolean <optional>
false If set to false, then the socket will automatically end the writable side when the readable side ends.
rejectUnauthorized boolean <optional>
true If not false, the server certificate is verified against the list of supplied CAs. An 'error' event is emitted if verification fails; err.code contains the OpenSSL error code.
pskCallback PSKCallback <optional>
When negotiating TLS-PSK (pre-shared keys), this function is called with optional identity hint provided by the server or null in case of TLS 1.3 where hint was removed. It will be necessary to provide a custom tls.checkServerIdentity() for the connection as the default one will try to check host name/IP of the server against the certificate but that's not applicable for PSK because there won't be a certificate present. More information can be found in the RFC 4279.
ALPNProtocols Array.<string> | Array.<Buffer> | Array.<DataView> | Buffer | DataView <optional>
An array of strings, Buffers or DataViews, or a single Buffer or DataView containing the supported ALPN protocols. Buffers should have the format [len][name][len][name]... E.g. '\x08http/1.1\x08http/1.0', where the len byte is the length of the next protocol name. Passing an array is usually much simpler, e.g. ['http/1.1', 'http/1.0']. Protocols earlier in the list have higher preference than those later.
servername string <optional>
Server name for the SNI (Server Name Indication) TLS extension. It is the name of the host being connected to, and must be a host name, and not an IP address. It can be used by a multi-homed server to choose the correct certificate to present to the client, see the SNICallback option to tls.createServer().
checkServerIdentity tls.checkServerIdentity <optional>
A callback function to be used (instead of the builtin tls.checkServerIdentity() function) when checking the server's host name (or the provided servername when explicitly set) against the certificate. This should return an if verification fails. The method should return undefined if the servername and cert are verified.
session Buffer <optional>
A Buffer instance, containing TLS session.
minDHSize number <optional>
1024 Minimum size of the DH parameter in bits to accept a TLS connection. When a server offers a DH parameter with a size less than minDHSize, the TLS connection is destroyed and an error is thrown.
highWaterMark number <optional>
16 * 1024 Consistent with the readable stream highWaterMark parameter.
secureContext tls.SecureContext <optional>
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().
ca Array.<string> | string | Array.<Buffer> | Buffer <optional>
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.
cert Array.<string> | string | Array.<Buffer> | Buffer <optional>
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.
sigalgs string <optional>
Colon-separated list of supported signature algorithms. The list can contain digest algorithms (SHA256, MD5 etc.), public key algorithms (RSA-PSS, ECDSA etc.), combination of both ('RSA+SHA384') or TLS v1.3 scheme names (rsa_pss_pss_sha512). See OpenSSL man pages for more info.
ciphers string <optional>
Cipher suite specification, replacing the default. Cipher names are separated by colons, and must be uppercased in order for OpenSSL to accept them.
clientCertEngine string <optional>
Name of an OpenSSL engine which can provide the client certificate.
crl string | Array.<string> | Buffer | Array.<Buffer> <optional>
PEM formatted CRLs (Certificate Revocation Lists).
dhparam string | Buffer <optional>
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 or else an error will be thrown. Although 1024 bits is permissible, 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 <optional>
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 <optional>
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 | Array.<string> | Buffer | Array.<Buffer> | Array.<object> <optional>
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. Passphrase is optional. Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.
privateKeyEngine string <optional>
Name of an OpenSSL engine to get private key from. Should be used together with privateKeyIdentifier.
privateKeyIdentifier string <optional>
Identifier of a private key managed by an OpenSSL engine. Should be used together with privateKeyEngine. Should not be set together with key, because both options define a private key in different ways.
maxVersion string <optional>
tls.DEFAULT_MAX_VERSION Optionally set the maximum TLS version to allow. One of 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. Cannot be specified along with the secureProtocol option; use one or the other.
minVersion string <optional>
tls.DEFAULT_MIN_VERSION Optionally set the minimum TLS version to allow. One of 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. Cannot be specified along with the secureProtocol option; use one or the other. Avoid setting to less than TLSv1.2, but it may be required for interoperability.
passphrase string <optional>
Shared passphrase used for a single private key and/or a PFX.
pfx string | Array.<string> | Buffer | Array.<Buffer> | Array.<object> <optional>
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.
secureOptions number <optional>
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 <optional>
Legacy mechanism to select the TLS protocol version to use, it does not support independent control of the minimum and maximum version, and does not support limiting the protocol to TLSv1.3. Use minVersion and maxVersion instead. The possible values are listed as SSL_METHODS, use the function names as strings. For example, use 'TLSv1_1_method' to force TLS version 1.1, or 'TLS_method' to allow any TLS protocol version up to TLSv1.3. It is not recommended to use TLS versions less than 1.2, but it may be required for interoperability. Default: none, see minVersion.
sessionIdContext string <optional>
Opaque identifier used by servers to ensure session state is not shared between applications. Unused by clients.
ticketKeys Buffer <optional>
48-bytes of cryptographically strong pseudorandom data. See Session Resumption for more information.
sessionTimeout number <optional>
300 The number of seconds after which a TLS session created by the server will no longer be resumable. See Session Resumption for more information.
Source:
Type:
  • object

SocketConnectOpts

Properties:
Name Type Attributes Default Description
port number Listening server port to connect to.
allowHalfOpen boolean <optional>
false If set to false, then the socket will automatically end the writable side when the readable side ends.
Source:
Type:
  • object