ENGINE-140: work around nasty side effects of brand new update_identity with_myself parameter ENGINE-140
authorEdouard Tisserant <edouard@pep-project.org>
Thu, 10 Nov 2016 01:34:46 +0100
branchENGINE-140
changeset 13667fe33611a1bb
parent 1364 2ba0f96f6c0e
child 1367 48449a2a81ed
ENGINE-140: work around nasty side effects of brand new update_identity with_myself parameter
src/sync_impl.c
     1.1 --- a/src/sync_impl.c	Tue Nov 08 23:04:26 2016 +0100
     1.2 +++ b/src/sync_impl.c	Thu Nov 10 01:34:46 2016 +0100
     1.3 @@ -565,8 +565,8 @@
     1.4      me = NULL;
     1.5  
     1.6      if (encrypted) {
     1.7 -        if (msg->payload.present == DeviceGroup_Protocol__payload_PR_groupKeys || 
     1.8 -            msg->payload.present == DeviceGroup_Protocol__payload_PR_groupUpdate) {
     1.9 +        bool attach_own_private_keys = false;
    1.10 +        if (msg->payload.present == DeviceGroup_Protocol__payload_PR_groupKeys) {
    1.11              PEP_rating rating = PEP_rating_undefined;
    1.12              status = outgoing_message_rating(session, _message, &rating);
    1.13              if (status != PEP_STATUS_OK)
    1.14 @@ -575,7 +575,45 @@
    1.15                  status = PEP_SYNC_NO_TRUST;
    1.16                  goto error;
    1.17              }
    1.18 -            
    1.19 +            attach_own_private_keys = true;
    1.20 +        }
    1.21 +
    1.22 +        // outgoing_message_rating doesn't work for msg->to being own identity 
    1.23 +        // we check that from and to are the same, and with good comm_type
    1.24 +        if (msg->payload.present == DeviceGroup_Protocol__payload_PR_groupUpdate) {
    1.25 +            if(_message->to != NULL && _message->to->ident != NULL && 
    1.26 +               _message->to->next == NULL && _message->from != NULL &&
    1.27 +               strcmp(_message->to->ident->address, _message->from->address) == 0 && 
    1.28 +               strcmp(_message->to->ident->user_id, PEP_OWN_USERID) == 0 && 
    1.29 +               strcmp(_message->from->user_id, PEP_OWN_USERID) == 0) 
    1.30 +            {
    1.31 +                pEp_identity *_identity = NULL;
    1.32 +                status = get_identity(session,
    1.33 +                                      _message->to->ident->address,
    1.34 +                                      _message->to->ident->user_id,
    1.35 +                                      &_identity);
    1.36 +                
    1.37 +                if (status != PEP_STATUS_OK)
    1.38 +                    goto error;
    1.39 +
    1.40 +                PEP_comm_type _comm_type = _identity->comm_type;
    1.41 +                free_identity(_identity);
    1.42 +
    1.43 +                if(_comm_type != PEP_ct_pEp)
    1.44 +                {
    1.45 +                    status = PEP_SYNC_NO_TRUST;
    1.46 +                    goto error;
    1.47 +                }
    1.48 +            }
    1.49 +            else 
    1.50 +            {
    1.51 +                status = PEP_ILLEGAL_VALUE;
    1.52 +                goto error;
    1.53 +            }
    1.54 +            attach_own_private_keys = true;
    1.55 +        }
    1.56 +
    1.57 +        if(attach_own_private_keys){
    1.58              stringlist_t *keylist = NULL;
    1.59              status = keys_retrieve_by_flag(session, PEP_kpf_own_key, &keylist);
    1.60              if (status != PEP_STATUS_OK)