MCPcopy Create free account
hub / github.com/porsager/postgres / secure

Function secure

cjs/src/connection.js:266–294  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

264 }
265
266 async function secure() {
267 if (sslnegotiation !== 'direct') {
268 write(SSLRequest)
269 const canSSL = await new Promise(r => socket.once('data', x => r(x[0] === 83))) // S
270
271 if (!canSSL && ssl === 'prefer')
272 return connected()
273 }
274
275 const options = {
276 socket,
277 servername: net.isIP(socket.host) ? undefined : socket.host
278 }
279
280 if (sslnegotiation === 'direct')
281 options.ALPNProtocols = ['postgresql']
282
283 if (ssl === 'require' || ssl === 'allow' || ssl === 'prefer')
284 options.rejectUnauthorized = false
285 else if (typeof ssl === 'object')
286 Object.assign(options, ssl)
287
288 socket.removeAllListeners()
289 socket = tls.connect(options)
290 socket.on('secureConnect', connected)
291 socket.on('error', error)
292 socket.on('close', closed)
293 socket.on('drain', drain)
294 }
295
296 /* c8 ignore next 3 */
297 function drain() {

Callers 1

connectFunction · 0.70

Calls 2

writeFunction · 0.70
connectedFunction · 0.70

Tested by

no test coverage detected