aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Brunschwig <[email protected]>2021-05-14 07:49:58 +0200
committerPatrick Brunschwig <[email protected]>2021-05-14 07:49:58 +0200
commite5bf1c9d070d33f3152b97d21661a815ee747ed6 (patch)
treefc365bb9d8207e45b5228bd76fafc42377d39a38
parentc79e96e82eab8677c46fc939207140c0e5ebb372 (diff)
downloadenigmail-e5bf1c9d070d33f3152b97d21661a815ee747ed6.tar.gz
enigmail-e5bf1c9d070d33f3152b97d21661a815ee747ed6.tar.bz2
enigmail-e5bf1c9d070d33f3152b97d21661a815ee747ed6.zip
implemented deletion of keys
-rw-r--r--package/cryptoAPI/gpgme.js60
-rw-r--r--package/tests/gpgme-test.js18
2 files changed, 77 insertions, 1 deletions
diff --git a/package/cryptoAPI/gpgme.js b/package/cryptoAPI/gpgme.js
index c10083e1..add5e547 100644
--- a/package/cryptoAPI/gpgme.js
+++ b/package/cryptoAPI/gpgme.js
@@ -325,6 +325,38 @@ class GpgMECryptoAPI extends CryptoAPI {
*/
async importKeyData(keyData, minimizeKey = false, limitedUids = []) {
+ EnigmailLog.DEBUG(`gpgme.js: importKeyData(${keyData.length}, ${minimizeKey})\n`);
+
+ /*
+ // Using gpgme-json doesn't work with importing private keys, therefore using
+ // gpg directly
+
+ let res = await this.execJsonCmd({
+ op: "import",
+ data: keyData,
+ protocol: "openpgp",
+ base64: false
+ });
+
+ if ("result" in res) {
+ EnigmailLog.DEBUG(`gpgme.js: importKeys: ${JSON.stringify(res)}`);
+ let r = {
+ exitCode: 0,
+ importSum: res.result.considered,
+ importedKeys: [],
+ importUnchanged: res.result.unchanged
+ };
+
+ for (let k of res.result.imports) {
+ r.importedKeys.push(k.fingerprint);
+ }
+
+ return r;
+ }
+
+ return null;
+*/
+
let args = ["--no-verbose", "--status-fd", "2"];
if (minimizeKey) {
args = args.concat(["--import-options", "import-minimal"]);
@@ -390,7 +422,33 @@ class GpgMECryptoAPI extends CryptoAPI {
* - {String} errorMsg: error message if deletion not successful
*/
async deleteKeys(fpr, deleteSecretKey, parentWindow) {
- return null;
+ EnigmailLog.DEBUG(`gpgme.js: deleteKeys(${fpr.join("+")}, ${deleteSecretKey})\n`);
+ let args = ["--no-verbose", "--status-fd", "2", "--batch", "--yes"];
+
+ if (deleteSecretKey) {
+ args.push("--delete-secret-and-public-key");
+ }
+ else {
+ args.push("--delete-keys");
+ }
+
+ args = args.concat(fpr);
+ const res = await EnigmailExecution.execAsync(this._gpgPath, args, "");
+ const deletedKeys = [];
+
+ let lines = res.statusMsg.split(/[\r\n]+/);
+ for (let l of lines) {
+ if (l.search(/^KEY_CONSIDERED /) === 0) {
+ deletedKeys.push(l.split(/ /)[1]);
+ }
+ }
+
+ let exitCode = (deletedKeys.length >= fpr.length) ? 0 : 1;
+
+ return {
+ exitCode: exitCode,
+ errorMsg: exitCode !== 0 ? res.errorMsg : ""
+ };
}
/**
diff --git a/package/tests/gpgme-test.js b/package/tests/gpgme-test.js
index 2cfe864a..b99cfffc 100644
--- a/package/tests/gpgme-test.js
+++ b/package/tests/gpgme-test.js
@@ -321,3 +321,21 @@ iD8DBQE+yUcu4mZch0nhy8kRAuh/AKDM1Xc49BKVfJIFg/btWGfbF/pgcwCgw0Zk
result = await gpgmeApi.verifyMime(fileData, sigData);
Assert.equal(result.statusFlags, EnigmailConstants.GOOD_SIGNATURE);
}))));
+
+
+test(withTestGpgHome(withEnigmail(asyncTest(async function testDeleteKey(esvc, window) {
+ const gpgmeApi = getGpgMEApi();
+ gpgmeApi.initialize(null, esvc, null);
+
+ const secKeyFile = do_get_file("resources/dev-strike.sec", false);
+ let r = await gpgmeApi.importKeyFromFile(secKeyFile, false, null);
+ Assert.equal(r.importSum, 1);
+
+ // delete some unknown key
+ r = await gpgmeApi.deleteKeys(["0x347562ABCD34234DD34234B3456E3546C2456EEE"], false);
+ Assert.ok(r.exitCode !== 0, "deletion not possible");
+
+ // delete private key
+ r = await gpgmeApi.deleteKeys(["0x65537E212DC19025AD38EDB2781617319CE311C4"], true);
+ Assert.equal(r.exitCode, 0, "deletion of secret key");
+}))));