merge default into my branch roker-linux
authorRoker <roker@pep-project.org>
Tue, 23 Aug 2016 07:33:56 +0200
branchroker-linux
changeset 105675047084d27d
parent 1037 11e745d9a3d6
parent 1055 9d0b3d675963
child 1143 7189eb035523
merge default into my branch
src/Makefile
     1.1 --- a/.hgtags	Thu Aug 18 17:01:19 2016 +0200
     1.2 +++ b/.hgtags	Tue Aug 23 07:33:56 2016 +0200
     1.3 @@ -1,3 +1,4 @@
     1.4  c51c34a97ba7345f4fe9cd1313335f41e0da17b1 list
     1.5  b5d0f1e3b9c7f727c427562a0e9ff1a027250820 0.7
     1.6  2b4d6c760ad771d9917cd6f0f96c4ab379d75d1d 0.7.0
     1.7 +a1ba15c1ac041c780e52e759db6b77d116f29c72 0.8.0
     2.1 --- a/src/cryptotech.c	Thu Aug 18 17:01:19 2016 +0200
     2.2 +++ b/src/cryptotech.c	Tue Aug 23 07:33:56 2016 +0200
     2.3 @@ -7,7 +7,7 @@
     2.4  #include "pgp_netpgp.h"
     2.5  #endif
     2.6  #endif
     2.7 -
     2.8 +// 
     2.9  
    2.10  #include <stdlib.h>
    2.11  #include <memory.h>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/openpgp_compat.c	Tue Aug 23 07:33:56 2016 +0200
     3.3 @@ -0,0 +1,23 @@
     3.4 +#include "pEp_internal.h"
     3.5 +#include "dynamic_api.h"
     3.6 +#include "openpgp_compat.h"
     3.7 +
     3.8 +DYNAMIC_API PEP_STATUS OpenPGP_list_keyinfo (
     3.9 +        PEP_SESSION session, const char* search_pattern, stringpair_list_t** keyinfo_list
    3.10 +    )
    3.11 +{
    3.12 +    assert(session);
    3.13 +    assert(keyinfo_list);
    3.14 +
    3.15 +    if (!(session && keyinfo_list))
    3.16 +        return PEP_ILLEGAL_VALUE;
    3.17 +
    3.18 +    stringpair_list_t* _keyinfo_list = NULL;
    3.19 +    
    3.20 +    PEP_STATUS retval = pgp_list_keyinfo(session, search_pattern, &_keyinfo_list);
    3.21 +        
    3.22 +    if (retval == PEP_STATUS_OK)
    3.23 +        *keyinfo_list = _keyinfo_list;
    3.24 +    
    3.25 +    return retval;
    3.26 +}
    3.27 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/openpgp_compat.h	Tue Aug 23 07:33:56 2016 +0200
     4.3 @@ -0,0 +1,44 @@
     4.4 +// openpgp_compat.h
     4.5 +//
     4.6 +// These functions are the exposure of non-generic PGP-specific functionality (largely related to PGP
     4.7 +// keyrings) to adapters that need them without polluting the engine interface.
     4.8 +//
     4.9 +#pragma once
    4.10 +
    4.11 +#ifdef __cplusplus
    4.12 +extern "C" {
    4.13 +#endif
    4.14 +
    4.15 +#include <stddef.h>
    4.16 +#include <stdint.h>
    4.17 +#include <stdbool.h>
    4.18 +    
    4.19 +#include "dynamic_api.h"
    4.20 +#include "stringpair.h"    
    4.21 +
    4.22 +#ifdef USE_GPG
    4.23 +#include "pgp_gpg.h"
    4.24 +#else
    4.25 +#ifdef USE_NETPGP
    4.26 +#include "pgp_netpgp.h"
    4.27 +#endif
    4.28 +#endif    
    4.29 +    
    4.30 +//  OpenPGP_list_keyinfo() - get a key/UID list for pattern matches in keyring (NULL
    4.31 +//                           to return entire keyring)
    4.32 +//
    4.33 +//  parameters:
    4.34 +//      session (in)          session handle
    4.35 +//      show_revoked (in)     true if identities with revoked primary keys should also
    4.36 +//                            be listed; false if only valid keys should be shown
    4.37 +//      keyinfo_list (out)    list of identities for each available key 
    4.38 +//
    4.39 +//  caveat:
    4.40 +//      keyinfo_list must be freed by the caller.
    4.41 +DYNAMIC_API PEP_STATUS OpenPGP_list_keyinfo (
    4.42 +        PEP_SESSION session, const char* search_pattern, stringpair_list_t** keyinfo_list
    4.43 +    );
    4.44 +    
    4.45 +#ifdef __cplusplus
    4.46 +}
    4.47 +#endif
    4.48 \ No newline at end of file
     5.1 --- a/src/pEpEngine.c	Thu Aug 18 17:01:19 2016 +0200
     5.2 +++ b/src/pEpEngine.c	Tue Aug 23 07:33:56 2016 +0200
     5.3 @@ -1234,6 +1234,7 @@
     5.4      return session->cryptotech[PEP_crypt_OpenPGP].find_keys(session, pattern, keylist);
     5.5  }
     5.6  
     5.7 +
     5.8  DYNAMIC_API PEP_STATUS generate_keypair(
     5.9          PEP_SESSION session, pEp_identity *identity
    5.10      )
     6.1 --- a/src/pEpEngine.h	Thu Aug 18 17:01:19 2016 +0200
     6.2 +++ b/src/pEpEngine.h	Tue Aug 23 07:33:56 2016 +0200
     6.3 @@ -10,6 +10,7 @@
     6.4  
     6.5  #include "dynamic_api.h"
     6.6  #include "stringlist.h"
     6.7 +#include "stringpair.h"    
     6.8  #include "timestamp.h"
     6.9  
    6.10  #define PEP_VERSION "1.0" // protocol version
    6.11 @@ -644,7 +645,6 @@
    6.12          PEP_SESSION session, const char *pattern, stringlist_t **keylist
    6.13      );
    6.14  
    6.15 -
    6.16  // send_key() - send key(s) to keyserver
    6.17  //
    6.18  //  parameters:
     7.1 --- a/src/pgp_gpg.c	Thu Aug 18 17:01:19 2016 +0200
     7.2 +++ b/src/pgp_gpg.c	Tue Aug 23 07:33:56 2016 +0200
     7.3 @@ -1225,6 +1225,101 @@
     7.4      return PEP_STATUS_OK;
     7.5  }
     7.6  
     7.7 +PEP_STATUS pgp_list_keyinfo(PEP_SESSION session, const char* pattern, 
     7.8 +                            stringpair_list_t** keyinfo_list)
     7.9 +{    
    7.10 +    gpgme_error_t gpgme_error;
    7.11 +    assert(session);
    7.12 +    assert(keyinfo_list);
    7.13 +    
    7.14 +    if (!session || !keyinfo_list)
    7.15 +        return PEP_ILLEGAL_VALUE;
    7.16 +    
    7.17 +    *keyinfo_list = NULL;
    7.18 +    
    7.19 +    gpgme_error = gpg.gpgme_op_keylist_start(session->ctx, pattern, 0);
    7.20 +    gpgme_error = _GPGERR(gpgme_error);
    7.21 +    
    7.22 +    switch(gpgme_error) {
    7.23 +        case GPG_ERR_NO_ERROR:
    7.24 +            break;
    7.25 +        case GPG_ERR_INV_VALUE:
    7.26 +            assert(0);
    7.27 +            return PEP_UNKNOWN_ERROR;
    7.28 +        default:
    7.29 +            gpg.gpgme_op_keylist_end(session->ctx);
    7.30 +            return PEP_GET_KEY_FAILED;        
    7.31 +    };
    7.32 +    
    7.33 +    gpgme_key_t key;
    7.34 +    stringpair_list_t* _keyinfo_list = new_stringpair_list(NULL);
    7.35 +    stringpair_list_t* list_curr = _keyinfo_list;
    7.36 +    stringpair_t* pair = NULL;
    7.37 +        
    7.38 +    do {
    7.39 +        gpgme_error = gpg.gpgme_op_keylist_next(session->ctx, &key);
    7.40 +        gpgme_error = _GPGERR(gpgme_error);
    7.41 +      
    7.42 +        switch(gpgme_error) {
    7.43 +            case GPG_ERR_EOF:
    7.44 +                break;
    7.45 +            case GPG_ERR_NO_ERROR:
    7.46 +                assert(key);
    7.47 +                assert(key->subkeys);
    7.48 +                if (!key || !key->subkeys)
    7.49 +                    return PEP_GET_KEY_FAILED;
    7.50 +
    7.51 +                // first subkey is primary key
    7.52 +                char* fpr = key->subkeys->fpr;
    7.53 +                char* uid = key->uids->uid;
    7.54 +                
    7.55 +                assert(fpr);
    7.56 +                assert(uid); // ??
    7.57 +                if (!fpr)
    7.58 +                    return PEP_GET_KEY_FAILED;
    7.59 +                
    7.60 +                PEP_STATUS key_status = PEP_GET_KEY_FAILED;
    7.61 +                
    7.62 +                bool key_revoked = false;
    7.63 +                                
    7.64 +                if (key->subkeys->revoked)
    7.65 +                    continue;
    7.66 +                
    7.67 +                pair = new_stringpair(fpr, uid);
    7.68 +
    7.69 +                assert(pair);
    7.70 +                
    7.71 +                if (pair) {
    7.72 +                    list_curr = stringpair_list_add(list_curr, pair);
    7.73 +                    pair = NULL;
    7.74 +                    
    7.75 +                    assert(list_curr);
    7.76 +                    if (list_curr != NULL)
    7.77 +                        break;
    7.78 +                    else
    7.79 +                        free_stringpair(pair);
    7.80 +                }
    7.81 +                // else fallthrough (list_curr or pair wasn't allocateable)
    7.82 +            case GPG_ERR_ENOMEM:
    7.83 +                free_stringpair_list(_keyinfo_list);
    7.84 +                gpg.gpgme_op_keylist_end(session->ctx);
    7.85 +                return PEP_OUT_OF_MEMORY;
    7.86 +            default:
    7.87 +                gpg.gpgme_op_keylist_end(session->ctx);
    7.88 +                return PEP_UNKNOWN_ERROR;
    7.89 +        }
    7.90 +    } while (gpgme_error != GPG_ERR_EOF);
    7.91 +    
    7.92 +    if (_keyinfo_list->value == NULL) {
    7.93 +        free_stringpair_list(_keyinfo_list);
    7.94 +        _keyinfo_list = NULL;
    7.95 +    }
    7.96 +    
    7.97 +    *keyinfo_list = _keyinfo_list;
    7.98 +    
    7.99 +    return PEP_STATUS_OK;
   7.100 +}
   7.101 +
   7.102  static void _switch_mode(pEpSession *session, gpgme_keylist_mode_t remove_mode,
   7.103      gpgme_keylist_mode_t add_mode)
   7.104  {
     8.1 --- a/src/pgp_gpg.h	Thu Aug 18 17:01:19 2016 +0200
     8.2 +++ b/src/pgp_gpg.h	Tue Aug 23 07:33:56 2016 +0200
     8.3 @@ -30,6 +30,10 @@
     8.4          PEP_SESSION session, const char *pattern, stringlist_t **keylist
     8.5      );
     8.6  
     8.7 +PEP_STATUS pgp_list_keyinfo(
     8.8 +    PEP_SESSION session, const char* pattern, stringpair_list_t** keyinfo_list
     8.9 +    );
    8.10 +
    8.11  PEP_STATUS pgp_generate_keypair(
    8.12          PEP_SESSION session, pEp_identity *identity
    8.13      );
     9.1 --- a/src/pgp_netpgp.c	Thu Aug 18 17:01:19 2016 +0200
     9.2 +++ b/src/pgp_netpgp.c	Tue Aug 23 07:33:56 2016 +0200
     9.3 @@ -1169,7 +1169,7 @@
     9.4          return PEP_OUT_OF_MEMORY;
     9.5      } else { 
     9.6  
     9.7 -        *keylist = stringlist_add(*keylist, newfprstr);
     9.8 +        stringlist_add(*keylist, newfprstr);
     9.9          free(newfprstr);
    9.10          if (*keylist == NULL) {
    9.11              return PEP_OUT_OF_MEMORY;
    9.12 @@ -1178,6 +1178,34 @@
    9.13      return PEP_STATUS_OK;
    9.14  }
    9.15  
    9.16 +static PEP_STATUS add_keyinfo_to_stringpair_list(void* arg, pgp_key_t *key) {
    9.17 +    stringpair_list_t** keyinfo_list = (stringpair_list_t**)arg;
    9.18 +    stringpair_t* pair = NULL;
    9.19 +    char* id_fpr = NULL;
    9.20 +    char* primary_userid = (char*)pgp_key_get_primary_userid(key);
    9.21 +
    9.22 +    bool key_revoked = false;
    9.23 +                
    9.24 +//    PEP_STATUS key_status = pgp_key_revoked(session, id_fpr, &key_revoked);
    9.25 +                
    9.26 +//    if (key_revoked || key_status == PEP_GET_KEY_FAILED)
    9.27 +//        return PEP_STATUS_OK; // we just move on
    9.28 +        
    9.29 +    fpr_to_str(&id_fpr, key->pubkeyfpr.fingerprint,
    9.30 +                key->pubkeyfpr.length);
    9.31 +
    9.32 +    pair = new_stringpair(id_fpr, primary_userid);
    9.33 +    
    9.34 +    if (pair == NULL)
    9.35 +        return PEP_OUT_OF_MEMORY;
    9.36 +    
    9.37 +    *keyinfo_list = stringpair_list_add(*keyinfo_list, pair);
    9.38 +    free(id_fpr);
    9.39 +    if (*keyinfo_list == NULL)
    9.40 +        return PEP_OUT_OF_MEMORY;
    9.41 +    return PEP_STATUS_OK;
    9.42 +}
    9.43 +
    9.44  PEP_STATUS pgp_find_keys(
    9.45      PEP_SESSION session, const char *pattern, stringlist_t **keylist
    9.46      )
    9.47 @@ -1644,3 +1672,33 @@
    9.48      
    9.49      return PEP_STATUS_OK;
    9.50  }
    9.51 +
    9.52 +
    9.53 +PEP_STATUS pgp_list_keyinfo(
    9.54 +        PEP_SESSION session, const char* pattern, stringpair_list_t** keyinfo_list)
    9.55 +{
    9.56 +    
    9.57 +    if (!session || !keyinfo_list)
    9.58 +        return PEP_UNKNOWN_ERROR;
    9.59 +    
    9.60 +    if (pthread_mutex_lock(&netpgp_mutex))
    9.61 +    {
    9.62 +        return PEP_UNKNOWN_ERROR;
    9.63 +    }
    9.64 +    
    9.65 +    pgp_key_t *key;
    9.66 +
    9.67 +    PEP_STATUS result;
    9.68 +    
    9.69 +    result = find_keys_do(pattern, &add_keyinfo_to_stringpair_list, (void*)keyinfo_list);
    9.70 +    
    9.71 +    if (!keyinfo_list)
    9.72 +        result = PEP_KEY_NOT_FOUND;
    9.73 +    
    9.74 +unlock_netpgp:
    9.75 +    pthread_mutex_unlock(&netpgp_mutex);
    9.76 +    
    9.77 +    return result;
    9.78 +}
    9.79 +
    9.80 +
    10.1 --- a/src/pgp_netpgp.h	Thu Aug 18 17:01:19 2016 +0200
    10.2 +++ b/src/pgp_netpgp.h	Tue Aug 23 07:33:56 2016 +0200
    10.3 @@ -30,6 +30,10 @@
    10.4          PEP_SESSION session, const char *pattern, stringlist_t **keylist
    10.5      );
    10.6  
    10.7 +PEP_STATUS pgp_list_keyinfo(
    10.8 +    PEP_SESSION session, const char* pattern, stringpair_list_t** keyinfo_list
    10.9 +    );
   10.10 +
   10.11  PEP_STATUS pgp_generate_keypair(
   10.12          PEP_SESSION session, pEp_identity *identity
   10.13      );
    11.1 --- a/src/platform_unix.c	Thu Aug 18 17:01:19 2016 +0200
    11.2 +++ b/src/platform_unix.c	Tue Aug 23 07:33:56 2016 +0200
    11.3 @@ -6,6 +6,7 @@
    11.4  #include <sys/stat.h>
    11.5  #include <sys/types.h>
    11.6  #include <fcntl.h>
    11.7 +#include <regex.h>
    11.8  
    11.9  #include "platform_unix.h"
   11.10  
   11.11 @@ -123,6 +124,12 @@
   11.12      return retval;
   11.13  }
   11.14  
   11.15 +// FIXME: This may cause problems - this is a quick compatibility fix for netpgp code
   11.16 +int regnexec(const regex_t* preg, const char* string,
   11.17 +             size_t len, size_t nmatch, regmatch_t pmatch[], int eflags) {
   11.18 +    return regexec(preg, string, nmatch, pmatch, eflags);
   11.19 +}
   11.20 +
   11.21  #endif
   11.22  
   11.23  const char *unix_local_db(void)
    12.1 --- a/src/platform_unix.h	Thu Aug 18 17:01:19 2016 +0200
    12.2 +++ b/src/platform_unix.h	Tue Aug 23 07:33:56 2016 +0200
    12.3 @@ -5,6 +5,7 @@
    12.4  #include <unistd.h>
    12.5  #include <strings.h>
    12.6  #include <sys/select.h>
    12.7 +#include <regex.h>
    12.8  
    12.9  #ifdef __cplusplus
   12.10  extern "C" {
   12.11 @@ -43,6 +44,8 @@
   12.12  #if !defined(BSD) && !defined(__APPLE__)
   12.13  size_t strlcpy(char* dst, const	char* src, size_t size);
   12.14  size_t strlcat(char* dst, const	char* src, size_t size);
   12.15 +int regnexec(const regex_t* preg, const char* string,
   12.16 +             size_t len, size_t nmatch, regmatch_t pmatch[], int eflags);
   12.17  #endif
   12.18  
   12.19  #ifdef __cplusplus
    13.1 --- a/test/encrypt_for_identity_test.cc	Thu Aug 18 17:01:19 2016 +0200
    13.2 +++ b/test/encrypt_for_identity_test.cc	Tue Aug 23 07:33:56 2016 +0200
    13.3 @@ -90,7 +90,7 @@
    13.4      for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
    13.5      {
    13.6          cout << "\t " << kl4->value << endl;
    13.7 -        assert(strcmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
    13.8 +        assert(strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0);
    13.9          cout << "Encrypted for Alice! Yay! It worked!" << endl;
   13.10      }
   13.11      cout << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/pgp_list_keys_test.cc	Tue Aug 23 07:33:56 2016 +0200
    14.3 @@ -0,0 +1,71 @@
    14.4 +#include <iostream>
    14.5 +#include <string>
    14.6 +#include <assert.h>
    14.7 +#include "pEpEngine.h"
    14.8 +#include "stringpair.h"
    14.9 +#include "openpgp_compat.h"
   14.10 +
   14.11 +using namespace std;
   14.12 +
   14.13 +void print_stringpair_list(stringpair_list_t* spl) {
   14.14 +    for ( ; spl != NULL; spl = spl->next) {
   14.15 +        if (spl->value) {
   14.16 +            cout << "Key:" << endl;
   14.17 +            if (spl->value->key)
   14.18 +                cout << "\tFPR: " << spl->value->key << endl;
   14.19 +            if (spl->value->value)
   14.20 +                cout << "\tUID: " << spl->value->value << endl;
   14.21 +        }
   14.22 +    }
   14.23 +}
   14.24 +
   14.25 +int main() {
   14.26 +    cout << "\n*** openpgp_compat test ***\n\n";
   14.27 +
   14.28 +    PEP_SESSION session;
   14.29 +    
   14.30 +    cout << "calling init()\n";
   14.31 +    PEP_STATUS status1 = init(&session);   
   14.32 +    assert(status1 == PEP_STATUS_OK);
   14.33 +    assert(session);
   14.34 +    cout << "init() completed.\n";
   14.35 +
   14.36 +    cout << "Listing all the keys:" << endl;
   14.37 +    stringpair_list_t* all_the_ids = NULL;
   14.38 +    OpenPGP_list_keyinfo(session, "", &all_the_ids);
   14.39 +    print_stringpair_list(all_the_ids);
   14.40 +    free_stringpair_list(all_the_ids);
   14.41 +    
   14.42 +    cout << "**********************" << endl << endl << "Checking on Alice, Bob and John" << endl;
   14.43 +    all_the_ids = NULL;
   14.44 +    OpenPGP_list_keyinfo(session, "pEp Test", &all_the_ids);
   14.45 +    print_stringpair_list(all_the_ids);
   14.46 +    free_stringpair_list(all_the_ids);
   14.47 +
   14.48 +    cout << "**********************" << endl << endl << "Compare to find_keys for Alice, Bob and John" << endl;
   14.49 +    stringlist_t* all_the_keys;
   14.50 +    find_keys(session, "pEp Test", &all_the_keys);
   14.51 +    stringlist_t* i;
   14.52 +    for (i = all_the_keys; i; i = i->next) {
   14.53 +        cout << i->value << endl;
   14.54 +    }
   14.55 +    free_stringlist(all_the_keys);
   14.56 +
   14.57 +    
   14.58 +    cout << "**********************" << endl << endl << "Checking FPR" << endl;
   14.59 +    all_the_ids = NULL;
   14.60 +    OpenPGP_list_keyinfo(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &all_the_ids);
   14.61 +    print_stringpair_list(all_the_ids);
   14.62 +    free_stringpair_list(all_the_ids);
   14.63 +
   14.64 +    cout << "**********************" << endl << endl << "Checking on nothing" << endl;
   14.65 +    all_the_ids = NULL;
   14.66 +    OpenPGP_list_keyinfo(session, "ekhwr89234uh4rknfjsklejfnlskjflselkflkserjs", &all_the_ids);
   14.67 +    print_stringpair_list(all_the_ids);
   14.68 +    free_stringpair_list(all_the_ids);
   14.69 +
   14.70 +    cout << "calling release()\n";
   14.71 +    release(session);
   14.72 +    return 0;
   14.73 +}
   14.74 +