aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Brunschwig <[email protected]>2021-05-16 17:16:11 +0200
committerPatrick Brunschwig <[email protected]>2021-05-16 17:16:11 +0200
commit67e582d1b49cac1f09ef0f67f4cf455032d77da7 (patch)
treefb6be1e4830a12d5cba0e9d2b037d42f14da0462
parentb1b7dcd95711512a7905cb433f99f8306a6a08bc (diff)
downloadenigmail-67e582d1b49cac1f09ef0f67f4cf455032d77da7.tar.gz
enigmail-67e582d1b49cac1f09ef0f67f4cf455032d77da7.tar.bz2
enigmail-67e582d1b49cac1f09ef0f67f4cf455032d77da7.zip
implemented verification of attachments
-rw-r--r--package/cryptoAPI/gpgme.js31
-rw-r--r--package/tests/gpgme-test.js32
2 files changed, 60 insertions, 3 deletions
diff --git a/package/cryptoAPI/gpgme.js b/package/cryptoAPI/gpgme.js
index d876110a..b10831aa 100644
--- a/package/cryptoAPI/gpgme.js
+++ b/package/cryptoAPI/gpgme.js
@@ -569,6 +569,13 @@ class GpgMECryptoAPI extends CryptoAPI {
*/
async getFileName(byteData) {
+ let r = await this.decrypt(byteData, {
+ noOutput: true
+ });
+
+ if (r.exitCode === 0) {
+ return r.encryptedFileName;
+ }
return null;
}
@@ -586,7 +593,29 @@ class GpgMECryptoAPI extends CryptoAPI {
*/
async verifyAttachment(filePath, sigPath) {
- return null;
+ let dataFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
+ let sigFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
+ EnigmailFiles.initPath(dataFile, filePath);
+ EnigmailFiles.initPath(sigFile, sigPath);
+
+ if (!dataFile.exists()) {
+ throw new Error(`Data file ${filePath} does not exist`);
+ }
+ if (!sigFile.exists()) {
+ throw new Error(`Signature file ${sigPath} does not exist`);
+ }
+
+ let data = EnigmailFiles.readBinaryFile(dataFile);
+ let sig = EnigmailFiles.readBinaryFile(sigFile);
+
+ let r = await this.verifyMime(data, sig, null);
+ if (r.statusFlags & (EnigmailConstants.BAD_SIGNATURE | EnigmailConstants.UNVERIFIED_SIGNATURE)) {
+ throw r.errorMsg ? r.errorMsg : EnigmailLocale.getString("unverifiedSig") + " - " + EnigmailLocale.getString("msgSignedUnkownKey");
+ }
+
+ const detailArr = r.sigDetails.split(/ /);
+ const dateTime = EnigmailTime.getDateTime(detailArr[2], true, true);
+ return r.errorMsg + "\n" + EnigmailLocale.getString("keyAndSigDate", [r.keyId, dateTime]);
}
/**
diff --git a/package/tests/gpgme-test.js b/package/tests/gpgme-test.js
index 60c56d6a..85b74721 100644
--- a/package/tests/gpgme-test.js
+++ b/package/tests/gpgme-test.js
@@ -395,7 +395,6 @@ test(withTestGpgHome(withEnigmail(asyncTest(async function testSignatures(esvc,
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);
@@ -408,7 +407,7 @@ test(withTestGpgHome(withEnigmail(asyncTest(async function testSignatures(esvc,
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].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);
@@ -418,6 +417,35 @@ test(withTestGpgHome(withEnigmail(asyncTest(async function testSignatures(esvc,
Assert.equal(signedUids[0].sigList[1].createdTime, 1536940295);
}))));
+test(withTestGpgHome(withEnigmail(asyncTest(async function testAttachment(esvc, window) {
+ const gpgmeApi = getGpgMEApi();
+ gpgmeApi.initialize(null, esvc, null);
+
+ const attachment = do_get_file("resources/attachment.txt", false);
+ const signature = do_get_file("resources/attachment.txt.asc", false);
+
+ try {
+ await gpgmeApi.verifyAttachment(attachment.path, signature.path);
+ Assert.ok(false, "Should not obtain a valid verification");
+ }
+ catch (err) {
+ Assert.assertContains(err, "Unverified signature - signed with unknown key");
+ }
+
+ let keyFile = do_get_file("resources/dev-strike.asc", false);
+ let r = await gpgmeApi.importKeyFromFile(keyFile);
+ Assert.equal(r.exitCode, 0);
+
+ try {
+ let result = await gpgmeApi.verifyAttachment(attachment.path, signature.path);
+ Assert.assertContains(result, 'Good signature from anonymous strike');
+ Assert.assertContains(result, 'Key ID: 0x65537E212DC19025AD38EDB2781617319CE311C');
+ }
+ catch (err) {
+ Assert.equal(err, "exception in verifyAttachment");
+ }
+}))));
+
////////////////////////////////////////////////////////
// Helper Functions