TLSSocket | typescript
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Implements

Index

Constructors

constructor

  • Construct a new tls.TLSSocket object from an existing TCP socket.

    Parameters

    • socket: Socket
    • Optional options: object
      • Optional ALPNProtocols?: string[] | Buffer

        An array of strings or a Buffer naming possible ALPN protocols. (Protocols should be ordered by their priority.) When the server receives both NPN and ALPN extensions from the client, ALPN takes precedence over NPN and the server does not send an NPN extension to the client.

      • Optional NPNProtocols?: string[] | Buffer

        An array of strings or a Buffer naming possible NPN protocols. (Protocols should be ordered by their priority.)

      • Optional SNICallback?: Function

        SNICallback(servername, cb) A function that will be called if the client supports SNI TLS extension. Two arguments will be passed when called: servername and cb. SNICallback should invoke cb(null, ctx), where ctx is a SecureContext instance. (tls.createSecureContext(...) can be used to get a proper SecureContext.) If SNICallback wasn't provided the default callback with high-level API will be used (see below).

      • Optional isServer?: boolean

        If true the TLS socket will be instantiated in server-mode. Defaults to false.

      • Optional rejectUnauthorized?: boolean

        If true the server will reject any connection which is not authorized with the list of supplied CAs. This option only has an effect if requestCert is true. Defaults to false.

      • Optional requestCert?: boolean

        If true the server will request a certificate from clients that connect and attempt to verify that certificate. Defaults to false.

      • Optional 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

      • Optional secureContext?: SecureContext

        An optional TLS context object from tls.createSecureContext()

      • Optional server?: Server

        An optional net.Server instance.

      • Optional session?: Buffer

        An optional Buffer instance containing a TLS session.

    Returns TLSSocket

Properties

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.

encrypted

encrypted: boolean

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

localAddress

localAddress: string

The string representation of the local IP address.

localPort

localPort: number

The numeric representation of the local port.

readable

readable: boolean

remoteAddress

remoteAddress: string

The string representation of the remote IP address. For example, '74.125.127.100' or '2001:4860:a005::68'.

remoteFamily

remoteFamily: string

The string representation of the remote IP family. 'IPv4' or 'IPv6'.

remotePort

remotePort: number

The numeric representation of the remote port. For example, 443.

writable

writable: boolean

Static Socket

Socket: object

Type declaration

  • constructor: function
    • new __type(options?: object): Socket
    • Parameters

      • Optional options: object
        • Optional allowHalfOpen?: boolean
        • Optional fd?: number
        • Optional readable?: boolean
        • Optional writable?: boolean

      Returns Socket

Static bufferSize

bufferSize: number

Static bytesRead

bytesRead: number

Static bytesWritten

bytesWritten: number

Static connecting

connecting: boolean

Static defaultMaxListeners

defaultMaxListeners: number

Static destroyed

destroyed: boolean

Static localAddress

localAddress: string

Static localPort

localPort: number

Static remoteAddress

remoteAddress: string

Static remoteFamily

remoteFamily: string

Static remotePort

remotePort: number

Methods

_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

    Returns void

addListener

  • addListener(event: string, listener: Function): this
  • addListener(event: "OCSPResponse", listener: function): this
  • addListener(event: "secureConnect", listener: function): this
  • events.EventEmitter

    1. OCSPResponse
    2. secureConnect

    Parameters

    • event: string
    • listener: Function

    Returns this

  • Parameters

    • event: "OCSPResponse"
    • listener: function
        • Parameters

          Returns void

    Returns this

  • Parameters

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

    Returns this

address

  • address(): object
  • Returns the bound address, the address family name and port of the underlying socket as reported by the operating system.

    Returns object

    • An object with three properties, e.g. { port: 12346, family: 'IPv4', address: '127.0.0.1' }.
    • address: string
    • family: string
    • port: number

emit

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

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

    Returns boolean

  • Parameters

    • event: "OCSPResponse"
    • response: Buffer

    Returns boolean

  • Parameters

    • event: "secureConnect"

    Returns boolean

end

  • end(): void
  • Returns void

eventNames

  • eventNames(): (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

getPeerCertificate

  • getPeerCertificate(detailed?: boolean): object
  • 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

    • Optional detailed: boolean

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

    Returns object

    • An object representing the peer's certificate.

getSession

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

    Returns any

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

getTLSTicket

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

    Returns any

    • TLS session ticket or undefined if none was negotiated.

isPaused

  • isPaused(): boolean
  • Returns boolean

listenerCount

  • listenerCount(type: string | symbol): number

listeners

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

on

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

    • event: string
    • listener: Function

    Returns this

  • Parameters

    • event: "OCSPResponse"
    • listener: function
        • Parameters

          Returns void

    Returns this

  • Parameters

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

    Returns this

once

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

    • event: string
    • listener: Function

    Returns this

  • Parameters

    • event: "OCSPResponse"
    • listener: function
        • Parameters

          Returns void

    Returns this

  • Parameters

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

    Returns this

pause

  • pause(): this
  • Returns this

pipe

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

    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
  • Parameters

    • event: string
    • listener: Function

    Returns this

  • Parameters

    • event: "OCSPResponse"
    • listener: function
        • Parameters

          Returns void

    Returns this

  • Parameters

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

    Returns this

prependOnceListener

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

    • event: string
    • listener: Function

    Returns this

  • Parameters

    • event: "OCSPResponse"
    • listener: function
        • Parameters

          Returns void

    Returns this

  • Parameters

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

    Returns this

push

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

    • chunk: any
    • Optional encoding: string

    Returns boolean

read

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

    • Optional size: number

    Returns any

removeAllListeners

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

removeListener

  • removeListener(event: string, listener: Function): this
  • 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
  • Parameters

    • event: string
    • listener: Function

    Returns this

  • Parameters

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

    Returns this

  • Parameters

    • event: "data"
    • listener: function
        • (chunk: Buffer | string): void
        • Parameters

          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

renegotiate

  • renegotiate(options: TlsOptions, callback: function): any
  • 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: TlsOptions

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

    • callback: function

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

        • (err: Error): any
        • Parameters

          • err: Error

          Returns any

    Returns any

resume

  • resume(): this
  • Returns this

setDefaultEncoding

  • setDefaultEncoding(encoding: string): this
  • Parameters

    • encoding: string

    Returns this

setEncoding

  • setEncoding(encoding: string): void
  • Parameters

    • encoding: string

    Returns void

setMaxListeners

  • setMaxListeners(n: number): 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.

unpipe

  • unpipe<T>(destination?: T): void
  • Type parameters

    Parameters

    • Optional destination: T

    Returns void

unshift

  • unshift(chunk: any): void
  • Parameters

    • chunk: any

    Returns void

wrap

write

  • write(chunk: any, cb?: Function): boolean
  • Parameters

    • chunk: any
    • Optional cb: Function

    Returns boolean

Static addListener

  • addListener(event: string, listener: Function): this
  • events.EventEmitter

    1. close
    2. connect
    3. data
    4. drain
    5. end
    6. error
    7. lookup
    8. timeout

    Parameters

    • event: string
    • listener: Function

    Returns this

Static address

  • address(): object
  • Returns object

    • address: string
    • family: string
    • port: number

Static connect

  • connect(port: number, host?: string, connectionListener?: Function): void
  • connect(path: string, connectionListener?: Function): void
  • Parameters

    • port: number
    • Optional host: string
    • Optional connectionListener: Function

    Returns void

  • Parameters

    • path: string
    • Optional connectionListener: Function

    Returns void

Static destroy

  • destroy(): void
  • Returns void

Static emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

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

    Returns boolean

Static end

  • end(): void
  • end(buffer: Buffer, cb?: Function): void
  • end(str: string, cb?: Function): void
  • end(str: string, encoding?: string, cb?: Function): void
  • end(data?: any, encoding?: string): void
  • Returns void

  • Parameters

    • buffer: Buffer
    • Optional cb: Function

    Returns void

  • Parameters

    • str: string
    • Optional cb: Function

    Returns void

  • Parameters

    • str: string
    • Optional encoding: string
    • Optional cb: Function

    Returns void

  • Parameters

    • Optional data: any
    • Optional encoding: string

    Returns void

Static listenerCount

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

    Returns number

Static on

  • on(event: string, listener: Function): this
  • Parameters

    • event: string
    • listener: Function

    Returns this

Static once

  • once(event: string, listener: Function): this
  • Parameters

    • event: string
    • listener: Function

    Returns this

Static prependListener

  • prependListener(event: string, listener: Function): this
  • Parameters

    • event: string
    • listener: Function

    Returns this

Static prependOnceListener

  • prependOnceListener(event: string, listener: Function): this

Static ref

  • ref(): void
  • Returns void

Static setEncoding

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

    • Optional encoding: string

    Returns void

Static setKeepAlive

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

    • Optional enable: boolean
    • Optional initialDelay: number

    Returns void

Static setNoDelay

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

    • Optional noDelay: boolean

    Returns void

Static setTimeout

  • setTimeout(timeout: number, callback?: Function): void
  • Parameters

    • timeout: number
    • Optional callback: Function

    Returns void

Static unref

  • unref(): void
  • Returns void

Static write

  • write(buffer: Buffer): boolean
  • write(buffer: Buffer, cb?: Function): boolean
  • write(str: string, cb?: Function): boolean
  • write(str: string, encoding?: string, cb?: Function): boolean
  • write(str: string, encoding?: string, fd?: string): boolean
  • write(data: any, encoding?: string, callback?: Function): void
  • Parameters

    Returns boolean

  • Parameters

    • buffer: Buffer
    • Optional cb: Function

    Returns boolean

  • Parameters

    • str: string
    • Optional cb: Function

    Returns boolean

  • Parameters

    • str: string
    • Optional encoding: string
    • Optional cb: Function

    Returns boolean

  • Parameters

    • str: string
    • Optional encoding: string
    • Optional fd: string

    Returns boolean

  • Parameters

    • data: any
    • Optional encoding: string
    • Optional callback: Function

    Returns void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc