slightly redesigning things
authorVolker Birk <vb@pep-project.org>
Thu, 02 Jun 2016 13:46:38 +0200
changeset 711d88dea0f5448
parent 692 6f7f1b7627bc
child 712 1719c03def17
slightly redesigning things
asn.1/devicegroup.asn1
src/sync_actions.c
src/sync_fsm.c
src/sync_fsm.h
sync/fsm.yml2
sync/gen_statemachine.ysl2
sync/sync.fsm
     1.1 --- a/asn.1/devicegroup.asn1	Sun May 29 14:35:39 2016 +0200
     1.2 +++ b/asn.1/devicegroup.asn1	Thu Jun 02 13:46:38 2016 +0200
     1.3 @@ -19,17 +19,19 @@
     1.4      partner Identity
     1.5  }
     1.6  
     1.7 -OwnKeys ::= SEQUENCE {
     1.8 +GroupKeys ::= SEQUENCE {
     1.9      header Header,
    1.10      state INTEGER,
    1.11      me Identity,
    1.12      keylist KeyList
    1.13  }
    1.14  
    1.15 +/* for the tags see end of sync.fsm */
    1.16 +
    1.17  DeviceGroup-Protocol ::= CHOICE {
    1.18      beacon [APPLICATION 1] Beacon,
    1.19      handshakeRequest [APPLICATION 2] HandshakeRequest,
    1.20 -    ownKeys [APPLICATION 3] OwnKeys
    1.21 +    groupKeys [APPLICATION 3] GroupKeys
    1.22  }
    1.23  
    1.24  END
     2.1 --- a/src/sync_actions.c	Sun May 29 14:35:39 2016 +0200
     2.2 +++ b/src/sync_actions.c	Thu Jun 02 13:46:38 2016 +0200
     2.3 @@ -9,7 +9,7 @@
     2.4  #include "map_asn1.h"
     2.5  #include "../asn.1/Beacon.h"
     2.6  #include "../asn.1/HandshakeRequest.h"
     2.7 -#include "../asn.1/OwnKeys.h"
     2.8 +#include "../asn.1/GroupKeys.h"
     2.9  
    2.10  
    2.11  // sendBeacon() - send Beacon message
    2.12 @@ -295,7 +295,7 @@
    2.13  }
    2.14  
    2.15  
    2.16 -// sendOwnKeys() - send OwnKeys message
    2.17 +// sendGroupKeys() - send GroupKeys message
    2.18  //
    2.19  //  params:
    2.20  //      session (in)        session handle
    2.21 @@ -305,14 +305,14 @@
    2.22  //  returns:
    2.23  //      PEP_STATUS_OK or any other value on error
    2.24  
    2.25 -PEP_STATUS sendOwnKeys(
    2.26 +PEP_STATUS sendGroupKeys(
    2.27          PEP_SESSION session,
    2.28          DeviceState_state state,
    2.29          const Identity partner
    2.30      )
    2.31  {
    2.32      PEP_STATUS status = PEP_STATUS_OK;
    2.33 -    OwnKeys_t *msg = NULL;
    2.34 +    GroupKeys_t *msg = NULL;
    2.35      char *payload = NULL;
    2.36      message *_message = NULL;
    2.37  
    2.38 @@ -325,7 +325,7 @@
    2.39      if (!session->messageToSend)
    2.40          return PEP_SEND_FUNCTION_NOT_REGISTERED;
    2.41  
    2.42 -    msg = (OwnKeys_t *) calloc(1, sizeof(OwnKeys_t));
    2.43 +    msg = (GroupKeys_t *) calloc(1, sizeof(GroupKeys_t));
    2.44      assert(msg);
    2.45      if (!msg)
    2.46          goto enomem;
    2.47 @@ -347,19 +347,12 @@
    2.48      if (Identity_from_Struct(me, &msg->me) == NULL)
    2.49          goto enomem;
    2.50  
    2.51 -    stringlist_t *sl;
    2.52 -    status = own_key_retrieve(session, &sl);
    2.53 -    if (status != PEP_STATUS_OK)
    2.54 -        goto error;
    2.55 -    if (KeyList_from_stringlist(sl, &msg->keylist) == NULL)
    2.56 -        goto enomem;
    2.57 -
    2.58 -    if (asn_check_constraints(&asn_DEF_OwnKeys, msg, NULL, NULL)) {
    2.59 +    if (asn_check_constraints(&asn_DEF_GroupKeys, msg, NULL, NULL)) {
    2.60          status = PEP_CONTRAINTS_VIOLATED;
    2.61          goto error;
    2.62      }
    2.63  
    2.64 -    ssize_t size = uper_encode_to_new_buffer(&asn_DEF_OwnKeys,
    2.65 +    ssize_t size = uper_encode_to_new_buffer(&asn_DEF_GroupKeys,
    2.66              NULL, msg, (void **) &payload);
    2.67      if (size == -1) {
    2.68          status = PEP_CANNOT_ENCODE;
    2.69 @@ -374,52 +367,16 @@
    2.70      status = session->messageToSend(session->sync_obj, _message);
    2.71  
    2.72      free_message(_message);
    2.73 -    ASN_STRUCT_FREE(asn_DEF_OwnKeys, msg);
    2.74 +    ASN_STRUCT_FREE(asn_DEF_GroupKeys, msg);
    2.75  
    2.76      return status;
    2.77  
    2.78  enomem:
    2.79      status = PEP_OUT_OF_MEMORY;
    2.80  error:
    2.81 -    ASN_STRUCT_FREE(asn_DEF_OwnKeys, msg);
    2.82 +    ASN_STRUCT_FREE(asn_DEF_GroupKeys, msg);
    2.83      free(payload);
    2.84      free_message(_message);
    2.85      return status;
    2.86  }
    2.87  
    2.88 -
    2.89 -// transmitGroupKeys() - 
    2.90 -//
    2.91 -//  params:
    2.92 -//      session (in)        session handle
    2.93 -//      state (in)          state the state machine is in
    2.94 -//      partner (in)        partner in sync
    2.95 -//
    2.96 -//  returns:
    2.97 -//      PEP_STATUS_OK or any other value on error
    2.98 -
    2.99 -PEP_STATUS transmitGroupKeys(
   2.100 -        PEP_SESSION session,
   2.101 -        DeviceState_state state,
   2.102 -        const Identity partner
   2.103 -    )
   2.104 -{
   2.105 -    PEP_STATUS status = PEP_STATUS_OK;
   2.106 -
   2.107 -    assert(session);
   2.108 -    assert(partner);
   2.109 -    if (!(session && partner))
   2.110 -        return PEP_ILLEGAL_VALUE;
   2.111 -
   2.112 -    // working code
   2.113 -
   2.114 -
   2.115 -    return status;
   2.116 -
   2.117 -enomem:
   2.118 -    status = PEP_OUT_OF_MEMORY;
   2.119 -error:
   2.120 -    // free...
   2.121 -    return status;
   2.122 -}
   2.123 -
     3.1 --- a/src/sync_fsm.c	Sun May 29 14:35:39 2016 +0200
     3.2 +++ b/src/sync_fsm.c	Thu Jun 02 13:46:38 2016 +0200
     3.3 @@ -56,7 +56,7 @@
     3.4      
     3.5      case WaitForGroupKeys:
     3.6          switch (event) {
     3.7 -            case ReceiveGroupKeys:
     3.8 +            case GroupKeys:
     3.9                  storeGroupKeys(session, state, partner);
    3.10                  return Grouped;
    3.11              case Cancel:
    3.12 @@ -72,7 +72,7 @@
    3.13      case Grouped:
    3.14          switch (event) {
    3.15              case KeyGen:
    3.16 -                sendOwnKeys(session, state, NULL);
    3.17 +                sendGroupKeys(session, state, NULL);
    3.18                  break;
    3.19              case HandshakeRequest:
    3.20                  sendHandshakeRequest(session, state, partner);
    3.21 @@ -82,7 +82,7 @@
    3.22                  reject(session, state, partner);
    3.23                  break;
    3.24              case HandshakeAccepted:
    3.25 -                transmitGroupKeys(session, state, partner);
    3.26 +                sendGroupKeys(session, state, partner);
    3.27                  break;
    3.28              case Reject:
    3.29                  reject(session, state, NULL);
     4.1 --- a/src/sync_fsm.h	Sun May 29 14:35:39 2016 +0200
     4.2 +++ b/src/sync_fsm.h	Thu Jun 02 13:46:38 2016 +0200
     4.3 @@ -35,14 +35,14 @@
     4.4  
     4.5  typedef enum _DeviceState_event {
     4.6      DeviceState_event_NONE = 0,
     4.7 +    Beacon = 1,
     4.8 +    HandshakeRequest = 2,
     4.9 +    GroupKeys = 3,
    4.10      Init, 
    4.11      KeyGen, 
    4.12      CannotDecrypt, 
    4.13 -    Beacon, 
    4.14 -    HandshakeRequest, 
    4.15      HandshakeRejected, 
    4.16      HandshakeAccepted, 
    4.17 -    ReceiveGroupKeys, 
    4.18      Cancel, 
    4.19      Reject
    4.20  } DeviceState_event;
    4.21 @@ -54,8 +54,7 @@
    4.22  PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, const Identity partner);
    4.23  PEP_STATUS reject(PEP_SESSION session, DeviceState_state state, const Identity partner);
    4.24  PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, const Identity partner);
    4.25 -PEP_STATUS sendOwnKeys(PEP_SESSION session, DeviceState_state state, const Identity partner);
    4.26 -PEP_STATUS transmitGroupKeys(PEP_SESSION session, DeviceState_state state, const Identity partner);
    4.27 +PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, const Identity partner);
    4.28  
    4.29  // state machine
    4.30  
     5.1 --- a/sync/fsm.yml2	Sun May 29 14:35:39 2016 +0200
     5.2 +++ b/sync/fsm.yml2	Thu Jun 02 13:46:38 2016 +0200
     5.3 @@ -12,3 +12,4 @@
     5.4  decl action @name, do is action;
     5.5  decl condition @flag, if is condition;
     5.6  decl interface @name;
     5.7 +decl tag @name (id);
     6.1 --- a/sync/gen_statemachine.ysl2	Sun May 29 14:35:39 2016 +0200
     6.2 +++ b/sync/gen_statemachine.ysl2	Thu Jun 02 13:46:38 2016 +0200
     6.3 @@ -10,7 +10,7 @@
     6.4      include ./functions.ysl2
     6.5  
     6.6      template "/protocol/fsm" {
     6.7 -        document "../src/sync_fsm.h", "text"
     6.8 +        document "../src/sync_fsm.h", "text" {
     6.9          ||
    6.10          #pragma once
    6.11  
    6.12 @@ -45,7 +45,14 @@
    6.13  
    6.14          typedef enum _«@name»_event {
    6.15              «@name»_event_NONE = 0,
    6.16 -        `` for "func:distinctName(state/event)" |> «@name»`if "position()!=last()" > , `
    6.17 +        ||
    6.18 +        for "func:distinctName(state/event[not(not(/protocol/fsm/tag/@name=@name))])" {
    6.19 +            const "name", "@name";
    6.20 +            |> «$name» = «/protocol/fsm/tag[@name=$name]/@id»,
    6.21 +        }
    6.22 +        for "func:distinctName(state/event[not(/protocol/fsm/tag/@name=@name)])"
    6.23 +            |> «@name»`if "position()!=last()" > , `
    6.24 +        ||
    6.25          } «@name»_event;
    6.26  
    6.27          // actions
    6.28 @@ -77,6 +84,7 @@
    6.29          #endif
    6.30  
    6.31          ||
    6.32 +        }
    6.33          document "../src/sync_driver.c", "text"
    6.34          ||
    6.35          // Driver for «@name» state machine
     7.1 --- a/sync/sync.fsm	Sun May 29 14:35:39 2016 +0200
     7.2 +++ b/sync/sync.fsm	Thu Jun 02 13:46:38 2016 +0200
     7.3 @@ -43,8 +43,8 @@
     7.4              on HandshakeAccepted(Identity partner) {
     7.5                  if keyElectionWon(partner) {    // an already existing group
     7.6                                                  // always wins
     7.7 -                    storeOwnKeysAsGroupKeys;
     7.8 -                    transmitGroupKeys(partner);
     7.9 +                    ownGroupKeys;
    7.10 +                    sendGroupKeys(partner);
    7.11                      go Grouped;
    7.12                  }
    7.13                  go WaitForGroupKeys(Identity partner);
    7.14 @@ -52,7 +52,7 @@
    7.15          }
    7.16      
    7.17          state WaitForGroupKeys(Identity partner) {
    7.18 -            on ReceiveGroupKeys(Identity partner, Stringlist keys) {
    7.19 +            on GroupKeys(Identity partner, Stringlist keys) {
    7.20                  do storeGroupKeys(partner, keys);
    7.21                  go Grouped;
    7.22              }
    7.23 @@ -65,7 +65,7 @@
    7.24  
    7.25          state Grouped {
    7.26              on KeyGen
    7.27 -                do sendOwnKeys; // always send all keys
    7.28 +                do sendGroupKeys; // always send all keys
    7.29              on HandshakeRequest(Identity partner) {
    7.30                  do sendHandshakeRequest(partner);
    7.31                  do showHandshake(partner);
    7.32 @@ -73,18 +73,14 @@
    7.33              on HandshakeRejected(Identity partner)
    7.34                  do reject(partner);
    7.35              on HandshakeAccepted(Identity partner)
    7.36 -                do transmitGroupKeys(partner);
    7.37 +                do sendGroupKeys(partner);
    7.38              on Reject(Identity partner)
    7.39                  do reject partner;
    7.40          }
    7.41 -    }
    7.42  
    7.43 -    interface commons {
    7.44 -        Header head;
    7.45 -    }
    7.46 -
    7.47 -    interface OwnKeys {
    7.48 -        Stringlist ownKeys;
    7.49 +        tag Beacon 1;
    7.50 +        tag HandshakeRequest 2;
    7.51 +        tag GroupKeys 3;
    7.52      }
    7.53  }
    7.54