sync : exclude handshake message from device already using trusted keys, i.e. presumably in the group
authorEdouard Tisserant <edouard@pep-project.org>
Thu, 27 Oct 2016 10:15:31 +0200
changeset 1339a8b118fae4ae
parent 1338 515f4edb52d0
child 1340 276625d4f083
sync : exclude handshake message from device already using trusted keys, i.e. presumably in the group
src/sync_impl.c
     1.1 --- a/src/sync_impl.c	Wed Oct 26 05:14:14 2016 +0200
     1.2 +++ b/src/sync_impl.c	Thu Oct 27 10:15:31 2016 +0200
     1.3 @@ -257,9 +257,8 @@
     1.4      if (!(session && src))
     1.5          return PEP_ILLEGAL_VALUE;
     1.6  
     1.7 -    bool found = false;
     1.8 -    bool expired = false;
     1.9 -    bool discarded = false;
    1.10 +    bool consume = false;
    1.11 +    bool discard = false;
    1.12      bool force_keep_msg = false;
    1.13  
    1.14      for (bloblist_t *bl = src->attachments; bl && bl->value; bl = bl->next) {
    1.15 @@ -285,7 +284,7 @@
    1.16                      time_t expiry = timegm(src->recv) + SYNC_MSG_EXPIRE_TIME;
    1.17                      time_t now = time(NULL);
    1.18                      if(expiry != 0 && now != 0 && expiry < now){
    1.19 -                        expired = true;
    1.20 +                        consume = true;
    1.21                          goto free_all;
    1.22                      }
    1.23                  }
    1.24 @@ -302,9 +301,17 @@
    1.25                                  strncmp(session->sync_uuid,
    1.26                                          (const char *)msg->payload.choice.handshakeRequest.partner.user_id->buf,
    1.27                                          msg->payload.choice.handshakeRequest.partner.user_id->size) != 0){
    1.28 -                                discarded = true;
    1.29 +                                discard = true;
    1.30                                  goto free_all;
    1.31                              }
    1.32 +                            
    1.33 +                            // Ignore and consume handshakes with devices
    1.34 +                            // already using trusted own key to encrypt
    1.35 +                            if (rating >= PEP_rating_trusted){
    1.36 +                                consume = true;
    1.37 +                                goto free_all;
    1.38 +                            }
    1.39 +
    1.40                              break;
    1.41                          // accepting GroupKeys needs encryption and trust of peer device
    1.42                          case DeviceGroup_Protocol__payload_PR_groupKeys:
    1.43 @@ -314,7 +321,7 @@
    1.44                                  (strncmp(session->sync_uuid,
    1.45                                          (const char *)msg->payload.choice.groupKeys.partner.user_id->buf,
    1.46                                          msg->payload.choice.groupKeys.partner.user_id->size) != 0)){
    1.47 -                                discarded = true;
    1.48 +                                discard = true;
    1.49                                  goto free_all;
    1.50                              }
    1.51  
    1.52 @@ -332,7 +339,7 @@
    1.53                              status = get_trust(session, _from);
    1.54                              if (_from->comm_type < PEP_ct_strong_encryption) {
    1.55                                  free_identity(_from);
    1.56 -                                discarded = true;
    1.57 +                                discard = true;
    1.58                                  goto free_all;
    1.59                              }
    1.60                              free_identity(_from);
    1.61 @@ -346,7 +353,7 @@
    1.62                              force_keep_msg = true;
    1.63                              
    1.64                              if (!keylist || rating < PEP_rating_reliable){
    1.65 -                                discarded = true;
    1.66 +                                discard = true;
    1.67                                  goto free_all;
    1.68                              }
    1.69                              // GroupUpdate and UpdateRequests come from group.
    1.70 @@ -363,7 +370,7 @@
    1.71                              status = get_trust(session, _from);
    1.72                              if (_from->comm_type < PEP_ct_pEp) {
    1.73                                  free_identity(_from);
    1.74 -                                discarded = true;
    1.75 +                                discard = true;
    1.76                                  goto free_all;
    1.77                              }
    1.78                              free_identity(_from);
    1.79 @@ -373,7 +380,7 @@
    1.80                      }
    1.81  
    1.82  
    1.83 -                    found = true;
    1.84 +                    consume = true;
    1.85                      sync_msg_t *sync_msg = malloc(sizeof(sync_msg_t));
    1.86                      if(sync_msg == NULL){
    1.87                          status = PEP_OUT_OF_MEMORY;
    1.88 @@ -388,12 +395,12 @@
    1.89                          }
    1.90                          goto free_all;
    1.91                      }
    1.92 -                    // don't message now that it is in the queue
    1.93 +                    // don't free message now that it is in the queue
    1.94                      goto free_userid;
    1.95                  }
    1.96                  else if (status == PEP_OWN_SEQUENCE) {
    1.97                      status = PEP_STATUS_OK;
    1.98 -                    discarded = true;
    1.99 +                    discard = true;
   1.100                      goto free_all;
   1.101                  }
   1.102  
   1.103 @@ -412,7 +419,7 @@
   1.104          return PEP_MESSAGE_DISCARDED;
   1.105      }
   1.106  
   1.107 -    if ((expired || found) && !session->keep_sync_msg) {
   1.108 +    if (consume && !session->keep_sync_msg) {
   1.109          for (stringpair_list_t *spl = src->opt_fields ; spl && spl->value ;
   1.110                  spl = spl->next) {
   1.111              if (spl->value->key &&
   1.112 @@ -425,7 +432,7 @@
   1.113          return PEP_MESSAGE_DISCARDED;
   1.114      }
   1.115  
   1.116 -    if (discarded)
   1.117 +    if(discard)
   1.118          return PEP_MESSAGE_DISCARDED;
   1.119  
   1.120      if (!session->keep_sync_msg) {