renamed reject() to rejectHandshake(). Added acceptHandshake. Toke away from sync'actions ownership of partner's identity. keysync
authorEdouard Tisserant <edouard@pep-project.org>
Wed, 14 Sep 2016 17:20:02 +0200
branchkeysync
changeset 1162f8db5c47b7f3
parent 1161 9a1f9ec6561a
child 1163 5d54f358c636
renamed reject() to rejectHandshake(). Added acceptHandshake. Toke away from sync'actions ownership of partner's identity.
src/sync_actions.c
src/sync_driver.c
src/sync_fsm.c
src/sync_send_actions.c
sync/gen_statemachine.ysl2
     1.1 --- a/src/sync_actions.c	Wed Sep 14 01:54:05 2016 +0200
     1.2 +++ b/src/sync_actions.c	Wed Sep 14 17:20:02 2016 +0200
     1.3 @@ -127,12 +127,20 @@
     1.4      if (!session->showHandshake)
     1.5          return PEP_SYNC_NO_TRUSTWORDS_CALLBACK;
     1.6  
     1.7 +    // showHandshake take ownership of given identities
     1.8      pEp_identity *me = NULL;
     1.9      status = get_identity(session, partner->address, PEP_OWN_USERID, &me);
    1.10      if (status != PEP_STATUS_OK)
    1.11          goto error;
    1.12      
    1.13 -    status = session->showHandshake(session->sync_obj, me, partner);
    1.14 +    pEp_identity *_partner = NULL;
    1.15 +    _partner = identity_dup(partner);
    1.16 +    if (_partner == NULL){
    1.17 +        status = PEP_OUT_OF_MEMORY;
    1.18 +        goto error;
    1.19 +    }
    1.20 +
    1.21 +    status = session->showHandshake(session->sync_obj, me, _partner);
    1.22      if (status != PEP_STATUS_OK)
    1.23          goto error;
    1.24  
    1.25 @@ -140,7 +148,6 @@
    1.26  
    1.27  error:
    1.28      free_identity(me);
    1.29 -    free_identity(partner);
    1.30      return status;
    1.31  }
    1.32  
    1.33 @@ -172,7 +179,6 @@
    1.34  
    1.35      status = trust_personal_key(session, partner);
    1.36  
    1.37 -    free_identity(partner);
    1.38      return status;
    1.39  }
    1.40  
    1.41 @@ -205,7 +211,6 @@
    1.42      status = set_identity_flags(session, partner,
    1.43              partner->flags | PEP_idf_not_for_sync);
    1.44  
    1.45 -    free_identity(partner);
    1.46      return status;
    1.47  }
    1.48  
    1.49 @@ -249,13 +254,11 @@
    1.50              break;
    1.51      }
    1.52  
    1.53 -    free_identity(partner);
    1.54      free_identity_list(group_keys);
    1.55      return status;
    1.56  
    1.57  enomem:
    1.58      status = PEP_OUT_OF_MEMORY;
    1.59 -    free_identity(partner);
    1.60      free_identity_list(group_keys);
    1.61      return status;
    1.62  }
     2.1 --- a/src/sync_driver.c	Wed Sep 14 01:54:05 2016 +0200
     2.2 +++ b/src/sync_driver.c	Wed Sep 14 17:20:02 2016 +0200
     2.3 @@ -17,10 +17,8 @@
     2.4  
     2.5      while(true)
     2.6      {
     2.7 -        Identity _partner = partner ? identity_dup(partner) : NULL;
     2.8 -
     2.9          DeviceState_state new_state = fsm_DeviceState(session,
    2.10 -            session->sync_state, event, _partner, extra);
    2.11 +            session->sync_state, event, partner, extra);
    2.12  
    2.13          if (new_state == DeviceState_state_invalid_out_of_memory)
    2.14              return PEP_OUT_OF_MEMORY;
     3.1 --- a/src/sync_fsm.c	Wed Sep 14 01:54:05 2016 +0200
     3.2 +++ b/src/sync_fsm.c	Wed Sep 14 17:20:02 2016 +0200
     3.3 @@ -75,17 +75,27 @@
     3.4                          return (int) invalid_action;
     3.5                      break;
     3.6                  case HandshakeRejected:
     3.7 -                    status = reject(session, state, partner, NULL);
     3.8 +                    status = rejectHandshake(session, state, partner, NULL);
     3.9                      if (status == PEP_OUT_OF_MEMORY)
    3.10                          return (int) invalid_out_of_memory;
    3.11                      if (status != PEP_STATUS_OK)
    3.12                          return (int) invalid_action;
    3.13                      return Sole;
    3.14                  case HandshakeAccepted:
    3.15 +                    status = acceptHandshake(session, state, partner, NULL);
    3.16 +                    if (status == PEP_OUT_OF_MEMORY)
    3.17 +                        return (int) invalid_out_of_memory;
    3.18 +                    if (status != PEP_STATUS_OK)
    3.19 +                        return (int) invalid_action;
    3.20                      cond_result = keyElectionWon(session, partner);
    3.21                      if (cond_result < 0)
    3.22                          return cond_result;
    3.23                      if (cond_result) {
    3.24 +                        status = sendGroupKeys(session, state, partner, NULL);
    3.25 +                        if (status == PEP_OUT_OF_MEMORY)
    3.26 +                            return (int) invalid_out_of_memory;
    3.27 +                        if (status != PEP_STATUS_OK)
    3.28 +                            return (int) invalid_action;
    3.29                          return Grouped;
    3.30                      }
    3.31                      return WaitForGroupKeys;
    3.32 @@ -107,7 +117,7 @@
    3.33                  case Cancel:
    3.34                      return Sole;
    3.35                  case Reject:
    3.36 -                    status = reject(session, state, partner, NULL);
    3.37 +                    status = rejectHandshake(session, state, partner, NULL);
    3.38                      if (status == PEP_OUT_OF_MEMORY)
    3.39                          return (int) invalid_out_of_memory;
    3.40                      if (status != PEP_STATUS_OK)
    3.41 @@ -141,16 +151,26 @@
    3.42                          return (int) invalid_action;
    3.43                      break;
    3.44                  case HandshakeRejected:
    3.45 -                    status = reject(session, state, partner, NULL);
    3.46 +                    status = rejectHandshake(session, state, partner, NULL);
    3.47                      if (status == PEP_OUT_OF_MEMORY)
    3.48                          return (int) invalid_out_of_memory;
    3.49                      if (status != PEP_STATUS_OK)
    3.50                          return (int) invalid_action;
    3.51                      break;
    3.52 -                case Hand:
    3.53 +                case HandshakeAccepted:
    3.54 +                    status = acceptHandshake(session, state, partner, NULL);
    3.55 +                    if (status == PEP_OUT_OF_MEMORY)
    3.56 +                        return (int) invalid_out_of_memory;
    3.57 +                    if (status != PEP_STATUS_OK)
    3.58 +                        return (int) invalid_action;
    3.59 +                    status = sendGroupKeys(session, state, partner, NULL);
    3.60 +                    if (status == PEP_OUT_OF_MEMORY)
    3.61 +                        return (int) invalid_out_of_memory;
    3.62 +                    if (status != PEP_STATUS_OK)
    3.63 +                        return (int) invalid_action;
    3.64                      break;
    3.65                  case Reject:
    3.66 -                    status = reject(session, state, NULL, NULL);
    3.67 +                    status = rejectHandshake(session, state, NULL, NULL);
    3.68                      if (status == PEP_OUT_OF_MEMORY)
    3.69                          return (int) invalid_out_of_memory;
    3.70                      if (status != PEP_STATUS_OK)
     4.1 --- a/src/sync_send_actions.c	Wed Sep 14 01:54:05 2016 +0200
     4.2 +++ b/src/sync_send_actions.c	Wed Sep 14 17:20:02 2016 +0200
     4.3 @@ -19,7 +19,7 @@
     4.4  //  params:
     4.5  //      session (in)        session handle
     4.6  //      state (in)          state the state machine is in
     4.7 -//      partner (in)        (must be NULL)
     4.8 +//      partner (in)        partner to communicate with
     4.9  //
    4.10  //  returns:
    4.11  //      PEP_STATUS_OK or any other value on error
    4.12 @@ -47,13 +47,11 @@
    4.13          goto error;
    4.14  
    4.15      free_DeviceGroup_Protocol_msg(msg);
    4.16 -    free_identity(partner);
    4.17      return PEP_STATUS_OK;
    4.18  
    4.19  enomem:
    4.20      status = PEP_OUT_OF_MEMORY;
    4.21  error:
    4.22 -    free_identity(partner);
    4.23      free_DeviceGroup_Protocol_msg(msg);
    4.24      return status;
    4.25  }
    4.26 @@ -92,13 +90,11 @@
    4.27          goto error;
    4.28  
    4.29      free_DeviceGroup_Protocol_msg(msg);
    4.30 -    free_identity(partner);
    4.31      return PEP_STATUS_OK;
    4.32  
    4.33  enomem:
    4.34      status = PEP_OUT_OF_MEMORY;
    4.35  error:
    4.36 -    free_identity(partner);
    4.37      free_DeviceGroup_Protocol_msg(msg);
    4.38      return status;
    4.39  }
    4.40 @@ -145,13 +141,11 @@
    4.41  
    4.42      free_identity_list(kl);
    4.43      free_DeviceGroup_Protocol_msg(msg);
    4.44 -    free_identity(partner);
    4.45      return PEP_STATUS_OK;
    4.46  
    4.47  enomem:
    4.48      status = PEP_OUT_OF_MEMORY;
    4.49  error:
    4.50 -    free_identity(partner);
    4.51      free_DeviceGroup_Protocol_msg(msg);
    4.52      free_identity_list(kl);
    4.53      return status;
     5.1 --- a/sync/gen_statemachine.ysl2	Wed Sep 14 01:54:05 2016 +0200
     5.2 +++ b/sync/gen_statemachine.ysl2	Wed Sep 14 17:20:02 2016 +0200
     5.3 @@ -141,10 +141,8 @@
     5.4  
     5.5              while(true)
     5.6              {
     5.7 -                Identity _partner = partner ? identity_dup(partner) : NULL;
     5.8 -
     5.9                  «@name»_state new_state = fsm_«@name»(session,
    5.10 -                    session->«@filename»_state, event, _partner, extra);
    5.11 +                    session->«@filename»_state, event, partner, extra);
    5.12  
    5.13                  if (new_state == «@name»_state_invalid_out_of_memory)
    5.14                      return PEP_OUT_OF_MEMORY;