Skip to content

Commit d9d655c

Browse files
committed
Allow ignoring certificate errors when using an untrusted self-signed certificate for https communication with the AspCore backend.
We can ignore all cert errors or only cert errors from specific domain names configured in electron.manifest.json
1 parent c2a8c62 commit d9d655c

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

ElectronNET.Host/main.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if (manifestJsonFile.singleInstance || manifestJsonFile.aspCoreBackendPort) {
5454
args.forEach(parameter => {
5555
const words = parameter.split('=');
5656

57-
if(words.length > 1) {
57+
if (words.length > 1) {
5858
app.commandLine.appendSwitch(words[0].replace('--', ''), words[1]);
5959
} else {
6060
app.commandLine.appendSwitch(words[0].replace('--', ''));
@@ -75,6 +75,29 @@ if (manifestJsonFile.singleInstance || manifestJsonFile.aspCoreBackendPort) {
7575
}
7676
}
7777

78+
// Bypass all SSL/TLS certificate errors. -- Less secure.
79+
if (manifestJsonFile.ignoreAllCertificateErrors) {
80+
console.log('All SSL/TLS Certificate errors will be ignored.');
81+
app.commandLine.appendSwitch('ignore-certificate-errors');
82+
}
83+
84+
// Bypass SSL/TLS certificate errors only for the domain names specified in the electron.manifest.json file.
85+
if (manifestJsonFile.hasOwnProperty('domainNamesToIgnoreCertificateErrors')) {
86+
if (manifestJsonFile.domainNamesToIgnoreCertificateErrors.length > 0) {
87+
manifestJsonFile.domainNamesToIgnoreCertificateErrors.forEach(function (site) {
88+
console.log('SSL/TLS certificate errors will be ignored for ' + site);
89+
});
90+
91+
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
92+
if (shouldIgnoreCertificateForUrl(url)) {
93+
console.log('SSL/TLS certificate error ignored for URL: ' + url);
94+
event.preventDefault()
95+
callback(true)
96+
}
97+
})
98+
}
99+
}
100+
78101
app.on('ready', () => {
79102

80103
// Fix ERR_UNKNOWN_URL_SCHEME using file protocol
@@ -333,3 +356,15 @@ function getEnvironmentParameter() {
333356

334357
return '';
335358
}
359+
360+
function shouldIgnoreCertificateForUrl(url) {
361+
if (manifestJsonFile.hasOwnProperty('domainNamesToIgnoreCertificateErrors')) {
362+
// Removing the scheme from the url so it will cover https and wss://
363+
const urlWithoutScheme = url.replace(/(^\w+:|^)\/\//, '');
364+
const sites = manifestJsonFile.domainNamesToIgnoreCertificateErrors.filter((oneSite) => urlWithoutScheme.startsWith(oneSite));
365+
366+
return sites.length > 0;
367+
}
368+
369+
return false;
370+
}

0 commit comments

Comments
 (0)