keewebhttp: bugfixes

This commit is contained in:
antelle 2017-05-23 23:14:23 +02:00
parent e6b10c8a97
commit bcb728444c
3 changed files with 59 additions and 20 deletions

View File

@ -12,7 +12,13 @@
</style> </style>
</head> </head>
<body> <body>
<h1>KeeWeb Plugin: KeeWebHttp</h1> <h1>KeeWeb Plugin: KeeWebHttp</h1>
<a href="https://plugins.keeweb.info/plugins/keewebhttp">https://plugins.keeweb.info/plugins/keewebhttp</a> <a href="https://plugins.keeweb.info/plugins/keewebhttp">https://plugins.keeweb.info/plugins/keewebhttp</a>
<p>This plugin enables integrations with browser extensions, like
<a href="https://chrome.google.com/webstore/detail/chromeipass/ompiailgknfdndiefoaoiligalphfdae?utm_source=chrome-ntp-icon">chromeIPass</a>
or
<a href="https://addons.mozilla.org/en-US/firefox/addon/passifox/">PassIFox</a>.
</p>
<p>It's the same as KeePassHttp, but for KeeWeb.</p>
</body> </body>
</html> </html>

View File

@ -11,7 +11,7 @@
"licence": "MIT", "licence": "MIT",
"url": "https://plugins.keeweb.info/plugins/keewebhttp", "url": "https://plugins.keeweb.info/plugins/keewebhttp",
"resources": { "resources": {
"js": "NB8wqvULI7yTqf8FAkJYx2TbyW/BjDo7zpm15MHHHTcYYVIRhYFAeiKx5f9j9UtXLYr1deVc7STdvVLhNsD//tN4LRsSXmOiMt2NnhjIHLhVHwlKxSZTMeK5NrajxjdS0YtBKMg5oDt9vYa15qOvoX0fhmc9E1gD6j5z9sJAxT450JEDRZidXLnUnEnGIZunVH5OCe75eavvcEQ64sZ3pUouTN9iWU66sjC3hG/pk3o5I4+8W4v1MWy2TR7IKaVOLrRiDrzT/rnZoroRg7QLLUb+L185S/OYMEo8MIa7lMu/ULhmbhk0+JT2pukEofPkOZAlF8BIf1EGXGp6gObo4w==" "js": "iTzPUSfTwTOP0zjeZHi8xNzmEg357fHuBQ4kHDlFqu4Svn5tZoseSm/XI9rscKnM5EudOAKhsJfck6Z0N3hTw3Ih3LAYlik6ltpI6P1hU0KP0j9L6bcrCnd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,7 +1,5 @@
let server; let uninstall;
let uninstalled = false; const timeout = setTimeout(run, 500);
setTimeout(run, 500);
function run() { function run() {
const nodeRequire = window.require; const nodeRequire = window.require;
@ -25,8 +23,30 @@ function run() {
const keys = {}; const keys = {};
const logger = new Logger('keewebhttp'); const logger = new Logger('keewebhttp');
let uninstalled;
let server;
uninstall = function() {
uninstalled = true;
removeEventListeners();
stopServer();
};
addEventListeners();
startServer(); startServer();
function addEventListeners() {
AppModel.instance.files.on('add', fileOpened);
}
function removeEventListeners() {
AppModel.instance.files.off('add', fileOpened);
}
function fileOpened(e) {
console.log('file opened', e);
}
function startServer() { function startServer() {
if (uninstalled) { if (uninstalled) {
return; return;
@ -78,6 +98,16 @@ function run() {
server.conn = {}; server.conn = {};
} }
function stopServer() {
if (server) {
server.close();
for (const key of Object.keys(server.conn)) {
server.conn[key].destroy();
}
server = null;
}
}
class RequestContext { class RequestContext {
constructor(postData) { constructor(postData) {
this.postData = postData; this.postData = postData;
@ -171,13 +201,17 @@ function run() {
} }
getKeyById() { getKeyById() {
// TODO let key = keys[this.req.Id];
return keys[this.req.Id]; if (!key) {
key = ''; // TODO: read key
keys[this.req.Id] = key;
}
return key;
} }
saveKeyWithId() { saveKeyWithId() {
keys[this.req.Id] = this.req.Key; keys[this.req.Id] = this.req.Key;
// TODO // TODO: write key
} }
verifyRequest() { verifyRequest() {
@ -236,8 +270,9 @@ function run() {
electron.remote.app.getMainWindow().focus(); electron.remote.app.getMainWindow().focus();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
Alerts.yesno({ Alerts.yesno({
icon: 'plug',
header: 'External Connection', header: 'External Connection',
body: 'Some app is trying to connect to KeeWeb. If you are setting up your plugin, please allow the connection. Otherwise, click No.', body: 'Some app is trying to manage passwords in KeeWeb. If you are setting up your plugin, please allow the connection. Otherwise, click No.',
success: () => { success: () => {
resolve(); resolve();
}, },
@ -247,7 +282,7 @@ function run() {
}); });
}).then(() => { }).then(() => {
this.req.Id = 'KeeWeb_' + new Date().toISOString() + '_' + crypto.randomBytes(16).toString('hex'); this.req.Id = 'KeeWeb_' + new Date().toISOString() + '_' + crypto.randomBytes(16).toString('hex');
logger.info('associate: ', this.req.Id); logger.info(`associate: ${this.req.Id}`);
this.saveKeyWithId(); this.saveKeyWithId();
this.createResponse(); this.createResponse();
return this.resp; return this.resp;
@ -296,9 +331,10 @@ function run() {
this.createResponse(); this.createResponse();
const preset = GeneratorPresets.all.filter(p => p.default)[0] || GeneratorPresets.defaultPreset; const preset = GeneratorPresets.all.filter(p => p.default)[0] || GeneratorPresets.defaultPreset;
const password = Generator.generate(preset); const password = Generator.generate(preset);
const bits = Buffer.from(password, 'utf8').byteLength * 8;
this.resp.Count = 1; this.resp.Count = 1;
this.resp.Entries = [{ this.resp.Entries = [{
Login: '', Login: this.encrypt(bits.toString()),
Name: '', Name: '',
Password: this.encrypt(password), Password: this.encrypt(password),
StringFields: null, StringFields: null,
@ -309,12 +345,9 @@ function run() {
} }
module.exports.uninstall = function() { module.exports.uninstall = function() {
if (server) { if (uninstall) {
server.close(); uninstall();
for (const key of Object.keys(server.conn)) { } else {
server.conn[key].destroy(); clearTimeout(timeout);
}
server = null;
} }
uninstalled = true;
}; };