mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Support Internationalized Domain Names in OpenPGP
This commit is contained in:
parent
696a2bbd3c
commit
ca249bcced
3 changed files with 15 additions and 11 deletions
|
|
@ -17,7 +17,7 @@ const
|
||||||
keys.find(key =>
|
keys.find(key =>
|
||||||
// key[sign ? 'can_sign' : 'can_decrypt']
|
// key[sign ? 'can_sign' : 'can_decrypt']
|
||||||
(key.can_sign || key.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 {
|
export const GnuPGUserStore = new class {
|
||||||
|
|
@ -46,6 +46,7 @@ export const GnuPGUserStore = new class {
|
||||||
key.fingerprint = key.subkeys[0].fingerprint;
|
key.fingerprint = key.subkeys[0].fingerprint;
|
||||||
key.uids.forEach(uid => uid.email && aEmails.push(uid.email));
|
key.uids.forEach(uid => uid.email && aEmails.push(uid.email));
|
||||||
key.emails = aEmails;
|
key.emails = aEmails;
|
||||||
|
key.for = email => aEmails.includes(IDN.toASCII(email));
|
||||||
key.askDelete = ko.observable(false);
|
key.askDelete = ko.observable(false);
|
||||||
key.openForDeletion = ko.observable(null).askDeleteHelper();
|
key.openForDeletion = ko.observable(null).askDeleteHelper();
|
||||||
key.remove = () => {
|
key.remove = () => {
|
||||||
|
|
@ -149,7 +150,7 @@ export const GnuPGUserStore = new class {
|
||||||
const count = recipients.length,
|
const count = recipients.length,
|
||||||
length = count ? recipients.filter(email =>
|
length = count ? recipients.filter(email =>
|
||||||
// (key.can_verify || key.can_encrypt) &&
|
// (key.can_verify || key.can_encrypt) &&
|
||||||
this.publicKeys.find(key => key.emails.includes(email))
|
this.publicKeys.find(key => key.for(email))
|
||||||
).length : 0;
|
).length : 0;
|
||||||
return length && length === count;
|
return length && length === count;
|
||||||
}
|
}
|
||||||
|
|
@ -157,7 +158,7 @@ export const GnuPGUserStore = new class {
|
||||||
getPublicKeyFingerprints(recipients) {
|
getPublicKeyFingerprints(recipients) {
|
||||||
const fingerprints = [];
|
const fingerprints = [];
|
||||||
recipients.forEach(email => {
|
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;
|
return fingerprints;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import { Passphrases } from 'Storage/Passphrases';
|
||||||
const
|
const
|
||||||
findOpenPGPKey = (keys, query/*, sign*/) =>
|
findOpenPGPKey = (keys, query/*, sign*/) =>
|
||||||
keys.find(key =>
|
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') => {
|
decryptKey = async (privateKey, btnTxt = 'SIGN') => {
|
||||||
|
|
@ -81,7 +81,7 @@ class OpenPgpKeyModel {
|
||||||
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 = 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.armor = armor;
|
||||||
this.askDelete = ko.observable(false);
|
this.askDelete = ko.observable(false);
|
||||||
this.openForDeletion = ko.observable(null).askDeleteHelper();
|
this.openForDeletion = ko.observable(null).askDeleteHelper();
|
||||||
|
|
@ -94,9 +94,12 @@ class OpenPgpKeyModel {
|
||||||
get fingerprint() { return this.key.getFingerprint(); }
|
get fingerprint() { return this.key.getFingerprint(); }
|
||||||
get can_encrypt() { return !!this.key.getEncryptionKey(); }
|
get can_encrypt() { return !!this.key.getEncryptionKey(); }
|
||||||
get can_sign() { return !!this.key.getSigningKey(); }
|
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(); }
|
get armor() { return this.key.armor(); }
|
||||||
*/
|
*/
|
||||||
|
for(email) {
|
||||||
|
return this.emails.includes(IDN.toASCII(email));
|
||||||
|
}
|
||||||
|
|
||||||
view() {
|
view() {
|
||||||
showScreenPopup(OpenPgpKeyPopupView, [this]);
|
showScreenPopup(OpenPgpKeyPopupView, [this]);
|
||||||
|
|
@ -196,7 +199,7 @@ export const OpenPGPUserStore = new class {
|
||||||
hasPublicKeyForEmails(recipients) {
|
hasPublicKeyForEmails(recipients) {
|
||||||
const count = recipients.length,
|
const count = recipients.length,
|
||||||
length = count ? recipients.filter(email =>
|
length = count ? recipients.filter(email =>
|
||||||
this.publicKeys().find(key => key.emails.includes(email))
|
this.publicKeys().find(key => key.for(email))
|
||||||
).length : 0;
|
).length : 0;
|
||||||
return length && length === count;
|
return length && length === count;
|
||||||
}
|
}
|
||||||
|
|
@ -246,7 +249,7 @@ export const OpenPGPUserStore = new class {
|
||||||
*/
|
*/
|
||||||
async verify(message) {
|
async verify(message) {
|
||||||
const data = message.pgpSigned(), // { partId: "1", sigPartId: "2", micAlg: "pgp-sha256" }
|
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) {
|
if (data && publicKey) {
|
||||||
data.folder = message.folder;
|
data.folder = message.folder;
|
||||||
data.uid = message.uid;
|
data.uid = message.uid;
|
||||||
|
|
@ -305,7 +308,7 @@ export const OpenPGPUserStore = new class {
|
||||||
*/
|
*/
|
||||||
async encrypt(text, recipients, signPrivateKey) {
|
async encrypt(text, recipients, signPrivateKey) {
|
||||||
const count = recipients.length;
|
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 (count === recipients.length) {
|
||||||
if (signPrivateKey) {
|
if (signPrivateKey) {
|
||||||
signPrivateKey = await decryptKey(signPrivateKey);
|
signPrivateKey = await decryptKey(signPrivateKey);
|
||||||
|
|
|
||||||
|
|
@ -128,12 +128,12 @@ export const
|
||||||
let result = {};
|
let result = {};
|
||||||
recipients.forEach(email => {
|
recipients.forEach(email => {
|
||||||
OpenPGPUserStore.publicKeys().forEach(key => {
|
OpenPGPUserStore.publicKeys().forEach(key => {
|
||||||
if (key.emails.includes(email)) {
|
if (key.for(email)) {
|
||||||
result[email] = key.armor;
|
result[email] = key.armor;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
GnuPGUserStore.publicKeys.map(async key => {
|
GnuPGUserStore.publicKeys.map(async key => {
|
||||||
if (!result[email] && key.emails.includes(email)) {
|
if (!result[email] && key.for(email)) {
|
||||||
result[email] = await key.fetch();
|
result[email] = await key.fetch();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue