Sync : fixed some wrong sementics in FSM, and added missing check. Doesn't fix any known bug.
authorEdouard Tisserant <edouard@pep-project.org>
Wed, 19 Apr 2017 18:31:57 +0200
changeset 1724a2a8ffce4a01
parent 1723 c93e1ddf1059
child 1725 e450d7db515d
Sync : fixed some wrong sementics in FSM, and added missing check. Doesn't fix any known bug.
sync/devicegroup.fsm
sync/generated/sync_fsm.c
sync/skeletons/sync_actions.c
     1.1 --- a/sync/devicegroup.fsm	Wed Apr 19 17:12:54 2017 +0200
     1.2 +++ b/sync/devicegroup.fsm	Wed Apr 19 18:31:57 2017 +0200
     1.3 @@ -71,10 +71,10 @@
     1.4  
     1.5          state HandshakingSole timeout=600 (Identity expected) {
     1.6              on Init{
     1.7 -                if keyElectionWon(partner) { // TODO : should be "expected"
     1.8 -                    do notifyInitFormGroup(partner);
     1.9 +                if keyElectionWon(expected) {
    1.10 +                    do notifyInitFormGroup(expected);
    1.11                  } else {
    1.12 -                    do notifyInitAddOurDevice(partner);
    1.13 +                    do notifyInitAddOurDevice(expected);
    1.14                  }
    1.15              }
    1.16              on HandshakeRejected(Identity partner) {
    1.17 @@ -97,8 +97,8 @@
    1.18              }
    1.19              on Cancel go Sole;
    1.20              on GroupKeys(Identity partner, GroupKeys groupkeys) {
    1.21 -                if keyElectionWon(partner) { // TODO : use "expected"
    1.22 -                    // not suppose to receive groupkeys - ignore
    1.23 +                if keyElectionWon(expected) {
    1.24 +                    // not supposed to receive groupkeys - ignore
    1.25                  } else {
    1.26                      // UUID changes in between, so we can only check for same address and fpr
    1.27                      if sameKeyAndAddress(partner, expected) {
    1.28 @@ -204,7 +204,7 @@
    1.29          state HandshakingGrouped timeout=600 (Identity expected) {
    1.30              // HandshakeRequest from same group are filtered in receive_sync_msg
    1.31              on Init{
    1.32 -                if keyElectionWon(partner) { // TODO : should be "expected"
    1.33 +                if keyElectionWon(expected) {
    1.34                      do notifyInitAddOtherDevice(partner);
    1.35                  } else {
    1.36                      do notifyInitMoveOurDevice(partner);
    1.37 @@ -227,9 +227,13 @@
    1.38              }
    1.39              on Cancel go Grouped;
    1.40              on GroupKeys(Identity partner, GroupKeys groupkeys) {
    1.41 -                // TODO : check election  lost, check same address & fpr
    1.42 -                if sameIdentities(partner, expected) {
    1.43 -                    go WaitForAcceptGrouped(partner, groupkeys);
    1.44 +                if keyElectionWon(expected) {
    1.45 +                    // not supposed to receive groupkeys - ignore
    1.46 +                } else {
    1.47 +                    // UUID changes in between, so we can only check for same address and fpr
    1.48 +                    if sameKeyAndAddress(partner, expected) {
    1.49 +                        go WaitForAcceptGrouped(partner, groupkeys);
    1.50 +                    }
    1.51                  }
    1.52              }
    1.53              on GroupUpdate(Identity partner, IdentityList keys) {
     2.1 --- a/sync/generated/sync_fsm.c	Wed Apr 19 17:12:54 2017 +0200
     2.2 +++ b/sync/generated/sync_fsm.c	Wed Apr 19 18:31:57 2017 +0200
     2.3 @@ -283,7 +283,7 @@
     2.4                  {
     2.5                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Init")
     2.6                      {
     2.7 -                        int cond_result = keyElectionWon(session, partner);
     2.8 +                        int cond_result = keyElectionWon(session, expected);
     2.9                          #ifndef NDEBUG
    2.10                          char resstr[11] = {0,};
    2.11                          snprintf(resstr,10,"result=%d",cond_result);
    2.12 @@ -293,7 +293,7 @@
    2.13                              return cond_result;
    2.14                          if (cond_result) {
    2.15                          DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitFormGroup")
    2.16 -                        status = notifyInitFormGroup(session, state, partner, NULL);
    2.17 +                        status = notifyInitFormGroup(session, state, expected, NULL);
    2.18                          if (status == PEP_OUT_OF_MEMORY)
    2.19                              return (int) invalid_out_of_memory;
    2.20                          if (status != PEP_STATUS_OK)
    2.21 @@ -301,7 +301,7 @@
    2.22                          }
    2.23                          else {
    2.24                          DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitAddOurDevice")
    2.25 -                        status = notifyInitAddOurDevice(session, state, partner, NULL);
    2.26 +                        status = notifyInitAddOurDevice(session, state, expected, NULL);
    2.27                          if (status == PEP_OUT_OF_MEMORY)
    2.28                              return (int) invalid_out_of_memory;
    2.29                          if (status != PEP_STATUS_OK)
    2.30 @@ -427,7 +427,7 @@
    2.31                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=GroupKeys")
    2.32                      group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
    2.33                      {
    2.34 -                        int cond_result = keyElectionWon(session, partner);
    2.35 +                        int cond_result = keyElectionWon(session, expected);
    2.36                          #ifndef NDEBUG
    2.37                          char resstr[11] = {0,};
    2.38                          snprintf(resstr,10,"result=%d",cond_result);
    2.39 @@ -951,7 +951,7 @@
    2.40                  {
    2.41                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Init")
    2.42                      {
    2.43 -                        int cond_result = keyElectionWon(session, partner);
    2.44 +                        int cond_result = keyElectionWon(session, expected);
    2.45                          #ifndef NDEBUG
    2.46                          char resstr[11] = {0,};
    2.47                          snprintf(resstr,10,"result=%d",cond_result);
    2.48 @@ -1076,29 +1076,43 @@
    2.49                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=GroupKeys")
    2.50                      group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
    2.51                      {
    2.52 -                        int cond_result = sameIdentities(session, partner, expected);
    2.53 +                        int cond_result = keyElectionWon(session, expected);
    2.54                          #ifndef NDEBUG
    2.55                          char resstr[11] = {0,};
    2.56                          snprintf(resstr,10,"result=%d",cond_result);
    2.57                          #endif
    2.58 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys, condition=sameIdentities", resstr)
    2.59 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys, condition=keyElectionWon", resstr)
    2.60                          if (cond_result < 0)
    2.61                              return cond_result;
    2.62                          if (cond_result) {
    2.63 -                        assert(session->sync_state_payload);
    2.64 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
    2.65 -                        free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
    2.66 -                        free(session->sync_state_payload);
    2.67 -                        session->sync_state_payload = NULL;
    2.68 -                        session->sync_state_payload = malloc(sizeof(WaitForAcceptGrouped_state_payload_t));
    2.69 -                        assert(session->sync_state_payload);
    2.70 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
    2.71 -                        ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected =
    2.72 -                            identity_dup(partner);
    2.73 -                        ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->groupkeys =
    2.74 -                            group_keys_extra_dup(groupkeys);
    2.75 -                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys", "target=WaitForAcceptGrouped")
    2.76 -                        return WaitForAcceptGrouped;
    2.77 +                        }
    2.78 +                        else {
    2.79 +                        {
    2.80 +                            int cond_result = sameKeyAndAddress(session, partner, expected);
    2.81 +                            #ifndef NDEBUG
    2.82 +                            char resstr[11] = {0,};
    2.83 +                            snprintf(resstr,10,"result=%d",cond_result);
    2.84 +                            #endif
    2.85 +                            DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys, condition=sameKeyAndAddress", resstr)
    2.86 +                            if (cond_result < 0)
    2.87 +                                return cond_result;
    2.88 +                            if (cond_result) {
    2.89 +                            assert(session->sync_state_payload);
    2.90 +                            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
    2.91 +                            free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
    2.92 +                            free(session->sync_state_payload);
    2.93 +                            session->sync_state_payload = NULL;
    2.94 +                            session->sync_state_payload = malloc(sizeof(WaitForAcceptGrouped_state_payload_t));
    2.95 +                            assert(session->sync_state_payload);
    2.96 +                            if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
    2.97 +                            ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected =
    2.98 +                                identity_dup(partner);
    2.99 +                            ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->groupkeys =
   2.100 +                                group_keys_extra_dup(groupkeys);
   2.101 +                            DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys", "target=WaitForAcceptGrouped")
   2.102 +                            return WaitForAcceptGrouped;
   2.103 +                            }
   2.104 +                        }
   2.105                          }
   2.106                      }
   2.107                      break;
     3.1 --- a/sync/skeletons/sync_actions.c	Wed Apr 19 17:12:54 2017 +0200
     3.2 +++ b/sync/skeletons/sync_actions.c	Wed Apr 19 18:31:57 2017 +0200
     3.3 @@ -28,8 +28,8 @@
     3.4      PEP_STATUS status = PEP_STATUS_OK;
     3.5  
     3.6      assert(session);
     3.7 -    assert(partner);
     3.8 -    if (!(session && partner))
     3.9 +    assert(!partner);
    3.10 +    if (!(session && !partner))
    3.11          return PEP_ILLEGAL_VALUE;
    3.12  
    3.13      // working code
    3.14 @@ -65,8 +65,8 @@
    3.15      PEP_STATUS status = PEP_STATUS_OK;
    3.16  
    3.17      assert(session);
    3.18 -    assert(partner);
    3.19 -    if (!(session && partner))
    3.20 +    assert(!partner);
    3.21 +    if (!(session && !partner))
    3.22          return PEP_ILLEGAL_VALUE;
    3.23  
    3.24      // working code