group_key_reset
Volker Birk 2019-12-08 15:13:17 +01:00
commit 2e360633d5
8 changed files with 444 additions and 394 deletions

View File

@ -93,7 +93,7 @@ else ifeq ($(BUILD_FOR),Darwin)
endif
ifeq ($(BUILD_FOR),Linux)
CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=always
CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=auto
else ifeq ($(BUILD_FOR),Darwin)
CFLAGS=-pthread -fPIC -fstrict-aliasing -fcolor-diagnostics
endif
@ -148,7 +148,7 @@ endif
# The flag -DNDEBUG will always be removed from CXXFLAGS for compiling tests.
# The tests do not work properly, if compiled with -DNDEBUG
ifeq ($(BUILD_FOR),Linux)
CXXFLAGS=-fdiagnostics-color=always -I../src -I../asn.1 $(ETPAN_INC)
CXXFLAGS=-fdiagnostics-color=auto -I../src -I../asn.1 $(ETPAN_INC)
ifdef WARN
CXXFLAGS+=
else

View File

@ -1208,6 +1208,7 @@ static PEP_rating decrypt_rating(PEP_STATUS status)
return PEP_rating_unencrypted;
case PEP_DECRYPTED:
case PEP_VERIFY_SIGNER_KEY_REVOKED:
case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH:
return PEP_rating_unreliable;
@ -3419,6 +3420,8 @@ static PEP_STATUS _decrypt_message(
unsigned int major_ver = 0;
unsigned int minor_ver = 0;
stringpair_list_t* revoke_replace_pairs = NULL;
// Grab input flags
bool reencrypt = ((*flags & PEP_decrypt_flag_untrusted_server) &&
(_have_extrakeys(*keylist) || session->unencrypted_subject));
@ -3546,9 +3549,7 @@ static PEP_STATUS _decrypt_message(
status = _mime_decode_message_internal(ptext, psize, &msg, &has_inner);
if (status != PEP_STATUS_OK)
goto pEp_error;
/* Ensure messages whose maintext is in the attachments
move main text into message struct longmsg et al */
/* KG: This IS a src modification of old - we're adding to it
w/ memhole subject, but the question is whether or not
this is OK overall... */
@ -3616,7 +3617,8 @@ static PEP_STATUS _decrypt_message(
if (status != PEP_STATUS_OK)
goto pEp_error;
if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED ||
decrypt_status == PEP_VERIFY_SIGNER_KEY_REVOKED) {
char* wrap_info = NULL;
if (!has_inner) {
@ -3888,67 +3890,69 @@ static PEP_STATUS _decrypt_message(
} // End prepare output message for return
// 3. Check to see if the sender used any of our revoked keys
stringpair_list_t* revoke_replace_pairs = NULL;
status = check_for_own_revoked_key(session, _keylist, &revoke_replace_pairs);
if (!is_me(session, msg->from)) {
status = check_for_own_revoked_key(session, _keylist, &revoke_replace_pairs);
//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;
//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;
for (curr_pair_node = revoke_replace_pairs; curr_pair_node; curr_pair_node = curr_pair_node->next) {
curr_pair = curr_pair_node->value;
if (!curr_pair)
continue; // Again, shouldn't occur
if (!curr_pair)
continue; // Again, shouldn't occur
if (curr_pair->key && curr_pair->value) {
status = create_standalone_key_reset_message(session,
&reset_msg,
msg->from,
curr_pair->key,
curr_pair->value);
if (curr_pair->key && curr_pair->value) {
status = create_standalone_key_reset_message(session,
&reset_msg,
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_pair->key, msg->from->user_id);
if (status != PEP_STATUS_OK) // It's ok to barf because it's a DB problem??
// 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;
}
else {
// According to Volker, this would only be a fatal error, so...
free_message(reset_msg); // ??
reset_msg = NULL; // ??
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_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;
}
}
}
}
}
}
free_stringpair_list(revoke_replace_pairs);
revoke_replace_pairs = NULL;
} // end !is_me(msg->from)
bool reenc_signer_key_is_own_key = false; // only matters for reencrypted messages
@ -3964,7 +3968,8 @@ static PEP_STATUS _decrypt_message(
}
if (reencrypt) {
if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED
|| decrypt_status == PEP_VERIFY_SIGNER_KEY_REVOKED) {
const char* sfpr = NULL;
if (has_extra_keys)
sfpr = _keylist->value;
@ -4049,6 +4054,7 @@ pEp_error:
free_message(msg);
free_message(reset_msg);
free_stringlist(_keylist);
free_stringpair_list(revoke_replace_pairs);
return status;
}

View File

@ -84,8 +84,10 @@ typedef enum {
PEP_VERIFY_NO_KEY = 0x0407,
PEP_VERIFIED_AND_TRUSTED = 0x0408,
PEP_CANNOT_REENCRYPT = 0x0409,
PEP_VERIFY_SIGNER_KEY_REVOKED = 0x040a,
PEP_CANNOT_DECRYPT_UNKNOWN = 0x04ff,
PEP_TRUSTWORD_NOT_FOUND = 0x0501,
PEP_TRUSTWORDS_FPR_WRONG_LENGTH = 0x0502,
PEP_TRUSTWORDS_DUPLICATE_FPR = 0x0503,

View File

@ -143,17 +143,17 @@ struct _pEpSession {
sqlite3_stmt *begin_transaction;
sqlite3_stmt *commit_transaction;
sqlite3_stmt *rollback_transaction;
sqlite3_stmt *tpk_find;
sqlite3_stmt *cert_find;
sqlite3_stmt *tsk_find;
sqlite3_stmt *tpk_find_by_keyid;
sqlite3_stmt *cert_find_by_keyid;
sqlite3_stmt *tsk_find_by_keyid;
sqlite3_stmt *tpk_find_by_email;
sqlite3_stmt *cert_find_by_email;
sqlite3_stmt *tsk_find_by_email;
sqlite3_stmt *tpk_all;
sqlite3_stmt *cert_all;
sqlite3_stmt *tsk_all;
sqlite3_stmt *tpk_save_insert_primary;
sqlite3_stmt *tpk_save_insert_subkeys;
sqlite3_stmt *tpk_save_insert_userids;
sqlite3_stmt *cert_save_insert_primary;
sqlite3_stmt *cert_save_insert_subkeys;
sqlite3_stmt *cert_save_insert_userids;
sqlite3_stmt *delete_keypair;
} sq_sql;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -113,7 +113,7 @@ $(TARGET): $(OBJS)
test: all
$(RM) -rf ./pEp_test_home/*
$(TEST_CMD_PFX) $(TEST_DEBUGGER) python3 $(GTEST_PL) ./$(TARGET)
$(TEST_CMD_PFX) $(TEST_DEBUGGER) GTEST_COLOR=no python3 $(GTEST_PL) --gtest_color=no ./$(TARGET)
clean:
$(RM) $(TARGET) $(TARGET).o $(TARGET).d $(OBJS) $(notdir $(basename $(OBJS))) $(DEPS)
$(RM) -rf ./pEp_test_home/*

View File

@ -1217,6 +1217,36 @@ TEST_F(KeyResetMessageTest, not_a_test) {
myfile.close();
}
TEST_F(KeyResetMessageTest, check_no_reset_message_to_self) {
pEp_identity* bob = NULL;
PEP_STATUS status = set_up_preset(session, BOB,
true, true, true, true, true, &bob);
slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
message* bob_msg = new_message(PEP_dir_outgoing);
bob_msg->from = identity_dup(bob);
bob_msg->to = new_identity_list(identity_dup(bob));
bob_msg->shortmsg = strdup("Engine bugs suck\n");
bob_msg->longmsg = strdup("Everything is the engine's fault.\n");
message* enc_msg = NULL;
status = encrypt_message(session, bob_msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
ASSERT_EQ(status, PEP_STATUS_OK);
key_reset_all_own_keys(session);
message* dec_msg = NULL;
stringlist_t* keylist = NULL;
PEP_rating rating;
PEP_decrypt_flags_t flags = 0;
status = decrypt_message(session, enc_msg, &dec_msg, &keylist, &rating, &flags);
ASSERT_EQ(m_queue.size(), 0);
ASSERT_EQ(status, PEP_VERIFY_SIGNER_KEY_REVOKED);
}
TEST_F(KeyResetMessageTest, check_reset_mistrust_next_msg_have_not_mailed) {
pEp_identity* carol = NULL;

View File

@ -126,7 +126,7 @@ TEST_F(VerifyTest, check_revoked_tpk) {
&keylist, NULL);
// Now it should fail.
ASSERT_EQ(status , PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
ASSERT_EQ(status , PEP_VERIFY_SIGNER_KEY_REVOKED);
ASSERT_NE(keylist, nullptr);
// No signer.
ASSERT_STREQ(keylist->value, "");
@ -150,7 +150,7 @@ TEST_F(VerifyTest, check_revoked_tpk) {
&keylist);
// Now it should fail.
ASSERT_EQ(status , PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
ASSERT_EQ(status , PEP_VERIFY_SIGNER_KEY_REVOKED);
ASSERT_NE(keylist, nullptr);
// No signer.
ASSERT_STREQ(keylist->value, "");
@ -175,7 +175,7 @@ TEST_F(VerifyTest, check_revoked_signing_key) {
&keylist, NULL);
// It should fail.
ASSERT_EQ(status , PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
ASSERT_EQ(status , PEP_VERIFY_SIGNER_KEY_REVOKED);
ASSERT_NE(keylist, nullptr);
// No signer.
ASSERT_STREQ(keylist->value, "");
@ -199,7 +199,7 @@ TEST_F(VerifyTest, check_revoked_signing_key) {
&keylist);
// Now it should fail.
ASSERT_EQ(status , PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH);
ASSERT_EQ(status , PEP_VERIFY_SIGNER_KEY_REVOKED);
ASSERT_NE(keylist, nullptr);
// No signer.
ASSERT_STREQ(keylist->value, "");