@@ -221,6 +221,10 @@ var MattermostView = React.createClass({
|
|||||||
|
|
||||||
webview.addEventListener('did-fail-load', function(e) {
|
webview.addEventListener('did-fail-load', function(e) {
|
||||||
console.log(thisObj.props.name, 'webview did-fail-load', e);
|
console.log(thisObj.props.name, 'webview did-fail-load', e);
|
||||||
|
if (e.errorCode === -3) { // An operation was aborted (due to user action).
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// should use permanent way to indicate
|
// should use permanent way to indicate
|
||||||
var did_fail_load_notification = new Notification(`Failed to load "${thisObj.props.name}"`, {
|
var did_fail_load_notification = new Notification(`Failed to load "${thisObj.props.name}"`, {
|
||||||
body: `ErrorCode: ${e.errorCode}`,
|
body: `ErrorCode: ${e.errorCode}`,
|
||||||
|
33
src/main.js
33
src/main.js
@@ -10,6 +10,7 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
var settings = require('./common/settings');
|
var settings = require('./common/settings');
|
||||||
|
var certificateStore = require('./main/certificateStore').load(path.resolve(app.getPath('userData'), 'certificate.json'));
|
||||||
var appMenu = require('./main/menus/app');
|
var appMenu = require('./main/menus/app');
|
||||||
|
|
||||||
var argv = require('yargs').argv;
|
var argv = require('yargs').argv;
|
||||||
@@ -80,6 +81,38 @@ app.on('before-quit', function() {
|
|||||||
willAppQuit = true;
|
willAppQuit = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.on('certificate-error', function(event, webContents, url, error, certificate, callback) {
|
||||||
|
if (certificateStore.isTrusted(url, certificate)) {
|
||||||
|
event.preventDefault();
|
||||||
|
callback(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var detail = `URL: ${url}\nError: ${error}`;
|
||||||
|
if (certificateStore.isExisting(url)) {
|
||||||
|
detail = `Certificate is different from previous one.\n\n` + detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
electron.dialog.showMessageBox(mainWindow, {
|
||||||
|
title: 'Certificate error',
|
||||||
|
message: `Do you trust certificate from "${certificate.issuerName}"?`,
|
||||||
|
detail: detail,
|
||||||
|
type: 'warning',
|
||||||
|
buttons: [
|
||||||
|
'Yes',
|
||||||
|
'No'
|
||||||
|
],
|
||||||
|
cancelId: 1
|
||||||
|
}, function(response) {
|
||||||
|
if (response === 0) {
|
||||||
|
certificateStore.add(url, certificate);
|
||||||
|
certificateStore.save();
|
||||||
|
webContents.loadURL(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
|
62
src/main/certificateStore.js
Normal file
62
src/main/certificateStore.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const url = require('url');
|
||||||
|
|
||||||
|
function comparableCertificate(certificate) {
|
||||||
|
return {
|
||||||
|
data: certificate.data.toString(),
|
||||||
|
issuerName: certificate.issuerName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function areEqual(certificate0, certificate1) {
|
||||||
|
if (certificate0.data !== certificate1.data) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (certificate0.issuerName !== certificate1.issuerName) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHost(targetURL) {
|
||||||
|
return url.parse(targetURL).host;
|
||||||
|
}
|
||||||
|
|
||||||
|
var CertificateStore = function(storeFile) {
|
||||||
|
this.storeFile = storeFile
|
||||||
|
try {
|
||||||
|
this.data = JSON.parse(fs.readFileSync(storeFile, 'utf-8'));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
this.data = {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
CertificateStore.prototype.save = function() {
|
||||||
|
fs.writeFileSync(this.storeFile, JSON.stringify(this.data, null, ' '));
|
||||||
|
};
|
||||||
|
|
||||||
|
CertificateStore.prototype.add = function(targetURL, certificate) {
|
||||||
|
this.data[getHost(targetURL)] = comparableCertificate(certificate);
|
||||||
|
};
|
||||||
|
|
||||||
|
CertificateStore.prototype.isExisting = function(targetURL) {
|
||||||
|
return this.data.hasOwnProperty(getHost(targetURL));
|
||||||
|
};
|
||||||
|
|
||||||
|
CertificateStore.prototype.isTrusted = function(targetURL, certificate) {
|
||||||
|
var host = getHost(targetURL);
|
||||||
|
if (!this.isExisting(targetURL)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return areEqual(this.data[host], comparableCertificate(certificate));
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
load: function(storeFile) {
|
||||||
|
return new CertificateStore(storeFile);
|
||||||
|
}
|
||||||
|
};
|
Reference in New Issue
Block a user