From 7459828936b79343b47efed0305a9b0ea6b02dac Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Tue, 26 Jul 2016 18:52:16 -0300 Subject: [PATCH] Allow Self Signed Services Fixes #88 --- app/model/Service.js | 4 ++++ app/ux/WebView.js | 3 +++ app/view/main/MainController.js | 10 ++++++++++ electron/main.js | 24 +++++++++++++++++++++--- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/model/Service.js b/app/model/Service.js index 7f652c9a..4ebb5427 100644 --- a/app/model/Service.js +++ b/app/model/Service.js @@ -37,6 +37,10 @@ Ext.define('Rambox.model.Service', { name: 'muted' ,type: 'boolean' ,defaultValue: false + },{ + name: 'trust' + ,type: 'boolean' + ,defaultValue: false },{ name: 'js_unread' ,type: 'string' diff --git a/app/ux/WebView.js b/app/ux/WebView.js index 9bcd292a..831aa037 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -31,6 +31,9 @@ Ext.define('Rambox.ux.WebView',{ } } + // Allow Custom sites with self certificates + if ( me.record.get('trust') ) require('electron').ipcRenderer.send('allowCertificate', me.src) + Ext.apply(me, { items: [{ xtype: 'component' diff --git a/app/view/main/MainController.js b/app/view/main/MainController.js index ec8abd0a..fce33b77 100644 --- a/app/view/main/MainController.js +++ b/app/view/main/MainController.js @@ -549,6 +549,14 @@ Ext.define('Rambox.view.main.MainController', { ,uncheckedValue: false ,inputValue: true } + ,{ + xtype: 'checkbox' + ,boxLabel: 'Trust invalid authority certificates' + ,name: 'trust' + ,checked: edit ? record.get('trust') : false + ,uncheckedValue: false + ,inputValue: true + } ] } ,{ @@ -602,6 +610,7 @@ Ext.define('Rambox.view.main.MainController', { ,align: formValues.align ,notifications: formValues.notifications ,muted: formValues.muted + ,trust: formValues.trust ,js_unread: formValues.js_unread }); @@ -630,6 +639,7 @@ Ext.define('Rambox.view.main.MainController', { ,align: formValues.align ,notifications: formValues.notifications ,muted: formValues.muted + ,trust: formValues.trust ,js_unread: formValues.js_unread !== '' ? 'function checkUnread(){updateBadge(' + formValues.js_unread + ')}function updateBadge(e){e>=1?document.title="("+e+") "+originalTitle:document.title=originalTitle}var originalTitle=document.title;setInterval(checkUnread,3000);' : '' }); service.save(); diff --git a/electron/main.js b/electron/main.js index f36036df..a9bf9a81 100644 --- a/electron/main.js +++ b/electron/main.js @@ -179,9 +179,6 @@ function updateBadge(title) { app.setBadgeCount(messageCount); } -// Allow Custom sites with self certificates -app.commandLine.appendSwitch('ignore-certificate-errors'); - const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => { // Someone tried to run a second instance, we should focus our window. if (mainWindow) { @@ -195,6 +192,27 @@ if (shouldQuit) { return; } +var allowedURLCertificates = []; +electron.ipcMain.on('allowCertificate', (event, url) => { + allowedURLCertificates.push(require('url').parse(url).host); +}); +app.on('certificate-error', function(event, webContents, url, error, certificate, callback) { + if ( allowedURLCertificates.indexOf(require('url').parse(url).host) >= 0 ) { + event.preventDefault(); + callback(true); + } else { + callback(false); + electron.dialog.showMessageBox(mainWindow, { + title: 'Certification Error' + ,message: 'The service with the following URL has an invalid authority certification.\n\n'+url+'\n\nYou have to remove the service and add it again, enabling the "Trust invalid authority certificates" in the Options.' + ,buttons: ['OK'] + ,type: 'error' + }, function() { + + }); + } +}); + // This method will be called when Electron has finished // initialization and is ready to create browser windows. app.on('ready', createWindow);