merge sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Fri, 03 May 2019 15:19:14 +0200
branchsync
changeset 36173d6f394c9a6c
parent 3616 8229562ff2a1
parent 3615 37782ea8068a
child 3618 d486cda725b1
child 3620 ed2e72f63757
child 3626 7965990ff7bd
merge
     1.1 --- a/Makefile	Fri May 03 15:18:05 2019 +0200
     1.2 +++ b/Makefile	Fri May 03 15:19:14 2019 +0200
     1.3 @@ -19,6 +19,13 @@
     1.4      $(info ================================================)
     1.5  endif
     1.6  
     1.7 +ifneq ($(MAKE_VERSION),$(word 2,$(sort $(MAKE_VERSION) 4)))
     1.8 +    $(warning ================================================)
     1.9 +    $(warning You are using a make version older than 4. This might cause problems.)
    1.10 +    $(warning ================================================)
    1.11 +endif
    1.12 +
    1.13 +
    1.14  .PHONY: all sync asn1 build install dbinstall uninstall clean tags test package db
    1.15  
    1.16  build: asn1
     2.1 --- a/asn.1/Makefile	Fri May 03 15:18:05 2019 +0200
     2.2 +++ b/asn.1/Makefile	Fri May 03 15:19:14 2019 +0200
     2.3 @@ -21,9 +21,6 @@
     2.4  	$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 keysync.asn1 $<
     2.5  	rm -f converter-sample.c
     2.6  
     2.7 -sync.asn1 keysync.asn1 pEp.asn1:
     2.8 -	cp -f ../sync/generated/*.asn1 ../asn.1
     2.9 -
    2.10  clean:
    2.11  	rm -f *.a *.o *.c *.h *.sample sync.asn1 keysync.asn1
    2.12  
     3.1 --- a/src/keymanagement.c	Fri May 03 15:18:05 2019 +0200
     3.2 +++ b/src/keymanagement.c	Fri May 03 15:19:14 2019 +0200
     3.3 @@ -1753,7 +1753,6 @@
     3.4      sqlite3_reset(session->own_keys_retrieve);
     3.5      
     3.6      int result;
     3.7 -    char *fpr = NULL;
     3.8      
     3.9      stringlist_t *_bl = _keylist;
    3.10      sqlite3_bind_int(session->own_keys_retrieve, 1, excluded_flags);
    3.11 @@ -1762,18 +1761,12 @@
    3.12          result = sqlite3_step(session->own_keys_retrieve);
    3.13          switch (result) {
    3.14              case SQLITE_ROW:
    3.15 -                fpr = strdup((const char *) sqlite3_column_text(session->own_keys_retrieve, 0));
    3.16 -                if(fpr == NULL)
    3.17 +                _bl = stringlist_add(_bl, (const char *)
    3.18 +                        sqlite3_column_text(session->own_keys_retrieve, 0));
    3.19 +                if (_bl == NULL)
    3.20                      goto enomem;
    3.21 -
    3.22 -                _bl = stringlist_add(_bl, fpr);
    3.23 -                if (_bl == NULL) {
    3.24 -                    free(fpr);
    3.25 -                    goto enomem;
    3.26 -                }
    3.27                  if (_keylist == NULL)
    3.28                      _keylist = _bl;
    3.29 -                
    3.30                  break;
    3.31                  
    3.32              case SQLITE_DONE:
     4.1 --- a/src/message_api.c	Fri May 03 15:18:05 2019 +0200
     4.2 +++ b/src/message_api.c	Fri May 03 15:19:14 2019 +0200
     4.3 @@ -2896,23 +2896,30 @@
     4.4  }
     4.5  
     4.6  static PEP_STATUS import_priv_keys_from_decrypted_msg(PEP_SESSION session,
     4.7 -                                                      message* src, 
     4.8                                                        message* msg,
     4.9                                                        bool* imported_keys,
    4.10                                                        bool* imported_private,
    4.11 -                                                      identity_list** private_il) {
    4.12 -                                                          
    4.13 +                                                      identity_list** private_il)
    4.14 +{
    4.15 +    assert(msg && imported_keys && imported_private);
    4.16 +    if (!(msg && imported_keys && imported_private))
    4.17 +        return PEP_ILLEGAL_VALUE;
    4.18 +
    4.19      PEP_STATUS status = PEP_STATUS_OK;
    4.20 -    
    4.21 +    *imported_keys = NULL;
    4.22 +    *imported_private = false;
    4.23 +    if (private_il)
    4.24 +        *private_il = NULL;
    4.25 +
    4.26      // check for private key in decrypted message attachment while importing
    4.27      identity_list *_private_il = NULL;
    4.28 -    *imported_keys = import_attached_keys(session, msg, &_private_il);
    4.29 -    
    4.30 -    if (_private_il && identity_list_length(_private_il) == 1 &&
    4.31 -        _private_il->ident->address)
    4.32 -        *imported_private = true;
    4.33 -
    4.34 -    if (private_il && imported_private) {
    4.35 +
    4.36 +    bool _imported_keys = import_attached_keys(session, msg, &_private_il);
    4.37 +    bool _imported_private = false;
    4.38 +    if (_private_il && _private_il->ident && _private_il->ident->address)
    4.39 +        _imported_private = true;
    4.40 +
    4.41 +    if (private_il && _imported_private) {
    4.42          // the private identity list should NOT be subject to myself() or
    4.43          // update_identity() at this point.
    4.44          // If the receiving app wants them to be in the trust DB, it
    4.45 @@ -2922,27 +2929,31 @@
    4.46          char* own_id = NULL;
    4.47          status = get_default_own_userid(session, &own_id);
    4.48          
    4.49 -        if (status != PEP_STATUS_OK) {
    4.50 -            free(own_id);
    4.51 -            own_id = NULL;
    4.52 -        }
    4.53 -        
    4.54 -        identity_list* il = _private_il;
    4.55 -        for ( ; il; il = il->next) {
    4.56 +        for (identity_list* il = _private_il; il; il = il->next) {
    4.57              if (own_id) {
    4.58                  free(il->ident->user_id);
    4.59                  il->ident->user_id = strdup(own_id);
    4.60 +                assert(il->ident->user_id);
    4.61 +                if (!il->ident->user_id) {
    4.62 +                    status = PEP_OUT_OF_MEMORY;
    4.63 +                    break;
    4.64 +                }
    4.65              }
    4.66              il->ident->me = true;
    4.67          }
    4.68 -        *private_il = _private_il;
    4.69 -        
    4.70          free(own_id);
    4.71 +        if (!status)
    4.72 +            *private_il = _private_il;
    4.73      }
    4.74 -    else
    4.75 +    else {
    4.76          free_identity_list(_private_il);
    4.77 +    }
    4.78   
    4.79 -    
    4.80 +    if (!status) {
    4.81 +        *imported_keys = _imported_keys;
    4.82 +        *imported_private = _imported_private;
    4.83 +    }
    4.84 +
    4.85      return status;
    4.86  }
    4.87  
    4.88 @@ -3243,7 +3254,7 @@
    4.89  
    4.90  }
    4.91  
    4.92 -DYNAMIC_API PEP_STATUS _decrypt_message(
    4.93 +static PEP_STATUS _decrypt_message(
    4.94          PEP_SESSION session,
    4.95          message *src,
    4.96          message **dst,
    4.97 @@ -3426,7 +3437,7 @@
    4.98                  //
    4.99                  // We are importing from the decrypted outermost message now.
   4.100                  //
   4.101 -                status = import_priv_keys_from_decrypted_msg(session, src, msg,
   4.102 +                status = import_priv_keys_from_decrypted_msg(session, msg,
   4.103                                                               &imported_keys,
   4.104                                                               &imported_private_key_address,
   4.105                                                               private_il);
   4.106 @@ -3553,7 +3564,7 @@
   4.107                                              private_il = NULL;
   4.108                                              
   4.109                                              // import keys from decrypted INNER source
   4.110 -                                            status = import_priv_keys_from_decrypted_msg(session, src, inner_message,
   4.111 +                                            status = import_priv_keys_from_decrypted_msg(session, inner_message,
   4.112                                                                                           &imported_keys,
   4.113                                                                                           &imported_private_key_address,
   4.114                                                                                           private_il);
     5.1 --- a/src/stringlist.c	Fri May 03 15:18:05 2019 +0200
     5.2 +++ b/src/stringlist.c	Fri May 03 15:19:14 2019 +0200
     5.3 @@ -18,7 +18,7 @@
     5.4      if (result && value) {
     5.5          result->value = strdup(value);
     5.6          assert(result->value);
     5.7 -        if (result->value == 0) {
     5.8 +        if (!result->value) {
     5.9              free(result);
    5.10              return NULL;
    5.11          }
     6.1 --- a/sync/Makefile	Fri May 03 15:18:05 2019 +0200
     6.2 +++ b/sync/Makefile	Fri May 03 15:19:14 2019 +0200
     6.3 @@ -29,6 +29,7 @@
     6.4  
     6.5  .copy: .actions .statemachines .codecs .messages
     6.6  	cp -f generated/*.c generated/*.h ../src
     6.7 +	cp -f generated/*.asn1 ../asn.1
     6.8  	touch .copy
     6.9  
    6.10  %.xml: %.fsm
     7.1 --- a/sync/cond_act_sync.yml2	Fri May 03 15:18:05 2019 +0200
     7.2 +++ b/sync/cond_act_sync.yml2	Fri May 03 15:19:14 2019 +0200
     7.3 @@ -111,14 +111,33 @@
     7.4  function "copy_UUID" {
     7.5      param "src", param "dst";
     7.6      ||
     7.7 -        TID_t *src = «$src»;
     7.8 -        TID_t *dst = «$dst»;
     7.9 +        {
    7.10 +            TID_t *src = «$src»;
    7.11 +            TID_t *dst = «$dst»;
    7.12  
    7.13 -        assert(src->size == 16);
    7.14 -        if (!(src->size == 16))
    7.15 -            return PEP_UNKNOWN_ERROR;
    7.16 +            assert(src->size == 16);
    7.17 +            if (!(src->size == 16))
    7.18 +                return PEP_UNKNOWN_ERROR;
    7.19  
    7.20 -        OCTET_STRING_fromBuf(dst, (char *) src->buf, src->size);
    7.21 +            OCTET_STRING_fromBuf(dst, (char *) src->buf, src->size);
    7.22 +        }
    7.23 +    ||
    7.24 +}
    7.25 +
    7.26 +function "xor_UUID" {
    7.27 +    param "src", param "dst";
    7.28 +    ||
    7.29 +        {
    7.30 +            TID_t *src = «$src»;
    7.31 +            TID_t *dst = «$dst»;
    7.32 +
    7.33 +            assert(src->size == 16 && dst->size == 16);
    7.34 +            if (!(src->size == 16 && dst->size == 16))
    7.35 +                return PEP_UNKNOWN_ERROR;
    7.36 +
    7.37 +            for (int i=0; i < src->size; ++i)
    7.38 +                dst->buf[i] ^= src->buf[i];
    7.39 +        }
    7.40      ||
    7.41  }
    7.42  
    7.43 @@ -154,7 +173,14 @@
    7.44          return PEP_OUT_OF_MEMORY;
    7.45  
    7.46  ||
    7.47 -    call "new_UUID" with "dst" > &session->sync_state.keysync.negotiation
    7.48 +    call "copy_UUID" {
    7.49 +        with "src" > &session->sync_state.keysync.challenge
    7.50 +        with "dst" > &session->sync_state.keysync.negotiation
    7.51 +    }
    7.52 +    call "xor_UUID" {
    7.53 +        with "src" > &session->own_sync_state.challenge
    7.54 +        with "dst" > &session->sync_state.keysync.negotiation
    7.55 +    }
    7.56      call "copy_UUID" {
    7.57          with "src" > &session->sync_state.keysync.negotiation
    7.58          with "dst" > &session->own_sync_state.negotiation
    7.59 @@ -298,6 +324,7 @@
    7.60          return status;
    7.61  
    7.62      IdentityList_from_identity_list(il, &session->sync_state.keysync.ownIdentities);
    7.63 +    free_identity_list(il);
    7.64  ||
    7.65  
    7.66  action saveGroupKeys
     8.1 --- a/sync/sync.fsm	Fri May 03 15:18:05 2019 +0200
     8.2 +++ b/sync/sync.fsm	Fri May 03 15:19:14 2019 +0200
     8.3 @@ -23,9 +23,9 @@
     8.4  
     8.5          state Sole timeout=off {
     8.6              on Init {
     8.7 +                do closeTransaction;
     8.8 +                do newChallenge;
     8.9                  do showBeingSole;
    8.10 -                do newChallenge;
    8.11 -                do closeTransaction;
    8.12                  send Beacon;
    8.13              }
    8.14  
    8.15 @@ -46,11 +46,12 @@
    8.16                          send Beacon;
    8.17                      }
    8.18                      else /* we are second */ {
    8.19 -                        do replyChallenge; // partner's challenge
    8.20                          do newTransaction;
    8.21                          do tellWeAreNotGrouped;
    8.22                          // second is sending NegotiationRequest
    8.23 +                        do replyChallenge; // partner's challenge
    8.24                          send NegotiationRequest;
    8.25 +                        do useOwnChallenge;
    8.26                      }
    8.27                  }
    8.28              }
    8.29 @@ -264,8 +265,9 @@
    8.30  
    8.31          state Grouped timeout=off {
    8.32              on Init {
    8.33 +                do closeTransaction;
    8.34 +                do newChallenge;
    8.35                  do showBeingInGroup;
    8.36 -                do closeTransaction;
    8.37              }
    8.38  
    8.39              on GroupKeys
    8.40 @@ -277,10 +279,11 @@
    8.41              }
    8.42  
    8.43              on Beacon {
    8.44 -                do replyChallenge;
    8.45                  do newTransaction;
    8.46                  do tellWeAreGrouped;
    8.47 +                do replyChallenge; // partner's challenge
    8.48                  send NegotiationRequest;
    8.49 +                do useOwnChallenge;
    8.50              }
    8.51  
    8.52              on NegotiationOpen if sameTransactionAndPartner
     9.1 --- a/sync/sync_protocol.md	Fri May 03 15:18:05 2019 +0200
     9.2 +++ b/sync/sync_protocol.md	Fri May 03 15:19:14 2019 +0200
     9.3 @@ -47,7 +47,8 @@
     9.4  
     9.5  ### Negotiation
     9.6  
     9.7 -A Negotiation is a Transaction identified by a TID.
     9.8 +A Negotiation is a Transaction identified by a TID. The Negotiation's TID is
     9.9 +the XOR of the two Challenge TIDs of the two devices, respectively.
    9.10  
    9.11  ## Roles and Keys
    9.12