1.1 --- a/src/message_api.c Mon Mar 18 15:57:57 2019 +0100
1.2 +++ b/src/message_api.c Mon Mar 18 15:58:53 2019 +0100
1.3 @@ -3855,16 +3855,22 @@
1.4 char *sync_fpr = NULL;
1.5 PEP_STATUS tmpstatus = base_extract_message(session, msg, &size, &data, &sync_fpr);
1.6 if (!tmpstatus && size && data) {
1.7 - pEp_identity *_from = identity_dup(msg->from);
1.8 - if (!_from) {
1.9 - free_message(*dst);
1.10 - *dst = NULL;
1.11 - free_stringlist(*keylist);
1.12 - *keylist = NULL;
1.13 - return PEP_OUT_OF_MEMORY;
1.14 + if ((*keylist && strcasecmp(msg->from->fpr, (*keylist)->value))
1.15 + || (sync_fpr && strcasecmp(msg->from->fpr, sync_fpr))) {
1.16 + pEp_identity *_from = identity_dup(msg->from);
1.17 + if (!_from) {
1.18 + free_message(*dst);
1.19 + *dst = NULL;
1.20 + free_stringlist(*keylist);
1.21 + *keylist = NULL;
1.22 + free(sync_fpr);
1.23 + return PEP_OUT_OF_MEMORY;
1.24 + }
1.25 + if (session->sync_state.common.from)
1.26 + free_identity(session->sync_state.common.from);
1.27 + session->sync_state.common.from = _from;
1.28 + signal_Sync_message(session, *rating, data, size, sync_fpr);
1.29 }
1.30 - session->sync_state.common.from = _from;
1.31 - signal_Sync_message(session, *rating, data, size, sync_fpr);
1.32 }
1.33 free(sync_fpr);
1.34 }
1.35 @@ -4069,6 +4075,8 @@
1.36 if (!(session && ident && rating))
1.37 return PEP_ILLEGAL_VALUE;
1.38
1.39 + *rating = PEP_rating_undefined;
1.40 +
1.41 if (ident->me)
1.42 status = _myself(session, ident, false, true);
1.43 else
2.1 --- a/sync/gen_statemachine.ysl2 Mon Mar 18 15:57:57 2019 +0100
2.2 +++ b/sync/gen_statemachine.ysl2 Mon Mar 18 15:58:53 2019 +0100
2.3 @@ -55,7 +55,7 @@
2.4
2.5 #define «yml:ucase(@name)»_TIMEOUT_EVENT new_«@name»_event(«@name»_PR_NOTHING, 0, NULL);
2.6
2.7 -
2.8 +
2.9 // free_«@name»_event() - free memory occupied by event
2.10 //
2.11 // parameters:
2.12 @@ -321,23 +321,9 @@
2.13 if (!session->inject_«yml:lcase(@name)»_event)
2.14 return PEP_«yml:ucase(@name)»_NO_INJECT_CALLBACK;
2.15
2.16 - «@name»_t *msg = NULL;
2.17 - PEP_STATUS status = decode_«@name»_message(data, size, &msg);
2.18 - if (status)
2.19 - return status;
2.20 -
2.21 + PEP_STATUS status = PEP_STATUS_OK;
2.22 «@name»_event_t *ev = NULL;
2.23
2.24 - «@name»_PR fsm = msg->present;
2.25 - int event = 0;
2.26 -
2.27 - switch (fsm) {
2.28 - `` apply "fsm", 2, mode=signal_message
2.29 - default:
2.30 - status = PEP_«yml:ucase(@name)»_ILLEGAL_MESSAGE;
2.31 - goto the_end;
2.32 - }
2.33 -
2.34 if (fpr) {
2.35 if (session->«yml:lcase(@name)»_state.common.from->fpr)
2.36 free(session->«yml:lcase(@name)»_state.common.from->fpr);
2.37 @@ -349,6 +335,21 @@
2.38 }
2.39 }
2.40
2.41 + «@name»_t *msg = NULL;
2.42 + status = decode_«@name»_message(data, size, &msg);
2.43 + if (status)
2.44 + return status;
2.45 +
2.46 + «@name»_PR fsm = msg->present;
2.47 + int event = 0;
2.48 +
2.49 + switch (fsm) {
2.50 + `` apply "fsm", 2, mode=signal_message
2.51 + default:
2.52 + status = PEP_«yml:ucase(@name)»_ILLEGAL_MESSAGE;
2.53 + goto the_end;
2.54 + }
2.55 +
2.56 ev = new_«@name»_event(fsm, event, msg);
2.57 if (!ev) {
2.58 status = PEP_OUT_OF_MEMORY;
2.59 @@ -449,6 +450,7 @@
2.60 goto the_end;
2.61 }
2.62 }
2.63 + break;
2.64
2.65 default:
2.66 status = PEP_«yml:ucase(@name)»_ILLEGAL_MESSAGE;
2.67 @@ -622,43 +624,54 @@
2.68 {
2.69 ||
2.70 case «../@name»_PR_«yml:lcase(@name)»:
2.71 - event = msg->choice.«yml:lcase(@name)».payload.present;
2.72 - switch (event) {
2.73 + switch (msg->choice.«yml:lcase(@name)».payload.present) {
2.74 ||
2.75 if "message[@security='unencrypted']" {
2.76 - | // these messages require a detached signature
2.77 - for "message[@security='unencrypted']"
2.78 - |>> case «../@name»__payload_PR_«yml:mixedCase(@name)»:
2.79 + |>> // these messages require a detached signature
2.80 + for "message[@security='unencrypted']" {
2.81 ||
2.82 + case «../@name»__payload_PR_«yml:mixedCase(@name)»:
2.83 if (!fpr) {
2.84 status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;
2.85 goto the_end;
2.86 }
2.87 + event = «@name»;
2.88 + break;
2.89 +
2.90 + ||
2.91 + }
2.92 + }
2.93 + if "message[@security='untrusted']" {
2.94 + |>> // these messages must arrive encrypted
2.95 + for "message[@security='untrusted']" {
2.96 + ||
2.97 + case «../@name»__payload_PR_«yml:mixedCase(@name)»:
2.98 + if (rating < PEP_rating_reliable) {
2.99 + status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;
2.100 + goto the_end;
2.101 + }
2.102 + event = «@name»;
2.103 break;
2.104
2.105 ||
2.106 + }
2.107 }
2.108 - if "message[@security='untrusted']"
2.109 - ||
2.110 - // these messages must arrive encrypted
2.111 - `` for "message[@security='untrusted']" |>> case «../@name»__payload_PR_«yml:mixedCase(@name)»:
2.112 - if (fpr || rating < PEP_rating_reliable) {
2.113 - status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;
2.114 - goto the_end;
2.115 - }
2.116 - break;
2.117 + if "message[@security='trusted']" {
2.118 + |>> // these messages must come through a trusted channel
2.119 + for "message[@security='trusted']" {
2.120 + ||
2.121 + case «../@name»__payload_PR_«yml:mixedCase(@name)»:
2.122 + if (rating < PEP_rating_trusted) {
2.123 + status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;
2.124 + goto the_end;
2.125 + }
2.126 + event = «@name»;
2.127 + break;
2.128
2.129 - ||
2.130 - if "message[@security='trusted']"
2.131 + ||
2.132 + }
2.133 + }
2.134 ||
2.135 - // these messages must come through a trusted channel
2.136 - `` for "message[@security='trusted']" |>> case «ancestor::fsm/@name»__payload_PR_«yml:mixedCase(@name)»:
2.137 - if (fpr || rating < PEP_rating_trusted) {
2.138 - status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;
2.139 - goto the_end;
2.140 - }
2.141 - break;
2.142 -
2.143 default:
2.144 status = PEP_«yml:ucase(ancestor::protocol/@name)»_ILLEGAL_MESSAGE;
2.145 goto the_end;
3.1 --- a/sync/sync.fsm Mon Mar 18 15:57:57 2019 +0100
3.2 +++ b/sync/sync.fsm Mon Mar 18 15:58:53 2019 +0100
3.3 @@ -42,6 +42,7 @@
3.4 do openTransaction;
3.5 do storeTransaction;
3.6 send HandshakeRequest;
3.7 + go HandshakeRequested;
3.8 }
3.9 }
3.10
3.11 @@ -56,6 +57,9 @@
3.12 }
3.13 }
3.14
3.15 + }
3.16 +
3.17 + state HandshakeRequested {
3.18 on HandshakeAnswer
3.19 go HandshakingNew();
3.20 }
3.21 @@ -312,13 +316,11 @@
3.22 field TID challenge;
3.23 auto Version version;
3.24 field TID transaction;
3.25 - field Hash fpr;
3.26 field bool is_group;
3.27 }
3.28
3.29 message HandshakeAnswer 4 {
3.30 field TID transaction;
3.31 - field Hash fpr;
3.32 }
3.33
3.34 message Rollback 5, security=untrusted {