aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Brunschwig <[email protected]>2022-01-04 19:02:03 +0100
committerPatrick Brunschwig <[email protected]>2022-01-04 19:02:03 +0100
commitae37aedf2fdeb84cef88b3f619735884bdd8d85f (patch)
tree434e56d442cc8a93661d52fe05b040a755f5867f
parent08905dc84edbf0d20ba6f4ffbba733f2d9ec3e02 (diff)
downloadenigmail-ae37aedf2fdeb84cef88b3f619735884bdd8d85f.tar.gz
enigmail-ae37aedf2fdeb84cef88b3f619735884bdd8d85f.tar.bz2
enigmail-ae37aedf2fdeb84cef88b3f619735884bdd8d85f.zip
fixed handling special cases such as unavailable public keys
-rw-r--r--package/cryptoAPI/pgpjs-crypto-main.jsm12
-rw-r--r--package/cryptoAPI/pgpjs-crypto-worker.js129
-rw-r--r--package/cryptoAPI/pgpjs-keystore.jsm10
3 files changed, 92 insertions, 59 deletions
diff --git a/package/cryptoAPI/pgpjs-crypto-main.jsm b/package/cryptoAPI/pgpjs-crypto-main.jsm
index 634abe6c..131a5b09 100644
--- a/package/cryptoAPI/pgpjs-crypto-main.jsm
+++ b/package/cryptoAPI/pgpjs-crypto-main.jsm
@@ -273,7 +273,7 @@ var WorkerRequestHandler = {
return PgpJS.armor(PgpJS.enums.armor.privateKey, packets.write());
}
- return null;
+ return "";
},
downloadMissingKeys: async function(keyIds) {
@@ -298,7 +298,11 @@ var WorkerRequestHandler = {
}
catch (x) {}
- return PgpJS.armor(PgpJS.enums.armor.publicKey, packets.write());
+ if (packets.length > 0) {
+ return PgpJS.armor(PgpJS.enums.armor.publicKey, packets.write());
+ }
+ else
+ return "";
},
getKeydesc: function (pubKeyIds) {
@@ -370,7 +374,7 @@ cryptoWorker.onmessage = async function(e) {
}
}
else {
- EnigmailLog.ERROR(`pgpjs-crypto-worker.jsm. onmessage: Unknown function call ${e.data.func} received from worker\n`);
+ EnigmailLog.ERROR(`pgpjs-crypto-worker.jsm: onmessage: Unknown function call ${e.data.func} received from worker\n`);
}
return;
}
@@ -380,7 +384,7 @@ cryptoWorker.onmessage = async function(e) {
pendingPromises[e.data.trxId].resolve(e.data.result);
}
else {
- EnigmailLog.ERROR(`${e.data.error}\n`);
+ EnigmailLog.ERROR(`pgpjs-crypto-worker.jsm: onmessage: ${e.data.error}\n`);
pendingPromises[e.data.trxId].reject(e.data.error);
}
delete pendingPromises[e.data.trxId];
diff --git a/package/cryptoAPI/pgpjs-crypto-worker.js b/package/cryptoAPI/pgpjs-crypto-worker.js
index 1a4bfcff..e71caea3 100644
--- a/package/cryptoAPI/pgpjs-crypto-worker.js
+++ b/package/cryptoAPI/pgpjs-crypto-worker.js
@@ -105,6 +105,7 @@ var workerBody = {
const retData = getReturnObj();
let encToDetails = "";
+ let secretKeys = [];
try {
encToDetails = await requestMessage("getKeydesc", pubKeyIds);
@@ -112,13 +113,14 @@ var workerBody = {
// get OpenPGP.js key objects for secret keys
let armoredSecretKeys = await requestMessage("getSecretKeysForIds", pubKeyIds);
- let secretKeys = await PgpJS.readKeys({
- armoredKeys: armoredSecretKeys
- });
-
- if (secretKeys.length === 0) {
+ if (armoredSecretKeys.length === 0) {
retData.statusFlags |= EnigmailConstants.NO_SECKEY;
}
+ else {
+ secretKeys = await PgpJS.readKeys({
+ armoredKeys: armoredSecretKeys
+ });
+ }
// try to decrypt the message using the secret keys one-by-one
for (let sk of secretKeys) {
@@ -127,11 +129,11 @@ var workerBody = {
decryptionReason: EnigmailConstants.KEY_DECRYPT_REASON_ENCRYPTED_MSG
});
- let secKey = await PgpJS.readKeys({
- armoredKeys: decryptedSecKey
- });
+ if (decryptedSecKey.length > 0) {
+ let secKey = await PgpJS.readKeys({
+ armoredKeys: decryptedSecKey
+ });
- if (secKey) {
secKey.revocationSignatures = []; // remove revocation sigs to allow decryption
let result = await PgpJS.decrypt({
message: message,
@@ -249,39 +251,47 @@ var workerBody = {
signature,
returnData = false
}) {
- DEBUG_LOG(`verifyDetached(${data}, ${signature})\n`);
+ DEBUG_LOG(`verifyDetached(${data.length}, ${signature.length})\n`);
+ try {
+ let sigString;
- let sigString;
+ if (typeof(signature) === "string") {
+ sigString = signature;
+ }
+ else {
+ sigString = await PgpJS.armor(PgpJS.enums.armor.signature, signature.write());
+ }
- if (typeof(signature) === "string") {
- sigString = signature;
- }
- else {
- sigString = await PgpJS.armor(PgpJS.enums.armor.signature, signature.write());
- }
+ // if (sigString.packets.length === 0) {
+ // result.exitCode = 1;
+ // result.statusFlags = EnigmailConstants.NO_PUBKEY;
+ // result.errorMsg = EnigmailLocale.getString("unverifiedSig") + EnigmailLocale.getString("msgTypeUnsupported");
+ // return result;
+ // }
+
+ let msg;
+ if (typeof(data) === "string") {
+ msg = await PgpJS.createMessage({
+ text: data
+ });
+ }
+ else {
+ msg = await PgpJS.createMessage({
+ binary: data
+ });
+ }
- // if (sigString.packets.length === 0) {
- // result.exitCode = 1;
- // result.statusFlags = EnigmailConstants.NO_PUBKEY;
- // result.errorMsg = EnigmailLocale.getString("unverifiedSig") + EnigmailLocale.getString("msgTypeUnsupported");
- // return result;
- // }
-
- let msg;
- if (typeof(data) === "string") {
- msg = await PgpJS.createMessage({
- text: data
- });
+ await msg.appendSignature(sigString);
+
+ return this.verifyMessage(msg, returnData);
}
- else {
- msg = await PgpJS.createMessage({
- binary: data
- });
+ catch (ex) {
+ return {
+ exitCode: 1,
+ statusFlags: EnigmailConstants.NO_PUBKEY,
+ errorMsg: ex.toString()
+ };
}
-
- await msg.appendSignature(sigString);
-
- return this.verifyMessage(msg, returnData);
},
/**
@@ -326,6 +336,11 @@ var workerBody = {
armoredPubKeys = await requestMessage("downloadMissingKeys", keyIds);
}
+ if (armoredPubKeys.length === 0) {
+ result.keyId = keyIds[0];
+ return result;
+ }
+
let pubKeys = await PgpJS.readKeys({
armoredKeys: armoredPubKeys
});
@@ -499,7 +514,9 @@ var workerBody = {
}
return await PgpJS.encrypt({
- message: await PgpJS.createMessage({text}),
+ message: await PgpJS.createMessage({
+ text
+ }),
encryptionKeys: publicKeys,
signingKeys: privateKeys, // for signing
format: "armored"
@@ -515,22 +532,26 @@ var workerBody = {
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"
- });
- }
+ 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-keystore.jsm b/package/cryptoAPI/pgpjs-keystore.jsm
index 1aa9d890..4660650c 100644
--- a/package/cryptoAPI/pgpjs-keystore.jsm
+++ b/package/cryptoAPI/pgpjs-keystore.jsm
@@ -269,6 +269,10 @@ var pgpjs_keyStore = {
const PgpJS = getOpenPGPLibrary();
let keyList = await this.readKeys(keyArr);
+ if (keyList.length === 0) {
+ return "";
+ }
+
let packets = new PgpJS.PacketList();
for (let i in keyList) {
@@ -314,7 +318,7 @@ var pgpjs_keyStore = {
/**
* Export secret key(s) as ASCII armored data
*
- * @param {String} keyArr Specification by fingerprint or keyID, separate mutliple keys with spaces
+ * @param {String} keyArr Specification by fingerprint or keyID, separate mutliple keys with spaces
* @param {Boolean} minimalKey if true, reduce key to minimum required
*
* @return {Object}:
@@ -329,6 +333,10 @@ var pgpjs_keyStore = {
const PgpJS = getOpenPGPLibrary();
let keyList = await this.readKeys(keyArr);
+ if (keyList.length === 0) {
+ return "";
+ }
+
let packets = new PgpJS.PacketList();
for (let k of keyList) {