2022-03-09 22:08:22 +08:00
|
|
|
import { doc, addShortcut } from 'Common/Globals';
|
2021-01-24 17:25:23 +08:00
|
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
|
|
|
|
2022-02-24 21:01:41 +08:00
|
|
|
export class OpenPgpKeyPopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2022-01-30 04:42:56 +08:00
|
|
|
super('OpenPgpKey');
|
2014-09-06 05:44:29 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addObservables({
|
|
|
|
key: '',
|
|
|
|
keyDom: null
|
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-09-06 05:44:29 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
selectKey() {
|
|
|
|
const el = this.keyDom();
|
2019-07-05 03:19:24 +08:00
|
|
|
if (el) {
|
2020-10-03 05:54:15 +08:00
|
|
|
let sel = getSelection(),
|
2021-01-27 07:26:31 +08:00
|
|
|
range = doc.createRange();
|
2020-10-03 05:54:15 +08:00
|
|
|
sel.removeAllRanges();
|
|
|
|
range.selectNodeContents(el);
|
|
|
|
sel.addRange(range);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2022-01-30 04:42:56 +08:00
|
|
|
if (navigator.clipboard) {
|
|
|
|
navigator.clipboard.writeText(this.key()).then(
|
|
|
|
() => console.log('Copied to clipboard'),
|
|
|
|
err => console.error(err)
|
|
|
|
);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-09-06 05:44:29 +08:00
|
|
|
|
2016-09-30 21:42:38 +08:00
|
|
|
onShow(openPgpKey) {
|
2022-01-30 04:42:56 +08:00
|
|
|
// TODO: show more info
|
2021-11-03 21:58:34 +08:00
|
|
|
this.key(openPgpKey ? openPgpKey.armor : '');
|
2022-01-31 18:51:15 +08:00
|
|
|
/*
|
|
|
|
this.key = key;
|
|
|
|
const aEmails = [];
|
|
|
|
if (key.users) {
|
|
|
|
key.users.forEach(user => user.userID.email && aEmails.push(user.userID.email));
|
|
|
|
}
|
|
|
|
this.id = key.getKeyID().toHex();
|
|
|
|
this.fingerprint = key.getFingerprint();
|
|
|
|
this.can_encrypt = !!key.getEncryptionKey();
|
|
|
|
this.can_sign = !!key.getSigningKey();
|
|
|
|
this.emails = aEmails;
|
|
|
|
this.armor = armor;
|
|
|
|
this.askDelete = ko.observable(false);
|
|
|
|
this.openForDeletion = ko.observable(null).askDeleteHelper();
|
|
|
|
|
|
|
|
key.id = key.subkeys[0].keyid;
|
|
|
|
key.fingerprint = key.subkeys[0].fingerprint;
|
|
|
|
key.uids.forEach(uid => uid.email && aEmails.push(uid.email));
|
|
|
|
key.emails = aEmails;
|
|
|
|
"disabled": false,
|
|
|
|
"expired": false,
|
|
|
|
"revoked": false,
|
|
|
|
"is_secret": true,
|
|
|
|
"can_sign": true,
|
|
|
|
"can_decrypt": true
|
|
|
|
"can_verify": true
|
|
|
|
"can_encrypt": true,
|
|
|
|
"uids": [
|
|
|
|
{
|
|
|
|
"name": "demo",
|
|
|
|
"comment": "",
|
|
|
|
"email": "demo@snappymail.eu",
|
|
|
|
"uid": "demo <demo@snappymail.eu>",
|
|
|
|
"revoked": false,
|
|
|
|
"invalid": false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"subkeys": [
|
|
|
|
{
|
|
|
|
"fingerprint": "2C223F20EA2ADB4CB68F81D95F3A5CDC09AD8AE3",
|
|
|
|
"keyid": "5F3A5CDC09AD8AE3",
|
|
|
|
"timestamp": 1643381672,
|
|
|
|
"expires": 0,
|
|
|
|
"is_secret": false,
|
|
|
|
"invalid": false,
|
|
|
|
"can_encrypt": false,
|
|
|
|
"can_sign": true,
|
|
|
|
"disabled": false,
|
|
|
|
"expired": false,
|
|
|
|
"revoked": false,
|
|
|
|
"can_certify": true,
|
|
|
|
"can_authenticate": false,
|
|
|
|
"is_qualified": false,
|
|
|
|
"is_de_vs": false,
|
|
|
|
"pubkey_algo": 303,
|
|
|
|
"length": 256,
|
|
|
|
"keygrip": "5A1A6C7310D0508C68E8E74F15068301E83FD1AE",
|
|
|
|
"is_cardkey": false,
|
|
|
|
"curve": "ed25519"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fingerprint": "3CD720549D8833872C267D08F1230DCE2A561ADE",
|
|
|
|
"keyid": "F1230DCE2A561ADE",
|
|
|
|
"timestamp": 1643381672,
|
|
|
|
"expires": 0,
|
|
|
|
"is_secret": false,
|
|
|
|
"invalid": false,
|
|
|
|
"can_encrypt": true,
|
|
|
|
"can_sign": false,
|
|
|
|
"disabled": false,
|
|
|
|
"expired": false,
|
|
|
|
"revoked": false,
|
|
|
|
"can_certify": false,
|
|
|
|
"can_authenticate": false,
|
|
|
|
"is_qualified": false,
|
|
|
|
"is_de_vs": false,
|
|
|
|
"pubkey_algo": 302,
|
|
|
|
"length": 256,
|
|
|
|
"keygrip": "886921A7E06BE56F8E8C51797BB476BB26DF21BF",
|
|
|
|
"is_cardkey": false,
|
|
|
|
"curve": "cv25519"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
*/
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2015-09-02 03:50:30 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onBuild() {
|
2022-03-09 22:08:22 +08:00
|
|
|
addShortcut('a', 'meta', 'OpenPgpKey', () => {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.selectKey();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|