keewebhttp: fix config entry search

This commit is contained in:
antelle 2017-05-24 19:42:45 +02:00
parent 0f33a73441
commit 85f64dc94d
2 changed files with 25 additions and 16 deletions

View File

@ -11,7 +11,7 @@
"licence": "MIT",
"url": "https://plugins.keeweb.info/plugins/keewebhttp",
"resources": {
"js": "to0fWxarSAgke4VqZoV3P/dO92ea7RDlmCCyXJEbFOKER+JpJraPsPn0oeWoSzY396T7e2hRxM8HNo7rcnZtkojtCNALmOmz5aSg1cD8CmB3jYJJaG3r5t7WduyrOrha9+tU8XM5faAYeg6lrJb42D6e67/GHZG3GkPSpq3963Wjv36lb9/XQtUkgAOpV5dnuJhNdostFqngWnadvov1NnSNZtr6fbSoq+4worBPUnZTuDqzPTW0QIa2rfoA+Qsg4DLUBnuRLrgTA/8ObzI+qH5aKujIk4sBw6QZffGMpzESFlockS65cr5gmSu152A5oEgkqXT1sRKhMDC1qrFgnA=="
"js": "TckiF5MG/wcxxDccWP/JWeAQUlw6PD8/cNLirc/68eUNJ9MhwT7Rox1191V26BN8pdbzvqamBy30gGa1WvHa8byRAN9l7BoN2gCHOrf52hNPAkWGVXrrDEKkuMlvODifqjbzqW0llPoF1Ylq9vmTVei0qYLhCgsiz3Y8q5v7Ng6MWqph//DpiZuXq8xN23qjMEav5Rkab4/7IIbNlZOCEgt9JALQ6uW76OOWpoXNWegWIGDvkrs83Dq4WRn9As2YP6EueAywVkCCSjc9XkrbMTNOBOhTL7vgzyx5QiPfW7cWilcp27DGXbTp2uAbzyEnAiNg/U0wDckmqr8k2BwSbQ=="
},
"publicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0oZB2Kt7AzRFNqf8FuO3C3kepHPAIQYiDPYdQxHcsiaFCwyKVx6K1cE/3vBhb8/2rj+QIIWNfAAuu1Y+2VK90ZBeq6HciukWzQRO/HWhfdy0c7JwDAslmyGI5olj0ZQkNLhkde1MiMxjDPpRhZtdJaryVO5cFJaJESpv3dV6m0qXsaQCluWYOSNfSjP9C8o2zRVjSi3ZQZnZIV5pnk9K2MtlZIPXrN9iJiM5zZ9DTSnqApI6dC9mX4R3LvGN+GTovm9C8Crl+qb106nGRR3LcweicDnPyMtZLa/E0DBpWYxUVLDp6WeLhxoUBr+6+t3Xp9IDnPoANDQXJXD0f1vQxQIDAQAB",
"desktop": true,

View File

@ -10,6 +10,7 @@ function run() {
const path = nodeRequire('path');
const electron = nodeRequire('electron');
const Backbone = require('backbone');
const kdbxweb = require('kdbxweb');
const AppModel = require('models/app-model');
const EntryModel = require('models/entry-model');
@ -24,6 +25,7 @@ function run() {
const FileReadTimeout = 500;
const EntryTitle = 'KeePassHttp Settings';
const EntryFieldPrefix = 'AES Key: ';
const EntryUuid = 'NGl6QIpbQcCfNol9Yj7LMQ==';
const keys = {};
const addedKeys = {};
@ -163,6 +165,7 @@ function run() {
let settingsEntry = getSettingsEntry(file);
if (!settingsEntry) {
settingsEntry = EntryModel.newEntry(file.get('groups').first(), file);
settingsEntry.entry.uuid = new kdbxweb.KdbxUuid(EntryUuid);
settingsEntry.setField('Title', EntryTitle);
}
for (const key of Object.keys(addedKeys)) {
@ -177,16 +180,11 @@ function run() {
}
}
file.reload();
Backbone.trigger('refresh');
}
function getSettingsEntry(file) {
let entry = null;
file.get('groups').first().forEachOwnEntry({ textLower: EntryTitle.toLowerCase() }, e => {
if (e.title === EntryTitle) {
entry = e;
}
});
return entry;
return file.getEntry(file.subId(EntryUuid));
}
class RequestContext {
@ -362,7 +360,7 @@ function run() {
}
});
}).then(() => {
this.req.Id = 'KeeWeb_' + new Date().toISOString() + '_' + crypto.randomBytes(16).toString('hex');
this.req.Id = 'KeeWeb ' + new Date().toISOString();
logger.info(`associate: ${this.req.Id}`);
this.saveKeyWithId();
this.createResponse();
@ -385,13 +383,24 @@ function run() {
this.resp.Count = entries.length;
logger.info(`getLogins(${url}): ${this.resp.Count}`);
if (!config.onlyCount) {
this.resp.Entries = entries.map(entry => ({
Login: entry.user ? this.encrypt(entry.user) : '',
Name: entry.title ? this.encrypt(entry.title) : '',
Password: entry.password ? this.encrypt(entry.password) : '',
StringFields: null,
Uuid: this.encrypt(entry.id)
}));
this.resp.Entries = entries.map(entry => {
let customFields = null;
for (const field of Object.keys(entry.fields)) {
if (!customFields) {
customFields = [];
}
const fieldKey = this.encrypt(field);
const fieldValue = this.encrypt(entry.fields[field]);
customFields.push({ Key: fieldKey, Value: fieldValue });
}
return {
Login: entry.user ? this.encrypt(entry.user) : '',
Name: entry.title ? this.encrypt(entry.title) : '',
Password: entry.password ? this.encrypt(entry.password) : '',
StringFields: customFields,
Uuid: this.encrypt(entry.entry.uuid.id)
};
});
}
}