try add ca file to global root caas

This commit is contained in:
Mirko Golze
2023-10-09 21:09:52 +02:00
parent b9291201d9
commit 71e8ea457c
3 changed files with 42 additions and 18 deletions

View File

@@ -40,6 +40,7 @@
"node-machine-id": "^1.1.12",
"qs": "^6.11.0",
"socks-proxy-agent": "^8.0.2",
"ssl-root-cas": "^1.3.1",
"uuid": "^9.0.0",
"vm2": "^3.9.13",
"yup": "^0.32.11"

View File

@@ -1,3 +1,4 @@
const os = require('os');
const qs = require('qs');
const https = require('https');
const axios = require('axios');
@@ -201,22 +202,19 @@ const registerNetworkIpc = (mainWindow) => {
cancelTokenUid
});
const preferences = getPreferences();
const sslVerification = get(preferences, 'request.sslVerification', true);
const httpsAgentRequestFields = {};
if (!sslVerification) {
if (!preferences.isTlsVerification()) {
httpsAgentRequestFields['rejectUnauthorized'] = false;
} else {
const cacertArray = [preferences['cacert'], process.env.SSL_CERT_FILE, process.env.NODE_EXTRA_CA_CERTS];
cacertFile = cacertArray.find((el) => el);
if (cacertFile && cacertFile.length > 1) {
try {
const fs = require('fs');
caCrt = fs.readFileSync(cacertFile);
httpsAgentRequestFields['ca'] = caCrt;
} catch (err) {
console.log('Error reading CA cert file:' + cacertFile, err);
}
}
const cacertArray = [preferences.getCaCert(), process.env.SSL_CERT_FILE, process.env.NODE_EXTRA_CA_CERTS];
let cacertFile = cacertArray.find((el) => el);
if (cacertFile && cacertFile.length > 1) {
try {
const sslRootCas = require('ssl-root-cas').inject();
sslRootCas.addFile(cacertFile);
} catch (err) {
console.log('Error reading CA cert file:' + cacertFile, err);
}
}
@@ -249,16 +247,13 @@ const registerNetworkIpc = (mainWindow) => {
if (socksEnabled) {
const socksProxyAgent = new SocksProxyAgent(proxyUri);
request.httpsAgent = socksProxyAgent;
request.httpAgent = socksProxyAgent;
} else {
request.httpsAgent = new HttpsProxyAgent(
proxyUri,
Object.keys(httpsAgentRequestFields).length > 0 ? { ...httpsAgentRequestFields } : undefined
);
request.httpAgent = new HttpProxyAgent(proxyUri);
}
} else if (Object.keys(httpsAgentRequestFields).length > 0) {