ENGINE-398: removed unnecessary (and impossible) check code, expanded tests ENGINE-398
authorKrista Bennett <krista@pep-project.org>
Tue, 04 Sep 2018 07:16:25 +0200
branchENGINE-398
changeset 2924fea58c0a9fd8
parent 2920 aa7662073dc0
child 2925 83b913e8bd22
ENGINE-398: removed unnecessary (and impossible) check code, expanded tests
src/message_api.c
test/include/KeyResetMessageTests.h
test/src/engine_tests/KeyResetMessageTests.cc
     1.1 --- a/src/message_api.c	Mon Sep 03 08:36:48 2018 +0200
     1.2 +++ b/src/message_api.c	Tue Sep 04 07:16:25 2018 +0200
     1.3 @@ -3254,15 +3254,11 @@
     1.4  }
     1.5  
     1.6  PEP_STATUS receive_key_reset(PEP_SESSION session,
     1.7 -                             message* reset_msg,
     1.8 -                             const char* signing_fpr) {
     1.9 +                             message* reset_msg) {
    1.10  
    1.11      if (!session || !reset_msg)
    1.12          return PEP_ILLEGAL_VALUE;
    1.13 -        
    1.14 -    if (EMPTYSTR(signing_fpr))
    1.15 -        return PEP_ILLEGAL_VALUE; // need better error - this is an attack 
    1.16 -        
    1.17 +                
    1.18      if (!reset_msg->from || !reset_msg->from->user_id)
    1.19          return PEP_MALFORMED_KEY_RESET_MSG;
    1.20          
    1.21 @@ -3278,27 +3274,7 @@
    1.22      
    1.23      stringlist_t* keylist = NULL;
    1.24      pEp_identity* temp_ident = NULL;
    1.25 -    
    1.26 -    // Make sure the signing fpr belongs to the "from" user, since that is 
    1.27 -    // who we are to change defaults for.
    1.28 -    
    1.29 -    // 1. See if this fpr is even associated with this user_id
    1.30 -    pEp_identity* sender_id = reset_msg->from;
    1.31 -    bool user_has_fpr = false;
    1.32 -    
    1.33 -    temp_ident = identity_dup(sender_id);
    1.34 -    free(temp_ident->fpr);
    1.35 -    temp_ident->fpr = strdup(signing_fpr);
    1.36 -    
    1.37 -    status = exists_trust_entry(session, temp_ident, &user_has_fpr);
    1.38 -    if (status != PEP_STATUS_OK)
    1.39 -        goto pep_free;
    1.40 -        
    1.41 -    if (!user_has_fpr) {   
    1.42 -        status = PEP_KEY_NOT_FOUND;
    1.43 -        goto pep_free;
    1.44 -    }
    1.45 -    
    1.46 +            
    1.47      char* rest = NULL;
    1.48      char* p = strtok_r(reset_msg->longmsg, "\n", &rest);
    1.49      if (!EMPTYSTR(p + 5))
    1.50 @@ -3307,10 +3283,23 @@
    1.51          status = PEP_MALFORMED_KEY_RESET_MSG;
    1.52          goto pep_free;
    1.53      }
    1.54 -
    1.55 -    // Before we go further, let's be sure this was signed by the revoked fpr.
    1.56 -    if (strcasecmp(revoke_fpr, signing_fpr) != 0) {
    1.57 -        status = PEP_ILLEGAL_VALUE;
    1.58 +    
    1.59 +    // 1. See if this fpr is even associated with this user_id
    1.60 +    pEp_identity* sender_id = reset_msg->from;
    1.61 +    bool user_has_fpr = false;
    1.62 +
    1.63 +    temp_ident = identity_dup(sender_id);
    1.64 +    free(temp_ident->fpr);
    1.65 +    temp_ident->fpr = strdup(revoke_fpr);
    1.66 +    
    1.67 +    status = exists_trust_entry(session, temp_ident, &user_has_fpr);
    1.68 +    free_identity(temp_ident);
    1.69 +    
    1.70 +    if (status != PEP_STATUS_OK)
    1.71 +        goto pep_free;
    1.72 +        
    1.73 +    if (!user_has_fpr) {   
    1.74 +        status = PEP_KEY_NOT_FOUND;
    1.75          goto pep_free;
    1.76      }
    1.77          
    1.78 @@ -3358,7 +3347,6 @@
    1.79      
    1.80      sender_id->comm_type = sender_id->comm_type & (~PEP_ct_confirmed);
    1.81      status = set_identity(session, sender_id);
    1.82 -
    1.83      
    1.84      if (status == PEP_STATUS_OK)
    1.85          status = PEP_KEY_RESET_SUCCESSFUL;
    1.86 @@ -3644,14 +3632,9 @@
    1.87                                          bool is_key_reset = (strcmp(wrap_info, "KEY_RESET") == 0);
    1.88  
    1.89                                          if (is_key_reset) {
    1.90 -                                            if (decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
    1.91 -                                                if (!_keylist || !_keylist->value) {
    1.92 -                                                    status = PEP_UNKNOWN_ERROR;
    1.93 -                                                    goto pep_error;
    1.94 -                                                }    
    1.95 +                                            if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
    1.96                                                  status = receive_key_reset(session,
    1.97 -                                                                           inner_message,
    1.98 -                                                                           _keylist->value);
    1.99 +                                                                           inner_message);
   1.100                                                  if (status != PEP_STATUS_OK) {
   1.101                                                      free_message(inner_message);
   1.102                                                      goto pep_error;
     2.1 --- a/test/include/KeyResetMessageTests.h	Mon Sep 03 08:36:48 2018 +0200
     2.2 +++ b/test/include/KeyResetMessageTests.h	Tue Sep 04 07:16:25 2018 +0200
     2.3 @@ -20,6 +20,9 @@
     2.4          vector<message*> m_queue;
     2.5          
     2.6          static constexpr const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
     2.7 +        static constexpr const char* bob_fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
     2.8 +        
     2.9 +        static constexpr const char* alice_receive_reset_fpr = "3EB562B0BE859A313636885910B2C4691EF99182";
    2.10  
    2.11          static const string alice_user_id;
    2.12          static const string bob_user_id;    
     3.1 --- a/test/src/engine_tests/KeyResetMessageTests.cc	Mon Sep 03 08:36:48 2018 +0200
     3.2 +++ b/test/src/engine_tests/KeyResetMessageTests.cc	Tue Sep 04 07:16:25 2018 +0200
     3.3 @@ -9,6 +9,7 @@
     3.4  
     3.5  #include "pEpEngine.h"
     3.6  #include "pEp_internal.h"
     3.7 +#include "mime.h"
     3.8  
     3.9  #include "test_util.h"
    3.10  #include "EngineTestIndividualSuite.h"
    3.11 @@ -102,7 +103,22 @@
    3.12  }
    3.13  
    3.14  void KeyResetMessageTests::receive_setup() {
    3.15 +    PEP_STATUS status = read_file_and_import_key(session,
    3.16 +                "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");  
    3.17 +    assert(status == PEP_STATUS_OK);
    3.18 +    status = set_up_ident_from_scratch(session,
    3.19 +                "test_keys/priv/pep-test-bob-0xC9C2EE39_priv.asc",  
    3.20 +                "pep.test.bob@pep-project.org", bob_fpr, 
    3.21 +                bob_user_id.c_str(), "Robert Redford", NULL, true
    3.22 +            );
    3.23 +    assert(status == PEP_STATUS_OK);
    3.24      
    3.25 +    status = set_up_ident_from_scratch(session,
    3.26 +                "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc",
    3.27 +                "pep.test.alice@pep-project.org", NULL, alice_user_id.c_str(), "Alice is tired of Bob",
    3.28 +                NULL, false
    3.29 +            );
    3.30 +    assert(status == PEP_STATUS_OK);    
    3.31  }
    3.32  
    3.33  void KeyResetMessageTests::check_key_reset_message() {
    3.34 @@ -179,6 +195,9 @@
    3.35      hashmap[erin_user_id] = false;
    3.36      hashmap[fenris_user_id] = false;
    3.37      
    3.38 +    // Number of messages we SHOULD be sending.
    3.39 +    TEST_ASSERT(m_queue.size() == 4);
    3.40 +    
    3.41      for (vector<message*>::iterator it = m_queue.begin(); it != m_queue.end(); it++) {
    3.42          message* curr_sent_msg = *it;
    3.43          TEST_ASSERT(curr_sent_msg);
    3.44 @@ -192,9 +211,10 @@
    3.45          unordered_map<string, bool>::iterator jt = hashmap.find(to->user_id);
    3.46          
    3.47          TEST_ASSERT(jt != hashmap.end());
    3.48 -        hashmap[jt->first] = true;        
    3.49 +        hashmap[jt->first] = true;   
    3.50      }
    3.51      
    3.52 +    // Make sure we have 
    3.53      TEST_ASSERT(hashmap[alice_user_id] == false);
    3.54      TEST_ASSERT(hashmap[bob_user_id] == true);
    3.55      TEST_ASSERT(hashmap[carol_user_id] == true);
    3.56 @@ -206,6 +226,31 @@
    3.57  }
    3.58  
    3.59  void KeyResetMessageTests::check_receive_revoked() {
    3.60 +    receive_setup();
    3.61 +    pEp_identity* alice_ident = new_identity("pep.test.alice@pep-project.org", NULL,
    3.62 +                                            alice_user_id.c_str(), NULL);
    3.63 +                                            
    3.64 +    PEP_STATUS status = update_identity(session, alice_ident);
    3.65 +    TEST_ASSERT(status == PEP_STATUS_OK);
    3.66 +    TEST_ASSERT(strcmp(alice_fpr, alice_ident->fpr) == 0);
    3.67 +    
    3.68 +    
    3.69 +//    TEST_ASSERT(strcmp("3EB562B0BE859A313636885910B2C4691EF99182", alice_ident->fpr) == 0);
    3.70 +    
    3.71 +    string received_mail = slurp("test_files/398_reset_from_alice_to_bob.eml");
    3.72 +    char* decrypted_msg = NULL;
    3.73 +    char* modified_src = NULL;
    3.74 +    stringlist_t* keylist = NULL;
    3.75 +    PEP_rating rating;
    3.76 +    PEP_decrypt_flags_t flags;
    3.77 +    status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
    3.78 +                                  &decrypted_msg, &keylist, &rating, &flags, &modified_src);
    3.79 +                                  
    3.80 +    TEST_ASSERT_MSG(status == PEP_DECRYPTED, tl_status_string(status));
    3.81 +    
    3.82 +    status = update_identity(session, alice_ident);
    3.83 +    TEST_ASSERT(strcmp(alice_receive_reset_fpr, alice_ident->fpr) == 0);
    3.84 +    
    3.85      TEST_ASSERT(true);
    3.86  }
    3.87