mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-02-24 06:47:05 +08:00
#89 OpenPGP.js sign cleartext
This commit is contained in:
parent
66340614b5
commit
f625abe0b2
3 changed files with 52 additions and 26 deletions
|
@ -236,4 +236,21 @@ export const OpenPGPUserStore = new class {
|
|||
}
|
||||
}
|
||||
|
||||
async signCleartext(text, privateKey) {
|
||||
const passphrase = prompt('OpenPGP.js Passphrase for ' + privateKey.id + ' ' + privateKey.emails[0]);
|
||||
if (null !== passphrase) {
|
||||
privateKey = await openpgp.decryptKey({
|
||||
privateKey: privateKey.key,
|
||||
passphrase
|
||||
});
|
||||
const unsignedMessage = await openpgp.createCleartextMessage({ text: text });
|
||||
return await openpgp.sign({
|
||||
message: unsignedMessage, // CleartextMessage or Message object
|
||||
signingKeys: privateKey
|
||||
// detached: false
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -106,17 +106,18 @@ export const PgpUserStore = new class {
|
|||
* Returns the first library that can.
|
||||
*/
|
||||
async getKeyForSigning(email) {
|
||||
/*
|
||||
let key = GnuPGUserStore.getPrivateKeyFor(email, 1);
|
||||
if (key) {
|
||||
return ['gnupg', key];
|
||||
}
|
||||
|
||||
key = OpenPGPUserStore.getPrivateKeyFor(email, 1);
|
||||
*/
|
||||
let key = OpenPGPUserStore.getPrivateKeyFor(email, 1);
|
||||
if (key) {
|
||||
return ['openpgp', key];
|
||||
}
|
||||
|
||||
return await this.getMailvelopePrivateKeyFor(email, 1);
|
||||
// return await this.getMailvelopePrivateKeyFor(email, 1);
|
||||
}
|
||||
|
||||
async decrypt(message) {
|
||||
|
|
|
@ -282,7 +282,7 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
this.canPgpSign(false);
|
||||
value && PgpUserStore.getKeyForSigning(value.email()).then(result => {
|
||||
console.log({canPgpSign:result});
|
||||
this.canPgpSign(!!result)
|
||||
this.canPgpSign(result)
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -405,7 +405,7 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
|
||||
if (!sSentFolder) {
|
||||
showScreenPopup(FolderSystemPopupView, [SetSystemFoldersNotification.Sent]);
|
||||
} else {
|
||||
} else try {
|
||||
this.sendError(false);
|
||||
this.sending(true);
|
||||
|
||||
|
@ -452,28 +452,30 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
30000
|
||||
);
|
||||
|
||||
let pgpPromise = null,
|
||||
cfg = {
|
||||
data: params.Text,
|
||||
};
|
||||
if ('openpgp' == sign) {
|
||||
let privateKey, sender = this.currentIdentity().email();
|
||||
try {
|
||||
const key = OpenPGPUserStore.getPrivateKeyFor(sender);
|
||||
if (key) {
|
||||
key.decrypt(window.prompt('Passphrase'));
|
||||
cfg.privateKey = privateKey = key;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
privateKey = null;
|
||||
}
|
||||
if (!privateKey) {
|
||||
this.sendError(true);
|
||||
this.sendErrorDesc(i18n('PGP_NOTIFICATIONS/NO_PRIVATE_KEY_FOUND_FOR', { EMAIL: sender }));
|
||||
return;
|
||||
}
|
||||
if (encrypt) {
|
||||
throw 'Encryption not yet implemented';
|
||||
}
|
||||
if (sign && 'openpgp' != sign[0]) {
|
||||
throw 'Signing with ' + sign[0] + ' not yet implemented';
|
||||
}
|
||||
if (sign && 'openpgp' == sign[0]) {
|
||||
if (params.TextIsHtml) {
|
||||
throw i18n('PGP_NOTIFICATIONS/PGP_ERROR', { ERROR: "Can't sign HTML" });
|
||||
}
|
||||
OpenPGPUserStore.signCleartext(params.Text, sign[1]).then(text => {
|
||||
if (text) {
|
||||
params.Text = text;
|
||||
send();
|
||||
} else {
|
||||
this.sendError(true);
|
||||
this.sendErrorDesc(i18n('PGP_NOTIFICATIONS/PGP_ERROR', { ERROR: 'Signing failed' }));
|
||||
this.sending(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
send();
|
||||
}
|
||||
/*
|
||||
if (encrypt && sign && encrypt != sign) {
|
||||
// error 'sign and encrypt must be same engine';
|
||||
} else if ('openpgp' == encrypt) {
|
||||
|
@ -498,6 +500,12 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
this.sendErrorDesc(i18n('PGP_NOTIFICATIONS/PGP_ERROR', { ERROR: '' + e }));
|
||||
})
|
||||
: send();
|
||||
*/
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.sendError(true);
|
||||
this.sendErrorDesc(e);
|
||||
this.sending(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue