Sync message decrypt rating could't be evaluated properly without knowing peer's user_id, itslef encoded inside the encrypted blob. Peer identity rating is then re-evaluated after unpacking. keysync
authorEdouard Tisserant <edouard@pep-project.org>
Sun, 18 Sep 2016 16:55:53 +0200
branchkeysync
changeset 116505c831cfab65
parent 1163 5d54f358c636
child 1166 f128fb9fe444
Sync message decrypt rating could't be evaluated properly without knowing peer's user_id, itslef encoded inside the encrypted blob. Peer identity rating is then re-evaluated after unpacking.
src/message_api.c
src/sync_fsm.h
src/sync_impl.c
src/sync_impl.h
sync/gen_statemachine.ysl2
     1.1 --- a/src/message_api.c	Wed Sep 14 19:53:04 2016 +0200
     1.2 +++ b/src/message_api.c	Sun Sep 18 16:55:53 2016 +0200
     1.3 @@ -1406,7 +1406,7 @@
     1.4              if (imported_keys)
     1.5                  remove_attached_keys(src);
     1.6              if (session->retrieve_next_sync_msg) {
     1.7 -                status = receive_DeviceState_msg(session, src, *rating);
     1.8 +                status = receive_DeviceState_msg(session, src, *rating, *keylist);
     1.9                  if (status == PEP_MESSAGE_CONSUMED) {
    1.10                      free_message(msg);
    1.11                      msg = NULL;
    1.12 @@ -1681,7 +1681,7 @@
    1.13          if (imported_keys)
    1.14              remove_attached_keys(msg);
    1.15          if (*rating >= PEP_rating_reliable && session->retrieve_next_sync_msg) {
    1.16 -            status = receive_DeviceState_msg(session, msg, *rating);
    1.17 +            status = receive_DeviceState_msg(session, msg, *rating, _keylist);
    1.18              if (status == PEP_MESSAGE_CONSUMED) {
    1.19                  free_message(msg);
    1.20                  msg = NULL;
     2.1 --- a/src/sync_fsm.h	Wed Sep 14 19:53:04 2016 +0200
     2.2 +++ b/src/sync_fsm.h	Sun Sep 18 16:55:53 2016 +0200
     2.3 @@ -79,7 +79,12 @@
     2.4  
     2.5  // message receiver
     2.6  
     2.7 -PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, message *msg, PEP_rating rating);
     2.8 +PEP_STATUS receive_DeviceState_msg(
     2.9 +        PEP_SESSION session, 
    2.10 +        message *src, 
    2.11 +        PEP_rating rating, 
    2.12 +        stringlist_t *keylist
    2.13 +    );
    2.14  
    2.15  // state machine
    2.16  
     3.1 --- a/src/sync_impl.c	Wed Sep 14 19:53:04 2016 +0200
     3.2 +++ b/src/sync_impl.c	Sun Sep 18 16:55:53 2016 +0200
     3.3 @@ -62,7 +62,11 @@
     3.4      return status;
     3.5  }
     3.6  
     3.7 -PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, message *src, PEP_rating rating)
     3.8 +PEP_STATUS receive_DeviceState_msg(
     3.9 +    PEP_SESSION session, 
    3.10 +    message *src, 
    3.11 +    PEP_rating rating, 
    3.12 +    stringlist_t *keylist)
    3.13  {
    3.14      assert(session && src);
    3.15      if (!(session && src))
    3.16 @@ -82,26 +86,6 @@
    3.17              uper_decode_complete(NULL, &asn_DEF_DeviceGroup_Protocol, (void **)
    3.18                      &msg, bl->value, bl->size);
    3.19              if (msg) {
    3.20 -                switch (msg->payload.present) {
    3.21 -                    // HandshakeRequest needs encryption
    3.22 -                    case DeviceGroup_Protocol__payload_PR_handshakeRequest:
    3.23 -                        if (rating < PEP_rating_reliable) {
    3.24 -                            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    3.25 -                            goto skip;
    3.26 -                        }
    3.27 -                        break;
    3.28 -                    // accepting GroupKeys needs trust
    3.29 -                    case DeviceGroup_Protocol__payload_PR_groupKeys:
    3.30 -                        if (rating < PEP_rating_trusted) {
    3.31 -                            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    3.32 -                            goto skip;
    3.33 -                        }
    3.34 -                        break;
    3.35 -                    default:
    3.36 -                        break;
    3.37 -                }
    3.38 -
    3.39 -                found = true;
    3.40  
    3.41                  int32_t value = (int32_t) msg->header.sequence;
    3.42                  char *user_id = strndup((char *) msg->header.me.user_id->buf,
    3.43 @@ -112,14 +96,61 @@
    3.44                      return PEP_OUT_OF_MEMORY;
    3.45                  }
    3.46  
    3.47 +                switch (msg->payload.present) {
    3.48 +                    // HandshakeRequest needs encryption
    3.49 +                    case DeviceGroup_Protocol__payload_PR_handshakeRequest:
    3.50 +                        if (rating < PEP_rating_reliable) {
    3.51 +                            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    3.52 +                            free(user_id);
    3.53 +                            goto skip;
    3.54 +                        }
    3.55 +                        break;
    3.56 +                    // accepting GroupKeys needs encryption and trust
    3.57 +                    case DeviceGroup_Protocol__payload_PR_groupKeys:
    3.58 +                        if (!keylist || rating < PEP_rating_reliable) {
    3.59 +                            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    3.60 +                            free(user_id);
    3.61 +                            goto skip;
    3.62 +                        }
    3.63 +
    3.64 +                        // check trust of identity with the right user_id
    3.65 +                        pEp_identity *_from = new_identity(src->from->address, 
    3.66 +                                                           keylist->value,
    3.67 +                                                           user_id,
    3.68 +                                                           src->from->username);
    3.69 +                        if (_from == NULL){
    3.70 +                            free(user_id);
    3.71 +                            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    3.72 +                            return PEP_OUT_OF_MEMORY;
    3.73 +                        }
    3.74 +                        PEP_rating this_user_id_rating = PEP_rating_undefined;
    3.75 +                        identity_rating(session, _from, &this_user_id_rating);
    3.76 +                        free_identity(_from);
    3.77 +
    3.78 +                        if (this_user_id_rating < PEP_rating_trusted ) {
    3.79 +                            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    3.80 +                            free(user_id);
    3.81 +                            goto skip;
    3.82 +                        }
    3.83 +                        break;
    3.84 +                    default:
    3.85 +                        break;
    3.86 +                }
    3.87 +
    3.88 +
    3.89                  PEP_STATUS status = sequence_value(session, (char *) user_id,
    3.90                          &value);
    3.91  
    3.92                  if (status == PEP_STATUS_OK) {
    3.93 +                    found = true;
    3.94                      status = session->inject_sync_msg(msg, session->sync_obj);
    3.95                      ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    3.96 -                    if (status != PEP_STATUS_OK)
    3.97 +                    if (status != PEP_STATUS_OK){
    3.98                          return status;
    3.99 +                    }
   3.100 +                }
   3.101 +                else if (status == PEP_OWN_SEQUENCE) {
   3.102 +                    goto skip;
   3.103                  }
   3.104              }
   3.105  
     4.1 --- a/src/sync_impl.h	Wed Sep 14 19:53:04 2016 +0200
     4.2 +++ b/src/sync_impl.h	Sun Sep 18 16:55:53 2016 +0200
     4.3 @@ -12,8 +12,11 @@
     4.4          DeviceGroup_Protocol_t *msg
     4.5      );
     4.6  
     4.7 -PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, message *src,
     4.8 -        PEP_rating rating);
     4.9 +PEP_STATUS receive_DeviceState_msg(
    4.10 +    PEP_SESSION session, 
    4.11 +    message *src, 
    4.12 +    PEP_rating rating, 
    4.13 +    stringlist_t *keylist);
    4.14  
    4.15  DeviceGroup_Protocol_t *new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR type);
    4.16  void free_DeviceGroup_Protocol_msg(DeviceGroup_Protocol_t *msg);
     5.1 --- a/sync/gen_statemachine.ysl2	Wed Sep 14 19:53:04 2016 +0200
     5.2 +++ b/sync/gen_statemachine.ysl2	Sun Sep 18 16:55:53 2016 +0200
     5.3 @@ -93,7 +93,12 @@
     5.4  
     5.5          // message receiver
     5.6          
     5.7 -        PEP_STATUS receive_«@name»_msg(PEP_SESSION session, message *msg, PEP_rating rating);
     5.8 +        PEP_STATUS receive_DeviceState_msg(
     5.9 +                PEP_SESSION session, 
    5.10 +                message *src, 
    5.11 +                PEP_rating rating, 
    5.12 +                stringlist_t *keylist
    5.13 +            );
    5.14  
    5.15          // state machine
    5.16