Skip to content

Commit

Permalink
Merge pull request zulip#141 from Lplenka/Certificate_Issue
Browse files Browse the repository at this point in the history
✨ Added support for self-signed certificate fixes zulip#126
  • Loading branch information
akashnimare authored Apr 27, 2017
2 parents 616bc0f + 7b3c7ba commit 3dade76
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
28 changes: 26 additions & 2 deletions app/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ function serverError(targetURL) {
}
});
req.on('error', e => {
console.error(e);
if (e.toString().indexOf('Error: self signed certificate') >= 0) {
const url = targetURL.replace(/^https?:\/\//, '');
console.log('Server StatusCode:', 200);
console.log('You are connected to:', url);
} else {
console.error(e);
}
});
req.end();
} else if (data.domain) {
Expand Down Expand Up @@ -256,9 +262,27 @@ function createMainWindow() {
// app.commandLine.appendSwitch('ignore-certificate-errors', 'true');

// For self-signed certificate
ipc.on('certificate-err', (e, domain) => {
const detail = `URL: ${domain} \n Error: Self-Signed Certificate`;
dialog.showMessageBox(mainWindow, {
title: 'Certificate error',
message: `Do you trust certificate from ${domain}?`,
// eslint-disable-next-line object-shorthand
detail: detail,
type: 'warning',
buttons: ['Yes', 'No'],
cancelId: 1
// eslint-disable-next-line object-shorthand
}, response => {
if (response === 0) {
// eslint-disable-next-line object-shorthand
db.push('/domain', domain);
mainWindow.loadURL(domain);
}
});
});
// eslint-disable-next-line max-params
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
console.log('warning: ', url, ' certificate-error');
event.preventDefault();
callback(true);
});
Expand Down
3 changes: 1 addition & 2 deletions app/renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ <h1>Zulip Login</h1>
Zulip Server URL
</label>
<input type="text" id="url" autofocus="autofocus" spellcheck="false" placeholder="Server URL">
<button type="submit" id="main" class="btn-primary btn-large" value="Submit"
onclick="addDomain();">Connect</button>
<button type="submit" id="main" class="btn-primary btn-large" value="Submit">Connect</button>
<p id="error"></p>
</form>
</div>
Expand Down
3 changes: 3 additions & 0 deletions app/renderer/js/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ window.addDomain = function () {
$el.main.innerHTML = 'Connect';
db.push('/domain', domain);
ipcRenderer.send('new-domain', domain);
} else if (error.toString().indexOf('Error: self signed certificate') >= 0) {
$el.main.innerHTML = 'Connect';
ipcRenderer.send('certificate-err', domain);
} else {
$el.main.innerHTML = 'Connect';
displayError('Not a valid Zulip server');
Expand Down
8 changes: 5 additions & 3 deletions app/renderer/js/pref.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ window.prefDomain = function () {
const ipcRenderer = require('electron').ipcRenderer;
const JsonDB = require('node-json-db');
// eslint-disable-next-line import/no-extraneous-dependencies
const {
app
} = require('electron').remote;
const {app} = require('electron').remote;

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

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

0 comments on commit 3dade76

Please sign in to comment.