node:tls
Node-compatible TLS/SSL encrypted sockets, servers, and certificate utilities
(node:tls).
Available in vjs only (not available in vjs-lite). Enabled by default
unless --no-node-compat is passed.
import ... from "node:tls"
node-compat (enabled by default in vjs; absent in vjs-lite; disable with --no-node-compat)Example
Section titled “Example”import { DEFAULT_MIN_VERSION, getCiphers } from "node:tls";
console.log(DEFAULT_MIN_VERSION, getCiphers().length);checkServerIdentityvjs onlyv0.0.0-alpha.2cert is valid for hostname according to RFC 6125 / SAN rules.connectvjs onlyv0.0.0-alpha.2options.createSecureContextvjs onlyv0.0.0-alpha.2SecureContext from PEM certificates, keys, and TLS policy.createServervjs onlyv0.0.0-alpha.2Server.getCiphersvjs onlyv0.0.0-alpha.2PeerCertificatevjs onlyv0.0.0-alpha.2TLSSocket.getPeerCertificate().DetailedPeerCertificatevjs onlyv0.0.0-alpha.2detailed: true.CipherNameAndProtocolvjs onlyv0.0.0-alpha.2SecureContextvjs onlyv0.0.0-alpha.2createSecureContext().SecureContextOptionsvjs onlyv0.0.0-alpha.2createSecureContext().TLSSocketOptionsvjs onlyv0.0.0-alpha.2new TLSSocket(socket, options).TlsOptionsvjs onlyv0.0.0-alpha.2createServer() and new Server().ConnectionOptionsvjs onlyv0.0.0-alpha.2tls.connect().DEFAULT_CIPHERSvjs onlyv0.0.0-alpha.2DEFAULT_ECDH_CURVEvjs onlyv0.0.0-alpha.2DEFAULT_MAX_VERSIONvjs onlyv0.0.0-alpha.2DEFAULT_MIN_VERSIONvjs onlyv0.0.0-alpha.2rootCertificatesvjs onlyv0.0.0-alpha.2Functions
Section titled “Functions”checkServerIdentity
Section titled “checkServerIdentity”export function checkServerIdentity(hostname: string, cert: PeerCertificate): Error | undefined;
Verify that cert is valid for hostname according to RFC 6125 / SAN rules.
| Name | Type | Description |
|---|---|---|
hostname | string | Expected server hostname or IP address. |
cert | PeerCertificate | Peer certificate metadata to verify. |
connect
Section titled “connect”export function connect(
options: ConnectionOptions,
secureConnectListener?: () => void,
): TLSSocket;
export function connect(
port: number,
host?: string,
options?: ConnectionOptions,
secureConnectListener?: () => void,
): TLSSocket;
export function connect(
port: number,
options?: ConnectionOptions,
secureConnectListener?: () => void,
): TLSSocket;
Open an encrypted TLS client connection using options.
connect(options, secureConnectListener?)| Name | Type | Description |
|---|---|---|
options | ConnectionOptions | TLS connection options. |
secureConnectListener optional | () => void | Optional "secureConnect" listener. |
TLSSocket — Connected TLSSocket.connect(port, host?, options?, secureConnectListener?)Open an encrypted TLS client connection to port and optional host.
| Name | Type | Description |
|---|---|---|
port | number | Remote TCP port. |
host optional | string | Remote hostname or IP address. |
options optional | ConnectionOptions | Optional TLS connection options. |
secureConnectListener optional | () => void | Optional "secureConnect" listener. |
TLSSocket — Connected TLSSocket.connect(port, options?, secureConnectListener?)Open an encrypted TLS client connection to port on localhost with options.
| Name | Type | Description |
|---|---|---|
port | number | Remote TCP port. |
options optional | ConnectionOptions | Optional TLS connection options. |
secureConnectListener optional | () => void | Optional "secureConnect" listener. |
TLSSocket — Connected TLSSocket.createSecureContext
Section titled “createSecureContext”export function createSecureContext(options?: SecureContextOptions): SecureContext;
Create a reusable SecureContext from PEM certificates, keys, and TLS policy.
| Name | Type | Description |
|---|---|---|
options optional | SecureContextOptions | Secure context configuration. |
SecureContext — Initialized SecureContext.createServer
Section titled “createServer”export function createServer(secureConnectionListener?: (socket: TLSSocket) => void): Server;
export function createServer(
options: TlsOptions,
secureConnectionListener?: (socket: TLSSocket) => void,
): Server;
Create a new TLS Server.
createServer(secureConnectionListener?)| Name | Type | Description |
|---|---|---|
secureConnectionListener optional | (socket: TLSSocket) => void | Optional "secureConnection" listener. |
Server — New tls.Server instance.createServer(options, secureConnectionListener?)Create a new TLS Server with explicit options.
| Name | Type | Description |
|---|---|---|
options | TlsOptions | TLS server configuration. |
secureConnectionListener optional | (socket: TLSSocket) => void | Optional "secureConnection" listener. |
Server — New tls.Server instance.getCiphers
Section titled “getCiphers”export function getCiphers(): string[];
Return the list of supported TLS cipher suite names in lowercase.
string[] — Array of cipher suite names.Classes
Section titled “Classes”TLSSocket
Section titled “TLSSocket”export class TLSSocket {
readonly encrypted: boolean;
readonly authorized: boolean;
readonly authorizationError?: Error;
readonly alpnProtocol: string | false | null;
readonly servername?: string | false;
readonly localAddress?: string;
readonly localPort?: number;
readonly remoteAddress?: string;
readonly remotePort?: number;
readonly destroyed: boolean;
readonly readable: boolean;
readonly writable: boolean;
constructor(socket: unknown, options?: TLSSocketOptions);
getPeerCertificate(detailed: true): DetailedPeerCertificate;
getPeerCertificate(detailed?: false): PeerCertificate;
getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate;
getCipher(): CipherNameAndProtocol;
getProtocol(): string | null;
getSession(): Uint8Array | undefined;
renegotiate(
options: { rejectUnauthorized?: boolean; requestCert?: boolean },
callback: (err: Error | null) => void,
): boolean | undefined;
setMaxSendFragment(size: number): boolean;
setTimeout(timeout: number, callback?: () => void): this;
write(chunk: string | Uint8Array, callback?: (err?: Error | null) => void): boolean;
write(chunk: string, encoding: string, callback?: (err?: Error | null) => void): boolean;
end(callback?: () => void): this;
end(chunk: string | Uint8Array, callback?: () => void): this;
destroy(error?: Error): this;
pause(): this;
resume(): this;
setEncoding(encoding?: string): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
emit(eventName: string | symbol, ...args: any[]): boolean;
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
}
Encrypted duplex TLS socket wrapping a TCP or duplex stream.
constructor(socket: unknown, options?: TLSSocketOptions);
Wrap an existing stream or socket in TLS encryption.
| Name | Type | Description |
|---|---|---|
socket | unknown | Underlying TCP socket or duplex stream. |
options optional | TLSSocketOptions | Optional TLS socket configuration. |
| Property | Type | Description | Since |
|---|---|---|---|
encrypted readonly | boolean | Always true for a TLSSocket. | v0.0.0-alpha.2 |
authorized readonly | boolean | true if the peer certificate passed verification. | v0.0.0-alpha.2 |
authorizationError readonly optional | Error | Error describing why peer verification failed, if unauthorized. | v0.0.0-alpha.2 |
alpnProtocol readonly | string | false | null | Negotiated ALPN protocol string, false, or null. | v0.0.0-alpha.2 |
servername readonly optional | string | false | Requested SNI server name, if present. | v0.0.0-alpha.2 |
localAddress readonly optional | string | Bound local IP address. | v0.0.0-alpha.2 |
localPort readonly optional | number | Bound local port. | v0.0.0-alpha.2 |
remoteAddress readonly optional | string | Remote peer IP address. | v0.0.0-alpha.2 |
remotePort readonly optional | number | Remote peer port. | v0.0.0-alpha.2 |
destroyed readonly | boolean | Whether destroy() has been called. | v0.0.0-alpha.2 |
readable readonly | boolean | Whether the socket is readable. | v0.0.0-alpha.2 |
writable readonly | boolean | Whether the socket is writable. | v0.0.0-alpha.2 |
TLSSocket.getPeerCertificate
Section titled “TLSSocket.getPeerCertificate”getPeerCertificate(detailed: true): DetailedPeerCertificate;
getPeerCertificate(detailed?: false): PeerCertificate;
getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate;
Return the peer certificate object (or {} if none).
Return the peer certificate object.
| Name | Type | Description |
|---|---|---|
detailed optional | true | false | boolean | — |
TLSSocket.getCipher
Section titled “TLSSocket.getCipher”getCipher(): CipherNameAndProtocol;
Return negotiated cipher suite and TLS version details.
TLSSocket.getProtocol
Section titled “TLSSocket.getProtocol”getProtocol(): string | null;
Return the negotiated TLS protocol string (for example "TLSv1.3"), or null.
string | nullTLSSocket.getSession
Section titled “TLSSocket.getSession”getSession(): Uint8Array | undefined;
Return serialized TLS session data, if available.
Uint8Array | undefinedTLSSocket.renegotiate
Section titled “TLSSocket.renegotiate”renegotiate(
options: { rejectUnauthorized?: boolean; requestCert?: boolean },
callback: (err: Error | null) => void,
): boolean | undefined;
Initiate TLS renegotiation where supported.
| Name | Type | Description |
|---|---|---|
options | { rejectUnauthorized?: boolean; requestCert?: boolean } | — |
callback | (err: Error | null) => void | — |
boolean | undefinedTLSSocket.setMaxSendFragment
Section titled “TLSSocket.setMaxSendFragment”setMaxSendFragment(size: number): boolean;
Configure maximum plaintext fragment size per TLS record.
| Name | Type | Description |
|---|---|---|
size | number | — |
booleanTLSSocket.setTimeout
Section titled “TLSSocket.setTimeout”setTimeout(timeout: number, callback?: () => void): this;
Set socket inactivity timeout in milliseconds.
| Name | Type | Description |
|---|---|---|
timeout | number | — |
callback optional | () => void | — |
thisTLSSocket.write
Section titled “TLSSocket.write”write(chunk: string | Uint8Array, callback?: (err?: Error | null) => void): boolean;
write(chunk: string, encoding: string, callback?: (err?: Error | null) => void): boolean;
Write encrypted data to the socket.
write(chunk, callback?)| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | — |
callback optional | (err?: Error | null) => void | — |
booleanwrite(chunk, encoding, callback?)Write string data with encoding to the socket.
| Name | Type | Description |
|---|---|---|
chunk | string | — |
encoding | string | — |
callback optional | (err?: Error | null) => void | — |
booleanTLSSocket.end
Section titled “TLSSocket.end”end(callback?: () => void): this;
end(chunk: string | Uint8Array, callback?: () => void): this;
Half-close the TLS socket.
end(callback?)| Name | Type | Description |
|---|---|---|
callback optional | () => void | — |
thisend(chunk, callback?)Write a final chunk and half-close the TLS socket.
| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | — |
callback optional | () => void | — |
thisTLSSocket.destroy
Section titled “TLSSocket.destroy”destroy(error?: Error): this;
Destroy the TLS socket immediately.
| Name | Type | Description |
|---|---|---|
error optional | Error | — |
thisTLSSocket.pause
Section titled “TLSSocket.pause”pause(): this;
Pause "data" event emission.
thisTLSSocket.resume
Section titled “TLSSocket.resume”resume(): this;
Resume "data" event emission.
thisTLSSocket.setEncoding
Section titled “TLSSocket.setEncoding”setEncoding(encoding?: string): this;
Set encoding for decoded "data" chunks.
| Name | Type | Description |
|---|---|---|
encoding optional | string | — |
thisTLSSocket.on
Section titled “TLSSocket.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisTLSSocket.once
Section titled “TLSSocket.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisTLSSocket.off
Section titled “TLSSocket.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisTLSSocket.emit
Section titled “TLSSocket.emit”emit(eventName: string | symbol, ...args: any[]): boolean;
Synchronously emit an event.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
...args | any[] | — |
booleanTLSSocket.[Symbol.asyncIterator]
Section titled “TLSSocket.[Symbol.asyncIterator]”[Symbol.asyncIterator](): AsyncIterableIterator<any>;
Iterate asynchronously over decrypted chunks.
Server
Section titled “Server”export class Server {
readonly listening: boolean;
constructor(secureConnectionListener?: (socket: TLSSocket) => void);
constructor(
options: TlsOptions,
secureConnectionListener?: (socket: TLSSocket) => void,
);
listen(port?: number, hostname?: string, listeningListener?: () => void): this;
listen(port?: number, listeningListener?: () => void): this;
listen(options: { port?: number; host?: string; backlog?: number; path?: string }, listeningListener?: () => void): this;
close(callback?: (err?: Error) => void): this;
address(): { address: string; family: string; port: number } | string | null;
addContext(hostname: string, context: SecureContextOptions): void;
setSecureContext(options: SecureContextOptions): void;
getTicketKeys(): Uint8Array;
setTicketKeys(keys: Uint8Array): void;
ref(): this;
unref(): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
emit(eventName: string | symbol, ...args: any[]): boolean;
[Symbol.asyncDispose](): Promise<void>;
}
TLS-enabled TCP server accepting inbound TLSSocket connections.
constructor(secureConnectionListener?: (socket: TLSSocket) => void);
constructor(
options: TlsOptions,
secureConnectionListener?: (socket: TLSSocket) => void,
);
Construct a tls.Server with an optional "secureConnection" listener.
new Server(secureConnectionListener?)| Name | Type | Description |
|---|---|---|
secureConnectionListener optional | (socket: TLSSocket) => void | Callback invoked with each authenticated TLSSocket. |
new Server(options, secureConnectionListener?)Construct a tls.Server with explicit options and optional listener.
| Name | Type | Description |
|---|---|---|
options | TlsOptions | TLS server certificates and handshake options. |
secureConnectionListener optional | (socket: TLSSocket) => void | Callback invoked with each authenticated TLSSocket. |
| Property | Type | Description | Since |
|---|---|---|---|
listening readonly | boolean | true while the server is listening. | v0.0.0-alpha.2 |
Server.listen
Section titled “Server.listen”listen(port?: number, hostname?: string, listeningListener?: () => void): this;
listen(port?: number, listeningListener?: () => void): this;
listen(options: { port?: number; host?: string; backlog?: number; path?: string }, listeningListener?: () => void): this;
Start listening for TLS connections on port.
listen(port?, hostname?, listeningListener?)| Name | Type | Description |
|---|---|---|
port optional | number | — |
hostname optional | string | — |
listeningListener optional | () => void | — |
thislisten(port?, listeningListener?)Start listening on port with optional listener.
| Name | Type | Description |
|---|---|---|
port optional | number | — |
listeningListener optional | () => void | — |
thislisten(options, listeningListener?)Start listening using explicit options.
| Name | Type | Description |
|---|---|---|
options | { port?: number; host?: string; backlog?: number; path?: string } | — |
listeningListener optional | () => void | — |
thisServer.close
Section titled “Server.close”close(callback?: (err?: Error) => void): this;
Stop accepting new TLS connections.
| Name | Type | Description |
|---|---|---|
callback optional | (err?: Error) => void | — |
thisServer.address
Section titled “Server.address”address(): { address: string; family: string; port: number } | string | null;
Return bound local address metadata or null.
{ address: string; family: string; port: number } | string | nullServer.addContext
Section titled “Server.addContext”addContext(hostname: string, context: SecureContextOptions): void;
Register an SNI hostname-specific SecureContextOptions.
| Name | Type | Description |
|---|---|---|
hostname | string | — |
context | SecureContextOptions | — |
voidServer.setSecureContext
Section titled “Server.setSecureContext”setSecureContext(options: SecureContextOptions): void;
Replace the server’s default TLS credentials and options.
| Name | Type | Description |
|---|---|---|
options | SecureContextOptions | — |
voidServer.getTicketKeys
Section titled “Server.getTicketKeys”getTicketKeys(): Uint8Array;
Return the current 48-byte TLS session ticket keys.
Server.setTicketKeys
Section titled “Server.setTicketKeys”setTicketKeys(keys: Uint8Array): void;
Replace the 48-byte TLS session ticket keys.
| Name | Type | Description |
|---|---|---|
keys | Uint8Array | — |
voidServer.ref
Section titled “Server.ref”ref(): this;
Keep the event loop active while listening.
thisServer.unref
Section titled “Server.unref”unref(): this;
Allow the event loop to exit if the server is the only active handle.
thisServer.on
Section titled “Server.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisServer.once
Section titled “Server.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisServer.off
Section titled “Server.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove an event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisServer.emit
Section titled “Server.emit”emit(eventName: string | symbol, ...args: any[]): boolean;
Synchronously emit an event.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
...args | any[] | — |
booleanServer.[Symbol.asyncDispose]
Section titled “Server.[Symbol.asyncDispose]”[Symbol.asyncDispose](): Promise<void>;
Close the server asynchronously when disposed via await using.
Promise<void>Interfaces
Section titled “Interfaces”PeerCertificate
Section titled “PeerCertificate”export interface PeerCertificate {
subject: Record<string, string | string[]>;
issuer: Record<string, string | string[]>;
subjectaltname?: string;
infoAccess?: Record<string, string[]>;
valid_from: string;
valid_to: string;
fingerprint: string;
fingerprint256: string;
fingerprint512?: string;
serialNumber: string;
raw: Uint8Array;
}
Decoded X.509 certificate metadata returned by TLSSocket.getPeerCertificate().
| Property | Type | Description | Since |
|---|---|---|---|
subject | Record<string, string | string[]> | Certificate subject distinguished-name fields. | v0.0.0-alpha.2 |
issuer | Record<string, string | string[]> | Certificate issuer distinguished-name fields. | v0.0.0-alpha.2 |
subjectaltname optional | string | Comma-separated Subject Alternative Name entries. | v0.0.0-alpha.2 |
infoAccess optional | Record<string, string[]> | Authority Information Access URIs keyed by extension name. | v0.0.0-alpha.2 |
valid_from | string | Validity start date string. | v0.0.0-alpha.2 |
valid_to | string | Validity expiration date string. | v0.0.0-alpha.2 |
fingerprint | string | SHA-1 fingerprint string. | v0.0.0-alpha.2 |
fingerprint256 | string | SHA-256 fingerprint string. | v0.0.0-alpha.2 |
fingerprint512 optional | string | SHA-512 fingerprint string. | v0.0.0-alpha.2 |
serialNumber | string | Hexadecimal certificate serial number. | v0.0.0-alpha.2 |
raw | Uint8Array | Raw DER-encoded certificate bytes. | v0.0.0-alpha.2 |
DetailedPeerCertificate
Section titled “DetailedPeerCertificate”export interface DetailedPeerCertificate extends PeerCertificate {
issuerCertificate: DetailedPeerCertificate;
}
Peer certificate including the issuing certificate chain when detailed: true.
| Property | Type | Description | Since |
|---|---|---|---|
issuerCertificate | DetailedPeerCertificate | Issuing CA certificate in the verified chain. | v0.0.0-alpha.2 |
CipherNameAndProtocol
Section titled “CipherNameAndProtocol”export interface CipherNameAndProtocol {
name: string;
standardName: string;
version: string;
}
Negotiated TLS cipher suite and protocol details.
| Property | Type | Description | Since |
|---|---|---|---|
name | string | OpenSSL-style cipher suite name. | v0.0.0-alpha.2 |
standardName | string | IANA standard cipher suite name. | v0.0.0-alpha.2 |
version | string | Negotiated TLS protocol version string. | v0.0.0-alpha.2 |
SecureContext
Section titled “SecureContext”export interface SecureContext {
context: unknown;
}
Opaque secure context object created by createSecureContext().
| Property | Type | Description | Since |
|---|---|---|---|
context | unknown | Internal secure context handle. | v0.0.0-alpha.2 |
SecureContextOptions
Section titled “SecureContextOptions”export interface SecureContextOptions {
ca?: string | Uint8Array | Array<string | Uint8Array>;
cert?: string | Uint8Array | Array<string | Uint8Array>;
key?:
| string
| Uint8Array
| Array<string | Uint8Array | { pem: string | Uint8Array; passphrase?: string }>;
passphrase?: string;
pfx?:
| string
| Uint8Array
| Array<string | Uint8Array | { buf: string | Uint8Array; passphrase?: string }>;
ciphers?: string;
ecdhCurve?: string;
minVersion?: SecureVersion;
maxVersion?: SecureVersion;
secureProtocol?: string;
honorCipherOrder?: boolean;
ALPNProtocols?: string[] | Uint8Array[] | Uint8Array;
sessionTimeout?: number;
ticketKeys?: Uint8Array;
crl?: string | Uint8Array | Array<string | Uint8Array>;
dhparam?: string | Uint8Array;
sigalgs?: string;
}
Options accepted by createSecureContext().
| Property | Type | Description | Since |
|---|---|---|---|
ca optional | string | Uint8Array | Array<string | Uint8Array> | Trusted CA certificates (PEM string or bytes). | v0.0.0-alpha.2 |
cert optional | string | Uint8Array | Array<string | Uint8Array> | Certificate chain(s) in PEM format. | v0.0.0-alpha.2 |
key optional | | string
| Uint8Array
| Array<string | Uint8Array | { pem: string | Uint8Array; passphrase?: string }> | Private key(s) in PEM format. | v0.0.0-alpha.2 |
passphrase optional | string | Passphrase protecting encrypted private keys or PKCS#12 bundles. | v0.0.0-alpha.2 |
pfx optional | | string
| Uint8Array
| Array<string | Uint8Array | { buf: string | Uint8Array; passphrase?: string }> | PKCS#12 certificate/key bundle(s). | v0.0.0-alpha.2 |
ciphers optional | string | Cipher suite specification string. | v0.0.0-alpha.2 |
ecdhCurve optional | string | Named ECDH curve(s). | v0.0.0-alpha.2 |
minVersion optional | SecureVersion | Minimum allowed TLS version. | v0.0.0-alpha.2 |
maxVersion optional | SecureVersion | Maximum allowed TLS version. | v0.0.0-alpha.2 |
secureProtocol optional | string | Legacy SSL/TLS method identifier. | v0.0.0-alpha.2 |
honorCipherOrder optional | boolean | Prefer server cipher order when negotiating. | v0.0.0-alpha.2 |
ALPNProtocols optional | string[] | Uint8Array[] | Uint8Array | Advertised ALPN protocol names. | v0.0.0-alpha.2 |
sessionTimeout optional | number | TLS session timeout in seconds. | v0.0.0-alpha.2 |
ticketKeys optional | Uint8Array | 48-byte TLS session ticket encryption keys. | v0.0.0-alpha.2 |
crl optional | string | Uint8Array | Array<string | Uint8Array> | Certificate revocation list(s) in PEM format. | v0.0.0-alpha.2 |
dhparam optional | string | Uint8Array | Diffie-Hellman parameters in PEM format. | v0.0.0-alpha.2 |
sigalgs optional | string | Supported signature algorithms list. | v0.0.0-alpha.2 |
TLSSocketOptions
Section titled “TLSSocketOptions”export interface TLSSocketOptions extends SecureContextOptions {
isServer?: boolean;
server?: Server;
requestCert?: boolean;
rejectUnauthorized?: boolean;
SNICallback?: (
servername: string,
cb: (err: Error | null, ctx?: SecureContext) => void,
) => void;
session?: Uint8Array;
requestOCSP?: boolean;
secureContext?: SecureContext;
}
Options accepted by new TLSSocket(socket, options).
| Property | Type | Description | Since |
|---|---|---|---|
isServer optional | boolean | Configure socket in TLS server mode when true. | v0.0.0-alpha.2 |
server optional | Server | Owning TLS server instance, if applicable. | v0.0.0-alpha.2 |
requestCert optional | boolean | Request a client certificate during handshake. | v0.0.0-alpha.2 |
rejectUnauthorized optional | boolean | Reject peers whose certificate fails trust verification (default true). | v0.0.0-alpha.2 |
SNICallback optional | (
servername: string,
cb: (err: Error | null, ctx?: SecureContext) => void,
) => void | Callback selecting a SecureContext dynamically from SNI servername. | v0.0.0-alpha.2 |
session optional | Uint8Array | Resumable TLS session bytes. | v0.0.0-alpha.2 |
requestOCSP optional | boolean | Request OCSP stapling response from peer. | v0.0.0-alpha.2 |
secureContext optional | SecureContext | Pre-built SecureContext instance. | v0.0.0-alpha.2 |
TlsOptions
Section titled “TlsOptions”export interface TlsOptions extends SecureContextOptions {
handshakeTimeout?: number;
requestCert?: boolean;
rejectUnauthorized?: boolean;
SNICallback?: (
servername: string,
cb: (err: Error | null, ctx?: SecureContext) => void,
) => void;
noDelay?: boolean;
keepAlive?: boolean;
allowHalfOpen?: boolean;
pauseOnConnect?: boolean;
secureContext?: SecureContext;
}
Options accepted by createServer() and new Server().
| Property | Type | Description | Since |
|---|---|---|---|
handshakeTimeout optional | number | TLS handshake timeout in milliseconds. | v0.0.0-alpha.2 |
requestCert optional | boolean | Request client certificate authentication. | v0.0.0-alpha.2 |
rejectUnauthorized optional | boolean | Reject clients without valid certificates (default true when requestCert is set). | v0.0.0-alpha.2 |
SNICallback optional | (
servername: string,
cb: (err: Error | null, ctx?: SecureContext) => void,
) => void | Callback selecting a SecureContext dynamically from SNI servername. | v0.0.0-alpha.2 |
noDelay optional | boolean | Disable Nagle's algorithm (TCP_NODELAY). | v0.0.0-alpha.2 |
keepAlive optional | boolean | Enable TCP keep-alive probes. | v0.0.0-alpha.2 |
allowHalfOpen optional | boolean | Allow half-open TCP sockets. | v0.0.0-alpha.2 |
pauseOnConnect optional | boolean | Pause accepted sockets before emitting "secureConnection". | v0.0.0-alpha.2 |
secureContext optional | SecureContext | Pre-built SecureContext instance. | v0.0.0-alpha.2 |
ConnectionOptions
Section titled “ConnectionOptions”export interface ConnectionOptions extends SecureContextOptions {
host?: string;
port?: number;
path?: string;
servername?: string;
checkServerIdentity?: typeof checkServerIdentity;
rejectUnauthorized?: boolean;
timeout?: number;
socket?: unknown;
secureContext?: SecureContext;
session?: Uint8Array;
}
Options accepted by tls.connect().
| Property | Type | Description | Since |
|---|---|---|---|
host optional | string | Remote hostname or IP address (default "localhost"). | v0.0.0-alpha.2 |
port optional | number | Remote TCP port (0..=65535). | v0.0.0-alpha.2 |
path optional | string | Unix socket or named pipe path. | v0.0.0-alpha.2 |
servername optional | string | SNI server name for certificate verification. | v0.0.0-alpha.2 |
checkServerIdentity optional | typeof checkServerIdentity | Custom hostname/certificate verification callback. | v0.0.0-alpha.2 |
rejectUnauthorized optional | boolean | Reject servers with invalid certificates (default true). | v0.0.0-alpha.2 |
timeout optional | number | Socket inactivity timeout in milliseconds. | v0.0.0-alpha.2 |
socket optional | unknown | Existing duplex socket to wrap with TLS. | v0.0.0-alpha.2 |
secureContext optional | SecureContext | Pre-built SecureContext instance. | v0.0.0-alpha.2 |
session optional | Uint8Array | Resumable TLS session bytes. | v0.0.0-alpha.2 |
Type Aliases
Section titled “Type Aliases”SecureVersion
Section titled “SecureVersion”export type SecureVersion = "TLSv1.3" | "TLSv1.2" | "TLSv1.1" | "TLSv1";
Supported TLS protocol version identifiers.
Constants
Section titled “Constants”DEFAULT_CIPHERS
Section titled “DEFAULT_CIPHERS”export const DEFAULT_CIPHERS: string;
Default cipher suite specification string.
DEFAULT_ECDH_CURVE
Section titled “DEFAULT_ECDH_CURVE”export const DEFAULT_ECDH_CURVE: string;
Default ECDH curve name.
DEFAULT_MAX_VERSION
Section titled “DEFAULT_MAX_VERSION”export const DEFAULT_MAX_VERSION: SecureVersion;
Default maximum supported TLS version.
DEFAULT_MIN_VERSION
Section titled “DEFAULT_MIN_VERSION”export const DEFAULT_MIN_VERSION: SecureVersion;
Default minimum supported TLS version.
rootCertificates
Section titled “rootCertificates”export const rootCertificates: readonly string[];
Bundled PEM-encoded root CA certificates trusted by default.
Default Export
Section titled “Default Export”default export
Section titled “default export”const _default: {
/** Default cipher string. @since 0.0.0-alpha.2 */
readonly DEFAULT_CIPHERS: string;
/** Default ECDH curve. @since 0.0.0-alpha.2 */
readonly DEFAULT_ECDH_CURVE: string;
/** Default maximum TLS version. @since 0.0.0-alpha.2 */
readonly DEFAULT_MAX_VERSION: SecureVersion;
/** Default minimum TLS version. @since 0.0.0-alpha.2 */
readonly DEFAULT_MIN_VERSION: SecureVersion;
/** `Server` constructor. @since 0.0.0-alpha.2 */
Server: typeof Server;
/** `TLSSocket` constructor. @since 0.0.0-alpha.2 */
TLSSocket: typeof TLSSocket;
/** Verify certificate SAN/CN against hostname. @since 0.0.0-alpha.2 */
checkServerIdentity: typeof checkServerIdentity;
/** Open a TLS client connection. @since 0.0.0-alpha.2 */
connect: typeof connect;
/** Create a `SecureContext`. @since 0.0.0-alpha.2 */
createSecureContext: typeof createSecureContext;
/** Create a TLS server. @since 0.0.0-alpha.2 */
createServer: typeof createServer;
/** Return supported cipher suite names. @since 0.0.0-alpha.2 */
getCiphers: typeof getCiphers;
/** Bundled root CA certificates. @since 0.0.0-alpha.2 */
readonly rootCertificates: readonly string[];
};
export default _default;
Default export object providing the node:tls API.
