merged in sequoia branch Release_2.1 Release_2.1.3
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 14 Oct 2020 14:46:03 +0200
branchRelease_2.1
changeset 5108273dd589f974
parent 5102 93b36f57b116
parent 5104 e107487bc3db
child 5109 3d217688aa69
merged in sequoia branch
.hgtags
src/pEpEngine.h
     1.1 --- a/src/pgp_sequoia.c	Mon Oct 12 15:43:50 2020 +0200
     1.2 +++ b/src/pgp_sequoia.c	Wed Oct 14 14:46:03 2020 +0200
     1.3 @@ -1981,14 +1981,15 @@
     1.4      if (!key || status != PEP_STATUS_OK) {
     1.5          ERROR_OUT (err, status,
     1.6                     "%s has no signing capable key", fpr);
     1.7 -    }               
     1.8 -    
     1.9 +    }
    1.10 +
    1.11      signing_keypair = pgp_key_into_key_pair (NULL, pgp_key_clone (key));
    1.12      pgp_key_free (key);
    1.13      if (! signing_keypair)
    1.14          ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a keypair");
    1.15  
    1.16      signer = pgp_key_pair_as_signer (signing_keypair);
    1.17 +    signing_keypair = NULL;
    1.18      if (! signer)
    1.19          ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");
    1.20  
    1.21 @@ -2031,11 +2032,7 @@
    1.22  
    1.23   out:
    1.24      pgp_signer_free (signer);
    1.25 -    // XXX: pgp_key_pair_as_signer is only supposed to reference
    1.26 -    // signing_keypair, but it consumes it.  If this is fixed, this
    1.27 -    // will become a leak.
    1.28 -    //
    1.29 -    //pgp_key_pair_free (signing_keypair);
    1.30 +    pgp_key_pair_free (signing_keypair);
    1.31      pgp_valid_key_amalgamation_free (ka);
    1.32      pgp_cert_valid_key_iter_free (iter);
    1.33      pgp_cert_free(signer_cert);
    1.34 @@ -2208,6 +2205,7 @@
    1.35              ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a keypair");
    1.36  
    1.37          signer = pgp_key_pair_as_signer (signing_keypair);
    1.38 +        signing_keypair = NULL;
    1.39          if (! signer)
    1.40              ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");
    1.41  
    1.42 @@ -2249,13 +2247,9 @@
    1.43      *ctext = t;
    1.44      (*ctext)[*csize] = 0;
    1.45  
    1.46 - out:    
    1.47 + out:
    1.48      pgp_signer_free (signer);
    1.49 -    // XXX: pgp_key_pair_as_signer is only supposed to reference
    1.50 -    // signing_keypair, but it consumes it.  If this is fixed, this
    1.51 -    // will become a leak.
    1.52 -    //
    1.53 -    // pgp_key_pair_free (signing_keypair);
    1.54 +    pgp_key_pair_free (signing_keypair);
    1.55      pgp_valid_key_amalgamation_free (ka);
    1.56      pgp_cert_valid_key_iter_free (iter);
    1.57      pgp_cert_free(signer_cert);
    1.58 @@ -3111,8 +3105,9 @@
    1.59      if (! keypair)
    1.60          ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a keypair");
    1.61  
    1.62 -    // signer references keypair.
    1.63 +    // signer takes ownership of keypair.
    1.64      signer = pgp_key_pair_as_signer (keypair);
    1.65 +    keypair = NULL;
    1.66      if (! signer)
    1.67          ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");
    1.68  
    1.69 @@ -3151,8 +3146,9 @@
    1.70              if (! subkey_keypair)
    1.71                  ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a keypair");
    1.72  
    1.73 -            // subkey_signer references subkey_keypair.
    1.74 +            // subkey_signer takes ownership subkey_keypair.
    1.75              subkey_signer = pgp_key_pair_as_signer (subkey_keypair);
    1.76 +            subkey_keypair = NULL;
    1.77              if (! signer)
    1.78                  ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");
    1.79          }
    1.80 @@ -3162,12 +3158,6 @@
    1.81              (&err, ka, signer, subkey_signer, t, &sigs, &sig_count);
    1.82          pgp_signer_free (subkey_signer);
    1.83          subkey_signer = NULL;
    1.84 -        // XXX: pgp_key_pair_as_signer is only supposed to reference
    1.85 -        // signing_keypair, but it consumes it.  If this is fixed,
    1.86 -        // this will become a leak.
    1.87 -        //
    1.88 -        //pgp_key_pair_free (subkey_keypair);
    1.89 -        subkey_keypair = NULL;
    1.90          if (sq_status)
    1.91              ERROR_OUT(err, PEP_UNKNOWN_ERROR,
    1.92                        "setting expiration (generating self signatures)");
    1.93 @@ -3227,14 +3217,10 @@
    1.94      pgp_valid_key_amalgamation_free (ka);
    1.95      pgp_cert_valid_key_iter_free (key_iter);
    1.96      pgp_signer_free (subkey_signer);
    1.97 -    // XXX: pgp_key_pair_as_signer is only supposed to reference
    1.98 -    // signing_keypair, but it consumes it.  If this is fixed, this
    1.99 -    // will become a leak.
   1.100 -    //
   1.101 -    //pgp_key_pair_free (subkey_keypair);
   1.102 +    pgp_key_pair_free (subkey_keypair);
   1.103      pgp_key_free (subkey);
   1.104      pgp_signer_free (signer);
   1.105 -    //pgp_key_pair_free (keypair);
   1.106 +    pgp_key_pair_free (keypair);
   1.107      pgp_key_free (key);
   1.108      pgp_cert_valid_key_iter_free (iter);
   1.109      pgp_cert_free(cert);
   1.110 @@ -3280,6 +3266,7 @@
   1.111          ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a keypair");
   1.112  
   1.113      signer = pgp_key_pair_as_signer (keypair);
   1.114 +    keypair = NULL;
   1.115      if (! signer)
   1.116          ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");
   1.117  
     2.1 --- a/test/src/Engine.h	Mon Oct 12 15:43:50 2020 +0200
     2.2 +++ b/test/src/Engine.h	Wed Oct 14 14:46:03 2020 +0200
     2.3 @@ -19,11 +19,12 @@
     2.4          void shut_down();
     2.5  
     2.6          PEP_SESSION session;
     2.7 -        
     2.8 -    protected:
     2.9 +
    2.10          string engine_home;
    2.11          string real_home;
    2.12          string prev_pgp_home;
    2.13 +
    2.14 +    protected:
    2.15          
    2.16          messageToSend_t cached_messageToSend;
    2.17          inject_sync_event_t cached_inject_sync_event;
     3.1 --- a/test/src/ImportKeyTest.cc	Mon Oct 12 15:43:50 2020 +0200
     3.2 +++ b/test/src/ImportKeyTest.cc	Wed Oct 14 14:46:03 2020 +0200
     3.3 @@ -1,6 +1,12 @@
     3.4  #include <stdlib.h>
     3.5  #include <string>
     3.6  #include <cstring>
     3.7 +#include <iostream>
     3.8 +#include <fstream>
     3.9 +#include <sys/types.h>
    3.10 +#include <sys/stat.h>
    3.11 +#include <unistd.h>
    3.12 +
    3.13  
    3.14  #include "pEpEngine.h"
    3.15  #include "test_util.h"
    3.16 @@ -66,17 +72,6 @@
    3.17                  session = NULL;
    3.18              }
    3.19  
    3.20 -            PEP_STATUS import_and_and_fix_key(string filename, stringlist_t** keylist, uint64_t* changes, char** fixed_key, size_t* fixed_key_size) {
    3.21 -                string pubkey = slurp(filename);
    3.22 -                PEP_STATUS status = _import_key_with_fpr_return(session, pubkey.c_str(), pubkey.size(), NULL, keylist, changes);
    3.23 -                if (status != PEP_KEY_IMPORTED)
    3.24 -                    return status;
    3.25 -                else if (*changes != 1)
    3.26 -                    return PEP_TEST_NO_KEY_IMPORT;    
    3.27 -                else
    3.28 -                    return export_key(session, (*keylist)->value, fixed_key, fixed_key_size);
    3.29 -            }
    3.30 -
    3.31          private:
    3.32              const char* test_suite_name;
    3.33              const char* test_name;
    3.34 @@ -133,27 +128,16 @@
    3.35  
    3.36  TEST_F(ImportKeyTest, check_import_change_pub_nochange) {
    3.37      PEP_STATUS status = PEP_STATUS_OK;
    3.38 -
    3.39 -    char* fixed_key = NULL;
    3.40 -    size_t fixed_key_size = 0;
    3.41 +    
    3.42 +    string pubkey = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    3.43      stringlist_t* keylist = NULL;
    3.44      uint64_t changes = 0;
    3.45 -
    3.46 -    // this checks to see if a key was imported and if it changed the first time.
    3.47 -    status = import_and_and_fix_key("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc", &keylist, &changes, &fixed_key, &fixed_key_size);    
    3.48 -    ASSERT_OK;
    3.49 -    string pubkey = string(fixed_key);
    3.50 -
    3.51 -    // N.B. This is transitional - ideally, we'll test it this way, but we first need to understand what the equality metric is and change the heuristic.
    3.52 -    // free_stringlist(keylist);
    3.53 -    // keylist = NULL;
    3.54 -    // uint64_t changes = 0;
    3.55 -    // status = _import_key_with_fpr_return(session, pubkey.c_str(), pubkey.size(), NULL, &keylist, &changes);
    3.56 -    // ASSERT_EQ(status, PEP_KEY_IMPORTED);
    3.57 -    // ASSERT_NE(keylist, nullptr);
    3.58 -    // ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
    3.59 -    // ASSERT_EQ(keylist->next, nullptr);
    3.60 -    // ASSERT_EQ(changes, 1);
    3.61 +    status = _import_key_with_fpr_return(session, pubkey.c_str(), pubkey.size(), NULL, &keylist, &changes);
    3.62 +    ASSERT_EQ(status, PEP_KEY_IMPORTED);
    3.63 +    ASSERT_NE(keylist, nullptr);
    3.64 +    ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
    3.65 +    ASSERT_EQ(keylist->next, nullptr);
    3.66 +    ASSERT_EQ(changes, 1);
    3.67  
    3.68      // import again!
    3.69      free_stringlist(keylist);
    3.70 @@ -167,6 +151,52 @@
    3.71      ASSERT_EQ(changes, 0);
    3.72  }
    3.73  
    3.74 +TEST_F(ImportKeyTest, check_import_change_pub_nochange_binary_bigkey) {
    3.75 +    PEP_STATUS status = PEP_STATUS_OK;
    3.76 +
    3.77 +    int retval = 0;
    3.78 +
    3.79 +#ifndef WIN32
    3.80 +    struct stat fst;
    3.81 +    retval = stat("test_keys/bigkey.pgp", &fst);
    3.82 +#else
    3.83 +    struct _stat fst;
    3.84 +    retval = _stat("test_keys/bigkey.pgp", &fst);
    3.85 +#endif
    3.86 +
    3.87 +    ASSERT_EQ(retval, 0);
    3.88 +    size_t img_size = (size_t)(fst.st_size);
    3.89 +    ASSERT_NE(img_size, 0);
    3.90 +    char* img = (char*)calloc(1, img_size);
    3.91 +
    3.92 +    ifstream img_file("test_keys/bigkey.pgp", ios::in | ios::binary);
    3.93 +
    3.94 +    img_file.read(img, img_size);
    3.95 +    img_file.close();
    3.96 +
    3.97 +    cout << img_size << endl;   
    3.98 +
    3.99 +    stringlist_t* keylist = NULL;
   3.100 +    uint64_t changes = 0;
   3.101 +    status = _import_key_with_fpr_return(session, img, img_size, NULL, &keylist, &changes);
   3.102 +    ASSERT_EQ(status, PEP_KEY_IMPORTED);
   3.103 +    ASSERT_NE(keylist, nullptr);
   3.104 +//    ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
   3.105 +    ASSERT_EQ(keylist->next, nullptr);
   3.106 +    ASSERT_EQ(changes, 1);
   3.107 +
   3.108 +    // import again!
   3.109 +    free_stringlist(keylist);
   3.110 +    keylist = NULL;
   3.111 +    changes = 0;
   3.112 +    status = _import_key_with_fpr_return(session, img, img_size, NULL, &keylist, &changes);
   3.113 +    ASSERT_EQ(status, PEP_KEY_IMPORTED);
   3.114 +    ASSERT_NE(keylist, nullptr);
   3.115 +  //  ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
   3.116 +    ASSERT_EQ(keylist->next, nullptr);
   3.117 +    ASSERT_EQ(changes, 0);
   3.118 +}
   3.119 +
   3.120  TEST_F(ImportKeyTest, check_import_change_wo_fpr_illegal) {
   3.121      PEP_STATUS status = PEP_STATUS_OK;
   3.122      
     4.1 Binary file test/test_keys/bigkey.pgp has changed