check for same partner only while being in a transaction sync
authorVolker Birk <vb@pep-project.org>
Tue, 30 Apr 2019 22:34:04 +0200
branchsync
changeset 359119d842c279ee
parent 3590 69969ad8d4af
child 3592 34410422e806
check for same partner only while being in a transaction
sync/cond_act_sync.yml2
sync/sync.fsm
     1.1 --- a/sync/cond_act_sync.yml2	Tue Apr 30 21:02:44 2019 +0200
     1.2 +++ b/sync/cond_act_sync.yml2	Tue Apr 30 22:34:04 2019 +0200
     1.3 @@ -50,9 +50,24 @@
     1.4      TID_t *t1 = &session->sync_state.keysync.negotiation;
     1.5      TID_t *t2 = &session->own_sync_state.negotiation;
     1.6  
     1.7 +    // test if TID is identical
     1.8      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
     1.9  ||
    1.10  
    1.11 +condition sameTransactionAndPartner
    1.12 +||
    1.13 +    TID_t *t1 = &session->sync_state.keysync.negotiation;
    1.14 +    TID_t *t2 = &session->own_sync_state.negotiation;
    1.15 +
    1.16 +    const char *s1 = session->sync_state.common.signature_fpr;
    1.17 +    const char *s2 = session->own_sync_state.signature_fpr;
    1.18 +
    1.19 +    // test if TID is identical
    1.20 +    *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0
    1.21 +    // and test if we're talking to the same sender
    1.22 +            && s1 && s2 && strcmp(s1, s2) == 0;
    1.23 +||
    1.24 +
    1.25  condition keyElectionWon
    1.26  ||
    1.27      pEp_identity *from = session->sync_state.common.from;
    1.28 @@ -115,26 +130,23 @@
    1.29      with "dst" > &session->own_sync_state.challenge
    1.30  }
    1.31  
    1.32 -action openTransaction {
    1.33 +action newTransaction {
    1.34  ||
    1.35 -    // if transaction already open do nothing
    1.36 -    for (int i=0; i<session->sync_state.keysync.negotiation.size; ++i) {
    1.37 -        if (session->sync_state.keysync.negotiation.buf[i])
    1.38 -            return PEP_STATUS_OK;
    1.39 -    }
    1.40 -
    1.41      // sender key must be stable while transaction
    1.42 -    if (!session->own_sync_state.signature_fpr) {
    1.43 -        assert(session->sync_state.common.signature_fpr);
    1.44 -        session->own_sync_state.signature_fpr
    1.45 -                = strdup(session->sync_state.common.signature_fpr);
    1.46 -        assert(session->own_sync_state.signature_fpr);
    1.47 -        if (!session->own_sync_state.signature_fpr)
    1.48 -            return PEP_OUT_OF_MEMORY;
    1.49 -    }
    1.50 +    assert(session->sync_state.common.signature_fpr);
    1.51 +    free(session->own_sync_state.signature_fpr);
    1.52 +    session->own_sync_state.signature_fpr
    1.53 +            = strdup(session->sync_state.common.signature_fpr);
    1.54 +    assert(session->own_sync_state.signature_fpr);
    1.55 +    if (!session->own_sync_state.signature_fpr)
    1.56 +        return PEP_OUT_OF_MEMORY;
    1.57  
    1.58  ||
    1.59      call "new_UUID" with "dst" > &session->sync_state.keysync.negotiation
    1.60 +    call "copy_UUID" {
    1.61 +        with "src" > &session->sync_state.keysync.negotiation
    1.62 +        with "dst" > &session->own_sync_state.negotiation
    1.63 +    }
    1.64  }
    1.65  
    1.66  action closeTransaction
    1.67 @@ -145,9 +157,22 @@
    1.68      session->own_sync_state.signature_fpr = NULL;
    1.69  ||
    1.70  
    1.71 -action storeTransaction call "copy_UUID" {
    1.72 -    with "src" > &session->sync_state.keysync.negotiation
    1.73 -    with "dst" > &session->own_sync_state.negotiation
    1.74 +action storeTransaction {
    1.75 +||
    1.76 +    // sender key must be stable while transaction
    1.77 +    assert(session->sync_state.common.signature_fpr);
    1.78 +    free(session->own_sync_state.signature_fpr);
    1.79 +    session->own_sync_state.signature_fpr
    1.80 +            = strdup(session->sync_state.common.signature_fpr);
    1.81 +    assert(session->own_sync_state.signature_fpr);
    1.82 +    if (!session->own_sync_state.signature_fpr)
    1.83 +        return PEP_OUT_OF_MEMORY;
    1.84 +
    1.85 +||
    1.86 +    call "copy_UUID" {
    1.87 +        with "src" > &session->sync_state.keysync.negotiation
    1.88 +        with "dst" > &session->own_sync_state.negotiation
    1.89 +    }
    1.90  }
    1.91  
    1.92  function "show_handshake" {
     2.1 --- a/sync/sync.fsm	Tue Apr 30 21:02:44 2019 +0200
     2.2 +++ b/sync/sync.fsm	Tue Apr 30 22:34:04 2019 +0200
     2.3 @@ -37,7 +37,7 @@
     2.4  
     2.5              on Beacon {
     2.6                  if sameChallenge {
     2.7 -                    // this is our own beacon; ignore
     2.8 +                    // this is our own Beacon; ignore
     2.9                  }
    2.10                  else {
    2.11                      if weAreFirst {
    2.12 @@ -45,8 +45,7 @@
    2.13                      }
    2.14                      else /* we are second */ {
    2.15                          do storeChallenge; // partner's challenge
    2.16 -                        do openTransaction; // NOP if negotiation already open
    2.17 -                        do storeTransaction;
    2.18 +                        do newTransaction;
    2.19                          do tellWeAreNotGrouped;
    2.20                          // second is sending NegotiationRequest
    2.21                          send NegotiationRequest;
    2.22 @@ -56,7 +55,7 @@
    2.23  
    2.24              on NegotiationRequest if challengeAccepted {
    2.25                  if sameTransaction {
    2.26 -                    // this is our own handshake request; ignore
    2.27 +                    // this is our own NegotiationRequest; ignore
    2.28                  }
    2.29                  else {
    2.30                      // first is receiving NegotiationRequest
    2.31 @@ -69,7 +68,7 @@
    2.32                  }
    2.33              }
    2.34  
    2.35 -            on NegotiationOpen if sameTransaction {
    2.36 +            on NegotiationOpen if sameTransactionAndPartner {
    2.37                  // second is receiving NegotiationOpen
    2.38                  go HandshakingNewSecond;
    2.39              }
    2.40 @@ -86,7 +85,7 @@
    2.41                  go Sole;
    2.42              }
    2.43  
    2.44 -            on Rollback if sameTransaction
    2.45 +            on Rollback if sameTransactionAndPartner
    2.46                  go Sole;
    2.47  
    2.48              // Reject is CommitReject
    2.49 @@ -96,7 +95,7 @@
    2.50                  go End;
    2.51              }
    2.52  
    2.53 -            on CommitReject if sameTransaction {
    2.54 +            on CommitReject if sameTransactionAndPartner {
    2.55                  do disable;
    2.56                  go End;
    2.57              }
    2.58 @@ -109,7 +108,7 @@
    2.59              }
    2.60  
    2.61              // got a CommitAccept from second
    2.62 -            on CommitAcceptSecond if sameTransaction
    2.63 +            on CommitAcceptSecond if sameTransactionAndPartner
    2.64                  go HandshakingNewPhase2First;
    2.65          }
    2.66  
    2.67 @@ -124,7 +123,7 @@
    2.68                  go Sole;
    2.69              }
    2.70  
    2.71 -            on Rollback if sameTransaction
    2.72 +            on Rollback if sameTransactionAndPartner
    2.73                  go Sole;
    2.74  
    2.75              // Reject is CommitReject
    2.76 @@ -134,7 +133,7 @@
    2.77                  go End;
    2.78              }
    2.79  
    2.80 -            on CommitReject if sameTransaction {
    2.81 +            on CommitReject if sameTransactionAndPartner {
    2.82                  do disable;
    2.83                  go End;
    2.84              }
    2.85 @@ -147,40 +146,40 @@
    2.86              }
    2.87  
    2.88              // got a CommitAccept from first
    2.89 -            on CommitAcceptFirst if sameTransaction
    2.90 +            on CommitAcceptFirst if sameTransactionAndPartner
    2.91                  go HandshakingNewPhase2Second;
    2.92          }
    2.93  
    2.94          state HandshakingNewPhase1First {
    2.95 -            on Rollback if sameTransaction {
    2.96 +            on Rollback if sameTransactionAndPartner {
    2.97                  do untrustThisKey;
    2.98                  go Sole;
    2.99              }
   2.100              
   2.101 -            on CommitReject if sameTransaction {
   2.102 +            on CommitReject if sameTransactionAndPartner {
   2.103                  do untrustThisKey;
   2.104                  do disable;
   2.105                  go End;
   2.106              }
   2.107  
   2.108 -            on CommitAcceptSecond if sameTransaction {
   2.109 +            on CommitAcceptSecond if sameTransactionAndPartner {
   2.110                  go NewGroupFirst;
   2.111              }
   2.112          }
   2.113  
   2.114          state HandshakingNewPhase1Second {
   2.115 -            on Rollback if sameTransaction {
   2.116 +            on Rollback if sameTransactionAndPartner {
   2.117                  do untrustThisKey;
   2.118                  go Sole;
   2.119              }
   2.120              
   2.121 -            on CommitReject if sameTransaction {
   2.122 +            on CommitReject if sameTransactionAndPartner {
   2.123                  do untrustThisKey;
   2.124                  do disable;
   2.125                  go End;
   2.126              }
   2.127  
   2.128 -            on CommitAcceptFirst if sameTransaction {
   2.129 +            on CommitAcceptFirst if sameTransactionAndPartner {
   2.130                  go NewGroupSecond;
   2.131              }
   2.132          }
   2.133 @@ -277,13 +276,12 @@
   2.134  
   2.135              on Beacon {
   2.136                  do storeChallenge;
   2.137 -                do openTransaction;
   2.138 -                do storeTransaction;
   2.139 +                do newTransaction;
   2.140                  do tellWeAreGrouped;
   2.141                  send NegotiationRequest;
   2.142              }
   2.143  
   2.144 -            on NegotiationOpen if sameTransaction
   2.145 +            on NegotiationOpen if sameTransactionAndPartner
   2.146                  go HandshakingGrouped;
   2.147  
   2.148              on GroupTrustThisKey {
   2.149 @@ -302,7 +300,7 @@
   2.150                  go Sole;
   2.151              }
   2.152  
   2.153 -            on Rollback if sameTransaction
   2.154 +            on Rollback if sameTransactionAndPartner
   2.155                  go Sole;
   2.156  
   2.157              // Reject is CommitReject
   2.158 @@ -312,7 +310,7 @@
   2.159                  go End;
   2.160              }
   2.161  
   2.162 -            on CommitReject if sameTransaction {
   2.163 +            on CommitReject if sameTransactionAndPartner {
   2.164                  do disable;
   2.165                  go End;
   2.166              }
   2.167 @@ -324,20 +322,20 @@
   2.168                  go HandshakingJoinPhase1;
   2.169              }
   2.170  
   2.171 -            on CommitAcceptForGroup if sameTransaction
   2.172 +            on CommitAcceptForGroup if sameTransactionAndPartner
   2.173                  go HandshakingJoinPhase2;
   2.174          }
   2.175  
   2.176          state HandshakingJoinPhase1 {
   2.177 -            on Rollback if sameTransaction
   2.178 +            on Rollback if sameTransactionAndPartner
   2.179                  go Sole;
   2.180              
   2.181 -            on CommitReject if sameTransaction {
   2.182 +            on CommitReject if sameTransactionAndPartner {
   2.183                  do disable;
   2.184                  go End;
   2.185              }
   2.186  
   2.187 -            on CommitAcceptForGroup if sameTransaction {
   2.188 +            on CommitAcceptForGroup if sameTransactionAndPartner {
   2.189                  go JoinGroup;
   2.190              }
   2.191          }
   2.192 @@ -385,7 +383,7 @@
   2.193                  go Grouped;
   2.194              }
   2.195  
   2.196 -            on Rollback if sameTransaction
   2.197 +            on Rollback if sameTransactionAndPartner
   2.198                  go Grouped;
   2.199  
   2.200              // Reject is CommitReject
   2.201 @@ -394,7 +392,7 @@
   2.202                  go Grouped;
   2.203              }
   2.204  
   2.205 -            on CommitReject if sameTransaction
   2.206 +            on CommitReject if sameTransactionAndPartner
   2.207                  go Grouped;
   2.208  
   2.209              // Accept is Phase1Commit
   2.210 @@ -405,7 +403,7 @@
   2.211                  go HandshakingGroupedPhase1;
   2.212              }
   2.213  
   2.214 -            on CommitAccept if sameTransaction
   2.215 +            on CommitAccept if sameTransactionAndPartner
   2.216                  go HandshakingGroupedPhase2;
   2.217  
   2.218              on GroupTrustThisKey {
   2.219 @@ -415,7 +413,7 @@
   2.220  
   2.221              on CommitAcceptForGroup {
   2.222                  do showDeviceAdded;
   2.223 -                if sameTransaction {
   2.224 +                if sameTransactionAndPartner {
   2.225                      do hideHandshakeDialog;
   2.226                      go Grouped;
   2.227                  }
   2.228 @@ -426,13 +424,13 @@
   2.229          }
   2.230  
   2.231          state HandshakingGroupedPhase1 {
   2.232 -            on Rollback if sameTransaction
   2.233 +            on Rollback if sameTransactionAndPartner
   2.234                  go Grouped;
   2.235  
   2.236 -            on CommitReject if sameTransaction
   2.237 +            on CommitReject if sameTransactionAndPartner
   2.238                  go Grouped;
   2.239  
   2.240 -            on CommitAccept if sameTransaction {
   2.241 +            on CommitAccept if sameTransactionAndPartner {
   2.242                  send GroupKeys;
   2.243                  go Grouped;
   2.244              }
   2.245 @@ -443,7 +441,7 @@
   2.246  
   2.247              on CommitAcceptForGroup {
   2.248                  do showDeviceAdded;
   2.249 -                if sameTransaction
   2.250 +                if sameTransactionAndPartner
   2.251                      go Grouped;
   2.252              }
   2.253  
   2.254 @@ -475,7 +473,7 @@
   2.255  
   2.256              on CommitAcceptForGroup {
   2.257                  do showDeviceAdded;
   2.258 -                if sameTransaction {
   2.259 +                if sameTransactionAndPartner {
   2.260                      do hideHandshakeDialog;
   2.261                      go Grouped;
   2.262                  }