stowing changes ENGINE-84
authorKrista Grothoff <krista@pep-project.org>
Sun, 06 Nov 2016 22:55:37 +0100
branchENGINE-84
changeset 1352239640860531
parent 1351 388a8aa06c83
child 1357 b1677cd84729
stowing changes
src/cryptotech.c
src/cryptotech.h
src/keymanagement.c
src/pgp_gpg.c
test/message_api_test.cc
     1.1 --- a/src/cryptotech.c	Fri Nov 04 12:48:06 2016 +0100
     1.2 +++ b/src/cryptotech.c	Sun Nov 06 22:55:37 2016 +0100
     1.3 @@ -47,6 +47,7 @@
     1.4          cryptotech[PEP_crypt_OpenPGP].key_expired = pgp_key_expired;
     1.5          cryptotech[PEP_crypt_OpenPGP].key_revoked = pgp_key_revoked;
     1.6          cryptotech[PEP_crypt_OpenPGP].key_created = pgp_key_created;
     1.7 +        cryptotech[PEP_crypt_OpenPGP].pair_has_private = pgp_pair_has_private;
     1.8  #ifdef PGP_BINARY_PATH
     1.9          cryptotech[PEP_crypt_OpenPGP].binary_path = PGP_BINARY_PATH;
    1.10  #endif
     2.1 --- a/src/cryptotech.h	Fri Nov 04 12:48:06 2016 +0100
     2.2 +++ b/src/cryptotech.h	Sun Nov 06 22:55:37 2016 +0100
     2.3 @@ -72,6 +72,9 @@
     2.4  
     2.5  typedef PEP_STATUS (*binary_path_t)(const char **path);
     2.6  
     2.7 +typedef PEP_STATUS (*pair_has_private_t)(PEP_SESSION session, const char *fpr,
     2.8 +        bool *has_private);
     2.9 +
    2.10  typedef struct _PEP_cryptotech_t {
    2.11      uint8_t id;
    2.12      // the following are default values; comm_type may vary with key length or b0rken crypto
    2.13 @@ -94,6 +97,7 @@
    2.14      key_revoked_t key_revoked;
    2.15      key_created_t key_created;
    2.16      binary_path_t binary_path;
    2.17 +    pair_has_private_t pair_has_private;
    2.18  } PEP_cryptotech_t;
    2.19  
    2.20  extern PEP_cryptotech_t cryptotech[PEP_crypt__count];
     3.1 --- a/src/keymanagement.c	Fri Nov 04 12:48:06 2016 +0100
     3.2 +++ b/src/keymanagement.c	Sun Nov 06 22:55:37 2016 +0100
     3.3 @@ -421,6 +421,17 @@
     3.4      if (stored_identity)
     3.5      {
     3.6          if (EMPTYSTR(identity->fpr)) {
     3.7 +            
     3.8 +            // First check to see if it's blacklisted?
     3.9 +            char* stored_fpr = stored_identity->fpr;
    3.10 +            
    3.11 +            bool dont_use_fpr = false;
    3.12 +            
    3.13 +            status = blacklist_is_listed(session, stored_fpr, &dont_use_fpr);
    3.14 +            if (!dont_use_fpr) {
    3.15 +                // Make sure there is a *private* key associated with this fpr
    3.16 +            }
    3.17 +            
    3.18              identity->fpr = strdup(stored_identity->fpr);
    3.19              assert(identity->fpr);
    3.20              if (identity->fpr == NULL)
     4.1 --- a/src/pgp_gpg.c	Fri Nov 04 12:48:06 2016 +0100
     4.2 +++ b/src/pgp_gpg.c	Sun Nov 06 22:55:37 2016 +0100
     4.3 @@ -2118,3 +2118,30 @@
     4.4      return PEP_STATUS_OK;
     4.5  }
     4.6  
     4.7 +PEP_STATUS pgp_pair_has_private(PEP_SESSION session, const char *fpr,
     4.8 +        bool *has_private) {
     4.9 +    status = PEP_STATUS_OK;
    4.10 +    gpg_key_t output_key;
    4.11 +    gpgme_error_t gpgerr = gpgme_get_key(session->ctx, fpr, &output_key, true);
    4.12 +    *has_private = false;
    4.13 +    switch (gpgerr) {
    4.14 +        case GPG_ERR_EOF:
    4.15 +        case GPG_ERR_INV_VALUE:
    4.16 +            status = PEP_KEY_NOT_FOUND;
    4.17 +            break;
    4.18 +        case GPG_ERR_AMBIGUOUS_NAME:
    4.19 +            status = PEP_KEY_HAS_AMBIG_NAME;
    4.20 +            break;
    4.21 +        case GPG_ERR_NO_ERROR:
    4.22 +            *has_private = true;
    4.23 +            gpgme_key_release(output_key);
    4.24 +            break;
    4.25 +        case GPG_ERR_ENOMEM:
    4.26 +            status = PEP_OUT_OF_MEMORY;
    4.27 +            break;
    4.28 +        default:
    4.29 +            status = PEP_UNKNOWN_ERROR;
    4.30 +            break;
    4.31 +    }
    4.32 +    return status;
    4.33 +}
    4.34 \ No newline at end of file
     5.1 --- a/test/message_api_test.cc	Fri Nov 04 12:48:06 2016 +0100
     5.2 +++ b/test/message_api_test.cc	Sun Nov 06 22:55:37 2016 +0100
     5.3 @@ -145,11 +145,14 @@
     5.4      }
     5.5      inFile4.close();
     5.6      
     5.7 -    const char* out_msg_plain = text4.c_str();
     5.8 +//    const char* out_msg_plain = text4.c_str();
     5.9 +    
    5.10 +    const char* out_msg_plain = "From: krista@kgrothoff.org\nTo: Volker <vb@pep-project.org>\nSubject: Test\nContent-Type: text/plain; charset=utf-8\nContent-Language: en-US\nContent-Transfer-Encoding:quoted-printable\n\ngaga\n\n";
    5.11      char* enc_msg = NULL;
    5.12      char* dec_msg = NULL;
    5.13  
    5.14 -    PEP_STATUS status7 = MIME_encrypt_message(session, text4.c_str(), text4.length(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    5.15 +//    PEP_STATUS status7 = MIME_encrypt_message(session, text4.c_str(), text4.length(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    5.16 +    PEP_STATUS status7 = MIME_encrypt_message(session, out_msg_plain, strlen(out_msg_plain), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    5.17      assert(status7 == PEP_STATUS_OK);
    5.18      
    5.19      cout << enc_msg << endl;