Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TLSSocket

Hierarchy

Implements

  • ReadableStream
  • Writable

Index

Constructors

constructor

Properties

Optional alpnProtocol

alpnProtocol: string

String containing the selected ALPN protocol. When ALPN has no selected protocol, tlsSocket.alpnProtocol equals false.

authorizationError

authorizationError: Error

The reason why the peer's certificate has not been verified. This property becomes available only when tlsSocket.authorized === false.

authorized

authorized: boolean

A boolean that is true if the peer certificate was signed by one of the specified CAs, otherwise false.

bufferSize

bufferSize: number

bytesRead

bytesRead: number

bytesWritten

bytesWritten: number

connecting

connecting: boolean

destroyed

destroyed: boolean

encrypted

encrypted: boolean

Static boolean value, always true. May be used to distinguish TLS sockets from regular ones.

localAddress

localAddress: string

localPort

localPort: number

readable

readable: boolean

readableHighWaterMark

readableHighWaterMark: number

readableLength

readableLength: number

Optional remoteAddress

remoteAddress: string

Optional remoteFamily

remoteFamily: string

Optional remotePort

remotePort: number

writable

writable: boolean

writableFinished

writableFinished: boolean

writableHighWaterMark

writableHighWaterMark: number

writableLength

writableLength: number

Static defaultMaxListeners

defaultMaxListeners: number

Methods

__@asyncIterator

  • __@asyncIterator(): AsyncIterableIterator<any>
  • Returns AsyncIterableIterator<any>

_destroy

  • _destroy(error: Error | null, callback: function): void
  • Parameters

    • error: Error | null
    • callback: function
        • (error: Error | null): void
        • Parameters

          • error: Error | null

          Returns void

    Returns void

_final

  • _final(callback: function): void
  • Parameters

    • callback: function
        • (error?: Error | null): void
        • Parameters

          • Optional error: Error | null

          Returns void

    Returns void

_read

  • _read(size: number): void
  • Parameters

    • size: number

    Returns void

_write

  • _write(chunk: any, encoding: string, callback: function): void
  • Parameters

    • chunk: any
    • encoding: string
    • callback: function
        • (error?: Error | null): void
        • Parameters

          • Optional error: Error | null

          Returns void

    Returns void

Optional _writev

  • _writev(chunks: Array<object>, callback: function): void
  • Parameters

    • chunks: Array<object>
    • callback: function
        • (error?: Error | null): void
        • Parameters

          • Optional error: Error | null

          Returns void

    Returns void

addListener

  • addListener(event: string, listener: function): this
  • addListener(event: "OCSPResponse", listener: function): this
  • addListener(event: "secureConnect", listener: function): this
  • addListener(event: "session", listener: function): this
  • addListener(event: "keylog", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "OCSPResponse"
    • listener: function
        • (response: Buffer): void
        • Parameters

          • response: Buffer

          Returns void

    Returns this

  • Parameters

    • event: "secureConnect"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "session"
    • listener: function
        • (session: Buffer): void
        • Parameters

          • session: Buffer

          Returns void

    Returns this

  • Parameters

    • event: "keylog"
    • listener: function
        • (line: Buffer): void
        • Parameters

          • line: Buffer

          Returns void

    Returns this

address

connect

  • connect(options: SocketConnectOpts, connectionListener?: function): this
  • connect(port: number, host: string, connectionListener?: function): this
  • connect(port: number, connectionListener?: function): this
  • connect(path: string, connectionListener?: function): this
  • Parameters

    • options: SocketConnectOpts
    • Optional connectionListener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • port: number
    • host: string
    • Optional connectionListener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • port: number
    • Optional connectionListener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • path: string
    • Optional connectionListener: function
        • (): void
        • Returns void

    Returns this

cork

  • cork(): void
  • Returns void

destroy

  • destroy(error?: Error): void
  • Parameters

    • Optional error: Error

    Returns void

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • emit(event: "OCSPResponse", response: Buffer): boolean
  • emit(event: "secureConnect"): boolean
  • emit(event: "session", session: Buffer): boolean
  • emit(event: "keylog", line: Buffer): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

  • Parameters

    • event: "OCSPResponse"
    • response: Buffer

    Returns boolean

  • Parameters

    • event: "secureConnect"

    Returns boolean

  • Parameters

    • event: "session"
    • session: Buffer

    Returns boolean

  • Parameters

    • event: "keylog"
    • line: Buffer

    Returns boolean

enableTrace

  • enableTrace(): void
  • When enabled, TLS packet trace information is written to stderr. This can be used to debug TLS connection problems.

    Note: The format of the output is identical to the output of openssl s_client -trace or openssl s_server -trace. While it is produced by OpenSSL's SSL_trace() function, the format is undocumented, can change without notice, and should not be relied on.

    Returns void

end

  • end(cb?: function): void
  • end(buffer: Uint8Array | string, cb?: function): void
  • end(str: Uint8Array | string, encoding?: string, cb?: function): void
  • Parameters

    • Optional cb: function
        • (): void
        • Returns void

    Returns void

  • Parameters

    • buffer: Uint8Array | string
    • Optional cb: function
        • (): void
        • Returns void

    Returns void

  • Parameters

    • str: Uint8Array | string
    • Optional encoding: string
    • Optional cb: function
        • (): void
        • Returns void

    Returns void

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getCipher

  • Returns an object representing the cipher name and the SSL/TLS protocol version of the current connection.

    Returns CipherNameAndProtocol

    Returns an object representing the cipher name and the SSL/TLS protocol version of the current connection.

getMaxListeners

  • getMaxListeners(): number
  • Returns number

getPeerCertificate

  • Returns an object representing the peer's certificate. The returned object has some properties corresponding to the field of the certificate. If detailed argument is true the full chain with issuer property will be returned, if false only the top certificate without issuer property. If the peer does not provide a certificate, it returns null or an empty object.

    Parameters

    • detailed: true

      If true; the full chain with issuer property will be returned.

    Returns DetailedPeerCertificate

    An object representing the peer's certificate.

  • Parameters

    • Optional detailed: false

    Returns PeerCertificate

  • Parameters

    • Optional detailed: boolean

    Returns PeerCertificate | DetailedPeerCertificate

getProtocol

  • getProtocol(): string | null
  • Returns a string containing the negotiated SSL/TLS protocol version of the current connection. The value 'unknown' will be returned for connected sockets that have not completed the handshaking process. The value null will be returned for server sockets or disconnected client sockets. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_get_version.html for more information.

    Returns string | null

    negotiated SSL/TLS protocol version of the current connection

getSession

  • getSession(): Buffer | undefined
  • Could be used to speed up handshake establishment when reconnecting to the server.

    Returns Buffer | undefined

    ASN.1 encoded TLS session or undefined if none was negotiated.

getTLSTicket

  • getTLSTicket(): Buffer | undefined
  • NOTE: Works only with client TLS sockets. Useful only for debugging, for session reuse provide session option to tls.connect().

    Returns Buffer | undefined

    TLS session ticket or undefined if none was negotiated.

isPaused

  • isPaused(): boolean
  • Returns boolean

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string, listener: function): this
  • on(event: "OCSPResponse", listener: function): this
  • on(event: "secureConnect", listener: function): this
  • on(event: "session", listener: function): this
  • on(event: "keylog", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "OCSPResponse"
    • listener: function
        • (response: Buffer): void
        • Parameters

          • response: Buffer

          Returns void

    Returns this

  • Parameters

    • event: "secureConnect"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "session"
    • listener: function
        • (session: Buffer): void
        • Parameters

          • session: Buffer

          Returns void

    Returns this

  • Parameters

    • event: "keylog"
    • listener: function
        • (line: Buffer): void
        • Parameters

          • line: Buffer

          Returns void

    Returns this

once

  • once(event: string, listener: function): this
  • once(event: "OCSPResponse", listener: function): this
  • once(event: "secureConnect", listener: function): this
  • once(event: "session", listener: function): this
  • once(event: "keylog", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "OCSPResponse"
    • listener: function
        • (response: Buffer): void
        • Parameters

          • response: Buffer

          Returns void

    Returns this

  • Parameters

    • event: "secureConnect"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "session"
    • listener: function
        • (session: Buffer): void
        • Parameters

          • session: Buffer

          Returns void

    Returns this

  • Parameters

    • event: "keylog"
    • listener: function
        • (line: Buffer): void
        • Parameters

          • line: Buffer

          Returns void

    Returns this

pause

  • pause(): this
  • Returns this

pipe

  • pipe<T>(destination: T, options?: object): T
  • Type parameters

    • T: WritableStream

    Parameters

    • destination: T
    • Optional options: object
      • Optional end?: boolean

    Returns T

prependListener

  • prependListener(event: string, listener: function): this
  • prependListener(event: "OCSPResponse", listener: function): this
  • prependListener(event: "secureConnect", listener: function): this
  • prependListener(event: "session", listener: function): this
  • prependListener(event: "keylog", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "OCSPResponse"
    • listener: function
        • (response: Buffer): void
        • Parameters

          • response: Buffer

          Returns void

    Returns this

  • Parameters

    • event: "secureConnect"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "session"
    • listener: function
        • (session: Buffer): void
        • Parameters

          • session: Buffer

          Returns void

    Returns this

  • Parameters

    • event: "keylog"
    • listener: function
        • (line: Buffer): void
        • Parameters

          • line: Buffer

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string, listener: function): this
  • prependOnceListener(event: "OCSPResponse", listener: function): this
  • prependOnceListener(event: "secureConnect", listener: function): this
  • prependOnceListener(event: "session", listener: function): this
  • prependOnceListener(event: "keylog", listener: function): this
  • Parameters

    • event: string
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

  • Parameters

    • event: "OCSPResponse"
    • listener: function
        • (response: Buffer): void
        • Parameters

          • response: Buffer

          Returns void

    Returns this

  • Parameters

    • event: "secureConnect"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "session"
    • listener: function
        • (session: Buffer): void
        • Parameters

          • session: Buffer

          Returns void

    Returns this

  • Parameters

    • event: "keylog"
    • listener: function
        • (line: Buffer): void
        • Parameters

          • line: Buffer

          Returns void

    Returns this

push

  • push(chunk: any, encoding?: string): boolean
  • Parameters

    • chunk: any
    • Optional encoding: string

    Returns boolean

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

read

  • read(size?: number): any
  • Parameters

    • Optional size: number

    Returns any

ref

  • ref(): void
  • Returns void

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: "close", listener: function): this
  • removeListener(event: "data", listener: function): this
  • removeListener(event: "end", listener: function): this
  • removeListener(event: "readable", listener: function): this
  • removeListener(event: "error", listener: function): this
  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: "close"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "data"
    • listener: function
        • (chunk: any): void
        • Parameters

          • chunk: any

          Returns void

    Returns this

  • Parameters

    • event: "end"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "readable"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Parameters

    • event: "error"
    • listener: function
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    Returns this

  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

renegotiate

  • renegotiate(options: object, callback: function): undefined | boolean
  • Initiate TLS renegotiation process.

    NOTE: Can be used to request peer's certificate after the secure connection has been established. ANOTHER NOTE: When running as the server, socket will be destroyed with an error after handshakeTimeout timeout.

    Parameters

    • options: object

      The options may contain the following fields: rejectUnauthorized, requestCert (See tls.createServer() for details).

      • Optional rejectUnauthorized?: boolean
      • Optional requestCert?: boolean
    • callback: function

      callback(err) will be executed with null as err, once the renegotiation is successfully completed.

        • (err: Error | null): void
        • Parameters

          • err: Error | null

          Returns void

    Returns undefined | boolean

    undefined when socket is destroy, false if negotiaion can't be initiated.

resume

  • resume(): this
  • Returns this

setDefaultEncoding

  • setDefaultEncoding(encoding: string): this
  • Parameters

    • encoding: string

    Returns this

setEncoding

  • setEncoding(encoding?: string): this
  • Parameters

    • Optional encoding: string

    Returns this

setKeepAlive

  • setKeepAlive(enable?: boolean, initialDelay?: number): this
  • Parameters

    • Optional enable: boolean
    • Optional initialDelay: number

    Returns this

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

setMaxSendFragment

  • setMaxSendFragment(size: number): boolean
  • Set maximum TLS fragment size (default and maximum value is: 16384, minimum is: 512). Smaller fragment size decreases buffering latency on the client: large fragments are buffered by the TLS layer until the entire fragment is received and its integrity is verified; large fragments can span multiple roundtrips, and their processing can be delayed due to packet loss or reordering. However, smaller fragments add extra TLS framing bytes and CPU overhead, which may decrease overall server throughput.

    Parameters

    • size: number

      TLS fragment size (default and maximum value is: 16384, minimum is: 512).

    Returns boolean

    Returns true on success, false otherwise.

setNoDelay

  • setNoDelay(noDelay?: boolean): this
  • Parameters

    • Optional noDelay: boolean

    Returns this

setTimeout

  • setTimeout(timeout: number, callback?: function): this
  • Parameters

    • timeout: number
    • Optional callback: function
        • (): void
        • Returns void

    Returns this

uncork

  • uncork(): void
  • Returns void

unpipe

  • unpipe(destination?: WritableStream): this
  • Parameters

    • Optional destination: WritableStream

    Returns this

unref

  • unref(): void
  • Returns void

unshift

  • unshift(chunk: any, encoding?: BufferEncoding): void
  • Parameters

    • chunk: any
    • Optional encoding: BufferEncoding

    Returns void

wrap

  • wrap(oldStream: ReadableStream): this
  • Parameters

    • oldStream: ReadableStream

    Returns this

write

  • write(buffer: Uint8Array | string, cb?: function): boolean
  • write(str: Uint8Array | string, encoding?: string, cb?: function): boolean
  • Parameters

    • buffer: Uint8Array | string
    • Optional cb: function
        • (err?: Error): void
        • Parameters

          • Optional err: Error

          Returns void

    Returns boolean

  • Parameters

    • str: Uint8Array | string
    • Optional encoding: string
    • Optional cb: function
        • (err?: Error): void
        • Parameters

          • Optional err: Error

          Returns void

    Returns boolean

Static from

  • from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable
  • A utility method for creating Readable Streams out of iterators.

    Parameters

    • iterable: Iterable<any> | AsyncIterable<any>
    • Optional options: ReadableOptions

    Returns Readable

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc