src/message_api.c
branchsync
changeset 4352 69ac22b40ac7
parent 4321 795490894153
child 4360 1ab2ccbf5f9f
child 4364 10211edee233
     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                              }