2017-02-28 16:45:04 -06:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const electron = require('electron');
|
|
|
|
|
2017-05-31 23:39:08 -05:00
|
|
|
const log = require('../log.js');
|
|
|
|
const logLevels = require('../enums/logLevels.js');
|
|
|
|
|
2017-02-28 16:45:04 -06:00
|
|
|
let ignoreAllCertErrors = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If certificate error occurs allow user to deny or allow particular certificate
|
|
|
|
* error. If user selects 'Ignore All', then all subsequent certificate errors
|
|
|
|
* will ignored during this session.
|
|
|
|
*
|
|
|
|
* Note: the dialog is synchronous so further processing is blocked until
|
|
|
|
* user provides a response.
|
|
|
|
*/
|
|
|
|
electron.app.on('certificate-error', function(event, webContents, url, error,
|
|
|
|
certificate, callback) {
|
|
|
|
|
|
|
|
if (ignoreAllCertErrors) {
|
|
|
|
event.preventDefault();
|
|
|
|
callback(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-31 23:39:08 -05:00
|
|
|
log.send(logLevels.WARNING, 'Certificate error: ' + error + ' for url: ' + url);
|
|
|
|
|
2017-03-03 18:07:48 -06:00
|
|
|
const browserWin = electron.BrowserWindow.fromWebContents(webContents);
|
|
|
|
const buttonId = electron.dialog.showMessageBox(browserWin, {
|
2017-02-28 16:45:04 -06:00
|
|
|
type: 'warning',
|
|
|
|
buttons: [ 'Allow', 'Deny', 'Ignore All' ],
|
|
|
|
defaultId: 1,
|
|
|
|
cancelId: 1,
|
|
|
|
noLink: true,
|
|
|
|
title: 'Certificate Error',
|
|
|
|
message: 'Certificate Error: ' + error + '\nURL: ' + url,
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (buttonId === 2) {
|
|
|
|
ignoreAllCertErrors = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(buttonId !== 1);
|
|
|
|
});
|