Merge with sync sequoia_windows
authorThomas
Thu, 30 May 2019 13:15:16 +0200
branchsequoia_windows
changeset 37879c8b6dd07b92
parent 3784 b6a0f8ceede7
parent 3786 008dfd0ca85f
child 3792 5fc0cce01f07
Merge with sync
     1.1 --- a/src/map_asn1.c	Thu May 30 07:58:19 2019 +0200
     1.2 +++ b/src/map_asn1.c	Thu May 30 13:15:16 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 07:58:19 2019 +0200
     2.2 +++ b/sync/cond_act_sync.yml2	Thu May 30 13:15:16 2019 +0200
     2.3 @@ -359,9 +359,41 @@
     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_STATUS status = set_identity(session, _il->ident);
    2.12 +        pEp_identity *ident = _il->ident;
    2.13 +        bool is_own_already = false;
    2.14 +
    2.15 +        PEP_STATUS status = is_own_address(session, ident->address, &is_own_already);
    2.16 +        if (status) {
    2.17 +            free_identity_list(il);
    2.18 +            return status;
    2.19 +        }
    2.20 +
    2.21 +        char *user_id = NULL;
    2.22 +        status = get_default_own_userid(session, &user_id);
    2.23 +        if (status) {
    2.24 +            free_identity_list(il);
    2.25 +            return status;
    2.26 +        }
    2.27 +
    2.28 +        free(ident->user_id);
    2.29 +        ident->user_id = user_id;
    2.30 +
    2.31 +        if (is_own_already) {
    2.32 +            ident->comm_type = PEP_ct_pEp;
    2.33 +            status = set_trust(session, ident);
    2.34 +        }
    2.35 +        else {
    2.36 +            oil = identity_list_add(oil, ident);
    2.37 +            if (!oil) {
    2.38 +                free_identity_list(il);
    2.39 +                return PEP_OUT_OF_MEMORY;
    2.40 +            }
    2.41 +            status = myself(session, ident);
    2.42 +        }
    2.43          if (status) {
    2.44              free_identity_list(il);
    2.45              return status;
    2.46 @@ -375,7 +407,7 @@
    2.47  ||
    2.48      PEP_STATUS status = PEP_STATUS_OK;
    2.49  
    2.50 -    // set flag for current keys
    2.51 +    // set flag for all keys; don't change anything else
    2.52      for (identity_list *il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
    2.53          if (!(il->ident->flags && PEP_idf_not_for_sync)) {
    2.54              status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
    2.55 @@ -388,43 +420,48 @@
    2.56  action receivedKeysAreGroupKeys
    2.57  ||
    2.58      PEP_STATUS status = PEP_STATUS_OK;
    2.59 -
    2.60 -    // set flag for current keys
    2.61 +    // set flag for all keys
    2.62      for (identity_list *il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
    2.63          if (!(il->ident->flags && PEP_idf_not_for_sync)) {
    2.64 +            
    2.65              status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
    2.66              if (status)
    2.67                  return status;
    2.68          }
    2.69      }
    2.70  
    2.71 +    char *user_id = NULL;
    2.72 +    status = get_default_own_userid(session, &user_id);
    2.73 +    if (status)
    2.74 +        return status;
    2.75 +
    2.76      identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
    2.77      if (!il)
    2.78          return PEP_OUT_OF_MEMORY;
    2.79  
    2.80 -    for (il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
    2.81 +    for (identity_list *_il = il; _il && _il->ident ; _il = _il->next) {
    2.82          // replace partner's user_id with own user_id
    2.83 -        free(il->ident->user_id);
    2.84 -        il->ident->user_id = strdup(session->sync_state.transport.from->user_id);
    2.85 -        if (!il->ident->user_id) {
    2.86 +        free(_il->ident->user_id);
    2.87 +        _il->ident->user_id = strdup(user_id);
    2.88 +        assert(_il->ident->user_id);
    2.89 +        if (!_il->ident->user_id) {
    2.90              free_identity_list(il);
    2.91 +            free(user_id);
    2.92              return PEP_OUT_OF_MEMORY;
    2.93          }
    2.94 -
    2.95 -        status = myself(session, il->ident);
    2.96 +    
    2.97 +        const char *own_key = _il->ident->fpr;
    2.98 +        _il->ident->fpr = NULL;
    2.99 +        status = set_own_key(session, _il->ident, own_key);
   2.100          if (status) {
   2.101              free_identity_list(il);
   2.102 -            return status;
   2.103 -        }
   2.104 -
   2.105 -        status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
   2.106 -        if (status) {
   2.107 -            free_identity_list(il);
   2.108 +            free(user_id);
   2.109              return status;
   2.110          }
   2.111      }
   2.112  
   2.113      free_identity_list(il);
   2.114 +    free(user_id);
   2.115  ||
   2.116  
   2.117  action trustThisKey
     3.1 --- a/sync/sync.fsm	Thu May 30 07:58:19 2019 +0200
     3.2 +++ b/sync/sync.fsm	Thu May 30 13:15:16 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              }