KeySync: use _is_own_uuid and _is_own_group_uuid, added in previous revision AllGroupDevicesShowHandshake
authorEdouard Tisserant <edouard@pep-project.org>
Wed, 01 Mar 2017 15:28:25 +0100
branchAllGroupDevicesShowHandshake
changeset 1606c3f8396acee4
parent 1605 54bb3990a70f
child 1607 f22aa0501060
KeySync: use _is_own_uuid and _is_own_group_uuid, added in previous revision
src/sync_impl.c
     1.1 --- a/src/sync_impl.c	Wed Mar 01 15:08:55 2017 +0100
     1.2 +++ b/src/sync_impl.c	Wed Mar 01 15:28:25 2017 +0100
     1.3 @@ -34,7 +34,7 @@
     1.4  static bool _is_own_uuid( PEP_SESSION session, UTF8String_t *uuid)
     1.5  {
     1.6      return strncmp(session->sync_session->sync_uuid,
     1.7 -                   (const char*)uuid->buf, uuid->size) != 0;
     1.8 +                   (const char*)uuid->buf, uuid->size) == 0;
     1.9  }
    1.10  
    1.11  static bool _is_own_group_uuid( PEP_SESSION session, UTF8String_t *uuid)
    1.12 @@ -92,26 +92,18 @@
    1.13  
    1.14  // TODO check matching group-ID as well
    1.15  
    1.16 -                if (strncmp(session->sync_session->sync_uuid,
    1.17 -                            (const char *)msg->payload.choice.handshakeRequest.partner_id->buf,
    1.18 -                            msg->payload.choice.handshakeRequest.partner_id->size) != 0){
    1.19 +                if (!_is_own_uuid(session, 
    1.20 +                        msg->payload.choice.handshakeRequest.partner_id)){
    1.21                      status = PEP_SYNC_ILLEGAL_MESSAGE;
    1.22                      goto error;
    1.23                  }
    1.24  
    1.25                  if(msgIsFromGroup) {
    1.26 -                    char *devgrp = NULL;
    1.27 -                    status = get_device_group(session, &devgrp);
    1.28 -
    1.29 -                    // if handshake request comes from same group, ignore it
    1.30 -                    if (status == PEP_STATUS_OK && devgrp && devgrp[0] &&
    1.31 -                        strncmp(devgrp,
    1.32 -                                (const char *)msg->payload.choice.handshakeRequest.group_id->buf,
    1.33 -                                msg->payload.choice.handshakeRequest.group_id->size) == 0){
    1.34 +                    if(_is_own_group_uuid(session, 
    1.35 +                           msg->payload.choice.handshakeRequest.group_id)) {
    1.36                          status = PEP_SYNC_ILLEGAL_MESSAGE;
    1.37                          goto error;
    1.38                      }
    1.39 -                    free(devgrp);
    1.40                      // if it comes from another group, then this is groupmerge
    1.41                      
    1.42  // TODO insert handshake request's group id into partner's id
    1.43 @@ -128,9 +120,8 @@
    1.44              case DeviceGroup_Protocol__payload_PR_groupKeys:
    1.45              {
    1.46                  // re-check uuid in case sync_uuid changed while in the queue
    1.47 -                if (strncmp(session->sync_session->sync_uuid,
    1.48 -                            (const char *)msg->payload.choice.groupKeys.partner_id->buf,
    1.49 -                            msg->payload.choice.groupKeys.partner_id->size) != 0){
    1.50 +                if (!_is_own_uuid(session, 
    1.51 +                        msg->payload.choice.groupKeys.partner_id)){
    1.52                      status = PEP_SYNC_ILLEGAL_MESSAGE;
    1.53                      goto error;
    1.54                  }
    1.55 @@ -463,12 +454,12 @@
    1.56                          // HandshakeRequest needs encryption
    1.57                          case DeviceGroup_Protocol__payload_PR_handshakeRequest:
    1.58                              if (rating < PEP_rating_reliable ||
    1.59 +                                !_is_own_uuid(session, 
    1.60 +                                    msg->payload.choice.handshakeRequest.partner_id)){
    1.61  
    1.62  // TODO check matching group-ID as well
    1.63 +// TODO if handshake request is for group then dont consume
    1.64  
    1.65 -                                strncmp(session->sync_session->sync_uuid,
    1.66 -                                        (const char *)msg->payload.choice.handshakeRequest.partner_id->buf,
    1.67 -                                        msg->payload.choice.handshakeRequest.partner_id->size) != 0){
    1.68                                  discard = true;
    1.69                                  goto free_all;
    1.70                              }
    1.71 @@ -479,9 +470,8 @@
    1.72                          {
    1.73                              if (!keylist || rating < PEP_rating_reliable ||
    1.74                                  // message is only consumed by instance it is addressed to
    1.75 -                                (strncmp(session->sync_session->sync_uuid,
    1.76 -                                        (const char *)msg->payload.choice.groupKeys.partner_id->buf,
    1.77 -                                        msg->payload.choice.groupKeys.partner_id->size) != 0)){
    1.78 +                                !_is_own_uuid(session, 
    1.79 +                                    msg->payload.choice.groupKeys.partner_id)){
    1.80                                  discard = true;
    1.81                                  goto free_all;
    1.82                              }