update logic sync
authorVolker Birk <vb@pep-project.org>
Wed, 29 May 2019 23:17:19 +0200
branchsync
changeset 3779c6898c703a27
parent 3778 83e1e26d5cf0
child 3780 e4d673d3038e
update logic
sync/cond_act_sync.yml2
sync/gen_message_func.ysl2
sync/gen_statemachine.ysl2
sync/sync.fsm
     1.1 --- a/sync/cond_act_sync.yml2	Wed May 29 21:00:09 2019 +0200
     1.2 +++ b/sync/cond_act_sync.yml2	Wed May 29 23:17:19 2019 +0200
     1.3 @@ -29,14 +29,6 @@
     1.4  condition partnerIsGrouped
     1.5  |> *result = session->sync_state.keysync.is_group;
     1.6  
     1.7 -condition challengeAccepted
     1.8 -||
     1.9 -    TID_t *t1 = &session->sync_state.keysync.challenge;
    1.10 -    TID_t *t2 = &session->sync_state.own.challenge;
    1.11 -
    1.12 -    *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    1.13 -||
    1.14 -
    1.15  condition sameChallenge
    1.16  ||
    1.17      TID_t *t1 = &session->sync_state.keysync.challenge;
    1.18 @@ -45,22 +37,22 @@
    1.19      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    1.20  ||
    1.21  
    1.22 -condition sameTransaction
    1.23 +condition sameNegotiation
    1.24  ||
    1.25      TID_t *t1 = &session->sync_state.keysync.negotiation;
    1.26 -    TID_t *t2 = &session->sync_state.own.negotiation;
    1.27 +    TID_t *t2 = &session->sync_state.comm_partner.negotiation;
    1.28  
    1.29      // test if TID is identical
    1.30      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    1.31  ||
    1.32  
    1.33 -condition sameTransactionAndPartner
    1.34 +condition sameNegotiationAndPartner
    1.35  ||
    1.36      TID_t *t1 = &session->sync_state.keysync.negotiation;
    1.37 -    TID_t *t2 = &session->sync_state.own.negotiation;
    1.38 +    TID_t *t2 = &session->sync_state.comm_partner.negotiation;
    1.39  
    1.40 -    const char *s1 = session->sync_state.comm_partner.signature_fpr;
    1.41 -    const char *s2 = session->sync_state.transport.signature_fpr;
    1.42 +    const char *s1 = session->sync_state.comm_partner.sender_fpr;
    1.43 +    const char *s2 = session->sync_state.transport.sender_fpr;
    1.44  
    1.45      // test if TID is identical
    1.46      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0
    1.47 @@ -70,8 +62,8 @@
    1.48  
    1.49  condition keyElectionWon
    1.50  ||
    1.51 -    pEp_identity *from = session->sync_state.comm_partner.from;
    1.52 -    char *signature_fpr = session->sync_state.comm_partner.signature_fpr;
    1.53 +    pEp_identity *from = session->sync_state.transport.from;
    1.54 +    char *sender_fpr = session->sync_state.comm_partner.sender_fpr;
    1.55  
    1.56      assert(from && from->address && from->address[0] && from->user_id &&
    1.57              from->user_id[0]);
    1.58 @@ -91,8 +83,8 @@
    1.59          return PEP_ILLEGAL_VALUE;
    1.60      }
    1.61  
    1.62 -    size_t len = MIN(strlen(signature_fpr), strlen(me->fpr));
    1.63 -    *result = strncasecmp(signature_fpr, me->fpr, len) > 0;
    1.64 +    size_t len = MIN(strlen(sender_fpr), strlen(me->fpr));
    1.65 +    *result = strncasecmp(sender_fpr, me->fpr, len) > 0;
    1.66      free_identity(me);
    1.67  ||
    1.68  
    1.69 @@ -162,59 +154,77 @@
    1.70  
    1.71      // we take the actual signature of the last message and store it in our
    1.72      // state for the comm partner
    1.73 -    assert(session->sync_state.transport.signature_fpr);
    1.74 +    assert(session->sync_state.transport.sender_fpr);
    1.75  
    1.76 -    free(session->sync_state.comm_partner.signature_fpr);
    1.77 +    free(session->sync_state.comm_partner.sender_fpr);
    1.78  
    1.79 -    session->sync_state.comm_partner.signature_fpr
    1.80 -            = strdup(session->sync_state.transport.signature_fpr);
    1.81 -    assert(session->sync_state.comm_partner.signature_fpr);
    1.82 -    if (!session->sync_state.comm_partner.signature_fpr)
    1.83 +    session->sync_state.comm_partner.sender_fpr
    1.84 +            = strdup(session->sync_state.transport.sender_fpr);
    1.85 +    assert(session->sync_state.comm_partner.sender_fpr);
    1.86 +    if (!session->sync_state.comm_partner.sender_fpr)
    1.87          return PEP_OUT_OF_MEMORY;
    1.88  
    1.89  ||
    1.90 +    // we need a unique TID for the Negotiation with each single comm_partner
    1.91 +    // we identify the comm_partners by their Challenge
    1.92 +    // we derive the actual Negotiation TID by having random data and XORing it
    1.93 +    // with comm_partner's Challenge
    1.94 +
    1.95 +    // this is the random data we are using as a base
    1.96 +
    1.97 +    call "new_UUID" with "dst" > &session->sync_state.own.negotiation
    1.98 +
    1.99 +    // copy this into the buffer
   1.100 +
   1.101      call "copy_UUID" {
   1.102 +        with "src" > &session->sync_state.own.negotiation
   1.103 +        with "dst" > &session->sync_state.keysync.negotiation
   1.104 +    }
   1.105 +
   1.106 +    // we're XORing this with the challenge of the comm_partner, which is in
   1.107 +    // the buffer already
   1.108 +
   1.109 +    call "xor_UUID" {
   1.110          with "src" > &session->sync_state.keysync.challenge
   1.111          with "dst" > &session->sync_state.keysync.negotiation
   1.112      }
   1.113 -    call "xor_UUID" {
   1.114 -        with "src" > &session->sync_state.own.challenge
   1.115 -        with "dst" > &session->sync_state.keysync.negotiation
   1.116 -    }
   1.117 +
   1.118 +    // this is the Negotiation's TID for this comm_partner
   1.119 +
   1.120      call "copy_UUID" {
   1.121          with "src" > &session->sync_state.keysync.negotiation
   1.122 -        with "dst" > &session->sync_state.own.negotiation
   1.123 +        with "dst" > &session->sync_state.comm_partner.negotiation
   1.124      }
   1.125  }
   1.126  
   1.127 -action closeTransaction
   1.128 +action closeNegotiation
   1.129  ||
   1.130      memset(session->sync_state.keysync.negotiation.buf, 0,
   1.131              session->sync_state.keysync.negotiation.size);
   1.132 -    memset(session->sync_state.own.negotiation.buf, 0,
   1.133 -            session->sync_state.own.negotiation.size);
   1.134 +    memset(session->sync_state.comm_partner.negotiation.buf, 0,
   1.135 +            session->sync_state.comm_partner.negotiation.size);
   1.136  ||
   1.137  
   1.138 -action storeTransaction {
   1.139 +action storeNegotiation {
   1.140  ||
   1.141      // sender key must be stable while transaction
   1.142  
   1.143      // we take the actual signature of the last message and store it in our
   1.144      // state for the comm partner
   1.145 -    assert(session->sync_state.transport.signature_fpr);
   1.146 +    assert(session->sync_state.transport.sender_fpr);
   1.147  
   1.148 -    free(session->sync_state.comm_partner.signature_fpr);
   1.149 +    free(session->sync_state.comm_partner.sender_fpr);
   1.150  
   1.151 -    session->sync_state.comm_partner.signature_fpr
   1.152 -            = strdup(session->sync_state.transport.signature_fpr);
   1.153 -    assert(session->sync_state.comm_partner.signature_fpr);
   1.154 -    if (!session->sync_state.comm_partner.signature_fpr)
   1.155 +    session->sync_state.comm_partner.sender_fpr
   1.156 +            = strdup(session->sync_state.transport.sender_fpr);
   1.157 +    assert(session->sync_state.comm_partner.sender_fpr);
   1.158 +    if (!session->sync_state.comm_partner.sender_fpr)
   1.159          return PEP_OUT_OF_MEMORY;
   1.160  
   1.161  ||
   1.162      call "copy_UUID" {
   1.163          with "src" > &session->sync_state.keysync.negotiation
   1.164 -        with "dst" > &session->sync_state.own.negotiation
   1.165 +        with "dst" > &session->sync_state.comm_partner.negotiation
   1.166      }
   1.167  }
   1.168  
   1.169 @@ -244,11 +254,11 @@
   1.170      ||
   1.171      otherwise
   1.172      ||
   1.173 -        assert(session->sync_state.comm_partner.from);
   1.174 -        if (!session->sync_state.comm_partner.from)
   1.175 +        assert(session->sync_state.transport.from);
   1.176 +        if (!session->sync_state.transport.from)
   1.177              return PEP_ILLEGAL_VALUE;
   1.178  
   1.179 -        pEp_identity *from = session->sync_state.comm_partner.from;
   1.180 +        pEp_identity *from = session->sync_state.transport.from;
   1.181          pEp_identity *me = NULL;
   1.182          PEP_STATUS status = get_identity(session, from->address, from->user_id, &me);
   1.183          assert(status == PEP_STATUS_OK);
   1.184 @@ -267,10 +277,10 @@
   1.185              return PEP_OUT_OF_MEMORY;
   1.186          }
   1.187  
   1.188 -        assert(session->sync_state.comm_partner.signature_fpr);
   1.189 -        if (session->sync_state.comm_partner.signature_fpr) {
   1.190 +        assert(session->sync_state.comm_partner.sender_fpr);
   1.191 +        if (session->sync_state.comm_partner.sender_fpr) {
   1.192              free(partner->fpr);
   1.193 -            partner->fpr = strdup(session->sync_state.comm_partner.signature_fpr);
   1.194 +            partner->fpr = strdup(session->sync_state.comm_partner.sender_fpr);
   1.195              if (!partner->fpr) {
   1.196                  free_identity(me);
   1.197                  free_identity(partner);
   1.198 @@ -393,7 +403,7 @@
   1.199      for (il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
   1.200          // replace partner's user_id with own user_id
   1.201          free(il->ident->user_id);
   1.202 -        il->ident->user_id = strdup(session->sync_state.comm_partner.from->user_id);
   1.203 +        il->ident->user_id = strdup(session->sync_state.transport.from->user_id);
   1.204          if (!il->ident->user_id) {
   1.205              free_identity_list(il);
   1.206              return PEP_OUT_OF_MEMORY;
   1.207 @@ -417,15 +427,15 @@
   1.208  
   1.209  action trustThisKey
   1.210  ||
   1.211 -    assert(session->sync_state.comm_partner.from && session->sync_state.comm_partner.signature_fpr);
   1.212 -    if (!(session->sync_state.comm_partner.from && session->sync_state.comm_partner.signature_fpr))
   1.213 +    assert(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr);
   1.214 +    if (!(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr))
   1.215          return PEP_ILLEGAL_VALUE;
   1.216  
   1.217 -    pEp_identity *ident = identity_dup(session->sync_state.comm_partner.from);
   1.218 +    pEp_identity *ident = identity_dup(session->sync_state.transport.from);
   1.219      if (!ident)
   1.220          return PEP_OUT_OF_MEMORY;
   1.221      free(ident->fpr);
   1.222 -    ident->fpr = strdup(session->sync_state.comm_partner.signature_fpr);
   1.223 +    ident->fpr = strdup(session->sync_state.comm_partner.sender_fpr);
   1.224      assert(ident->fpr);
   1.225      if (!ident->fpr) {
   1.226          free_identity(ident);
   1.227 @@ -444,13 +454,13 @@
   1.228  
   1.229  action untrustThisKey
   1.230  ||
   1.231 -    assert(session->sync_state.comm_partner.from && session->sync_state.comm_partner.signature_fpr);
   1.232 -    if (!(session->sync_state.comm_partner.from && session->sync_state.comm_partner.signature_fpr))
   1.233 +    assert(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr);
   1.234 +    if (!(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr))
   1.235          return PEP_ILLEGAL_VALUE;
   1.236  
   1.237 -    pEp_identity *ident = session->sync_state.comm_partner.from;
   1.238 +    pEp_identity *ident = session->sync_state.transport.from;
   1.239      free(ident->fpr);
   1.240 -    ident->fpr = strdup(session->sync_state.comm_partner.signature_fpr);
   1.241 +    ident->fpr = strdup(session->sync_state.comm_partner.sender_fpr);
   1.242      assert(ident->fpr);
   1.243      if (!ident->fpr)
   1.244          return PEP_OUT_OF_MEMORY;
     2.1 --- a/sync/gen_message_func.ysl2	Wed May 29 21:00:09 2019 +0200
     2.2 +++ b/sync/gen_message_func.ysl2	Wed May 29 23:17:19 2019 +0200
     2.3 @@ -53,8 +53,7 @@
     2.4  
     2.5      struct comm_partner_state_s {
     2.6          // transport data we expect
     2.7 -        pEp_identity *from;
     2.8 -        char *signature_fpr;
     2.9 +        char *sender_fpr;
    2.10  
    2.11          // TIDs our comm partner wants to have
    2.12          `` for "func:distinctName(fsm/message/field[@type='TID'])" |>> «func:ctype()» «@name»;
    2.13 @@ -65,7 +64,7 @@
    2.14      struct transport_data_s {
    2.15          // transport data we got
    2.16          pEp_identity *from;
    2.17 -        char *signature_fpr;
    2.18 +        char *sender_fpr;
    2.19      } transport;
    2.20      `` apply "fsm", mode=state
    2.21  };
    2.22 @@ -133,10 +132,8 @@
    2.23  
    2.24      // state we learned about our communication partner
    2.25  
    2.26 -    free_identity(session->«yml:lcase(@name)»_state.comm_partner.from);
    2.27 -    session->«yml:lcase(@name)»_state.comm_partner.from = NULL;
    2.28 -    free(session->«yml:lcase(@name)»_state.comm_partner.signature_fpr);
    2.29 -    session->«yml:lcase(@name)»_state.comm_partner.signature_fpr = NULL;
    2.30 +    free(session->«yml:lcase(@name)»_state.comm_partner.sender_fpr);
    2.31 +    session->«yml:lcase(@name)»_state.comm_partner.sender_fpr = NULL;
    2.32  
    2.33      // TIDs our comm partner wants to have
    2.34  ||
    2.35 @@ -148,8 +145,8 @@
    2.36  
    2.37      free_identity(session->«yml:lcase(@name)»_state.transport.from);
    2.38      session->«yml:lcase(@name)»_state.transport.from = NULL;
    2.39 -    free(session->«yml:lcase(@name)»_state.transport.signature_fpr);
    2.40 -    session->«yml:lcase(@name)»_state.transport.signature_fpr = NULL;
    2.41 +    free(session->«yml:lcase(@name)»_state.transport.sender_fpr);
    2.42 +    session->«yml:lcase(@name)»_state.transport.sender_fpr = NULL;
    2.43  
    2.44      // message buffers
    2.45  
     3.1 --- a/sync/gen_statemachine.ysl2	Wed May 29 21:00:09 2019 +0200
     3.2 +++ b/sync/gen_statemachine.ysl2	Wed May 29 23:17:19 2019 +0200
     3.3 @@ -38,7 +38,7 @@
     3.4  
     3.5              // transport data
     3.6              pEp_identity *from;
     3.7 -            char *signature_fpr;
     3.8 +            char *sender_fpr;
     3.9  
    3.10              identity_list *own_identities;
    3.11          } «@name»_event_t;
    3.12 @@ -119,7 +119,7 @@
    3.13                  free_identity_list(ev->own_identities);
    3.14                  free_«@name»_message(ev->msg);
    3.15                  free_identity(ev->from);
    3.16 -                free(ev->signature_fpr);
    3.17 +                free(ev->sender_fpr);
    3.18                  free(ev);
    3.19              }
    3.20          }
    3.21 @@ -211,7 +211,7 @@
    3.22                      const char *data,
    3.23                      size_t size,
    3.24                      const pEp_identity *from,
    3.25 -                    const char *signature_fpr
    3.26 +                    const char *sender_fpr
    3.27                  );
    3.28  
    3.29              #ifdef __cplusplus
    3.30 @@ -328,7 +328,7 @@
    3.31                      const char *data,
    3.32                      size_t size,
    3.33                      const pEp_identity *from,
    3.34 -                    const char *signature_fpr
    3.35 +                    const char *sender_fpr
    3.36                  )
    3.37              {
    3.38                  assert(session && data && size);
    3.39 @@ -373,10 +373,10 @@
    3.40                      }
    3.41                  }
    3.42  
    3.43 -                if (signature_fpr) {
    3.44 -                    ev->signature_fpr = strdup(signature_fpr);
    3.45 -                    assert(ev->signature_fpr);
    3.46 -                    if (!ev->signature_fpr) {
    3.47 +                if (sender_fpr) {
    3.48 +                    ev->sender_fpr = strdup(sender_fpr);
    3.49 +                    assert(ev->sender_fpr);
    3.50 +                    if (!ev->sender_fpr) {
    3.51                          status = PEP_OUT_OF_MEMORY;
    3.52                          goto the_end;
    3.53                      }
    3.54 @@ -447,8 +447,8 @@
    3.55  
    3.56                      // these go anycast; previously used address is sticky (unicast)
    3.57                      `` for "fsm/message[@type='anycast']" |>> case «../@name»_PR_«yml:mixedCase(@name)»:
    3.58 -                        if (!session->«yml:lcase(@name)»_state.comm_partner.from `> |`|
    3.59 -                            (session->«yml:lcase(@name)»_state.comm_partner.from->flags &
    3.60 +                        if (!session->«yml:lcase(@name)»_state.transport.from `> |`|
    3.61 +                            (session->«yml:lcase(@name)»_state.transport.from->flags &
    3.62                              PEP_idf_not_for_«yml:lcase(@name)»)) {
    3.63  
    3.64                              // no address available yet, try to find one
    3.65 @@ -468,7 +468,7 @@
    3.66                              }
    3.67                          }
    3.68                          else {
    3.69 -                            pEp_identity *channel = identity_dup(session->«yml:lcase(@name)»_state.comm_partner.from);
    3.70 +                            pEp_identity *channel = identity_dup(session->«yml:lcase(@name)»_state.transport.from);
    3.71                              if (!channel) {
    3.72                                  status = PEP_OUT_OF_MEMORY;
    3.73                                  goto the_end;
    3.74 @@ -521,13 +521,13 @@
    3.75                      `` for "fsm/message[@security='untrusted']" |>>> case «../@name»_PR_«yml:mixedCase(@name)»:
    3.76                              // add fpr of key of comm partner
    3.77  
    3.78 -                            assert(session->«yml:lcase(@name)»_state.comm_partner.signature_fpr);
    3.79 -                            if (!session->«yml:lcase(@name)»_state.comm_partner.signature_fpr) {
    3.80 +                            assert(session->«yml:lcase(@name)»_state.comm_partner.sender_fpr);
    3.81 +                            if (!session->«yml:lcase(@name)»_state.comm_partner.sender_fpr) {
    3.82                                  status = PEP_«yml:ucase(@name)»_CANNOT_ENCRYPT;
    3.83                                  goto the_end;
    3.84                              }
    3.85  
    3.86 -                            extra = new_stringlist(session->«yml:lcase(@name)»_state.comm_partner.signature_fpr);
    3.87 +                            extra = new_stringlist(session->«yml:lcase(@name)»_state.comm_partner.sender_fpr);
    3.88                              if (!extra) {
    3.89                                  status = PEP_OUT_OF_MEMORY;
    3.90                                  goto the_end;
    3.91 @@ -573,12 +573,12 @@
    3.92                              // secret keys
    3.93  
    3.94                              if (transaction) {
    3.95 -                                assert(session->«yml:lcase(@name)»_state.comm_partner.signature_fpr &&
    3.96 -                                    session->«yml:lcase(@name)»_state.comm_partner.from &&
    3.97 -                                    session->«yml:lcase(@name)»_state.comm_partner.from->user_id);
    3.98 -                                if (!(session->«yml:lcase(@name)»_state.comm_partner.signature_fpr &&
    3.99 -                                        session->«yml:lcase(@name)»_state.comm_partner.from &&
   3.100 -                                        session->«yml:lcase(@name)»_state.comm_partner.from->user_id))
   3.101 +                                assert(session->«yml:lcase(@name)»_state.comm_partner.sender_fpr &&
   3.102 +                                    session->«yml:lcase(@name)»_state.transport.from &&
   3.103 +                                    session->«yml:lcase(@name)»_state.transport.from->user_id);
   3.104 +                                if (!(session->«yml:lcase(@name)»_state.comm_partner.sender_fpr &&
   3.105 +                                        session->«yml:lcase(@name)»_state.transport.from &&
   3.106 +                                        session->«yml:lcase(@name)»_state.transport.from->user_id))
   3.107                                  {
   3.108                                      status = PEP_«yml:ucase(@name)»_CANNOT_ENCRYPT;
   3.109                                      goto the_end;
   3.110 @@ -587,8 +587,8 @@
   3.111                                  // test if this is a green channel
   3.112  
   3.113                                  pEp_identity *ident = new_identity(NULL,
   3.114 -                                        session->«yml:lcase(@name)»_state.comm_partner.signature_fpr,
   3.115 -                                        session->«yml:lcase(@name)»_state.comm_partner.from->user_id,
   3.116 +                                        session->«yml:lcase(@name)»_state.comm_partner.sender_fpr,
   3.117 +                                        session->«yml:lcase(@name)»_state.transport.from->user_id,
   3.118                                          NULL
   3.119                                      );
   3.120                                  if (!ident) {
   3.121 @@ -612,7 +612,7 @@
   3.122  
   3.123                                  bool is_own_key = false;
   3.124                                  status = own_key_is_listed(session,
   3.125 -                                        session->«yml:lcase(@name)»_state.comm_partner.signature_fpr,
   3.126 +                                        session->«yml:lcase(@name)»_state.comm_partner.sender_fpr,
   3.127                                          &is_own_key);
   3.128                                  assert(!status);
   3.129                                  if (status)
   3.130 @@ -625,7 +625,7 @@
   3.131  
   3.132                                  // if so add key of comm partner to extra keys
   3.133  
   3.134 -                                extra = new_stringlist(session->«yml:lcase(@name)»_state.comm_partner.signature_fpr);
   3.135 +                                extra = new_stringlist(session->«yml:lcase(@name)»_state.comm_partner.sender_fpr);
   3.136                                  if (!extra) {
   3.137                                      status = PEP_OUT_OF_MEMORY;
   3.138                                      goto the_end;
   3.139 @@ -813,10 +813,10 @@
   3.140                      ev->from = NULL;
   3.141                  }
   3.142  
   3.143 -                if (ev->signature_fpr) {
   3.144 -                    free(session->«yml:lcase(@name)»_state.transport.signature_fpr);
   3.145 -                    session->«yml:lcase(@name)»_state.transport.signature_fpr = ev->signature_fpr;
   3.146 -                    ev->signature_fpr = NULL;
   3.147 +                if (ev->sender_fpr) {
   3.148 +                    free(session->«yml:lcase(@name)»_state.transport.sender_fpr);
   3.149 +                    session->«yml:lcase(@name)»_state.transport.sender_fpr = ev->sender_fpr;
   3.150 +                    ev->sender_fpr = NULL;
   3.151                  }
   3.152  
   3.153                  // update own identities
   3.154 @@ -901,7 +901,7 @@
   3.155          if "position()=1" |>> // these messages require a detached signature
   3.156          ||
   3.157                  case «../@name»_PR_«yml:mixedCase(@name)»:
   3.158 -                    if (!signature_fpr) {
   3.159 +                    if (!sender_fpr) {
   3.160                          status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;
   3.161                          goto the_end;
   3.162                      }
   3.163 @@ -931,7 +931,7 @@
   3.164                          status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;
   3.165                          goto the_end;
   3.166                      }
   3.167 -                    status = own_key_is_listed(session, signature_fpr, &is_own_key);
   3.168 +                    status = own_key_is_listed(session, sender_fpr, &is_own_key);
   3.169                      if (status)
   3.170                          goto the_end;
   3.171                      if (!is_own_key) {
     4.1 --- a/sync/sync.fsm	Wed May 29 21:00:09 2019 +0200
     4.2 +++ b/sync/sync.fsm	Wed May 29 23:17:19 2019 +0200
     4.3 @@ -23,7 +23,7 @@
     4.4  
     4.5          state Sole timeout=off {
     4.6              on Init {
     4.7 -                do closeTransaction;
     4.8 +                do closeNegotiation;
     4.9                  do newChallenge;
    4.10                  do showBeingSole;
    4.11                  send Beacon;
    4.12 @@ -43,13 +43,13 @@
    4.13                  }
    4.14                  else {
    4.15                      if weAreFirst {
    4.16 +                        do useOwnChallenge;
    4.17                          send Beacon;
    4.18                      }
    4.19                      else /* we are second */ {
    4.20                          do newNegotiation;
    4.21                          do tellWeAreNotGrouped;
    4.22                          // second is sending NegotiationRequest
    4.23 -                        do replyChallenge; // partner's challenge
    4.24                          send NegotiationRequest;
    4.25                          do useOwnChallenge;
    4.26                      }
    4.27 @@ -57,23 +57,24 @@
    4.28              }
    4.29  
    4.30              on NegotiationRequest {
    4.31 -                if challengeAccepted {
    4.32 -                    if sameTransaction {
    4.33 +                if sameChallenge { // challenge accepted
    4.34 +                    if sameNegotiation {
    4.35                          // this is our own NegotiationRequest; ignore
    4.36                      }
    4.37                      else {
    4.38                          // first is receiving NegotiationRequest
    4.39 -                        do storeTransaction;
    4.40 +                        do storeNegotiation;
    4.41                          // first is sending NegotiationOpen
    4.42                          send NegotiationOpen;
    4.43                          if partnerIsGrouped
    4.44                              go HandshakingWithGroup;
    4.45 -                        go HandshakingNewFirst;
    4.46 +                        else
    4.47 +                            go HandshakingNewFirst;
    4.48                      }
    4.49                  }
    4.50              }
    4.51  
    4.52 -            on NegotiationOpen if sameTransactionAndPartner {
    4.53 +            on NegotiationOpen if sameNegotiationAndPartner {
    4.54                  // second is receiving NegotiationOpen
    4.55                  go HandshakingNewSecond;
    4.56              }
    4.57 @@ -90,7 +91,7 @@
    4.58                  go Sole;
    4.59              }
    4.60  
    4.61 -            on Rollback if sameTransactionAndPartner
    4.62 +            on Rollback if sameNegotiationAndPartner
    4.63                  go Sole;
    4.64  
    4.65              // Reject is CommitReject
    4.66 @@ -100,7 +101,7 @@
    4.67                  go End;
    4.68              }
    4.69  
    4.70 -            on CommitReject if sameTransactionAndPartner {
    4.71 +            on CommitReject if sameNegotiationAndPartner {
    4.72                  do disable;
    4.73                  go End;
    4.74              }
    4.75 @@ -113,7 +114,7 @@
    4.76              }
    4.77  
    4.78              // got a CommitAccept from second
    4.79 -            on CommitAcceptSecond if sameTransactionAndPartner
    4.80 +            on CommitAcceptSecond if sameNegotiationAndPartner
    4.81                  go HandshakingNewPhase2First;
    4.82          }
    4.83  
    4.84 @@ -128,7 +129,7 @@
    4.85                  go Sole;
    4.86              }
    4.87  
    4.88 -            on Rollback if sameTransactionAndPartner
    4.89 +            on Rollback if sameNegotiationAndPartner
    4.90                  go Sole;
    4.91  
    4.92              // Reject is CommitReject
    4.93 @@ -138,7 +139,7 @@
    4.94                  go End;
    4.95              }
    4.96  
    4.97 -            on CommitReject if sameTransactionAndPartner {
    4.98 +            on CommitReject if sameNegotiationAndPartner {
    4.99                  do disable;
   4.100                  go End;
   4.101              }
   4.102 @@ -151,40 +152,40 @@
   4.103              }
   4.104  
   4.105              // got a CommitAccept from first
   4.106 -            on CommitAcceptFirst if sameTransactionAndPartner
   4.107 +            on CommitAcceptFirst if sameNegotiationAndPartner
   4.108                  go HandshakingNewPhase2Second;
   4.109          }
   4.110  
   4.111          state HandshakingNewPhase1First {
   4.112 -            on Rollback if sameTransactionAndPartner {
   4.113 +            on Rollback if sameNegotiationAndPartner {
   4.114                  do untrustThisKey;
   4.115                  go Sole;
   4.116              }
   4.117              
   4.118 -            on CommitReject if sameTransactionAndPartner {
   4.119 +            on CommitReject if sameNegotiationAndPartner {
   4.120                  do untrustThisKey;
   4.121                  do disable;
   4.122                  go End;
   4.123              }
   4.124  
   4.125 -            on CommitAcceptSecond if sameTransactionAndPartner {
   4.126 +            on CommitAcceptSecond if sameNegotiationAndPartner {
   4.127                  go NewGroupFirst;
   4.128              }
   4.129          }
   4.130  
   4.131          state HandshakingNewPhase1Second {
   4.132 -            on Rollback if sameTransactionAndPartner {
   4.133 +            on Rollback if sameNegotiationAndPartner {
   4.134                  do untrustThisKey;
   4.135                  go Sole;
   4.136              }
   4.137              
   4.138 -            on CommitReject if sameTransactionAndPartner {
   4.139 +            on CommitReject if sameNegotiationAndPartner {
   4.140                  do untrustThisKey;
   4.141                  do disable;
   4.142                  go End;
   4.143              }
   4.144  
   4.145 -            on CommitAcceptFirst if sameTransactionAndPartner {
   4.146 +            on CommitAcceptFirst if sameNegotiationAndPartner {
   4.147                  go NewGroupSecond;
   4.148              }
   4.149          }
   4.150 @@ -265,7 +266,7 @@
   4.151  
   4.152          state Grouped timeout=off {
   4.153              on Init {
   4.154 -                do closeTransaction;
   4.155 +                do closeNegotiation;
   4.156                  do newChallenge;
   4.157                  do showBeingInGroup;
   4.158              }
   4.159 @@ -281,12 +282,11 @@
   4.160              on Beacon {
   4.161                  do newNegotiation;
   4.162                  do tellWeAreGrouped;
   4.163 -                do replyChallenge; // partner's challenge
   4.164                  send NegotiationRequest;
   4.165                  do useOwnChallenge;
   4.166              }
   4.167  
   4.168 -            on NegotiationOpen if sameTransactionAndPartner
   4.169 +            on NegotiationOpen if sameNegotiationAndPartner
   4.170                  go HandshakingGrouped;
   4.171  
   4.172              on GroupTrustThisKey {
   4.173 @@ -305,7 +305,7 @@
   4.174                  go Sole;
   4.175              }
   4.176  
   4.177 -            on Rollback if sameTransactionAndPartner
   4.178 +            on Rollback if sameNegotiationAndPartner
   4.179                  go Sole;
   4.180  
   4.181              // Reject is CommitReject
   4.182 @@ -315,7 +315,7 @@
   4.183                  go End;
   4.184              }
   4.185  
   4.186 -            on CommitReject if sameTransactionAndPartner {
   4.187 +            on CommitReject if sameNegotiationAndPartner {
   4.188                  do disable;
   4.189                  go End;
   4.190              }
   4.191 @@ -327,20 +327,20 @@
   4.192                  go HandshakingJoinPhase1;
   4.193              }
   4.194  
   4.195 -            on CommitAcceptForGroup if sameTransactionAndPartner
   4.196 +            on CommitAcceptForGroup if sameNegotiationAndPartner
   4.197                  go HandshakingJoinPhase2;
   4.198          }
   4.199  
   4.200          state HandshakingJoinPhase1 {
   4.201 -            on Rollback if sameTransactionAndPartner
   4.202 +            on Rollback if sameNegotiationAndPartner
   4.203                  go Sole;
   4.204              
   4.205 -            on CommitReject if sameTransactionAndPartner {
   4.206 +            on CommitReject if sameNegotiationAndPartner {
   4.207                  do disable;
   4.208                  go End;
   4.209              }
   4.210  
   4.211 -            on CommitAcceptForGroup if sameTransactionAndPartner {
   4.212 +            on CommitAcceptForGroup if sameNegotiationAndPartner {
   4.213                  go JoinGroup;
   4.214              }
   4.215          }
   4.216 @@ -387,7 +387,7 @@
   4.217                  go Grouped;
   4.218              }
   4.219  
   4.220 -            on Rollback if sameTransactionAndPartner
   4.221 +            on Rollback if sameNegotiationAndPartner
   4.222                  go Grouped;
   4.223  
   4.224              // Reject is CommitReject
   4.225 @@ -396,7 +396,7 @@
   4.226                  go Grouped;
   4.227              }
   4.228  
   4.229 -            on CommitReject if sameTransactionAndPartner
   4.230 +            on CommitReject if sameNegotiationAndPartner
   4.231                  go Grouped;
   4.232  
   4.233              // Accept is Phase1Commit
   4.234 @@ -407,7 +407,7 @@
   4.235                  go HandshakingGroupedPhase1;
   4.236              }
   4.237  
   4.238 -            on CommitAccept if sameTransactionAndPartner
   4.239 +            on CommitAccept if sameNegotiationAndPartner
   4.240                  go HandshakingGroupedPhase2;
   4.241  
   4.242              on GroupTrustThisKey {
   4.243 @@ -417,7 +417,7 @@
   4.244  
   4.245              on CommitAcceptForGroup {
   4.246                  do showDeviceAdded;
   4.247 -                if sameTransactionAndPartner {
   4.248 +                if sameNegotiationAndPartner {
   4.249                      do hideHandshakeDialog;
   4.250                      go Grouped;
   4.251                  }
   4.252 @@ -428,13 +428,13 @@
   4.253          }
   4.254  
   4.255          state HandshakingGroupedPhase1 {
   4.256 -            on Rollback if sameTransactionAndPartner
   4.257 +            on Rollback if sameNegotiationAndPartner
   4.258                  go Grouped;
   4.259  
   4.260 -            on CommitReject if sameTransactionAndPartner
   4.261 +            on CommitReject if sameNegotiationAndPartner
   4.262                  go Grouped;
   4.263  
   4.264 -            on CommitAccept if sameTransactionAndPartner {
   4.265 +            on CommitAccept if sameNegotiationAndPartner {
   4.266                  send GroupKeys;
   4.267                  go Grouped;
   4.268              }
   4.269 @@ -445,7 +445,7 @@
   4.270  
   4.271              on CommitAcceptForGroup {
   4.272                  do showDeviceAdded;
   4.273 -                if sameTransactionAndPartner
   4.274 +                if sameNegotiationAndPartner
   4.275                      go Grouped;
   4.276              }
   4.277  
   4.278 @@ -477,7 +477,7 @@
   4.279  
   4.280              on CommitAcceptForGroup {
   4.281                  do showDeviceAdded;
   4.282 -                if sameTransactionAndPartner {
   4.283 +                if sameNegotiationAndPartner {
   4.284                      do hideHandshakeDialog;
   4.285                      go Grouped;
   4.286                  }