Compare commits

...

15 Commits
master ... sync

Author SHA1 Message Date
Krista Bennett f6229c5995 Converted .hgignore to .gitignore 2 years ago
Krista 'DarthMama' Bennett 8516a5c215 Merged in 762 fix, will do patch release once sequoia recompiled and tested 3 years ago
Krista 'DarthMama' Bennett 23ec2f71d1 Bump patch version 3 years ago
Krista 'DarthMama' Bennett 7d7695bf74 Added tag Release_2.0.6 for changeset ebb62ba262dd 3 years ago
Krista 'DarthMama' Bennett e907105ad9 ENGINE-755: now works and is tested, though if we want to do this right we should modify the rest of the test as well... !!!!!!!!REQUIRES LIBETPAN UPDATE!!!!!!!! 3 years ago
Krista 'DarthMama' Bennett a858d0efc8 cross-branch test contamination maybe? 3 years ago
Krista 'DarthMama' Bennett 1e9cfb261b Bump patch version 3 years ago
Krista 'DarthMama' Bennett ece740c75a Added tag Release_2.0.5 for changeset 3db667f48863 3 years ago
Krista 'DarthMama' Bennett 073cd2b527 Don't call pkg-config if the sequoia vars are already set in local.conf - we should probably refactor this so local.conf comes afterward anyway. I don't understand damiano's reasoning here. 3 years ago
Krista 'DarthMama' Bennett 131c5b74c2 upgraded sync patch version 3 years ago
Krista 'DarthMama' Bennett 360fb6811c Added tag Release_2.0.4 for changeset fe0eb4d17b11 3 years ago
Krista 'DarthMama' Bennett 4442c0cd41 Fixed tests and added test for revoked message key reset responses for PGP users 3 years ago
Krista 'DarthMama' Bennett 3b8e43c1fe Fixed origin of null user_id problem for non-empty from. 3 years ago
Krista 'DarthMama' Bennett 065b02ade4 ENGINE-751: First fix, tests not adjusted, committing changes to fix other bug found here 3 years ago
Krista 'DarthMama' Bennett e816306770 Fixed tests. 3 years ago

@ -1,14 +1,12 @@
syntax: regexp
^asn\.1/.*\.(c|h)$
^asn\.1/libasn1\.a$
.*xcuserdata/
^build/
^local.conf
^test_home/
syntax: glob
asn.1/Makefile.am.*
asn.1/converter-example.mk
asn.1/libasn1.a
local.conf
build/
test_home/
asn.1/*.c
asn.1/*.h
xcuserdata/
*.orig
*.old
*.d

@ -305,13 +305,24 @@ endif
######### Post processing assignments ########
# These variables are ineffective when set anywhere else but here.
# KB: I have no idea why we do this - it totally defeats the purpose of
# local.conf.
# For now: set if has no value.
ifeq ($(OPENPGP),SEQUOIA)
SEQUOIA_CFLAGS=$(shell pkg-config --cflags-only-other sequoia-openpgp)
SEQUOIA_LDFLAGS=$(shell pkg-config --libs-only-l --libs-only-other sequoia-openpgp)
SEQUOIA_LIB=$(shell pkg-config --libs-only-L sequoia-openpgp)
SEQUOIA_INC=$(shell pkg-config --cflags-only-I sequoia-openpgp)
CFLAGS+= $(SEQUOIA_CFLAGS)
LD_FLAGS+= $(SEQUOIA_LDFLAGS)
ifeq ($(SEQUOIA_CFLAGS),)
SEQUOIA_CFLAGS=$(shell pkg-config --cflags-only-other sequoia-openpgp)
endif
ifeq ($(SEQUOIA_LDFLAGS),)
SEQUOIA_LDFLAGS=$(shell pkg-config --libs-only-l --libs-only-other sequoia-openpgp)
endif
ifeq ($(SEQUOIA_LIB),)
SEQUOIA_LIB=$(shell pkg-config --libs-only-L sequoia-openpgp)
endif
ifeq ($(SEQUOIA_INC),)
SEQUOIA_INC=$(shell pkg-config --cflags-only-I sequoia-openpgp)
endif
CFLAGS+= $(SEQUOIA_CFLAGS)
LD_FLAGS+= $(SEQUOIA_LDFLAGS)
endif
# YML_PATH is needed in the environment of every call to a program of the YML2 distribution

@ -569,10 +569,25 @@ struct mailimf_mailbox * mailbox_from_string(
if (_name == NULL)
goto enomem;
_address = strdup(address);
if (_address == NULL)
goto enomem;
char* at = strstr(address, "@");
if (!at) {
// Presumed URI
int added_char_len = 6; // " " @URI
int new_addr_len = strlen(address) + added_char_len + 1;
_address = calloc(new_addr_len, 1);
if (_address == NULL)
goto enomem;
_address[0] = '"';
strlcat(_address, address, new_addr_len);
strlcat(_address, "\"@URI", new_addr_len);
}
else {
_address = strdup(address);
if (_address == NULL)
goto enomem;
}
mb = mailimf_mailbox_new(_name, _address);
assert(mb);
if (mb == NULL)
@ -1990,6 +2005,7 @@ pEp_error:
static pEp_identity *mailbox_to_identity(const struct mailimf_mailbox * mb)
{
char *username = NULL;
char *address = NULL;
assert(mb);
assert(mb->mb_addr_spec);
@ -2005,14 +2021,30 @@ static pEp_identity *mailbox_to_identity(const struct mailimf_mailbox * mb)
goto enomem;
}
pEp_identity *ident = new_identity(mb->mb_addr_spec, NULL, NULL, username);
const char* raw_addr = mb->mb_addr_spec;
if (raw_addr && raw_addr[0] == '"') {
int addr_len = strlen(raw_addr);
if (addr_len >= 6) { // ""@URI
const char* endcheck = strstr(raw_addr + 1, "\"@URI");
if (endcheck && *(endcheck + 5) == '\0') {
int actual_size = addr_len - 6;
address = calloc(actual_size + 1, 1);
if (!address)
goto enomem;
strlcpy(address, raw_addr + 1, actual_size + 1);
}
}
}
pEp_identity *ident = new_identity(address ? address : raw_addr, NULL, NULL, username);
if (ident == NULL)
goto enomem;
free(username);
free(address);
return ident;
enomem:
free(address);
free(username);
return NULL;
}

@ -782,6 +782,16 @@ PEP_STATUS send_key_reset_to_recents(PEP_SESSION session,
if (is_me(session, curr_id))
continue;
// Also, don't bother to send it to non-pEp-users
bool pEp_user = false;
status = is_pEp_user(session, curr_id, &pEp_user);
if (status != PEP_STATUS_OK)
goto pEp_free;
if (!pEp_user)
continue;
// Check if they've already been told - this shouldn't be the case, but...
bool contacted = false;
status = has_key_reset_been_sent(session, from_ident->address, user_id, old_fpr, &contacted);

@ -3203,8 +3203,11 @@ static PEP_STATUS reconcile_src_and_inner_messages(message* src,
PEP_STATUS status = PEP_STATUS_OK;
if (strcasecmp(src->from->address, inner_message->from->address) == 0)
if (src->from && inner_message->from &&
src->from->address && inner_message->from->address &&
strcasecmp(src->from->address, inner_message->from->address) == 0) {
status = reconcile_identity(src->from, inner_message->from);
}
if (status == PEP_STATUS_OK && inner_message->to)
status = reconcile_identity_lists(src->to, inner_message->to);
@ -3909,30 +3912,30 @@ static PEP_STATUS _decrypt_message(
} // this we do if this isn't an inner message
pEp_identity* cs_from = calculated_src->from;
if (cs_from && !EMPTYSTR(cs_from->address)) {
if (!is_me(session, cs_from)) {
status = update_identity(session, cs_from);
pEp_identity* msg_from = msg->from;
if (msg_from && !EMPTYSTR(msg_from->address)) {
if (!is_me(session, msg_from)) {
status = update_identity(session, msg_from);
if (status == PEP_CANNOT_FIND_IDENTITY) {
cs_from->user_id = calloc(1, strlen(cs_from->address) + 6);
if (!cs_from->user_id)
msg_from->user_id = calloc(1, strlen(msg_from->address) + 6);
if (!msg_from->user_id)
return PEP_OUT_OF_MEMORY;
snprintf(cs_from->user_id, strlen(cs_from->address) + 6,
"TOFU_%s", cs_from->address);
snprintf(msg_from->user_id, strlen(msg_from->address) + 6,
"TOFU_%s", msg_from->address);
status = PEP_STATUS_OK;
}
}
else {
// update the own from identity, read_only, but preserve username
// for returned message.
char* cached_ownname = cs_from->username;
char* cached_ownname = msg_from->username;
// Shouldn't be possible, but just in case.
if (!cached_ownname)
cached_ownname = strdup(cs_from->address);
cs_from->username = NULL;
status = _myself(session, cs_from, false, false, myself_read_only);
free(cs_from->username);
cs_from->username = cached_ownname;
cached_ownname = strdup(msg_from->address);
msg_from->username = NULL;
status = _myself(session, msg_from, false, false, myself_read_only);
free(msg_from->username);
msg_from->username = cached_ownname;
}
}
} // end if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED)
@ -3943,7 +3946,7 @@ static PEP_STATUS _decrypt_message(
// eligible signer comm_types to PEP_ct_pEp_*
// This also sets and upgrades pEp version
if (decrypt_status == PEP_DECRYPTED_AND_VERIFIED && !is_key_reset && is_pEp_msg && calculated_src->from)
status = update_sender_to_pEp_trust(session, calculated_src->from, _keylist, major_ver, minor_ver);
status = update_sender_to_pEp_trust(session, msg->from, _keylist, major_ver, minor_ver);
/* Ok, now we have a keylist used for decryption/verification.
now we need to update the message rating with the
@ -3951,7 +3954,7 @@ static PEP_STATUS _decrypt_message(
if (!is_key_reset) { // key reset messages invalidate some of the ratings in the DB by now.
status = amend_rating_according_to_sender_and_recipients(session,
rating, calculated_src->from, _keylist);
rating, msg->from, _keylist);
if (status != PEP_STATUS_OK)
goto pEp_error;
@ -4010,98 +4013,107 @@ static PEP_STATUS _decrypt_message(
}
} // End prepare output message for return
// 3. Check to see if the sender used any of our revoked keys
if (!is_me(session, msg->from)) {
status = check_for_own_revoked_key(session, _keylist, &revoke_replace_pairs);
// 3. Check to see if the sender is a pEp user who used any of our revoked keys
if (msg->from && !is_me(session, msg->from)) {
bool pEp_peep = false;
//assert(status != PEP_STATUS_OK); // FIXME: FOR DEBUGGING ONLY DO NOT LEAVE IN
if (status != PEP_STATUS_OK) {
// This should really never choke unless the DB is broken.
status = PEP_UNKNOWN_DB_ERROR;
goto pEp_error;
}
if (msg) {
stringpair_list_t* curr_pair_node;
stringpair_t* curr_pair;
for (curr_pair_node = revoke_replace_pairs; curr_pair_node; curr_pair_node = curr_pair_node->next) {
curr_pair = curr_pair_node->value;
if (!EMPTYSTR(msg->from->user_id)) {
status = is_pEp_user(session, msg->from, &pEp_peep);
// If it's a pEp user, check if there was a revoked key used so we can notify
if (pEp_peep) {
status = check_for_own_revoked_key(session, _keylist, &revoke_replace_pairs);
if (!curr_pair)
continue; // Again, shouldn't occur
//assert(status != PEP_STATUS_OK); // FIXME: FOR DEBUGGING ONLY DO NOT LEAVE IN
if (status != PEP_STATUS_OK) {
// This should really never choke unless the DB is broken.
status = PEP_UNKNOWN_DB_ERROR;
goto pEp_error;
}
if (msg) {
stringpair_list_t* curr_pair_node;
stringpair_t* curr_pair;
if (curr_pair->key && curr_pair->value) {
/* Figure out which address(es) this came to so we know who to reply from */
for (curr_pair_node = revoke_replace_pairs; curr_pair_node; curr_pair_node = curr_pair_node->next) {
curr_pair = curr_pair_node->value;
identity_list* my_rev_ids = NULL;
/* check by replacement ID for identities which used this key? */
status = get_identities_by_main_key_id(session, curr_pair->value,
&my_rev_ids);
if (status == PEP_STATUS_OK && my_rev_ids) {
// get identities in this list the message was to/cc'd to (not for bcc)
identity_list* used_ids_for_key = NULL;
status = ident_list_intersect(my_rev_ids, msg->to, &used_ids_for_key);
if (status != PEP_STATUS_OK)
goto pEp_error; // out of memory
if (!curr_pair)
continue; // Again, shouldn't occur
identity_list* used_cc_ids = NULL;
status = ident_list_intersect(my_rev_ids, msg->cc, &used_cc_ids);
if (status != PEP_STATUS_OK)
goto pEp_error;
if (curr_pair->key && curr_pair->value) {
/* Figure out which address(es) this came to so we know who to reply from */
used_ids_for_key = identity_list_join(used_ids_for_key, used_cc_ids);
identity_list* curr_recip = used_ids_for_key;
for ( ; curr_recip && curr_recip->ident; curr_recip = curr_recip->next) {
if (!is_me(session, curr_recip->ident))
continue;
status = create_standalone_key_reset_message(session,
&reset_msg,
curr_recip->ident,
msg->from,
curr_pair->key,
curr_pair->value);
// If we can't find the identity, this is someone we've never mailed, so we just
// go on letting them use the wrong key until we mail them ourselves. (Spammers, etc)
if (status != PEP_CANNOT_FIND_IDENTITY) {
identity_list* my_rev_ids = NULL;
/* check by replacement ID for identities which used this key? */
status = get_identities_by_main_key_id(session, curr_pair->value,
&my_rev_ids);
if (status == PEP_STATUS_OK && my_rev_ids) {
// get identities in this list the message was to/cc'd to (not for bcc)
identity_list* used_ids_for_key = NULL;
status = ident_list_intersect(my_rev_ids, msg->to, &used_ids_for_key);
if (status != PEP_STATUS_OK)
goto pEp_error;
goto pEp_error; // out of memory
if (!reset_msg) {
status = PEP_OUT_OF_MEMORY;
identity_list* used_cc_ids = NULL;
status = ident_list_intersect(my_rev_ids, msg->cc, &used_cc_ids);
if (status != PEP_STATUS_OK)
goto pEp_error;
}
// insert into queue
if (session->messageToSend)
status = session->messageToSend(reset_msg);
else
status = PEP_SYNC_NO_MESSAGE_SEND_CALLBACK;
if (status == PEP_STATUS_OK) {
// Put into notified DB
status = set_reset_contact_notified(session, curr_recip->ident->address, curr_pair->key, msg->from->user_id);
if (status != PEP_STATUS_OK) // It's ok to barf because it's a DB problem??
goto pEp_error;
}
else {
// According to Volker, this would only be a fatal error, so...
free_message(reset_msg); // ??
reset_msg = NULL; // ??
goto pEp_error;
}
}
}
} // else we couldn't find an ident for replacement key
used_ids_for_key = identity_list_join(used_ids_for_key, used_cc_ids);
identity_list* curr_recip = used_ids_for_key;
for ( ; curr_recip && curr_recip->ident; curr_recip = curr_recip->next) {
if (!is_me(session, curr_recip->ident))
continue;
status = create_standalone_key_reset_message(session,
&reset_msg,
curr_recip->ident,
msg->from,
curr_pair->key,
curr_pair->value);
// If we can't find the identity, this is someone we've never mailed, so we just
// go on letting them use the wrong key until we mail them ourselves. (Spammers, etc)
if (status != PEP_CANNOT_FIND_IDENTITY) {
if (status != PEP_STATUS_OK)
goto pEp_error;
if (!reset_msg) {
status = PEP_OUT_OF_MEMORY;
goto pEp_error;
}
// insert into queue
if (session->messageToSend)
status = session->messageToSend(reset_msg);
else
status = PEP_SYNC_NO_MESSAGE_SEND_CALLBACK;
if (status == PEP_STATUS_OK) {
// Put into notified DB
status = set_reset_contact_notified(session, curr_recip->ident->address, curr_pair->key, msg->from->user_id);
if (status != PEP_STATUS_OK) // It's ok to barf because it's a DB problem??
goto pEp_error;
}
else {
// According to Volker, this would only be a fatal error, so...
free_message(reset_msg); // ??
reset_msg = NULL; // ??
goto pEp_error;
}
}
}
} // else we couldn't find an ident for replacement key
}
}
}
}
}
}
free_stringpair_list(revoke_replace_pairs);
revoke_replace_pairs = NULL;
} // end !is_me(msg->from)

@ -21,11 +21,11 @@ extern "C" {
// RELEASE version this targets
// (string: major.minor.patch)
#define PEP_ENGINE_VERSION "2.0.4"
#define PEP_ENGINE_VERSION "2.0.7"
// Numeric values of above:
#define PEP_ENGINE_VERSION_MAJOR 2
#define PEP_ENGINE_VERSION_MINOR 0
#define PEP_ENGINE_VERSION_PATCH 4
#define PEP_ENGINE_VERSION_PATCH 7
#define PEP_OWN_USERID "pEp_own_userId"

@ -100,25 +100,34 @@ int sq_sql_trace_callback (unsigned trace_constant,
void* context_ptr,
void* P,
void* X) {
const char* TC_str = "";
const char* info_str = "";
const char* title = "SEQUOIA_SQL_DEBUG";
switch (trace_constant) {
case SQLITE_TRACE_STMT:
fprintf(stderr, "SEQUOIA_SQL_DEBUG: STMT - ");
const char* X_str = (const char*) X;
if (!EMPTYSTR(X_str) && X_str[0] == '-' && X_str[1] == '-')
fprintf(stderr, "%s\n", X_str);
else
fprintf(stderr, "%s\n", sqlite3_expanded_sql((sqlite3_stmt*)P));
TC_str = "STMT";
info_str = (const char*) X;
if (EMPTYSTR(info_str) || info_str[0] != '-' || info_str[1] != '-')
info_str = sqlite3_expanded_sql((sqlite3_stmt*)P);
break;
case SQLITE_TRACE_ROW:
fprintf(stderr, "SEQUOIA_SQL_DEBUG: ROW - ");
fprintf(stderr, "%s\n", sqlite3_expanded_sql((sqlite3_stmt*)P));
TC_str = "ROW";
info_str = sqlite3_expanded_sql((sqlite3_stmt*)P);
break;
case SQLITE_TRACE_CLOSE:
fprintf(stderr, "SEQUOIA_SQL_DEBUG: CLOSE - ");
TC_str = "CLOSE";
break;
default:
break;
}
#ifndef ANDROID
fprintf(stderr, "%s: %s - %s\n", title, TC_str, info_str);
#else
__android_log_print(ANDROID_LOG_DEBUG, "pEpEngine", " %s :: %s :: %s :: %s ",
title, TC_str, info_str, NULL);
#endif
return 0;
}
#endif
@ -781,6 +790,7 @@ static PEP_STATUS cert_save(PEP_SESSION session, pgp_cert_t cert,
char *email = NULL;
char *name = NULL;
T("cert_save - begin transaction for saving %s", fpr);
sqlite3_stmt *stmt = session->sq_sql.begin_transaction;
int sqlite_result = sqlite3_step(stmt);
sqlite3_reset(stmt);
@ -788,7 +798,8 @@ static PEP_STATUS cert_save(PEP_SESSION session, pgp_cert_t cert,
ERROR_OUT(NULL, PEP_UNKNOWN_ERROR,
"begin transaction failed: %s",
sqlite3_errmsg(session->key_db));
T("cert_save - successfully began transaction for saving %s", fpr);
pgp_fpr = pgp_cert_fingerprint(cert);
fpr = pgp_fingerprint_to_hex(pgp_fpr);
T("(%s, private_idents: %s)", fpr, private_idents ? "yes" : "no");
@ -934,16 +945,22 @@ static PEP_STATUS cert_save(PEP_SESSION session, pgp_cert_t cert,
// Prevent ERROR_OUT from causing an infinite loop.
if (! tried_commit) {
tried_commit = 1;
T("cert_save - about to %s transaction for saving %s",
(status == PEP_STATUS_OK ? "commit" : "roll back"),
fpr);
stmt = status == PEP_STATUS_OK
? session->sq_sql.commit_transaction
: session->sq_sql.rollback_transaction;
int sqlite_result = sqlite3_step(stmt);
sqlite3_reset(stmt);
sqlite3_reset(stmt);
if (sqlite_result != SQLITE_DONE)
ERROR_OUT(NULL, PEP_UNKNOWN_ERROR,
status == PEP_STATUS_OK
? "commit failed: %s" : "rollback failed: %s",
sqlite3_errmsg(session->key_db));
T("cert_save - %s transaction for saving %s",
(status == PEP_STATUS_OK ? "committed" : "rolled back"),
fpr);
}
T("(%s) -> %s", fpr, pEp_status_to_string(status));
@ -2366,17 +2383,6 @@ PEP_STATUS _pgp_import_keydata(PEP_SESSION session, const char *key_data,
break;
}
int int_result = sqlite3_exec(
session->key_db,
"PRAGMA wal_checkpoint(FULL);\n"
,
NULL,
NULL,
NULL
);
if (int_result != SQLITE_OK)
status = PEP_UNKNOWN_DB_ERROR;
out:
pgp_cert_parser_free(parser);

@ -87,10 +87,10 @@ TEST_F(CleanInvalidOwnKeysTest, check_clean_invalid_own_keys_no_alts_revoked) {
pEp_identity* alice = NULL;
PEP_STATUS status = get_identity(session, "pep.test.alice@pep-project.org", "ALICE", &alice);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_EQ(alice->fpr, nullptr);
ASSERT_STRNE(alice->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
char* fpr = NULL;
status = get_user_default_key(session, "ALICE", &fpr);
ASSERT_EQ(fpr, nullptr);
ASSERT_STREQ(fpr, alice->fpr);
ASSERT_EQ(status, PEP_STATUS_OK);
}
@ -100,10 +100,10 @@ TEST_F(CleanInvalidOwnKeysTest, check_clean_invalid_own_keys_no_alts_mistrusted)
pEp_identity* alice = NULL;
PEP_STATUS status = get_identity(session, "pep.test.alice@pep-project.org", "ALICE", &alice);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_EQ(alice->fpr, nullptr);
ASSERT_STRNE(alice->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
char* fpr = NULL;
status = get_user_default_key(session, "ALICE", &fpr);
ASSERT_EQ(fpr, nullptr);
ASSERT_STREQ(fpr, alice->fpr);
ASSERT_EQ(status, PEP_STATUS_OK);
}
@ -113,13 +113,12 @@ TEST_F(CleanInvalidOwnKeysTest, check_clean_invalid_own_keys_no_alts_expired) {
pEp_identity* bob = NULL;
PEP_STATUS status = get_identity(session, "expired_bob_0@darthmama.org", "BOB", &bob);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_NE(bob->fpr, nullptr);
ASSERT_STREQ(bob->fpr, "E4A8CD51C25D0ED5BAD0834BD2FDE305A35FE3F5");
char* fpr = NULL;
status = get_user_default_key(session, "BOB", &fpr);
ASSERT_NE(fpr, nullptr);
ASSERT_STREQ(fpr, "E4A8CD51C25D0ED5BAD0834BD2FDE305A35FE3F5");
ASSERT_EQ(status, PEP_STATUS_OK);
bool expired = true;
status = key_expired(session, bob->fpr, time(NULL), &expired);
ASSERT_FALSE(expired);
ASSERT_STREQ(bob->fpr, fpr);
}

@ -353,3 +353,268 @@ TEST_F(EncryptForIdentityTest, check_encrypt_for_identity) {
}
output_stream << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
}
TEST_F(EncryptForIdentityTest, check_encrypt_for_identity_with_URI) {
// message_api test code
const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
const string gabrielle_pub_key = slurp("test_keys/pub/pep-test-gabrielle-0xE203586C_pub.asc");
const string bella_pub_key = slurp("test_keys/pub/pep.test.bella-0xAF516AAE_pub.asc");
PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
ASSERT_EQ(statuspub, PEP_TEST_KEY_IMPORT_SUCCESS);
ASSERT_EQ(statuspriv, PEP_TEST_KEY_IMPORT_SUCCESS);
statuspub = import_key(session, gabrielle_pub_key.c_str(), gabrielle_pub_key.length(), NULL);
ASSERT_EQ(statuspub, PEP_TEST_KEY_IMPORT_SUCCESS);
statuspub = import_key(session, bella_pub_key.c_str(), bella_pub_key.length(), NULL);
ASSERT_EQ(statuspub, PEP_TEST_KEY_IMPORT_SUCCESS);
const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
const char* gabrielle_fpr = "906C9B8349954E82C5623C3C8C541BD4E203586C";
const char* bella_fpr = "5631BF1357326A02AA470EEEB815EF7FA4516AAE";
const char* nobody_fpr = "1111111111111111111111111111111111111111";
output_stream << "creating message…\n";
pEp_identity* alice = new_identity("payto://BIC/SYSTEMA", alice_fpr, PEP_OWN_USERID, "Alice Test");
pEp_identity* bob = new_identity("payto://BIC/SYSTEMB", NULL, "42", "Bob Test");
alice->me = true;
PEP_STATUS mystatus = set_own_key(session, alice, alice_fpr);
ASSERT_EQ(mystatus, PEP_STATUS_OK);
identity_list* to_list = new_identity_list(bob); // to bob
message* outgoing_message = new_message(PEP_dir_outgoing);
ASSERT_NE(outgoing_message, nullptr);
outgoing_message->from = alice;
outgoing_message->to = to_list;
outgoing_message->shortmsg = strdup("Greetings, humans!");
outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
output_stream << "message created.\n";
char* encoded_text = nullptr;
PEP_STATUS status = mime_encode_message(outgoing_message, false, &encoded_text);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_NE(encoded_text, nullptr);
output_stream << "decrypted:\n\n";
output_stream << encoded_text << "\n";
free(encoded_text);
message* encrypted_msg = nullptr;
output_stream << "calling encrypt_message_for_identity()\n";
status = encrypt_message_for_self(session, alice, outgoing_message, NULL, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
output_stream << "encrypt_message() returns " << tl_status_string(status) << '.' << endl;
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_NE(encrypted_msg, nullptr);
output_stream << "message encrypted.\n";
status = mime_encode_message(encrypted_msg, false, &encoded_text);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_NE(encoded_text, nullptr);
output_stream << "encrypted:\n\n";
output_stream << encoded_text << "\n";
message* decoded_msg = nullptr;
status = mime_decode_message(encoded_text, strlen(encoded_text), &decoded_msg);
ASSERT_EQ(status, PEP_STATUS_OK);
const string string3 = encoded_text;
unlink("tmp/msg_encrypt_for_self.asc");
ofstream outFile3("tmp/msg_encrypt_for_self.asc");
outFile3.write(string3.c_str(), string3.size());
outFile3.close();
message* decrypted_msg = nullptr;
stringlist_t* keylist_used = nullptr;
PEP_rating rating;
PEP_decrypt_flags_t flags;
flags = 0;
status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
ASSERT_NE(decrypted_msg, nullptr);
ASSERT_NE(keylist_used, nullptr);
ASSERT_NE(rating, 0);
ASSERT_TRUE(status == PEP_DECRYPTED && rating == PEP_rating_unreliable);
PEP_comm_type ct = encrypted_msg->from->comm_type;
ASSERT_TRUE(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed);
output_stream << "keys used:\n";
int i = 0;
for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++)
{
if (i == 0) {
ASSERT_STRCASEEQ("",kl4->value);
}
else {
output_stream << "\t " << kl4->value << endl;
ASSERT_STRCASEEQ("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value);
output_stream << "Encrypted for Alice! Yay! It worked!" << endl;
}
ASSERT_LT(i , 2);
}
output_stream << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
output_stream << "freeing messages…\n";
free_message(encrypted_msg);
free_message(decrypted_msg);
free_stringlist (keylist_used);
output_stream << "done.\n";
output_stream << "Now encrypt for self with extra keys." << endl;
stringlist_t* extra_keys = new_stringlist(gabrielle_fpr);
stringlist_add(extra_keys, bella_fpr);
encrypted_msg = NULL;
decrypted_msg = NULL;
keylist_used = NULL;
output_stream << "calling encrypt_message_for_identity()\n";
status = encrypt_message_for_self(session, alice, outgoing_message, extra_keys, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
output_stream << "encrypt_message() returns " << tl_status_string(status) << '.' << endl;
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_NE(encrypted_msg, nullptr);
output_stream << "message encrypted.\n";
flags = 0;
status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
ASSERT_NE(decrypted_msg, nullptr);
ASSERT_NE(keylist_used, nullptr);
ASSERT_NE(rating, 0);
ASSERT_TRUE(status == PEP_DECRYPTED && rating == PEP_rating_unreliable);
ct = encrypted_msg->from->comm_type;
ASSERT_TRUE(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed);
output_stream << "keys used:\n";
for (stringlist_t* incoming_kl = extra_keys; incoming_kl && incoming_kl->value; incoming_kl = incoming_kl->next) {
bool found = false;
output_stream << "Encrypted for: ";
for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++) {
if (strcasecmp(incoming_kl->value, kl4->value) == 0) {
output_stream << "\t " << kl4->value;
found = true;
break;
}
}
output_stream << endl;
ASSERT_TRUE(found);
}
output_stream << "Encrypted for all the extra keys!" << endl;
bool found = false;
for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
{
if (strcasecmp(alice_fpr, kl4->value) == 0) {
found = true;
output_stream << "Encrypted also for Alice! Yay!" << endl;
break;
}
}
ASSERT_TRUE(found);
free_message(encrypted_msg);
encrypted_msg = NULL;
free_message(decrypted_msg);
decrypted_msg = NULL;
free_stringlist(keylist_used);
keylist_used = NULL;
output_stream << "Now add a bad fpr." << endl;
stringlist_add(extra_keys, nobody_fpr);
output_stream << "calling encrypt_message_for_identity()\n";
status = encrypt_message_for_self(session, alice, outgoing_message, extra_keys, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
output_stream << "encrypt_message() returns " << tl_status_string(status) << '.' << endl;
ASSERT_NE(status, PEP_STATUS_OK);
free_message(outgoing_message);
outgoing_message = NULL;
free_message(encrypted_msg);
encrypted_msg = NULL;
free_message(decrypted_msg);
decrypted_msg = NULL;
free_stringlist(keylist_used);
keylist_used = NULL;
output_stream << "*** Now testing MIME_encrypt_for_self ***" << endl;
alice = new_identity("payto://BIC/SYSTEMA", NULL, PEP_OWN_USERID, "Alice Test");
bob = new_identity("payto://BIC/SYSTEMB", NULL, "42", "Bob Test");
output_stream << "Reading in alice_bob_encrypt_test_plaintext_mime.eml..." << endl;
const string mimetext = slurp("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
output_stream << "Text read:" << endl;
output_stream << mimetext.c_str() << endl;
char* encrypted_mimetext = nullptr;
output_stream << "Calling MIME_encrypt_message_for_self" << endl;
status = MIME_encrypt_message_for_self(session, alice, mimetext.c_str(),
mimetext.size(),
NULL,
&encrypted_mimetext,
PEP_enc_PGP_MIME,
PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
output_stream << "Encrypted message:" << endl;
output_stream << encrypted_mimetext << endl;
output_stream << "Calling MIME_decrypt_message" << endl;
char* decrypted_mimetext = nullptr;
free_stringlist(keylist_used);
keylist_used = nullptr;
PEP_decrypt_flags_t mimeflags;
PEP_rating mimerating;
char* modified_src = NULL;
mimeflags = 0;
status = MIME_decrypt_message(session,
encrypted_mimetext,
strlen(encrypted_mimetext),
&decrypted_mimetext,
&keylist_used,
&mimerating,
&mimeflags,
&modified_src);
ASSERT_NE(decrypted_mimetext, nullptr);
ASSERT_NE(keylist_used, nullptr);
ASSERT_NE(mimerating, 0);
ASSERT_TRUE(status == PEP_DECRYPTED && mimerating == PEP_rating_unreliable);
output_stream << "Decrypted message:" << endl;
output_stream << decrypted_mimetext << endl;
output_stream << "keys used:\n";
i = 0;
for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++)
{
if (i == 0) {
ASSERT_STRCASEEQ("",kl4->value);
}
else {
output_stream << "\t " << kl4->value << endl;
ASSERT_STRCASEEQ("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value);
output_stream << "Encrypted for Alice! Yay! It worked!" << endl;
}
ASSERT_LT(i , 2);
}
output_stream << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
}

@ -262,6 +262,8 @@ TEST_F(KeyResetMessageTest, check_reset_key_and_notify) {
for (curr_ident = send_idents; curr_ident && curr_ident->ident; curr_ident = curr_ident->next) {
status = update_identity(session, curr_ident->ident);
// Poor Bob. He doesn't get to be a pEp user.
if (strcmp(curr_ident->ident->user_id, bob_user_id.c_str()) == 0)
continue;
@ -324,7 +326,7 @@ TEST_F(KeyResetMessageTest, check_reset_key_and_notify) {
hashmap[fenris_user_id] = false;
// Number of messages we SHOULD be sending.
ASSERT_EQ(m_queue.size(), 4);
ASSERT_EQ(m_queue.size(), 3);
for (vector<message*>::iterator it = m_queue.begin(); it != m_queue.end(); it++) {
message* curr_sent_msg = *it;
@ -368,7 +370,7 @@ TEST_F(KeyResetMessageTest, check_reset_key_and_notify) {
// Make sure we have messages only to desired recips
ASSERT_FALSE(hashmap[alice_user_id]);
ASSERT_TRUE(hashmap[bob_user_id]);
ASSERT_FALSE(hashmap[bob_user_id]); // non-pEp user
ASSERT_TRUE(hashmap[carol_user_id]);
ASSERT_FALSE(hashmap[dave_user_id]);
ASSERT_TRUE(hashmap[erin_user_id]);
@ -460,6 +462,40 @@ TEST_F(KeyResetMessageTest, check_reset_receive_revoked) {
free(keylist);
}
TEST_F(KeyResetMessageTest, revoke_and_check_receive_message) {
pEp_identity* me = new_identity("inquisitor@darthmama.org", NULL, PEP_OWN_USERID, "INQUISITOR");
string inbox = slurp("test_mails/to_inquisitor_pgp.eml");
slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");
slurp_and_import_key(session, "test_keys/priv/inquisitor-0xA4728718_renewed_priv.asc");
PEP_STATUS status = set_own_key(session, me, "8E8D2381AE066ABE1FEE509821BA977CA4728718");
ASSERT_EQ(status, PEP_STATUS_OK);
status = key_reset(session, "8E8D2381AE066ABE1FEE509821BA977CA4728718", me);
ASSERT_EQ(status, PEP_STATUS_OK);
status = myself(session, me);
ASSERT_NE(me->fpr, nullptr);
ASSERT_STRNE(me->fpr, "8E8D2381AE066ABE1FEE509821BA977CA4728718");
ASSERT_EQ(m_queue.size() , 0);
m_queue.clear();
message* enc_msg = NULL;