From 6741a6c735179b8e2db38af42a102ba2b9ceb1e7 Mon Sep 17 00:00:00 2001 From: Krista 'DarthMama' Bennett Date: Tue, 1 Sep 2020 08:14:25 +0200 Subject: [PATCH] ENGINE-633: little bugs make big problems (argument order screwed up in import_keys_from_decrypted_message, failure to initialise comm_type in validate_fpr) --- pEpErr.py | 48 ++++++++++++++++++++++------- src/keymanagement.c | 2 ++ src/message_api.c | 2 +- test/src/GetKeyRatingForUserTest.cc | 5 ++- test/src/TrustManipulationTest.cc | 11 ++++++- 5 files changed, 54 insertions(+), 14 deletions(-) diff --git a/pEpErr.py b/pEpErr.py index 0baf5c13..59b891cd 100755 --- a/pEpErr.py +++ b/pEpErr.py @@ -8,12 +8,32 @@ # import sys +import argparse -def parse_enum_line(line): +def parse_enum_line(line, ct): line = line.strip() - parts = line.split() - if len(parts) != 3 or parts[1] != '=' or not parts[0].startswith("PEP_"): + if (line.startswith("//") or line == ""): return + + parts = [] + + if (ct): + temp = line.split(",") + if len(temp) == 0: + return + else: + parts = temp[0].split() + + else: + parts = line.split() + + if len(parts) != 3 or parts[1] != '=': + return + if not ct and not parts[0].startswith("PEP_"): + return + elif ct and not parts[0].startswith("PEP_ct_"): + return + key = int(parts[2].strip(','), 0) value = parts[0] valueDict[key] = value @@ -27,11 +47,13 @@ def get_error(code): print(str(code) + " -> " + error) -error_val = int(sys.argv[1], 0) -if error_val == None: - print("No error code, no error status!") - exit(-1) +parser = argparse.ArgumentParser() +parser.add_argument("value", type=int) +parser.add_argument("--comm_type", "-ct", help="number represents a comm type", action='store_true') + +args = parser.parse_args() +error_val = args.value input_fname = "src/pEpEngine.h" @@ -46,16 +68,20 @@ valueDict = dict() # If another struct is added first, expect chaos! ;) # for line in content: - if line.startswith("} PEP_STATUS;"): - break + if not args.comm_type: + if line.startswith("} PEP_STATUS;"): + break + else: + if line.startswith("} PEP_comm_type;"): + break - if not line.startswith("typedef enum {") and not inStruct: + if ((not args.comm_type and not line.startswith("typedef enum {")) or (args.comm_type and not line.startswith("typedef enum _PEP_comm_type {"))) and not inStruct: continue if not inStruct: inStruct = True continue - parse_enum_line(line) + parse_enum_line(line, args.comm_type) get_error(error_val) diff --git a/src/keymanagement.c b/src/keymanagement.c index 51e94602..0ba01150 100644 --- a/src/keymanagement.c +++ b/src/keymanagement.c @@ -134,6 +134,8 @@ PEP_STATUS validate_fpr(PEP_SESSION session, else if (status != PEP_STATUS_OK && has_private) // should never happen has_private = false; + ident->comm_type = PEP_ct_unknown; + status = get_trust(session, ident); if (status != PEP_STATUS_OK) ident->comm_type = PEP_ct_unknown; diff --git a/src/message_api.c b/src/message_api.c index 20889889..fe75028d 100644 --- a/src/message_api.c +++ b/src/message_api.c @@ -4236,7 +4236,7 @@ static PEP_STATUS _decrypt_message( // otherwise, we don't ask for a sender import fpr because for pEp 2.0+ any legit default key attachments should // be INSIDE the message status = import_keys_from_decrypted_msg(session, msg, - &keys_were_imported, is_pEp_msg, + is_pEp_msg, &keys_were_imported, &imported_private_key_address, private_il, &_imported_key_list, diff --git a/test/src/GetKeyRatingForUserTest.cc b/test/src/GetKeyRatingForUserTest.cc index 3d3400a9..fd76f5c2 100644 --- a/test/src/GetKeyRatingForUserTest.cc +++ b/test/src/GetKeyRatingForUserTest.cc @@ -97,7 +97,10 @@ TEST_F(GetKeyRatingForUserTest, check_get_key_rating_for_user) { // Ok, so we have no info really, let's set it. status = set_identity(session, alice); - + ASSERT_OK; + status = set_fpr_preserve_ident(session, alice, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", false); + ASSERT_OK; + status = update_identity(session, alice); ASSERT_NOTNULL(alice->fpr); diff --git a/test/src/TrustManipulationTest.cc b/test/src/TrustManipulationTest.cc index 78ed125a..89c0359f 100644 --- a/test/src/TrustManipulationTest.cc +++ b/test/src/TrustManipulationTest.cc @@ -149,7 +149,16 @@ TEST_F(TrustManipulationTest, check_trust_manipulation) { ASSERT_STREQ(user->fpr, keypair2); ASSERT_EQ(user->comm_type , PEP_ct_mistrusted); output_stream << "Hoorah, we now do not trust key 2. (We never liked key 2 anyway.)" << endl; - output_stream << "Now we call update_identity to see what gifts it gives us (should be key 1 with key 1's initial trust.)" << endl; + + // Ok, here's where the test breaks when we remove key election. Update identity won't be giving us anything because there's no default. + +// output_stream << "Now we call update_identity to see what gifts it gives us (should be key 1 with key 1's initial trust.)" << endl; + output_stream << "Now we call update_identity to see what gifts it gives us (should be NOTHING.)" << endl; + status = update_identity(session, user); + ASSERT_NULL(user->fpr); + // Now set key 1 as the default again + status = set_fpr_preserve_ident(session, user, keypair1, true); + ASSERT_OK; status = update_identity(session, user); ASSERT_NOTNULL(user->fpr); ASSERT_STREQ(user->fpr, keypair1);