aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Brunschwig <[email protected]>2022-01-02 17:49:33 +0100
committerPatrick Brunschwig <[email protected]>2022-01-02 17:49:33 +0100
commit08905dc84edbf0d20ba6f4ffbba733f2d9ec3e02 (patch)
treed523e2d773cf0c5257311cf10ddbed3de62041b8
parentbce7f97b873aa2e6a42abad79f2629079ed9d8fe (diff)
downloadenigmail-08905dc84edbf0d20ba6f4ffbba733f2d9ec3e02.tar.gz
enigmail-08905dc84edbf0d20ba6f4ffbba733f2d9ec3e02.tar.bz2
enigmail-08905dc84edbf0d20ba6f4ffbba733f2d9ec3e02.zip
moved some of the functionality at better places
-rw-r--r--package/cryptoAPI/openpgp-js.js40
-rw-r--r--package/cryptoAPI/pgpjs-crypto-worker.js1
-rw-r--r--package/cryptoAPI/pgpjs-keys.jsm12
-rw-r--r--package/cryptoAPI/pgpjs-keystore.jsm50
4 files changed, 62 insertions, 41 deletions
diff --git a/package/cryptoAPI/openpgp-js.js b/package/cryptoAPI/openpgp-js.js
index a4518d1c..89dc1368 100644
--- a/package/cryptoAPI/openpgp-js.js
+++ b/package/cryptoAPI/openpgp-js.js
@@ -16,11 +16,12 @@ const pgpjs_keyStore = ChromeUtils.import("chrome://enigmail/content/modules/cry
const pgpjs_encrypt = ChromeUtils.import("chrome://enigmail/content/modules/cryptoAPI/pgpjs-encrypt.jsm").pgpjs_encrypt;
const pgpjs_crypto = ChromeUtils.import("chrome://enigmail/content/modules/cryptoAPI/pgpjs-crypto-main.jsm").pgpjs_crypto;
const pgpjs_keymanipulation = ChromeUtils.import("chrome://enigmail/content/modules/cryptoAPI/pgpjs-keymanipulation.jsm").pgpjs_keymanipulation;
-const EnigmailLazy = ChromeUtils.import("chrome://enigmail/content/modules/lazy.jsm").EnigmailLazy;
const EnigmailLog = ChromeUtils.import("chrome://enigmail/content/modules/log.jsm").EnigmailLog;
const EnigmailConstants = ChromeUtils.import("chrome://enigmail/content/modules/constants.jsm").EnigmailConstants;
+const XPCOMUtils = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm").XPCOMUtils;
-const getKeyRing = EnigmailLazy.loader("enigmail/keyRing.jsm", "EnigmailKeyRing");
+/* eslint no-invalid-this: 0 */
+XPCOMUtils.defineLazyModuleGetter(this, "EnigmailKeyRing", "chrome://enigmail/content/modules/keyRing.jsm", "EnigmailKeyRing"); /* global EnigmailKeyRing: false */
// Load generic API
if (typeof CryptoAPI === "undefined") {
@@ -88,38 +89,7 @@ class OpenPGPjsCryptoAPI extends CryptoAPI {
*/
async importKeyData(keyData, minimizeKey, limitedUid) {
- if (minimizeKey) {
- let firstUid = null;
- if (limitedUid && limitedUid.length > 0) {
- firstUid = limitedUid[0];
- }
- keyData = (await pgpjs_keys.getStrippedKey(keyData, firstUid, true)).write();
- }
-
- try {
- let imported = await pgpjs_keyStore.writeKey(keyData);
-
- return {
- exitCode: 0,
- importedKeys: imported,
- importSum: imported.length,
- importUnchanged: 0,
- secCount: 0,
- secDups: 0,
- secImported: 0
- };
- }
- catch (ex) {
- return {
- exitCode: 1,
- importedKeys: [],
- importSum: 0,
- importUnchanged: 0,
- secCount: 0,
- secDups: 0,
- secImported: 0
- };
- }
+ return pgpjs_keyStore.importKeyData(keyData, minimizeKey, limitedUid);
}
/**
@@ -156,7 +126,7 @@ class OpenPGPjsCryptoAPI extends CryptoAPI {
let exitCode = 1;
try {
await pgpjs_keyStore.deleteKeys(fpr);
- getKeyRing().updateKeys(fpr);
+ EnigmailKeyRing.updateKeys(fpr);
exitCode = 0;
}
diff --git a/package/cryptoAPI/pgpjs-crypto-worker.js b/package/cryptoAPI/pgpjs-crypto-worker.js
index 726e923d..1a4bfcff 100644
--- a/package/cryptoAPI/pgpjs-crypto-worker.js
+++ b/package/cryptoAPI/pgpjs-crypto-worker.js
@@ -152,7 +152,6 @@ var workerBody = {
if ("signatures" in result && result.signatures.length > 0) {
let pkt = new PgpJS.PacketList();
- // TODO: check if that works
for (let sig of result.signatures) {
let sigPackets = await sig.signature;
pkt = pkt.concat(sigPackets.packets);
diff --git a/package/cryptoAPI/pgpjs-keys.jsm b/package/cryptoAPI/pgpjs-keys.jsm
index 36d4fc4a..e53aa195 100644
--- a/package/cryptoAPI/pgpjs-keys.jsm
+++ b/package/cryptoAPI/pgpjs-keys.jsm
@@ -166,11 +166,13 @@ var pgpjs_keys = {
// user IDs
for (let u of k.users) {
- if (!key.name) {
- key.name = u.userID.userID.replace(/[\r\n]+/g, " ");
- }
- else {
- key.uids.push(u.userID.userID.replace(/[\r\n]+/g, " "));
+ if (u.userID) {
+ if (!key.name) {
+ key.name = u.userID.userID.replace(/[\r\n]+/g, " ");
+ }
+ else {
+ key.uids.push(u.userID.userID.replace(/[\r\n]+/g, " "));
+ }
}
}
}
diff --git a/package/cryptoAPI/pgpjs-keystore.jsm b/package/cryptoAPI/pgpjs-keystore.jsm
index a25e6263..1aa9d890 100644
--- a/package/cryptoAPI/pgpjs-keystore.jsm
+++ b/package/cryptoAPI/pgpjs-keystore.jsm
@@ -27,6 +27,56 @@ var pgpjs_keyStore = {
getKeyFlags: getKeyFlags, // FIXME
/**
+ * Import key(s) from a string provided
+ *
+ * @param {String} keyData: the key data to be imported (ASCII armored)
+ * @param {Boolean} minimizeKey: import the minimum key without any 3rd-party signatures
+ * @param {Array of String} limitedUid: only import the UID specified
+ *
+ * @return {Object} or null in case no data / error:
+ * - {Number} exitCode: result code (0: OK)
+ * - {Array of String) importedKeys: imported fingerprints
+ * - {Number} importSum: total number of processed keys
+ * - {Number} importUnchanged: number of unchanged keys
+ */
+
+ importKeyData: async function(keyData, minimizeKey, limitedUid) {
+ if (minimizeKey) {
+ let firstUid = null;
+ if (limitedUid && limitedUid.length > 0) {
+ firstUid = limitedUid[0];
+ }
+ keyData = (await pgpjs_keys.getStrippedKey(keyData, firstUid, true)).write();
+ }
+
+ try {
+ let imported = await this.writeKey(keyData);
+
+ return {
+ exitCode: 0,
+ importedKeys: imported,
+ importSum: imported.length,
+ importUnchanged: 0,
+ secCount: 0,
+ secDups: 0,
+ secImported: 0
+ };
+ }
+ catch (ex) {
+ return {
+ exitCode: 1,
+ importedKeys: [],
+ importSum: 0,
+ importUnchanged: 0,
+ secCount: 0,
+ secDups: 0,
+ secImported: 0
+ };
+ }
+ },
+
+
+ /**
* Write key(s) into the database.
*
* @param {String} keyData: armored or binary key data