File tree 2 files changed +56
-1
lines changed
2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
var dns = require ( 'dns' )
4
+ var fs = require ( 'fs' ) ;
4
5
5
6
var defaults = require ( './defaults' )
6
7
@@ -26,7 +27,35 @@ var readSSLConfigFromEnvironment = function () {
26
27
case 'require' :
27
28
case 'verify-ca' :
28
29
case 'verify-full' :
29
- return true
30
+ var caFileName = val ( 'sslrootcert' , { } )
31
+ if ( ! caFileName ) {
32
+ throw new Error ( 'Postgres SSL connection requested using PGSSLMODE environment variable, but no PGSSLROOTCERT environment variable defined' )
33
+ }
34
+
35
+ var crtFileName = val ( 'sslcert' , { } )
36
+ if ( ! crtFileName ) {
37
+ throw new Error ( 'Postgres SSL connection requested using PGSSLMODE environment variable, but no PGSSLCERT environment variable defined' )
38
+ }
39
+
40
+ var keyFileName = val ( 'sslkey' , { } )
41
+ if ( ! keyFileName ) {
42
+ throw new Error ( 'Postgres SSL connection requested using PGSSLMODE environment variable, but no PGSSLKEY environment variable defined' )
43
+ }
44
+
45
+ var result = {
46
+ rejectUnauthorized : false ,
47
+ ca : fs . readFileSync ( caFileName ) . toString ( ) ,
48
+ cert : fs . readFileSync ( crtFileName ) . toString ( )
49
+ }
50
+
51
+ // "hiding" the private key so it doesn't show up in stack traces
52
+ // or if the client is console.logged
53
+ Object . defineProperty ( result , 'key' , {
54
+ enumerable : false ,
55
+ value : fs . readFileSync ( keyFileName ) . toString ( )
56
+ } )
57
+
58
+ return result
30
59
case 'no-verify' :
31
60
return { rejectUnauthorized : false }
32
61
}
Original file line number Diff line number Diff line change
1
+ diff --git a/packages/pg/lib/connection-parameters.js b/packages/pg/lib/connection-parameters.js
2
+ index 6a535a8..30934c2 100644
3
+ --- a/packages/pg/lib/connection-parameters.js
4
+ +++ b/packages/pg/lib/connection-parameters.js
5
+ @@ -26,7 +26,20 @@ var readSSLConfigFromEnvironment = function () {
6
+ case 'require':
7
+ case 'verify-ca':
8
+ case 'verify-full':
9
+ - return true
10
+ + result = {
11
+ + rejectUnauthorized: false,
12
+ + ca: fs.readFileSync(val('sslrootcert', config)).toString(),
13
+ + cert: fs.readFileSync(val('sslcert', config)).toString()
14
+ + }
15
+ +
16
+ + // "hiding" the private key so it doesn't show up in stack traces
17
+ + // or if the client is console.logged
18
+ + Object.defineProperty(result, 'key', {
19
+ + enumerable: false,
20
+ + value: fs.readFileSync(val('sslkey', config)).toString()
21
+ + })
22
+ +
23
+ + return result
24
+ case 'no-verify':
25
+ return { rejectUnauthorized: false }
26
+ }
You can’t perform that action at this time.
0 commit comments