KeySync : made UUID renewal when entering group explicit in fsm, and moved it after sendGroupKeys to be sure it is accepted by peer. Also fixed bug generating else part of conditions in fsm.
authorEdouard Tisserant <edouard@pep-project.org>
Tue, 21 Feb 2017 23:08:01 +0100
changeset 160110e4e77e2278
parent 1600 9be501327dfd
child 1602 904da6719597
KeySync : made UUID renewal when entering group explicit in fsm, and moved it after sendGroupKeys to be sure it is accepted by peer. Also fixed bug generating else part of conditions in fsm.
src/sync_actions.c
sync/devicegroup.fsm
sync/gen_statemachine.ysl2
sync/generated/sync_fsm.c
sync/generated/sync_fsm.h
sync/skeletons/sync_actions.c
     1.1 --- a/src/sync_actions.c	Mon Feb 20 22:36:07 2017 +0100
     1.2 +++ b/src/sync_actions.c	Tue Feb 21 23:08:01 2017 +0100
     1.3 @@ -285,13 +285,6 @@
     1.4      if (status != PEP_STATUS_OK)
     1.5          return status;
     1.6      
     1.7 -    // change sync_uuid when entering group 
     1.8 -    // thus ignoring unprocessed handshakes
     1.9 -    // addressed to previous self (sole) once in.
    1.10 -    pEpUUID uuid;
    1.11 -    uuid_generate_random(uuid);
    1.12 -    uuid_unparse_upper(uuid, session->sync_uuid);
    1.13 -
    1.14      return status;
    1.15  }
    1.16  
    1.17 @@ -328,6 +321,7 @@
    1.18  
    1.19      return status;
    1.20  }
    1.21 +
    1.22  // makeGroup() - 
    1.23  //
    1.24  //  params:
    1.25 @@ -349,6 +343,34 @@
    1.26      PEP_STATUS status = PEP_STATUS_OK;
    1.27  
    1.28      assert(session);
    1.29 +    
    1.30 +    // take that new uuid as group-id
    1.31 +    status = set_device_group(session, session->sync_uuid);
    1.32 +
    1.33 +    return status;
    1.34 +}
    1.35 +
    1.36 +// renewUUID() - 
    1.37 +//
    1.38 +//  params:
    1.39 +//      session (in)        session handle
    1.40 +//      state (in)          state the state machine is in
    1.41 +//      partner (in)        ignored
    1.42 +//      extra (in)          ignored
    1.43 +//
    1.44 +//  returns:
    1.45 +//      PEP_STATUS_OK or any other value on error
    1.46 +
    1.47 +PEP_STATUS renewUUID(
    1.48 +        PEP_SESSION session,
    1.49 +        DeviceState_state state,
    1.50 +        Identity partner,
    1.51 +        void *extra
    1.52 +    )
    1.53 +{
    1.54 +    PEP_STATUS status = PEP_STATUS_OK;
    1.55 +
    1.56 +    assert(session);
    1.57  
    1.58      // change sync_uuid when entering group 
    1.59      // thus ignoring unprocessed handshakes
    1.60 @@ -357,9 +379,6 @@
    1.61      uuid_generate_random(uuid);
    1.62      uuid_unparse_upper(uuid, session->sync_uuid);
    1.63      
    1.64 -    // take that new uuid as group-id
    1.65 -    status = set_device_group(session, session->sync_uuid);
    1.66 -
    1.67      return status;
    1.68  }
    1.69  
     2.1 --- a/sync/devicegroup.fsm	Mon Feb 20 22:36:07 2017 +0100
     2.2 +++ b/sync/devicegroup.fsm	Tue Feb 21 23:08:01 2017 +0100
     2.3 @@ -87,6 +87,7 @@
     2.4                      if keyElectionWon(partner) {
     2.5                          do makeGroup;
     2.6                          do sendGroupKeys(partner);
     2.7 +                        do renewUUID;
     2.8                          do notifyAcceptedGroupCreated(partner);
     2.9                          go Grouped;
    2.10                      }
    2.11 @@ -96,8 +97,12 @@
    2.12              }
    2.13              on Cancel go Sole;
    2.14              on GroupKeys(Identity partner, GroupKeys groupkeys) {
    2.15 -                if sameIdentities(partner, expected) {
    2.16 -                    go WaitForAcceptSole(partner, groupkeys);
    2.17 +                if keyElectionWon(partner) {
    2.18 +                    // not suppose to receive groupkeys - ignore
    2.19 +                } else {
    2.20 +                    if sameIdentities(partner, expected) {
    2.21 +                        go WaitForAcceptSole(partner, groupkeys);
    2.22 +                    }
    2.23                  }
    2.24              }
    2.25              on Timeout {
    2.26 @@ -112,6 +117,7 @@
    2.27                  if sameIdentities(partner, expected) {
    2.28                      do storeGroupKeys(partner, groupkeys);
    2.29                      do sendGroupUpdate;
    2.30 +                    do renewUUID;
    2.31                      do notifyAcceptedDeviceAdded(partner);
    2.32                      go Grouped;
    2.33                  }
    2.34 @@ -132,10 +138,10 @@
    2.35                      do acceptHandshake(partner); 
    2.36                      do storeGroupKeys(partner, groupkeys);
    2.37                      do sendGroupUpdate;
    2.38 +                    do renewUUID;
    2.39                      do notifyAcceptedDeviceAdded(partner);
    2.40                      go Grouped;
    2.41                  }
    2.42 -                go Sole;
    2.43              }
    2.44              on Cancel go Sole;
    2.45              on Timeout {
    2.46 @@ -230,6 +236,7 @@
    2.47                  if sameIdentities(partner, expected) {
    2.48                      do storeGroupKeys(partner, groupkeys);
    2.49                      do sendGroupUpdate;
    2.50 +                    do renewUUID;
    2.51                      do notifyAcceptedDeviceMoved(partner);
    2.52                      go Grouped;
    2.53                  }
    2.54 @@ -249,6 +256,7 @@
    2.55                  do acceptHandshake(partner); 
    2.56                  do storeGroupKeys(partner, groupkeys);
    2.57                  do sendGroupUpdate;
    2.58 +                do renewUUID;
    2.59                  do notifyAcceptedDeviceMoved(partner);
    2.60                  go Grouped;
    2.61              }
     3.1 --- a/sync/gen_statemachine.ysl2	Mon Feb 20 22:36:07 2017 +0100
     3.2 +++ b/sync/gen_statemachine.ysl2	Tue Feb 21 23:08:01 2017 +0100
     3.3 @@ -202,7 +202,6 @@
     3.4                  time_t *timeout
     3.5              )
     3.6          {
     3.7 -            int cond_result;
     3.8              PEP_STATUS status = PEP_STATUS_OK;
     3.9  
    3.10              switch (state) {
    3.11 @@ -335,23 +334,25 @@
    3.12      }
    3.13  
    3.14      template "condition" {
    3.15 -        | cond_result = «@name»(session`apply "parm", 0`);
    3.16 -        | #ifndef NDEBUG
    3.17 -        | char resstr[11] = {0,};
    3.18 -        | snprintf(resstr,10,"result=%d",cond_result);
    3.19 -        | #endif
    3.20 -        | DEBUG_LOG("FSM condition", "«ancestor::fsm/@filename»_fsm.c, state=«ancestor::state/@name», event=«ancestor::event/@name», condition=«@name»", resstr)
    3.21 -        | if (cond_result < 0)
    3.22 -        |> return cond_result;
    3.23 -        | if (cond_result) {
    3.24 +        | {
    3.25 +        |> int cond_result = «@name»(session`apply "parm", 0`);
    3.26 +        |> #ifndef NDEBUG
    3.27 +        |> char resstr[11] = {0,};
    3.28 +        |> snprintf(resstr,10,"result=%d",cond_result);
    3.29 +        |> #endif
    3.30 +        |> DEBUG_LOG("FSM condition", "«ancestor::fsm/@filename»_fsm.c, state=«ancestor::state/@name», event=«ancestor::event/@name», condition=«@name»", resstr)
    3.31 +        |> if (cond_result < 0)
    3.32 +        |>> return cond_result;
    3.33 +        |> if (cond_result) {
    3.34          apply "action|transition|condition";
    3.35 -        | }
    3.36 +        |> }
    3.37          const "else", "./following-sibling::*[position()=1][name(.)='else']";
    3.38          if "$else" {
    3.39 -        | else {
    3.40 -        apply "$else/action|transition|condition";
    3.41 +        |> else {
    3.42 +        apply "$else/action|$else/transition|$else/condition";
    3.43 +        |> }
    3.44 +        }
    3.45          | }
    3.46 -        }
    3.47      }
    3.48  
    3.49      template "parm" choose {
     4.1 --- a/sync/generated/sync_fsm.c	Mon Feb 20 22:36:07 2017 +0100
     4.2 +++ b/sync/generated/sync_fsm.c	Tue Feb 21 23:08:01 2017 +0100
     4.3 @@ -50,7 +50,6 @@
     4.4          time_t *timeout
     4.5      )
     4.6  {
     4.7 -    int cond_result;
     4.8      PEP_STATUS status = PEP_STATUS_OK;
     4.9  
    4.10      switch (state) {
    4.11 @@ -62,17 +61,19 @@
    4.12                  case Init:
    4.13                  {
    4.14                      DEBUG_LOG("FSM event", "sync_fsm.c, state=InitState", "event=Init")
    4.15 -                    cond_result = deviceGrouped(session);
    4.16 -                    #ifndef NDEBUG
    4.17 -                    char resstr[11] = {0,};
    4.18 -                    snprintf(resstr,10,"result=%d",cond_result);
    4.19 -                    #endif
    4.20 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=InitState, event=Init, condition=deviceGrouped", resstr)
    4.21 -                    if (cond_result < 0)
    4.22 -                        return cond_result;
    4.23 -                    if (cond_result) {
    4.24 +                    {
    4.25 +                        int cond_result = deviceGrouped(session);
    4.26 +                        #ifndef NDEBUG
    4.27 +                        char resstr[11] = {0,};
    4.28 +                        snprintf(resstr,10,"result=%d",cond_result);
    4.29 +                        #endif
    4.30 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=InitState, event=Init, condition=deviceGrouped", resstr)
    4.31 +                        if (cond_result < 0)
    4.32 +                            return cond_result;
    4.33 +                        if (cond_result) {
    4.34                          DEBUG_LOG("FSM transition", "sync_fsm.c, state=InitState, event=Init", "target=Grouped")
    4.35                          return Grouped;
    4.36 +                        }
    4.37                      }
    4.38                      DEBUG_LOG("FSM transition", "sync_fsm.c, state=InitState, event=Init", "target=Sole")
    4.39                      return Sole;
    4.40 @@ -221,23 +222,25 @@
    4.41                  case HandshakeRequest:
    4.42                  {
    4.43                      DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=HandshakeRequest")
    4.44 -                    cond_result = sameIdentities(session, partner, expected);
    4.45 -                    #ifndef NDEBUG
    4.46 -                    char resstr[11] = {0,};
    4.47 -                    snprintf(resstr,10,"result=%d",cond_result);
    4.48 -                    #endif
    4.49 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest, condition=sameIdentities", resstr)
    4.50 -                    if (cond_result < 0)
    4.51 -                        return cond_result;
    4.52 -                    if (cond_result) {
    4.53 -                    }
    4.54 -                    else {
    4.55 +                    {
    4.56 +                        int cond_result = sameIdentities(session, partner, expected);
    4.57 +                        #ifndef NDEBUG
    4.58 +                        char resstr[11] = {0,};
    4.59 +                        snprintf(resstr,10,"result=%d",cond_result);
    4.60 +                        #endif
    4.61 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest, condition=sameIdentities", resstr)
    4.62 +                        if (cond_result < 0)
    4.63 +                            return cond_result;
    4.64 +                        if (cond_result) {
    4.65 +                        }
    4.66 +                        else {
    4.67                          DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest", "action=sendHandshakeRequest")
    4.68                          status = sendHandshakeRequest(session, state, partner, NULL);
    4.69                          if (status == PEP_OUT_OF_MEMORY)
    4.70                              return (int) invalid_out_of_memory;
    4.71                          if (status != PEP_STATUS_OK)
    4.72                              return (int) invalid_action;
    4.73 +                        }
    4.74                      }
    4.75                      assert(session->sync_state_payload);
    4.76                      if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
    4.77 @@ -279,29 +282,31 @@
    4.78                  case Init:
    4.79                  {
    4.80                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Init")
    4.81 -                    cond_result = keyElectionWon(session, partner);
    4.82 -                    #ifndef NDEBUG
    4.83 -                    char resstr[11] = {0,};
    4.84 -                    snprintf(resstr,10,"result=%d",cond_result);
    4.85 -                    #endif
    4.86 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=Init, condition=keyElectionWon", resstr)
    4.87 -                    if (cond_result < 0)
    4.88 -                        return cond_result;
    4.89 -                    if (cond_result) {
    4.90 +                    {
    4.91 +                        int cond_result = keyElectionWon(session, partner);
    4.92 +                        #ifndef NDEBUG
    4.93 +                        char resstr[11] = {0,};
    4.94 +                        snprintf(resstr,10,"result=%d",cond_result);
    4.95 +                        #endif
    4.96 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=Init, condition=keyElectionWon", resstr)
    4.97 +                        if (cond_result < 0)
    4.98 +                            return cond_result;
    4.99 +                        if (cond_result) {
   4.100                          DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitFormGroup")
   4.101                          status = notifyInitFormGroup(session, state, partner, NULL);
   4.102                          if (status == PEP_OUT_OF_MEMORY)
   4.103                              return (int) invalid_out_of_memory;
   4.104                          if (status != PEP_STATUS_OK)
   4.105                              return (int) invalid_action;
   4.106 -                    }
   4.107 -                    else {
   4.108 +                        }
   4.109 +                        else {
   4.110                          DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitAddOurDevice")
   4.111                          status = notifyInitAddOurDevice(session, state, partner, NULL);
   4.112                          if (status == PEP_OUT_OF_MEMORY)
   4.113                              return (int) invalid_out_of_memory;
   4.114                          if (status != PEP_STATUS_OK)
   4.115                              return (int) invalid_action;
   4.116 +                        }
   4.117                      }
   4.118                      break;
   4.119                  }
   4.120 @@ -325,30 +330,32 @@
   4.121                  case HandshakeAccepted:
   4.122                  {
   4.123                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=HandshakeAccepted")
   4.124 -                    cond_result = sameIdentities(session, partner, expected);
   4.125 -                    #ifndef NDEBUG
   4.126 -                    char resstr[11] = {0,};
   4.127 -                    snprintf(resstr,10,"result=%d",cond_result);
   4.128 -                    #endif
   4.129 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted, condition=sameIdentities", resstr)
   4.130 -                    if (cond_result < 0)
   4.131 -                        return cond_result;
   4.132 -                    if (cond_result) {
   4.133 +                    {
   4.134 +                        int cond_result = sameIdentities(session, partner, expected);
   4.135 +                        #ifndef NDEBUG
   4.136 +                        char resstr[11] = {0,};
   4.137 +                        snprintf(resstr,10,"result=%d",cond_result);
   4.138 +                        #endif
   4.139 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted, condition=sameIdentities", resstr)
   4.140 +                        if (cond_result < 0)
   4.141 +                            return cond_result;
   4.142 +                        if (cond_result) {
   4.143                          DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=acceptHandshake")
   4.144                          status = acceptHandshake(session, state, partner, NULL);
   4.145                          if (status == PEP_OUT_OF_MEMORY)
   4.146                              return (int) invalid_out_of_memory;
   4.147                          if (status != PEP_STATUS_OK)
   4.148                              return (int) invalid_action;
   4.149 -                        cond_result = keyElectionWon(session, partner);
   4.150 -                        #ifndef NDEBUG
   4.151 -                        char resstr[11] = {0,};
   4.152 -                        snprintf(resstr,10,"result=%d",cond_result);
   4.153 -                        #endif
   4.154 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted, condition=keyElectionWon", resstr)
   4.155 -                        if (cond_result < 0)
   4.156 -                            return cond_result;
   4.157 -                        if (cond_result) {
   4.158 +                        {
   4.159 +                            int cond_result = keyElectionWon(session, partner);
   4.160 +                            #ifndef NDEBUG
   4.161 +                            char resstr[11] = {0,};
   4.162 +                            snprintf(resstr,10,"result=%d",cond_result);
   4.163 +                            #endif
   4.164 +                            DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted, condition=keyElectionWon", resstr)
   4.165 +                            if (cond_result < 0)
   4.166 +                                return cond_result;
   4.167 +                            if (cond_result) {
   4.168                              DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=makeGroup")
   4.169                              status = makeGroup(session, state, NULL, NULL);
   4.170                              if (status == PEP_OUT_OF_MEMORY)
   4.171 @@ -361,6 +368,12 @@
   4.172                                  return (int) invalid_out_of_memory;
   4.173                              if (status != PEP_STATUS_OK)
   4.174                                  return (int) invalid_action;
   4.175 +                            DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=renewUUID")
   4.176 +                            status = renewUUID(session, state, NULL, NULL);
   4.177 +                            if (status == PEP_OUT_OF_MEMORY)
   4.178 +                                return (int) invalid_out_of_memory;
   4.179 +                            if (status != PEP_STATUS_OK)
   4.180 +                                return (int) invalid_action;
   4.181                              DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=notifyAcceptedGroupCreated")
   4.182                              status = notifyAcceptedGroupCreated(session, state, partner, NULL);
   4.183                              if (status == PEP_OUT_OF_MEMORY)
   4.184 @@ -374,6 +387,7 @@
   4.185                              session->sync_state_payload = NULL;
   4.186                              DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=Grouped")
   4.187                              return Grouped;
   4.188 +                            }
   4.189                          }
   4.190                          assert(session->sync_state_payload);
   4.191                          if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   4.192 @@ -387,6 +401,7 @@
   4.193                              identity_dup(partner);
   4.194                          DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=WaitForGroupKeysSole")
   4.195                          return WaitForGroupKeysSole;
   4.196 +                        }
   4.197                      }
   4.198                      assert(session->sync_state_payload);
   4.199                      if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   4.200 @@ -411,29 +426,45 @@
   4.201                  {
   4.202                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=GroupKeys")
   4.203                      group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
   4.204 -                    cond_result = sameIdentities(session, partner, expected);
   4.205 -                    #ifndef NDEBUG
   4.206 -                    char resstr[11] = {0,};
   4.207 -                    snprintf(resstr,10,"result=%d",cond_result);
   4.208 -                    #endif
   4.209 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys, condition=sameIdentities", resstr)
   4.210 -                    if (cond_result < 0)
   4.211 -                        return cond_result;
   4.212 -                    if (cond_result) {
   4.213 -                        assert(session->sync_state_payload);
   4.214 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   4.215 -                        free_identity(((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected);
   4.216 -                        free(session->sync_state_payload);
   4.217 -                        session->sync_state_payload = NULL;
   4.218 -                        session->sync_state_payload = malloc(sizeof(WaitForAcceptSole_state_payload_t));
   4.219 -                        assert(session->sync_state_payload);
   4.220 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
   4.221 -                        ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected =
   4.222 -                            identity_dup(partner);
   4.223 -                        ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->groupkeys =
   4.224 -                            group_keys_extra_dup(groupkeys);
   4.225 -                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys", "target=WaitForAcceptSole")
   4.226 -                        return WaitForAcceptSole;
   4.227 +                    {
   4.228 +                        int cond_result = keyElectionWon(session, partner);
   4.229 +                        #ifndef NDEBUG
   4.230 +                        char resstr[11] = {0,};
   4.231 +                        snprintf(resstr,10,"result=%d",cond_result);
   4.232 +                        #endif
   4.233 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys, condition=keyElectionWon", resstr)
   4.234 +                        if (cond_result < 0)
   4.235 +                            return cond_result;
   4.236 +                        if (cond_result) {
   4.237 +                        }
   4.238 +                        else {
   4.239 +                        {
   4.240 +                            int cond_result = sameIdentities(session, partner, expected);
   4.241 +                            #ifndef NDEBUG
   4.242 +                            char resstr[11] = {0,};
   4.243 +                            snprintf(resstr,10,"result=%d",cond_result);
   4.244 +                            #endif
   4.245 +                            DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys, condition=sameIdentities", resstr)
   4.246 +                            if (cond_result < 0)
   4.247 +                                return cond_result;
   4.248 +                            if (cond_result) {
   4.249 +                            assert(session->sync_state_payload);
   4.250 +                            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   4.251 +                            free_identity(((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected);
   4.252 +                            free(session->sync_state_payload);
   4.253 +                            session->sync_state_payload = NULL;
   4.254 +                            session->sync_state_payload = malloc(sizeof(WaitForAcceptSole_state_payload_t));
   4.255 +                            assert(session->sync_state_payload);
   4.256 +                            if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
   4.257 +                            ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected =
   4.258 +                                identity_dup(partner);
   4.259 +                            ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->groupkeys =
   4.260 +                                group_keys_extra_dup(groupkeys);
   4.261 +                            DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys", "target=WaitForAcceptSole")
   4.262 +                            return WaitForAcceptSole;
   4.263 +                            }
   4.264 +                        }
   4.265 +                        }
   4.266                      }
   4.267                      break;
   4.268                  }
   4.269 @@ -480,15 +511,16 @@
   4.270                  {
   4.271                      DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=GroupKeys")
   4.272                      group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
   4.273 -                    cond_result = sameIdentities(session, partner, expected);
   4.274 -                    #ifndef NDEBUG
   4.275 -                    char resstr[11] = {0,};
   4.276 -                    snprintf(resstr,10,"result=%d",cond_result);
   4.277 -                    #endif
   4.278 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys, condition=sameIdentities", resstr)
   4.279 -                    if (cond_result < 0)
   4.280 -                        return cond_result;
   4.281 -                    if (cond_result) {
   4.282 +                    {
   4.283 +                        int cond_result = sameIdentities(session, partner, expected);
   4.284 +                        #ifndef NDEBUG
   4.285 +                        char resstr[11] = {0,};
   4.286 +                        snprintf(resstr,10,"result=%d",cond_result);
   4.287 +                        #endif
   4.288 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys, condition=sameIdentities", resstr)
   4.289 +                        if (cond_result < 0)
   4.290 +                            return cond_result;
   4.291 +                        if (cond_result) {
   4.292                          DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=storeGroupKeys")
   4.293                          status = storeGroupKeys(session, state, partner, groupkeys);
   4.294                          if (status == PEP_OUT_OF_MEMORY)
   4.295 @@ -501,6 +533,12 @@
   4.296                              return (int) invalid_out_of_memory;
   4.297                          if (status != PEP_STATUS_OK)
   4.298                              return (int) invalid_action;
   4.299 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=renewUUID")
   4.300 +                        status = renewUUID(session, state, NULL, NULL);
   4.301 +                        if (status == PEP_OUT_OF_MEMORY)
   4.302 +                            return (int) invalid_out_of_memory;
   4.303 +                        if (status != PEP_STATUS_OK)
   4.304 +                            return (int) invalid_action;
   4.305                          DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=notifyAcceptedDeviceAdded")
   4.306                          status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
   4.307                          if (status == PEP_OUT_OF_MEMORY)
   4.308 @@ -514,6 +552,7 @@
   4.309                          session->sync_state_payload = NULL;
   4.310                          DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "target=Grouped")
   4.311                          return Grouped;
   4.312 +                        }
   4.313                      }
   4.314                      break;
   4.315                  }
   4.316 @@ -572,15 +611,16 @@
   4.317                  case HandshakeAccepted:
   4.318                  {
   4.319                      DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=HandshakeAccepted")
   4.320 -                    cond_result = sameIdentities(session, partner, expected);
   4.321 -                    #ifndef NDEBUG
   4.322 -                    char resstr[11] = {0,};
   4.323 -                    snprintf(resstr,10,"result=%d",cond_result);
   4.324 -                    #endif
   4.325 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted, condition=sameIdentities", resstr)
   4.326 -                    if (cond_result < 0)
   4.327 -                        return cond_result;
   4.328 -                    if (cond_result) {
   4.329 +                    {
   4.330 +                        int cond_result = sameIdentities(session, partner, expected);
   4.331 +                        #ifndef NDEBUG
   4.332 +                        char resstr[11] = {0,};
   4.333 +                        snprintf(resstr,10,"result=%d",cond_result);
   4.334 +                        #endif
   4.335 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted, condition=sameIdentities", resstr)
   4.336 +                        if (cond_result < 0)
   4.337 +                            return cond_result;
   4.338 +                        if (cond_result) {
   4.339                          DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=acceptHandshake")
   4.340                          status = acceptHandshake(session, state, partner, NULL);
   4.341                          if (status == PEP_OUT_OF_MEMORY)
   4.342 @@ -599,6 +639,12 @@
   4.343                              return (int) invalid_out_of_memory;
   4.344                          if (status != PEP_STATUS_OK)
   4.345                              return (int) invalid_action;
   4.346 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=renewUUID")
   4.347 +                        status = renewUUID(session, state, NULL, NULL);
   4.348 +                        if (status == PEP_OUT_OF_MEMORY)
   4.349 +                            return (int) invalid_out_of_memory;
   4.350 +                        if (status != PEP_STATUS_OK)
   4.351 +                            return (int) invalid_action;
   4.352                          DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=notifyAcceptedDeviceAdded")
   4.353                          status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
   4.354                          if (status == PEP_OUT_OF_MEMORY)
   4.355 @@ -613,15 +659,9 @@
   4.356                          session->sync_state_payload = NULL;
   4.357                          DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "target=Grouped")
   4.358                          return Grouped;
   4.359 +                        }
   4.360                      }
   4.361 -                    assert(session->sync_state_payload);
   4.362 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   4.363 -                    free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
   4.364 -                    free_group_keys_extra(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->groupkeys);
   4.365 -                    free(session->sync_state_payload);
   4.366 -                    session->sync_state_payload = NULL;
   4.367 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "target=Sole")
   4.368 -                    return Sole;
   4.369 +                    break;
   4.370                  }
   4.371                  case Cancel:
   4.372                  {
   4.373 @@ -831,23 +871,25 @@
   4.374                  case HandshakeRequest:
   4.375                  {
   4.376                      DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=HandshakeRequest")
   4.377 -                    cond_result = sameIdentities(session, partner, expected);
   4.378 -                    #ifndef NDEBUG
   4.379 -                    char resstr[11] = {0,};
   4.380 -                    snprintf(resstr,10,"result=%d",cond_result);
   4.381 -                    #endif
   4.382 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest, condition=sameIdentities", resstr)
   4.383 -                    if (cond_result < 0)
   4.384 -                        return cond_result;
   4.385 -                    if (cond_result) {
   4.386 -                    }
   4.387 -                    else {
   4.388 +                    {
   4.389 +                        int cond_result = sameIdentities(session, partner, expected);
   4.390 +                        #ifndef NDEBUG
   4.391 +                        char resstr[11] = {0,};
   4.392 +                        snprintf(resstr,10,"result=%d",cond_result);
   4.393 +                        #endif
   4.394 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest, condition=sameIdentities", resstr)
   4.395 +                        if (cond_result < 0)
   4.396 +                            return cond_result;
   4.397 +                        if (cond_result) {
   4.398 +                        }
   4.399 +                        else {
   4.400                          DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest", "action=sendHandshakeRequest")
   4.401                          status = sendHandshakeRequest(session, state, partner, NULL);
   4.402                          if (status == PEP_OUT_OF_MEMORY)
   4.403                              return (int) invalid_out_of_memory;
   4.404                          if (status != PEP_STATUS_OK)
   4.405                              return (int) invalid_action;
   4.406 +                        }
   4.407                      }
   4.408                      assert(session->sync_state_payload);
   4.409                      if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   4.410 @@ -901,29 +943,31 @@
   4.411                  case Init:
   4.412                  {
   4.413                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Init")
   4.414 -                    cond_result = keyElectionWon(session, partner);
   4.415 -                    #ifndef NDEBUG
   4.416 -                    char resstr[11] = {0,};
   4.417 -                    snprintf(resstr,10,"result=%d",cond_result);
   4.418 -                    #endif
   4.419 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=Init, condition=keyElectionWon", resstr)
   4.420 -                    if (cond_result < 0)
   4.421 -                        return cond_result;
   4.422 -                    if (cond_result) {
   4.423 +                    {
   4.424 +                        int cond_result = keyElectionWon(session, partner);
   4.425 +                        #ifndef NDEBUG
   4.426 +                        char resstr[11] = {0,};
   4.427 +                        snprintf(resstr,10,"result=%d",cond_result);
   4.428 +                        #endif
   4.429 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=Init, condition=keyElectionWon", resstr)
   4.430 +                        if (cond_result < 0)
   4.431 +                            return cond_result;
   4.432 +                        if (cond_result) {
   4.433                          DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Init", "action=notifyInitAddOtherDevice")
   4.434                          status = notifyInitAddOtherDevice(session, state, partner, NULL);
   4.435                          if (status == PEP_OUT_OF_MEMORY)
   4.436                              return (int) invalid_out_of_memory;
   4.437                          if (status != PEP_STATUS_OK)
   4.438                              return (int) invalid_action;
   4.439 -                    }
   4.440 -                    else {
   4.441 +                        }
   4.442 +                        else {
   4.443                          DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Init", "action=notifyInitMoveOurDevice")
   4.444                          status = notifyInitMoveOurDevice(session, state, partner, NULL);
   4.445                          if (status == PEP_OUT_OF_MEMORY)
   4.446                              return (int) invalid_out_of_memory;
   4.447                          if (status != PEP_STATUS_OK)
   4.448                              return (int) invalid_action;
   4.449 +                        }
   4.450                      }
   4.451                      break;
   4.452                  }
   4.453 @@ -953,15 +997,16 @@
   4.454                          return (int) invalid_out_of_memory;
   4.455                      if (status != PEP_STATUS_OK)
   4.456                          return (int) invalid_action;
   4.457 -                    cond_result = keyElectionWon(session, partner);
   4.458 -                    #ifndef NDEBUG
   4.459 -                    char resstr[11] = {0,};
   4.460 -                    snprintf(resstr,10,"result=%d",cond_result);
   4.461 -                    #endif
   4.462 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted, condition=keyElectionWon", resstr)
   4.463 -                    if (cond_result < 0)
   4.464 -                        return cond_result;
   4.465 -                    if (cond_result) {
   4.466 +                    {
   4.467 +                        int cond_result = keyElectionWon(session, partner);
   4.468 +                        #ifndef NDEBUG
   4.469 +                        char resstr[11] = {0,};
   4.470 +                        snprintf(resstr,10,"result=%d",cond_result);
   4.471 +                        #endif
   4.472 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted, condition=keyElectionWon", resstr)
   4.473 +                        if (cond_result < 0)
   4.474 +                            return cond_result;
   4.475 +                        if (cond_result) {
   4.476                          DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=sendGroupKeys")
   4.477                          status = sendGroupKeys(session, state, partner, NULL);
   4.478                          if (status == PEP_OUT_OF_MEMORY)
   4.479 @@ -981,6 +1026,7 @@
   4.480                          session->sync_state_payload = NULL;
   4.481                          DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "target=Grouped")
   4.482                          return Grouped;
   4.483 +                        }
   4.484                      }
   4.485                      assert(session->sync_state_payload);
   4.486                      if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   4.487 @@ -1010,15 +1056,16 @@
   4.488                  {
   4.489                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=GroupKeys")
   4.490                      group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
   4.491 -                    cond_result = sameIdentities(session, partner, expected);
   4.492 -                    #ifndef NDEBUG
   4.493 -                    char resstr[11] = {0,};
   4.494 -                    snprintf(resstr,10,"result=%d",cond_result);
   4.495 -                    #endif
   4.496 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys, condition=sameIdentities", resstr)
   4.497 -                    if (cond_result < 0)
   4.498 -                        return cond_result;
   4.499 -                    if (cond_result) {
   4.500 +                    {
   4.501 +                        int cond_result = sameIdentities(session, partner, expected);
   4.502 +                        #ifndef NDEBUG
   4.503 +                        char resstr[11] = {0,};
   4.504 +                        snprintf(resstr,10,"result=%d",cond_result);
   4.505 +                        #endif
   4.506 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys, condition=sameIdentities", resstr)
   4.507 +                        if (cond_result < 0)
   4.508 +                            return cond_result;
   4.509 +                        if (cond_result) {
   4.510                          assert(session->sync_state_payload);
   4.511                          if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   4.512                          free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
   4.513 @@ -1033,6 +1080,7 @@
   4.514                              group_keys_extra_dup(groupkeys);
   4.515                          DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys", "target=WaitForAcceptGrouped")
   4.516                          return WaitForAcceptGrouped;
   4.517 +                        }
   4.518                      }
   4.519                      break;
   4.520                  }
   4.521 @@ -1073,15 +1121,16 @@
   4.522                  {
   4.523                      DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysGrouped", "event=GroupKeys")
   4.524                      group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
   4.525 -                    cond_result = sameIdentities(session, partner, expected);
   4.526 -                    #ifndef NDEBUG
   4.527 -                    char resstr[11] = {0,};
   4.528 -                    snprintf(resstr,10,"result=%d",cond_result);
   4.529 -                    #endif
   4.530 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys, condition=sameIdentities", resstr)
   4.531 -                    if (cond_result < 0)
   4.532 -                        return cond_result;
   4.533 -                    if (cond_result) {
   4.534 +                    {
   4.535 +                        int cond_result = sameIdentities(session, partner, expected);
   4.536 +                        #ifndef NDEBUG
   4.537 +                        char resstr[11] = {0,};
   4.538 +                        snprintf(resstr,10,"result=%d",cond_result);
   4.539 +                        #endif
   4.540 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys, condition=sameIdentities", resstr)
   4.541 +                        if (cond_result < 0)
   4.542 +                            return cond_result;
   4.543 +                        if (cond_result) {
   4.544                          DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "action=storeGroupKeys")
   4.545                          status = storeGroupKeys(session, state, partner, groupkeys);
   4.546                          if (status == PEP_OUT_OF_MEMORY)
   4.547 @@ -1094,6 +1143,12 @@
   4.548                              return (int) invalid_out_of_memory;
   4.549                          if (status != PEP_STATUS_OK)
   4.550                              return (int) invalid_action;
   4.551 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "action=renewUUID")
   4.552 +                        status = renewUUID(session, state, NULL, NULL);
   4.553 +                        if (status == PEP_OUT_OF_MEMORY)
   4.554 +                            return (int) invalid_out_of_memory;
   4.555 +                        if (status != PEP_STATUS_OK)
   4.556 +                            return (int) invalid_action;
   4.557                          DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "action=notifyAcceptedDeviceMoved")
   4.558                          status = notifyAcceptedDeviceMoved(session, state, partner, NULL);
   4.559                          if (status == PEP_OUT_OF_MEMORY)
   4.560 @@ -1107,6 +1162,7 @@
   4.561                          session->sync_state_payload = NULL;
   4.562                          DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "target=Grouped")
   4.563                          return Grouped;
   4.564 +                        }
   4.565                      }
   4.566                      break;
   4.567                  }
   4.568 @@ -1183,6 +1239,12 @@
   4.569                          return (int) invalid_out_of_memory;
   4.570                      if (status != PEP_STATUS_OK)
   4.571                          return (int) invalid_action;
   4.572 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=renewUUID")
   4.573 +                    status = renewUUID(session, state, NULL, NULL);
   4.574 +                    if (status == PEP_OUT_OF_MEMORY)
   4.575 +                        return (int) invalid_out_of_memory;
   4.576 +                    if (status != PEP_STATUS_OK)
   4.577 +                        return (int) invalid_action;
   4.578                      DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=notifyAcceptedDeviceMoved")
   4.579                      status = notifyAcceptedDeviceMoved(session, state, partner, NULL);
   4.580                      if (status == PEP_OUT_OF_MEMORY)
     5.1 --- a/sync/generated/sync_fsm.h	Mon Feb 20 22:36:07 2017 +0100
     5.2 +++ b/sync/generated/sync_fsm.h	Tue Feb 21 23:08:01 2017 +0100
     5.3 @@ -85,6 +85,7 @@
     5.4  PEP_STATUS acceptHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     5.5  PEP_STATUS makeGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     5.6  PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     5.7 +PEP_STATUS renewUUID(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     5.8  PEP_STATUS notifyAcceptedGroupCreated(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     5.9  PEP_STATUS notifyTimeout(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    5.10  PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     6.1 --- a/sync/skeletons/sync_actions.c	Mon Feb 20 22:36:07 2017 +0100
     6.2 +++ b/sync/skeletons/sync_actions.c	Tue Feb 21 23:08:01 2017 +0100
     6.3 @@ -193,6 +193,43 @@
     6.4  }
     6.5  
     6.6  
     6.7 +// renewUUID() - 
     6.8 +//
     6.9 +//  params:
    6.10 +//      session (in)        session handle
    6.11 +//      state (in)          state the state machine is in
    6.12 +//      partner (in)        (must be NULL)
    6.13 +//
    6.14 +//  returns:
    6.15 +//      PEP_STATUS_OK or any other value on error
    6.16 +
    6.17 +PEP_STATUS renewUUID(
    6.18 +        PEP_SESSION session,
    6.19 +        DeviceState_state state,
    6.20 +        Identity partner,
    6.21 +        void *extra
    6.22 +    )
    6.23 +{
    6.24 +    PEP_STATUS status = PEP_STATUS_OK;
    6.25 +
    6.26 +    assert(session);
    6.27 +    assert(!partner);
    6.28 +    if (!(session && !partner))
    6.29 +        return PEP_ILLEGAL_VALUE;
    6.30 +
    6.31 +    // working code
    6.32 +
    6.33 +    // free extra
    6.34 +    return status;
    6.35 +
    6.36 +enomem:
    6.37 +    status = PEP_OUT_OF_MEMORY;
    6.38 +error:
    6.39 +    // free extra
    6.40 +    return status;
    6.41 +}
    6.42 +
    6.43 +
    6.44  // notifyAcceptedGroupCreated() - 
    6.45  //
    6.46  //  params: