merge "default" into my branch ENGINE-199
authorRoker <roker@pep-project.org>
Thu, 20 Apr 2017 10:37:10 +0200
branchENGINE-199
changeset 17283c032ad43e6e
parent 1722 1d16b6822287
parent 1727 7a905529fc0e
child 1729 1dd554ac85d1
merge "default" into my branch
     1.1 --- a/src/message_api.c	Wed Apr 19 17:44:19 2017 +0200
     1.2 +++ b/src/message_api.c	Thu Apr 20 10:37:10 2017 +0200
     1.3 @@ -2563,12 +2563,20 @@
     1.4                                                  keylist,
     1.5                                                  rating,
     1.6                                                  flags);
     1.7 -                                                
     1.8 +    if (decrypt_status > PEP_CANNOT_DECRYPT_UNKNOWN)
     1.9 +    {
    1.10 +        status = decrypt_status;
    1.11 +        goto pep_error;
    1.12 +    }
    1.13 +
    1.14      status = mime_encode_message(dec_msg, false, mime_plaintext);
    1.15  
    1.16      if (status == PEP_STATUS_OK)
    1.17 +    {
    1.18 +        free(tmp_msg);
    1.19          return decrypt_status;
    1.20 -        
    1.21 +    }
    1.22 +    
    1.23  pep_error:
    1.24      free_message(tmp_msg);
    1.25      free_message(dec_msg);
     2.1 --- a/src/sync_actions.c	Wed Apr 19 17:44:19 2017 +0200
     2.2 +++ b/src/sync_actions.c	Thu Apr 20 10:37:10 2017 +0200
     2.3 @@ -105,6 +105,23 @@
     2.4      return 1;
     2.5  }
     2.6  
     2.7 +int sameKeyAndAddress(PEP_SESSION session, Identity a, Identity b)
     2.8 +{
     2.9 +    assert(session);
    2.10 +    assert(a);
    2.11 +    assert(b);
    2.12 +
    2.13 +    if (!(session && a && b))
    2.14 +        return invalid_condition; // error
    2.15 +
    2.16 +    if (a->fpr == NULL || b->fpr == NULL ||
    2.17 +        (!_same_fpr(a->fpr, strlen(a->fpr), b->fpr, strlen(b->fpr))) ||
    2.18 +        a->address == NULL || b->address == NULL ||
    2.19 +        strcmp(a->address, b->address) != 0)
    2.20 +            return 0;
    2.21 +    return 1;
    2.22 +}
    2.23 +
    2.24  // actions
    2.25  
    2.26  PEP_STATUS _notifyHandshake(
     3.1 --- a/sync/devicegroup.fsm	Wed Apr 19 17:44:19 2017 +0200
     3.2 +++ b/sync/devicegroup.fsm	Thu Apr 20 10:37:10 2017 +0200
     3.3 @@ -21,6 +21,7 @@
     3.4          condition deviceGrouped();
     3.5          condition keyElectionWon(Identity partner);
     3.6          condition sameIdentities(Identity a, Identity b);
     3.7 +        condition sameKeyAndAddress(Identity a, Identity b);
     3.8  
     3.9          state InitState {
    3.10              on Init {
    3.11 @@ -71,10 +72,10 @@
    3.12  
    3.13          state HandshakingSole timeout=600 (Identity expected) {
    3.14              on Init{
    3.15 -                if keyElectionWon(partner) {
    3.16 -                    do notifyInitFormGroup(partner);
    3.17 +                if keyElectionWon(expected) {
    3.18 +                    do notifyInitFormGroup(expected);
    3.19                  } else {
    3.20 -                    do notifyInitAddOurDevice(partner);
    3.21 +                    do notifyInitAddOurDevice(expected);
    3.22                  }
    3.23              }
    3.24              on HandshakeRejected(Identity partner) {
    3.25 @@ -97,10 +98,11 @@
    3.26              }
    3.27              on Cancel go Sole;
    3.28              on GroupKeys(Identity partner, GroupKeys groupkeys) {
    3.29 -                if keyElectionWon(partner) {
    3.30 -                    // not suppose to receive groupkeys - ignore
    3.31 +                if keyElectionWon(expected) {
    3.32 +                    // not supposed to receive groupkeys - ignore
    3.33                  } else {
    3.34 -                    if sameIdentities(partner, expected) {
    3.35 +                    // UUID changes in between, so we can only check for same address and fpr
    3.36 +                    if sameKeyAndAddress(partner, expected) {
    3.37                          go WaitForAcceptSole(partner, groupkeys);
    3.38                      }
    3.39                  }
    3.40 @@ -114,7 +116,8 @@
    3.41      
    3.42          state WaitForGroupKeysSole timeout=600 (Identity expected) {
    3.43              on GroupKeys(Identity partner, GroupKeys groupkeys) {
    3.44 -                if sameIdentities(partner, expected) {
    3.45 +                // UUID changes in between, so we can only check for same address and fpr
    3.46 +                if sameKeyAndAddress(partner, expected) {
    3.47                      do storeGroupKeys(partner, groupkeys);
    3.48                      do sendGroupUpdate;
    3.49                      do renewUUID;
    3.50 @@ -134,7 +137,8 @@
    3.51                  go Sole;
    3.52              }
    3.53              on HandshakeAccepted(Identity partner) {
    3.54 -                if sameIdentities(partner, expected) {
    3.55 +                // UUID changes in between, so we can only check for same address and fpr
    3.56 +                if sameKeyAndAddress(partner, expected) {
    3.57                      do acceptHandshake(partner); 
    3.58                      do storeGroupKeys(partner, groupkeys);
    3.59                      do sendGroupUpdate;
    3.60 @@ -201,7 +205,7 @@
    3.61          state HandshakingGrouped timeout=600 (Identity expected) {
    3.62              // HandshakeRequest from same group are filtered in receive_sync_msg
    3.63              on Init{
    3.64 -                if keyElectionWon(partner) {
    3.65 +                if keyElectionWon(expected) {
    3.66                      do notifyInitAddOtherDevice(partner);
    3.67                  } else {
    3.68                      do notifyInitMoveOurDevice(partner);
    3.69 @@ -224,8 +228,13 @@
    3.70              }
    3.71              on Cancel go Grouped;
    3.72              on GroupKeys(Identity partner, GroupKeys groupkeys) {
    3.73 -                if sameIdentities(partner, expected) {
    3.74 -                    go WaitForAcceptGrouped(partner, groupkeys);
    3.75 +                if keyElectionWon(expected) {
    3.76 +                    // not supposed to receive groupkeys - ignore
    3.77 +                } else {
    3.78 +                    // UUID changes in between, so we can only check for same address and fpr
    3.79 +                    if sameKeyAndAddress(partner, expected) {
    3.80 +                        go WaitForAcceptGrouped(partner, groupkeys);
    3.81 +                    }
    3.82                  }
    3.83              }
    3.84              on GroupUpdate(Identity partner, IdentityList keys) {
     4.1 --- a/sync/generated/sync_fsm.c	Wed Apr 19 17:44:19 2017 +0200
     4.2 +++ b/sync/generated/sync_fsm.c	Thu Apr 20 10:37:10 2017 +0200
     4.3 @@ -283,7 +283,7 @@
     4.4                  {
     4.5                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Init")
     4.6                      {
     4.7 -                        int cond_result = keyElectionWon(session, partner);
     4.8 +                        int cond_result = keyElectionWon(session, expected);
     4.9                          #ifndef NDEBUG
    4.10                          char resstr[11] = {0,};
    4.11                          snprintf(resstr,10,"result=%d",cond_result);
    4.12 @@ -293,7 +293,7 @@
    4.13                              return cond_result;
    4.14                          if (cond_result) {
    4.15                          DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitFormGroup")
    4.16 -                        status = notifyInitFormGroup(session, state, partner, NULL);
    4.17 +                        status = notifyInitFormGroup(session, state, expected, NULL);
    4.18                          if (status == PEP_OUT_OF_MEMORY)
    4.19                              return (int) invalid_out_of_memory;
    4.20                          if (status != PEP_STATUS_OK)
    4.21 @@ -301,7 +301,7 @@
    4.22                          }
    4.23                          else {
    4.24                          DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitAddOurDevice")
    4.25 -                        status = notifyInitAddOurDevice(session, state, partner, NULL);
    4.26 +                        status = notifyInitAddOurDevice(session, state, expected, NULL);
    4.27                          if (status == PEP_OUT_OF_MEMORY)
    4.28                              return (int) invalid_out_of_memory;
    4.29                          if (status != PEP_STATUS_OK)
    4.30 @@ -427,7 +427,7 @@
    4.31                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=GroupKeys")
    4.32                      group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
    4.33                      {
    4.34 -                        int cond_result = keyElectionWon(session, partner);
    4.35 +                        int cond_result = keyElectionWon(session, expected);
    4.36                          #ifndef NDEBUG
    4.37                          char resstr[11] = {0,};
    4.38                          snprintf(resstr,10,"result=%d",cond_result);
    4.39 @@ -439,12 +439,12 @@
    4.40                          }
    4.41                          else {
    4.42                          {
    4.43 -                            int cond_result = sameIdentities(session, partner, expected);
    4.44 +                            int cond_result = sameKeyAndAddress(session, partner, expected);
    4.45                              #ifndef NDEBUG
    4.46                              char resstr[11] = {0,};
    4.47                              snprintf(resstr,10,"result=%d",cond_result);
    4.48                              #endif
    4.49 -                            DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys, condition=sameIdentities", resstr)
    4.50 +                            DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys, condition=sameKeyAndAddress", resstr)
    4.51                              if (cond_result < 0)
    4.52                                  return cond_result;
    4.53                              if (cond_result) {
    4.54 @@ -512,12 +512,12 @@
    4.55                      DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=GroupKeys")
    4.56                      group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
    4.57                      {
    4.58 -                        int cond_result = sameIdentities(session, partner, expected);
    4.59 +                        int cond_result = sameKeyAndAddress(session, partner, expected);
    4.60                          #ifndef NDEBUG
    4.61                          char resstr[11] = {0,};
    4.62                          snprintf(resstr,10,"result=%d",cond_result);
    4.63                          #endif
    4.64 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys, condition=sameIdentities", resstr)
    4.65 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys, condition=sameKeyAndAddress", resstr)
    4.66                          if (cond_result < 0)
    4.67                              return cond_result;
    4.68                          if (cond_result) {
    4.69 @@ -612,12 +612,12 @@
    4.70                  {
    4.71                      DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=HandshakeAccepted")
    4.72                      {
    4.73 -                        int cond_result = sameIdentities(session, partner, expected);
    4.74 +                        int cond_result = sameKeyAndAddress(session, partner, expected);
    4.75                          #ifndef NDEBUG
    4.76                          char resstr[11] = {0,};
    4.77                          snprintf(resstr,10,"result=%d",cond_result);
    4.78                          #endif
    4.79 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted, condition=sameIdentities", resstr)
    4.80 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted, condition=sameKeyAndAddress", resstr)
    4.81                          if (cond_result < 0)
    4.82                              return cond_result;
    4.83                          if (cond_result) {
    4.84 @@ -951,7 +951,7 @@
    4.85                  {
    4.86                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Init")
    4.87                      {
    4.88 -                        int cond_result = keyElectionWon(session, partner);
    4.89 +                        int cond_result = keyElectionWon(session, expected);
    4.90                          #ifndef NDEBUG
    4.91                          char resstr[11] = {0,};
    4.92                          snprintf(resstr,10,"result=%d",cond_result);
    4.93 @@ -1076,29 +1076,43 @@
    4.94                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=GroupKeys")
    4.95                      group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
    4.96                      {
    4.97 -                        int cond_result = sameIdentities(session, partner, expected);
    4.98 +                        int cond_result = keyElectionWon(session, expected);
    4.99                          #ifndef NDEBUG
   4.100                          char resstr[11] = {0,};
   4.101                          snprintf(resstr,10,"result=%d",cond_result);
   4.102                          #endif
   4.103 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys, condition=sameIdentities", resstr)
   4.104 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys, condition=keyElectionWon", resstr)
   4.105                          if (cond_result < 0)
   4.106                              return cond_result;
   4.107                          if (cond_result) {
   4.108 -                        assert(session->sync_state_payload);
   4.109 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   4.110 -                        free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
   4.111 -                        free(session->sync_state_payload);
   4.112 -                        session->sync_state_payload = NULL;
   4.113 -                        session->sync_state_payload = malloc(sizeof(WaitForAcceptGrouped_state_payload_t));
   4.114 -                        assert(session->sync_state_payload);
   4.115 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
   4.116 -                        ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected =
   4.117 -                            identity_dup(partner);
   4.118 -                        ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->groupkeys =
   4.119 -                            group_keys_extra_dup(groupkeys);
   4.120 -                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys", "target=WaitForAcceptGrouped")
   4.121 -                        return WaitForAcceptGrouped;
   4.122 +                        }
   4.123 +                        else {
   4.124 +                        {
   4.125 +                            int cond_result = sameKeyAndAddress(session, partner, expected);
   4.126 +                            #ifndef NDEBUG
   4.127 +                            char resstr[11] = {0,};
   4.128 +                            snprintf(resstr,10,"result=%d",cond_result);
   4.129 +                            #endif
   4.130 +                            DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys, condition=sameKeyAndAddress", resstr)
   4.131 +                            if (cond_result < 0)
   4.132 +                                return cond_result;
   4.133 +                            if (cond_result) {
   4.134 +                            assert(session->sync_state_payload);
   4.135 +                            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
   4.136 +                            free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
   4.137 +                            free(session->sync_state_payload);
   4.138 +                            session->sync_state_payload = NULL;
   4.139 +                            session->sync_state_payload = malloc(sizeof(WaitForAcceptGrouped_state_payload_t));
   4.140 +                            assert(session->sync_state_payload);
   4.141 +                            if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
   4.142 +                            ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected =
   4.143 +                                identity_dup(partner);
   4.144 +                            ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->groupkeys =
   4.145 +                                group_keys_extra_dup(groupkeys);
   4.146 +                            DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys", "target=WaitForAcceptGrouped")
   4.147 +                            return WaitForAcceptGrouped;
   4.148 +                            }
   4.149 +                        }
   4.150                          }
   4.151                      }
   4.152                      break;
     5.1 --- a/sync/generated/sync_fsm.h	Wed Apr 19 17:44:19 2017 +0200
     5.2 +++ b/sync/generated/sync_fsm.h	Thu Apr 20 10:37:10 2017 +0200
     5.3 @@ -32,6 +32,7 @@
     5.4  int deviceGrouped(PEP_SESSION session);
     5.5  int keyElectionWon(PEP_SESSION session, Identity partner);
     5.6  int sameIdentities(PEP_SESSION session, Identity a, Identity b);
     5.7 +int sameKeyAndAddress(PEP_SESSION session, Identity a, Identity b);
     5.8  
     5.9  // states
    5.10  
     6.1 --- a/sync/skeletons/sync_actions.c	Wed Apr 19 17:44:19 2017 +0200
     6.2 +++ b/sync/skeletons/sync_actions.c	Thu Apr 20 10:37:10 2017 +0200
     6.3 @@ -28,8 +28,8 @@
     6.4      PEP_STATUS status = PEP_STATUS_OK;
     6.5  
     6.6      assert(session);
     6.7 -    assert(partner);
     6.8 -    if (!(session && partner))
     6.9 +    assert(!partner);
    6.10 +    if (!(session && !partner))
    6.11          return PEP_ILLEGAL_VALUE;
    6.12  
    6.13      // working code
    6.14 @@ -65,8 +65,8 @@
    6.15      PEP_STATUS status = PEP_STATUS_OK;
    6.16  
    6.17      assert(session);
    6.18 -    assert(partner);
    6.19 -    if (!(session && partner))
    6.20 +    assert(!partner);
    6.21 +    if (!(session && !partner))
    6.22          return PEP_ILLEGAL_VALUE;
    6.23  
    6.24      // working code