#89 verify detached signature using GnuPG

This commit is contained in:
the-djmaze 2022-02-02 14:36:49 +01:00
parent 08ea226dbe
commit 93db6e6e0e
6 changed files with 82 additions and 71 deletions

View file

@ -184,7 +184,21 @@ export const GnuPGUserStore = new class {
}
}
verify(/*message, fCallback*/) {
async verify(message) {
let data = message.pgpSigned(); // { BodyPartId: "1", SigPartId: "2", MicAlg: "pgp-sha256" }
if (data) {
// const sender = message.from[0].email;
// let mode = await this.hasPublicKeyForEmails([sender]);
data.Folder = message.folder;
data.Uid = message.uid;
let response = await Remote.post('MessagePgpVerify', null, data);
if (response && response.Result) {
return {
fingerprint: response.Result.fingerprint,
success: 0 == response.Result.status // GOODSIG
};
}
}
}
};

View file

@ -175,6 +175,47 @@ export const PgpUserStore = new class {
return GnuPGUserStore.decrypt(message);
}
async verify(message) {
const plain = message.plain();
if (/-----BEGIN PGP SIGNED MESSAGE-----/.test(plain) && /-----BEGIN PGP SIGNATURE-----/.test(plain)) {
let result = await OpenPGPUserStore.verify(plain);
console.dir(result);
}
if (message.pgpSigned()) {
const sender = message.from[0].email;
let mode = await this.hasPublicKeyForEmails([sender]);
if ('gnupg' === mode) {
return GnuPGUserStore.verify(message);
}
if ('openpgp' === mode) {
const publicKey = OpenPGPUserStore.getPublicKeyFor(sender);
OpenPGPUserStore.verify(plain, null/*detachedSignature*/, publicKey).then(result => {
if (result) {
message.plain(result.data);
message.viewPlain();
console.dir({signatures:result.signatures});
}
/*
if (validKey) {
i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', {
USER: validKey.user + ' (' + validKey.id + ')'
});
message.getText()
} else {
const keyIds = arrayLength(signingKeyIds) ? signingKeyIds : null,
additional = keyIds
? keyIds.map(item => (item && item.toHex ? item.toHex() : null)).filter(v => v).join(', ')
: '';
i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') + (additional ? ' (' + additional + ')' : '');
}
*/
});
}
}
}
/**
* Creates an iframe with an editor for a new encrypted mail.
* The iframe will be injected into the container identified by selector.