export function getSocket()

in src/socket.ts [119:152]


export function getSocket({
  ephemeralCert,
  host,
  port,
  instanceInfo,
  privateKey,
  serverCaCert,
  instanceDnsName,
  serverName,
}: SocketOptions): tls.TLSSocket {
  const socketOpts = {
    host,
    port,
    secureContext: tls.createSecureContext({
      ca: serverCaCert.cert,
      cert: ephemeralCert.cert,
      key: privateKey,
      minVersion: 'TLSv1.3',
    }),
    // This checks the provided serverName against the server certificate. It
    // is called after the TLS CA chain of is validated.
    checkServerIdentity: validateCertificate(
      instanceInfo,
      instanceDnsName,
      serverName
    ),
  };
  const tlsSocket = tls.connect(socketOpts);
  tlsSocket.setKeepAlive(true, DEFAULT_KEEP_ALIVE_DELAY_MS);
  // overrides the stream.connect method since the stream is already
  // connected and some drivers might try to call it internally
  tlsSocket.connect = () => tlsSocket;
  return tlsSocket;
}