merging sync
authorVolker Birk <vb@pep-project.org>
Tue, 28 Jan 2020 13:57:06 +0100
branchsync
changeset 4365cccf17941b9d
parent 4364 10211edee233
parent 4363 5cf6a03ac9be
child 4366 a3c264375e16
merging
src/message_api.c
     1.1 --- a/src/key_reset.c	Tue Jan 28 13:56:44 2020 +0100
     1.2 +++ b/src/key_reset.c	Tue Jan 28 13:57:06 2020 +0100
     1.3 @@ -20,6 +20,11 @@
     1.4  #define KEY_RESET_MAJOR_VERSION 1L
     1.5  #define KEY_RESET_MINOR_VERSION 0L
     1.6  
     1.7 +static void _add_auto_consume(message* msg) {
     1.8 +    add_opt_field(msg, "pEp-auto-consume", "yes");
     1.9 +    msg->in_reply_to = stringlist_add(msg->in_reply_to, "pEp-auto-consume@pEp.foundation");
    1.10 +}
    1.11 +
    1.12  static PEP_STATUS _generate_reset_structs(PEP_SESSION session,
    1.13                                            const pEp_identity* reset_ident,
    1.14                                            const char* old_fpr,
    1.15 @@ -793,7 +798,8 @@
    1.16              free(reset_msg);
    1.17              goto pEp_free;
    1.18          }
    1.19 -        
    1.20 +
    1.21 +        _add_auto_consume(reset_msg);        
    1.22          // insert into queue
    1.23          status = send_cb(reset_msg);
    1.24  
    1.25 @@ -943,7 +949,8 @@
    1.26          if (status != PEP_STATUS_OK) {
    1.27              goto pEp_free;
    1.28          }
    1.29 -
    1.30 +        _add_auto_consume(enc_msg);
    1.31 +        
    1.32          // insert into queue
    1.33          status = send_cb(enc_msg);
    1.34  
    1.35 @@ -1204,33 +1211,36 @@
    1.36                      for (curr_ident = key_idents; curr_ident && curr_ident->ident; 
    1.37                                                      curr_ident = curr_ident->next) {
    1.38                          
    1.39 +                        pEp_identity* this_ident = curr_ident->ident;
    1.40                          // Do the full reset on this identity        
    1.41                          // Base case for is_own_private starts here
    1.42 -                        // tmp ident is an actual identity now (not just a skeleton?)
    1.43 +                        // Note that we reset this key for ANY own ident that has it. And if 
    1.44 +                        // tmp_ident did NOT have this key, it won't matter. We will reset the 
    1.45 +                        // key for all idents for this user.
    1.46                          status = revoke_key(session, fpr_copy, NULL);
    1.47                          
    1.48                          // If we have a full identity, we have some cleanup and generation tasks here
    1.49 -                        if (!EMPTYSTR(tmp_ident->address)) {
    1.50 +                        if (!EMPTYSTR(this_ident->address)) {
    1.51                              // generate new key
    1.52                              if (status == PEP_STATUS_OK) {
    1.53 -                                tmp_ident->fpr = NULL;
    1.54 -                                status = myself(session, tmp_ident);
    1.55 +                                this_ident->fpr = NULL;
    1.56 +                                status = myself(session, this_ident);
    1.57                              }
    1.58 -                            if (status == PEP_STATUS_OK && tmp_ident->fpr && strcmp(fpr_copy, tmp_ident->fpr) != 0)
    1.59 -                                new_key = strdup(tmp_ident->fpr);
    1.60 +                            if (status == PEP_STATUS_OK && this_ident->fpr && strcmp(fpr_copy, this_ident->fpr) != 0)
    1.61 +                                new_key = strdup(this_ident->fpr);
    1.62                              // Error handling?    
    1.63                              
    1.64                              // mistrust fpr from trust
    1.65 -                            tmp_ident->fpr = fpr_copy;
    1.66 +                            this_ident->fpr = fpr_copy;
    1.67                                                              
    1.68 -                            tmp_ident->comm_type = PEP_ct_mistrusted;
    1.69 -                            status = set_trust(session, tmp_ident);
    1.70 -                            tmp_ident->fpr = NULL;
    1.71 +                            this_ident->comm_type = PEP_ct_mistrusted;
    1.72 +                            status = set_trust(session, this_ident);
    1.73 +                            this_ident->fpr = NULL;
    1.74                              
    1.75                              // Done with old use of ident.
    1.76                              if (status == PEP_STATUS_OK) {
    1.77 -                                // Update fpr for outgoing
    1.78 -                                status = myself(session, tmp_ident);
    1.79 +                                // Generate new key
    1.80 +                                status = myself(session, this_ident);
    1.81                              }
    1.82                          }    
    1.83                          
    1.84 @@ -1255,11 +1265,10 @@
    1.85                              
    1.86                              tmp_ident->fpr = fpr_copy;
    1.87                              if (status == PEP_STATUS_OK)
    1.88 -                                status = send_key_reset_to_recents(session, tmp_ident, fpr_copy, new_key);        
    1.89 +                                status = send_key_reset_to_recents(session, this_ident, fpr_copy, new_key);        
    1.90                              tmp_ident->fpr = NULL;    
    1.91                          }                    
    1.92 -                        // Ident list gets freed below, do not free here!
    1.93 -                    }
    1.94 +                    }  // Ident list gets freed below, do not free here!
    1.95                  }
    1.96                  // Ok, we've either now reset for each own identity with this key, or 
    1.97                  // we got an error and want to bail anyway.
     2.1 --- a/src/message_api.c	Tue Jan 28 13:56:44 2020 +0100
     2.2 +++ b/src/message_api.c	Tue Jan 28 13:57:06 2020 +0100
     2.3 @@ -4615,6 +4615,25 @@
     2.4              wsize, full);
     2.5  }
     2.6  
     2.7 +static void remove_separators(const char* str1, char* str2, int str1len) {
     2.8 +    int i = 0;
     2.9 +    char* curr_write = str2;
    2.10 +    for ( ; i < str1len; i++) {
    2.11 +        switch (str1[i]) {
    2.12 +            case ' ':
    2.13 +            case '\t':
    2.14 +            case '\r':
    2.15 +            case '\n':
    2.16 +            case '\0':
    2.17 +                continue;
    2.18 +            default:
    2.19 +                *curr_write = str1[i];
    2.20 +                curr_write++;
    2.21 +        }
    2.22 +    }
    2.23 +    *curr_write = '\0';
    2.24 +}
    2.25 +
    2.26  DYNAMIC_API PEP_STATUS get_trustwords_for_fprs(
    2.27          PEP_SESSION session, const char* fpr1, const char* fpr2,
    2.28          const char* lang, char **words, size_t *wsize, bool full
    2.29 @@ -4699,6 +4718,10 @@
    2.30      
    2.31      status = check_for_zero_fpr(XORed_fpr);
    2.32      
    2.33 +    if (status == PEP_TRUSTWORDS_DUPLICATE_FPR) {
    2.34 +        remove_separators(fpr1, XORed_fpr, fpr1_len);
    2.35 +        status = PEP_STATUS_OK;
    2.36 +    }
    2.37      if (status != PEP_STATUS_OK)
    2.38          goto error_release;
    2.39      
     3.1 --- a/src/pEpEngine.c	Tue Jan 28 13:56:44 2020 +0100
     3.2 +++ b/src/pEpEngine.c	Tue Jan 28 13:57:06 2020 +0100
     3.3 @@ -843,7 +843,6 @@
     3.4      // mean we should use it, and we should be *safe*, not relying 
     3.5      // on an implementation-specific quirk which might be sanely removed 
     3.6      // in a future sqlite version.
     3.7 -    stringpair_t* revoked_key_to_own_address = NULL;
     3.8      
     3.9      identity_list* id_list = NULL;
    3.10      status = own_identities_retrieve(session, &id_list);
     4.1 --- a/sync/cond_act_sync.yml2	Tue Jan 28 13:56:44 2020 +0100
     4.2 +++ b/sync/cond_act_sync.yml2	Tue Jan 28 13:57:06 2020 +0100
     4.3 @@ -277,7 +277,6 @@
     4.4          assert(status == PEP_STATUS_OK);
     4.5          if (status)
     4.6              return status;
     4.7 -        assert(strcmp(me->fpr, session->sync_state.comm_partner.sender_fpr) != 0);
     4.8  
     4.9          assert(me->fpr && me->fpr[0]);
    4.10          if (!(me->fpr && me->fpr[0])) {
    4.11 @@ -312,7 +311,6 @@
    4.12              return PEP_OUT_OF_MEMORY;
    4.13          }
    4.14  
    4.15 -        assert(strcmp(me->fpr, partner->fpr) != 0);
    4.16          status = session->notifyHandshake(me, partner, «$type»);
    4.17          if (status)
    4.18              return status;
     5.1 --- a/sync/sync.fsm	Tue Jan 28 13:56:44 2020 +0100
     5.2 +++ b/sync/sync.fsm	Tue Jan 28 13:57:06 2020 +0100
     5.3 @@ -360,7 +360,8 @@
     5.4              // this is for a leaving group member
     5.5              on GroupKeyResetRequiredAndDisable {
     5.6                  send InitUnledGroupKeyReset;
     5.7 -                go DisableOnInitUnledGroupKeyReset;
     5.8 +                do disable;
     5.9 +                do resetOwnKeysUngrouped;
    5.10              }
    5.11  
    5.12              on InitUnledGroupKeyReset {
    5.13 @@ -385,13 +386,6 @@
    5.14              }
    5.15          }
    5.16  
    5.17 -        state DisableOnInitUnledGroupKeyReset {
    5.18 -            on InitUnledGroupKeyReset {
    5.19 -                do disable;
    5.20 -                do resetOwnKeysUngrouped;
    5.21 -            }    
    5.22 -        }
    5.23 -
    5.24          // sole device handshaking with group
    5.25          state HandshakingToJoin {
    5.26              on Init
     6.1 --- a/test/src/TrustwordsTest.cc	Tue Jan 28 13:56:44 2020 +0100
     6.2 +++ b/test/src/TrustwordsTest.cc	Tue Jan 28 13:57:06 2020 +0100
     6.3 @@ -150,19 +150,26 @@
     6.4      output_stream << "\nTest 2: fpr1 == fpr1, short" << endl;
     6.5  
     6.6      output_stream << "\nfinding French trustwords for " << fingerprint2 << "...\n";
     6.7 -    trustwords(session, fingerprint1.c_str(), "fr", &words1, &wsize1, 5);
     6.8 +    trustwords(session, fingerprint2.c_str(), "fr", &words1, &wsize1, 5);
     6.9      ASSERT_NE(words1, nullptr);
    6.10      output_stream << words1 << "\n";
    6.11  
    6.12      output_stream << "\nfinding French trustwords for " << identity2->address << " and " << identity2->address << "...\n";
    6.13      status = get_trustwords(session, identity2, identity2, "fr", &full_wordlist, &wsize_full, false);
    6.14 -    ASSERT_EQ(status , PEP_TRUSTWORDS_DUPLICATE_FPR);
    6.15 -    output_stream << "Discovered duplicate fprs as desired" << endl;
    6.16 +    ASSERT_STREQ(words1, full_wordlist);
    6.17 +    // ASSERT_EQ(status , PEP_TRUSTWORDS_DUPLICATE_FPR);
    6.18 +    // output_stream << "Discovered duplicate fprs as desired" << endl;
    6.19 +
    6.20 +    output_stream << "\nfinding English trustwords for " << fingerprint2 << "...\n";
    6.21 +    trustwords(session, fingerprint2.c_str(), "en", &words1, &wsize1, 5);
    6.22 +    ASSERT_NE(words1, nullptr);
    6.23 +    output_stream << words1 << "\n";
    6.24  
    6.25      output_stream << "\nfinding English trustwords for " << identity2->address << " and " << identity2->address << "... with spaces\n";
    6.26      get_trustwords(session, identity2, identity2_with_spaces, "en", &full_wordlist, &wsize_full, false);
    6.27 -    ASSERT_EQ(status , PEP_TRUSTWORDS_DUPLICATE_FPR);
    6.28 -    output_stream << "Discovered duplicate fprs as desired" << endl;
    6.29 +    ASSERT_STREQ(words1, full_wordlist);    
    6.30 +    // ASSERT_EQ(status , PEP_TRUSTWORDS_DUPLICATE_FPR);
    6.31 +    // output_stream << "Discovered duplicate fprs as desired" << endl;
    6.32  
    6.33      pEp_free(words1);
    6.34      words1 = nullptr;