From 3ff0e7f81ddae79b1ddfbbe682d1cc371f32841c Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 6 May 2020 00:23:29 +0200 Subject: [PATCH] Kill GnuPG agent at POST step --- README.md | 2 +- __tests__/gpg.test.ts | 6 ++++++ dist/index.js | 5 +++++ src/gpg.ts | 4 ++++ src/main.ts | 3 +++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 04623ca..d4d6cbd 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ If you are interested, [check out](https://git.io/Je09Y) my other :octocat: GitH * Allow to seed the internal cache of `gpg-agent` with provided passphrase * Enable signing for Git commits and tags * Configure and check committer info against GPG key -* Purge imported GPG key and cache information from runner +* Purge imported GPG key, cache information and kill agent from runner ## Usage diff --git a/__tests__/gpg.test.ts b/__tests__/gpg.test.ts index 7722f5f..7e31652 100644 --- a/__tests__/gpg.test.ts +++ b/__tests__/gpg.test.ts @@ -180,4 +180,10 @@ describe('gpg', () => { await gpg.deleteKey(userInfo.fingerprint); }); }); + + describe('killAgent', () => { + it('kills GnuPG agent', async () => { + await gpg.killAgent(); + }); + }); }); diff --git a/dist/index.js b/dist/index.js index 0b9c5a0..3b20468 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1092,6 +1092,8 @@ function cleanup() { core.info('🚿 Removing keys'); const privateKey = yield openpgp.readPrivateKey(process.env.SIGNING_KEY); yield gpg.deleteKey(privateKey.fingerprint); + core.info('💀 Killing GnuPG agent'); + yield gpg.killAgent(); } catch (error) { core.warning(error.message); @@ -1274,6 +1276,9 @@ exports.deleteKey = (fingerprint) => __awaiter(void 0, void 0, void 0, function* } }); }); +exports.killAgent = () => __awaiter(void 0, void 0, void 0, function* () { + yield gpgConnectAgent('KILLAGENT'); +}); /***/ }), diff --git a/src/gpg.ts b/src/gpg.ts index 08576b6..f0134d3 100644 --- a/src/gpg.ts +++ b/src/gpg.ts @@ -163,3 +163,7 @@ export const deleteKey = async (fingerprint: string): Promise => { } }); }; + +export const killAgent = async (): Promise => { + await gpgConnectAgent('KILLAGENT'); +}; diff --git a/src/main.ts b/src/main.ts index 49642e2..25aaf00 100644 --- a/src/main.ts +++ b/src/main.ts @@ -87,6 +87,9 @@ async function cleanup(): Promise { core.info('🚿 Removing keys'); const privateKey = await openpgp.readPrivateKey(process.env.SIGNING_KEY); await gpg.deleteKey(privateKey.fingerprint); + + core.info('💀 Killing GnuPG agent'); + await gpg.killAgent(); } catch (error) { core.warning(error.message); }