aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Brunschwig <[email protected]>2021-05-16 16:16:58 +0200
committerPatrick Brunschwig <[email protected]>2021-05-16 16:16:58 +0200
commitb1b7dcd95711512a7905cb433f99f8306a6a08bc (patch)
treeadd4efe514bf2e7926f28c7cec0aa2bf37dbcbe5
parent43ab823f9adc9e682582dac9b7d539d2f57b8d32 (diff)
downloadenigmail-b1b7dcd95711512a7905cb433f99f8306a6a08bc.tar.gz
enigmail-b1b7dcd95711512a7905cb433f99f8306a6a08bc.tar.bz2
enigmail-b1b7dcd95711512a7905cb433f99f8306a6a08bc.zip
implemented getting signatures
-rw-r--r--package/cryptoAPI/gnupg-keylist.jsm2
-rw-r--r--package/cryptoAPI/gpgme.js73
-rw-r--r--package/cryptoAPI/interface.js2
-rw-r--r--package/tests/gpgme-test.js30
4 files changed, 100 insertions, 7 deletions
diff --git a/package/cryptoAPI/gnupg-keylist.jsm b/package/cryptoAPI/gnupg-keylist.jsm
index 3926df71..84950488 100644
--- a/package/cryptoAPI/gnupg-keylist.jsm
+++ b/package/cryptoAPI/gnupg-keylist.jsm
@@ -344,7 +344,7 @@ async function getPhotoFileFromGnuPG(keyId, photoNumber) {
/**
* Return signatures for a given key list
*
- * @param {String} gpgKeyList Output from gpg such as produced by getKeySig()
+ * @param {String} gpgKeyList Output from gpg such as produced by getKeySignatures()
* Only the first public key is processed!
* @param {Boolean} ignoreUnknownUid true if unknown signer's UIDs should be filtered out
*
diff --git a/package/cryptoAPI/gpgme.js b/package/cryptoAPI/gpgme.js
index 1ffda7c5..d876110a 100644
--- a/package/cryptoAPI/gpgme.js
+++ b/package/cryptoAPI/gpgme.js
@@ -20,6 +20,7 @@ if (typeof CryptoAPI === "undefined") {
/* eslint no-invalid-this: 0 */
XPCOMUtils.defineLazyModuleGetter(this, "EnigmailKeyRing", "chrome://enigmail/content/modules/keyRing.jsm", "EnigmailKeyRing"); /* global EnigmailKeyRing: false */
XPCOMUtils.defineLazyModuleGetter(this, "EnigmailDialog", "chrome://enigmail/content/modules/dialog.jsm", "EnigmailDialog"); /* global EnigmailDialog: false */
+XPCOMUtils.defineLazyModuleGetter(this, "EnigmailData", "chrome://enigmail/content/modules/data.jsm", "EnigmailData"); /* global EnigmailData: false */
const EnigmailLog = ChromeUtils.import("chrome://enigmail/content/modules/log.jsm").EnigmailLog;
const EnigmailExecution = ChromeUtils.import("chrome://enigmail/content/modules/execution.jsm").EnigmailExecution;
@@ -123,7 +124,7 @@ class GpgMECryptoAPI extends CryptoAPI {
/**
* Obtain signatures for a given set of key IDs.
*
- * @param {String} fpr: key fingerprint
+ * @param {String} fpr: key fingerprint. Separate multiple keys by spaces.
* @param {Boolean} ignoreUnknownUid: if true, filter out unknown signer's UIDs
*
* @return {Promise<Array of Object>}
@@ -135,12 +136,74 @@ class GpgMECryptoAPI extends CryptoAPI {
* - {Array} sigList:
* - {String} userId
* - {String} created
+ * - {Number} createdTime
* - {String} signerKeyId
* - {String} sigType
* - {Boolean} sigKnown
*/
async getKeySignatures(fpr, ignoreUnknownUid = false) {
- return null;
+ EnigmailLog.DEBUG(`gpgme.js: getKeySignatures(${fpr}, ${ignoreUnknownUid})\n`);
+ let cmdObj = {
+ "op": "keylist",
+ "sigs": true,
+ "keys": fpr.split(/[ ,]+/)
+ };
+
+ let keysObj = await this.execJsonCmd(cmdObj);
+ let signatureList = [];
+
+ if ("keys" in keysObj && keysObj.keys.length > 0) {
+ for (let key of keysObj.keys) {
+ for (let uid of key.userids) {
+ const sig = {
+ userId: EnigmailData.convertGpgToUnicode(uid.uid),
+ rawUserId: EnigmailData.convertGpgToUnicode(uid.uid),
+ keyId: key.subkeys[0].keyid,
+ fpr: key.fingerprint,
+ created: EnigmailTime.getDateTime(key.subkeys[0].timestamp, true, false),
+ sigList: []
+ };
+
+ for (let s of uid.signatures) {
+ let uid = s.name ? s.name : "";
+ let sigKnown = s.status === "Success";
+ if (sigKnown) {
+ if (s.email) {
+ if (uid.length > 0) {
+ uid += " <" + s.email + ">";
+ }
+ else {
+ uid = s.email;
+ }
+ }
+
+ if (s.comment.length > 0) {
+ if (uid.length > 0) {
+ uid += "(" + s.comment + ")";
+ }
+ else {
+ uid = s.comment;
+ }
+ }
+ }
+
+ if (sigKnown || ignoreUnknownUid) {
+ sig.sigList.push({
+ userId: EnigmailData.convertGpgToUnicode(uid),
+ created: EnigmailTime.getDateTime(s.timestamp, true, false),
+ createdTime: s.timestamp,
+ signerKeyId: s.keyid,
+ sigType: s.exportable ? "x" : "l",
+ sigKnown: sigKnown
+ });
+ }
+ }
+ signatureList.push(sig);
+ }
+ }
+ }
+
+ return signatureList;
}
/**
@@ -240,7 +303,7 @@ class GpgMECryptoAPI extends CryptoAPI {
let rcpt = grp.keylist.split(/[,; ]+/);
for (let r of rcpt) {
grpObj.userIds.push({
- userId: r,
+ userId: EnigmailData.convertGpgToUnicode(r),
keyTrust: "q"
});
}
@@ -1326,11 +1389,11 @@ function createKeyObj(keyData) {
}
if (keyData.userids.length > 0) {
- keyObj.userId = keyData.userids[0].uid;
+ keyObj.userId = EnigmailData.convertGpgToUnicode(keyData.userids[0].uid);
for (let u of keyData.userids) {
keyObj.userIds.push({
- userId: u.uid,
+ userId: EnigmailData.convertGpgToUnicode(u.uid),
keyTrust: VALIDITY_SYMBOL[u.validity],
uidFpr: "0",
type: "uid"
diff --git a/package/cryptoAPI/interface.js b/package/cryptoAPI/interface.js
index a4bfbb43..bb0d5b72 100644
--- a/package/cryptoAPI/interface.js
+++ b/package/cryptoAPI/interface.js
@@ -76,7 +76,7 @@ class CryptoAPI {
/**
* Obtain signatures for a given set of key IDs.
*
- * @param {String} fpr: key fingerprint
+ * @param {String} fpr: key fingerprint. Separate multiple keys by spaces.
* @param {Boolean} ignoreUnknownUid: if true, filter out unknown signer's UIDs
*
* @return {Promise<Array of Object>}
diff --git a/package/tests/gpgme-test.js b/package/tests/gpgme-test.js
index e0d5472a..60c56d6a 100644
--- a/package/tests/gpgme-test.js
+++ b/package/tests/gpgme-test.js
@@ -391,7 +391,37 @@ test(withTestGpgHome(withEnigmail(asyncTest(async function testExportKey(esvc, w
Assert.ok(r.includes("sub:-:3072:1:2462FC183074D416:1537000928::::::s") === false);
}))));
+test(withTestGpgHome(withEnigmail(asyncTest(async function testSignatures(esvc, window) {
+ const gpgmeApi = getGpgMEApi();
+ gpgmeApi.initialize(null, esvc, null);
+
+ gpgmeApi.initialize();
+ let keyFile = do_get_file("resources/multi-uid.asc", false);
+ let r = await gpgmeApi.importKeyFromFile(keyFile);
+
+ Assert.equal(r.exitCode, 0);
+ Assert.equal(r.importSum, 1);
+ Assert.equal(r.importedKeys[0], "ADC49530CB6B132412D856107F1568CB8997F7BA");
+
+ let signedUids = await gpgmeApi.getKeySignatures("ADC49530CB6B132412D856107F1568CB8997F7BA", true);
+
+ Assert.equal(signedUids.length, 4);
+ Assert.equal(signedUids[0].userId, "Unit Test <[email protected]>");
+ Assert.equal(signedUids[0].sigList.length, 2);
+ Assert.equal(signedUids[0].sigList[0].signerKeyId, "7F1568CB8997F7BA" );
+ Assert.equal(signedUids[0].sigList[0].sigType, "x");
+ Assert.equal(signedUids[0].sigList[0].createdTime, 1536940615);
+ Assert.ok(signedUids[0].sigList[0].sigKnown);
+
+ Assert.equal(signedUids[0].sigList[1].signerKeyId, "781617319CE311C4");
+ Assert.equal(signedUids[0].sigList[1].sigKnown, false);
+ Assert.equal(signedUids[0].sigList[1].createdTime, 1536940295);
+}))));
+
+////////////////////////////////////////////////////////
+// Helper Functions
+////////////////////////////////////////////////////////
async function testGpgKeyData(gpgmeApi, keyData) {
const importArgs = ["--no-default-keyring", "--no-tty", "--batch", "--no-verbose", "--with-fingerprint", "--with-colons", "--import-options", "import-show", "--dry-run", "--import"];
let r = await EnigmailExecution.execAsync(gpgmeApi._gpgPath, importArgs, keyData);