mirror of https://github.com/keeweb/keeweb.git
Testing features on start
This commit is contained in:
parent
0405ba0321
commit
1054cdcfc4
|
@ -18,6 +18,7 @@ const ExportApi = require('./comp/export-api');
|
|||
const SettingsManager = require('./comp/settings-manager');
|
||||
const PluginManager = require('./plugins/plugin-manager');
|
||||
const Launcher = require('./comp/launcher');
|
||||
const FeatureTester = require('./comp/feature-tester');
|
||||
const Timeouts = require('./const/timeouts');
|
||||
const FeatureDetector = require('./util/feature-detector');
|
||||
const KdbxwebInit = require('./util/kdbxweb-init');
|
||||
|
@ -108,28 +109,37 @@ ready(() => {
|
|||
}
|
||||
|
||||
function showApp() {
|
||||
return Promise.resolve().then(() => {
|
||||
const skipHttpsWarning = localStorage.skipHttpsWarning || appModel.settings.get('skipHttpsWarning');
|
||||
const protocolIsInsecure = ['https:', 'file:', 'app:'].indexOf(location.protocol) < 0;
|
||||
const hostIsInsecure = location.hostname !== 'localhost';
|
||||
if (protocolIsInsecure && hostIsInsecure && !skipHttpsWarning) {
|
||||
return new Promise(resolve => {
|
||||
Alerts.error({
|
||||
header: Locale.appSecWarn, icon: 'user-secret', esc: false, enter: false, click: false,
|
||||
body: Locale.appSecWarnBody1 + '<br/><br/>' + Locale.appSecWarnBody2,
|
||||
buttons: [
|
||||
{result: '', title: Locale.appSecWarnBtn, error: true}
|
||||
],
|
||||
complete: () => {
|
||||
showView();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
return FeatureTester.test()
|
||||
.catch(e => {
|
||||
Alerts.error({
|
||||
header: Locale.appFeatureTestFailed, esc: false, enter: false, click: false,
|
||||
body: Locale.appFeatureTestFailedBody + '<br/><br/>' + e,
|
||||
buttons: []
|
||||
});
|
||||
} else {
|
||||
showView();
|
||||
}
|
||||
});
|
||||
throw 'Feature testing failed: ' + e;
|
||||
})
|
||||
.then(() => {
|
||||
const skipHttpsWarning = localStorage.skipHttpsWarning || appModel.settings.get('skipHttpsWarning');
|
||||
const protocolIsInsecure = ['https:', 'file:', 'app:'].indexOf(location.protocol) < 0;
|
||||
const hostIsInsecure = location.hostname !== 'localhost';
|
||||
if (protocolIsInsecure && hostIsInsecure && !skipHttpsWarning) {
|
||||
return new Promise(resolve => {
|
||||
Alerts.error({
|
||||
header: Locale.appSecWarn, icon: 'user-secret', esc: false, enter: false, click: false,
|
||||
body: Locale.appSecWarnBody1 + '<br/><br/>' + Locale.appSecWarnBody2,
|
||||
buttons: [
|
||||
{result: '', title: Locale.appSecWarnBtn, error: true}
|
||||
],
|
||||
complete: () => {
|
||||
showView();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
showView();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function postInit() {
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
const kdbxweb = require('kdbxweb');
|
||||
|
||||
const FeatureTester = {
|
||||
test() {
|
||||
return Promise.resolve()
|
||||
.then(() => this.checkWebAssembly())
|
||||
.then(() => this.checkWebCrypto())
|
||||
.then(() => this.checkLocalStorage());
|
||||
},
|
||||
|
||||
checkWebAssembly() {
|
||||
try {
|
||||
const module = new global.WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
|
||||
return new global.WebAssembly.Instance(module) instanceof global.WebAssembly.Instance;
|
||||
} catch (e) {
|
||||
throw 'WebAssembly is not supported';
|
||||
}
|
||||
},
|
||||
|
||||
checkWebCrypto() {
|
||||
return Promise.resolve().then(() => {
|
||||
const aesCbc = kdbxweb.CryptoEngine.createAesCbc();
|
||||
const key = '6b2796fa863a6552986c428528d053b76de7ba8e12f8c0e74edb5ed44da3f601';
|
||||
const data = 'e567554429098a38d5f819115edffd39';
|
||||
const iv = '4db46dff4add42cb813b98de98e627c4';
|
||||
const exp = '46ab4c37d9ec594e5742971f76f7c1620bc29f2e0736b27832d6bcc5c1c39dc1';
|
||||
return aesCbc.importKey(kdbxweb.ByteUtils.hexToBytes(key)).then(() => {
|
||||
return aesCbc.encrypt(kdbxweb.ByteUtils.hexToBytes(data), kdbxweb.ByteUtils.hexToBytes(iv)).then(res => {
|
||||
if (kdbxweb.ByteUtils.bytesToHex(res) !== exp) {
|
||||
throw 'AES is not working properly';
|
||||
}
|
||||
if (kdbxweb.CryptoEngine.random(1).length !== 1) {
|
||||
throw 'Random is not working';
|
||||
}
|
||||
});
|
||||
}).catch(e => { throw 'WebCrypto is not supported: ' + e; });
|
||||
});
|
||||
},
|
||||
|
||||
checkLocalStorage() {
|
||||
try {
|
||||
localStorage.setItem('_test', '1');
|
||||
localStorage.removeItem('_test');
|
||||
} catch (e) {
|
||||
throw 'WebCrypto is not supported';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = FeatureTester;
|
|
@ -285,6 +285,8 @@
|
|||
"appSecWarnBody1": "You have loaded this app with an insecure connection. Someone may be watching you and stealing your passwords. We strongly advise you to stop, unless you clearly understand what you're doing.",
|
||||
"appSecWarnBody2": "Yes, your database is encrypted but no one can guarantee that the app has not been modified on the way to you.",
|
||||
"appSecWarnBtn": "I understand the risks, continue",
|
||||
"appFeatureTestFailed": "Not supported",
|
||||
"appFeatureTestFailedBody": "Your browser doesn't support some important features we're using.",
|
||||
"appUnsavedWarn": "Unsaved changes!",
|
||||
"appUnsavedWarnBody": "You have unsaved files, if you close the app, changes will be lost.",
|
||||
"appDontExitBtn": "Don't exit",
|
||||
|
|
Loading…
Reference in New Issue