ENGINE-162 limit gpg find_keys results to keys with matching uid's email
authorEdouard Tisserant <edouard@pep-project.org>
Thu, 05 Jan 2017 21:58:57 +0100
changeset 15259c91cb1eb4b2
parent 1522 57c2dbcb70dd
child 1526 fd344589f32b
ENGINE-162 limit gpg find_keys results to keys with matching uid's email
src/pgp_gpg.c
     1.1 --- a/src/pgp_gpg.c	Tue Dec 20 22:51:41 2016 +0100
     1.2 +++ b/src/pgp_gpg.c	Thu Jan 05 21:58:57 2017 +0100
     1.3 @@ -1488,12 +1488,27 @@
     1.4              case GPG_ERR_NO_ERROR:
     1.5                  assert(key);
     1.6                  assert(key->subkeys);
     1.7 -                char *fpr = key->subkeys->fpr;
     1.8 -                assert(fpr);
     1.9 -                _k = stringlist_add(_k, fpr);
    1.10 -                assert(_k);
    1.11 -                if (_k != NULL)
    1.12 +                if(!key->subkeys)
    1.13                      break;
    1.14 +                assert(key->uids);
    1.15 +                gpgme_user_id_t kuid = key->uids;
    1.16 +                // check that at least one uid's email matches pattern exactly
    1.17 +                while(kuid) {
    1.18 +                    if(kuid->email && strcmp(kuid->email, pattern) == 0){
    1.19 +                        char *fpr = key->subkeys->fpr;
    1.20 +                        assert(fpr);
    1.21 +                        _k = stringlist_add(_k, fpr);
    1.22 +                        assert(_k);
    1.23 +                        if (_k == NULL){
    1.24 +                            free_stringlist(_keylist);
    1.25 +                            gpg.gpgme_op_keylist_end(session->ctx);
    1.26 +                            return PEP_OUT_OF_MEMORY;
    1.27 +                        }
    1.28 +                        break;
    1.29 +                    }
    1.30 +                    kuid = kuid->next;
    1.31 +                }
    1.32 +                break;
    1.33              case GPG_ERR_ENOMEM:
    1.34                  free_stringlist(_keylist);
    1.35                  gpg.gpgme_op_keylist_end(session->ctx);