aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Brunschwig <[email protected]>2021-12-29 17:01:10 +0100
committerPatrick Brunschwig <[email protected]>2021-12-29 17:01:10 +0100
commit51be0d53d68035f093842512e073e43778a7b583 (patch)
treee8c5f77a1f67304e5b2e9ec9cdc1ae1fa1408ba1
parent2eaeaee8b93637a452d2f5d28396fc809be02e8a (diff)
downloadenigmail-51be0d53d68035f093842512e073e43778a7b583.tar.gz
enigmail-51be0d53d68035f093842512e073e43778a7b583.tar.bz2
enigmail-51be0d53d68035f093842512e073e43778a7b583.zip
moved encryption work to worker
-rw-r--r--package/cryptoAPI/pgpjs-crypto-main.jsm58
-rw-r--r--package/cryptoAPI/pgpjs-crypto-worker.js55
-rw-r--r--package/cryptoAPI/pgpjs-encrypt.jsm25
-rw-r--r--package/cryptoAPI/pgpjs-keystore.jsm4
4 files changed, 118 insertions, 24 deletions
diff --git a/package/cryptoAPI/pgpjs-crypto-main.jsm b/package/cryptoAPI/pgpjs-crypto-main.jsm
index 2ade0037..a391da25 100644
--- a/package/cryptoAPI/pgpjs-crypto-main.jsm
+++ b/package/cryptoAPI/pgpjs-crypto-main.jsm
@@ -129,6 +129,64 @@ var pgpjs_crypto = {
const detailArr = ret.sigDetails.split(/ /);
const dateTime = EnigmailTime.getDateTime(detailArr[2], true, true);
return ret.errorMsg + "\n" + EnigmailLocale.getString("keyAndSigDate", [ret.keyId, dateTime]);
+ },
+
+ /**
+ * Encrypt (and possibly sign) some text data
+ *
+ * @param {String} text: The data to encrypt.
+ * @param {Array<Key>} publicKeys: Array of keys to which to encrypt the message
+ * @param {Key} signingKey: If provided, the message will be signed using that key.
+ * If null, message will not be signed.
+ */
+ encryptData: async function(text, publicKeys, signingKey) {
+ EnigmailLog.DEBUG(`pgpjs-encrypt.jsm: encryptData(${text.length})\n`);
+ const PgpJS = getOpenPGPLibrary();
+
+ let publicKeyPackets = new PgpJS.PacketList();
+ publicKeyPackets = publicKeyPackets.concat(await publicKeys.toPacketList());
+ let armoredPk = PgpJS.armor(PgpJS.enums.armor.publicKey, publicKeyPackets.write());
+
+ let armoredSk = null;
+
+ if (signingKey) {
+ let signingKeyPackets = new PgpJS.PacketList();
+ signingKeyPackets = signingKeyPackets.concat(await signingKey.toPacketList());
+ armoredSk = PgpJS.armor(PgpJS.enums.armor.privateKey, signingKeyPackets.write());
+ }
+
+ let result = await PgpJsWorkerParent.sendMessage("encryptData", {
+ text,
+ encryptionKeys: armoredPk,
+ signingKeys: armoredSk
+ });
+
+ return result;
+ },
+
+ /**
+ * Sign some text data
+ *
+ * @param {String} text: The data to sign.
+ * @param {Key} signingKey: The key used to sign the text.
+ * @param {Boolean} detachedSignature: Create a detached signature (true) or clearsigned message (false).
+ */
+ signData: async function(text, signingKey, detachedSignature) {
+ EnigmailLog.DEBUG(`pgpjs-encrypt.jsm: signData(${text.length})\n`);
+ const PgpJS = getOpenPGPLibrary();
+
+
+ let signingKeyPackets = new PgpJS.PacketList();
+ signingKeyPackets = signingKeyPackets.concat(await signingKey.toPacketList());
+ let armoredSk = PgpJS.armor(PgpJS.enums.armor.privateKey, signingKeyPackets.write());
+
+ let result = await PgpJsWorkerParent.sendMessage("signData", {
+ text,
+ signingKeys: armoredSk,
+ detachedSignature
+ });
+
+ return result;
}
};
diff --git a/package/cryptoAPI/pgpjs-crypto-worker.js b/package/cryptoAPI/pgpjs-crypto-worker.js
index b06d19c6..9be91f66 100644
--- a/package/cryptoAPI/pgpjs-crypto-worker.js
+++ b/package/cryptoAPI/pgpjs-crypto-worker.js
@@ -479,6 +479,61 @@ var workerBody = {
}
return result;
+ },
+
+ encryptData: async function({
+ text,
+ encryptionKeys,
+ signingKeys
+ }) {
+
+ let publicKeys = await PgpJS.readKeys({
+ armoredKeys: encryptionKeys
+ });
+
+ let privateKeys = undefined;
+
+ if (signingKeys) {
+ privateKeys = await PgpJS.readPrivateKeys({
+ armoredKeys: signingKeys
+ });
+ }
+
+ return await PgpJS.encrypt({
+ message: await PgpJS.createMessage({text}),
+ encryptionKeys: publicKeys,
+ signingKeys: privateKeys, // for signing
+ format: "armored"
+ });
+ },
+
+ signData: async function({
+ text,
+ signingKeys,
+ detachedSignature
+ }) {
+ let privateKeys = await PgpJS.readPrivateKeys({
+ armoredKeys: signingKeys
+ });
+
+ if (detachedSignature) {
+ return await PgpJS.sign({
+ message: await PgpJS.createMessage({text}),
+ signingKeys: privateKeys,
+ detached: detachedSignature,
+ format: "armored"
+ });
+ }
+ else {
+ return await PgpJS.sign({
+ message: await PgpJS.createCleartextMessage({text}),
+ signingKeys: privateKeys,
+ detached: detachedSignature,
+ format: "armored"
+ });
+ }
+
+
}
};
diff --git a/package/cryptoAPI/pgpjs-encrypt.jsm b/package/cryptoAPI/pgpjs-encrypt.jsm
index b84bbc52..f5370682 100644
--- a/package/cryptoAPI/pgpjs-encrypt.jsm
+++ b/package/cryptoAPI/pgpjs-encrypt.jsm
@@ -16,6 +16,7 @@ const getOpenPGPLibrary = ChromeUtils.import("chrome://enigmail/content/modules/
const EnigmailConstants = ChromeUtils.import("chrome://enigmail/content/modules/constants.jsm").EnigmailConstants;
const pgpjs_keys = ChromeUtils.import("chrome://enigmail/content/modules/cryptoAPI/pgpjs-keys.jsm").pgpjs_keys;
const pgpjs_keyStore = ChromeUtils.import("chrome://enigmail/content/modules/cryptoAPI/pgpjs-keystore.jsm").pgpjs_keyStore;
+const pgpjs_crypto = ChromeUtils.import("chrome://enigmail/content/modules/cryptoAPI/pgpjs-crypto-main.jsm").pgpjs_crypto;
const EnigmailLocale = ChromeUtils.import("chrome://enigmail/content/modules/locale.jsm").EnigmailLocale;
var gLastKeyDecrypted = null;
@@ -148,12 +149,7 @@ async function encryptData(recipientKeyIds, signingKeyId, text, encryptionFlags)
let uniqueKeyIds = [...new Set(recipientKeyIds)]; // make key IDs unique
let publicKeys = await pgpjs_keyStore.getKeysForKeyIds(false, uniqueKeyIds);
- return await PgpJS.encrypt({
- message: await PgpJS.createMessage({text}),
- encryptionKeys: publicKeys,
- signingKeys: pk.key ? [pk.key] : undefined, // for signing
- format: "armored"
- });
+ return pgpjs_crypto.encryptData(text, publicKeys, pk.key);
}
/**
@@ -183,22 +179,7 @@ async function signData(signingKeyId, text, detachedSignature, encryptionFlags)
throw Error("No password provided");
}
- if (detachedSignature) {
- return await PgpJS.sign({
- message: await PgpJS.createMessage({text}),
- signingKeys: [pk.key],
- detached: detachedSignature,
- format: "armored"
- });
- }
- else {
- return await PgpJS.sign({
- message: await PgpJS.createCleartextMessage({text}),
- signingKeys: [pk.key],
- detached: detachedSignature,
- format: "armored"
- });
- }
+ return pgpjs_crypto.signData(text, pk.key, detachedSignature);
}
/**
diff --git a/package/cryptoAPI/pgpjs-keystore.jsm b/package/cryptoAPI/pgpjs-keystore.jsm
index b76e4cb4..a25e6263 100644
--- a/package/cryptoAPI/pgpjs-keystore.jsm
+++ b/package/cryptoAPI/pgpjs-keystore.jsm
@@ -391,10 +391,10 @@ var pgpjs_keyStore = {
}
returnArray.toPacketList = function() {
- let pktList = new PgpJS.packet.List();
+ let pktList = new PgpJS.PacketList();
for (let i = 0; i < this.length; i++) {
- pktList.concat(this[i].toPacketList());
+ pktList = pktList.concat(this[i].toPacketList());
}
return pktList;