mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
OpenPGP fix handling of importing keys
This commit is contained in:
parent
5aa71a3ede
commit
b5062624fa
2 changed files with 32 additions and 20 deletions
|
|
@ -63,11 +63,7 @@ export class UserSettingsSecurity extends AbstractViewSettings {
|
||||||
|
|
||||||
importToOpenPGP() {
|
importToOpenPGP() {
|
||||||
OpenPGPUserStore.isSupported() && Remote.request('GetPGPKeys',
|
OpenPGPUserStore.isSupported() && Remote.request('GetPGPKeys',
|
||||||
(iError, oData) => {
|
(iError, oData) => !iError && oData.Result && OpenPGPUserStore.importKeys(oData.Result)
|
||||||
if (!iError && oData.Result) {
|
|
||||||
oData.Result.forEach(key => OpenPGPUserStore.importKey(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,15 +77,11 @@ const
|
||||||
class OpenPgpKeyModel {
|
class OpenPgpKeyModel {
|
||||||
constructor(armor, key) {
|
constructor(armor, key) {
|
||||||
this.key = key;
|
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().toUpperCase();
|
this.id = key.getKeyID().toHex().toUpperCase();
|
||||||
this.fingerprint = key.getFingerprint();
|
this.fingerprint = key.getFingerprint();
|
||||||
this.can_encrypt = !!key.getEncryptionKey();
|
this.can_encrypt = !!key.getEncryptionKey();
|
||||||
this.can_sign = !!key.getSigningKey();
|
this.can_sign = !!key.getSigningKey();
|
||||||
this.emails = aEmails;
|
this.emails = key.users.map(user => user.userID.email).filter(email => email);
|
||||||
this.armor = armor;
|
this.armor = armor;
|
||||||
this.askDelete = ko.observable(false);
|
this.askDelete = ko.observable(false);
|
||||||
this.openForDeletion = ko.observable(null).askDeleteHelper();
|
this.openForDeletion = ko.observable(null).askDeleteHelper();
|
||||||
|
|
@ -93,6 +89,15 @@ class OpenPgpKeyModel {
|
||||||
// key.getPrimaryUser()
|
// key.getPrimaryUser()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
get id() { return this.key.getKeyID().toHex().toUpperCase(); }
|
||||||
|
get fingerprint() { return this.key.getFingerprint(); }
|
||||||
|
get can_encrypt() { return !!this.key.getEncryptionKey(); }
|
||||||
|
get can_sign() { return !!this.key.getSigningKey(); }
|
||||||
|
get emails() { return this.key.users.map(user => user.userID.email).filter(email => email); }
|
||||||
|
get armor() { return this.key.armor(); }
|
||||||
|
*/
|
||||||
|
|
||||||
view() {
|
view() {
|
||||||
showScreenPopup(OpenPgpKeyPopupView, [this]);
|
showScreenPopup(OpenPgpKeyPopupView, [this]);
|
||||||
}
|
}
|
||||||
|
|
@ -142,18 +147,29 @@ export const OpenPGPUserStore = new class {
|
||||||
}
|
}
|
||||||
|
|
||||||
importKey(armoredKey) {
|
importKey(armoredKey) {
|
||||||
window.openpgp && openpgp.readKey({armoredKey:armoredKey}).then(key => {
|
this.importKeys([armoredKey]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async importKeys(keys) {
|
||||||
|
if (window.openpgp) {
|
||||||
|
const privateKeys = this.privateKeys(),
|
||||||
|
publicKeys = this.publicKeys();
|
||||||
|
for (const armoredKey of keys) try {
|
||||||
|
let key = await openpgp.readKey({armoredKey:armoredKey});
|
||||||
if (!key.err) {
|
if (!key.err) {
|
||||||
key = new OpenPgpKeyModel(armoredKey, key);
|
key = new OpenPgpKeyModel(armoredKey, key);
|
||||||
const isPrivate = key.key.isPrivate(),
|
const keys = key.key.isPrivate() ? privateKeys : publicKeys;
|
||||||
keys = isPrivate ? this.privateKeys : this.publicKeys;
|
keys.find(entry => entry.fingerprint == key.fingerprint)
|
||||||
if (!keys.find(entry => entry.fingerprint == key.fingerprint)) {
|
|| keys.push(key);
|
||||||
keys.push(key);
|
|
||||||
keys(sort(keys));
|
|
||||||
storeOpenPgpKeys(keys, isPrivate ? privateKeysItem : publicKeysItem);
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e, armoredKey);
|
||||||
|
}
|
||||||
|
this.privateKeys(sort(privateKeys));
|
||||||
|
this.publicKeys(sort(publicKeys));
|
||||||
|
storeOpenPgpKeys(privateKeys, privateKeysItem);
|
||||||
|
storeOpenPgpKeys(publicKeys, publicKeysItem);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue