ENGINE-188 brutal fixes so that last mp_sync_test.py still completes. closing that branch ENGINE-188
authorEdouard Tisserant <edouard@pep-project.org>
Mon, 13 Mar 2017 14:33:17 +0100
branchENGINE-188
changeset 1647f089d9e32e60
parent 1636 cc152225ec01
child 1648 158e65c83311
ENGINE-188 brutal fixes so that last mp_sync_test.py still completes. closing that branch
src/sync_impl.c
sync/devicegroup.fsm
sync/generated/sync_fsm.c
     1.1 --- a/src/sync_impl.c	Sat Mar 11 14:50:05 2017 +0100
     1.2 +++ b/src/sync_impl.c	Mon Mar 13 14:33:17 2017 +0100
     1.3 @@ -548,45 +548,50 @@
     1.4                                  goto free_all;
     1.5                              }
     1.6  
     1.7 -                            // do not consume handshake groupKeys for group
     1.8 +                            // do not consume groupKeys for group
     1.9                              if(is_for_group){ 
    1.10                                  // This happens in case case of groupmerge
    1.11                                  force_keep_msg = true;
    1.12                              }
    1.13  
    1.14 -                            // check trust of identity using user_id given in msg.header.me
    1.15 -                            // to exacly match identity of device, the one trusted in
    1.16 -                            // case of accepted handshake from a sole device
    1.17 -                            pEp_identity *_from = new_identity(NULL, 
    1.18 -                                                               keylist->value,
    1.19 -                                                               user_id,
    1.20 -                                                               NULL);
    1.21 -                            if (_from == NULL){
    1.22 -                                status = PEP_OUT_OF_MEMORY;
    1.23 -                                goto free_all;
    1.24 -                            }
    1.25 -                            status = get_trust(session, _from);
    1.26 -                            if (status != PEP_STATUS_OK || _from->comm_type < PEP_ct_strong_encryption) {
    1.27 +                            // Trust check disabled here but it still it should be safe.
    1.28 +                            // SameIdentity checks in state machine ensures that we only
    1.29 +                            // store groupkeys signed by device or group that have been 
    1.30 +                            // previously accepted in handshake.
    1.31 +                            //
    1.32 +                            // // check trust of identity using user_id given in msg.header.me
    1.33 +                            // // to exacly match identity of device, the one trusted in
    1.34 +                            // // case of accepted handshake from a sole device
    1.35 +                            // pEp_identity *_from = new_identity(NULL, 
    1.36 +                            //                                    keylist->value,
    1.37 +                            //                                    user_id,
    1.38 +                            //                                    NULL);
    1.39 +                            // if (_from == NULL){
    1.40 +                            //     status = PEP_OUT_OF_MEMORY;
    1.41 +                            //     goto free_all;
    1.42 +                            // }
    1.43 +                            // status = get_trust(session, _from);
    1.44 +                            // if (status != PEP_STATUS_OK || _from->comm_type < PEP_ct_strong_encryption) {
    1.45  
    1.46 -                                // re-try with group_id instead, in case of handshake with pre-existing group
    1.47 -                                UTF8String_t *guuid = msg->payload.choice.groupKeys.group_id;
    1.48 -                                free(_from->user_id);
    1.49 -                                if ((_from->user_id = strndup((const char*)guuid->buf, guuid->size)) == NULL){
    1.50 -                                    free_identity(_from);
    1.51 -                                    status = PEP_OUT_OF_MEMORY;
    1.52 -                                    goto free_all;
    1.53 -                                }
    1.54 -                                _from->comm_type = PEP_ct_unknown;
    1.55 +                            //     // re-try with group_id instead, in case of handshake with pre-existing group
    1.56 +                            //     UTF8String_t *guuid = msg->payload.choice.groupKeys.group_id;
    1.57 +                            //     free(_from->user_id);
    1.58 +                            //     if ((_from->user_id = strndup((const char*)guuid->buf, guuid->size)) == NULL){
    1.59 +                            //         free_identity(_from);
    1.60 +                            //         status = PEP_OUT_OF_MEMORY;
    1.61 +                            //         goto free_all;
    1.62 +                            //     }
    1.63 +                            //     _from->comm_type = PEP_ct_unknown;
    1.64  
    1.65 -                                status = get_trust(session, _from);
    1.66 -                                if (status != PEP_STATUS_OK || _from->comm_type < PEP_ct_strong_encryption) {
    1.67 -                                    status = PEP_STATUS_OK;
    1.68 -                                    free_identity(_from);
    1.69 -                                    discard = true;
    1.70 -                                    goto free_all;
    1.71 -                                }
    1.72 -                            }
    1.73 -                            free_identity(_from);
    1.74 +                            //     status = get_trust(session, _from);
    1.75 +                            //     if (status != PEP_STATUS_OK || _from->comm_type < PEP_ct_strong_encryption) {
    1.76 +                            //         status = PEP_STATUS_OK;
    1.77 +                            //         free_identity(_from);
    1.78 +                            //         discard = true;
    1.79 +                            //         goto free_all;
    1.80 +                            //     }
    1.81 +                            // }
    1.82 +                            // free_identity(_from);
    1.83                              break;
    1.84                          }
    1.85                          case DeviceGroup_Protocol__payload_PR_groupUpdate:
    1.86 @@ -938,30 +943,30 @@
    1.87      free(group_keys_extra);
    1.88  }
    1.89  
    1.90 -group_keys_extra_t* group_keys_extra_dup(group_keys_extra_t* groupkeys)
    1.91 +group_keys_extra_t* group_keys_extra_dup(group_keys_extra_t* group_key_extra_src)
    1.92  {
    1.93 -    group_keys_extra_t *group_keys_extra;
    1.94 -    group_keys_extra = malloc(sizeof(group_keys_extra_t));
    1.95 -    if(group_keys_extra == NULL){
    1.96 +    group_keys_extra_t *group_key_extra_dst;
    1.97 +    group_key_extra_dst = calloc(1,sizeof(group_keys_extra_t));
    1.98 +    if(group_key_extra_dst == NULL){
    1.99          return NULL;
   1.100      }
   1.101  
   1.102 -    char *group_id = strdup(group_keys_extra->group_id);
   1.103 +    char *group_id = strdup(group_key_extra_src->group_id);
   1.104  
   1.105 -    if (group_keys_extra->group_id && !group_id){
   1.106 -        free(group_keys_extra);
   1.107 +    if (group_key_extra_dst->group_id && !group_id){
   1.108 +        free(group_key_extra_dst);
   1.109          return NULL;
   1.110      }
   1.111 -    group_keys_extra->group_id = group_id;
   1.112 +    group_key_extra_dst->group_id = group_id;
   1.113  
   1.114 -    identity_list *group_keys = identity_list_dup(group_keys_extra->group_keys);;
   1.115 +    identity_list *group_keys = identity_list_dup(group_key_extra_src->group_keys);;
   1.116      if (!group_keys) {
   1.117          free(group_id);
   1.118 -        free(group_keys_extra);
   1.119 +        free(group_key_extra_dst);
   1.120          return NULL;
   1.121      }
   1.122 -    group_keys_extra->group_keys = group_keys;
   1.123 +    group_key_extra_dst->group_keys = group_keys;
   1.124  
   1.125 -    return group_keys_extra;
   1.126 +    return group_key_extra_dst;
   1.127  }
   1.128  
     2.1 --- a/sync/devicegroup.fsm	Sat Mar 11 14:50:05 2017 +0100
     2.2 +++ b/sync/devicegroup.fsm	Mon Mar 13 14:33:17 2017 +0100
     2.3 @@ -142,6 +142,7 @@
     2.4                      do notifyAcceptedDeviceAdded(partner);
     2.5                      go Grouped;
     2.6                  }
     2.7 +                go Sole;
     2.8              }
     2.9              on Cancel go Sole;
    2.10              on Timeout {
    2.11 @@ -266,11 +267,13 @@
    2.12                  go Grouped;
    2.13              }
    2.14              on HandshakeAccepted(Identity partner) {
    2.15 -                do acceptHandshake(partner); 
    2.16 -                do storeGroupKeys(partner, groupkeys);
    2.17 -                do sendGroupUpdate;
    2.18 -                do renewUUID;
    2.19 -                do notifyAcceptedDeviceMoved(partner);
    2.20 +                if sameIdentities(partner, expected) {
    2.21 +                    do acceptHandshake(partner); 
    2.22 +                    do storeGroupKeys(partner, groupkeys);
    2.23 +                    do sendGroupUpdate;
    2.24 +                    do renewUUID;
    2.25 +                    do notifyAcceptedDeviceMoved(partner);
    2.26 +                }
    2.27                  go Grouped;
    2.28              }
    2.29              on Cancel go Grouped;
     3.1 --- a/sync/generated/sync_fsm.c	Sat Mar 11 14:50:05 2017 +0100
     3.2 +++ b/sync/generated/sync_fsm.c	Mon Mar 13 14:33:17 2017 +0100
     3.3 @@ -661,7 +661,14 @@
     3.4                          return Grouped;
     3.5                          }
     3.6                      }
     3.7 -                    break;
     3.8 +                    assert(session->sync_state_payload);
     3.9 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
    3.10 +                    free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
    3.11 +                    free_group_keys_extra(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->groupkeys);
    3.12 +                    free(session->sync_state_payload);
    3.13 +                    session->sync_state_payload = NULL;
    3.14 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "target=Sole")
    3.15 +                    return Sole;
    3.16                  }
    3.17                  case Cancel:
    3.18                  {
    3.19 @@ -1287,36 +1294,48 @@
    3.20                  case HandshakeAccepted:
    3.21                  {
    3.22                      DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=HandshakeAccepted")
    3.23 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=acceptHandshake")
    3.24 -                    status = acceptHandshake(session, state, partner, NULL);
    3.25 -                    if (status == PEP_OUT_OF_MEMORY)
    3.26 -                        return (int) invalid_out_of_memory;
    3.27 -                    if (status != PEP_STATUS_OK)
    3.28 -                        return (int) invalid_action;
    3.29 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=storeGroupKeys")
    3.30 -                    status = storeGroupKeys(session, state, partner, groupkeys);
    3.31 -                    if (status == PEP_OUT_OF_MEMORY)
    3.32 -                        return (int) invalid_out_of_memory;
    3.33 -                    if (status != PEP_STATUS_OK)
    3.34 -                        return (int) invalid_action;
    3.35 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=sendGroupUpdate")
    3.36 -                    status = sendGroupUpdate(session, state, NULL, NULL);
    3.37 -                    if (status == PEP_OUT_OF_MEMORY)
    3.38 -                        return (int) invalid_out_of_memory;
    3.39 -                    if (status != PEP_STATUS_OK)
    3.40 -                        return (int) invalid_action;
    3.41 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=renewUUID")
    3.42 -                    status = renewUUID(session, state, NULL, NULL);
    3.43 -                    if (status == PEP_OUT_OF_MEMORY)
    3.44 -                        return (int) invalid_out_of_memory;
    3.45 -                    if (status != PEP_STATUS_OK)
    3.46 -                        return (int) invalid_action;
    3.47 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=notifyAcceptedDeviceMoved")
    3.48 -                    status = notifyAcceptedDeviceMoved(session, state, partner, NULL);
    3.49 -                    if (status == PEP_OUT_OF_MEMORY)
    3.50 -                        return (int) invalid_out_of_memory;
    3.51 -                    if (status != PEP_STATUS_OK)
    3.52 -                        return (int) invalid_action;
    3.53 +                    {
    3.54 +                        int cond_result = sameIdentities(session, partner, expected);
    3.55 +                        #ifndef NDEBUG
    3.56 +                        char resstr[11] = {0,};
    3.57 +                        snprintf(resstr,10,"result=%d",cond_result);
    3.58 +                        #endif
    3.59 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted, condition=sameIdentities", resstr)
    3.60 +                        if (cond_result < 0)
    3.61 +                            return cond_result;
    3.62 +                        if (cond_result) {
    3.63 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=acceptHandshake")
    3.64 +                        status = acceptHandshake(session, state, partner, NULL);
    3.65 +                        if (status == PEP_OUT_OF_MEMORY)
    3.66 +                            return (int) invalid_out_of_memory;
    3.67 +                        if (status != PEP_STATUS_OK)
    3.68 +                            return (int) invalid_action;
    3.69 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=storeGroupKeys")
    3.70 +                        status = storeGroupKeys(session, state, partner, groupkeys);
    3.71 +                        if (status == PEP_OUT_OF_MEMORY)
    3.72 +                            return (int) invalid_out_of_memory;
    3.73 +                        if (status != PEP_STATUS_OK)
    3.74 +                            return (int) invalid_action;
    3.75 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=sendGroupUpdate")
    3.76 +                        status = sendGroupUpdate(session, state, NULL, NULL);
    3.77 +                        if (status == PEP_OUT_OF_MEMORY)
    3.78 +                            return (int) invalid_out_of_memory;
    3.79 +                        if (status != PEP_STATUS_OK)
    3.80 +                            return (int) invalid_action;
    3.81 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=renewUUID")
    3.82 +                        status = renewUUID(session, state, NULL, NULL);
    3.83 +                        if (status == PEP_OUT_OF_MEMORY)
    3.84 +                            return (int) invalid_out_of_memory;
    3.85 +                        if (status != PEP_STATUS_OK)
    3.86 +                            return (int) invalid_action;
    3.87 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=notifyAcceptedDeviceMoved")
    3.88 +                        status = notifyAcceptedDeviceMoved(session, state, partner, NULL);
    3.89 +                        if (status == PEP_OUT_OF_MEMORY)
    3.90 +                            return (int) invalid_out_of_memory;
    3.91 +                        if (status != PEP_STATUS_OK)
    3.92 +                            return (int) invalid_action;
    3.93 +                        }
    3.94 +                    }
    3.95                      assert(session->sync_state_payload);
    3.96                      if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
    3.97                      free_identity(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected);