Skip to content

Commit

Permalink
selecting other fields
Browse files Browse the repository at this point in the history
  • Loading branch information
antelle committed Apr 29, 2021
1 parent b5bdc2e commit ec931d4
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 7 deletions.
23 changes: 23 additions & 0 deletions docs/keeweb-connect-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,29 @@ Decrypted response:
}
```

### `get-any-field`

Allows user to select a field, similar to `get-logins`.

Unencrypted message:
```json
{
"action": "get-any-field",
"url": "<url>",
"title": "<page-title>"
}
```

Decrypted response:
```json
{
"field": "<field-name>",
"value": "<field-value>",
"version": "1.2.3",
"success": "true"
}
```

### `attention-required`

Event emitted by KeeWeb when its own tab needs user attention, for example, to approve a connection request.
Expand Down
7 changes: 7 additions & 0 deletions src/background/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ class Backend extends TypedEmitter<BackendEvents> {
}
return this._protocol.getTotp(url, title);
}

async getAnyField(url: string, title: string): Promise<string> {
if (!this._protocol) {
throw new Error('Not connected');
}
return this._protocol.getAnyField(url, title);
}
}

const backend = new Backend();
Expand Down
3 changes: 3 additions & 0 deletions src/background/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ async function runCommand(args: CommandArgs): Promise<void> {
text = await backend.getTotp(args.url, args.tab.title || '');
} catch {}
} else {
try {
text = await backend.getAnyField(args.url, args.tab.title || '');
} catch {}
}

await autoFill(args.url, args.tab, args.frameId, {
Expand Down
21 changes: 20 additions & 1 deletion src/background/protocol/protocol-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {
KeeWebConnectGetLoginsRequestPayload,
KeeWebConnectGetLoginsResponsePayload,
KeeWebConnectGetTotpByUrlRequestPayload,
KeeWebConnectGetTotpByUrlResponsePayload
KeeWebConnectGetTotpByUrlResponsePayload,
KeeWebConnectGetAnyFieldRequestPayload,
KeeWebConnectGetAnyFieldResponsePayload
} from './types';
import { fromBase64, randomBase64, randomBytes, toBase64 } from 'background/utils';
import { box as tweetnaclBox, BoxKeyPair } from 'tweetnacl';
Expand Down Expand Up @@ -293,6 +295,23 @@ class ProtocolImpl {

return payload.totp;
}

async getAnyField(url: string, title: string): Promise<string> {
const requestPayload: KeeWebConnectGetAnyFieldRequestPayload = {
action: 'get-any-field',
url,
title
};
const request = this.makeEncryptedRequest(requestPayload);

const response = <KeeWebConnectEncryptedResponse>await this.request(request);

const payload = <KeeWebConnectGetAnyFieldResponsePayload>(
this.decryptResponsePayload(request, response)
);

return payload.value;
}
}

export { ProtocolImpl };
13 changes: 13 additions & 0 deletions src/background/protocol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,16 @@ export interface KeeWebConnectGetTotpByUrlRequestPayload extends KeeWebConnectRe
export interface KeeWebConnectGetTotpByUrlResponsePayload extends KeeWebConnectResponse {
totp: string;
}

// get-any-field

export interface KeeWebConnectGetAnyFieldRequestPayload extends KeeWebConnectRequest {
action: 'get-any-field';
url: string;
title: string;
}

export interface KeeWebConnectGetAnyFieldResponsePayload extends KeeWebConnectResponse {
field: string;
value: string;
}
12 changes: 6 additions & 6 deletions src/background/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ export function createUIMenus(): void {
title: chrome.i18n.getMessage('cmdInsertOtp'),
contexts: ['editable']
});
// chrome.contextMenus.create({
// id: 'insert-other',
// parentId: 'keeweb-options',
// title: chrome.i18n.getMessage('menuOtherOptions') + '…',
// contexts: ['editable']
// });
chrome.contextMenus.create({
id: 'insert-other',
parentId: 'keeweb-options',
title: chrome.i18n.getMessage('menuOtherOptions') + '…',
contexts: ['editable']
});
chrome.contextMenus.create({
id: 'settings',
parentId: 'keeweb-options',
Expand Down

0 comments on commit ec931d4

Please sign in to comment.