Shelving changes for subkey problem ENGINE-155
authorKrista Grothoff <krista@pep-project.org>
Tue, 20 Dec 2016 11:21:35 +0100
branchENGINE-155
changeset 1498f726362229d8
parent 1497 5c110c844ff5
child 1530 184b8fde20cc
Shelving changes for subkey problem
src/pgp_gpg.c
     1.1 --- a/src/pgp_gpg.c	Mon Dec 19 13:16:17 2016 +0100
     1.2 +++ b/src/pgp_gpg.c	Tue Dec 20 11:21:35 2016 +0100
     1.3 @@ -383,6 +383,52 @@
     1.4              dlclose(gpgme);
     1.5  }
     1.6  
     1.7 +/* Note: this could really screw the pooch if the next key isn't the */
     1.8 +/* appropriate type, but it's better than the current failure */
     1.9 +PEP_STATUS _first_viable_subkey_fpr(PEP_SESSION session,
    1.10 +                                    gpgme_key_t key,
    1.11 +                                    char** ret_fpr) {
    1.12 +    *ref_fpr = NULL;
    1.13 +    
    1.14 +    if (key && key->subkeys) {
    1.15 +        gpgme_subkey_t subkey = key->subkeys;
    1.16 +
    1.17 +        switch (subkeys->protocol) {
    1.18 +            case GPGME_PROTOCOL_OpenPGP:
    1.19 +            case GPGME_PROTOCOL_DEFAULT:
    1.20 +            case GPGME_PROTOCOL_CMS:
    1.21 +                break;
    1.22 +            default:
    1.23 +                return PEP_UNKNOWN_ERROR;
    1.24 +        }
    1.25 +        
    1.26 +        while (subkey) {
    1.27 +            if (!(subkey->revoked || subkey->expired ||
    1.28 +                subkey->disabled || subkey->invalid)) {
    1.29 +
    1.30 +                if (gpgme_check_version("2.1.0")) {
    1.31 +                    switch (subkey->pubkey_algo) {
    1.32 +                        case PUBKEY_ALGO_ECDH:
    1.33 +                        case PUBKEY_ALGO_ECDSA:
    1.34 +                        case PUBKEY_ALGO_EDDSA:
    1.35 +                            subkey = subkey->next;
    1.36 +                            continue;
    1.37 +                        default:
    1.38 +                            break;
    1.39 +                    }
    1.40 +                }    
    1.41 +                break;
    1.42 +            }
    1.43 +            subkey = subkey->next;
    1.44 +        }
    1.45 +        if (subkey) {
    1.46 +            *ret_fpr = subkey->fpr;
    1.47 +            return PEP_STATUS_OK;
    1.48 +        }
    1.49 +    }
    1.50 +    return PEP_KEY_NOT_FOUND;         
    1.51 +}
    1.52 +
    1.53  PEP_STATUS pgp_decrypt_and_verify(
    1.54      PEP_SESSION session, const char *ctext, size_t csize,
    1.55      const char *dsigtext, size_t dsigsize,