removing bugs sync
authorVolker Birk <vb@pep-project.org>
Thu, 30 May 2019 12:47:18 +0200
branchsync
changeset 3786008dfd0ca85f
parent 3785 a654da1d7c7c
child 3787 9c8b6dd07b92
child 3788 f6f5f9093bb9
removing bugs
src/map_asn1.c
sync/cond_act_sync.yml2
sync/sync.fsm
     1.1 --- a/src/map_asn1.c	Thu May 30 11:02:36 2019 +0200
     1.2 +++ b/src/map_asn1.c	Thu May 30 12:47:18 2019 +0200
     1.3 @@ -134,11 +134,15 @@
     1.4      if (!list)
     1.5          return NULL;
     1.6  
     1.7 -    if (allocated)
     1.8 +    if (allocated) {
     1.9          result = (IdentityList_t *) calloc(1, sizeof(IdentityList_t));
    1.10 -    assert(result);
    1.11 -    if (!result)
    1.12 -        return NULL;
    1.13 +        assert(result);
    1.14 +        if (!result)
    1.15 +            return NULL;
    1.16 +    }
    1.17 +    else {
    1.18 +        asn_sequence_empty(result);
    1.19 +    }
    1.20  
    1.21      for (const identity_list *l = list; l && l->ident; l=l->next) {
    1.22          Identity_t *ident = Identity_from_Struct(l->ident, NULL);
     2.1 --- a/sync/cond_act_sync.yml2	Thu May 30 11:02:36 2019 +0200
     2.2 +++ b/sync/cond_act_sync.yml2	Thu May 30 12:47:18 2019 +0200
     2.3 @@ -359,6 +359,8 @@
     2.4      if (!il)
     2.5          return PEP_OUT_OF_MEMORY;
     2.6      
     2.7 +    identity_list *oil = session->sync_state.own.identities;
     2.8 +
     2.9      // BUG: this should be a transaction and been rolled back completely on error
    2.10      for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
    2.11          pEp_identity *ident = _il->ident;
    2.12 @@ -370,17 +372,26 @@
    2.13              return status;
    2.14          }
    2.15  
    2.16 +        char *user_id = NULL;
    2.17 +        status = get_default_own_userid(session, &user_id);
    2.18 +        if (status) {
    2.19 +            free_identity_list(il);
    2.20 +            return status;
    2.21 +        }
    2.22 +
    2.23 +        free(ident->user_id);
    2.24 +        ident->user_id = user_id;
    2.25 +
    2.26          if (is_own_already) {
    2.27 -            char *user_id = NULL;
    2.28 -            status = get_default_own_userid(session, &user_id);
    2.29 -            if (!status) {
    2.30 -                free(ident->user_id);
    2.31 -                ident->user_id = user_id;
    2.32 -                ident->comm_type = PEP_ct_pEp;
    2.33 -                status = set_trust(session, ident);
    2.34 -            }
    2.35 +            ident->comm_type = PEP_ct_pEp;
    2.36 +            status = set_trust(session, ident);
    2.37          }
    2.38          else {
    2.39 +            oil = identity_list_add(oil, ident);
    2.40 +            if (!oil) {
    2.41 +                free_identity_list(il);
    2.42 +                return PEP_OUT_OF_MEMORY;
    2.43 +            }
    2.44              status = myself(session, ident);
    2.45          }
    2.46          if (status) {
    2.47 @@ -396,7 +407,7 @@
    2.48  ||
    2.49      PEP_STATUS status = PEP_STATUS_OK;
    2.50  
    2.51 -    // set flag for current keys
    2.52 +    // set flag for all keys; don't change anything else
    2.53      for (identity_list *il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
    2.54          if (!(il->ident->flags && PEP_idf_not_for_sync)) {
    2.55              status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
    2.56 @@ -409,43 +420,48 @@
    2.57  action receivedKeysAreGroupKeys
    2.58  ||
    2.59      PEP_STATUS status = PEP_STATUS_OK;
    2.60 -
    2.61 -    // set flag for current keys
    2.62 +    // set flag for all keys
    2.63      for (identity_list *il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
    2.64          if (!(il->ident->flags && PEP_idf_not_for_sync)) {
    2.65 +            
    2.66              status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
    2.67              if (status)
    2.68                  return status;
    2.69          }
    2.70      }
    2.71  
    2.72 +    char *user_id = NULL;
    2.73 +    status = get_default_own_userid(session, &user_id);
    2.74 +    if (status)
    2.75 +        return status;
    2.76 +
    2.77      identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
    2.78      if (!il)
    2.79          return PEP_OUT_OF_MEMORY;
    2.80  
    2.81 -    for (il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
    2.82 +    for (identity_list *_il = il; _il && _il->ident ; _il = _il->next) {
    2.83          // replace partner's user_id with own user_id
    2.84 -        free(il->ident->user_id);
    2.85 -        il->ident->user_id = strdup(session->sync_state.transport.from->user_id);
    2.86 -        if (!il->ident->user_id) {
    2.87 +        free(_il->ident->user_id);
    2.88 +        _il->ident->user_id = strdup(user_id);
    2.89 +        assert(_il->ident->user_id);
    2.90 +        if (!_il->ident->user_id) {
    2.91              free_identity_list(il);
    2.92 +            free(user_id);
    2.93              return PEP_OUT_OF_MEMORY;
    2.94          }
    2.95 -
    2.96 -        status = myself(session, il->ident);
    2.97 +    
    2.98 +        const char *own_key = _il->ident->fpr;
    2.99 +        _il->ident->fpr = NULL;
   2.100 +        status = set_own_key(session, _il->ident, own_key);
   2.101          if (status) {
   2.102              free_identity_list(il);
   2.103 -            return status;
   2.104 -        }
   2.105 -
   2.106 -        status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
   2.107 -        if (status) {
   2.108 -            free_identity_list(il);
   2.109 +            free(user_id);
   2.110              return status;
   2.111          }
   2.112      }
   2.113  
   2.114      free_identity_list(il);
   2.115 +    free(user_id);
   2.116  ||
   2.117  
   2.118  action trustThisKey
     3.1 --- a/sync/sync.fsm	Thu May 30 11:02:36 2019 +0200
     3.2 +++ b/sync/sync.fsm	Thu May 30 12:47:18 2019 +0200
     3.3 @@ -236,10 +236,7 @@
     3.4              on OwnKeysSecond {
     3.5                  do saveGroupKeys;
     3.6  
     3.7 -                if keyElectionWon
     3.8 -                    do ownKeysAreGroupKeys;
     3.9 -                else
    3.10 -                    do receivedKeysAreGroupKeys;
    3.11 +                do receivedKeysAreGroupKeys;
    3.12                  do showGroupCreated;
    3.13                  go Grouped;
    3.14              }
    3.15 @@ -254,10 +251,7 @@
    3.16              on OwnKeysFirst {
    3.17                  do saveGroupKeys;
    3.18  
    3.19 -                if keyElectionWon
    3.20 -                    do ownKeysAreGroupKeys;
    3.21 -                else
    3.22 -                    do receivedKeysAreGroupKeys;
    3.23 +                do ownKeysAreGroupKeys;
    3.24                  do showGroupCreated;
    3.25                  go Grouped;
    3.26              }