ENGINE-398: key_mistrusted duplicates reset functionality, but with a couple of differences (generation), so we make it explicit. Also more test stuff. Committing to merge in default. ENGINE-398
authorKrista Bennett <krista@pep-project.org>
Sat, 08 Sep 2018 11:35:52 +0200
branchENGINE-398
changeset 2933737e2d878712
parent 2931 2bd3cfab7934
child 2934 616cdd6433d2
ENGINE-398: key_mistrusted duplicates reset functionality, but with a couple of differences (generation), so we make it explicit. Also more test stuff. Committing to merge in default.
src/message_api.c
src/message_api.h
test/src/engine_tests/KeyResetMessageTests.cc
     1.1 --- a/src/message_api.c	Fri Sep 07 12:33:41 2018 +0200
     1.2 +++ b/src/message_api.c	Sat Sep 08 11:35:52 2018 +0200
     1.3 @@ -3332,7 +3332,6 @@
     1.4      temp_ident->fpr = strdup(revoke_fpr);
     1.5      
     1.6      status = exists_trust_entry(session, temp_ident, &user_has_fpr);
     1.7 -    free_identity(temp_ident);
     1.8      
     1.9      if (status != PEP_STATUS_OK)
    1.10          goto pep_free;
    1.11 @@ -3369,9 +3368,12 @@
    1.12          status = PEP_MALFORMED_KEY_RESET_MSG;
    1.13          goto pep_free;
    1.14      }
    1.15 +
    1.16 +    // Reset the original key
    1.17 +    status = key_reset(session, revoke_fpr, temp_ident);
    1.18 +    if (status != PEP_STATUS_OK)
    1.19 +        goto pep_free;
    1.20          
    1.21 -    // We know that the signer has the sender's user_id, and that the revoked fpr
    1.22 -    // is theirs. We now need to make sure that we've imported the key we need.    
    1.23      status = find_keys(session, new_fpr, &keylist);
    1.24      if (status != PEP_STATUS_OK)
    1.25          goto pep_free;
    1.26 @@ -3391,10 +3393,10 @@
    1.27          status = PEP_KEY_RESET_SUCCESSFUL;
    1.28      
    1.29  pep_free:    
    1.30 -    free(keylist);    
    1.31 +    free_stringlist(keylist);    
    1.32      free(revoke_fpr);
    1.33      free(new_fpr);
    1.34 -    free(temp_ident);
    1.35 +    free_identity(temp_ident);
    1.36      return status;
    1.37  }
    1.38  
    1.39 @@ -3994,6 +3996,7 @@
    1.40          
    1.41      char* fpr_copy = NULL;
    1.42      char* own_id = NULL;
    1.43 +    char* new_key = NULL;
    1.44      identity_list* key_idents = NULL;
    1.45      stringlist_t* keys = NULL;
    1.46      
    1.47 @@ -4065,35 +4068,47 @@
    1.48                  }
    1.49              }
    1.50                          
    1.51 -//            char* fpr_backup = ident->fpr;
    1.52              free(ident->fpr);
    1.53              ident->fpr = fpr_copy;            
    1.54              // Create revocation
    1.55              status = revoke_key(session, fpr_copy, NULL);
    1.56 -            // mistrust fpr from trust
    1.57 -            if (status == PEP_STATUS_OK)
    1.58 -                status = key_mistrusted(session, ident);
    1.59 -            // Remove fpr from ALL identities
    1.60 -            // Remove fpr from ALL users    
    1.61 -            if (status == PEP_STATUS_OK)
    1.62 -                status = remove_fpr_as_default(session, fpr_copy);
    1.63 -            if (status == PEP_STATUS_OK)
    1.64 -                status = add_mistrusted_key(session, fpr_copy);
    1.65              // generate new key
    1.66              if (status == PEP_STATUS_OK) {
    1.67                  ident->fpr = NULL;
    1.68                  status = generate_keypair(session, ident);
    1.69              }
    1.70 -            // add to revocation list (ident->fpr is now the NEW key)
    1.71 +            if (status == PEP_STATUS_OK) {
    1.72 +                new_key = strdup(ident->fpr);
    1.73 +                status = set_own_key(session, ident, new_key);
    1.74 +            }
    1.75 +            // mistrust fpr from trust
    1.76 +            ident->fpr = fpr_copy;
    1.77 +            
    1.78 +            ident->comm_type = PEP_ct_mistrusted;
    1.79 +            status = set_trust(session, ident);
    1.80 +            ident->fpr = NULL;
    1.81 +            
    1.82 +            // Done with old use of ident.
    1.83 +            if (status == PEP_STATUS_OK) {
    1.84 +                // Update fpr for outgoing
    1.85 +                status = myself(session, ident);
    1.86 +            }
    1.87 +            
    1.88 +            if (status == PEP_STATUS_OK)
    1.89 +                // cascade that mistrust for anyone using this key
    1.90 +                status = mark_as_compromised(session, fpr_copy);
    1.91 +            if (status == PEP_STATUS_OK)
    1.92 +                status = remove_fpr_as_default(session, fpr_copy);
    1.93 +            if (status == PEP_STATUS_OK)
    1.94 +                status = add_mistrusted_key(session, fpr_copy);
    1.95 +            // add to revocation list 
    1.96              if (status == PEP_STATUS_OK) 
    1.97 -                status = set_revoked(session, fpr_copy, ident->fpr, time(NULL));
    1.98 -            
    1.99 +                status = set_revoked(session, fpr_copy, new_key, time(NULL));            
   1.100              // for all active communication partners:
   1.101              //      active_send revocation
   1.102              if (status == PEP_STATUS_OK)
   1.103 -                status = send_key_reset_to_recents(session, fpr_copy, ident->fpr);
   1.104 -            
   1.105 -//            ident->fpr = fpr_backup;
   1.106 +                status = send_key_reset_to_recents(session, fpr_copy, new_key);
   1.107 +                
   1.108          }
   1.109          else { // not is_me
   1.110              // remove fpr from all identities
   1.111 @@ -4112,7 +4127,8 @@
   1.112      free(fpr_copy);
   1.113      free(own_id);
   1.114      free_identity_list(key_idents);
   1.115 -    free_stringlist(keys);    
   1.116 +    free_stringlist(keys);
   1.117 +    free(new_key);    
   1.118      return status;
   1.119  }
   1.120  
     2.1 --- a/src/message_api.h	Fri Sep 07 12:33:41 2018 +0200
     2.2 +++ b/src/message_api.h	Sat Sep 08 11:35:52 2018 +0200
     2.3 @@ -43,7 +43,7 @@
     2.4      // their own PGP-only device
     2.5      PEP_encrypt_flag_force_version_1 = 0x16,
     2.6      
     2.7 -    PEP_encrypt_flag_key_reset_only = 0x32,
     2.8 +    PEP_encrypt_flag_key_reset_only = 0x20
     2.9      
    2.10  } PEP_encrypt_flags; 
    2.11  
     3.1 --- a/test/src/engine_tests/KeyResetMessageTests.cc	Fri Sep 07 12:33:41 2018 +0200
     3.2 +++ b/test/src/engine_tests/KeyResetMessageTests.cc	Sat Sep 08 11:35:52 2018 +0200
     3.3 @@ -10,6 +10,7 @@
     3.4  #include "pEpEngine.h"
     3.5  #include "pEp_internal.h"
     3.6  #include "mime.h"
     3.7 +#include "keymanagement.h"
     3.8  
     3.9  #include "test_util.h"
    3.10  #include "EngineTestIndividualSuite.h"
    3.11 @@ -167,7 +168,8 @@
    3.12      // key, will get sent some nice key reset messages.
    3.13      // But... we need to have one look like an older message. So. Time to mess with the DB.
    3.14      // Dave is our victim. Because I have a friend called Dave, who is actually a nice dude, but it amuses me.
    3.15 -    // (Note: said friend is NOT David Hasselhoff. To my knowledge. Hi Dave!)
    3.16 +    // (Note: said friend is NOT David Hasselhoff. To my knowledge. Hi Dave! (Addendum: Dave confirms he is
    3.17 +    // not Hasselhoff. But he wishes he were, sort of.))
    3.18      //
    3.19      // update identity
    3.20      //      set timestamp = 661008730
    3.21 @@ -212,17 +214,30 @@
    3.22          
    3.23          TEST_ASSERT(jt != hashmap.end());
    3.24          hashmap[jt->first] = true;   
    3.25 +        
    3.26 +        message* decrypted_msg = NULL;
    3.27 +        stringlist_t* keylist = NULL;
    3.28 +        PEP_rating rating;
    3.29 +        PEP_decrypt_flags_t flags;
    3.30 +        
    3.31 +        status = decrypt_message(session, curr_sent_msg, 
    3.32 +                                 &decrypted_msg, &keylist, 
    3.33 +                                 &rating, &flags);
    3.34 +                                 
    3.35 +        TEST_ASSERT_MSG((status == PEP_DECRYPTED_AND_VERIFIED), tl_status_string(status));
    3.36 +        free_message(curr_sent_msg); // DO NOT USE AFTER THIS
    3.37      }
    3.38      
    3.39 -    // Make sure we have 
    3.40 +    // MESSAGE LIST NOW INVALID.
    3.41 +    m_queue.clear();
    3.42 +    
    3.43 +    // Make sure we have messages only to desired recips
    3.44      TEST_ASSERT(hashmap[alice_user_id] == false);
    3.45      TEST_ASSERT(hashmap[bob_user_id] == true);
    3.46      TEST_ASSERT(hashmap[carol_user_id] == true);
    3.47      TEST_ASSERT(hashmap[dave_user_id] == false);
    3.48      TEST_ASSERT(hashmap[erin_user_id] == true);
    3.49      TEST_ASSERT(hashmap[fenris_user_id] == true);
    3.50 -    
    3.51 -    TEST_ASSERT(true);
    3.52  }
    3.53  
    3.54  void KeyResetMessageTests::check_receive_revoked() {
    3.55 @@ -234,9 +249,6 @@
    3.56      TEST_ASSERT(status == PEP_STATUS_OK);
    3.57      TEST_ASSERT(strcmp(alice_fpr, alice_ident->fpr) == 0);
    3.58      
    3.59 -    
    3.60 -//    TEST_ASSERT(strcmp("3EB562B0BE859A313636885910B2C4691EF99182", alice_ident->fpr) == 0);
    3.61 -    
    3.62      string received_mail = slurp("test_files/398_reset_from_alice_to_bob.eml");
    3.63      char* decrypted_msg = NULL;
    3.64      char* modified_src = NULL;
    3.65 @@ -247,11 +259,22 @@
    3.66                                    &decrypted_msg, &keylist, &rating, &flags, &modified_src);
    3.67                                    
    3.68      TEST_ASSERT_MSG(status == PEP_DECRYPTED, tl_status_string(status));
    3.69 +    TEST_ASSERT(keylist);
    3.70 +    if (keylist) // there's a test option to continue when asserts fail, so...
    3.71 +        TEST_ASSERT_MSG(strcmp(keylist->value, alice_receive_reset_fpr) == 0,
    3.72 +                        keylist->value);
    3.73      
    3.74      status = update_identity(session, alice_ident);
    3.75 -    TEST_ASSERT(strcmp(alice_receive_reset_fpr, alice_ident->fpr) == 0);
    3.76 +    TEST_ASSERT(alice_ident->fpr);
    3.77 +    TEST_ASSERT_MSG(strcmp(alice_receive_reset_fpr, alice_ident->fpr) == 0,
    3.78 +                    alice_ident->fpr);
    3.79      
    3.80 -    TEST_ASSERT(true);
    3.81 +    keylist = NULL;
    3.82 +    status = find_keys(session, alice_fpr, &keylist);
    3.83 +
    3.84 +    TEST_ASSERT(status == PEP_KEY_NOT_FOUND);
    3.85 +    free(keylist);
    3.86 +    
    3.87  }
    3.88  
    3.89  void KeyResetMessageTests::check_receive_key_reset_private() {