From b90ec093ad073ff75b67b3fba456e219fbd137f4 Mon Sep 17 00:00:00 2001 From: SET Date: Thu, 26 Nov 2020 21:03:35 +0100 Subject: [PATCH] Use local scope ::Context when creating keys. The created key was searched with FindKey(), that operates on the class scope ::Context. The latter does not use loopback pinentry. Even though, the created key was found, the passphrase for the created key being cached in gpg-agent. --- GpgMEWorker.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/GpgMEWorker.cpp b/GpgMEWorker.cpp index 155457d..14b7966 100644 --- a/GpgMEWorker.cpp +++ b/GpgMEWorker.cpp @@ -290,11 +290,11 @@ const Error GpgMEWorker::CreateKeyWithEngineDefaultAlgo(GpgME::Key& k, KeyGenerationResult kgr = ctx->createKeyEx(uid.c_str(), "default", 0, expires, k, flags); - delete ppp; - delete ctx; if (kgr.error().code() == 0) // Why is k not assigned the newly created key ?! - k = FindKey(kgr.fingerprint(), e, true); + k = ctx->key(kgr.fingerprint(), e, true); + delete ppp; + delete ctx; return kgr.error(); } @@ -318,11 +318,12 @@ const Error GpgMEWorker::CreateKey(GpgME::Key& k, KeyGenerationResult kgr = ctx->createKeyEx(uid.c_str(), algo, 0, expires, k, flags); - delete ppp; - delete ctx; + if (kgr.error().code() == 0) // Why is k not assigned the newly created key ?! - k = FindKey(kgr.fingerprint(), e, true); + k = ctx->key(kgr.fingerprint(), e, true); + delete ppp; + delete ctx; return kgr.error(); }