now ignoring own key resets in non-grouped keys sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Sat, 18 Jan 2020 23:15:45 +0100
branchsync
changeset 435269ac22b40ac7
parent 4351 864d368faa8b
child 4353 3c59288158d7
now ignoring own key resets in non-grouped keys
src/message_api.c
test/src/KeyResetMessageTest.cc
     1.1 --- a/src/message_api.c	Fri Jan 17 11:20:09 2020 +0100
     1.2 +++ b/src/message_api.c	Sat Jan 18 23:15:45 2020 +0100
     1.3 @@ -3803,7 +3803,7 @@
     1.4                              is_inner = (strcmp(wrap_info, "INNER") == 0);
     1.5                              if (!is_inner)
     1.6                                  is_key_reset = (strcmp(wrap_info, "KEY_RESET") == 0);
     1.7 -                        }
     1.8 +                        }                        
     1.9                              
    1.10                          // check for private key in decrypted message attachment while importing
    1.11                          // N.B. Apparently, we always import private keys into the keyring; however,
    1.12 @@ -3812,26 +3812,54 @@
    1.13                          
    1.14                          // If we have a message 2.0 message, we are ONLY going to be ok with keys
    1.15                          // we imported from THIS part of the message.
    1.16 -                        imported_private_key_address = false;
    1.17 -                        free(private_il); 
    1.18 -                        private_il = NULL;
    1.19 -                        
    1.20 -                        // import keys from decrypted INNER source
    1.21 -                        status = import_priv_keys_from_decrypted_msg(session, inner_message,
    1.22 -                                                                     &imported_keys,
    1.23 -                                                                     &imported_private_key_address,
    1.24 -                                                                     private_il);
    1.25 -                        if (status != PEP_STATUS_OK)
    1.26 -                            goto pEp_error;            
    1.27 -
    1.28 +                                                        
    1.29 +                        bool ignore_msg = false;
    1.30 +                            
    1.31 +                        if (is_key_reset) {
    1.32 +                            if (inner_message->_sender_fpr) {
    1.33 +                                bool sender_key_is_me = false;
    1.34 +                                status = is_own_key(session, inner_message->_sender_fpr, &sender_key_is_me);
    1.35 +                                if (status != PEP_STATUS_OK && status != PEP_KEY_NOT_FOUND)
    1.36 +                                    goto pEp_error;
    1.37 +                                
    1.38 +                                if (sender_key_is_me) {    
    1.39 +                                    bool grouped = false;
    1.40 +                                    status = deviceGrouped(session, &grouped);
    1.41 +                                    
    1.42 +                                    if (status != PEP_STATUS_OK)
    1.43 +                                        goto pEp_error;
    1.44 +                                    
    1.45 +                                    if (!grouped)
    1.46 +                                        ignore_msg = true;    
    1.47 +                                }
    1.48 +                            }
    1.49 +                            else
    1.50 +                                ignore_msg = true;
    1.51 +                        }
    1.52 +
    1.53 +                        if (!ignore_msg) {
    1.54 +                            imported_private_key_address = false;
    1.55 +                            free(private_il); 
    1.56 +                            private_il = NULL;
    1.57 +                            
    1.58 +                            // import keys from decrypted INNER source
    1.59 +                            status = import_priv_keys_from_decrypted_msg(session, inner_message,
    1.60 +                                                                         &imported_keys,
    1.61 +                                                                         &imported_private_key_address,
    1.62 +                                                                         private_il);
    1.63 +                            if (status != PEP_STATUS_OK)
    1.64 +                                goto pEp_error;            
    1.65 +                        }        
    1.66                          if (is_key_reset) {
    1.67                              if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
    1.68 -                                status = receive_key_reset(session,
    1.69 -                                                           inner_message);
    1.70 -                                if (status != PEP_STATUS_OK) {
    1.71 -                                    free_message(inner_message);
    1.72 -                                    goto pEp_error;
    1.73 -                                }
    1.74 +                                if (!ignore_msg) {
    1.75 +                                    status = receive_key_reset(session,
    1.76 +                                                               inner_message);
    1.77 +                                    if (status != PEP_STATUS_OK) {
    1.78 +                                        free_message(inner_message);
    1.79 +                                        goto pEp_error;
    1.80 +                                    }
    1.81 +                                }    
    1.82                                  *flags |= PEP_decrypt_flag_consume;
    1.83                                  calculated_src = msg = inner_message;                                    
    1.84                              }
     2.1 --- a/test/src/KeyResetMessageTest.cc	Fri Jan 17 11:20:09 2020 +0100
     2.2 +++ b/test/src/KeyResetMessageTest.cc	Sat Jan 18 23:15:45 2020 +0100
     2.3 @@ -838,14 +838,20 @@
     2.4      alex_id->me = true;
     2.5      status = set_own_key(session, alex_id, pubkey1);
     2.6      ASSERT_EQ(status, PEP_STATUS_OK);
     2.7 +    status = set_identity_flags(session, alex_id, alex_id->flags | PEP_idf_devicegroup);
     2.8 +    ASSERT_EQ(status , PEP_STATUS_OK);
     2.9  
    2.10      alex_id2->me = true;
    2.11      status = set_own_key(session, alex_id2, pubkey1);
    2.12      ASSERT_EQ(status, PEP_STATUS_OK);
    2.13 +    status = set_identity_flags(session, alex_id2, alex_id2->flags | PEP_idf_devicegroup);
    2.14 +    ASSERT_EQ(status , PEP_STATUS_OK);
    2.15  
    2.16      alex_id3->me = true;
    2.17      status = set_own_key(session, alex_id3, pubkey1);
    2.18      ASSERT_EQ(status, PEP_STATUS_OK);
    2.19 +    status = set_identity_flags(session, alex_id3, alex_id3->flags | PEP_idf_devicegroup);
    2.20 +    ASSERT_EQ(status , PEP_STATUS_OK);
    2.21  
    2.22      status = myself(session, alex_id);
    2.23      ASSERT_EQ(status, PEP_STATUS_OK);
    2.24 @@ -1500,14 +1506,20 @@
    2.25      alex_id->me = true;
    2.26      status = set_own_key(session, alex_id, pubkey1);
    2.27      ASSERT_EQ(status, PEP_STATUS_OK);
    2.28 +    status = set_identity_flags(session, alex_id2, alex_id2->flags | PEP_idf_devicegroup);
    2.29 +    ASSERT_EQ(status , PEP_STATUS_OK);
    2.30  
    2.31      alex_id2->me = true;
    2.32      status = set_own_key(session, alex_id2, pubkey2);
    2.33      ASSERT_EQ(status, PEP_STATUS_OK);
    2.34 +    status = set_identity_flags(session, alex_id2, alex_id2->flags | PEP_idf_devicegroup);
    2.35 +    ASSERT_EQ(status , PEP_STATUS_OK);
    2.36  
    2.37      alex_id3->me = true;
    2.38      status = set_own_key(session, alex_id3, pubkey3);
    2.39      ASSERT_EQ(status, PEP_STATUS_OK);
    2.40 +    status = set_identity_flags(session, alex_id2, alex_id2->flags | PEP_idf_devicegroup);
    2.41 +    ASSERT_EQ(status , PEP_STATUS_OK);
    2.42  
    2.43      status = myself(session, alex_id);
    2.44      ASSERT_EQ(status, PEP_STATUS_OK);