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>
</head>
<body>
<h1>KeeWeb Plugin: KeeWebHttp</h1>
<a href="https://plugins.keeweb.info/plugins/keewebhttp">https://plugins.keeweb.info/plugins/keewebhttp</a>
<h1>KeeWeb Plugin: KeeWebHttp</h1>
<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>
</html>

View File

@ -11,7 +11,7 @@
"licence": "MIT",
"url": "https://plugins.keeweb.info/plugins/keewebhttp",
"resources": {
"js": "NB8wqvULI7yTqf8FAkJYx2TbyW/BjDo7zpm15MHHHTcYYVIRhYFAeiKx5f9j9UtXLYr1deVc7STdvVLhNsD//tN4LRsSXmOiMt2NnhjIHLhVHwlKxSZTMeK5NrajxjdS0YtBKMg5oDt9vYa15qOvoX0fhmc9E1gD6j5z9sJAxT450JEDRZidXLnUnEnGIZunVH5OCe75eavvcEQ64sZ3pUouTN9iWU66sjC3hG/pk3o5I4+8W4v1MWy2TR7IKaVOLrRiDrzT/rnZoroRg7QLLUb+L185S/OYMEo8MIa7lMu/ULhmbhk0+JT2pukEofPkOZAlF8BIf1EGXGp6gObo4w=="
"js": "iTzPUSfTwTOP0zjeZHi8xNzmEg357fHuBQ4kHDlFqu4Svn5tZoseSm/XI9rscKnM5EudOAKhsJfck6Z0N3hTw3Ih3LAYlik6ltpI6P1hU0KP0j9L6bcrCndEoH/BZy7iaJiZqIvQHoRy7NHNf26Bbq6W4VO1bBcx8sH3H7GnaQEGHj2zS68KRTDwVR2QIErLTtOQvwuiSZCUwyZYilvDIM1wGcKi6TDzSz38MHNIyx4X/n7uHV63ToZSB6ipcF6HpoAKGkXKBWaXosqy3LoDPAzif5EZzv7JQGB2dAtpOoq2G5grUA5YZrIQ/SSNfREWUDom7Xj1HCNb59RxViOR+Q=="
},
"publicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0oZB2Kt7AzRFNqf8FuO3C3kepHPAIQYiDPYdQxHcsiaFCwyKVx6K1cE/3vBhb8/2rj+QIIWNfAAuu1Y+2VK90ZBeq6HciukWzQRO/HWhfdy0c7JwDAslmyGI5olj0ZQkNLhkde1MiMxjDPpRhZtdJaryVO5cFJaJESpv3dV6m0qXsaQCluWYOSNfSjP9C8o2zRVjSi3ZQZnZIV5pnk9K2MtlZIPXrN9iJiM5zZ9DTSnqApI6dC9mX4R3LvGN+GTovm9C8Crl+qb106nGRR3LcweicDnPyMtZLa/E0DBpWYxUVLDp6WeLhxoUBr+6+t3Xp9IDnPoANDQXJXD0f1vQxQIDAQAB",
"desktop": true,

View File

@ -1,7 +1,5 @@
let server;
let uninstalled = false;
setTimeout(run, 500);
let uninstall;
const timeout = setTimeout(run, 500);
function run() {
const nodeRequire = window.require;
@ -25,8 +23,30 @@ function run() {
const keys = {};
const logger = new Logger('keewebhttp');
let uninstalled;
let server;
uninstall = function() {
uninstalled = true;
removeEventListeners();
stopServer();
};
addEventListeners();
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() {
if (uninstalled) {
return;
@ -78,6 +98,16 @@ function run() {
server.conn = {};
}
function stopServer() {
if (server) {
server.close();
for (const key of Object.keys(server.conn)) {
server.conn[key].destroy();
}
server = null;
}
}
class RequestContext {
constructor(postData) {
this.postData = postData;
@ -171,13 +201,17 @@ function run() {
}
getKeyById() {
// TODO
return keys[this.req.Id];
let key = keys[this.req.Id];
if (!key) {
key = ''; // TODO: read key
keys[this.req.Id] = key;
}
return key;
}
saveKeyWithId() {
keys[this.req.Id] = this.req.Key;
// TODO
// TODO: write key
}
verifyRequest() {
@ -236,8 +270,9 @@ function run() {
electron.remote.app.getMainWindow().focus();
return new Promise((resolve, reject) => {
Alerts.yesno({
icon: 'plug',
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: () => {
resolve();
},
@ -247,7 +282,7 @@ function run() {
});
}).then(() => {
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.createResponse();
return this.resp;
@ -296,9 +331,10 @@ function run() {
this.createResponse();
const preset = GeneratorPresets.all.filter(p => p.default)[0] || GeneratorPresets.defaultPreset;
const password = Generator.generate(preset);
const bits = Buffer.from(password, 'utf8').byteLength * 8;
this.resp.Count = 1;
this.resp.Entries = [{
Login: '',
Login: this.encrypt(bits.toString()),
Name: '',
Password: this.encrypt(password),
StringFields: null,
@ -309,12 +345,9 @@ function run() {
}
module.exports.uninstall = function() {
if (server) {
server.close();
for (const key of Object.keys(server.conn)) {
server.conn[key].destroy();
}
server = null;
if (uninstall) {
uninstall();
} else {
clearTimeout(timeout);
}
uninstalled = true;
};