merge sync ENGINE-639
authorDirk Zimmermann <dz@pep.security>
Fri, 27 Sep 2019 12:27:39 +0200
branchENGINE-639
changeset 409239767e4f027b
parent 4083 7fe37c64d29c
parent 4091 5d1a6414271f
child 4093 30ed48409334
merge sync
sync/gen_statemachine.ysl2
     1.1 --- a/db/Makefile	Mon Sep 23 12:39:38 2019 +0200
     1.2 +++ b/db/Makefile	Fri Sep 27 12:27:39 2019 +0200
     1.3 @@ -18,8 +18,10 @@
     1.4  
     1.5  .PHONY: install
     1.6  install: system.db
     1.7 -	mkdir -p `dirname $(SYSTEM_DB)`
     1.8 -	cp system.db $(SYSTEM_DB)
     1.9 +ifdef $(PER_MACHINE_USER_DIRECTORY)
    1.10 +	mkdir -p $(PER_MACHINE_DIRECTORY)
    1.11 +	cp system.db $(PER_MACHINE_DIRECTORY)
    1.12 +endif
    1.13  
    1.14  .PHONY: clean
    1.15  clean:
     2.1 --- a/src/Makefile	Mon Sep 23 12:39:38 2019 +0200
     2.2 +++ b/src/Makefile	Fri Sep 27 12:27:39 2019 +0200
     2.3 @@ -10,7 +10,7 @@
     2.4  endif
     2.5  
     2.6  ifdef PER_MACHINE_DIRECTORY
     2.7 -	EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY=$(PER_MACHINE_DIRECTORY)
     2.8 +	EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY=\"$(PER_MACHINE_DIRECTORY)\"
     2.9  endif
    2.10  
    2.11  CFLAGS+= $(ETPAN_INC) $(PEP_MIME_INC) -I../asn.1 $(EXTRA_MACROS)
     3.1 --- a/src/message_api.c	Mon Sep 23 12:39:38 2019 +0200
     3.2 +++ b/src/message_api.c	Fri Sep 27 12:27:39 2019 +0200
     3.3 @@ -4054,26 +4054,48 @@
     3.4  
     3.5      message *msg = *dst ? *dst : src;
     3.6  
     3.7 -    if (status == PEP_UNENCRYPTED || status == PEP_DECRYPTED_AND_VERIFIED) {
     3.8 -        if (session->inject_sync_event && msg && msg->from &&
     3.9 -                !(*flags & PEP_decrypt_flag_dont_trigger_sync)) {
    3.10 -            size_t size;
    3.11 -            const char *data;
    3.12 -            char *sender_fpr = NULL;
    3.13 -            
    3.14 -            PEP_STATUS tmpstatus = base_extract_message(session, msg, &size, &data, &sender_fpr);
    3.15 -            if (!tmpstatus && size && data) {
    3.16 -                const char* event_sender_fpr = ((*dst)->_sender_fpr ? (*dst)->_sender_fpr : sender_fpr);
    3.17 -                // FIXME - I don't think this is OK anymore. We either have a signed beacon or a properly encrypted/signed 2.1 message
    3.18 -                // if ((!event_sender_fpr) && *keylist)
    3.19 -                //     event_sender_fpr = (*keylist)->value;
    3.20 -                if (event_sender_fpr)
    3.21 -                    signal_Sync_message(session, *rating, data, size, msg->from, event_sender_fpr);
    3.22 -            }
    3.23 -            free(sender_fpr);
    3.24 +    if (session->inject_sync_event && msg && msg->from &&
    3.25 +            !(*flags & PEP_decrypt_flag_dont_trigger_sync)) {
    3.26 +        size_t size;
    3.27 +        const char *data;
    3.28 +        char *sender_fpr = NULL;
    3.29 +        PEP_STATUS tmpstatus = base_extract_message(session, msg, &size, &data, &sender_fpr);
    3.30 +        if (!tmpstatus && size && data) {
    3.31 +            if (sender_fpr)
    3.32 +                signal_Sync_message(session, *rating, data, size, msg->from, sender_fpr);
    3.33 +            // FIXME: this must be changed to sender_fpr
    3.34 +            else if (*keylist)
    3.35 +                signal_Sync_message(session, *rating, data, size, msg->from, (*keylist)->value);
    3.36          }
    3.37 +        free(sender_fpr);
    3.38      }
    3.39  
    3.40 +
    3.41 +    // Removed for now - partial fix in ENGINE-647, but we have sync issues. Need to 
    3.42 +    // fix testing issue.
    3.43 +    //
    3.44 +    // if (status == PEP_UNENCRYPTED || status == PEP_DECRYPTED_AND_VERIFIED) {
    3.45 +    //     if (session->inject_sync_event && msg && msg->from &&
    3.46 +    //             !(*flags & PEP_decrypt_flag_dont_trigger_sync)) {
    3.47 +    //         size_t size;
    3.48 +    //         const char *data;
    3.49 +    //         char *sender_fpr = NULL;
    3.50 +    // 
    3.51 +    //         PEP_STATUS tmpstatus = base_extract_message(session, msg, &size, &data, &sender_fpr);
    3.52 +    //         if (!tmpstatus && size && data) {
    3.53 +    //             bool use_extracted_fpr = (status != PEP_DECRYPTED_AND_VERIFIED) ||
    3.54 +    //                                       !dst || !(*dst) || !((*dst)->_sender_fpr);
    3.55 +    // 
    3.56 +    //             const char* event_sender_fpr = (use_extracted_fpr ? sender_fpr : (*dst)->_sender_fpr);
    3.57 +    //             // FIXME - I don't think this is OK anymore. We either have a signed beacon or a properly encrypted/signed 2.1 message
    3.58 +    //             // if ((!event_sender_fpr) && *keylist)
    3.59 +    //             //     event_sender_fpr = (*keylist)->value;
    3.60 +    //             if (event_sender_fpr)
    3.61 +    //                 signal_Sync_message(session, *rating, data, size, msg->from, event_sender_fpr);
    3.62 +    //         }
    3.63 +    //         free(sender_fpr);
    3.64 +    //     }
    3.65 +
    3.66      return status;
    3.67  }
    3.68  
     4.1 --- a/src/platform_unix.c	Mon Sep 23 12:39:38 2019 +0200
     4.2 +++ b/src/platform_unix.c	Fri Sep 27 12:27:39 2019 +0200
     4.3 @@ -305,11 +305,25 @@
     4.4      free(_new);
     4.5  }
     4.6  
     4.7 -DYNAMIC_API const char *per_user_directory(void)
     4.8 +#ifndef NDEBUG
     4.9 +static const char *_per_user_directory(int reset)
    4.10 +#else 
    4.11 +static const char *_per_user_directory(void)
    4.12 +#endif
    4.13  {
    4.14      static char *path = NULL;
    4.15 +
    4.16 +#ifdef NDEBUG    
    4.17      if (path)
    4.18          return path;
    4.19 +#else        
    4.20 +    if (path && !reset)
    4.21 +        return path;
    4.22 +    else if (path) {
    4.23 +        free(path);
    4.24 +        path = NULL;
    4.25 +    }
    4.26 +#endif    
    4.27  
    4.28      const char *home = NULL;
    4.29  #ifndef NDEBUG
    4.30 @@ -355,10 +369,17 @@
    4.31  #endif
    4.32          return path;
    4.33  
    4.34 -    if (!per_user_directory())
    4.35 +    char* pathret = NULL;
    4.36 +#ifndef NDEBUG 
    4.37 +    pathret = _per_user_directory(reset);
    4.38 +#else 
    4.39 +    pathret = _per_user_directory();
    4.40 +#endif
    4.41 +
    4.42 +    if (!pathret)
    4.43          return NULL;
    4.44  
    4.45 -    path = strdup(per_user_directory());
    4.46 +    path = strdup(pathret);
    4.47      assert(path);
    4.48      if (!path)
    4.49          return NULL;
    4.50 @@ -471,6 +492,15 @@
    4.51      return path;
    4.52  }
    4.53  
    4.54 +DYNAMIC_API const char *per_user_directory(void) {
    4.55 +#ifdef NDEBUG
    4.56 +    return _per_user_directory(void);
    4.57 +#else 
    4.58 +    return _per_user_directory(false);
    4.59 +#endif
    4.60 +}
    4.61 +
    4.62 +
    4.63  static const char *gpg_conf_path = ".gnupg";
    4.64  static const char *gpg_conf_name = "gpg.conf";
    4.65  static const char *gpg_agent_conf_name = "gpg-agent.conf";
    4.66 @@ -707,4 +737,3 @@
    4.67      _empty(&path);
    4.68      return NULL;
    4.69  }
    4.70 -
     5.1 --- a/sync/gen_statemachine.ysl2	Mon Sep 23 12:39:38 2019 +0200
     5.2 +++ b/sync/gen_statemachine.ysl2	Fri Sep 27 12:27:39 2019 +0200
     5.3 @@ -824,6 +824,7 @@
     5.4                      free(session->«yml:lcase(@name)»_state.transport.sender_fpr);
     5.5                      session->«yml:lcase(@name)»_state.transport.sender_fpr = ev->sender_fpr;
     5.6                      
     5.7 +                    /* Removed for temp ENGINE-647 fix. Will be reenabled once better sync debugging is in.
     5.8                      // Check against saved comm_partner sender_fpr state, if there is one yet
     5.9                      if (session->«yml:lcase(@name)»_state.comm_partner.sender_fpr) {
    5.10                          // 1. Does it match sender_fpr?
    5.11 @@ -839,6 +840,7 @@
    5.12                              }    
    5.13                          }
    5.14                      }
    5.15 +                    */
    5.16                                                              
    5.17                      ev->sender_fpr = NULL;
    5.18                  }
     6.1 --- a/sync/sync.fsm	Mon Sep 23 12:39:38 2019 +0200
     6.2 +++ b/sync/sync.fsm	Fri Sep 27 12:27:39 2019 +0200
     6.3 @@ -17,15 +17,15 @@
     6.4              on Init {
     6.5                  if deviceGrouped
     6.6                      go Grouped;
     6.7 +                do newChallengeAndNegotiationBase;
     6.8 +                send Beacon;
     6.9                  go Sole;
    6.10              }
    6.11          }
    6.12  
    6.13          state Sole timeout=off {
    6.14              on Init {
    6.15 -                do newChallengeAndNegotiationBase;
    6.16                  do showBeingSole;
    6.17 -                send Beacon;
    6.18              }
    6.19  
    6.20              on KeyGen {