Improved signing messages by allowing to choose between the options

This commit is contained in:
the-djmaze 2024-05-28 17:50:56 +02:00
parent c2e558c9b1
commit 6d15cabfe5

View file

@ -500,7 +500,7 @@ export class ComposePopupView extends AbstractViewPopup {
this.sendError(true);
this.sendErrorDesc(
getNotification(iError, data?.ErrorMessage, Notifications.CantSendMessage)
+ "\n" + data?.ErrorMessageAdditional
+ "\n" + (data?.ErrorMessageAdditional || data?.ErrorMessage)
);
};
try {
@ -535,9 +535,13 @@ export class ComposePopupView extends AbstractViewPopup {
}
this.savedErrorDesc(msg);
} else {
params.signPassphrase && Passphrases.delete(identity);
this.sendError(true);
sendFailed(iError, data);
// Remove remembered passphrase as it could be wrong
let key = ('S/MIME' === params.sign) ? identity : null;
params.signFingerprint
&& this.signOptions.forEach(option => ('GnuPG' === option[0]) && (key = option[1]));
key && Passphrases.delete(key);
}
} else {
if (arrayLength(this.aDraftInfo) > 0) {
@ -1546,12 +1550,11 @@ export class ComposePopupView extends AbstractViewPopup {
alternative.children.push(data);
data = alternative;
}
let sign = true;
let isSigned = false;
for (let i = 0; i < signOptions.length; ++i) {
if ('OpenPGP' == signOptions[i][0]) {
try {
// Doesn't sign attachments
params.html = params.plain = '';
let signed = new MimePart;
signed.headers['Content-Type'] =
'multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"';
@ -1562,6 +1565,8 @@ export class ComposePopupView extends AbstractViewPopup {
signature.headers['Content-Transfer-Encoding'] = '7Bit';
signature.body = await OpenPGPUserStore.sign(data.toString(), signOptions[i][1], 1);
signed.children.push(signature);
isSigned = true;
params.html = params.plain = '';
params.signed = signed.toString();
params.boundary = signed.boundary;
data = signed;
@ -1569,13 +1574,11 @@ export class ComposePopupView extends AbstractViewPopup {
Object.entries(PgpUserStore.getPublicKeyOfEmails([getEmail(this.from())]) || {})
.forEach(([k,v]) => params.publicKey = v);
*/
break;
} catch (e) {
sign = false;
console.error(e);
}
break;
}
if ('GnuPG' == signOptions[i][0]) {
} else if ('GnuPG' == signOptions[i][0]) {
// TODO: sign in PHP fails
let pass = await GnuPGUserStore.sign(signOptions[i][1]);
if (null != pass) {
@ -1583,12 +1586,10 @@ export class ComposePopupView extends AbstractViewPopup {
params.signFingerprint = signOptions[i][1].fingerprint;
params.signPassphrase = pass;
// params.attachPublicKey = false;
} else {
sign = false;
}
isSigned = true;
break;
}
if ('S/MIME' == signOptions[i][0]) {
} else if ('S/MIME' == signOptions[i][0]) {
// TODO: sign in PHP fails
params.sign = 'S/MIME';
// params.signCertificate = identity.smimeCertificate();
@ -1602,13 +1603,12 @@ export class ComposePopupView extends AbstractViewPopup {
if (null != pass) {
params.signPassphrase = pass.password;
pass.remember && Passphrases.handle(identity, pass.password);
} else {
sign = false;
isSigned = true;
}
}
}
}
if (signOptions.length && !sign) {
if (signOptions.length && !isSigned) {
throw 'Signing failed';
}