mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-28 19:49:20 +03:00
Added: GnuPG encrypt (sign still fails)
This commit is contained in:
parent
f3717815e1
commit
8fff6fa759
11 changed files with 196 additions and 91 deletions
|
|
@ -150,12 +150,16 @@ export const GnuPGUserStore = new class {
|
|||
return length && length === count;
|
||||
}
|
||||
|
||||
getPrivateKeyFor(query, sign) {
|
||||
return findGnuPGKey(this.privateKeys, query, sign);
|
||||
getPublicKeyFingerprints(recipients) {
|
||||
const fingerprints = [];
|
||||
recipients.forEach(email => {
|
||||
fingerprints.push(this.publicKeys.find(key => key.emails.includes(email)).fingerprint);
|
||||
});
|
||||
return fingerprints;
|
||||
}
|
||||
|
||||
getPublicKeyFor(query, sign) {
|
||||
return findGnuPGKey(this.publicKeys, query, sign);
|
||||
getPrivateKeyFor(query, sign) {
|
||||
return findGnuPGKey(this.privateKeys, query, sign);
|
||||
}
|
||||
|
||||
async decrypt(message) {
|
||||
|
|
@ -207,12 +211,8 @@ export const GnuPGUserStore = new class {
|
|||
}
|
||||
}
|
||||
|
||||
async sign(/*text, privateKey, detached*/) {
|
||||
throw 'Sign failed';
|
||||
}
|
||||
|
||||
async encrypt(/*text, recipients, signPrivateKey*/) {
|
||||
throw 'Encrypt failed';
|
||||
async sign(privateKey) {
|
||||
return await askPassphrase(privateKey);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -161,10 +161,6 @@ export const OpenPGPUserStore = new class {
|
|||
return findOpenPGPKey(this.privateKeys, query/*, sign*/);
|
||||
}
|
||||
|
||||
getPublicKeyFor(query/*, sign*/) {
|
||||
return findOpenPGPKey(this.publicKeys, query/*, sign*/);
|
||||
}
|
||||
|
||||
/**
|
||||
* https://docs.openpgpjs.org/#encrypt-and-decrypt-string-data-with-pgp-keys
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -91,12 +91,12 @@ export const PgpUserStore = new class {
|
|||
async hasPublicKeyForEmails(recipients) {
|
||||
const count = recipients.length;
|
||||
if (count) {
|
||||
if (OpenPGPUserStore.hasPublicKeyForEmails(recipients)) {
|
||||
return 'openpgp';
|
||||
}
|
||||
if (GnuPGUserStore.hasPublicKeyForEmails(recipients)) {
|
||||
return 'gnupg';
|
||||
}
|
||||
if (OpenPGPUserStore.hasPublicKeyForEmails(recipients)) {
|
||||
return 'openpgp';
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ export const PgpUserStore = new class {
|
|||
* Returns the first library that can.
|
||||
*/
|
||||
async getKeyForSigning(email) {
|
||||
/*
|
||||
/* // TODO: sign in PHP fails
|
||||
let key = GnuPGUserStore.getPrivateKeyFor(email, 1);
|
||||
if (key) {
|
||||
return ['gnupg', key];
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import { AccountUserStore } from 'Stores/User/Account';
|
|||
import { FolderUserStore } from 'Stores/User/Folder';
|
||||
import { PgpUserStore } from 'Stores/User/Pgp';
|
||||
import { OpenPGPUserStore } from 'Stores/User/OpenPGP';
|
||||
import { GnuPGUserStore } from 'Stores/User/GnuPG';
|
||||
import { MessageUserStore } from 'Stores/User/Message';
|
||||
|
||||
import Remote from 'Remote/User/Fetch';
|
||||
|
|
@ -407,15 +408,12 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
params.Encrypted = draft
|
||||
? await this.mailvelope.createDraft()
|
||||
: await this.mailvelope.encrypt(recipients);
|
||||
} else if (encrypt || sign) {
|
||||
} else if ('openpgp' == encrypt || (sign && 'openpgp' == sign[0])) {
|
||||
let data = new MimePart;
|
||||
data.headers['Content-Type'] = 'text/'+(TextIsHtml?'html':'plain')+'; charset="utf-8"';
|
||||
data.headers['Content-Transfer-Encoding'] = 'base64';
|
||||
data.body = base64_encode(Text);
|
||||
if (sign && sign[1]) {
|
||||
if ('openpgp' != sign[0]) {
|
||||
throw 'Signing with ' + sign[0] + ' not yet implemented';
|
||||
}
|
||||
let signed = new MimePart;
|
||||
signed.headers['Content-Type'] =
|
||||
'multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"';
|
||||
|
|
@ -429,13 +427,26 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
data = signed;
|
||||
}
|
||||
if (encrypt) {
|
||||
if ('openpgp' != encrypt) {
|
||||
throw 'Encryption with ' + encrypt + ' not yet implemented';
|
||||
}
|
||||
params.Encrypted = await OpenPGPUserStore.encrypt(data.toString(), recipients);
|
||||
} else {
|
||||
params.Signed = data.toString();
|
||||
}
|
||||
} else if ('gnupg' == encrypt || (sign && 'gnupg' == sign[0])) {
|
||||
params.Html = TextIsHtml ? Text : '';
|
||||
params.Text = TextIsHtml ? '' : Text;
|
||||
/* // TODO: sign in PHP fails
|
||||
if (sign) {
|
||||
params.SignFingerprint = sign[1].fingerprint;
|
||||
params.SignPassphrase = await GnuPGUserStore.sign(sign[1]);
|
||||
}
|
||||
*/
|
||||
if (encrypt) {
|
||||
params.EncryptFingerprints = GnuPGUserStore.getPublicKeyFingerprints(recipients).join(',');
|
||||
}
|
||||
} else if (encrypt) {
|
||||
throw 'Encryption with ' + encrypt + ' not yet implemented';
|
||||
} else if (sign) {
|
||||
throw 'Signing with ' + sign[0] + ' not yet implemented';
|
||||
} else {
|
||||
params.Html = TextIsHtml ? Text : '';
|
||||
params.Text = TextIsHtml ? '' : Text;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue