Skip to content

Commit 3dade76

Browse files
authored
Merge pull request #141 from Lplenka/Certificate_Issue
✨ Added support for self-signed certificate fixes #126
2 parents 616bc0f + 7b3c7ba commit 3dade76

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

app/main/index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ function serverError(targetURL) {
6767
}
6868
});
6969
req.on('error', e => {
70-
console.error(e);
70+
if (e.toString().indexOf('Error: self signed certificate') >= 0) {
71+
const url = targetURL.replace(/^https?:\/\//, '');
72+
console.log('Server StatusCode:', 200);
73+
console.log('You are connected to:', url);
74+
} else {
75+
console.error(e);
76+
}
7177
});
7278
req.end();
7379
} else if (data.domain) {
@@ -256,9 +262,27 @@ function createMainWindow() {
256262
// app.commandLine.appendSwitch('ignore-certificate-errors', 'true');
257263

258264
// For self-signed certificate
265+
ipc.on('certificate-err', (e, domain) => {
266+
const detail = `URL: ${domain} \n Error: Self-Signed Certificate`;
267+
dialog.showMessageBox(mainWindow, {
268+
title: 'Certificate error',
269+
message: `Do you trust certificate from ${domain}?`,
270+
// eslint-disable-next-line object-shorthand
271+
detail: detail,
272+
type: 'warning',
273+
buttons: ['Yes', 'No'],
274+
cancelId: 1
275+
// eslint-disable-next-line object-shorthand
276+
}, response => {
277+
if (response === 0) {
278+
// eslint-disable-next-line object-shorthand
279+
db.push('/domain', domain);
280+
mainWindow.loadURL(domain);
281+
}
282+
});
283+
});
259284
// eslint-disable-next-line max-params
260285
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
261-
console.log('warning: ', url, ' certificate-error');
262286
event.preventDefault();
263287
callback(true);
264288
});

app/renderer/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ <h1>Zulip Login</h1>
2020
Zulip Server URL
2121
</label>
2222
<input type="text" id="url" autofocus="autofocus" spellcheck="false" placeholder="Server URL">
23-
<button type="submit" id="main" class="btn-primary btn-large" value="Submit"
24-
onclick="addDomain();">Connect</button>
23+
<button type="submit" id="main" class="btn-primary btn-large" value="Submit">Connect</button>
2524
<p id="error"></p>
2625
</form>
2726
</div>

app/renderer/js/domain.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ window.addDomain = function () {
5959
$el.main.innerHTML = 'Connect';
6060
db.push('/domain', domain);
6161
ipcRenderer.send('new-domain', domain);
62+
} else if (error.toString().indexOf('Error: self signed certificate') >= 0) {
63+
$el.main.innerHTML = 'Connect';
64+
ipcRenderer.send('certificate-err', domain);
6265
} else {
6366
$el.main.innerHTML = 'Connect';
6467
displayError('Not a valid Zulip server');

app/renderer/js/pref.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ window.prefDomain = function () {
2020
const ipcRenderer = require('electron').ipcRenderer;
2121
const JsonDB = require('node-json-db');
2222
// eslint-disable-next-line import/no-extraneous-dependencies
23-
const {
24-
app
25-
} = require('electron').remote;
23+
const {app} = require('electron').remote;
2624

2725
const db = new JsonDB(app.getPath('userData') + '/domain.json', true, true);
2826

@@ -57,6 +55,10 @@ window.prefDomain = function () {
5755
document.getElementById('urladded').innerHTML = 'Switched to ' + newDomain;
5856
db.push('/domain', domain);
5957
ipcRenderer.send('new-domain', domain);
58+
} else if (error.toString().indexOf('Error: self signed certificate') >= 0) {
59+
document.getElementById('main').innerHTML = 'Switch';
60+
ipcRenderer.send('certificate-err', domain);
61+
document.getElementById('urladded').innerHTML = 'Switched to ' + newDomain;
6062
} else {
6163
document.getElementById('main').innerHTML = 'Switch';
6264
document.getElementById('urladded').innerHTML = 'Not a valid Zulip Server.';

0 commit comments

Comments
 (0)