Skip to content

Commit 3bc2d55

Browse files
Merge pull request #1 from lenchvolodymyr/fix/connection-via-ssl
fix connection via ssl
2 parents 887d38f + e1d1b2f commit 3bc2d55

File tree

3 files changed

+31
-236
lines changed

3 files changed

+31
-236
lines changed

reverse_engineering/helpers/connectionHelper.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6985
const 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,

reverse_engineering/helpers/postgresService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports = {
6666
await this.disconnect();
6767
}
6868

69-
const { client, sshTunnel } = await createClient(connectionInfo);
69+
const { client, sshTunnel } = await createClient(connectionInfo, specificLogger);
7070

7171
db.initializeClient(client, specificLogger);
7272
currentSshTunnel = sshTunnel;

reverse_engineering/package-lock.json

Lines changed: 0 additions & 221 deletions
This file was deleted.

0 commit comments

Comments
 (0)