Shelving changes briefly ENGINE-329
authorKrista Bennett <krista@pep-project.org>
Fri, 19 Jan 2018 14:02:54 +0100
branchENGINE-329
changeset 2416448d74f8eb90
parent 2415 7410f7666976
child 2417 9a6230237b1a
Shelving changes briefly
src/openpgp_compat.c
src/openpgp_compat.h
src/pgp_gpg.c
     1.1 --- a/src/openpgp_compat.c	Fri Jan 19 11:01:39 2018 +0100
     1.2 +++ b/src/openpgp_compat.c	Fri Jan 19 14:02:54 2018 +0100
     1.3 @@ -25,3 +25,6 @@
     1.4      return retval;
     1.5  }
     1.6  
     1.7 +PEP_STATUS import_ultimately_trusted_keypairs (PEP_SESSION session) {
     1.8 +    
     1.9 +}
     2.1 --- a/src/openpgp_compat.h	Fri Jan 19 11:01:39 2018 +0100
     2.2 +++ b/src/openpgp_compat.h	Fri Jan 19 14:02:54 2018 +0100
     2.3 @@ -42,7 +42,8 @@
     2.4          PEP_SESSION session, const char* search_pattern, stringpair_list_t** keyinfo_list
     2.5      );
     2.6      
     2.7 +PEP_STATUS import_ultimately_trusted_keypairs (PEP_SESSION session);
     2.8 +
     2.9  #ifdef __cplusplus
    2.10  }
    2.11  #endif
    2.12 -
     3.1 --- a/src/pgp_gpg.c	Fri Jan 19 11:01:39 2018 +0100
     3.2 +++ b/src/pgp_gpg.c	Fri Jan 19 14:02:54 2018 +0100
     3.3 @@ -1873,6 +1873,60 @@
     3.4      return _pgp_search_keys(session, pattern, keylist, 1);
     3.5  }
     3.6  
     3.7 +PEP_STATUS pgp_import_ultimately_trusted_keypairs(PEP_SESSION session) {
     3.8 +    stringlist_t* priv_keylist = NULL;
     3.9 +    gpgme_key_t key;
    3.10 +    PEP_STATUS first_fail = PEP_STATUS_OK;
    3.11 +
    3.12 +    // 1. get keys
    3.13 +    PEP_status status = pgp_find_private_keys(session, NULL, &priv_keylist);
    3.14 +
    3.15 +    bool has_already_failed = (first_fail != PEP_STATUS_OK);
    3.16 +
    3.17 +    if (status == PEP_STATUS_OK) {    
    3.18 +        stringlist_t* keylist_curr;    
    3.19 +        // 2. for each key
    3.20 +        for (keylist_curr = priv_keylist; keylist_curr; keylist_curr = keylist_curr->next) {
    3.21 +            // a. get key data
    3.22 +            if (!keylist_curr->value)
    3.23 +                continue;
    3.24 +                
    3.25 +            gpgme_error = gpg.gpgme_get_key(session->ctx, keylist_curr->value, &key, 1);
    3.26 +            gpgme_error = _GPGERR(gpgme_error);
    3.27 +            assert(gpgme_error != GPG_ERR_ENOMEM);
    3.28 +            switch (gpgme_error) {
    3.29 +                case GPG_ERR_NO_ERROR:
    3.30 +                    break;
    3.31 +                case GPG_ERR_EOF:
    3.32 +                    first_fail = (has_already_failed ? first_fail : PEP_KEY_NOT_FOUND);
    3.33 +                    break;
    3.34 +                case GPG_ERR_INV_VALUE:
    3.35 +                    first_fail = (has_already_failed ? first_fail : PEP_ILLEGAL_VALUE);
    3.36 +                    break;
    3.37 +                case GPG_ERR_AMBIGUOUS_NAME:
    3.38 +                    first_fail = (has_already_failed ? first_fail : PEP_KEY_HAS_AMBIG_NAME);
    3.39 +                    break;
    3.40 +                case GPG_ERR_ENOMEM:
    3.41 +                    first_fail = (has_already_failed ? first_fail : PEP_OUT_OF_MEMORY);
    3.42 +                    break;
    3.43 +                default:
    3.44 +                    assert(0);
    3.45 +                    first_fail = (has_already_failed ? first_fail : PEP_UNKNOWN_ERROR;
    3.46 +            }
    3.47 +            if (key && gpgme_error == GPG_ERR_NO_ERROR) {
    3.48 +                if (key->revoked || key->disabled)
    3.49 +                    first_fail = (has_already_failed ? first_fail : PEP_KEY_UNSUITABLE);
    3.50 +            }
    3.51 +            
    3.52 +            // a. ensure keypair
    3.53 +            // b. ensure ultimately trusted
    3.54 +            // c. get the name / address
    3.55 +            // d. create identity
    3.56 +        }
    3.57 +    }
    3.58 +}
    3.59 +//gpgme_error_t gpgme_op_keylist_ext_start (gpgme_ctx_t ctx, const char *pattern[], int secret_only, int reserved)
    3.60 +
    3.61  PEP_STATUS pgp_send_key(PEP_SESSION session, const char *pattern)
    3.62  {
    3.63      gpgme_error_t gpgme_error;