KeySync : added WaitForAccept(Sole|Grouped) states to deal with GroupKeys received before Handshake is accepted on device losing key election. KeySyncWaitForAccept
authorEdouard Tisserant <edouard@pep-project.org>
Mon, 20 Feb 2017 14:10:36 +0100
branchKeySyncWaitForAccept
changeset 1596f7c8b7401911
parent 1595 ddf2993d75fe
child 1597 cc039a6139cb
KeySync : added WaitForAccept(Sole|Grouped) states to deal with GroupKeys received before Handshake is accepted on device losing key election.
sync/devicegroup.fsm
sync/generated/sync_fsm.c
sync/generated/sync_fsm.h
     1.1 --- a/sync/devicegroup.fsm	Mon Feb 20 14:09:38 2017 +0100
     1.2 +++ b/sync/devicegroup.fsm	Mon Feb 20 14:10:36 2017 +0100
     1.3 @@ -95,11 +95,11 @@
     1.4                  go Sole;
     1.5              }
     1.6              on Cancel go Sole;
     1.7 -//            on GroupKeys(Identity partner, identity_list keys) {
     1.8 -//                if sameIdentities(partner, expected) {
     1.9 -//                    go WaitForAcceptSole(partner, keys);
    1.10 -//                }
    1.11 -//            }
    1.12 +            on GroupKeys(Identity partner, IdentityList keys) {
    1.13 +                if sameIdentities(partner, expected) {
    1.14 +                    go WaitForAcceptSole(partner, keys);
    1.15 +                }
    1.16 +            }
    1.17              on Timeout {
    1.18                  do notifyTimeout(expected);
    1.19                  do sendBeacon;
    1.20 @@ -108,7 +108,7 @@
    1.21          }
    1.22      
    1.23          state WaitForGroupKeysSole timeout=600 (Identity expected) {
    1.24 -            on GroupKeys(Identity partner, identity_list keys) {
    1.25 +            on GroupKeys(Identity partner, IdentityList keys) {
    1.26                  if sameIdentities(partner, expected) {
    1.27                      do storeGroupKeys(partner, keys);
    1.28                      do sendGroupUpdate;
    1.29 @@ -122,28 +122,28 @@
    1.30              }
    1.31          }
    1.32  
    1.33 -//        state WaitForAcceptSole timeout=600 (Identity expected, identity_list keys) {
    1.34 -//            on HandshakeRejected(Identity partner) {
    1.35 -//                do rejectHandshake(partner);
    1.36 -//                go Sole;
    1.37 -//            }
    1.38 -//            on HandshakeAccepted(Identity partner) {
    1.39 -//                if sameIdentities(partner, expected) {
    1.40 -//                    do acceptHandshake(partner); 
    1.41 -//                    do storeGroupKeys(partner, keys);
    1.42 -//                    do sendGroupUpdate;
    1.43 -//                    do notifyAcceptedDeviceAdded(partner);
    1.44 -//                    go Grouped;
    1.45 -//                }
    1.46 -//                go Sole;
    1.47 -//            }
    1.48 -//            on Cancel go Sole;
    1.49 -//            on Timeout {
    1.50 -//                do notifyTimeout(expected);
    1.51 -//                go Sole;
    1.52 -//            }
    1.53 -//        }
    1.54 -//
    1.55 +        state WaitForAcceptSole timeout=600 (Identity expected, IdentityList keys) {
    1.56 +            on HandshakeRejected(Identity partner) {
    1.57 +                do rejectHandshake(partner);
    1.58 +                go Sole;
    1.59 +            }
    1.60 +            on HandshakeAccepted(Identity partner) {
    1.61 +                if sameIdentities(partner, expected) {
    1.62 +                    do acceptHandshake(partner); 
    1.63 +                    do storeGroupKeys(partner, keys);
    1.64 +                    do sendGroupUpdate;
    1.65 +                    do notifyAcceptedDeviceAdded(partner);
    1.66 +                    go Grouped;
    1.67 +                }
    1.68 +                go Sole;
    1.69 +            }
    1.70 +            on Cancel go Sole;
    1.71 +            on Timeout {
    1.72 +                do notifyTimeout(expected);
    1.73 +                go Sole;
    1.74 +            }
    1.75 +        }
    1.76 +
    1.77          state Grouped end=1 {
    1.78              on KeyGen
    1.79                  do sendGroupUpdate;
    1.80 @@ -161,7 +161,7 @@
    1.81                  do sendHandshakeRequest(partner);
    1.82                  go HandshakingGrouped(partner);
    1.83              }
    1.84 -            on GroupUpdate(Identity partner, identity_list keys)
    1.85 +            on GroupUpdate(Identity partner, IdentityList keys)
    1.86                  do storeGroupUpdate(partner, keys);
    1.87          }
    1.88  
    1.89 @@ -186,7 +186,7 @@
    1.90                  }
    1.91                  go HandshakingGrouped(partner);
    1.92              }
    1.93 -            on GroupUpdate(Identity partner, identity_list keys)
    1.94 +            on GroupUpdate(Identity partner, IdentityList keys)
    1.95                  do storeGroupUpdate(partner, keys);
    1.96              on Timeout go Grouped;
    1.97          }
    1.98 @@ -214,11 +214,11 @@
    1.99                  go WaitForGroupKeysGrouped(partner);
   1.100              }
   1.101              on Cancel go Grouped;
   1.102 -//            on GroupKeys(Identity partner, identity_list keys) {
   1.103 -//                if sameIdentities(partner, expected) {
   1.104 -//                    go WaitForAcceptGrouped(partner, keys);
   1.105 -//                }
   1.106 -//            }
   1.107 +            on GroupKeys(Identity partner, IdentityList keys) {
   1.108 +                if sameIdentities(partner, expected) {
   1.109 +                    go WaitForAcceptGrouped(partner, keys);
   1.110 +                }
   1.111 +            }
   1.112              on Timeout {
   1.113                  do notifyTimeout(expected);
   1.114                  go Grouped;
   1.115 @@ -226,7 +226,7 @@
   1.116          }
   1.117  
   1.118          state WaitForGroupKeysGrouped timeout=600 (Identity expected) {
   1.119 -            on GroupKeys(Identity partner, identity_list keys) {
   1.120 +            on GroupKeys(Identity partner, IdentityList keys) {
   1.121                  if sameIdentities(partner, expected) {
   1.122                      do storeGroupKeys(partner, keys);
   1.123                      do sendGroupUpdate;
   1.124 @@ -240,25 +240,25 @@
   1.125              }
   1.126          }
   1.127  
   1.128 -//        state WaitForAcceptGrouped timeout=600 (Identity expected, identity_list keys) {
   1.129 -//            on HandshakeRejected(Identity partner) {
   1.130 -//                do rejectHandshake(partner);
   1.131 -//                go Grouped;
   1.132 -//            }
   1.133 -//            on HandshakeAccepted(Identity partner) {
   1.134 -//                do acceptHandshake(partner); 
   1.135 -//                do storeGroupKeys(partner, keys);
   1.136 -//                do sendGroupUpdate;
   1.137 -//                do notifyAcceptedDeviceMoved(partner);
   1.138 -//                go Grouped;
   1.139 -//            }
   1.140 -//            on Cancel go Grouped;
   1.141 -//            on Timeout {
   1.142 -//                do notifyTimeout(expected);
   1.143 -//                go Grouped;
   1.144 -//            }
   1.145 -//        }
   1.146 -//
   1.147 +        state WaitForAcceptGrouped timeout=600 (Identity expected, IdentityList keys) {
   1.148 +            on HandshakeRejected(Identity partner) {
   1.149 +                do rejectHandshake(partner);
   1.150 +                go Grouped;
   1.151 +            }
   1.152 +            on HandshakeAccepted(Identity partner) {
   1.153 +                do acceptHandshake(partner); 
   1.154 +                do storeGroupKeys(partner, keys);
   1.155 +                do sendGroupUpdate;
   1.156 +                do notifyAcceptedDeviceMoved(partner);
   1.157 +                go Grouped;
   1.158 +            }
   1.159 +            on Cancel go Grouped;
   1.160 +            on Timeout {
   1.161 +                do notifyTimeout(expected);
   1.162 +                go Grouped;
   1.163 +            }
   1.164 +        }
   1.165 +
   1.166          tag Init 1;
   1.167          tag Beacon 2;
   1.168          tag HandshakeRequest 3;
     2.1 --- a/sync/generated/sync_fsm.c	Mon Feb 20 14:09:38 2017 +0100
     2.2 +++ b/sync/generated/sync_fsm.c	Mon Feb 20 14:10:36 2017 +0100
     2.3 @@ -3,30 +3,40 @@
     2.4  
     2.5  // local definitions for DeviceState's state machine 
     2.6  
     2.7 -        typedef struct _SoleBeaconed_state_payload {
     2.8 -            Identity expected;
     2.9 -        } SoleBeaconed_state_payload_t;
    2.10 -        
    2.11 -        typedef struct _HandshakingSole_state_payload {
    2.12 -            Identity expected;
    2.13 -        } HandshakingSole_state_payload_t;
    2.14 -        
    2.15 -        typedef struct _WaitForGroupKeysSole_state_payload {
    2.16 -            Identity expected;
    2.17 -        } WaitForGroupKeysSole_state_payload_t;
    2.18 -        
    2.19 -        typedef struct _GroupedBeaconed_state_payload {
    2.20 -            Identity expected;
    2.21 -        } GroupedBeaconed_state_payload_t;
    2.22 -        
    2.23 -        typedef struct _HandshakingGrouped_state_payload {
    2.24 -            Identity expected;
    2.25 -        } HandshakingGrouped_state_payload_t;
    2.26 -        
    2.27 -        typedef struct _WaitForGroupKeysGrouped_state_payload {
    2.28 -            Identity expected;
    2.29 -        } WaitForGroupKeysGrouped_state_payload_t;
    2.30 -        
    2.31 +typedef struct _SoleBeaconed_state_payload {
    2.32 +    Identity expected;
    2.33 +} SoleBeaconed_state_payload_t;
    2.34 +
    2.35 +typedef struct _HandshakingSole_state_payload {
    2.36 +    Identity expected;
    2.37 +} HandshakingSole_state_payload_t;
    2.38 +
    2.39 +typedef struct _WaitForGroupKeysSole_state_payload {
    2.40 +    Identity expected;
    2.41 +} WaitForGroupKeysSole_state_payload_t;
    2.42 +
    2.43 +typedef struct _WaitForAcceptSole_state_payload {
    2.44 +    Identity expected;
    2.45 +    identity_list* keys;
    2.46 +} WaitForAcceptSole_state_payload_t;
    2.47 +
    2.48 +typedef struct _GroupedBeaconed_state_payload {
    2.49 +    Identity expected;
    2.50 +} GroupedBeaconed_state_payload_t;
    2.51 +
    2.52 +typedef struct _HandshakingGrouped_state_payload {
    2.53 +    Identity expected;
    2.54 +} HandshakingGrouped_state_payload_t;
    2.55 +
    2.56 +typedef struct _WaitForGroupKeysGrouped_state_payload {
    2.57 +    Identity expected;
    2.58 +} WaitForGroupKeysGrouped_state_payload_t;
    2.59 +
    2.60 +typedef struct _WaitForAcceptGrouped_state_payload {
    2.61 +    Identity expected;
    2.62 +    identity_list* keys;
    2.63 +} WaitForAcceptGrouped_state_payload_t;
    2.64 +
    2.65  
    2.66  // state machine for DeviceState
    2.67  
    2.68 @@ -396,6 +406,36 @@
    2.69                      DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=Cancel", "target=Sole")
    2.70                      return Sole;
    2.71                  }
    2.72 +                case GroupKeys:
    2.73 +                {
    2.74 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=GroupKeys")
    2.75 +                    identity_list* keys = (identity_list*)extra;
    2.76 +                    cond_result = sameIdentities(session, partner, expected);
    2.77 +                    #ifndef NDEBUG
    2.78 +                    char resstr[11] = {0,};
    2.79 +                    snprintf(resstr,10,"result=%d",cond_result);
    2.80 +                    #endif
    2.81 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys, condition=sameIdentities", resstr)
    2.82 +                    if (cond_result < 0)
    2.83 +                        return cond_result;
    2.84 +                    if (cond_result) {
    2.85 +                        assert(session->sync_state_payload);
    2.86 +                        if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
    2.87 +                        free_identity(((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected);
    2.88 +                        free(session->sync_state_payload);
    2.89 +                        session->sync_state_payload = NULL;
    2.90 +                        session->sync_state_payload = malloc(sizeof(WaitForAcceptSole_state_payload_t));
    2.91 +                        assert(session->sync_state_payload);
    2.92 +                        if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
    2.93 +                        ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected =
    2.94 +                            identity_dup(partner);
    2.95 +                        ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->keys =
    2.96 +                            identity_list_dup(keys);
    2.97 +                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys", "target=WaitForAcceptSole")
    2.98 +                        return WaitForAcceptSole;
    2.99 +                    }
   2.100 +                    break;
   2.101 +                }
   2.102                  case Timeout:
   2.103                  {
   2.104                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Timeout")
   2.105 @@ -438,6 +478,7 @@
   2.106                  case GroupKeys:
   2.107                  {
   2.108                      DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=GroupKeys")
   2.109 +                    identity_list* keys = (identity_list*)extra;
   2.110                      cond_result = sameIdentities(session, partner, expected);
   2.111                      #ifndef NDEBUG
   2.112                      char resstr[11] = {0,};
   2.113 @@ -448,7 +489,7 @@
   2.114                          return cond_result;
   2.115                      if (cond_result) {
   2.116                          DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=storeGroupKeys")
   2.117 -                        status = storeGroupKeys(session, state, partner, extra /*keys*/);
   2.118 +                        status = storeGroupKeys(session, state, partner, keys);
   2.119                          if (status == PEP_OUT_OF_MEMORY)
   2.120                              return (int) invalid_out_of_memory;
   2.121                          if (status != PEP_STATUS_OK)
   2.122 @@ -497,6 +538,125 @@
   2.123              }
   2.124              break;
   2.125          }
   2.126 +        case WaitForAcceptSole:
   2.127 +        {
   2.128 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=WaitForAcceptSole")
   2.129 +            assert(session->sync_state_payload);
   2.130 +            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.131 +            Identity expected = ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected;
   2.132 +            identity_list* keys = ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->keys;
   2.133 +            *timeout = 600;
   2.134 +            switch (event) {
   2.135 +                case Init: 
   2.136 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=Init") 
   2.137 +                    break;
   2.138 +                case HandshakeRejected:
   2.139 +                {
   2.140 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=HandshakeRejected")
   2.141 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeRejected", "action=rejectHandshake")
   2.142 +                    status = rejectHandshake(session, state, partner, NULL);
   2.143 +                    if (status == PEP_OUT_OF_MEMORY)
   2.144 +                        return (int) invalid_out_of_memory;
   2.145 +                    if (status != PEP_STATUS_OK)
   2.146 +                        return (int) invalid_action;
   2.147 +                    assert(session->sync_state_payload);
   2.148 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.149 +                    free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
   2.150 +                    free_identity_list(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->keys);
   2.151 +                    free(session->sync_state_payload);
   2.152 +                    session->sync_state_payload = NULL;
   2.153 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeRejected", "target=Sole")
   2.154 +                    return Sole;
   2.155 +                }
   2.156 +                case HandshakeAccepted:
   2.157 +                {
   2.158 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=HandshakeAccepted")
   2.159 +                    cond_result = sameIdentities(session, partner, expected);
   2.160 +                    #ifndef NDEBUG
   2.161 +                    char resstr[11] = {0,};
   2.162 +                    snprintf(resstr,10,"result=%d",cond_result);
   2.163 +                    #endif
   2.164 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted, condition=sameIdentities", resstr)
   2.165 +                    if (cond_result < 0)
   2.166 +                        return cond_result;
   2.167 +                    if (cond_result) {
   2.168 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=acceptHandshake")
   2.169 +                        status = acceptHandshake(session, state, partner, NULL);
   2.170 +                        if (status == PEP_OUT_OF_MEMORY)
   2.171 +                            return (int) invalid_out_of_memory;
   2.172 +                        if (status != PEP_STATUS_OK)
   2.173 +                            return (int) invalid_action;
   2.174 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=storeGroupKeys")
   2.175 +                        status = storeGroupKeys(session, state, partner, keys);
   2.176 +                        if (status == PEP_OUT_OF_MEMORY)
   2.177 +                            return (int) invalid_out_of_memory;
   2.178 +                        if (status != PEP_STATUS_OK)
   2.179 +                            return (int) invalid_action;
   2.180 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=sendGroupUpdate")
   2.181 +                        status = sendGroupUpdate(session, state, NULL, NULL);
   2.182 +                        if (status == PEP_OUT_OF_MEMORY)
   2.183 +                            return (int) invalid_out_of_memory;
   2.184 +                        if (status != PEP_STATUS_OK)
   2.185 +                            return (int) invalid_action;
   2.186 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=notifyAcceptedDeviceAdded")
   2.187 +                        status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
   2.188 +                        if (status == PEP_OUT_OF_MEMORY)
   2.189 +                            return (int) invalid_out_of_memory;
   2.190 +                        if (status != PEP_STATUS_OK)
   2.191 +                            return (int) invalid_action;
   2.192 +                        assert(session->sync_state_payload);
   2.193 +                        if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.194 +                        free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
   2.195 +                        free_identity_list(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->keys);
   2.196 +                        free(session->sync_state_payload);
   2.197 +                        session->sync_state_payload = NULL;
   2.198 +                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "target=Grouped")
   2.199 +                        return Grouped;
   2.200 +                    }
   2.201 +                    assert(session->sync_state_payload);
   2.202 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.203 +                    free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
   2.204 +                    free_identity_list(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->keys);
   2.205 +                    free(session->sync_state_payload);
   2.206 +                    session->sync_state_payload = NULL;
   2.207 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "target=Sole")
   2.208 +                    return Sole;
   2.209 +                }
   2.210 +                case Cancel:
   2.211 +                {
   2.212 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=Cancel")
   2.213 +                    assert(session->sync_state_payload);
   2.214 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.215 +                    free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
   2.216 +                    free_identity_list(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->keys);
   2.217 +                    free(session->sync_state_payload);
   2.218 +                    session->sync_state_payload = NULL;
   2.219 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=Cancel", "target=Sole")
   2.220 +                    return Sole;
   2.221 +                }
   2.222 +                case Timeout:
   2.223 +                {
   2.224 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=Timeout")
   2.225 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=Timeout", "action=notifyTimeout")
   2.226 +                    status = notifyTimeout(session, state, expected, NULL);
   2.227 +                    if (status == PEP_OUT_OF_MEMORY)
   2.228 +                        return (int) invalid_out_of_memory;
   2.229 +                    if (status != PEP_STATUS_OK)
   2.230 +                        return (int) invalid_action;
   2.231 +                    assert(session->sync_state_payload);
   2.232 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.233 +                    free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
   2.234 +                    free_identity_list(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->keys);
   2.235 +                    free(session->sync_state_payload);
   2.236 +                    session->sync_state_payload = NULL;
   2.237 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=Timeout", "target=Sole")
   2.238 +                    return Sole;
   2.239 +                }
   2.240 +                default:
   2.241 +                    return (DeviceState_state) invalid_event;
   2.242 +            }
   2.243 +            break;
   2.244 +        }
   2.245          case Grouped:
   2.246          {
   2.247              DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=Grouped")
   2.248 @@ -581,8 +741,9 @@
   2.249                  case GroupUpdate:
   2.250                  {
   2.251                      DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=GroupUpdate")
   2.252 +                    identity_list* keys = (identity_list*)extra;
   2.253                      DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=GroupUpdate", "action=storeGroupUpdate")
   2.254 -                    status = storeGroupUpdate(session, state, partner, extra /*keys*/);
   2.255 +                    status = storeGroupUpdate(session, state, partner, keys);
   2.256                      if (status == PEP_OUT_OF_MEMORY)
   2.257                          return (int) invalid_out_of_memory;
   2.258                      if (status != PEP_STATUS_OK)
   2.259 @@ -703,8 +864,9 @@
   2.260                  case GroupUpdate:
   2.261                  {
   2.262                      DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=GroupUpdate")
   2.263 +                    identity_list* keys = (identity_list*)extra;
   2.264                      DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=GroupUpdate", "action=storeGroupUpdate")
   2.265 -                    status = storeGroupUpdate(session, state, partner, extra /*keys*/);
   2.266 +                    status = storeGroupUpdate(session, state, partner, keys);
   2.267                      if (status == PEP_OUT_OF_MEMORY)
   2.268                          return (int) invalid_out_of_memory;
   2.269                      if (status != PEP_STATUS_OK)
   2.270 @@ -843,6 +1005,36 @@
   2.271                      DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=Cancel", "target=Grouped")
   2.272                      return Grouped;
   2.273                  }
   2.274 +                case GroupKeys:
   2.275 +                {
   2.276 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=GroupKeys")
   2.277 +                    identity_list* keys = (identity_list*)extra;
   2.278 +                    cond_result = sameIdentities(session, partner, expected);
   2.279 +                    #ifndef NDEBUG
   2.280 +                    char resstr[11] = {0,};
   2.281 +                    snprintf(resstr,10,"result=%d",cond_result);
   2.282 +                    #endif
   2.283 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys, condition=sameIdentities", resstr)
   2.284 +                    if (cond_result < 0)
   2.285 +                        return cond_result;
   2.286 +                    if (cond_result) {
   2.287 +                        assert(session->sync_state_payload);
   2.288 +                        if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.289 +                        free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
   2.290 +                        free(session->sync_state_payload);
   2.291 +                        session->sync_state_payload = NULL;
   2.292 +                        session->sync_state_payload = malloc(sizeof(WaitForAcceptGrouped_state_payload_t));
   2.293 +                        assert(session->sync_state_payload);
   2.294 +                        if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
   2.295 +                        ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected =
   2.296 +                            identity_dup(partner);
   2.297 +                        ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->keys =
   2.298 +                            identity_list_dup(keys);
   2.299 +                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys", "target=WaitForAcceptGrouped")
   2.300 +                        return WaitForAcceptGrouped;
   2.301 +                    }
   2.302 +                    break;
   2.303 +                }
   2.304                  case Timeout:
   2.305                  {
   2.306                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Timeout")
   2.307 @@ -879,6 +1071,7 @@
   2.308                  case GroupKeys:
   2.309                  {
   2.310                      DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysGrouped", "event=GroupKeys")
   2.311 +                    identity_list* keys = (identity_list*)extra;
   2.312                      cond_result = sameIdentities(session, partner, expected);
   2.313                      #ifndef NDEBUG
   2.314                      char resstr[11] = {0,};
   2.315 @@ -889,7 +1082,7 @@
   2.316                          return cond_result;
   2.317                      if (cond_result) {
   2.318                          DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "action=storeGroupKeys")
   2.319 -                        status = storeGroupKeys(session, state, partner, extra /*keys*/);
   2.320 +                        status = storeGroupKeys(session, state, partner, keys);
   2.321                          if (status == PEP_OUT_OF_MEMORY)
   2.322                              return (int) invalid_out_of_memory;
   2.323                          if (status != PEP_STATUS_OK)
   2.324 @@ -938,6 +1131,107 @@
   2.325              }
   2.326              break;
   2.327          }
   2.328 +        case WaitForAcceptGrouped:
   2.329 +        {
   2.330 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=WaitForAcceptGrouped")
   2.331 +            assert(session->sync_state_payload);
   2.332 +            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.333 +            Identity expected = ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected;
   2.334 +            identity_list* keys = ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->keys;
   2.335 +            *timeout = 600;
   2.336 +            switch (event) {
   2.337 +                case Init: 
   2.338 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=Init") 
   2.339 +                    break;
   2.340 +                case HandshakeRejected:
   2.341 +                {
   2.342 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=HandshakeRejected")
   2.343 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeRejected", "action=rejectHandshake")
   2.344 +                    status = rejectHandshake(session, state, partner, NULL);
   2.345 +                    if (status == PEP_OUT_OF_MEMORY)
   2.346 +                        return (int) invalid_out_of_memory;
   2.347 +                    if (status != PEP_STATUS_OK)
   2.348 +                        return (int) invalid_action;
   2.349 +                    assert(session->sync_state_payload);
   2.350 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.351 +                    free_identity(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected);
   2.352 +                    free_identity_list(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->keys);
   2.353 +                    free(session->sync_state_payload);
   2.354 +                    session->sync_state_payload = NULL;
   2.355 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeRejected", "target=Grouped")
   2.356 +                    return Grouped;
   2.357 +                }
   2.358 +                case HandshakeAccepted:
   2.359 +                {
   2.360 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=HandshakeAccepted")
   2.361 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=acceptHandshake")
   2.362 +                    status = acceptHandshake(session, state, partner, NULL);
   2.363 +                    if (status == PEP_OUT_OF_MEMORY)
   2.364 +                        return (int) invalid_out_of_memory;
   2.365 +                    if (status != PEP_STATUS_OK)
   2.366 +                        return (int) invalid_action;
   2.367 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=storeGroupKeys")
   2.368 +                    status = storeGroupKeys(session, state, partner, keys);
   2.369 +                    if (status == PEP_OUT_OF_MEMORY)
   2.370 +                        return (int) invalid_out_of_memory;
   2.371 +                    if (status != PEP_STATUS_OK)
   2.372 +                        return (int) invalid_action;
   2.373 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=sendGroupUpdate")
   2.374 +                    status = sendGroupUpdate(session, state, NULL, NULL);
   2.375 +                    if (status == PEP_OUT_OF_MEMORY)
   2.376 +                        return (int) invalid_out_of_memory;
   2.377 +                    if (status != PEP_STATUS_OK)
   2.378 +                        return (int) invalid_action;
   2.379 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=notifyAcceptedDeviceMoved")
   2.380 +                    status = notifyAcceptedDeviceMoved(session, state, partner, NULL);
   2.381 +                    if (status == PEP_OUT_OF_MEMORY)
   2.382 +                        return (int) invalid_out_of_memory;
   2.383 +                    if (status != PEP_STATUS_OK)
   2.384 +                        return (int) invalid_action;
   2.385 +                    assert(session->sync_state_payload);
   2.386 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.387 +                    free_identity(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected);
   2.388 +                    free_identity_list(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->keys);
   2.389 +                    free(session->sync_state_payload);
   2.390 +                    session->sync_state_payload = NULL;
   2.391 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "target=Grouped")
   2.392 +                    return Grouped;
   2.393 +                }
   2.394 +                case Cancel:
   2.395 +                {
   2.396 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=Cancel")
   2.397 +                    assert(session->sync_state_payload);
   2.398 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.399 +                    free_identity(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected);
   2.400 +                    free_identity_list(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->keys);
   2.401 +                    free(session->sync_state_payload);
   2.402 +                    session->sync_state_payload = NULL;
   2.403 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptGrouped, event=Cancel", "target=Grouped")
   2.404 +                    return Grouped;
   2.405 +                }
   2.406 +                case Timeout:
   2.407 +                {
   2.408 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=Timeout")
   2.409 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=Timeout", "action=notifyTimeout")
   2.410 +                    status = notifyTimeout(session, state, expected, NULL);
   2.411 +                    if (status == PEP_OUT_OF_MEMORY)
   2.412 +                        return (int) invalid_out_of_memory;
   2.413 +                    if (status != PEP_STATUS_OK)
   2.414 +                        return (int) invalid_action;
   2.415 +                    assert(session->sync_state_payload);
   2.416 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   2.417 +                    free_identity(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected);
   2.418 +                    free_identity_list(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->keys);
   2.419 +                    free(session->sync_state_payload);
   2.420 +                    session->sync_state_payload = NULL;
   2.421 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptGrouped, event=Timeout", "target=Grouped")
   2.422 +                    return Grouped;
   2.423 +                }
   2.424 +                default:
   2.425 +                    return (DeviceState_state) invalid_event;
   2.426 +            }
   2.427 +            break;
   2.428 +        }
   2.429          default:
   2.430              return (DeviceState_state) invalid_state;
   2.431      }
     3.1 --- a/sync/generated/sync_fsm.h	Mon Feb 20 14:09:38 2017 +0100
     3.2 +++ b/sync/generated/sync_fsm.h	Mon Feb 20 14:10:36 2017 +0100
     3.3 @@ -49,10 +49,12 @@
     3.4      SoleBeaconed, 
     3.5      HandshakingSole, 
     3.6      WaitForGroupKeysSole, 
     3.7 +    WaitForAcceptSole, 
     3.8      Grouped, 
     3.9      GroupedBeaconed, 
    3.10      HandshakingGrouped, 
    3.11 -    WaitForGroupKeysGrouped
    3.12 +    WaitForGroupKeysGrouped, 
    3.13 +    WaitForAcceptGrouped
    3.14  } DeviceState_state;
    3.15  
    3.16  // events