ENGINE-196 ENGINE-197 Sync : fixed group not forming because of checking groupKeys's sender still has same UUID whereas it becomes group's UUID (was working before 52baaf882562, cause group UUID was the one from device)
authorEdouard Tisserant <edouard@pep-project.org>
Wed, 19 Apr 2017 17:12:54 +0200
changeset 1723c93e1ddf1059
parent 1712 af3d488f90d8
child 1724 a2a8ffce4a01
ENGINE-196 ENGINE-197 Sync : fixed group not forming because of checking groupKeys's sender still has same UUID whereas it becomes group's UUID (was working before 52baaf882562, cause group UUID was the one from device)
src/sync_actions.c
sync/devicegroup.fsm
sync/generated/sync_fsm.c
     1.1 --- a/src/sync_actions.c	Wed Apr 19 10:38:44 2017 +0200
     1.2 +++ b/src/sync_actions.c	Wed Apr 19 17:12:54 2017 +0200
     1.3 @@ -105,6 +105,23 @@
     1.4      return 1;
     1.5  }
     1.6  
     1.7 +int sameKeyAndAddress(PEP_SESSION session, Identity a, Identity b)
     1.8 +{
     1.9 +    assert(session);
    1.10 +    assert(a);
    1.11 +    assert(b);
    1.12 +
    1.13 +    if (!(session && a && b))
    1.14 +        return invalid_condition; // error
    1.15 +
    1.16 +    if (a->fpr == NULL || b->fpr == NULL ||
    1.17 +        (!_same_fpr(a->fpr, strlen(a->fpr), b->fpr, strlen(b->fpr))) ||
    1.18 +        a->address == NULL || b->address == NULL ||
    1.19 +        strcmp(a->address, b->address) != 0)
    1.20 +            return 0;
    1.21 +    return 1;
    1.22 +}
    1.23 +
    1.24  // actions
    1.25  
    1.26  PEP_STATUS _notifyHandshake(
     2.1 --- a/sync/devicegroup.fsm	Wed Apr 19 10:38:44 2017 +0200
     2.2 +++ b/sync/devicegroup.fsm	Wed Apr 19 17:12:54 2017 +0200
     2.3 @@ -71,7 +71,7 @@
     2.4  
     2.5          state HandshakingSole timeout=600 (Identity expected) {
     2.6              on Init{
     2.7 -                if keyElectionWon(partner) {
     2.8 +                if keyElectionWon(partner) { // TODO : should be "expected"
     2.9                      do notifyInitFormGroup(partner);
    2.10                  } else {
    2.11                      do notifyInitAddOurDevice(partner);
    2.12 @@ -97,10 +97,11 @@
    2.13              }
    2.14              on Cancel go Sole;
    2.15              on GroupKeys(Identity partner, GroupKeys groupkeys) {
    2.16 -                if keyElectionWon(partner) {
    2.17 +                if keyElectionWon(partner) { // TODO : use "expected"
    2.18                      // not suppose to receive groupkeys - ignore
    2.19                  } else {
    2.20 -                    if sameIdentities(partner, expected) {
    2.21 +                    // UUID changes in between, so we can only check for same address and fpr
    2.22 +                    if sameKeyAndAddress(partner, expected) {
    2.23                          go WaitForAcceptSole(partner, groupkeys);
    2.24                      }
    2.25                  }
    2.26 @@ -114,7 +115,8 @@
    2.27      
    2.28          state WaitForGroupKeysSole timeout=600 (Identity expected) {
    2.29              on GroupKeys(Identity partner, GroupKeys groupkeys) {
    2.30 -                if sameIdentities(partner, expected) {
    2.31 +                // UUID changes in between, so we can only check for same address and fpr
    2.32 +                if sameKeyAndAddress(partner, expected) {
    2.33                      do storeGroupKeys(partner, groupkeys);
    2.34                      do sendGroupUpdate;
    2.35                      do renewUUID;
    2.36 @@ -134,7 +136,8 @@
    2.37                  go Sole;
    2.38              }
    2.39              on HandshakeAccepted(Identity partner) {
    2.40 -                if sameIdentities(partner, expected) {
    2.41 +                // UUID changes in between, so we can only check for same address and fpr
    2.42 +                if sameKeyAndAddress(partner, expected) {
    2.43                      do acceptHandshake(partner); 
    2.44                      do storeGroupKeys(partner, groupkeys);
    2.45                      do sendGroupUpdate;
    2.46 @@ -201,7 +204,7 @@
    2.47          state HandshakingGrouped timeout=600 (Identity expected) {
    2.48              // HandshakeRequest from same group are filtered in receive_sync_msg
    2.49              on Init{
    2.50 -                if keyElectionWon(partner) {
    2.51 +                if keyElectionWon(partner) { // TODO : should be "expected"
    2.52                      do notifyInitAddOtherDevice(partner);
    2.53                  } else {
    2.54                      do notifyInitMoveOurDevice(partner);
    2.55 @@ -224,6 +227,7 @@
    2.56              }
    2.57              on Cancel go Grouped;
    2.58              on GroupKeys(Identity partner, GroupKeys groupkeys) {
    2.59 +                // TODO : check election  lost, check same address & fpr
    2.60                  if sameIdentities(partner, expected) {
    2.61                      go WaitForAcceptGrouped(partner, groupkeys);
    2.62                  }
     3.1 --- a/sync/generated/sync_fsm.c	Wed Apr 19 10:38:44 2017 +0200
     3.2 +++ b/sync/generated/sync_fsm.c	Wed Apr 19 17:12:54 2017 +0200
     3.3 @@ -439,12 +439,12 @@
     3.4                          }
     3.5                          else {
     3.6                          {
     3.7 -                            int cond_result = sameIdentities(session, partner, expected);
     3.8 +                            int cond_result = sameKeyAndAddress(session, partner, expected);
     3.9                              #ifndef NDEBUG
    3.10                              char resstr[11] = {0,};
    3.11                              snprintf(resstr,10,"result=%d",cond_result);
    3.12                              #endif
    3.13 -                            DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys, condition=sameIdentities", resstr)
    3.14 +                            DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys, condition=sameKeyAndAddress", resstr)
    3.15                              if (cond_result < 0)
    3.16                                  return cond_result;
    3.17                              if (cond_result) {
    3.18 @@ -512,12 +512,12 @@
    3.19                      DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=GroupKeys")
    3.20                      group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
    3.21                      {
    3.22 -                        int cond_result = sameIdentities(session, partner, expected);
    3.23 +                        int cond_result = sameKeyAndAddress(session, partner, expected);
    3.24                          #ifndef NDEBUG
    3.25                          char resstr[11] = {0,};
    3.26                          snprintf(resstr,10,"result=%d",cond_result);
    3.27                          #endif
    3.28 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys, condition=sameIdentities", resstr)
    3.29 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys, condition=sameKeyAndAddress", resstr)
    3.30                          if (cond_result < 0)
    3.31                              return cond_result;
    3.32                          if (cond_result) {
    3.33 @@ -612,12 +612,12 @@
    3.34                  {
    3.35                      DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=HandshakeAccepted")
    3.36                      {
    3.37 -                        int cond_result = sameIdentities(session, partner, expected);
    3.38 +                        int cond_result = sameKeyAndAddress(session, partner, expected);
    3.39                          #ifndef NDEBUG
    3.40                          char resstr[11] = {0,};
    3.41                          snprintf(resstr,10,"result=%d",cond_result);
    3.42                          #endif
    3.43 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted, condition=sameIdentities", resstr)
    3.44 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted, condition=sameKeyAndAddress", resstr)
    3.45                          if (cond_result < 0)
    3.46                              return cond_result;
    3.47                          if (cond_result) {