test for encryption and trust when receiving messages sync
authorVolker Birk <vb@pep.foundation>
Thu, 23 Aug 2018 20:40:37 +0200
branchsync
changeset 289093370e9026b1
parent 2889 683eba0e3d81
child 2891 adf0103397e4
test for encryption and trust when receiving messages
sync/gen_statemachine.ysl2
     1.1 --- a/sync/gen_statemachine.ysl2	Thu Aug 23 18:13:34 2018 +0200
     1.2 +++ b/sync/gen_statemachine.ysl2	Thu Aug 23 20:40:37 2018 +0200
     1.3 @@ -299,7 +299,16 @@
     1.4                  if (status)
     1.5                      return status;
     1.6  
     1.7 -                «@name»_event_t *ev = new_«@name»_event(None, None, msg);
     1.8 +                «@name»_event_t *ev = NULL;
     1.9 +
    1.10 +                switch (msg->present) {
    1.11 +                    `` apply "fsm", 2, mode=signal_message
    1.12 +                    default:
    1.13 +                        status = PEP_«yml:ucase(@name)»_ILLEGAL_MESSAGE;
    1.14 +                        goto the_end;
    1.15 +                }
    1.16 +
    1.17 +                ev = new_«@name»_event(None, None, msg);
    1.18                  if (!ev) {
    1.19                      status = PEP_OUT_OF_MEMORY;
    1.20                      goto the_end;
    1.21 @@ -489,6 +498,40 @@
    1.22          apply "fsm", 0, mode=gen;
    1.23      }
    1.24  
    1.25 +    template "fsm", mode=signal_message
    1.26 +    {
    1.27 +        ||
    1.28 +        case «../@name»_PR_«yml:lcase(@name)»:
    1.29 +            switch (msg->choice.«yml:lcase(@name)».payload.present) {
    1.30 +                // these messages are going untested
    1.31 +        `` for "message[@security='unencrypted']" |>> case «../@name»__payload_PR_«yml:mixedCase(@name)»:
    1.32 +                    break;
    1.33 +
    1.34 +                // these messages must arrive encrypted
    1.35 +        `` for "message[@security='untrusted']" |>> case «../@name»__payload_PR_«yml:mixedCase(@name)»:
    1.36 +                    if (rating < PEP_rating_reliable) {
    1.37 +                        status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;
    1.38 +                        goto the_end;
    1.39 +                    }
    1.40 +                    break;
    1.41 +
    1.42 +                // these messages must come through a trusted channel
    1.43 +        `` for "message[@security='trusted']" |>> case «ancestor::fsm/@name»__payload_PR_«yml:mixedCase(@name)»:
    1.44 +                    if (rating < PEP_rating_trusted) {
    1.45 +                        status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;
    1.46 +                        goto the_end;
    1.47 +                    }
    1.48 +                    break;
    1.49 +
    1.50 +                default:
    1.51 +                    status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;
    1.52 +                    goto the_end;
    1.53 +            }
    1.54 +            break;
    1.55 +
    1.56 +        ||
    1.57 +    }
    1.58 +
    1.59      template "fsm", mode=event
    1.60      {
    1.61      ||