KeySync: moved some code, added some comments, fixed some maybe-bug in still untested groupMerge scenario. Preparing for having all devices in a group to show handshake dialog AllGroupDevicesShowHandshake
authorEdouard Tisserant <edouard@pep-project.org>
Wed, 01 Mar 2017 15:08:55 +0100
branchAllGroupDevicesShowHandshake
changeset 160554bb3990a70f
parent 1604 a39c90afab13
child 1606 c3f8396acee4
KeySync: moved some code, added some comments, fixed some maybe-bug in still untested groupMerge scenario. Preparing for having all devices in a group to show handshake dialog
asn.1/devicegroup.asn1
src/sync_impl.c
     1.1 --- a/asn.1/devicegroup.asn1	Mon Feb 27 15:28:20 2017 +0100
     1.2 +++ b/asn.1/devicegroup.asn1	Wed Mar 01 15:08:55 2017 +0100
     1.3 @@ -14,12 +14,16 @@
     1.4  Beacon ::= NULL
     1.5  
     1.6  HandshakeRequest ::= SEQUENCE {
     1.7 +    /* UUID of receiver, group UUID if grouped */
     1.8      partner-id     UTF8String  (SIZE(1..1024)) OPTIONAL,
     1.9 +    /* Group UUID of sender, if grouped */
    1.10      group-id       UTF8String  (SIZE(1..1024)) OPTIONAL
    1.11  }
    1.12  
    1.13  GroupKeys ::= SEQUENCE {
    1.14 +    /* UUID of receiver */
    1.15      partner-id     UTF8String  (SIZE(1..1024)) OPTIONAL,
    1.16 +    /* Group UUID of sender */
    1.17      group-id       UTF8String  (SIZE(1..1024)) OPTIONAL,
    1.18      ownIdentities IdentityList
    1.19  }
     2.1 --- a/src/sync_impl.c	Mon Feb 27 15:28:20 2017 +0100
     2.2 +++ b/src/sync_impl.c	Wed Mar 01 15:08:55 2017 +0100
     2.3 @@ -31,6 +31,25 @@
     2.4      } u;
     2.5  };
     2.6  
     2.7 +static bool _is_own_uuid( PEP_SESSION session, UTF8String_t *uuid)
     2.8 +{
     2.9 +    return strncmp(session->sync_session->sync_uuid,
    2.10 +                   (const char*)uuid->buf, uuid->size) != 0;
    2.11 +}
    2.12 +
    2.13 +static bool _is_own_group_uuid( PEP_SESSION session, UTF8String_t *uuid)
    2.14 +{
    2.15 +    PEP_STATUS status;
    2.16 +    char *devgrp = NULL;
    2.17 +
    2.18 +    status = get_device_group(session, &devgrp);
    2.19 +
    2.20 +    bool res = (status == PEP_STATUS_OK && devgrp && devgrp[0] &&
    2.21 +        strncmp(devgrp,(const char*)uuid->buf, uuid->size) == 0);
    2.22 +    free(devgrp);
    2.23 +    return res;
    2.24 +}
    2.25 +
    2.26  PEP_STATUS receive_sync_msg(
    2.27          PEP_SESSION session,
    2.28          sync_msg_t *sync_msg,
    2.29 @@ -54,6 +73,13 @@
    2.30              goto error;
    2.31          }
    2.32  
    2.33 +        partner = Identity_to_Struct(&msg->header.me, NULL);
    2.34 +        if (!partner){
    2.35 +            status = PEP_OUT_OF_MEMORY;
    2.36 +            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    2.37 +            goto error;
    2.38 +        }
    2.39 +
    2.40          msgIsFromGroup = msg->header.devicegroup;
    2.41  
    2.42          switch (msg->payload.present) {
    2.43 @@ -63,6 +89,9 @@
    2.44  
    2.45              case DeviceGroup_Protocol__payload_PR_handshakeRequest:
    2.46                  // re-check uuid in case sync_uuid changed while in the queue
    2.47 +
    2.48 +// TODO check matching group-ID as well
    2.49 +
    2.50                  if (strncmp(session->sync_session->sync_uuid,
    2.51                              (const char *)msg->payload.choice.handshakeRequest.partner_id->buf,
    2.52                              msg->payload.choice.handshakeRequest.partner_id->size) != 0){
    2.53 @@ -74,16 +103,19 @@
    2.54                      char *devgrp = NULL;
    2.55                      status = get_device_group(session, &devgrp);
    2.56  
    2.57 -                    // if handshake request comes from same group ignore, ignore it
    2.58 +                    // if handshake request comes from same group, ignore it
    2.59                      if (status == PEP_STATUS_OK && devgrp && devgrp[0] &&
    2.60                          strncmp(devgrp,
    2.61                                  (const char *)msg->payload.choice.handshakeRequest.group_id->buf,
    2.62 -                                msg->payload.choice.handshakeRequest.group_id->size) != 0){
    2.63 +                                msg->payload.choice.handshakeRequest.group_id->size) == 0){
    2.64                          status = PEP_SYNC_ILLEGAL_MESSAGE;
    2.65                          goto error;
    2.66                      }
    2.67                      free(devgrp);
    2.68                      // if it comes from another group, then this is groupmerge
    2.69 +                    
    2.70 +// TODO insert handshake request's group id into partner's id
    2.71 +
    2.72                  }
    2.73  
    2.74                  event = HandshakeRequest;
    2.75 @@ -159,12 +191,6 @@
    2.76                  goto error;
    2.77          }
    2.78  
    2.79 -        partner = Identity_to_Struct(&msg->header.me, NULL);
    2.80 -        if (!partner){
    2.81 -            status = PEP_OUT_OF_MEMORY;
    2.82 -            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
    2.83 -            goto error;
    2.84 -        }
    2.85      }
    2.86      else{
    2.87          partner = sync_msg->u.event.partner;
    2.88 @@ -437,6 +463,9 @@
    2.89                          // HandshakeRequest needs encryption
    2.90                          case DeviceGroup_Protocol__payload_PR_handshakeRequest:
    2.91                              if (rating < PEP_rating_reliable ||
    2.92 +
    2.93 +// TODO check matching group-ID as well
    2.94 +
    2.95                                  strncmp(session->sync_session->sync_uuid,
    2.96                                          (const char *)msg->payload.choice.handshakeRequest.partner_id->buf,
    2.97                                          msg->payload.choice.handshakeRequest.partner_id->size) != 0){