Removal of unnecessary test code. Switched Base64 operations to tweetnacl-js.

This commit is contained in:
varjolintu 2017-03-30 10:43:58 +03:00
parent ce7bc973c1
commit c0de6941cd
2 changed files with 57 additions and 59 deletions

View file

@ -11,7 +11,7 @@ keepass.latestKeePassXC = (typeof(localStorage.latestKeePassXC) == 'undefined')
keepass.requiredKeePassXC = 212;
keepass.nativeHostName = "com.varjolintu.chromekeepassxc";
keepass.nativePort = null;
keepass.keySize = 8; // wtf? stupid cryptoHelpers
keepass.keySize = 8;
keepass.latestVersionUrl = "https://raw.githubusercontent.com/keepassxreboot/keepassxc/develop/CHANGELOG";
keepass.cacheTimeout = 30 * 1000; // milliseconds
keepass.databaseHash = "no-hash"; //no-hash = keepasshttp is too old and does not return a hash value
@ -139,32 +139,16 @@ keepass.retrieveCredentials = function (callback, tab, url, submiturl, forceCall
// Handles the replies with callback provided
keepass.handleReply = function (msg) {
var reply;
// Specific callback handling. Needed?
/*var reply;
if (msg.action == "generate-reply") {
console.log("Handling generate-reply");
var a = [];
var response = JSON.stringify({ login: (msg.password.length * 8), password: msg.password });
keepass.updateLastUsed(keepass.databaseHash);
a.push(response);
reply = a;
}
/*else if (msg.action == "get-logins-reply") {
console.log("Handling get-logins-reply");
if (msg.count) {
var a = [];
for (var i = 0; i < msg.count; i++) {
var response = JSON.stringify({ login: msg.entries[i].login, name: msg.entries[i].name, password: msg.entries[i].password });
keepass.updateLastUsed(keepass.databaseHash);
console.log(response);
a.push(response);
}
reply = a;
}
}*/
else {
reply = msg;
}
return reply;
return reply;*/
return msg;
}
// Redirects the callback to a listener (handleReply())
@ -202,7 +186,34 @@ keepass.generatePassword = function (callback, tab, forceCallback) {
var passwords = [];
message = { "action": "generate-password" };
keepass.callbackOnId(keepass.nativePort.onMessage, "generate-reply", callback);
var verifier = keepass.setVerifier(message);
var id = verifier[0];
var key = verifier[1];
keepass.callbackOnId(keepass.nativePort.onMessage, "generate-reply", function(response) {
console.log("Handling generate-reply");
keepass.setcurrentKeePassXCVersion(response.version);
var passwords = [];
if (keepass.verifyResponse(response, key, id)) {
var rIv = response.nonce;
if(response.entries) {
for (var i = 0; i < response.entries.length; i++) {
keepass.decryptEntry(response.entries[i], key, rIv);
}
passwords = response.entries;
keepass.updateLastUsed(keepass.databaseHash);
}
else {
console.log("No entries returned. Is KeePassHttp up-to-date?");
}
}
else {
console.log("GeneratePassword rejected");
}
callback(passwords);
});
keepass.nativePort.postMessage(message);
}
@ -239,7 +250,7 @@ keepass.associate = function(callback, tab) {
var rawKey = nacl.randomBytes(keepass.keySize * 2);
//var rawKey = [41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56]; // This is just for testing with the test client. KSorLC0uLzAxMjM0NTY3OA== )*+,-./012345678
console.log(rawKey);
//console.log(rawKey);
var key = keepass.b64e(rawKey);
var request = {
@ -546,11 +557,8 @@ keepass.setVerifier = function(request, inputKey) {
request.id = id;
}
//var iv = cryptoHelpers.generateSharedKey(keepass.keySize);
var nonce = nacl.randomBytes(keepass.keySize * 2);
request.nonce = keepass.b64e(nonce);
//var decodedKey = keepass.b64d(key);
request.verifier = keepass.encrypt(request.nonce, key, request.nonce);
var test = keepass.encrypt("Aeh9maerCjE5v5V8Tz2YxA==", key, "Aeh9maerCjE5v5V8Tz2YxA==");
@ -584,13 +592,13 @@ keepass.verifyResponse = function(response, key, id) {
}
keepass.b64e = function(d) {
//return nacl.util.encodeBase64(d);
return btoa(keepass.to_s(d));
//return btoa(keepass.to_s(d));
return nacl.util.encodeBase64(d);
}
keepass.b64d = function(d) {
//return nacl.util.decodeBase64(d);
return keepass.to_b(atob(d));
//return keepass.to_b(atob(d));
return nacl.util.decodeBase64(d);
}
keepass.getCryptoKey = function() {

View file

@ -424,19 +424,18 @@ cipPassword.callbackPasswordCopied = function(bool) {
cipPassword.callbackGeneratedPassword = function(entries) {
if(entries && entries.length >= 1) {
console.log(entries[0]);
var res = JSON.parse(entries[0]);
cIPJQ("#cip-genpw-btn-clipboard:first").removeClass("b2c-btn-success");
cIPJQ("input#cip-genpw-textfield-password:first").val(res.password);
if(isNaN(res.login)) {
cIPJQ("input#cip-genpw-textfield-password:first").val(entries[0].password);
if(isNaN(entries[0].login)) {
cIPJQ("#cip-genpw-quality:first").text("??? Bits");
}
else {
cIPJQ("#cip-genpw-quality:first").text(res.login + " Bits");
cIPJQ("#cip-genpw-quality:first").text(entries[0].login + " Bits");
}
}
else {
if(cIPJQ("div#cip-genpw-error:first").length == 0) {
cIPJQ("button#cip-genpw-btn-generate:first").after("<div style='block' id='cip-genpw-error'>Cannot receive generated password.<br />Is your version of KeePassXC up-to-date?<br /><br /><a href='https://keepassxc.org'>Please visit the KeePassXC homepage</a></div>");
cIPJQ("button#cip-genpw-btn-generate:first").after("<div style='block' id='cip-genpw-error'>Cannot receive generated password.<br />Is your version of KeePassHttp up-to-date?<br /><br /><a href='https://github.com/pfn/keepasshttp/'>Please visit the KeePassHttp homepage</a></div>");
cIPJQ("input#cip-genpw-textfield-password:first").parent().hide();
cIPJQ("input#cip-genpw-checkbox-next-field:first").parent("label").hide();
cIPJQ("button#cip-genpw-btn-generate").hide();
@ -1253,11 +1252,10 @@ cip.preparePageForMultipleCredentials = function(credentials) {
cipAutocomplete.elements = [];
var visibleLogin;
for(var i = 0; i < credentials.length; i++) {
var res = JSON.parse(credentials[i]);
visibleLogin = (res.login.length > 0) ? res.login : "- no username -";
usernames.push(visibleLogin + " (" + res.name + ")");
visibleLogin = (credentials[i].login.length > 0) ? credentials[i].login : "- no username -";
usernames.push(visibleLogin + " (" + credentials[i].name + ")");
var item = {
"label": visibleLogin + " (" + res.name + ")",
"label": visibleLogin + " (" + credentials[i].name + ")",
"value": credentials[i].login,
"loginId": i
};
@ -1451,7 +1449,7 @@ cip.setValueWithChange = function(field, value) {
field[0].dispatchEvent(new Event('change', {'bubbles': true}));
}
cip.fillIn = function(combination, onlyPassword, suppressWarnings) {
ip.fillIn = function(combination, onlyPassword, suppressWarnings) {
// no credentials available
if (cip.credentials.length == 0 && !suppressWarnings) {
var message = "No logins found.";
@ -1467,24 +1465,20 @@ cip.fillIn = function(combination, onlyPassword, suppressWarnings) {
// exactly one pair of credentials available
if (cip.credentials.length == 1) {
var res = JSON.parse(cip.credentials[0]);
var filledIn = false;
if(uField && !onlyPassword) {
//cip.setValueWithChange(uField, cip.credentials[0].Login);
cip.setValueWithChange(uField, res.login);
cip.setValueWithChange(uField, cip.credentials[0].login);
filledIn = true;
}
if(pField) {
pField.attr("type", "password");
//cip.setValueWithChange(pField, cip.credentials[0].Password);
cip.setValueWithChange(pField, res.password);
cip.setValueWithChange(pField, cip.credentials[0].password);
pField.data("unchanged", true);
filledIn = true;
}
var list = {};
//if(cip.fillInStringFields(combination.fields, cip.credentials[0].StringFields, list)) {
if(cip.fillInStringFields(combination.fields, res.StringFields, list)) {
if(cip.fillInStringFields(combination.fields, cip.credentials[0].StringFields, list)) {
cipForm.destroy(false, {"password": list.list[0], "username": list.list[1]});
filledIn = true;
}
@ -1501,24 +1495,20 @@ cip.fillIn = function(combination, onlyPassword, suppressWarnings) {
}
// specific login id given
else if(combination.loginId != undefined && cip.credentials[combination.loginId]) {
var res = JSON.parse(cip.credentials[combination.loginId]);
var filledIn = false;
if(uField) {
//cip.setValueWithChange(uField, cip.credentials[combination.loginId].Login);
cip.setValueWithChange(uField, res.login);
cip.setValueWithChange(uField, cip.credentials[combination.loginId].login);
filledIn = true;
}
if(pField) {
//cip.setValueWithChange(pField, cip.credentials[combination.loginId].Password);
cip.setValueWithChange(pField, res.password);
cip.setValueWithChange(pField, cip.credentials[combination.loginId].password);
pField.data("unchanged", true);
filledIn = true;
}
var list = {};
//if(cip.fillInStringFields(combination.fields, cip.credentials[combination.loginId].StringFields, list)) {
if(cip.fillInStringFields(combination.fields, res.StringFields, list)) {
if(cip.fillInStringFields(combination.fields, cip.credentials[combination.loginId].StringFields, list)) {
cipForm.destroy(false, {"password": list.list[0], "username": list.list[1]});
filledIn = true;
}
@ -1578,8 +1568,8 @@ cip.fillIn = function(combination, onlyPassword, suppressWarnings) {
// user has to select correct credentials by himself
if(countPasswords > 1) {
if(!suppressWarnings) {
var message = "Error #105\nMore than one login was found in KeePassXC!\n" +
"Press the chromeKeePassXC icon for more options.";
var message = "Error #105\nMore than one login was found in KeePass!\n" +
"Press the chromeIPass icon for more options.";
chrome.extension.sendMessage({
action: 'alert',
args: [message]
@ -1598,8 +1588,8 @@ cip.fillIn = function(combination, onlyPassword, suppressWarnings) {
}
else {
if(!suppressWarnings) {
var message = "Error #104\nMore than one login was found in KeePassXC!\n" +
"Press the chromeKeePassXC icon for more options.";
var message = "Error #104\nMore than one login was found in KeePass!\n" +
"Press the chromeIPass icon for more options.";
chrome.extension.sendMessage({
action: 'alert',
args: [message]