renaming things sync
authorVolker Birk <vb@pep-project.org>
Wed, 29 May 2019 17:37:01 +0200
branchsync
changeset 3773874ce1a8837a
parent 3772 f4d6efa63ee1
child 3774 8632ec1f3ae1
renaming things
sync/cond_act_sync.yml2
sync/gen_message_func.ysl2
sync/gen_statemachine.ysl2
     1.1 --- a/sync/cond_act_sync.yml2	Wed May 29 16:34:12 2019 +0200
     1.2 +++ b/sync/cond_act_sync.yml2	Wed May 29 17:37:01 2019 +0200
     1.3 @@ -20,18 +20,18 @@
     1.4  
     1.5  condition weAreFirst
     1.6  ||
     1.7 -    TID_t *t1 = &session->sync_state.keysync_buf.challenge;
     1.8 +    TID_t *t1 = &session->sync_state.keysync.challenge;
     1.9      TID_t *t2 = &session->sync_state.own.challenge;
    1.10  
    1.11      *result = _TID_greater(t1, t2);
    1.12  ||
    1.13  
    1.14  condition partnerIsGrouped
    1.15 -|> *result = session->sync_state.keysync_buf.is_group;
    1.16 +|> *result = session->sync_state.keysync.is_group;
    1.17  
    1.18  condition challengeAccepted
    1.19  ||
    1.20 -    TID_t *t1 = &session->sync_state.keysync_buf.challenge;
    1.21 +    TID_t *t1 = &session->sync_state.keysync.challenge;
    1.22      TID_t *t2 = &session->sync_state.own.challenge;
    1.23  
    1.24      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    1.25 @@ -39,7 +39,7 @@
    1.26  
    1.27  condition sameChallenge
    1.28  ||
    1.29 -    TID_t *t1 = &session->sync_state.keysync_buf.challenge;
    1.30 +    TID_t *t1 = &session->sync_state.keysync.challenge;
    1.31      TID_t *t2 = &session->sync_state.own.challenge;
    1.32  
    1.33      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    1.34 @@ -47,7 +47,7 @@
    1.35  
    1.36  condition sameTransaction
    1.37  ||
    1.38 -    TID_t *t1 = &session->sync_state.keysync_buf.negotiation;
    1.39 +    TID_t *t1 = &session->sync_state.keysync.negotiation;
    1.40      TID_t *t2 = &session->sync_state.own.negotiation;
    1.41  
    1.42      // test if TID is identical
    1.43 @@ -56,11 +56,11 @@
    1.44  
    1.45  condition sameTransactionAndPartner
    1.46  ||
    1.47 -    TID_t *t1 = &session->sync_state.keysync_buf.negotiation;
    1.48 +    TID_t *t1 = &session->sync_state.keysync.negotiation;
    1.49      TID_t *t2 = &session->sync_state.own.negotiation;
    1.50  
    1.51      const char *s1 = session->sync_state.comm_partner.signature_fpr;
    1.52 -    const char *s2 = session->sync_state.own.signature_fpr;
    1.53 +    const char *s2 = session->sync_state.transport.signature_fpr;
    1.54  
    1.55      // test if TID is identical
    1.56      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0
    1.57 @@ -147,45 +147,50 @@
    1.58  }
    1.59  
    1.60  action replyChallenge call "copy_UUID" {
    1.61 -    with "src" > &session->sync_state.keysync_buf.challenge
    1.62 +    with "src" > &session->sync_state.keysync.challenge
    1.63      with "dst" > &session->sync_state.comm_partner.challenge
    1.64  }
    1.65  
    1.66  action useOwnChallenge call "copy_UUID" {
    1.67      with "src" > &session->sync_state.own.challenge
    1.68 -    with "dst" > &session->sync_state.keysync_buf.challenge
    1.69 +    with "dst" > &session->sync_state.keysync.challenge
    1.70  }
    1.71  
    1.72  action newTransaction {
    1.73  ||
    1.74      // sender key must be stable while transaction
    1.75 +
    1.76 +    // we take the actual signature of the last message and store it in our
    1.77 +    // state for the comm partner
    1.78 +    assert(session->sync_state.transport.signature_fpr);
    1.79 +
    1.80 +    free(session->sync_state.comm_partner.signature_fpr);
    1.81 +
    1.82 +    session->sync_state.comm_partner.signature_fpr
    1.83 +            = strdup(session->sync_state.transport.signature_fpr);
    1.84      assert(session->sync_state.comm_partner.signature_fpr);
    1.85 -    free(session->sync_state.own.signature_fpr);
    1.86 -    session->sync_state.own.signature_fpr
    1.87 -            = strdup(session->sync_state.comm_partner.signature_fpr);
    1.88 -    assert(session->sync_state.own.signature_fpr);
    1.89 -    if (!session->sync_state.own.signature_fpr)
    1.90 +    if (!session->sync_state.comm_partner.signature_fpr)
    1.91          return PEP_OUT_OF_MEMORY;
    1.92  
    1.93  ||
    1.94      call "copy_UUID" {
    1.95 -        with "src" > &session->sync_state.keysync_buf.challenge
    1.96 -        with "dst" > &session->sync_state.keysync_buf.negotiation
    1.97 +        with "src" > &session->sync_state.keysync.challenge
    1.98 +        with "dst" > &session->sync_state.keysync.negotiation
    1.99      }
   1.100      call "xor_UUID" {
   1.101          with "src" > &session->sync_state.own.challenge
   1.102 -        with "dst" > &session->sync_state.keysync_buf.negotiation
   1.103 +        with "dst" > &session->sync_state.keysync.negotiation
   1.104      }
   1.105      call "copy_UUID" {
   1.106 -        with "src" > &session->sync_state.keysync_buf.negotiation
   1.107 +        with "src" > &session->sync_state.keysync.negotiation
   1.108          with "dst" > &session->sync_state.own.negotiation
   1.109      }
   1.110  }
   1.111  
   1.112  action closeTransaction
   1.113  ||
   1.114 -    memset(session->sync_state.keysync_buf.negotiation.buf, 0,
   1.115 -            session->sync_state.keysync_buf.negotiation.size);
   1.116 +    memset(session->sync_state.keysync.negotiation.buf, 0,
   1.117 +            session->sync_state.keysync.negotiation.size);
   1.118      memset(session->sync_state.own.negotiation.buf, 0,
   1.119              session->sync_state.own.negotiation.size);
   1.120  ||
   1.121 @@ -193,17 +198,22 @@
   1.122  action storeTransaction {
   1.123  ||
   1.124      // sender key must be stable while transaction
   1.125 +
   1.126 +    // we take the actual signature of the last message and store it in our
   1.127 +    // state for the comm partner
   1.128 +    assert(session->sync_state.transport.signature_fpr);
   1.129 +
   1.130 +    free(session->sync_state.comm_partner.signature_fpr);
   1.131 +
   1.132 +    session->sync_state.comm_partner.signature_fpr
   1.133 +            = strdup(session->sync_state.transport.signature_fpr);
   1.134      assert(session->sync_state.comm_partner.signature_fpr);
   1.135 -    free(session->sync_state.own.signature_fpr);
   1.136 -    session->sync_state.own.signature_fpr
   1.137 -            = strdup(session->sync_state.comm_partner.signature_fpr);
   1.138 -    assert(session->sync_state.own.signature_fpr);
   1.139 -    if (!session->sync_state.own.signature_fpr)
   1.140 +    if (!session->sync_state.comm_partner.signature_fpr)
   1.141          return PEP_OUT_OF_MEMORY;
   1.142  
   1.143  ||
   1.144      call "copy_UUID" {
   1.145 -        with "src" > &session->sync_state.keysync_buf.negotiation
   1.146 +        with "src" > &session->sync_state.keysync.negotiation
   1.147          with "dst" > &session->sync_state.own.negotiation
   1.148      }
   1.149  }
   1.150 @@ -327,13 +337,13 @@
   1.151      if (status)
   1.152          return status;
   1.153  
   1.154 -    IdentityList_from_identity_list(il, &session->sync_state.keysync_buf.ownIdentities);
   1.155 +    IdentityList_from_identity_list(il, &session->sync_state.keysync.ownIdentities);
   1.156      free_identity_list(il);
   1.157  ||
   1.158  
   1.159  action saveGroupKeys
   1.160  ||
   1.161 -    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync_buf.ownIdentities, NULL);
   1.162 +    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
   1.163      if (!il)
   1.164          return PEP_OUT_OF_MEMORY;
   1.165      
   1.166 @@ -376,7 +386,7 @@
   1.167          }
   1.168      }
   1.169  
   1.170 -    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync_buf.ownIdentities, NULL);
   1.171 +    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
   1.172      if (!il)
   1.173          return PEP_OUT_OF_MEMORY;
   1.174  
   1.175 @@ -428,7 +438,7 @@
   1.176          return status;
   1.177      }
   1.178  
   1.179 -    OCTET_STRING_fromBuf(&session->sync_state.keysync_buf.key, ident->fpr, strlen(ident->fpr));
   1.180 +    OCTET_STRING_fromBuf(&session->sync_state.keysync.key, ident->fpr, strlen(ident->fpr));
   1.181      free_identity(ident);
   1.182  ||
   1.183  
   1.184 @@ -449,17 +459,17 @@
   1.185      if (status)
   1.186          return status;
   1.187  
   1.188 -    OCTET_STRING_fromBuf(&session->sync_state.keysync_buf.key, "", 0);
   1.189 +    OCTET_STRING_fromBuf(&session->sync_state.keysync.key, "", 0);
   1.190  ||
   1.191  
   1.192  action tellWeAreGrouped
   1.193  ||
   1.194 -    session->sync_state.keysync_buf.is_group = true;
   1.195 +    session->sync_state.keysync.is_group = true;
   1.196  ||
   1.197  
   1.198  action tellWeAreNotGrouped
   1.199  ||
   1.200 -    session->sync_state.keysync_buf.is_group = false;
   1.201 +    session->sync_state.keysync.is_group = false;
   1.202  ||
   1.203  
   1.204  action disable;
     2.1 --- a/sync/gen_message_func.ysl2	Wed May 29 16:34:12 2019 +0200
     2.2 +++ b/sync/gen_message_func.ysl2	Wed May 29 17:37:01 2019 +0200
     2.3 @@ -45,7 +45,7 @@
     2.4          stringlist_t *keys;
     2.5          identity_list *identities;
     2.6  
     2.7 -        `` if "func:distinctName(fsm/message/field[@type='TID'])" |>> // TIDs we're using ourselves
     2.8 +        // TIDs we're using ourselves
     2.9          `` for "func:distinctName(fsm/message/field[@type='TID'])" |>> «func:ctype()» «@name»;
    2.10      } own;
    2.11  
    2.12 @@ -57,7 +57,7 @@
    2.13          char *signature_fpr;
    2.14  
    2.15          // TIDs our comm partner wants to have
    2.16 -        TID_t challenge;
    2.17 +        `` for "func:distinctName(fsm/message/field[@type='TID'])" |>> «func:ctype()» «@name»;
    2.18      } comm_partner;
    2.19  
    2.20      // buffer for actual transport data coming in
    2.21 @@ -66,7 +66,7 @@
    2.22          // transport data we got
    2.23          pEp_identity *from;
    2.24          char *signature_fpr;
    2.25 -    } transport_buf;
    2.26 +    } transport;
    2.27      `` apply "fsm", mode=state
    2.28  };
    2.29  
    2.30 @@ -97,7 +97,7 @@
    2.31      int state;
    2.32  
    2.33      `` for "func:distinctName(message/field)" |> «func:ctype()» «@name»;
    2.34 -} «yml:lcase(@name)»_buf;
    2.35 +} «yml:lcase(@name)»;
    2.36  ||
    2.37  
    2.38  template "protocol", mode=impl
    2.39 @@ -118,21 +118,48 @@
    2.40      if (!session)
    2.41          return;
    2.42  
    2.43 +    // own state
    2.44 +
    2.45 +    free_stringlist(session->«yml:lcase(@name)»_state.own.keys);
    2.46 +    session->«yml:lcase(@name)»_state.own.keys = NULL;
    2.47 +    free_identity_list(session->«yml:lcase(@name)»_state.own.identities);
    2.48 +    session->«yml:lcase(@name)»_state.own.identities = NULL;
    2.49 +
    2.50 +    // TIDs we're using ourselves
    2.51 +||
    2.52 +    for "func:distinctName(fsm/message/field[@type='TID'])"
    2.53 +        |> ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_«@type», &session->«yml:lcase(../../../@name)»_state.own.«@name»);
    2.54 +||
    2.55 +
    2.56 +    // state we learned about our communication partner
    2.57 +
    2.58      free_identity(session->«yml:lcase(@name)»_state.comm_partner.from);
    2.59 +    session->«yml:lcase(@name)»_state.comm_partner.from = NULL;
    2.60      free(session->«yml:lcase(@name)»_state.comm_partner.signature_fpr);
    2.61 -    free_stringlist(session->own_«yml:lcase(@name)»_state.own_keys);
    2.62 -    free_identity_list(session->own_«yml:lcase(@name)»_state.own_identities);
    2.63 -    session->own_«yml:lcase(@name)»_state.own_keys = NULL;
    2.64 -    session->own_«yml:lcase(@name)»_state.own_identities = NULL;
    2.65 +    session->«yml:lcase(@name)»_state.comm_partner.signature_fpr = NULL;
    2.66 +
    2.67 +    // TIDs our comm partner wants to have
    2.68 +||
    2.69 +    for "func:distinctName(fsm/message/field[@type='TID'])"
    2.70 +        |> ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_«@type», &session->«yml:lcase(../../../@name)»_state.comm_partner.«@name»);
    2.71 +||
    2.72 +
    2.73 +    // buffer for transport data
    2.74 +
    2.75 +    free_identity(session->«yml:lcase(@name)»_state.transport.from);
    2.76 +    session->«yml:lcase(@name)»_state.transport.from = NULL;
    2.77 +    free(session->«yml:lcase(@name)»_state.transport.signature_fpr);
    2.78 +    session->«yml:lcase(@name)»_state.transport.signature_fpr = NULL;
    2.79 +
    2.80 +    // message buffers
    2.81  
    2.82  ||
    2.83 -for "fsm"
    2.84 -    for "func:distinctName(message/field[not(func:basicType())])"
    2.85 -        |> ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_«@type», &session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name»);
    2.86 -for "func:distinctName(fsm/message/field[@type='TID'])"
    2.87 -    |> ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_«@type», &session->own_«yml:lcase(../../../@name)»_state.«@name»);
    2.88 +    for "fsm" {
    2.89 +        for "func:distinctName(message/field[not(substring(@type,1,1)=yml:lcase(substring(@type,1,1)))])"
    2.90 +            |> ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_«@type», &session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name»);
    2.91 +        |
    2.92 +    }
    2.93  ||
    2.94 -
    2.95      memset(&session->«yml:lcase(@name)»_state, 0, sizeof(session->«yml:lcase(@name)»_state));
    2.96  }
    2.97  
    2.98 @@ -266,7 +293,7 @@
    2.99      const "message_name", "yml:mixedCase(../@name)";
   2.100      const "state" choose {
   2.101          when "@type='TID'"
   2.102 -            > own_«yml:lcase(ancestor::protocol/@name)»_state
   2.103 +            > «yml:lcase(ancestor::protocol/@name)»_state.own
   2.104          otherwise
   2.105              > «yml:lcase(ancestor::protocol/@name)»_state.«yml:lcase(ancestor::fsm/@name)»
   2.106      }
     3.1 --- a/sync/gen_statemachine.ysl2	Wed May 29 16:34:12 2019 +0200
     3.2 +++ b/sync/gen_statemachine.ysl2	Wed May 29 17:37:01 2019 +0200
     3.3 @@ -556,11 +556,11 @@
     3.4                              break;
     3.5  
     3.6                      `` for "fsm/message[@security='attach_own_keys']" |>>> case «../@name»_PR_«yml:mixedCase(@name)»:
     3.7 -                            // check if this is the key of a former negotiation
     3.8 +                            // check if we had a former negotiation
     3.9  
    3.10                              transaction = false;
    3.11 -                            for (int i=0; i < session->own_«yml:lcase(@name)»_state.negotiation.size; i++) {
    3.12 -                                if (session->own_«yml:lcase(@name)»_state.negotiation.buf[i]) {
    3.13 +                            for (int i=0; i < session->«yml:lcase(@name)»_state.own.negotiation.size; i++) {
    3.14 +                                if (session->«yml:lcase(@name)»_state.own.negotiation.buf[i]) {
    3.15                                      transaction = true;
    3.16                                      break;
    3.17                                  }
    3.18 @@ -573,10 +573,10 @@
    3.19                              // secret keys
    3.20  
    3.21                              if (transaction) {
    3.22 -                                assert(session->own_«yml:lcase(@name)»_state.signature_fpr &&
    3.23 +                                assert(session->«yml:lcase(@name)»_state.comm_partner.signature_fpr &&
    3.24                                      session->«yml:lcase(@name)»_state.comm_partner.from &&
    3.25                                      session->«yml:lcase(@name)»_state.comm_partner.from->user_id);
    3.26 -                                if (!(session->own_«yml:lcase(@name)»_state.signature_fpr &&
    3.27 +                                if (!(session->«yml:lcase(@name)»_state.comm_partner.signature_fpr &&
    3.28                                          session->«yml:lcase(@name)»_state.comm_partner.from &&
    3.29                                          session->«yml:lcase(@name)»_state.comm_partner.from->user_id))
    3.30                                  {
    3.31 @@ -587,7 +587,7 @@
    3.32                                  // test if this is a green channel
    3.33  
    3.34                                  pEp_identity *ident = new_identity(NULL,
    3.35 -                                        session->own_«yml:lcase(@name)»_state.signature_fpr,
    3.36 +                                        session->«yml:lcase(@name)»_state.comm_partner.signature_fpr,
    3.37                                          session->«yml:lcase(@name)»_state.comm_partner.from->user_id,
    3.38                                          NULL
    3.39                                      );
    3.40 @@ -612,7 +612,7 @@
    3.41  
    3.42                                  bool is_own_key = false;
    3.43                                  status = own_key_is_listed(session,
    3.44 -                                        session->own_«yml:lcase(@name)»_state.signature_fpr,
    3.45 +                                        session->«yml:lcase(@name)»_state.comm_partner.signature_fpr,
    3.46                                          &is_own_key);
    3.47                                  assert(!status);
    3.48                                  if (status)
    3.49 @@ -625,7 +625,7 @@
    3.50  
    3.51                                  // if so add key of comm partner to extra keys
    3.52  
    3.53 -                                extra = new_stringlist(session->own_«yml:lcase(@name)»_state.signature_fpr);
    3.54 +                                extra = new_stringlist(session->«yml:lcase(@name)»_state.comm_partner.signature_fpr);
    3.55                                  if (!extra) {
    3.56                                      status = PEP_OUT_OF_MEMORY;
    3.57                                      goto the_end;
    3.58 @@ -660,7 +660,7 @@
    3.59                                                 // if we include this in the size, libetpan will null terminate and 
    3.60                                                 // go bananas. We can't have a NUL in the mime text.
    3.61  
    3.62 -                            for (stringlist_t *sl = session->own_«yml:lcase(@name)»_state.own_keys;
    3.63 +                            for (stringlist_t *sl = session->«yml:lcase(@name)»_state.own.keys;
    3.64                                      sl && sl->value ; sl = sl->next)
    3.65                              {
    3.66                                  char *_key_data = NULL;
    3.67 @@ -822,8 +822,8 @@
    3.68                  // update own identities
    3.69  
    3.70                  if (ev->own_identities && ev->own_identities->ident) {
    3.71 -                    free_identity_list(session->own_«yml:lcase(@name)»_state.own_identities);
    3.72 -                    session->own_«yml:lcase(@name)»_state.own_identities = ev->own_identities;
    3.73 +                    free_identity_list(session->«yml:lcase(@name)»_state.own.identities);
    3.74 +                    session->«yml:lcase(@name)»_state.own.identities = ev->own_identities;
    3.75                      ev->own_identities = NULL;
    3.76                  }
    3.77