Browse Source

merged in sequoia branch

IOSAD-182 Release_2.1.3
parent
commit
c2213bdf55
4 changed files with 77 additions and 59 deletions
  1. +14
    -27
      src/pgp_sequoia.c
  2. +3
    -2
      test/src/Engine.h
  3. +60
    -30
      test/src/ImportKeyTest.cc
  4. BIN
      test/test_keys/bigkey.pgp

+ 14
- 27
src/pgp_sequoia.c View File

@ -1981,14 +1981,15 @@ PEP_STATUS pgp_sign_only(
if (!key || status != PEP_STATUS_OK) {
ERROR_OUT (err, status,
"%s has no signing capable key", fpr);
}
}
signing_keypair = pgp_key_into_key_pair (NULL, pgp_key_clone (key));
pgp_key_free (key);
if (! signing_keypair)
ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a keypair");
signer = pgp_key_pair_as_signer (signing_keypair);
signing_keypair = NULL;
if (! signer)
ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");
@ -2031,11 +2032,7 @@ PEP_STATUS pgp_sign_only(
out:
pgp_signer_free (signer);
// XXX: pgp_key_pair_as_signer is only supposed to reference
// signing_keypair, but it consumes it. If this is fixed, this
// will become a leak.
//
//pgp_key_pair_free (signing_keypair);
pgp_key_pair_free (signing_keypair);
pgp_valid_key_amalgamation_free (ka);
pgp_cert_valid_key_iter_free (iter);
pgp_cert_free(signer_cert);
@ -2208,6 +2205,7 @@ static PEP_STATUS pgp_encrypt_sign_optional(
ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a keypair");
signer = pgp_key_pair_as_signer (signing_keypair);
signing_keypair = NULL;
if (! signer)
ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");
@ -2249,13 +2247,9 @@ static PEP_STATUS pgp_encrypt_sign_optional(
*ctext = t;
(*ctext)[*csize] = 0;
out:
out:
pgp_signer_free (signer);
// XXX: pgp_key_pair_as_signer is only supposed to reference
// signing_keypair, but it consumes it. If this is fixed, this
// will become a leak.
//
// pgp_key_pair_free (signing_keypair);
pgp_key_pair_free (signing_keypair);
pgp_valid_key_amalgamation_free (ka);
pgp_cert_valid_key_iter_free (iter);
pgp_cert_free(signer_cert);
@ -3111,8 +3105,9 @@ PEP_STATUS pgp_renew_key(
if (! keypair)
ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a keypair");
// signer references keypair.
// signer takes ownership of keypair.
signer = pgp_key_pair_as_signer (keypair);
keypair = NULL;
if (! signer)
ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");
@ -3151,8 +3146,9 @@ PEP_STATUS pgp_renew_key(
if (! subkey_keypair)
ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a keypair");
// subkey_signer references subkey_keypair.
// subkey_signer takes ownership subkey_keypair.
subkey_signer = pgp_key_pair_as_signer (subkey_keypair);
subkey_keypair = NULL;
if (! signer)
ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");
}
@ -3162,12 +3158,6 @@ PEP_STATUS pgp_renew_key(
(&err, ka, signer, subkey_signer, t, &sigs, &sig_count);
pgp_signer_free (subkey_signer);
subkey_signer = NULL;
// XXX: pgp_key_pair_as_signer is only supposed to reference
// signing_keypair, but it consumes it. If this is fixed,
// this will become a leak.
//
//pgp_key_pair_free (subkey_keypair);
subkey_keypair = NULL;
if (sq_status)
ERROR_OUT(err, PEP_UNKNOWN_ERROR,
"setting expiration (generating self signatures)");
@ -3227,14 +3217,10 @@ PEP_STATUS pgp_renew_key(
pgp_valid_key_amalgamation_free (ka);
pgp_cert_valid_key_iter_free (key_iter);
pgp_signer_free (subkey_signer);
// XXX: pgp_key_pair_as_signer is only supposed to reference
// signing_keypair, but it consumes it. If this is fixed, this
// will become a leak.
//
//pgp_key_pair_free (subkey_keypair);
pgp_key_pair_free (subkey_keypair);
pgp_key_free (subkey);
pgp_signer_free (signer);
//pgp_key_pair_free (keypair);
pgp_key_pair_free (keypair);
pgp_key_free (key);
pgp_cert_valid_key_iter_free (iter);
pgp_cert_free(cert);
@ -3280,6 +3266,7 @@ PEP_STATUS pgp_revoke_key(
ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a keypair");
signer = pgp_key_pair_as_signer (keypair);
keypair = NULL;
if (! signer)
ERROR_OUT (err, PEP_UNKNOWN_ERROR, "Creating a signer");


+ 3
- 2
test/src/Engine.h View File

@ -19,11 +19,12 @@ class Engine {
void shut_down();
PEP_SESSION session;
protected:
string engine_home;
string real_home;
string prev_pgp_home;
protected:
messageToSend_t cached_messageToSend;
inject_sync_event_t cached_inject_sync_event;


+ 60
- 30
test/src/ImportKeyTest.cc View File

@ -1,6 +1,12 @@
#include <stdlib.h>
#include <string>
#include <cstring>
#include <iostream>
#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "pEpEngine.h"
#include "test_util.h"
@ -66,17 +72,6 @@ namespace {
session = NULL;
}
PEP_STATUS import_and_and_fix_key(string filename, stringlist_t** keylist, uint64_t* changes, char** fixed_key, size_t* fixed_key_size) {
string pubkey = slurp(filename);
PEP_STATUS status = _import_key_with_fpr_return(session, pubkey.c_str(), pubkey.size(), NULL, keylist, changes);
if (status != PEP_KEY_IMPORTED)
return status;
else if (*changes != 1)
return PEP_TEST_NO_KEY_IMPORT;
else
return export_key(session, (*keylist)->value, fixed_key, fixed_key_size);
}
private:
const char* test_suite_name;
const char* test_name;
@ -133,27 +128,16 @@ TEST_F(ImportKeyTest, check_import_fpr_priv_new) {
TEST_F(ImportKeyTest, check_import_change_pub_nochange) {
PEP_STATUS status = PEP_STATUS_OK;
char* fixed_key = NULL;
size_t fixed_key_size = 0;
string pubkey = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
stringlist_t* keylist = NULL;
uint64_t changes = 0;
// this checks to see if a key was imported and if it changed the first time.
status = import_and_and_fix_key("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc", &keylist, &changes, &fixed_key, &fixed_key_size);
ASSERT_OK;
string pubkey = string(fixed_key);
// 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.
// free_stringlist(keylist);
// keylist = NULL;
// uint64_t changes = 0;
// status = _import_key_with_fpr_return(session, pubkey.c_str(), pubkey.size(), NULL, &keylist, &changes);
// ASSERT_EQ(status, PEP_KEY_IMPORTED);
// ASSERT_NE(keylist, nullptr);
// ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
// ASSERT_EQ(keylist->next, nullptr);
// ASSERT_EQ(changes, 1);
status = _import_key_with_fpr_return(session, pubkey.c_str(), pubkey.size(), NULL, &keylist, &changes);
ASSERT_EQ(status, PEP_KEY_IMPORTED);
ASSERT_NE(keylist, nullptr);
ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
ASSERT_EQ(keylist->next, nullptr);
ASSERT_EQ(changes, 1);
// import again!
free_stringlist(keylist);
@ -167,6 +151,52 @@ TEST_F(ImportKeyTest, check_import_change_pub_nochange) {
ASSERT_EQ(changes, 0);
}
TEST_F(ImportKeyTest, check_import_change_pub_nochange_binary_bigkey) {
PEP_STATUS status = PEP_STATUS_OK;
int retval = 0;
#ifndef WIN32
struct stat fst;
retval = stat("test_keys/bigkey.pgp", &fst);
#else
struct _stat fst;
retval = _stat("test_keys/bigkey.pgp", &fst);
#endif
ASSERT_EQ(retval, 0);
size_t img_size = (size_t)(fst.st_size);
ASSERT_NE(img_size, 0);
char* img = (char*)calloc(1, img_size);
ifstream img_file("test_keys/bigkey.pgp", ios::in | ios::binary);
img_file.read(img, img_size);
img_file.close();
cout << img_size << endl;
stringlist_t* keylist = NULL;
uint64_t changes = 0;
status = _import_key_with_fpr_return(session, img, img_size, NULL, &keylist, &changes);
ASSERT_EQ(status, PEP_KEY_IMPORTED);
ASSERT_NE(keylist, nullptr);
// ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
ASSERT_EQ(keylist->next, nullptr);
ASSERT_EQ(changes, 1);
// import again!
free_stringlist(keylist);
keylist = NULL;
changes = 0;
status = _import_key_with_fpr_return(session, img, img_size, NULL, &keylist, &changes);
ASSERT_EQ(status, PEP_KEY_IMPORTED);
ASSERT_NE(keylist, nullptr);
// ASSERT_STREQ(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
ASSERT_EQ(keylist->next, nullptr);
ASSERT_EQ(changes, 0);
}
TEST_F(ImportKeyTest, check_import_change_wo_fpr_illegal) {
PEP_STATUS status = PEP_STATUS_OK;


BIN
test/test_keys/bigkey.pgp View File


Loading…
Cancel
Save