@@ -42,28 +42,44 @@ const connectViaSsh = info =>
4242 } ) ;
4343 } ) ;
4444
45- const getSslOptions = connectionInfo => {
45+ const getSslOptions = ( connectionInfo , logger ) => {
4646 const sslType = mapSslType ( connectionInfo . sslType ) ;
4747
4848 if ( sslType === 'disable' ) {
4949 return false ;
5050 }
5151
5252 if ( sslType === 'allow' ) {
53- true ;
53+ return true ;
5454 }
5555
56- if ( [ 'prefer' , 'require' , 'verify-ca' , 'verify-full' ] . includes ( sslType ) ) {
57- return {
58- ca : fs . existsSync ( connectionInfo . certAuthority )
59- ? fs . readFileSync ( connectionInfo . certAuthority ) . toString ( )
60- : '' ,
61- cert : fs . existsSync ( connectionInfo . clientCert ) ? fs . readFileSync ( connectionInfo . clientCert ) . toString ( ) : '' ,
62- key : fs . existsSync ( connectionInfo . clientPrivateKey )
63- ? fs . readFileSync ( connectionInfo . clientPrivateKey ) . toString ( )
64- : '' ,
65- } ;
56+ let sslOptions = {
57+ checkServerIdentity ( hostname , cert ) {
58+ logger . info ( 'Certificate' , {
59+ hostname,
60+ cert : {
61+ subject : cert . subject ,
62+ issuer : cert . issuer ,
63+ valid_from : cert . valid_from ,
64+ valid_to : cert . valid_to ,
65+ } ,
66+ } ) ;
67+ }
68+ } ;
69+
70+ if ( fs . existsSync ( connectionInfo . certAuthority ) ) {
71+ sslOptions . ca = fs . readFileSync ( connectionInfo . certAuthority ) . toString ( ) ;
72+ }
73+
74+ if ( fs . existsSync ( connectionInfo . clientCert ) ) {
75+ sslOptions . cert = fs . readFileSync ( connectionInfo . clientCert ) . toString ( ) ;
6676 }
77+
78+ if ( fs . existsSync ( connectionInfo . clientPrivateKey ) ) {
79+ sslOptions . key = fs . readFileSync ( connectionInfo . clientPrivateKey ) . toString ( ) ;
80+ }
81+
82+ return sslOptions ;
6783} ;
6884
6985const mapSslType = sslType => {
@@ -77,7 +93,7 @@ const mapSslType = sslType => {
7793 return oldToNewSslType [ sslType ] || sslType ;
7894} ;
7995
80- const createClient = async connectionInfo => {
96+ const createClient = async ( connectionInfo , logger ) => {
8197 let sshTunnel = null ;
8298
8399 if ( connectionInfo . ssh ) {
@@ -92,7 +108,7 @@ const createClient = async connectionInfo => {
92108 password : connectionInfo . userPassword ,
93109 port : connectionInfo . port ,
94110 keepAlive : true ,
95- ssl : getSslOptions ( connectionInfo ) ,
111+ ssl : getSslOptions ( connectionInfo , logger ) ,
96112 connectionTimeoutMillis : Number ( connectionInfo . queryRequestTimeout ) || 60000 ,
97113 query_timeout : Number ( connectionInfo . queryRequestTimeout ) || 60000 ,
98114 statement_timeout : Number ( connectionInfo . queryRequestTimeout ) || 60000 ,
0 commit comments