Fixed init problem in Chrome (not tested on Safari)

This commit is contained in:
leolivier 2018-03-24 12:30:03 +01:00
parent 37e550eb79
commit 0573744d2e
2 changed files with 30 additions and 23 deletions

View File

@ -9,7 +9,7 @@
"url": "https://github.com/leolivier"
},
"resources": {
"js": "na+696slok4iEscUEExyD2dF6bwT1AlmtiIogdAda9xZiBGiSNM4u43Q9oaBbnT+U1Kgoumgh0lHbnb+Hy5YtSFUTCi5M3+DKgaGVIQD0DivXqojGQF+aPKRnBv5tYu4QlGCXVVr3rXf65FHghfTXTrN0vSXM/PcysZkkrgaY6qxUZsROfnLX4EeX9JKdHcqRA3JpQI3ptBiYPL6zzJuQZcD18IMuULvs07f3QpP5IiTsgOWftBEQ20RPr3gqAjd6aAhKYGiNqBaJ7wR8MCKqNiJ4yPv6fPpNdimbh/mP3LY69CFaGvi9ZyABcP7I5zenw1ZScQsYfC+Qix25LZqBw=="
"js": "BeXlCVvW20aFD4PXy65b/sMxTl44rMy6yvFgTGIHJGlnLxIyQIvp4wPcDyf6sSXZqn5IthrxSDvRvsAW/gOcbeOAt/cwsafazJXU1El1xjKJ5FGcE6oJLZfcBYDSoAk5+OBQi1Casyw5F1PflBxtk4J64ASADnNNZbEi+kpnZcIho6e//qwfXMpqMftCZVqWgqVQX0N9OFa7qWxLv2x4acLx2B7cHu7/No97ChjwNNh8vqjo2BQG40rjiCtx0P6lh2r54K5c1QC3k15OJM2atSA+mG6d3HhHqhJMhjOCp3BwwyVfJ1jZ6/xg6GBDTaDmaIuegAfXd+gpZ+8DG5iPPg=="
},
"url": "https://plugins.keeweb.info/plugins/haveibeenpwned",
"publicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp9Cay/z7whBsHcf9klDjlA4qylWT7a/igTJ2nvUq2XuQrx98PTOexzzzg5oflk8nPEaMIsaFIf90V/rvQjJ1z9DR4zuQKDb4/GZVzxoylECAwNk80LvSPc1G0+6mwXIFp48wc6Advd4iYQCMkzWDCJXEm/1E+q85ty+H6EaLleKcJI0vlW96bbA9vFCmOsM5PYZfoGnVFRBLVthyUcGneilMvsxu5J7DKggQKPs04/WQZ5oHbUG83mxkxTdYDC3glpvV4BiaAD6z+2usO+fA97bXb+rY3O2iHJgWsa7jH0ybO0Nif6txE4d2+LJOLmfoImv7kdyu/eN3A78KejCOhwIDAQAB",

View File

@ -12,8 +12,6 @@ const Kdbxweb = require('kdbxweb');
const _ = require('_');
const detailsViewFieldChanged = DetailsView.prototype.fieldChanged;
const settings = { checkPwnedPwd: false, checkPwnedName: false, blockPwnedPwd: false, blockPwnedName: false };
const logger = new Logger('HaveIBeenPwned');
DetailsView.prototype.checkPwnedOnSettingsChanged = function (changes) {
// if (changes['CheckPwnedPwd'] || changes['CheckPwnedName'] || changes['BlockPwnedPwd'] || changes['BlockPwnedName']) {
@ -25,6 +23,11 @@ let _seen = [];
class HIBPUtils {
constructor() {
_seen = [];
this.checkPwnedPwd = true;
this.checkPwnedName = true;
this.blockPwnedPwd = false;
this.blockPwnedName = false;
this.logger = new Logger('HaveIBeenPwned');
};
replacer(key, value) {
if (value != null && typeof value === 'object') {
@ -106,10 +109,10 @@ class HIBPUtils {
const hibp = new HIBPUtils();
DetailsView.prototype.checkNamePwned = function (name) {
logger.info('check hibp name ' + name);
hibp.logger.info('check hibp name ' + name);
name = encodeURIComponent(name);
const url = `https://haveibeenpwned.com/api/v2/breachedaccount/${name}?truncateResponse=true`;
logger.info('url ' + url);
hibp.logger.info('url ' + url);
hibp.xhrcall({
url: url,
method: 'GET',
@ -118,9 +121,9 @@ DetailsView.prototype.checkNamePwned = function (name) {
data: null,
statuses: [200, 404],
success: (data, xhr) => {
logger.info('xhr ' + JSON.stringify(xhr));
hibp.logger.info('xhr ' + JSON.stringify(xhr));
if (data && data.length > 0) {
logger.info('found breaches ' + JSON.stringify(data));
hibp.logger.info('found breaches ' + JSON.stringify(data));
let breaches = '';
data.forEach(breach => { breaches += '<li>' + _.escape(breach.Name) + '</li>\n'; });
hibp.alert(`WARNING! This account has been pawned in the following breaches<br/>\n<ul>\n${breaches}\n</ul>\n<p>Please check on <a href='https://haveibeenpwned.com'>https://haveibeenpwned.com</a>\n`);
@ -128,20 +131,20 @@ DetailsView.prototype.checkNamePwned = function (name) {
this.userEditView.$el.addClass('input--error');
InputFx.shake(this.userEditView.$el);
} else {
logger.info('check pwnd name passed...');
hibp.logger.info('check pwnd name passed...');
this.userEditView.$el.removeClass('input--error');
}
},
error: (e, xhr) => {
const err = xhr.response && xhr.response.error || new Error('Network error');
logger.error('Pwned Password API error', 'GET', xhr.status, err);
hibp.logger.error('Pwned Password API error', 'GET', xhr.status, err);
err.status = xhr.status;
}
});
};
DetailsView.prototype.checkPwdPwned = function (passwordHash) {
logger.info('check hibp pwd (hash) ' + passwordHash);
hibp.logger.info('check hibp pwd (hash) ' + passwordHash);
const prefix = passwordHash.substring(0, 5);
hibp.xhrcall({
url: `https://api.pwnedpasswords.com/range/${prefix}`,
@ -152,7 +155,7 @@ DetailsView.prototype.checkPwdPwned = function (passwordHash) {
statuses: [200, 404],
success: data => {
if (data) {
logger.info('found breaches ' + JSON.stringify(data));
hibp.logger.info('found breaches ' + JSON.stringify(data));
data.split('\r\n').forEach(line => {
const h = line.split(':');
const suffix = h[0];
@ -165,23 +168,23 @@ DetailsView.prototype.checkPwdPwned = function (passwordHash) {
}
});
} else {
logger.info('check pwnd passwd passed...');
hibp.logger.info('check pwnd passwd passed...');
this.passEditView.$el.removeClass('input--error');
}
},
error: (e, xhr) => {
const err = xhr.response && xhr.response.error || new Error('Network error');
logger.error('Pwned Password API error', 'GET', xhr.status, err);
hibp.logger.error('Pwned Password API error', 'GET', xhr.status, err);
err.status = xhr.status;
}
});
};
DetailsView.prototype.fieldChanged = function (e) {
// logger.info('field changed ' + hibp.stringify(e));
detailsViewFieldChanged.apply(this, arguments);
if (e.field) {
if (e.field === '$Password' && settings.checkPwnedPwd) {
// hibp.logger.info('field changed ' + hibp.stringify(e));
if (e.field === '$Password' && hibp.checkPwnedPwd) {
if (this.passEditView.value) {
const pwd = this.passEditView.value.getText();
if (pwd.replace(/\s/, '') !== '' && !pwd.startsWith('{REF:')) {
@ -190,34 +193,37 @@ DetailsView.prototype.fieldChanged = function (e) {
});
}
}
} else if (e.field === '$UserName' && settings.checkPwnedName) {
} else if (e.field === '$UserName' && hibp.checkPwnedName) {
this.checkNamePwned(e.val);
}
}
};
module.exports.getSettings = function () {
return [{
const ret = [{
name: 'checkPwnedPwd',
label: 'Check passwords against HaveIBeenPwned list',
type: 'checkbox',
value: true
value: hibp.checkPwnedPwd
}, {
name: 'checkPwnedName',
label: 'Check user ids against HaveIBeenPwned list',
type: 'checkbox',
value: true
value: hibp.checkPwnedName
}, {
name: 'blockPwnedPwd',
label: 'Block pwned passwords if they are in HaveIBeenPwned list',
type: 'checkbox',
value: true
value: hibp.blockPwnedPwd
}, {
name: 'blockPwnedName',
label: 'Block pwned names if they are in HaveIBeenPwned list',
type: 'checkbox',
value: true
}];
value: hibp.blockPwnedName
}
];
hibp.logger.info(hibp.stringify(ret));
return ret;
};
module.exports.setSettings = function (changes) {
@ -232,9 +238,10 @@ module.exports.setSettings = function (changes) {
for (const field in changes) {
const ccfield = field.substr(0, 1).toLowerCase() + field.substring(1);
settings[ccfield] = changes[field];
hibp[ccfield] = changes[field];
}
DetailsView.prototype.checkPwnedOnSettingsChanged.apply(changes);
// hibp.logger.info(hibp.stringify(hibp));
};
module.exports.uninstall = function () {