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

Function secure

cf/src/connection.js:268–296  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

connectFunction · 0.70

Calls 2

writeFunction · 0.70
connectedFunction · 0.70

Tested by

no test coverage detected