diff --git a/dev/Stores/User/GnuPG.js b/dev/Stores/User/GnuPG.js index 66a7ad2a5..174686d9d 100644 --- a/dev/Stores/User/GnuPG.js +++ b/dev/Stores/User/GnuPG.js @@ -17,7 +17,7 @@ const keys.find(key => // key[sign ? 'can_sign' : 'can_decrypt'] (key.can_sign || key.can_decrypt) - && (key.emails.includes(query) || key.subkeys.find(key => query == key.keyid || query == key.fingerprint)) + && (key.for(query) || key.subkeys.find(key => query == key.keyid || query == key.fingerprint)) ); export const GnuPGUserStore = new class { @@ -46,6 +46,7 @@ export const GnuPGUserStore = new class { key.fingerprint = key.subkeys[0].fingerprint; key.uids.forEach(uid => uid.email && aEmails.push(uid.email)); key.emails = aEmails; + key.for = email => aEmails.includes(IDN.toASCII(email)); key.askDelete = ko.observable(false); key.openForDeletion = ko.observable(null).askDeleteHelper(); key.remove = () => { @@ -149,7 +150,7 @@ export const GnuPGUserStore = new class { const count = recipients.length, length = count ? recipients.filter(email => // (key.can_verify || key.can_encrypt) && - this.publicKeys.find(key => key.emails.includes(email)) + this.publicKeys.find(key => key.for(email)) ).length : 0; return length && length === count; } @@ -157,7 +158,7 @@ export const GnuPGUserStore = new class { getPublicKeyFingerprints(recipients) { const fingerprints = []; recipients.forEach(email => { - fingerprints.push(this.publicKeys.find(key => key.emails.includes(email)).fingerprint); + fingerprints.push(this.publicKeys.find(key => key.for(email)).fingerprint); }); return fingerprints; } diff --git a/dev/Stores/User/OpenPGP.js b/dev/Stores/User/OpenPGP.js index 68603f528..1a66dd137 100644 --- a/dev/Stores/User/OpenPGP.js +++ b/dev/Stores/User/OpenPGP.js @@ -16,7 +16,7 @@ import { Passphrases } from 'Storage/Passphrases'; const findOpenPGPKey = (keys, query/*, sign*/) => keys.find(key => - key.emails.includes(query) || query == key.id || query == key.fingerprint + key.for(query) || query == key.id || query == key.fingerprint ), decryptKey = async (privateKey, btnTxt = 'SIGN') => { @@ -81,7 +81,7 @@ class OpenPgpKeyModel { this.fingerprint = key.getFingerprint(); this.can_encrypt = !!key.getEncryptionKey(); this.can_sign = !!key.getSigningKey(); - this.emails = key.users.map(user => user.userID.email).filter(email => email); + this.emails = key.users.map(user => IDN.toASCII(user.userID.email)).filter(email => email); this.armor = armor; this.askDelete = ko.observable(false); this.openForDeletion = ko.observable(null).askDeleteHelper(); @@ -94,9 +94,12 @@ class OpenPgpKeyModel { 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 emails() { return this.key.users.map(user => IDN.toASCII(user.userID.email)).filter(email => email); } get armor() { return this.key.armor(); } */ + for(email) { + return this.emails.includes(IDN.toASCII(email)); + } view() { showScreenPopup(OpenPgpKeyPopupView, [this]); @@ -196,7 +199,7 @@ export const OpenPGPUserStore = new class { hasPublicKeyForEmails(recipients) { const count = recipients.length, length = count ? recipients.filter(email => - this.publicKeys().find(key => key.emails.includes(email)) + this.publicKeys().find(key => key.for(email)) ).length : 0; return length && length === count; } @@ -246,7 +249,7 @@ export const OpenPGPUserStore = new class { */ async verify(message) { const data = message.pgpSigned(), // { partId: "1", sigPartId: "2", micAlg: "pgp-sha256" } - publicKey = this.publicKeys().find(key => key.emails.includes(message.from[0].email)); + publicKey = this.publicKeys().find(key => key.for(message.from[0].email)); if (data && publicKey) { data.folder = message.folder; data.uid = message.uid; @@ -305,7 +308,7 @@ export const OpenPGPUserStore = new class { */ async encrypt(text, recipients, signPrivateKey) { const count = recipients.length; - recipients = recipients.map(email => this.publicKeys().find(key => key.emails.includes(email))).filter(key => key); + recipients = recipients.map(email => this.publicKeys().find(key => key.for(email))).filter(key => key); if (count === recipients.length) { if (signPrivateKey) { signPrivateKey = await decryptKey(signPrivateKey); diff --git a/dev/Stores/User/Pgp.js b/dev/Stores/User/Pgp.js index 006da3cc1..8b56a83ca 100644 --- a/dev/Stores/User/Pgp.js +++ b/dev/Stores/User/Pgp.js @@ -128,12 +128,12 @@ export const let result = {}; recipients.forEach(email => { OpenPGPUserStore.publicKeys().forEach(key => { - if (key.emails.includes(email)) { + if (key.for(email)) { result[email] = key.armor; } }); GnuPGUserStore.publicKeys.map(async key => { - if (!result[email] && key.emails.includes(email)) { + if (!result[email] && key.for(email)) { result[email] = await key.fetch(); } });