From 24eab6f6e08bfa75cf3002e9454ca83c06e7accd Mon Sep 17 00:00:00 2001 From: DebXWoody Date: Sat, 2 May 2020 06:51:41 +0200 Subject: [PATCH] Bugfix OpenPGP / Key Lookup / signers * Iterate list of UIDs for Key Lookup * Clean and set signers in context Issue: #7 #8 --- src/mode/openpgp.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/mode/openpgp.c b/src/mode/openpgp.c index d4a51d0..c200c03 100644 --- a/src/mode/openpgp.c +++ b/src/mode/openpgp.c @@ -184,6 +184,8 @@ char* _openpgp_gpg_signcrypt(xmppc_t *xmppc, char* recipient, char* message) { strcat(xmpp_jid_me, jid); strcat(xmpp_jid_recipient,recipient); + gpgme_signers_clear(ctx); + // lookup own key error = _openpgp_lookup_key(xmppc,xmpp_jid_me, &ctx, &recp[0]); if(error != 0) { @@ -191,6 +193,13 @@ char* _openpgp_gpg_signcrypt(xmppc_t *xmppc, char* recipient, char* message) { return NULL; } + error = gpgme_signers_add(ctx,recp[0]); + if(error != 0) { + logError(xmppc,"gpgme_signers_add %s. GpgME Error: %s\n", xmpp_jid_me, gpgme_strerror(error)); + return NULL; + } + + // lookup key of recipient error = _openpgp_lookup_key(xmppc,xmpp_jid_recipient, &ctx, &recp[1]); if(error != 0) { @@ -247,8 +256,15 @@ gpgme_error_t _openpgp_lookup_key(xmppc_t *xmppc,char* name, gpgme_ctx_t* ctx, g gpgme_error_t error = gpgme_op_keylist_start (*ctx, NULL, 0); while (!error) { error = gpgme_op_keylist_next (*ctx, key); - if(error == 0 && strcmp((*key)->uids->name, name) == 0) { - logDebug(xmppc, "Key found: %s ...\n", (*key)->uids->name); + if(!error) { + gpgme_user_id_t uids = (*key)->uids; + while (uids) { + if(strcmp(uids->name, name) == 0) { + logDebug(xmppc, "Key found: %s ...\n", uids->name); + return error; + } + uids=uids->next; + } } else { gpgme_key_release((*key)); }