ENGINE-586: While we no longer produce non-conformant uids, older versions of pEp and gpg can and do. So we specifically test for the unquoted 'address <address>' uid case if find-keys fails. But only then, and only this case when the addresses match. Quote your ats, ppl. sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Mon, 08 Jul 2019 12:31:47 +0200
branchsync
changeset 39051d3c2c487980
parent 3904 344a2d820213
child 3906 1a00a4b3ff54
child 3907 7c8cdcdd8a34
child 3928 117be5371dd4
ENGINE-586: While we no longer produce non-conformant uids, older versions of pEp and gpg can and do. So we specifically test for the unquoted 'address <address>' uid case if find-keys fails. But only then, and only this case when the addresses match. Quote your ats, ppl.
src/pEpEngine.c
     1.1 --- a/src/pEpEngine.c	Mon Jul 08 11:38:46 2019 +0200
     1.2 +++ b/src/pEpEngine.c	Mon Jul 08 12:31:47 2019 +0200
     1.3 @@ -4247,8 +4247,27 @@
     1.4      if (!(session && pattern && keylist))
     1.5          return PEP_ILLEGAL_VALUE;
     1.6  
     1.7 -    return session->cryptotech[PEP_crypt_OpenPGP].find_keys(session, pattern,
     1.8 -            keylist);
     1.9 +    PEP_STATUS status = session->cryptotech[PEP_crypt_OpenPGP].find_keys(session, pattern,
    1.10 +                                                                         keylist);
    1.11 +                                                                         
    1.12 +#ifndef USE_GPG
    1.13 +    if (*keylist == NULL) {
    1.14 +        // we have a problem, in that older GPG keys with no username associated don't 
    1.15 +        // quote out the address-as-username, meaning the uid is non-standard.
    1.16 +        // sequoia then stores the whole uid string for lookup, so we try again here with 
    1.17 +        // a whole-uid-pattern:
    1.18 +        if (strchr(pattern, '@')) {
    1.19 +            char* new_pattern = calloc(2*strlen(pattern) + 4, 1);
    1.20 +            int n = sprintf(new_pattern, "%s <%s>", pattern, pattern);
    1.21 +            if (n > 0)
    1.22 +                status = session->cryptotech[PEP_crypt_OpenPGP].find_keys(session, new_pattern,
    1.23 +                                                                          keylist);
    1.24 +            free(new_pattern);                                                                      
    1.25 +        }    
    1.26 +    }
    1.27 +#endif 
    1.28 +    
    1.29 +    return status;
    1.30  }
    1.31  
    1.32