... sync
authorVolker Birk <vb@pep.foundation>
Thu, 09 Aug 2018 12:26:53 +0200
branchsync
changeset 2831be6623599adb
parent 2830 d6f044e43e1a
child 2832 e03dfbbaf5ef
...
.hgignore
asn.1/devicegroup.asn1
asn.1/protocols.asn1
src/fsm_common.h
sync/cond_act.yml2
sync/devicegroup.fsm
sync/gen_message_func.ysl2
sync/gen_messages.ysl2
sync/generated/sync_driver.c
sync/generated/sync_fsm.c
sync/generated/sync_fsm.h
sync/generated/sync_send_actions.c
sync/skeletons/sync_actions.c
sync/sync.fsm
sync/sync_protocol.txt
sync/sync_ux.txt
test/Makefile
     1.1 --- a/.hgignore	Thu Aug 09 12:15:44 2018 +0200
     1.2 +++ b/.hgignore	Thu Aug 09 12:26:53 2018 +0200
     1.3 @@ -41,13 +41,7 @@
     1.4  test/msg_encrypt_for_self.asc
     1.5  tags
     1.6  asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj.user
     1.7 -src/sync_fsm.c
     1.8 -src/sync_fsm.h
     1.9 -src/sync_driver.c
    1.10 -src/sync_send_actions.c
    1.11 -sync/.actions
    1.12 -sync/.codegen
    1.13 -sync/.statemachines
    1.14 +sync/generated
    1.15  *.xml
    1.16  *.dot
    1.17  *.svg
    1.18 @@ -68,3 +62,15 @@
    1.19  .tags
    1.20  */.tags
    1.21  */*/.tags
    1.22 +asn.1/.generated
    1.23 +src/KeySync_fsm.c
    1.24 +src/KeySync_fsm.h
    1.25 +src/Sync_func.c
    1.26 +src/Sync_func.h
    1.27 +asn.1/keysync.asn1
    1.28 +asn.1/sync.asn1
    1.29 +sync/.codecs
    1.30 +sync/.messages
    1.31 +sync/.actions
    1.32 +sync/.codegen
    1.33 +sync/.statemachines
     2.1 --- a/asn.1/devicegroup.asn1	Thu Aug 09 12:15:44 2018 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,60 +0,0 @@
     2.4 -/* This file is under GNU General Public License 3.0 */
     2.5 -/* see LICENSE.txt */
     2.6 -
     2.7 -DEVICEGROUP
     2.8 -    { iso(1) org(3) dod(6) internet(1) private(4) enterprise(1) pEp (47878) sync(1) keysync(1) }
     2.9 -
    2.10 -DEFINITIONS AUTOMATIC TAGS EXTENSIBILITY IMPLIED ::=
    2.11 -
    2.12 -BEGIN
    2.13 -
    2.14 -EXPORTS DeviceGroup-Protocol;
    2.15 -IMPORTS Version, Identity, IdentityList FROM PEP;
    2.16 -
    2.17 -Beacon ::= NULL
    2.18 -
    2.19 -HandshakeRequest ::= SEQUENCE {
    2.20 -    /* UUID of receiver, group UUID if grouped */
    2.21 -    partner-id     UTF8String  (SIZE(1..1024)) OPTIONAL,
    2.22 -    /* Group UUID of sender, if grouped */
    2.23 -    group-id       UTF8String  (SIZE(1..1024)) OPTIONAL
    2.24 -}
    2.25 -
    2.26 -GroupKeys ::= SEQUENCE {
    2.27 -    /* UUID of receiver */
    2.28 -    partner-id     UTF8String  (SIZE(1..1024)) OPTIONAL,
    2.29 -    /* Group UUID of sender */
    2.30 -    group-id       UTF8String  (SIZE(1..1024)) OPTIONAL,
    2.31 -    ownIdentities IdentityList
    2.32 -}
    2.33 -
    2.34 -GroupUpdate ::= SEQUENCE {
    2.35 -    ownIdentities IdentityList
    2.36 -}
    2.37 -
    2.38 -/* TODO: narrow request to single key */
    2.39 -UpdateRequest ::= NULL 
    2.40 -
    2.41 -/* for the tags see end of sync.fsm */
    2.42 -
    2.43 -DeviceGroup-Protocol ::= SEQUENCE {
    2.44 -    header SEQUENCE {
    2.45 -        version     Version,
    2.46 -        sequence    INTEGER,  /* always increases */
    2.47 -        me          Identity, /* identity of the sender */
    2.48 -        state       INTEGER,  /* state the sender is in */
    2.49 -        devicegroup BOOLEAN
    2.50 -            /* signals if this message is coming from a device group member */
    2.51 -    },
    2.52 -
    2.53 -    payload CHOICE {
    2.54 -        beacon [APPLICATION 2] Beacon,
    2.55 -        handshakeRequest [APPLICATION 3] HandshakeRequest,
    2.56 -        groupKeys [APPLICATION 4] GroupKeys,
    2.57 -        groupUpdate [APPLICATION 5] GroupUpdate,
    2.58 -        updateRequest [APPLICATION 6] UpdateRequest
    2.59 -    }
    2.60 -}
    2.61 -
    2.62 -END
    2.63 -
     3.1 --- a/asn.1/protocols.asn1	Thu Aug 09 12:15:44 2018 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,17 +0,0 @@
     3.4 -/* This file is under GNU General Public License 3.0 */
     3.5 -/* see LICENSE.txt */
     3.6 -
     3.7 -SYNC
     3.8 -
     3.9 -DEFINITIONS AUTOMATIC TAGS EXTENSIBILITY IMPLIED ::=
    3.10 -
    3.11 -BEGIN
    3.12 -
    3.13 -IMPORTS DeviceGroup-Protocol FROM DEVICEGROUP;
    3.14 -
    3.15 -Sync-Protocols ::= CHOICE {
    3.16 -    deviceGroup [APPLICATION 1] DeviceGroup-Protocol
    3.17 -}
    3.18 -
    3.19 -END
    3.20 -
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/fsm_common.h	Thu Aug 09 12:26:53 2018 +0200
     4.3 @@ -0,0 +1,43 @@
     4.4 +// This file is under GNU General Public License 3.0
     4.5 +// see LICENSE.txt
     4.6 +
     4.7 +// generate state machine code
     4.8 +
     4.9 +// Copyleft (c) 2017, p≡p foundation
    4.10 +
    4.11 +// Written by Volker Birk
    4.12 +
    4.13 +
    4.14 +#pragma once
    4.15 +
    4.16 +#ifdef __cplusplus
    4.17 +extern "C" {
    4.18 +#endif
    4.19 +
    4.20 +// error values
    4.21 +
    4.22 +typedef enum _fsm_error {
    4.23 +    // these error values are corresponding to
    4.24 +    // PEP_SYNC_STATEMACHINE_ERROR - value
    4.25 +    invalid_state = -2,
    4.26 +    invalid_event = -3,
    4.27 +    invalid_condition = -4,
    4.28 +    invalid_action = -5,
    4.29 +
    4.30 +    // out of memory condition
    4.31 +    invalid_out_of_memory = -128,
    4.32 +} fsm_error;
    4.33 +
    4.34 +// common
    4.35 +
    4.36 +enum {
    4.37 +    End = -1,
    4.38 +    None = 0,
    4.39 +    Init = 1,
    4.40 +    Extra = 128 // messages will be below this ID
    4.41 +};
    4.42 +
    4.43 +#ifdef __cplusplus
    4.44 +}
    4.45 +#endif
    4.46 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/sync/cond_act.yml2	Thu Aug 09 12:26:53 2018 +0200
     5.3 @@ -0,0 +1,285 @@
     5.4 +// This file is under GNU General Public License 3.0
     5.5 +// see LICENSE.txt
     5.6 +
     5.7 +// generate conditions and actions
     5.8 +
     5.9 +// Copyleft (c) 2017, p≡p foundation
    5.10 +
    5.11 +// Written by Volker Birk
    5.12 +
    5.13 +
    5.14 +// prepare SQL statement
    5.15 +
    5.16 +function "init_sql" {
    5.17 +    param "sql";
    5.18 +    ||
    5.19 +        static const char *sql = `copy '$sql'`;
    5.20 +        static const size_t len = sizeof(`copy '$sql'`);
    5.21 +        sqlite3_stmt *_sql;
    5.22 +        int int_result = sqlite3_prepare_v2(session->db, sql, (int) len, &_sql, NULL);
    5.23 +        assert(int_result == SQLITE_OK);
    5.24 +        if (!(int_result == SQLITE_OK))
    5.25 +            return PEP_UNKNOWN_ERROR;
    5.26 +
    5.27 +    ||
    5.28 +}
    5.29 +
    5.30 +// exec_sql_* is returning _result
    5.31 +
    5.32 +function "exec_sql_int" {
    5.33 +    param "sql";
    5.34 +    call "init_sql" with "sql", "$sql";
    5.35 +    ||
    5.36 +        int _result = 0;
    5.37 +        int_result = sqlite3_step(_sql);
    5.38 +        assert(int_result == SQLITE_ROW);
    5.39 +        if (int_result == SQLITE_ROW)
    5.40 +            _result = sqlite3_column_int(_sql, 0);
    5.41 +        sqlite3_finalize(_sql);
    5.42 +        if (int_result != SQLITE_ROW)
    5.43 +            return PEP_UNKNOWN_ERROR;
    5.44 +
    5.45 +    ||
    5.46 +}
    5.47 +
    5.48 +// condition: PEP_STATUS «@name»(PEP_SESSION session, bool *result)
    5.49 +
    5.50 +condition deviceGrouped {
    5.51 +    call "exec_sql_int" with "sql"
    5.52 +        > "select count(*) from identity where user_id = '"PEP_OWN_USERID"' and (flags & 4) = 4;"
    5.53 +    |> *result = _result > 0;
    5.54 +}
    5.55 +
    5.56 +condition partnerIsGrouped
    5.57 +|> *result = session->sync_state.keysync.is_group;
    5.58 +
    5.59 +condition challengeAccepted
    5.60 +||
    5.61 +    TID_t *t1 = &session->sync_state.keysync.challenge;
    5.62 +    TID_t *t2 = &session->own_sync_state.challenge;
    5.63 +
    5.64 +    *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    5.65 +||
    5.66 +
    5.67 +condition keyElectionWon
    5.68 +||
    5.69 +    pEp_identity *from = session->sync_state.basic.from;
    5.70 +
    5.71 +    assert(from && from->fpr && from->fpr[0] && from->address && from->address[0]);
    5.72 +    if (!(from && from->fpr && from->fpr[0] && from->address && from->address[0]))
    5.73 +        return PEP_ILLEGAL_VALUE;
    5.74 +
    5.75 +    pEp_identity *me = NULL;
    5.76 +    PEP_STATUS status = get_identity(session, from->address, PEP_OWN_USERID, &me);
    5.77 +    assert(status == PEP_STATUS_OK);
    5.78 +    if (status)
    5.79 +        return status;
    5.80 +
    5.81 +    assert(me->fpr && me->fpr[0]);
    5.82 +    if (!(me->fpr && me->fpr[0])) {
    5.83 +        free_identity(me);
    5.84 +        return PEP_ILLEGAL_VALUE;
    5.85 +    }
    5.86 +
    5.87 +    size_t len = MIN(strlen(from->fpr), strlen(me->fpr));
    5.88 +    *result = strncasecmp(from->fpr, me->fpr, len) > 0;
    5.89 +    free_identity(me);
    5.90 +||
    5.91 +
    5.92 +// action: PEP_STATUS «@name»(PEP_SESSION session)
    5.93 +
    5.94 +action closeHandshakeDialog
    5.95 +||
    5.96 +    assert(session->notifyHandshake);
    5.97 +    if (!session->notifyHandshake)
    5.98 +        return PEP_SYNC_NO_NOTIFY_CALLBACK;
    5.99 +
   5.100 +    PEP_STATUS status = session->notifyHandshake(
   5.101 +            session->sync_management, NULL, NULL, SYNC_NOTIFY_OVERTAKEN);
   5.102 +    if (status)
   5.103 +        return status;
   5.104 +||
   5.105 +
   5.106 +function "new_UUID" {
   5.107 +    param "dst";
   5.108 +    ||
   5.109 +        pEpUUID c;
   5.110 +        uuid_generate_random(c);
   5.111 +
   5.112 +        OCTET_STRING_fromBuf(«$dst», (char *) c, 16);
   5.113 +    ||
   5.114 +}
   5.115 +
   5.116 +function "copy_UUID" {
   5.117 +    param "src", param "dst";
   5.118 +    ||
   5.119 +        TID_t *src = «$src»;
   5.120 +        TID_t *dst = «$dst»;
   5.121 +
   5.122 +        assert(src->size == 16);
   5.123 +        if (!(src->size == 16))
   5.124 +            return PEP_UNKNOWN_ERROR;
   5.125 +
   5.126 +        OCTET_STRING_fromBuf(dst, (char *) src->buf, src->size);
   5.127 +    ||
   5.128 +}
   5.129 +
   5.130 +action openChallenge
   5.131 +    call "new_UUID" with "dst" > &session->own_sync_state.challenge
   5.132 +
   5.133 +action storeChallenge call "copy_UUID" {
   5.134 +    with "src" > &session->sync_state.keysync.challenge
   5.135 +    with "dst" > &session->own_sync_state.challenge
   5.136 +}
   5.137 +
   5.138 +action openTransaction
   5.139 +    call "new_UUID" with "dst" > &session->own_sync_state.transaction
   5.140 +
   5.141 +action storeTransaction call "copy_UUID" {
   5.142 +    with "src" > &session->sync_state.keysync.transaction
   5.143 +    with "dst" >  &session->own_sync_state.transaction
   5.144 +}
   5.145 +
   5.146 +function "show_handshake" {
   5.147 +    param "type";
   5.148 +    ||
   5.149 +        assert(session->notifyHandshake);
   5.150 +        if (!session->notifyHandshake)
   5.151 +            return PEP_SYNC_NO_NOTIFY_CALLBACK;
   5.152 +     
   5.153 +        assert(session->sync_state.basic.from);
   5.154 +        if (!session->sync_state.basic.from)
   5.155 +            return PEP_ILLEGAL_VALUE;
   5.156 +
   5.157 +        pEp_identity *from = session->sync_state.basic.from;
   5.158 +        pEp_identity *me = NULL;
   5.159 +        PEP_STATUS status = get_identity(session, from->address, PEP_OWN_USERID, &me);
   5.160 +        assert(status == PEP_STATUS_OK);
   5.161 +        if (status)
   5.162 +            return status;
   5.163 +
   5.164 +        assert(me->fpr && me->fpr[0]);
   5.165 +        if (!(me->fpr && me->fpr[0])) {
   5.166 +            free_identity(me);
   5.167 +            return PEP_ILLEGAL_VALUE;
   5.168 +        }
   5.169 +
   5.170 +        pEp_identity *partner = identity_dup(from);
   5.171 +        if (!partner) {
   5.172 +            free_identity(me);
   5.173 +            return PEP_OUT_OF_MEMORY;
   5.174 +        }
   5.175 +
   5.176 +        status = session->notifyHandshake(session->sync_management, me,
   5.177 +                partner, «$type»);
   5.178 +        if (status)
   5.179 +            return status;
   5.180 +    ||
   5.181 +}
   5.182 +
   5.183 +action showSoleHandshake
   5.184 +    call "show_handshake" with "type" > SYNC_NOTIFY_INIT_FORM_GROUP
   5.185 +
   5.186 +action showJoinGroupHandshake
   5.187 +    call "show_handshake" with "type" > SYNC_NOTIFY_INIT_ADD_OUR_DEVICE
   5.188 +
   5.189 +action showGroupedHandshake
   5.190 +    call "show_handshake" with "type" > SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE
   5.191 +
   5.192 +action saveGroupKeys
   5.193 +||
   5.194 +    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.identities, NULL);
   5.195 +    if (!il)
   5.196 +        return PEP_OUT_OF_MEMORY;
   5.197 +    
   5.198 +    // BUG: this should be a transaction and been rolled back completely on error
   5.199 +    for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
   5.200 +        PEP_STATUS status = set_identity(session, _il->ident);
   5.201 +        if (status) {
   5.202 +            free_identity_list(il);
   5.203 +            return status;
   5.204 +        }
   5.205 +    }
   5.206 +
   5.207 +    free_identity_list(il);
   5.208 +||
   5.209 +
   5.210 +action ownKeysAreGroupKeys {
   5.211 +    call "init_sql" with "sql" {
   5.212 +        ||
   5.213 +        "select fpr, username, comm_type, lang,"
   5.214 +                "   identity.flags | pgp_keypair.flags"
   5.215 +                "   from identity"
   5.216 +                "   join person on id = identity.user_id"
   5.217 +                "   join pgp_keypair on fpr = identity.main_key_id"
   5.218 +                "   join trust on id = trust.user_id"
   5.219 +                "       and pgp_keypair_fpr = identity.main_key_id"
   5.220 +        ||
   5.221 +        >         "   where identity.user_id = '" PEP_OWN_USERID "';"
   5.222 +    }
   5.223 +
   5.224 +    ||
   5.225 +        identity_list *il = new_identity_list(NULL);
   5.226 +        if (!il)
   5.227 +            return PEP_OUT_OF_MEMORY;
   5.228 +
   5.229 +        pEp_identity *from = session->sync_state.basic.from;
   5.230 +        identity_list *_il = il;
   5.231 +
   5.232 +        int result;
   5.233 +        do {
   5.234 +            result = sqlite3_step(_sql);
   5.235 +            pEp_identity *_identity = NULL;
   5.236 +            switch (result) {
   5.237 +            case SQLITE_ROW:
   5.238 +                _identity = new_identity(
   5.239 +                        from->address,
   5.240 +                        (const char *) sqlite3_column_text(_sql, 0),
   5.241 +                        from->user_id,
   5.242 +                        (const char *) sqlite3_column_text(_sql, 1)
   5.243 +                        );
   5.244 +                assert(_identity);
   5.245 +                if (_identity == NULL)
   5.246 +                    return PEP_OUT_OF_MEMORY;
   5.247 +
   5.248 +                _identity->comm_type = (PEP_comm_type)
   5.249 +                    sqlite3_column_int(_sql, 2);
   5.250 +                const char* const _lang = (const char *)
   5.251 +                    sqlite3_column_text(_sql, 3);
   5.252 +                if (_lang && _lang[0]) {
   5.253 +                    assert(_lang[0] >= 'a' && _lang[0] <= 'z');
   5.254 +                    assert(_lang[1] >= 'a' && _lang[1] <= 'z');
   5.255 +                    assert(_lang[2] == 0);
   5.256 +                    _identity->lang[0] = _lang[0];
   5.257 +                    _identity->lang[1] = _lang[1];
   5.258 +                    _identity->lang[2] = 0;
   5.259 +                }
   5.260 +                _identity->flags = (unsigned int)
   5.261 +                    sqlite3_column_int(_sql, 4);
   5.262 +
   5.263 +                _il = identity_list_add(_il, _identity);
   5.264 +                if (!_il) {
   5.265 +                    free_identity_list(il);
   5.266 +                    free_identity(_identity);
   5.267 +                    return PEP_OUT_OF_MEMORY;
   5.268 +                }
   5.269 +                break;
   5.270 +
   5.271 +            case SQLITE_DONE:
   5.272 +                break;
   5.273 +
   5.274 +            default:
   5.275 +                free_identity_list(il);
   5.276 +                return PEP_UNKNOWN_ERROR;
   5.277 +            }
   5.278 +        } while (result != SQLITE_DONE);
   5.279 +
   5.280 +        IdentityList_t *r = IdentityList_from_identity_list(il, &session->sync_state.keysync.identities);
   5.281 +        free_identity_list(il);
   5.282 +        if (!r)
   5.283 +            return PEP_OUT_OF_MEMORY;
   5.284 +    ||
   5.285 +}
   5.286 +
   5.287 +action disable;
   5.288 +
     6.1 --- a/sync/devicegroup.fsm	Thu Aug 09 12:15:44 2018 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,354 +0,0 @@
     6.4 -// This file is under GNU General Public License 3.0
     6.5 -// see LICENSE.txt
     6.6 -
     6.7 -// DeviceGroup protocol for p≡p
     6.8 -
     6.9 -// Copyleft (c) 2016, p≡p foundation
    6.10 -
    6.11 -// Written by Volker Birk
    6.12 -
    6.13 -include ./fsm.yml2
    6.14 -
    6.15 -protocol DeviceGroup {
    6.16 -    // all messages have a timestamp, time out and are removed after timeout
    6.17 -
    6.18 -    broadcast sendBeacon;
    6.19 -    broadcast sendGroupUpdate;
    6.20 -    broadcast sendUpdateRequest;
    6.21 -    unencrypted sendBeacon;
    6.22 -
    6.23 -    fsm DeviceState filename=sync {
    6.24 -        condition deviceGrouped();
    6.25 -        condition keyElectionWon(Identity partner);
    6.26 -        condition sameIdentities(Identity a, Identity b);
    6.27 -        condition sameKeyAndAddress(Identity a, Identity b);
    6.28 -
    6.29 -        state InitState {
    6.30 -            on Init {
    6.31 -                if deviceGrouped()
    6.32 -                    go Grouped;
    6.33 -                go Sole;
    6.34 -            }
    6.35 -        }
    6.36 -
    6.37 -        state Sole end=1 {
    6.38 -            on KeyGen {
    6.39 -                do sendBeacon;
    6.40 -                go SoleWaiting;
    6.41 -            }
    6.42 -            on CannotDecrypt {
    6.43 -                do sendBeacon;
    6.44 -                go SoleWaiting;
    6.45 -            }
    6.46 -            on Beacon(Identity partner){
    6.47 -                do sendHandshakeRequest(partner);
    6.48 -                go SoleBeaconed(partner);
    6.49 -            }
    6.50 -            on HandshakeRequest(Identity partner) {
    6.51 -                do sendHandshakeRequest(partner);
    6.52 -                go HandshakingSole(partner);
    6.53 -            }
    6.54 -        }
    6.55 -
    6.56 -        // copy of sole state with a timeout to enable fast polling for a second
    6.57 -        // TODO use more YSLT power here (substates ?) 
    6.58 -        state SoleWaiting timeout=60 {
    6.59 -            on KeyGen {
    6.60 -                do sendBeacon;
    6.61 -            }
    6.62 -            on CannotDecrypt {
    6.63 -                do sendBeacon;
    6.64 -            }
    6.65 -            on Beacon(Identity partner){
    6.66 -                do sendHandshakeRequest(partner);
    6.67 -                go SoleBeaconed(partner);
    6.68 -            }
    6.69 -            on HandshakeRequest(Identity partner) {
    6.70 -                do sendHandshakeRequest(partner);
    6.71 -                go HandshakingSole(partner);
    6.72 -            }
    6.73 -            on Timeout go Sole;
    6.74 -        }
    6.75 -
    6.76 -        state SoleBeaconed timeout=600 (Identity expected) {
    6.77 -            on KeyGen{
    6.78 -                do sendBeacon;
    6.79 -                go Sole;
    6.80 -            }
    6.81 -            on CannotDecrypt{
    6.82 -                do sendBeacon;
    6.83 -                go Sole;
    6.84 -            }
    6.85 -            on Beacon(Identity partner) {
    6.86 -                do sendHandshakeRequest(partner);
    6.87 -                go SoleBeaconed(partner);
    6.88 -            }
    6.89 -            on HandshakeRequest(Identity partner) {
    6.90 -                if sameIdentities(partner, expected) {
    6.91 -                    // do nothing, to avoid sending handshake request twice 
    6.92 -                } else {
    6.93 -                    do sendHandshakeRequest(partner);
    6.94 -                }
    6.95 -                go HandshakingSole(partner);
    6.96 -            }
    6.97 -            on Timeout go Sole;
    6.98 -        }
    6.99 -
   6.100 -        state HandshakingSole timeout=600 (Identity expected) {
   6.101 -            on Init{
   6.102 -                if keyElectionWon(expected) {
   6.103 -                    do notifyInitFormGroup(expected);
   6.104 -                } else {
   6.105 -                    do notifyInitAddOurDevice(expected);
   6.106 -                }
   6.107 -            }
   6.108 -            on HandshakeRejected(Identity partner) {
   6.109 -                do rejectHandshake(partner);
   6.110 -                go Sole;
   6.111 -            }
   6.112 -            on HandshakeAccepted(Identity partner) {
   6.113 -                if sameIdentities(partner, expected) {
   6.114 -                    do acceptHandshake(partner); 
   6.115 -                    if keyElectionWon(partner) {
   6.116 -                        do makeGroup;
   6.117 -                        do sendGroupKeys(partner);
   6.118 -                        do renewUUID;
   6.119 -                        do notifyAcceptedGroupCreated(partner);
   6.120 -                        go Grouped;
   6.121 -                    }
   6.122 -                    go WaitForGroupKeysSole(partner);
   6.123 -                }
   6.124 -                go Sole;
   6.125 -            }
   6.126 -            on Cancel go Sole;
   6.127 -            on GroupKeys(Identity partner, GroupKeys groupkeys) {
   6.128 -                if keyElectionWon(expected) {
   6.129 -                    // not supposed to receive groupkeys - ignore
   6.130 -                } else {
   6.131 -                    // UUID changes in between, so we can only check for same address and fpr
   6.132 -                    if sameKeyAndAddress(partner, expected) {
   6.133 -                        go WaitForAcceptSole(partner, groupkeys);
   6.134 -                    }
   6.135 -                }
   6.136 -            }
   6.137 -            on Timeout {
   6.138 -                do notifyTimeout(expected);
   6.139 -                do sendBeacon;
   6.140 -                go Sole;
   6.141 -            }
   6.142 -        }
   6.143 -    
   6.144 -        state WaitForGroupKeysSole timeout=600 (Identity expected) {
   6.145 -            on GroupKeys(Identity partner, GroupKeys groupkeys) {
   6.146 -                // UUID changes in between, so we can only check for same address and fpr
   6.147 -                if sameKeyAndAddress(partner, expected) {
   6.148 -                    do storeGroupKeys(partner, groupkeys);
   6.149 -                    do sendGroupUpdate;
   6.150 -                    do renewUUID;
   6.151 -                    do notifyAcceptedDeviceAdded(partner);
   6.152 -                    go Grouped;
   6.153 -                }
   6.154 -            }
   6.155 -            on Timeout {
   6.156 -                do notifyTimeout(expected);
   6.157 -                go Sole;
   6.158 -            }
   6.159 -        }
   6.160 -
   6.161 -        state WaitForAcceptSole timeout=600 (Identity expected, GroupKeys groupkeys) {
   6.162 -            on HandshakeRejected(Identity partner) {
   6.163 -                do rejectHandshake(partner);
   6.164 -                go Sole;
   6.165 -            }
   6.166 -            on HandshakeAccepted(Identity partner) {
   6.167 -                // UUID changes in between, so we can only check for same address and fpr
   6.168 -                if sameKeyAndAddress(partner, expected) {
   6.169 -                    do acceptHandshake(partner); 
   6.170 -                    do storeGroupKeys(partner, groupkeys);
   6.171 -                    do sendGroupUpdate;
   6.172 -                    do renewUUID;
   6.173 -                    do notifyAcceptedDeviceAdded(partner);
   6.174 -                    go Grouped;
   6.175 -                }
   6.176 -                go Sole;
   6.177 -            }
   6.178 -            on Cancel go Sole;
   6.179 -            on Timeout {
   6.180 -                do notifyTimeout(expected);
   6.181 -                go Sole;
   6.182 -            }
   6.183 -        }
   6.184 -
   6.185 -        state Grouped end=1 {
   6.186 -            on KeyGen
   6.187 -                do sendGroupUpdate;
   6.188 -            on CannotDecrypt {
   6.189 -                do sendUpdateRequest;
   6.190 -                do sendBeacon;
   6.191 -                go GroupWaiting;
   6.192 -            }
   6.193 -            on UpdateRequest
   6.194 -                do sendGroupUpdate;
   6.195 -            on Beacon(Identity partner){
   6.196 -                do sendHandshakeRequest(partner);
   6.197 -                go GroupedBeaconed(partner);
   6.198 -            }
   6.199 -            on HandshakeRequest(Identity partner) {
   6.200 -                do sendHandshakeRequest(partner);
   6.201 -                go HandshakingGrouped(partner);
   6.202 -            }
   6.203 -            on GroupUpdate(Identity partner, IdentityList keys)
   6.204 -                do storeGroupUpdate(partner, keys);
   6.205 -        }
   6.206 -
   6.207 -        // copy of grouped state, with a timeout to enable fast poling for a minut
   6.208 -        state GroupWaiting timeout=60 {
   6.209 -            on KeyGen
   6.210 -                do sendGroupUpdate;
   6.211 -            on CannotDecrypt {
   6.212 -                do sendUpdateRequest;
   6.213 -                do sendBeacon;
   6.214 -            }
   6.215 -            on UpdateRequest
   6.216 -                do sendGroupUpdate;
   6.217 -            on Beacon(Identity partner){
   6.218 -                do sendHandshakeRequest(partner);
   6.219 -                go GroupedBeaconed(partner);
   6.220 -            }
   6.221 -            on HandshakeRequest(Identity partner) {
   6.222 -                do sendHandshakeRequest(partner);
   6.223 -                go HandshakingGrouped(partner);
   6.224 -            }
   6.225 -            on GroupUpdate(Identity partner, IdentityList keys)
   6.226 -                do storeGroupUpdate(partner, keys);
   6.227 -            on Timeout go Grouped;
   6.228 -        }
   6.229 -
   6.230 -        state GroupedBeaconed timeout=600 (Identity expected){
   6.231 -            on KeyGen
   6.232 -                do sendGroupUpdate;
   6.233 -            on CannotDecrypt {
   6.234 -                do sendUpdateRequest;
   6.235 -                do sendBeacon;
   6.236 -            }
   6.237 -            on UpdateRequest
   6.238 -                do sendGroupUpdate;
   6.239 -            on Beacon(Identity partner){
   6.240 -                do sendHandshakeRequest(partner);
   6.241 -                go GroupedBeaconed(partner);
   6.242 -            }
   6.243 -            on HandshakeRequest(Identity partner) {
   6.244 -                if sameIdentities(partner, expected) {
   6.245 -                    // do nothing, to avoid sending handshake request twice 
   6.246 -                } else {
   6.247 -                    do sendHandshakeRequest(partner);
   6.248 -                }
   6.249 -                go HandshakingGrouped(partner);
   6.250 -            }
   6.251 -            on GroupUpdate(Identity partner, IdentityList keys)
   6.252 -                do storeGroupUpdate(partner, keys);
   6.253 -            on Timeout go Grouped;
   6.254 -        }
   6.255 -
   6.256 -        state HandshakingGrouped timeout=600 (Identity expected) {
   6.257 -            // HandshakeRequest from same group are filtered in receive_sync_msg
   6.258 -            on Init{
   6.259 -                if keyElectionWon(expected) {
   6.260 -                    do notifyInitAddOtherDevice(partner);
   6.261 -                } else {
   6.262 -                    do notifyInitMoveOurDevice(partner);
   6.263 -                }
   6.264 -            }
   6.265 -            on HandshakeRejected(Identity partner) {
   6.266 -                do rejectHandshake(partner);             // stores rejection of partner
   6.267 -                do sendGroupUpdate;
   6.268 -                go Grouped;
   6.269 -            }
   6.270 -            on HandshakeAccepted(Identity partner) {
   6.271 -                do acceptHandshake(partner); 
   6.272 -                do sendGroupUpdate;
   6.273 -                if keyElectionWon(partner) {
   6.274 -                    do sendGroupKeys(partner);
   6.275 -                    do notifyAcceptedDeviceAdded(partner);
   6.276 -                    go Grouped;
   6.277 -                }
   6.278 -                go WaitForGroupKeysGrouped(partner);
   6.279 -            }
   6.280 -            on Cancel go Grouped;
   6.281 -            on GroupKeys(Identity partner, GroupKeys groupkeys) {
   6.282 -                if keyElectionWon(expected) {
   6.283 -                    // not supposed to receive groupkeys - ignore
   6.284 -                } else {
   6.285 -                    // UUID changes in between, so we can only check for same address and fpr
   6.286 -                    if sameKeyAndAddress(partner, expected) {
   6.287 -                        go WaitForAcceptGrouped(partner, groupkeys);
   6.288 -                    }
   6.289 -                }
   6.290 -            }
   6.291 -            on GroupUpdate(Identity partner, IdentityList keys) {
   6.292 -                do notifyOvertaken(partner);
   6.293 -                do storeGroupUpdate(partner, keys);
   6.294 -                go Grouped;
   6.295 -            }
   6.296 -            on Timeout {
   6.297 -                do notifyTimeout(expected);
   6.298 -                go Grouped;
   6.299 -            }
   6.300 -        }
   6.301 -
   6.302 -        state WaitForGroupKeysGrouped timeout=600 (Identity expected) {
   6.303 -            on GroupKeys(Identity partner, GroupKeys groupkeys) {
   6.304 -                if sameIdentities(partner, expected) {
   6.305 -                    do storeGroupKeys(partner, groupkeys);
   6.306 -                    do sendGroupUpdate;
   6.307 -                    do renewUUID;
   6.308 -                    do notifyAcceptedDeviceMoved(partner);
   6.309 -                    go Grouped;
   6.310 -                }
   6.311 -            }
   6.312 -            on GroupUpdate(Identity partner, IdentityList keys) {
   6.313 -                do notifyOvertaken(partner);
   6.314 -                do storeGroupUpdate(partner, keys);
   6.315 -                go Grouped;
   6.316 -            }
   6.317 -            on Timeout {
   6.318 -                do notifyTimeout(expected);
   6.319 -                go Grouped;
   6.320 -            }
   6.321 -        }
   6.322 -
   6.323 -        state WaitForAcceptGrouped timeout=600 (Identity expected, GroupKeys groupkeys) {
   6.324 -            on HandshakeRejected(Identity partner) {
   6.325 -                do rejectHandshake(partner);
   6.326 -                do sendGroupUpdate;
   6.327 -                go Grouped;
   6.328 -            }
   6.329 -            on HandshakeAccepted(Identity partner) {
   6.330 -                if sameIdentities(partner, expected) {
   6.331 -                    do acceptHandshake(partner); 
   6.332 -                    do storeGroupKeys(partner, groupkeys);
   6.333 -                    do sendGroupUpdate;
   6.334 -                    do renewUUID;
   6.335 -                    do notifyAcceptedDeviceMoved(partner);
   6.336 -                }
   6.337 -                go Grouped;
   6.338 -            }
   6.339 -            on Cancel go Grouped;
   6.340 -            on GroupUpdate(Identity partner, IdentityList keys) {
   6.341 -                do notifyOvertaken(partner);
   6.342 -                do storeGroupUpdate(partner, keys);
   6.343 -                go Grouped;
   6.344 -            }
   6.345 -            on Timeout {
   6.346 -                do notifyTimeout(expected);
   6.347 -                go Grouped;
   6.348 -            }
   6.349 -        }
   6.350 -
   6.351 -        tag Init 1;
   6.352 -        tag Beacon 2;
   6.353 -        tag HandshakeRequest 3;
   6.354 -        tag GroupKeys 4;
   6.355 -    }
   6.356 -}
   6.357 -
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/sync/gen_message_func.ysl2	Thu Aug 09 12:26:53 2018 +0200
     7.3 @@ -0,0 +1,319 @@
     7.4 +// This file is under GNU General Public License 3.0
     7.5 +// see LICENSE.txt
     7.6 +
     7.7 +// generate message functions
     7.8 +
     7.9 +// Copyleft (c) 2017, p≡p foundation
    7.10 +
    7.11 +// Written by Volker Birk
    7.12 +
    7.13 +include yslt.yml2
    7.14 +
    7.15 +tstylesheet {
    7.16 +
    7.17 +include standardlib.ysl2
    7.18 +include ./functions.ysl2
    7.19 +
    7.20 +template "/" {
    7.21 +    apply "protocol", 0, mode=header;
    7.22 +    apply "protocol", 0, mode=impl;
    7.23 +}
    7.24 +
    7.25 +template "protocol", mode=header
    7.26 +    document "generated/{@name}_func.h", "text"
    7.27 +||
    7.28 +// This file is under GNU General Public License 3.0
    7.29 +// see LICENSE.txt
    7.30 +
    7.31 +#pragma once
    7.32 +
    7.33 +#ifdef __cplusplus
    7.34 +extern "C" {
    7.35 +#endif
    7.36 +
    7.37 +#include <stdbool.h>
    7.38 +
    7.39 +#include "../asn.1/«@name».h"
    7.40 +`` for "func:distinctType(fsm/message/field[not(func:basicType())])" | #include "../asn.1/«@type».h"
    7.41 +
    7.42 +// state
    7.43 +
    7.44 +struct «@name»_state_s {
    7.45 +    struct basic_state_s {
    7.46 +        pEp_identity *from;
    7.47 +    } basic;
    7.48 +
    7.49 +    `` apply "fsm", mode=state
    7.50 +};
    7.51 +
    7.52 +struct own_«@name»_state_s {
    7.53 +    `` for "func:distinctName(fsm/message/field[@type='TID'])" |> «func:ctype()» «@name»;
    7.54 +};
    7.55 +
    7.56 +void free_«@name»_state(PEP_SESSION session);
    7.57 +
    7.58 +// functions for protocol «@name»
    7.59 +
    7.60 +«@name»_t *new_«@name»_message(«@name»_PR fsm, int message_type);
    7.61 +void free_«@name»_message(«@name»_t *msg);
    7.62 +
    7.63 +PEP_STATUS update_«@name»_state(PEP_SESSION session, «@name»_t *msg,
    7.64 +        «@name»_PR *fsm, int *message_type);
    7.65 +
    7.66 +PEP_STATUS update_«@name»_message(PEP_SESSION session, «@name»_PR fsm,
    7.67 +        int message_type, «@name»_t *msg);
    7.68 +
    7.69 +#ifdef __cplusplus
    7.70 +}
    7.71 +#endif
    7.72 +
    7.73 +||
    7.74 +
    7.75 +template "fsm", mode=state
    7.76 +||
    7.77 +struct _«@name»_state_s {
    7.78 +    int state;
    7.79 +
    7.80 +    `` for "func:distinctName(message/field)" |> «func:ctype()» «@name»;
    7.81 +} «yml:lcase(@name)»;
    7.82 +||
    7.83 +
    7.84 +template "protocol", mode=impl
    7.85 +    document "generated/{@name}_func.c", "text" {
    7.86 +||
    7.87 +// This file is under GNU General Public License 3.0
    7.88 +// see LICENSE.txt
    7.89 +
    7.90 +#include <assert.h>
    7.91 +#include <stdlib.h>
    7.92 +#include "pEp_internal.h"
    7.93 +#include "map_asn1.h"
    7.94 +#include "«@name»_func.h"
    7.95 +
    7.96 +void free_«@name»_state(PEP_SESSION session)
    7.97 +{
    7.98 +    if (!session)
    7.99 +        return;
   7.100 +
   7.101 +    free_identity(session->«yml:lcase(@name)»_state.basic.from);
   7.102 +    session->«yml:lcase(@name)»_state.basic.from = NULL;
   7.103 +
   7.104 +||
   7.105 +for "fsm"
   7.106 +    for "func:distinctName(message/field[not(func:basicType())])"
   7.107 +        |> ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_«@type», &session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name»);
   7.108 +|
   7.109 +for "func:distinctName(fsm/message/field[@type='TID'])"
   7.110 +    |> ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_«@type», &session->own_«yml:lcase(../../../@name)»_state.«@name»);
   7.111 +||
   7.112 +}
   7.113 +
   7.114 +«@name»_t *new_«@name»_message(«@name»_PR fsm, int message_type)
   7.115 +{
   7.116 +    assert(fsm && message_type);
   7.117 +    if (!(fsm && message_type))
   7.118 +        return NULL;
   7.119 +
   7.120 +    «@name»_t *msg = calloc(sizeof(«@name»_t), 1);
   7.121 +    assert(msg);
   7.122 +    if (!msg)
   7.123 +        return NULL;
   7.124 +
   7.125 +    msg->present = fsm;
   7.126 +    switch (fsm) {
   7.127 +        `` apply "fsm", mode=impl
   7.128 +        default:
   7.129 +            free(msg);
   7.130 +            return NULL;
   7.131 +    }
   7.132 +
   7.133 +    return msg;
   7.134 +}
   7.135 +
   7.136 +void free_«@name»_message(«@name»_t *msg)
   7.137 +{
   7.138 +    ASN_STRUCT_FREE(asn_DEF_«@name», msg);
   7.139 +}
   7.140 +
   7.141 +PEP_STATUS update_«@name»_state(PEP_SESSION session, «@name»_t *msg,
   7.142 +        «@name»_PR *fsm, int *message_type)
   7.143 +{
   7.144 +    int result = 0;
   7.145 +
   7.146 +    assert(session && msg && fsm && message_type);
   7.147 +    if (!(session && msg && fsm && message_type))
   7.148 +        return PEP_ILLEGAL_VALUE;
   7.149 +
   7.150 +    *fsm = 0;
   7.151 +    *message_type = 0;
   7.152 +
   7.153 +    switch (msg->present) {
   7.154 +        case «@name»_PR_NOTHING:
   7.155 +            return PEP_ILLEGAL_VALUE;
   7.156 +
   7.157 +        `` apply "fsm", 2, mode=update_state
   7.158 +        default:
   7.159 +            return PEP_ILLEGAL_VALUE;
   7.160 +    }
   7.161 +
   7.162 +    *fsm = msg->present;
   7.163 +    return PEP_STATUS_OK;
   7.164 +}
   7.165 +
   7.166 +PEP_STATUS update_«@name»_message(PEP_SESSION session, «@name»_PR fsm,
   7.167 +        int message_type, «@name»_t *msg)
   7.168 +{
   7.169 +    int result = 0;
   7.170 +
   7.171 +    assert(session && msg);
   7.172 +    if (!(session && msg))
   7.173 +        return PEP_ILLEGAL_VALUE;
   7.174 +
   7.175 +    switch (fsm) {
   7.176 +        case «@name»_PR_NOTHING:
   7.177 +            return PEP_ILLEGAL_VALUE;
   7.178 +
   7.179 +        `` apply "fsm", 2, mode=update_message
   7.180 +        default:
   7.181 +            return PEP_ILLEGAL_VALUE;
   7.182 +    }
   7.183 +
   7.184 +    return PEP_STATUS_OK;
   7.185 +}
   7.186 +
   7.187 +||
   7.188 +}
   7.189 +
   7.190 +template "fsm", mode=update_message
   7.191 +||
   7.192 +case «../@name»_PR_«yml:lcase(@name)»:
   7.193 +    switch (message_type) {
   7.194 +        case «@name»__payload_PR_NOTHING:
   7.195 +            return PEP_ILLEGAL_VALUE;
   7.196 +
   7.197 +        `` apply "message", 2, mode=update_message
   7.198 +        default:
   7.199 +            return PEP_ILLEGAL_VALUE;
   7.200 +    }
   7.201 +    break;
   7.202 +
   7.203 +||
   7.204 +
   7.205 +template "message", mode=update_message {
   7.206 +    const "message_name", "concat(yml:lcase(substring(@name,1,1)), substring(@name,2))";
   7.207 +    ||
   7.208 +    case «../@name»__payload_PR_«$message_name»:
   7.209 +        `` apply "field", mode=update_message with "message_name", "$message_name"
   7.210 +        break;
   7.211 +
   7.212 +    ||
   7.213 +}
   7.214 +
   7.215 +template "field", mode=update_message {
   7.216 +    param "message_name";
   7.217 +    choose {
   7.218 +        when "func:basicType()" // copyable
   7.219 +        ||
   7.220 +        msg->choice.«yml:lcase(../../@name)».payload.choice.«$message_name».«@name»
   7.221 +                 = session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name»;
   7.222 +
   7.223 +        ||
   7.224 +        when "@type='IdentityList'"
   7.225 +        ||
   7.226 +        {
   7.227 +            identity_list *il = IdentityList_to_identity_list(
   7.228 +                    &session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name», NULL);
   7.229 +            if (!il)
   7.230 +                return PEP_OUT_OF_MEMORY;
   7.231 +            IdentityList_t *_il = IdentityList_from_identity_list(il,
   7.232 +                    &msg->choice.«yml:lcase(../../@name)».payload.choice.«$message_name».«@name»);
   7.233 +            free_identity_list(il);
   7.234 +            if (!_il)
   7.235 +                return PEP_OUT_OF_MEMORY;
   7.236 +        }
   7.237 +
   7.238 +        ||
   7.239 +        otherwise // string based
   7.240 +        ||
   7.241 +        result = OCTET_STRING_fromBuf(&msg->choice.«yml:lcase(../../@name)».payload.choice.«$message_name».«@name»,
   7.242 +                (char *) session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name».buf,
   7.243 +                session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name».size);
   7.244 +        if (result)
   7.245 +            return PEP_OUT_OF_MEMORY;
   7.246 +
   7.247 +        ||
   7.248 +    }
   7.249 +}
   7.250 +
   7.251 +template "fsm", mode=update_state
   7.252 +||
   7.253 +case «../@name»_PR_«yml:lcase(@name)»:
   7.254 +    switch (msg->choice.«yml:lcase(@name)».payload.present) {
   7.255 +        case «@name»__payload_PR_NOTHING:
   7.256 +            return PEP_ILLEGAL_VALUE;
   7.257 +
   7.258 +        `` apply "message", 2, mode=update_state
   7.259 +        default:
   7.260 +            return PEP_ILLEGAL_VALUE;
   7.261 +    }
   7.262 +    *message_type = msg->choice.«yml:lcase(@name)».payload.present;
   7.263 +    break;
   7.264 +
   7.265 +||
   7.266 +
   7.267 +template "message", mode=update_state {
   7.268 +    const "message_name", "concat(yml:lcase(substring(@name,1,1)), substring(@name,2))";
   7.269 +    ||
   7.270 +    case «../@name»__payload_PR_«$message_name»:
   7.271 +        `` apply "field", mode=update_state with "message_name", "$message_name"
   7.272 +        break;
   7.273 +
   7.274 +    ||
   7.275 +}
   7.276 +
   7.277 +template "field", mode=update_state {
   7.278 +    param "message_name";
   7.279 +    choose {
   7.280 +        when "func:basicType()" // copyable
   7.281 +        ||
   7.282 +        session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name» = msg->choice.«yml:lcase(../../@name)»
   7.283 +                .payload.choice.«$message_name».«@name»;
   7.284 +
   7.285 +        ||
   7.286 +        when "@type='IdentityList'"
   7.287 +        ||
   7.288 +        {
   7.289 +            identity_list *il = IdentityList_to_identity_list(
   7.290 +                    &msg->choice.«yml:lcase(../../@name)».payload.choice.«$message_name».«@name», NULL);
   7.291 +            if (!il)
   7.292 +                return PEP_OUT_OF_MEMORY;
   7.293 +            IdentityList_t *_il = IdentityList_from_identity_list(il,
   7.294 +                    &session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name»);
   7.295 +            free_identity_list(il);
   7.296 +            if (!_il)
   7.297 +                return PEP_OUT_OF_MEMORY;
   7.298 +        }
   7.299 +
   7.300 +        ||
   7.301 +        otherwise // string based
   7.302 +        ||
   7.303 +        result = OCTET_STRING_fromBuf(&session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name»,
   7.304 +                (char *) msg->choice.«yml:lcase(../../@name)».payload.choice.«$message_name».«@name».buf,
   7.305 +                msg->choice.«yml:lcase(../../@name)».payload.choice.«$message_name».«@name».size);
   7.306 +        if (result)
   7.307 +            return PEP_OUT_OF_MEMORY;
   7.308 +
   7.309 +        ||
   7.310 +    }
   7.311 +}
   7.312 +
   7.313 +template "fsm", mode=impl
   7.314 +||
   7.315 +case «../@name»_PR_«yml:lcase(@name)»:
   7.316 +    msg->choice.«yml:lcase(@name)».payload.present = message_type;
   7.317 +        break;
   7.318 +
   7.319 +||
   7.320 +
   7.321 +}
   7.322 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/sync/gen_messages.ysl2	Thu Aug 09 12:26:53 2018 +0200
     8.3 @@ -0,0 +1,100 @@
     8.4 +// This file is under GNU General Public License 3.0
     8.5 +// see LICENSE.txt
     8.6 +// generated files of this template are under BSD License 2.0
     8.7 +
     8.8 +// generate message functions
     8.9 +
    8.10 +// Copyleft (c) 2017, p≡p foundation
    8.11 +
    8.12 +// Written by Volker Birk
    8.13 +
    8.14 +include yslt.yml2
    8.15 +
    8.16 +tstylesheet {
    8.17 +    include standardlib.ysl2
    8.18 +    include ./functions.ysl2
    8.19 +
    8.20 +    function "pEp_imports"
    8.21 +        | IMPORTS Identity, IdentityList, TID, Hash FROM PEP;
    8.22 +
    8.23 +    template "/" {
    8.24 +        apply "protocol", 0, mode=overview;
    8.25 +        apply "protocol/fsm", 0, mode=individual;
    8.26 +    }
    8.27 +
    8.28 +    template "protocol", mode=overview
    8.29 +        document "generated/{yml:lcase(@name)}.asn1", "text"
    8.30 +    ||
    8.31 +    -- This file is under BSD License 2.0
    8.32 +
    8.33 +    -- «@name» protocol stack for p≡p
    8.34 +    -- Copyright (c) 2016, 2017 p≡p foundation
    8.35 +
    8.36 +    -- Written by Volker Birk
    8.37 +
    8.38 +    «yml:ucase(@name)»
    8.39 +        { iso(1) org(3) dod(6) internet(1) private(4) enterprise(1) pEp(47878) «yml:lcase(@name)»(«@id») }
    8.40 +
    8.41 +    DEFINITIONS AUTOMATIC TAGS EXTENSIBILITY IMPLIED ::=
    8.42 +
    8.43 +    BEGIN
    8.44 +
    8.45 +    `` for "fsm" | IMPORTS «@name» FROM «yml:ucase(@name)»;
    8.46 +
    8.47 +    «@name» ::= CHOICE {
    8.48 +        `` for "fsm" |> «yml:lcase(@name)» [APPLICATION «@id»] «@name»`if "position()!=last()" > , `
    8.49 +    }
    8.50 +
    8.51 +    END
    8.52 +
    8.53 +    ||
    8.54 +
    8.55 +    template "fsm", mode=individual
    8.56 +        document "generated/{yml:lcase(@name)}.asn1", "text"
    8.57 +    ||
    8.58 +    -- This file is under BSD License 2.0
    8.59 +
    8.60 +    -- «@name» protocol for p≡p version «version/@major».«version/@minor»
    8.61 +    -- Copyright (c) 2016, 2017 p≡p foundation
    8.62 +
    8.63 +    -- Written by Volker Birk
    8.64 +
    8.65 +    «yml:ucase(@name)»
    8.66 +        { iso(1) org(3) dod(6) internet(1) private(4) enterprise(1) pEp(47878) «yml:lcase(../@name)»(«../@id») «yml:lcase(@name)»(«@id») }
    8.67 +
    8.68 +    DEFINITIONS AUTOMATIC TAGS EXTENSIBILITY IMPLIED ::=
    8.69 +
    8.70 +    BEGIN
    8.71 +
    8.72 +    EXPORTS «@name»;
    8.73 +    `` call "pEp_imports"
    8.74 +
    8.75 +    Version ::= SEQUENCE {
    8.76 +        major INTEGER (0..255) DEFAULT «version/@major»,
    8.77 +        minor INTEGER (0..255) DEFAULT «version/@minor»
    8.78 +    }
    8.79 +
    8.80 +    `` apply "message", 0, mode=impl;
    8.81 +    «@name» ::= SEQUENCE {
    8.82 +        header SEQUENCE {
    8.83 +            sequence INTEGER  -- always increases
    8.84 +        },
    8.85 +
    8.86 +        payload CHOICE {
    8.87 +        `` for "message" |>> «yml:mixedCase(@name)» [APPLICATION «@id»] «@name»`if "position()!=last()" > ,`
    8.88 +        }
    8.89 +    }
    8.90 +
    8.91 +    END
    8.92 +
    8.93 +    ||
    8.94 +
    8.95 +    template "message", mode=impl
    8.96 +    ||
    8.97 +    «@name» ::= SEQUENCE {
    8.98 +    `` for "field|auto" |> «func:asn1name()» «func:asn1type()»`if "position()!=last()" > ,`
    8.99 +    }
   8.100 +
   8.101 +    ||
   8.102 +}
   8.103 +
     9.1 --- a/sync/generated/sync_driver.c	Thu Aug 09 12:15:44 2018 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,40 +0,0 @@
     9.4 -// Driver for DeviceState state machine
     9.5 -
     9.6 -#include <assert.h>
     9.7 -#include "pEp_internal.h"
     9.8 -
     9.9 -
    9.10 -DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
    9.11 -        PEP_SESSION session,
    9.12 -        DeviceState_event event,
    9.13 -        Identity partner,
    9.14 -        void *extra,
    9.15 -        time_t *timeout
    9.16 -    )
    9.17 -{
    9.18 -    assert(session);
    9.19 -    if (!session)
    9.20 -        return PEP_ILLEGAL_VALUE;
    9.21 -
    9.22 -    while(true)
    9.23 -    {
    9.24 -        DeviceState_state new_state = fsm_DeviceState(session,
    9.25 -            session->sync_state, event, partner, extra, timeout);
    9.26 -
    9.27 -        if (new_state == DeviceState_state_invalid_out_of_memory)
    9.28 -            return PEP_OUT_OF_MEMORY;
    9.29 -
    9.30 -        if (new_state < 0)
    9.31 -            return PEP_SYNC_STATEMACHINE_ERROR - new_state;
    9.32 -        
    9.33 -        if (new_state == session->sync_state)
    9.34 -            break;
    9.35 -
    9.36 -        event = Init;
    9.37 -        extra = NULL;
    9.38 -        session->sync_state = new_state;
    9.39 -    } 
    9.40 -
    9.41 -    return PEP_STATUS_OK;
    9.42 -}
    9.43 -
    10.1 --- a/sync/generated/sync_fsm.c	Thu Aug 09 12:15:44 2018 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,1610 +0,0 @@
    10.4 -#include "pEp_internal.h"
    10.5 -#include "sync_fsm.h"
    10.6 -#include "sync_impl.h"
    10.7 -
    10.8 -// local definitions for DeviceState's state machine 
    10.9 -
   10.10 -typedef struct _SoleBeaconed_state_payload {
   10.11 -    Identity expected;
   10.12 -} SoleBeaconed_state_payload_t;
   10.13 -
   10.14 -typedef struct _HandshakingSole_state_payload {
   10.15 -    Identity expected;
   10.16 -} HandshakingSole_state_payload_t;
   10.17 -
   10.18 -typedef struct _WaitForGroupKeysSole_state_payload {
   10.19 -    Identity expected;
   10.20 -} WaitForGroupKeysSole_state_payload_t;
   10.21 -
   10.22 -typedef struct _WaitForAcceptSole_state_payload {
   10.23 -    Identity expected;
   10.24 -    group_keys_extra_t* groupkeys;
   10.25 -} WaitForAcceptSole_state_payload_t;
   10.26 -
   10.27 -typedef struct _GroupedBeaconed_state_payload {
   10.28 -    Identity expected;
   10.29 -} GroupedBeaconed_state_payload_t;
   10.30 -
   10.31 -typedef struct _HandshakingGrouped_state_payload {
   10.32 -    Identity expected;
   10.33 -} HandshakingGrouped_state_payload_t;
   10.34 -
   10.35 -typedef struct _WaitForGroupKeysGrouped_state_payload {
   10.36 -    Identity expected;
   10.37 -} WaitForGroupKeysGrouped_state_payload_t;
   10.38 -
   10.39 -typedef struct _WaitForAcceptGrouped_state_payload {
   10.40 -    Identity expected;
   10.41 -    group_keys_extra_t* groupkeys;
   10.42 -} WaitForAcceptGrouped_state_payload_t;
   10.43 -
   10.44 -
   10.45 -// state machine for DeviceState
   10.46 -
   10.47 -DeviceState_state fsm_DeviceState(
   10.48 -        PEP_SESSION session,
   10.49 -        DeviceState_state state,
   10.50 -        DeviceState_event event,
   10.51 -        Identity partner,
   10.52 -        void *extra,
   10.53 -        time_t *timeout
   10.54 -    )
   10.55 -{
   10.56 -    PEP_STATUS status = PEP_STATUS_OK;
   10.57 -
   10.58 -    switch (state) {
   10.59 -        case InitState:
   10.60 -        {
   10.61 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=InitState")
   10.62 -            switch (event) {
   10.63 -                case Init:
   10.64 -                {
   10.65 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=InitState", "event=Init")
   10.66 -                    *timeout = 0;
   10.67 -                    {
   10.68 -                        int cond_result = deviceGrouped(session);
   10.69 -                        #ifndef NDEBUG
   10.70 -                        char resstr[11] = {0,};
   10.71 -                        snprintf(resstr,10,"result=%d",cond_result);
   10.72 -                        #endif
   10.73 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=InitState, event=Init, condition=deviceGrouped", resstr)
   10.74 -                        if (cond_result < 0)
   10.75 -                            return cond_result;
   10.76 -                        if (cond_result) {
   10.77 -                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=InitState, event=Init", "target=Grouped")
   10.78 -                        return Grouped;
   10.79 -                        }
   10.80 -                    }
   10.81 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=InitState, event=Init", "target=Sole")
   10.82 -                    return Sole;
   10.83 -                }
   10.84 -                default:
   10.85 -                    return (DeviceState_state) invalid_event;
   10.86 -            }
   10.87 -            break;
   10.88 -        }
   10.89 -        case Sole:
   10.90 -        {
   10.91 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=Sole")
   10.92 -            switch (event) {
   10.93 -                case Init: 
   10.94 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=Init") 
   10.95 -                    *timeout = 0;
   10.96 -                    break;
   10.97 -                case KeyGen:
   10.98 -                {
   10.99 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=KeyGen")
  10.100 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=KeyGen", "action=sendBeacon")
  10.101 -                    status = sendBeacon(session, state, NULL, NULL);
  10.102 -                    if (status == PEP_OUT_OF_MEMORY)
  10.103 -                        return (int) invalid_out_of_memory;
  10.104 -                    if (status != PEP_STATUS_OK)
  10.105 -                        return (int) invalid_action;
  10.106 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Sole, event=KeyGen", "target=SoleWaiting")
  10.107 -                    return SoleWaiting;
  10.108 -                }
  10.109 -                case CannotDecrypt:
  10.110 -                {
  10.111 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=CannotDecrypt")
  10.112 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=CannotDecrypt", "action=sendBeacon")
  10.113 -                    status = sendBeacon(session, state, NULL, NULL);
  10.114 -                    if (status == PEP_OUT_OF_MEMORY)
  10.115 -                        return (int) invalid_out_of_memory;
  10.116 -                    if (status != PEP_STATUS_OK)
  10.117 -                        return (int) invalid_action;
  10.118 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Sole, event=CannotDecrypt", "target=SoleWaiting")
  10.119 -                    return SoleWaiting;
  10.120 -                }
  10.121 -                case Beacon:
  10.122 -                {
  10.123 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=Beacon")
  10.124 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=Beacon", "action=sendHandshakeRequest")
  10.125 -                    status = sendHandshakeRequest(session, state, partner, NULL);
  10.126 -                    if (status == PEP_OUT_OF_MEMORY)
  10.127 -                        return (int) invalid_out_of_memory;
  10.128 -                    if (status != PEP_STATUS_OK)
  10.129 -                        return (int) invalid_action;
  10.130 -                    session->sync_state_payload = malloc(sizeof(SoleBeaconed_state_payload_t));
  10.131 -                    assert(session->sync_state_payload);
  10.132 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.133 -                    ((SoleBeaconed_state_payload_t*)session->sync_state_payload)->expected =
  10.134 -                        identity_dup(partner);
  10.135 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Sole, event=Beacon", "target=SoleBeaconed")
  10.136 -                    return SoleBeaconed;
  10.137 -                }
  10.138 -                case HandshakeRequest:
  10.139 -                {
  10.140 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=HandshakeRequest")
  10.141 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=HandshakeRequest", "action=sendHandshakeRequest")
  10.142 -                    status = sendHandshakeRequest(session, state, partner, NULL);
  10.143 -                    if (status == PEP_OUT_OF_MEMORY)
  10.144 -                        return (int) invalid_out_of_memory;
  10.145 -                    if (status != PEP_STATUS_OK)
  10.146 -                        return (int) invalid_action;
  10.147 -                    session->sync_state_payload = malloc(sizeof(HandshakingSole_state_payload_t));
  10.148 -                    assert(session->sync_state_payload);
  10.149 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.150 -                    ((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected =
  10.151 -                        identity_dup(partner);
  10.152 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Sole, event=HandshakeRequest", "target=HandshakingSole")
  10.153 -                    return HandshakingSole;
  10.154 -                }
  10.155 -                default:
  10.156 -                    return (DeviceState_state) invalid_event;
  10.157 -            }
  10.158 -            break;
  10.159 -        }
  10.160 -        case SoleWaiting:
  10.161 -        {
  10.162 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=SoleWaiting")
  10.163 -            switch (event) {
  10.164 -                case Init: 
  10.165 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=Init") 
  10.166 -                    *timeout = 60;
  10.167 -                    break;
  10.168 -                case KeyGen:
  10.169 -                {
  10.170 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=KeyGen")
  10.171 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleWaiting, event=KeyGen", "action=sendBeacon")
  10.172 -                    status = sendBeacon(session, state, NULL, NULL);
  10.173 -                    if (status == PEP_OUT_OF_MEMORY)
  10.174 -                        return (int) invalid_out_of_memory;
  10.175 -                    if (status != PEP_STATUS_OK)
  10.176 -                        return (int) invalid_action;
  10.177 -                    break;
  10.178 -                }
  10.179 -                case CannotDecrypt:
  10.180 -                {
  10.181 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=CannotDecrypt")
  10.182 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleWaiting, event=CannotDecrypt", "action=sendBeacon")
  10.183 -                    status = sendBeacon(session, state, NULL, NULL);
  10.184 -                    if (status == PEP_OUT_OF_MEMORY)
  10.185 -                        return (int) invalid_out_of_memory;
  10.186 -                    if (status != PEP_STATUS_OK)
  10.187 -                        return (int) invalid_action;
  10.188 -                    break;
  10.189 -                }
  10.190 -                case Beacon:
  10.191 -                {
  10.192 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=Beacon")
  10.193 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleWaiting, event=Beacon", "action=sendHandshakeRequest")
  10.194 -                    status = sendHandshakeRequest(session, state, partner, NULL);
  10.195 -                    if (status == PEP_OUT_OF_MEMORY)
  10.196 -                        return (int) invalid_out_of_memory;
  10.197 -                    if (status != PEP_STATUS_OK)
  10.198 -                        return (int) invalid_action;
  10.199 -                    session->sync_state_payload = malloc(sizeof(SoleBeaconed_state_payload_t));
  10.200 -                    assert(session->sync_state_payload);
  10.201 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.202 -                    ((SoleBeaconed_state_payload_t*)session->sync_state_payload)->expected =
  10.203 -                        identity_dup(partner);
  10.204 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleWaiting, event=Beacon", "target=SoleBeaconed")
  10.205 -                    return SoleBeaconed;
  10.206 -                }
  10.207 -                case HandshakeRequest:
  10.208 -                {
  10.209 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=HandshakeRequest")
  10.210 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleWaiting, event=HandshakeRequest", "action=sendHandshakeRequest")
  10.211 -                    status = sendHandshakeRequest(session, state, partner, NULL);
  10.212 -                    if (status == PEP_OUT_OF_MEMORY)
  10.213 -                        return (int) invalid_out_of_memory;
  10.214 -                    if (status != PEP_STATUS_OK)
  10.215 -                        return (int) invalid_action;
  10.216 -                    session->sync_state_payload = malloc(sizeof(HandshakingSole_state_payload_t));
  10.217 -                    assert(session->sync_state_payload);
  10.218 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.219 -                    ((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected =
  10.220 -                        identity_dup(partner);
  10.221 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleWaiting, event=HandshakeRequest", "target=HandshakingSole")
  10.222 -                    return HandshakingSole;
  10.223 -                }
  10.224 -                case Timeout:
  10.225 -                {
  10.226 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=Timeout")
  10.227 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleWaiting, event=Timeout", "target=Sole")
  10.228 -                    return Sole;
  10.229 -                }
  10.230 -                default:
  10.231 -                    return (DeviceState_state) invalid_event;
  10.232 -            }
  10.233 -            break;
  10.234 -        }
  10.235 -        case SoleBeaconed:
  10.236 -        {
  10.237 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=SoleBeaconed")
  10.238 -            assert(session->sync_state_payload);
  10.239 -            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.240 -            Identity expected = ((SoleBeaconed_state_payload_t*)session->sync_state_payload)->expected;
  10.241 -            switch (event) {
  10.242 -                case Init: 
  10.243 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=Init") 
  10.244 -                    *timeout = 600;
  10.245 -                    break;
  10.246 -                case KeyGen:
  10.247 -                {
  10.248 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=KeyGen")
  10.249 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=KeyGen", "action=sendBeacon")
  10.250 -                    status = sendBeacon(session, state, NULL, NULL);
  10.251 -                    if (status == PEP_OUT_OF_MEMORY)
  10.252 -                        return (int) invalid_out_of_memory;
  10.253 -                    if (status != PEP_STATUS_OK)
  10.254 -                        return (int) invalid_action;
  10.255 -                    assert(session->sync_state_payload);
  10.256 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.257 -                    free_identity(((SoleBeaconed_state_payload_t*)session->sync_state_payload)->expected);
  10.258 -                    free(session->sync_state_payload);
  10.259 -                    session->sync_state_payload = NULL;
  10.260 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=KeyGen", "target=Sole")
  10.261 -                    return Sole;
  10.262 -                }
  10.263 -                case CannotDecrypt:
  10.264 -                {
  10.265 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=CannotDecrypt")
  10.266 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=CannotDecrypt", "action=sendBeacon")
  10.267 -                    status = sendBeacon(session, state, NULL, NULL);
  10.268 -                    if (status == PEP_OUT_OF_MEMORY)
  10.269 -                        return (int) invalid_out_of_memory;
  10.270 -                    if (status != PEP_STATUS_OK)
  10.271 -                        return (int) invalid_action;
  10.272 -                    assert(session->sync_state_payload);
  10.273 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.274 -                    free_identity(((SoleBeaconed_state_payload_t*)session->sync_state_payload)->expected);
  10.275 -                    free(session->sync_state_payload);
  10.276 -                    session->sync_state_payload = NULL;
  10.277 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=CannotDecrypt", "target=Sole")
  10.278 -                    return Sole;
  10.279 -                }
  10.280 -                case Beacon:
  10.281 -                {
  10.282 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=Beacon")
  10.283 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=Beacon", "action=sendHandshakeRequest")
  10.284 -                    status = sendHandshakeRequest(session, state, partner, NULL);
  10.285 -                    if (status == PEP_OUT_OF_MEMORY)
  10.286 -                        return (int) invalid_out_of_memory;
  10.287 -                    if (status != PEP_STATUS_OK)
  10.288 -                        return (int) invalid_action;
  10.289 -                    assert(session->sync_state_payload);
  10.290 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.291 -                    free_identity(((SoleBeaconed_state_payload_t*)session->sync_state_payload)->expected);
  10.292 -                    free(session->sync_state_payload);
  10.293 -                    session->sync_state_payload = NULL;
  10.294 -                    session->sync_state_payload = malloc(sizeof(SoleBeaconed_state_payload_t));
  10.295 -                    assert(session->sync_state_payload);
  10.296 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.297 -                    ((SoleBeaconed_state_payload_t*)session->sync_state_payload)->expected =
  10.298 -                        identity_dup(partner);
  10.299 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=Beacon", "target=SoleBeaconed")
  10.300 -                    return SoleBeaconed;
  10.301 -                }
  10.302 -                case HandshakeRequest:
  10.303 -                {
  10.304 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=HandshakeRequest")
  10.305 -                    {
  10.306 -                        int cond_result = sameIdentities(session, partner, expected);
  10.307 -                        #ifndef NDEBUG
  10.308 -                        char resstr[11] = {0,};
  10.309 -                        snprintf(resstr,10,"result=%d",cond_result);
  10.310 -                        #endif
  10.311 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest, condition=sameIdentities", resstr)
  10.312 -                        if (cond_result < 0)
  10.313 -                            return cond_result;
  10.314 -                        if (cond_result) {
  10.315 -                        }
  10.316 -                        else {
  10.317 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest", "action=sendHandshakeRequest")
  10.318 -                        status = sendHandshakeRequest(session, state, partner, NULL);
  10.319 -                        if (status == PEP_OUT_OF_MEMORY)
  10.320 -                            return (int) invalid_out_of_memory;
  10.321 -                        if (status != PEP_STATUS_OK)
  10.322 -                            return (int) invalid_action;
  10.323 -                        }
  10.324 -                    }
  10.325 -                    assert(session->sync_state_payload);
  10.326 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.327 -                    free_identity(((SoleBeaconed_state_payload_t*)session->sync_state_payload)->expected);
  10.328 -                    free(session->sync_state_payload);
  10.329 -                    session->sync_state_payload = NULL;
  10.330 -                    session->sync_state_payload = malloc(sizeof(HandshakingSole_state_payload_t));
  10.331 -                    assert(session->sync_state_payload);
  10.332 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.333 -                    ((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected =
  10.334 -                        identity_dup(partner);
  10.335 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=HandshakeRequest", "target=HandshakingSole")
  10.336 -                    return HandshakingSole;
  10.337 -                }
  10.338 -                case Timeout:
  10.339 -                {
  10.340 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleBeaconed", "event=Timeout")
  10.341 -                    assert(session->sync_state_payload);
  10.342 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.343 -                    free_identity(((SoleBeaconed_state_payload_t*)session->sync_state_payload)->expected);
  10.344 -                    free(session->sync_state_payload);
  10.345 -                    session->sync_state_payload = NULL;
  10.346 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleBeaconed, event=Timeout", "target=Sole")
  10.347 -                    return Sole;
  10.348 -                }
  10.349 -                default:
  10.350 -                    return (DeviceState_state) invalid_event;
  10.351 -            }
  10.352 -            break;
  10.353 -        }
  10.354 -        case HandshakingSole:
  10.355 -        {
  10.356 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=HandshakingSole")
  10.357 -            assert(session->sync_state_payload);
  10.358 -            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.359 -            Identity expected = ((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected;
  10.360 -            switch (event) {
  10.361 -                case Init:
  10.362 -                {
  10.363 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Init")
  10.364 -                    *timeout = 600;
  10.365 -                    {
  10.366 -                        int cond_result = keyElectionWon(session, expected);
  10.367 -                        #ifndef NDEBUG
  10.368 -                        char resstr[11] = {0,};
  10.369 -                        snprintf(resstr,10,"result=%d",cond_result);
  10.370 -                        #endif
  10.371 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=Init, condition=keyElectionWon", resstr)
  10.372 -                        if (cond_result < 0)
  10.373 -                            return cond_result;
  10.374 -                        if (cond_result) {
  10.375 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitFormGroup")
  10.376 -                        status = notifyInitFormGroup(session, state, expected, NULL);
  10.377 -                        if (status == PEP_OUT_OF_MEMORY)
  10.378 -                            return (int) invalid_out_of_memory;
  10.379 -                        if (status != PEP_STATUS_OK)
  10.380 -                            return (int) invalid_action;
  10.381 -                        }
  10.382 -                        else {
  10.383 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitAddOurDevice")
  10.384 -                        status = notifyInitAddOurDevice(session, state, expected, NULL);
  10.385 -                        if (status == PEP_OUT_OF_MEMORY)
  10.386 -                            return (int) invalid_out_of_memory;
  10.387 -                        if (status != PEP_STATUS_OK)
  10.388 -                            return (int) invalid_action;
  10.389 -                        }
  10.390 -                    }
  10.391 -                    break;
  10.392 -                }
  10.393 -                case HandshakeRejected:
  10.394 -                {
  10.395 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=HandshakeRejected")
  10.396 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeRejected", "action=rejectHandshake")
  10.397 -                    status = rejectHandshake(session, state, partner, NULL);
  10.398 -                    if (status == PEP_OUT_OF_MEMORY)
  10.399 -                        return (int) invalid_out_of_memory;
  10.400 -                    if (status != PEP_STATUS_OK)
  10.401 -                        return (int) invalid_action;
  10.402 -                    assert(session->sync_state_payload);
  10.403 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.404 -                    free_identity(((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected);
  10.405 -                    free(session->sync_state_payload);
  10.406 -                    session->sync_state_payload = NULL;
  10.407 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeRejected", "target=Sole")
  10.408 -                    return Sole;
  10.409 -                }
  10.410 -                case HandshakeAccepted:
  10.411 -                {
  10.412 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=HandshakeAccepted")
  10.413 -                    {
  10.414 -                        int cond_result = sameIdentities(session, partner, expected);
  10.415 -                        #ifndef NDEBUG
  10.416 -                        char resstr[11] = {0,};
  10.417 -                        snprintf(resstr,10,"result=%d",cond_result);
  10.418 -                        #endif
  10.419 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted, condition=sameIdentities", resstr)
  10.420 -                        if (cond_result < 0)
  10.421 -                            return cond_result;
  10.422 -                        if (cond_result) {
  10.423 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=acceptHandshake")
  10.424 -                        status = acceptHandshake(session, state, partner, NULL);
  10.425 -                        if (status == PEP_OUT_OF_MEMORY)
  10.426 -                            return (int) invalid_out_of_memory;
  10.427 -                        if (status != PEP_STATUS_OK)
  10.428 -                            return (int) invalid_action;
  10.429 -                        {
  10.430 -                            int cond_result = keyElectionWon(session, partner);
  10.431 -                            #ifndef NDEBUG
  10.432 -                            char resstr[11] = {0,};
  10.433 -                            snprintf(resstr,10,"result=%d",cond_result);
  10.434 -                            #endif
  10.435 -                            DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted, condition=keyElectionWon", resstr)
  10.436 -                            if (cond_result < 0)
  10.437 -                                return cond_result;
  10.438 -                            if (cond_result) {
  10.439 -                            DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=makeGroup")
  10.440 -                            status = makeGroup(session, state, NULL, NULL);
  10.441 -                            if (status == PEP_OUT_OF_MEMORY)
  10.442 -                                return (int) invalid_out_of_memory;
  10.443 -                            if (status != PEP_STATUS_OK)
  10.444 -                                return (int) invalid_action;
  10.445 -                            DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=sendGroupKeys")
  10.446 -                            status = sendGroupKeys(session, state, partner, NULL);
  10.447 -                            if (status == PEP_OUT_OF_MEMORY)
  10.448 -                                return (int) invalid_out_of_memory;
  10.449 -                            if (status != PEP_STATUS_OK)
  10.450 -                                return (int) invalid_action;
  10.451 -                            DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=renewUUID")
  10.452 -                            status = renewUUID(session, state, NULL, NULL);
  10.453 -                            if (status == PEP_OUT_OF_MEMORY)
  10.454 -                                return (int) invalid_out_of_memory;
  10.455 -                            if (status != PEP_STATUS_OK)
  10.456 -                                return (int) invalid_action;
  10.457 -                            DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=notifyAcceptedGroupCreated")
  10.458 -                            status = notifyAcceptedGroupCreated(session, state, partner, NULL);
  10.459 -                            if (status == PEP_OUT_OF_MEMORY)
  10.460 -                                return (int) invalid_out_of_memory;
  10.461 -                            if (status != PEP_STATUS_OK)
  10.462 -                                return (int) invalid_action;
  10.463 -                            assert(session->sync_state_payload);
  10.464 -                            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.465 -                            free_identity(((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected);
  10.466 -                            free(session->sync_state_payload);
  10.467 -                            session->sync_state_payload = NULL;
  10.468 -                            DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=Grouped")
  10.469 -                            return Grouped;
  10.470 -                            }
  10.471 -                        }
  10.472 -                        assert(session->sync_state_payload);
  10.473 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.474 -                        free_identity(((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected);
  10.475 -                        free(session->sync_state_payload);
  10.476 -                        session->sync_state_payload = NULL;
  10.477 -                        session->sync_state_payload = malloc(sizeof(WaitForGroupKeysSole_state_payload_t));
  10.478 -                        assert(session->sync_state_payload);
  10.479 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.480 -                        ((WaitForGroupKeysSole_state_payload_t*)session->sync_state_payload)->expected =
  10.481 -                            identity_dup(partner);
  10.482 -                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=WaitForGroupKeysSole")
  10.483 -                        return WaitForGroupKeysSole;
  10.484 -                        }
  10.485 -                    }
  10.486 -                    assert(session->sync_state_payload);
  10.487 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.488 -                    free_identity(((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected);
  10.489 -                    free(session->sync_state_payload);
  10.490 -                    session->sync_state_payload = NULL;
  10.491 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=Sole")
  10.492 -                    return Sole;
  10.493 -                }
  10.494 -                case Cancel:
  10.495 -                {
  10.496 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Cancel")
  10.497 -                    assert(session->sync_state_payload);
  10.498 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.499 -                    free_identity(((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected);
  10.500 -                    free(session->sync_state_payload);
  10.501 -                    session->sync_state_payload = NULL;
  10.502 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=Cancel", "target=Sole")
  10.503 -                    return Sole;
  10.504 -                }
  10.505 -                case GroupKeys:
  10.506 -                {
  10.507 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=GroupKeys")
  10.508 -                    group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
  10.509 -                    {
  10.510 -                        int cond_result = keyElectionWon(session, expected);
  10.511 -                        #ifndef NDEBUG
  10.512 -                        char resstr[11] = {0,};
  10.513 -                        snprintf(resstr,10,"result=%d",cond_result);
  10.514 -                        #endif
  10.515 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys, condition=keyElectionWon", resstr)
  10.516 -                        if (cond_result < 0)
  10.517 -                            return cond_result;
  10.518 -                        if (cond_result) {
  10.519 -                        }
  10.520 -                        else {
  10.521 -                        {
  10.522 -                            int cond_result = sameKeyAndAddress(session, partner, expected);
  10.523 -                            #ifndef NDEBUG
  10.524 -                            char resstr[11] = {0,};
  10.525 -                            snprintf(resstr,10,"result=%d",cond_result);
  10.526 -                            #endif
  10.527 -                            DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys, condition=sameKeyAndAddress", resstr)
  10.528 -                            if (cond_result < 0)
  10.529 -                                return cond_result;
  10.530 -                            if (cond_result) {
  10.531 -                            assert(session->sync_state_payload);
  10.532 -                            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.533 -                            free_identity(((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected);
  10.534 -                            free(session->sync_state_payload);
  10.535 -                            session->sync_state_payload = NULL;
  10.536 -                            session->sync_state_payload = malloc(sizeof(WaitForAcceptSole_state_payload_t));
  10.537 -                            assert(session->sync_state_payload);
  10.538 -                            if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.539 -                            ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected =
  10.540 -                                identity_dup(partner);
  10.541 -                            ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->groupkeys =
  10.542 -                                group_keys_extra_dup(groupkeys);
  10.543 -                            DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=GroupKeys", "target=WaitForAcceptSole")
  10.544 -                            return WaitForAcceptSole;
  10.545 -                            }
  10.546 -                        }
  10.547 -                        }
  10.548 -                    }
  10.549 -                    break;
  10.550 -                }
  10.551 -                case Timeout:
  10.552 -                {
  10.553 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Timeout")
  10.554 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Timeout", "action=notifyTimeout")
  10.555 -                    status = notifyTimeout(session, state, expected, NULL);
  10.556 -                    if (status == PEP_OUT_OF_MEMORY)
  10.557 -                        return (int) invalid_out_of_memory;
  10.558 -                    if (status != PEP_STATUS_OK)
  10.559 -                        return (int) invalid_action;
  10.560 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Timeout", "action=sendBeacon")
  10.561 -                    status = sendBeacon(session, state, NULL, NULL);
  10.562 -                    if (status == PEP_OUT_OF_MEMORY)
  10.563 -                        return (int) invalid_out_of_memory;
  10.564 -                    if (status != PEP_STATUS_OK)
  10.565 -                        return (int) invalid_action;
  10.566 -                    assert(session->sync_state_payload);
  10.567 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.568 -                    free_identity(((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected);
  10.569 -                    free(session->sync_state_payload);
  10.570 -                    session->sync_state_payload = NULL;
  10.571 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=Timeout", "target=Sole")
  10.572 -                    return Sole;
  10.573 -                }
  10.574 -                default:
  10.575 -                    return (DeviceState_state) invalid_event;
  10.576 -            }
  10.577 -            break;
  10.578 -        }
  10.579 -        case WaitForGroupKeysSole:
  10.580 -        {
  10.581 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=WaitForGroupKeysSole")
  10.582 -            assert(session->sync_state_payload);
  10.583 -            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.584 -            Identity expected = ((WaitForGroupKeysSole_state_payload_t*)session->sync_state_payload)->expected;
  10.585 -            switch (event) {
  10.586 -                case Init: 
  10.587 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=Init") 
  10.588 -                    *timeout = 600;
  10.589 -                    break;
  10.590 -                case GroupKeys:
  10.591 -                {
  10.592 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=GroupKeys")
  10.593 -                    group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
  10.594 -                    {
  10.595 -                        int cond_result = sameKeyAndAddress(session, partner, expected);
  10.596 -                        #ifndef NDEBUG
  10.597 -                        char resstr[11] = {0,};
  10.598 -                        snprintf(resstr,10,"result=%d",cond_result);
  10.599 -                        #endif
  10.600 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys, condition=sameKeyAndAddress", resstr)
  10.601 -                        if (cond_result < 0)
  10.602 -                            return cond_result;
  10.603 -                        if (cond_result) {
  10.604 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=storeGroupKeys")
  10.605 -                        status = storeGroupKeys(session, state, partner, groupkeys);
  10.606 -                        if (status == PEP_OUT_OF_MEMORY)
  10.607 -                            return (int) invalid_out_of_memory;
  10.608 -                        if (status != PEP_STATUS_OK)
  10.609 -                            return (int) invalid_action;
  10.610 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=sendGroupUpdate")
  10.611 -                        status = sendGroupUpdate(session, state, NULL, NULL);
  10.612 -                        if (status == PEP_OUT_OF_MEMORY)
  10.613 -                            return (int) invalid_out_of_memory;
  10.614 -                        if (status != PEP_STATUS_OK)
  10.615 -                            return (int) invalid_action;
  10.616 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=renewUUID")
  10.617 -                        status = renewUUID(session, state, NULL, NULL);
  10.618 -                        if (status == PEP_OUT_OF_MEMORY)
  10.619 -                            return (int) invalid_out_of_memory;
  10.620 -                        if (status != PEP_STATUS_OK)
  10.621 -                            return (int) invalid_action;
  10.622 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=notifyAcceptedDeviceAdded")
  10.623 -                        status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
  10.624 -                        if (status == PEP_OUT_OF_MEMORY)
  10.625 -                            return (int) invalid_out_of_memory;
  10.626 -                        if (status != PEP_STATUS_OK)
  10.627 -                            return (int) invalid_action;
  10.628 -                        assert(session->sync_state_payload);
  10.629 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.630 -                        free_identity(((WaitForGroupKeysSole_state_payload_t*)session->sync_state_payload)->expected);
  10.631 -                        free(session->sync_state_payload);
  10.632 -                        session->sync_state_payload = NULL;
  10.633 -                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "target=Grouped")
  10.634 -                        return Grouped;
  10.635 -                        }
  10.636 -                    }
  10.637 -                    break;
  10.638 -                }
  10.639 -                case Timeout:
  10.640 -                {
  10.641 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=Timeout")
  10.642 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=Timeout", "action=notifyTimeout")
  10.643 -                    status = notifyTimeout(session, state, expected, NULL);
  10.644 -                    if (status == PEP_OUT_OF_MEMORY)
  10.645 -                        return (int) invalid_out_of_memory;
  10.646 -                    if (status != PEP_STATUS_OK)
  10.647 -                        return (int) invalid_action;
  10.648 -                    assert(session->sync_state_payload);
  10.649 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.650 -                    free_identity(((WaitForGroupKeysSole_state_payload_t*)session->sync_state_payload)->expected);
  10.651 -                    free(session->sync_state_payload);
  10.652 -                    session->sync_state_payload = NULL;
  10.653 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysSole, event=Timeout", "target=Sole")
  10.654 -                    return Sole;
  10.655 -                }
  10.656 -                default:
  10.657 -                    return (DeviceState_state) invalid_event;
  10.658 -            }
  10.659 -            break;
  10.660 -        }
  10.661 -        case WaitForAcceptSole:
  10.662 -        {
  10.663 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=WaitForAcceptSole")
  10.664 -            assert(session->sync_state_payload);
  10.665 -            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.666 -            Identity expected = ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected;
  10.667 -            group_keys_extra_t* groupkeys = ((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->groupkeys;
  10.668 -            switch (event) {
  10.669 -                case Init: 
  10.670 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=Init") 
  10.671 -                    *timeout = 600;
  10.672 -                    break;
  10.673 -                case HandshakeRejected:
  10.674 -                {
  10.675 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=HandshakeRejected")
  10.676 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeRejected", "action=rejectHandshake")
  10.677 -                    status = rejectHandshake(session, state, partner, NULL);
  10.678 -                    if (status == PEP_OUT_OF_MEMORY)
  10.679 -                        return (int) invalid_out_of_memory;
  10.680 -                    if (status != PEP_STATUS_OK)
  10.681 -                        return (int) invalid_action;
  10.682 -                    assert(session->sync_state_payload);
  10.683 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.684 -                    free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
  10.685 -                    free_group_keys_extra(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->groupkeys);
  10.686 -                    free(session->sync_state_payload);
  10.687 -                    session->sync_state_payload = NULL;
  10.688 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeRejected", "target=Sole")
  10.689 -                    return Sole;
  10.690 -                }
  10.691 -                case HandshakeAccepted:
  10.692 -                {
  10.693 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=HandshakeAccepted")
  10.694 -                    {
  10.695 -                        int cond_result = sameKeyAndAddress(session, partner, expected);
  10.696 -                        #ifndef NDEBUG
  10.697 -                        char resstr[11] = {0,};
  10.698 -                        snprintf(resstr,10,"result=%d",cond_result);
  10.699 -                        #endif
  10.700 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted, condition=sameKeyAndAddress", resstr)
  10.701 -                        if (cond_result < 0)
  10.702 -                            return cond_result;
  10.703 -                        if (cond_result) {
  10.704 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=acceptHandshake")
  10.705 -                        status = acceptHandshake(session, state, partner, NULL);
  10.706 -                        if (status == PEP_OUT_OF_MEMORY)
  10.707 -                            return (int) invalid_out_of_memory;
  10.708 -                        if (status != PEP_STATUS_OK)
  10.709 -                            return (int) invalid_action;
  10.710 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=storeGroupKeys")
  10.711 -                        status = storeGroupKeys(session, state, partner, groupkeys);
  10.712 -                        if (status == PEP_OUT_OF_MEMORY)
  10.713 -                            return (int) invalid_out_of_memory;
  10.714 -                        if (status != PEP_STATUS_OK)
  10.715 -                            return (int) invalid_action;
  10.716 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=sendGroupUpdate")
  10.717 -                        status = sendGroupUpdate(session, state, NULL, NULL);
  10.718 -                        if (status == PEP_OUT_OF_MEMORY)
  10.719 -                            return (int) invalid_out_of_memory;
  10.720 -                        if (status != PEP_STATUS_OK)
  10.721 -                            return (int) invalid_action;
  10.722 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=renewUUID")
  10.723 -                        status = renewUUID(session, state, NULL, NULL);
  10.724 -                        if (status == PEP_OUT_OF_MEMORY)
  10.725 -                            return (int) invalid_out_of_memory;
  10.726 -                        if (status != PEP_STATUS_OK)
  10.727 -                            return (int) invalid_action;
  10.728 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "action=notifyAcceptedDeviceAdded")
  10.729 -                        status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
  10.730 -                        if (status == PEP_OUT_OF_MEMORY)
  10.731 -                            return (int) invalid_out_of_memory;
  10.732 -                        if (status != PEP_STATUS_OK)
  10.733 -                            return (int) invalid_action;
  10.734 -                        assert(session->sync_state_payload);
  10.735 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.736 -                        free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
  10.737 -                        free_group_keys_extra(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->groupkeys);
  10.738 -                        free(session->sync_state_payload);
  10.739 -                        session->sync_state_payload = NULL;
  10.740 -                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "target=Grouped")
  10.741 -                        return Grouped;
  10.742 -                        }
  10.743 -                    }
  10.744 -                    assert(session->sync_state_payload);
  10.745 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.746 -                    free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
  10.747 -                    free_group_keys_extra(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->groupkeys);
  10.748 -                    free(session->sync_state_payload);
  10.749 -                    session->sync_state_payload = NULL;
  10.750 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=HandshakeAccepted", "target=Sole")
  10.751 -                    return Sole;
  10.752 -                }
  10.753 -                case Cancel:
  10.754 -                {
  10.755 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=Cancel")
  10.756 -                    assert(session->sync_state_payload);
  10.757 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.758 -                    free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
  10.759 -                    free_group_keys_extra(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->groupkeys);
  10.760 -                    free(session->sync_state_payload);
  10.761 -                    session->sync_state_payload = NULL;
  10.762 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=Cancel", "target=Sole")
  10.763 -                    return Sole;
  10.764 -                }
  10.765 -                case Timeout:
  10.766 -                {
  10.767 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptSole", "event=Timeout")
  10.768 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptSole, event=Timeout", "action=notifyTimeout")
  10.769 -                    status = notifyTimeout(session, state, expected, NULL);
  10.770 -                    if (status == PEP_OUT_OF_MEMORY)
  10.771 -                        return (int) invalid_out_of_memory;
  10.772 -                    if (status != PEP_STATUS_OK)
  10.773 -                        return (int) invalid_action;
  10.774 -                    assert(session->sync_state_payload);
  10.775 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.776 -                    free_identity(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->expected);
  10.777 -                    free_group_keys_extra(((WaitForAcceptSole_state_payload_t*)session->sync_state_payload)->groupkeys);
  10.778 -                    free(session->sync_state_payload);
  10.779 -                    session->sync_state_payload = NULL;
  10.780 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptSole, event=Timeout", "target=Sole")
  10.781 -                    return Sole;
  10.782 -                }
  10.783 -                default:
  10.784 -                    return (DeviceState_state) invalid_event;
  10.785 -            }
  10.786 -            break;
  10.787 -        }
  10.788 -        case Grouped:
  10.789 -        {
  10.790 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=Grouped")
  10.791 -            switch (event) {
  10.792 -                case Init: 
  10.793 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=Init") 
  10.794 -                    *timeout = 0;
  10.795 -                    break;
  10.796 -                case KeyGen:
  10.797 -                {
  10.798 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=KeyGen")
  10.799 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=KeyGen", "action=sendGroupUpdate")
  10.800 -                    status = sendGroupUpdate(session, state, NULL, NULL);
  10.801 -                    if (status == PEP_OUT_OF_MEMORY)
  10.802 -                        return (int) invalid_out_of_memory;
  10.803 -                    if (status != PEP_STATUS_OK)
  10.804 -                        return (int) invalid_action;
  10.805 -                    break;
  10.806 -                }
  10.807 -                case CannotDecrypt:
  10.808 -                {
  10.809 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=CannotDecrypt")
  10.810 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=CannotDecrypt", "action=sendUpdateRequest")
  10.811 -                    status = sendUpdateRequest(session, state, NULL, NULL);
  10.812 -                    if (status == PEP_OUT_OF_MEMORY)
  10.813 -                        return (int) invalid_out_of_memory;
  10.814 -                    if (status != PEP_STATUS_OK)
  10.815 -                        return (int) invalid_action;
  10.816 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=CannotDecrypt", "action=sendBeacon")
  10.817 -                    status = sendBeacon(session, state, NULL, NULL);
  10.818 -                    if (status == PEP_OUT_OF_MEMORY)
  10.819 -                        return (int) invalid_out_of_memory;
  10.820 -                    if (status != PEP_STATUS_OK)
  10.821 -                        return (int) invalid_action;
  10.822 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Grouped, event=CannotDecrypt", "target=GroupWaiting")
  10.823 -                    return GroupWaiting;
  10.824 -                }
  10.825 -                case UpdateRequest:
  10.826 -                {
  10.827 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=UpdateRequest")
  10.828 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=UpdateRequest", "action=sendGroupUpdate")
  10.829 -                    status = sendGroupUpdate(session, state, NULL, NULL);
  10.830 -                    if (status == PEP_OUT_OF_MEMORY)
  10.831 -                        return (int) invalid_out_of_memory;
  10.832 -                    if (status != PEP_STATUS_OK)
  10.833 -                        return (int) invalid_action;
  10.834 -                    break;
  10.835 -                }
  10.836 -                case Beacon:
  10.837 -                {
  10.838 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=Beacon")
  10.839 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=Beacon", "action=sendHandshakeRequest")
  10.840 -                    status = sendHandshakeRequest(session, state, partner, NULL);
  10.841 -                    if (status == PEP_OUT_OF_MEMORY)
  10.842 -                        return (int) invalid_out_of_memory;
  10.843 -                    if (status != PEP_STATUS_OK)
  10.844 -                        return (int) invalid_action;
  10.845 -                    session->sync_state_payload = malloc(sizeof(GroupedBeaconed_state_payload_t));
  10.846 -                    assert(session->sync_state_payload);
  10.847 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.848 -                    ((GroupedBeaconed_state_payload_t*)session->sync_state_payload)->expected =
  10.849 -                        identity_dup(partner);
  10.850 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Grouped, event=Beacon", "target=GroupedBeaconed")
  10.851 -                    return GroupedBeaconed;
  10.852 -                }
  10.853 -                case HandshakeRequest:
  10.854 -                {
  10.855 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=HandshakeRequest")
  10.856 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=HandshakeRequest", "action=sendHandshakeRequest")
  10.857 -                    status = sendHandshakeRequest(session, state, partner, NULL);
  10.858 -                    if (status == PEP_OUT_OF_MEMORY)
  10.859 -                        return (int) invalid_out_of_memory;
  10.860 -                    if (status != PEP_STATUS_OK)
  10.861 -                        return (int) invalid_action;
  10.862 -                    session->sync_state_payload = malloc(sizeof(HandshakingGrouped_state_payload_t));
  10.863 -                    assert(session->sync_state_payload);
  10.864 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.865 -                    ((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected =
  10.866 -                        identity_dup(partner);
  10.867 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Grouped, event=HandshakeRequest", "target=HandshakingGrouped")
  10.868 -                    return HandshakingGrouped;
  10.869 -                }
  10.870 -                case GroupUpdate:
  10.871 -                {
  10.872 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=GroupUpdate")
  10.873 -                    identity_list* keys = (identity_list*)extra;
  10.874 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=GroupUpdate", "action=storeGroupUpdate")
  10.875 -                    status = storeGroupUpdate(session, state, partner, keys);
  10.876 -                    if (status == PEP_OUT_OF_MEMORY)
  10.877 -                        return (int) invalid_out_of_memory;
  10.878 -                    if (status != PEP_STATUS_OK)
  10.879 -                        return (int) invalid_action;
  10.880 -                    break;
  10.881 -                }
  10.882 -                default:
  10.883 -                    return (DeviceState_state) invalid_event;
  10.884 -            }
  10.885 -            break;
  10.886 -        }
  10.887 -        case GroupWaiting:
  10.888 -        {
  10.889 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=GroupWaiting")
  10.890 -            switch (event) {
  10.891 -                case Init: 
  10.892 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=Init") 
  10.893 -                    *timeout = 60;
  10.894 -                    break;
  10.895 -                case KeyGen:
  10.896 -                {
  10.897 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=KeyGen")
  10.898 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=KeyGen", "action=sendGroupUpdate")
  10.899 -                    status = sendGroupUpdate(session, state, NULL, NULL);
  10.900 -                    if (status == PEP_OUT_OF_MEMORY)
  10.901 -                        return (int) invalid_out_of_memory;
  10.902 -                    if (status != PEP_STATUS_OK)
  10.903 -                        return (int) invalid_action;
  10.904 -                    break;
  10.905 -                }
  10.906 -                case CannotDecrypt:
  10.907 -                {
  10.908 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=CannotDecrypt")
  10.909 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=CannotDecrypt", "action=sendUpdateRequest")
  10.910 -                    status = sendUpdateRequest(session, state, NULL, NULL);
  10.911 -                    if (status == PEP_OUT_OF_MEMORY)
  10.912 -                        return (int) invalid_out_of_memory;
  10.913 -                    if (status != PEP_STATUS_OK)
  10.914 -                        return (int) invalid_action;
  10.915 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=CannotDecrypt", "action=sendBeacon")
  10.916 -                    status = sendBeacon(session, state, NULL, NULL);
  10.917 -                    if (status == PEP_OUT_OF_MEMORY)
  10.918 -                        return (int) invalid_out_of_memory;
  10.919 -                    if (status != PEP_STATUS_OK)
  10.920 -                        return (int) invalid_action;
  10.921 -                    break;
  10.922 -                }
  10.923 -                case UpdateRequest:
  10.924 -                {
  10.925 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=UpdateRequest")
  10.926 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=UpdateRequest", "action=sendGroupUpdate")
  10.927 -                    status = sendGroupUpdate(session, state, NULL, NULL);
  10.928 -                    if (status == PEP_OUT_OF_MEMORY)
  10.929 -                        return (int) invalid_out_of_memory;
  10.930 -                    if (status != PEP_STATUS_OK)
  10.931 -                        return (int) invalid_action;
  10.932 -                    break;
  10.933 -                }
  10.934 -                case Beacon:
  10.935 -                {
  10.936 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=Beacon")
  10.937 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=Beacon", "action=sendHandshakeRequest")
  10.938 -                    status = sendHandshakeRequest(session, state, partner, NULL);
  10.939 -                    if (status == PEP_OUT_OF_MEMORY)
  10.940 -                        return (int) invalid_out_of_memory;
  10.941 -                    if (status != PEP_STATUS_OK)
  10.942 -                        return (int) invalid_action;
  10.943 -                    session->sync_state_payload = malloc(sizeof(GroupedBeaconed_state_payload_t));
  10.944 -                    assert(session->sync_state_payload);
  10.945 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.946 -                    ((GroupedBeaconed_state_payload_t*)session->sync_state_payload)->expected =
  10.947 -                        identity_dup(partner);
  10.948 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupWaiting, event=Beacon", "target=GroupedBeaconed")
  10.949 -                    return GroupedBeaconed;
  10.950 -                }
  10.951 -                case HandshakeRequest:
  10.952 -                {
  10.953 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=HandshakeRequest")
  10.954 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=HandshakeRequest", "action=sendHandshakeRequest")
  10.955 -                    status = sendHandshakeRequest(session, state, partner, NULL);
  10.956 -                    if (status == PEP_OUT_OF_MEMORY)
  10.957 -                        return (int) invalid_out_of_memory;
  10.958 -                    if (status != PEP_STATUS_OK)
  10.959 -                        return (int) invalid_action;
  10.960 -                    session->sync_state_payload = malloc(sizeof(HandshakingGrouped_state_payload_t));
  10.961 -                    assert(session->sync_state_payload);
  10.962 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
  10.963 -                    ((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected =
  10.964 -                        identity_dup(partner);
  10.965 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupWaiting, event=HandshakeRequest", "target=HandshakingGrouped")
  10.966 -                    return HandshakingGrouped;
  10.967 -                }
  10.968 -                case GroupUpdate:
  10.969 -                {
  10.970 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=GroupUpdate")
  10.971 -                    identity_list* keys = (identity_list*)extra;
  10.972 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=GroupUpdate", "action=storeGroupUpdate")
  10.973 -                    status = storeGroupUpdate(session, state, partner, keys);
  10.974 -                    if (status == PEP_OUT_OF_MEMORY)
  10.975 -                        return (int) invalid_out_of_memory;
  10.976 -                    if (status != PEP_STATUS_OK)
  10.977 -                        return (int) invalid_action;
  10.978 -                    break;
  10.979 -                }
  10.980 -                case Timeout:
  10.981 -                {
  10.982 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=Timeout")
  10.983 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupWaiting, event=Timeout", "target=Grouped")
  10.984 -                    return Grouped;
  10.985 -                }
  10.986 -                default:
  10.987 -                    return (DeviceState_state) invalid_event;
  10.988 -            }
  10.989 -            break;
  10.990 -        }
  10.991 -        case GroupedBeaconed:
  10.992 -        {
  10.993 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=GroupedBeaconed")
  10.994 -            assert(session->sync_state_payload);
  10.995 -            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
  10.996 -            Identity expected = ((GroupedBeaconed_state_payload_t*)session->sync_state_payload)->expected;
  10.997 -            switch (event) {
  10.998 -                case Init: 
  10.999 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Init") 
 10.1000 -                    *timeout = 600;
 10.1001 -                    break;
 10.1002 -                case KeyGen:
 10.1003 -                {
 10.1004 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=KeyGen")
 10.1005 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=KeyGen", "action=sendGroupUpdate")
 10.1006 -                    status = sendGroupUpdate(session, state, NULL, NULL);
 10.1007 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1008 -                        return (int) invalid_out_of_memory;
 10.1009 -                    if (status != PEP_STATUS_OK)
 10.1010 -                        return (int) invalid_action;
 10.1011 -                    break;
 10.1012 -                }
 10.1013 -                case CannotDecrypt:
 10.1014 -                {
 10.1015 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=CannotDecrypt")
 10.1016 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=CannotDecrypt", "action=sendUpdateRequest")
 10.1017 -                    status = sendUpdateRequest(session, state, NULL, NULL);
 10.1018 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1019 -                        return (int) invalid_out_of_memory;
 10.1020 -                    if (status != PEP_STATUS_OK)
 10.1021 -                        return (int) invalid_action;
 10.1022 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=CannotDecrypt", "action=sendBeacon")
 10.1023 -                    status = sendBeacon(session, state, NULL, NULL);
 10.1024 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1025 -                        return (int) invalid_out_of_memory;
 10.1026 -                    if (status != PEP_STATUS_OK)
 10.1027 -                        return (int) invalid_action;
 10.1028 -                    break;
 10.1029 -                }
 10.1030 -                case UpdateRequest:
 10.1031 -                {
 10.1032 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=UpdateRequest")
 10.1033 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=UpdateRequest", "action=sendGroupUpdate")
 10.1034 -                    status = sendGroupUpdate(session, state, NULL, NULL);
 10.1035 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1036 -                        return (int) invalid_out_of_memory;
 10.1037 -                    if (status != PEP_STATUS_OK)
 10.1038 -                        return (int) invalid_action;
 10.1039 -                    break;
 10.1040 -                }
 10.1041 -                case Beacon:
 10.1042 -                {
 10.1043 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Beacon")
 10.1044 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=Beacon", "action=sendHandshakeRequest")
 10.1045 -                    status = sendHandshakeRequest(session, state, partner, NULL);
 10.1046 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1047 -                        return (int) invalid_out_of_memory;
 10.1048 -                    if (status != PEP_STATUS_OK)
 10.1049 -                        return (int) invalid_action;
 10.1050 -                    assert(session->sync_state_payload);
 10.1051 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1052 -                    free_identity(((GroupedBeaconed_state_payload_t*)session->sync_state_payload)->expected);
 10.1053 -                    free(session->sync_state_payload);
 10.1054 -                    session->sync_state_payload = NULL;
 10.1055 -                    session->sync_state_payload = malloc(sizeof(GroupedBeaconed_state_payload_t));
 10.1056 -                    assert(session->sync_state_payload);
 10.1057 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
 10.1058 -                    ((GroupedBeaconed_state_payload_t*)session->sync_state_payload)->expected =
 10.1059 -                        identity_dup(partner);
 10.1060 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=Beacon", "target=GroupedBeaconed")
 10.1061 -                    return GroupedBeaconed;
 10.1062 -                }
 10.1063 -                case HandshakeRequest:
 10.1064 -                {
 10.1065 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=HandshakeRequest")
 10.1066 -                    {
 10.1067 -                        int cond_result = sameIdentities(session, partner, expected);
 10.1068 -                        #ifndef NDEBUG
 10.1069 -                        char resstr[11] = {0,};
 10.1070 -                        snprintf(resstr,10,"result=%d",cond_result);
 10.1071 -                        #endif
 10.1072 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest, condition=sameIdentities", resstr)
 10.1073 -                        if (cond_result < 0)
 10.1074 -                            return cond_result;
 10.1075 -                        if (cond_result) {
 10.1076 -                        }
 10.1077 -                        else {
 10.1078 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest", "action=sendHandshakeRequest")
 10.1079 -                        status = sendHandshakeRequest(session, state, partner, NULL);
 10.1080 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1081 -                            return (int) invalid_out_of_memory;
 10.1082 -                        if (status != PEP_STATUS_OK)
 10.1083 -                            return (int) invalid_action;
 10.1084 -                        }
 10.1085 -                    }
 10.1086 -                    assert(session->sync_state_payload);
 10.1087 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1088 -                    free_identity(((GroupedBeaconed_state_payload_t*)session->sync_state_payload)->expected);
 10.1089 -                    free(session->sync_state_payload);
 10.1090 -                    session->sync_state_payload = NULL;
 10.1091 -                    session->sync_state_payload = malloc(sizeof(HandshakingGrouped_state_payload_t));
 10.1092 -                    assert(session->sync_state_payload);
 10.1093 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
 10.1094 -                    ((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected =
 10.1095 -                        identity_dup(partner);
 10.1096 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=HandshakeRequest", "target=HandshakingGrouped")
 10.1097 -                    return HandshakingGrouped;
 10.1098 -                }
 10.1099 -                case GroupUpdate:
 10.1100 -                {
 10.1101 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=GroupUpdate")
 10.1102 -                    identity_list* keys = (identity_list*)extra;
 10.1103 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=GroupUpdate", "action=storeGroupUpdate")
 10.1104 -                    status = storeGroupUpdate(session, state, partner, keys);
 10.1105 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1106 -                        return (int) invalid_out_of_memory;
 10.1107 -                    if (status != PEP_STATUS_OK)
 10.1108 -                        return (int) invalid_action;
 10.1109 -                    break;
 10.1110 -                }
 10.1111 -                case Timeout:
 10.1112 -                {
 10.1113 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=Timeout")
 10.1114 -                    assert(session->sync_state_payload);
 10.1115 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1116 -                    free_identity(((GroupedBeaconed_state_payload_t*)session->sync_state_payload)->expected);
 10.1117 -                    free(session->sync_state_payload);
 10.1118 -                    session->sync_state_payload = NULL;
 10.1119 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupedBeaconed, event=Timeout", "target=Grouped")
 10.1120 -                    return Grouped;
 10.1121 -                }
 10.1122 -                default:
 10.1123 -                    return (DeviceState_state) invalid_event;
 10.1124 -            }
 10.1125 -            break;
 10.1126 -        }
 10.1127 -        case HandshakingGrouped:
 10.1128 -        {
 10.1129 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=HandshakingGrouped")
 10.1130 -            assert(session->sync_state_payload);
 10.1131 -            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1132 -            Identity expected = ((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected;
 10.1133 -            switch (event) {
 10.1134 -                case Init:
 10.1135 -                {
 10.1136 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Init")
 10.1137 -                    *timeout = 600;
 10.1138 -                    {
 10.1139 -                        int cond_result = keyElectionWon(session, expected);
 10.1140 -                        #ifndef NDEBUG
 10.1141 -                        char resstr[11] = {0,};
 10.1142 -                        snprintf(resstr,10,"result=%d",cond_result);
 10.1143 -                        #endif
 10.1144 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=Init, condition=keyElectionWon", resstr)
 10.1145 -                        if (cond_result < 0)
 10.1146 -                            return cond_result;
 10.1147 -                        if (cond_result) {
 10.1148 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Init", "action=notifyInitAddOtherDevice")
 10.1149 -                        status = notifyInitAddOtherDevice(session, state, partner, NULL);
 10.1150 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1151 -                            return (int) invalid_out_of_memory;
 10.1152 -                        if (status != PEP_STATUS_OK)
 10.1153 -                            return (int) invalid_action;
 10.1154 -                        }
 10.1155 -                        else {
 10.1156 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Init", "action=notifyInitMoveOurDevice")
 10.1157 -                        status = notifyInitMoveOurDevice(session, state, partner, NULL);
 10.1158 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1159 -                            return (int) invalid_out_of_memory;
 10.1160 -                        if (status != PEP_STATUS_OK)
 10.1161 -                            return (int) invalid_action;
 10.1162 -                        }
 10.1163 -                    }
 10.1164 -                    break;
 10.1165 -                }
 10.1166 -                case HandshakeRejected:
 10.1167 -                {
 10.1168 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=HandshakeRejected")
 10.1169 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeRejected", "action=rejectHandshake")
 10.1170 -                    status = rejectHandshake(session, state, partner, NULL);
 10.1171 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1172 -                        return (int) invalid_out_of_memory;
 10.1173 -                    if (status != PEP_STATUS_OK)
 10.1174 -                        return (int) invalid_action;
 10.1175 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeRejected", "action=sendGroupUpdate")
 10.1176 -                    status = sendGroupUpdate(session, state, NULL, NULL);
 10.1177 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1178 -                        return (int) invalid_out_of_memory;
 10.1179 -                    if (status != PEP_STATUS_OK)
 10.1180 -                        return (int) invalid_action;
 10.1181 -                    assert(session->sync_state_payload);
 10.1182 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1183 -                    free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1184 -                    free(session->sync_state_payload);
 10.1185 -                    session->sync_state_payload = NULL;
 10.1186 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeRejected", "target=Grouped")
 10.1187 -                    return Grouped;
 10.1188 -                }
 10.1189 -                case HandshakeAccepted:
 10.1190 -                {
 10.1191 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=HandshakeAccepted")
 10.1192 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=acceptHandshake")
 10.1193 -                    status = acceptHandshake(session, state, partner, NULL);
 10.1194 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1195 -                        return (int) invalid_out_of_memory;
 10.1196 -                    if (status != PEP_STATUS_OK)
 10.1197 -                        return (int) invalid_action;
 10.1198 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=sendGroupUpdate")
 10.1199 -                    status = sendGroupUpdate(session, state, NULL, NULL);
 10.1200 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1201 -                        return (int) invalid_out_of_memory;
 10.1202 -                    if (status != PEP_STATUS_OK)
 10.1203 -                        return (int) invalid_action;
 10.1204 -                    {
 10.1205 -                        int cond_result = keyElectionWon(session, partner);
 10.1206 -                        #ifndef NDEBUG
 10.1207 -                        char resstr[11] = {0,};
 10.1208 -                        snprintf(resstr,10,"result=%d",cond_result);
 10.1209 -                        #endif
 10.1210 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted, condition=keyElectionWon", resstr)
 10.1211 -                        if (cond_result < 0)
 10.1212 -                            return cond_result;
 10.1213 -                        if (cond_result) {
 10.1214 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=sendGroupKeys")
 10.1215 -                        status = sendGroupKeys(session, state, partner, NULL);
 10.1216 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1217 -                            return (int) invalid_out_of_memory;
 10.1218 -                        if (status != PEP_STATUS_OK)
 10.1219 -                            return (int) invalid_action;
 10.1220 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=notifyAcceptedDeviceAdded")
 10.1221 -                        status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
 10.1222 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1223 -                            return (int) invalid_out_of_memory;
 10.1224 -                        if (status != PEP_STATUS_OK)
 10.1225 -                            return (int) invalid_action;
 10.1226 -                        assert(session->sync_state_payload);
 10.1227 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1228 -                        free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1229 -                        free(session->sync_state_payload);
 10.1230 -                        session->sync_state_payload = NULL;
 10.1231 -                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "target=Grouped")
 10.1232 -                        return Grouped;
 10.1233 -                        }
 10.1234 -                    }
 10.1235 -                    assert(session->sync_state_payload);
 10.1236 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1237 -                    free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1238 -                    free(session->sync_state_payload);
 10.1239 -                    session->sync_state_payload = NULL;
 10.1240 -                    session->sync_state_payload = malloc(sizeof(WaitForGroupKeysGrouped_state_payload_t));
 10.1241 -                    assert(session->sync_state_payload);
 10.1242 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
 10.1243 -                    ((WaitForGroupKeysGrouped_state_payload_t*)session->sync_state_payload)->expected =
 10.1244 -                        identity_dup(partner);
 10.1245 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "target=WaitForGroupKeysGrouped")
 10.1246 -                    return WaitForGroupKeysGrouped;
 10.1247 -                }
 10.1248 -                case Cancel:
 10.1249 -                {
 10.1250 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Cancel")
 10.1251 -                    assert(session->sync_state_payload);
 10.1252 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1253 -                    free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1254 -                    free(session->sync_state_payload);
 10.1255 -                    session->sync_state_payload = NULL;
 10.1256 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=Cancel", "target=Grouped")
 10.1257 -                    return Grouped;
 10.1258 -                }
 10.1259 -                case GroupKeys:
 10.1260 -                {
 10.1261 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=GroupKeys")
 10.1262 -                    group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
 10.1263 -                    {
 10.1264 -                        int cond_result = keyElectionWon(session, expected);
 10.1265 -                        #ifndef NDEBUG
 10.1266 -                        char resstr[11] = {0,};
 10.1267 -                        snprintf(resstr,10,"result=%d",cond_result);
 10.1268 -                        #endif
 10.1269 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys, condition=keyElectionWon", resstr)
 10.1270 -                        if (cond_result < 0)
 10.1271 -                            return cond_result;
 10.1272 -                        if (cond_result) {
 10.1273 -                        }
 10.1274 -                        else {
 10.1275 -                        {
 10.1276 -                            int cond_result = sameKeyAndAddress(session, partner, expected);
 10.1277 -                            #ifndef NDEBUG
 10.1278 -                            char resstr[11] = {0,};
 10.1279 -                            snprintf(resstr,10,"result=%d",cond_result);
 10.1280 -                            #endif
 10.1281 -                            DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys, condition=sameKeyAndAddress", resstr)
 10.1282 -                            if (cond_result < 0)
 10.1283 -                                return cond_result;
 10.1284 -                            if (cond_result) {
 10.1285 -                            assert(session->sync_state_payload);
 10.1286 -                            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1287 -                            free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1288 -                            free(session->sync_state_payload);
 10.1289 -                            session->sync_state_payload = NULL;
 10.1290 -                            session->sync_state_payload = malloc(sizeof(WaitForAcceptGrouped_state_payload_t));
 10.1291 -                            assert(session->sync_state_payload);
 10.1292 -                            if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
 10.1293 -                            ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected =
 10.1294 -                                identity_dup(partner);
 10.1295 -                            ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->groupkeys =
 10.1296 -                                group_keys_extra_dup(groupkeys);
 10.1297 -                            DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=GroupKeys", "target=WaitForAcceptGrouped")
 10.1298 -                            return WaitForAcceptGrouped;
 10.1299 -                            }
 10.1300 -                        }
 10.1301 -                        }
 10.1302 -                    }
 10.1303 -                    break;
 10.1304 -                }
 10.1305 -                case GroupUpdate:
 10.1306 -                {
 10.1307 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=GroupUpdate")
 10.1308 -                    identity_list* keys = (identity_list*)extra;
 10.1309 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=GroupUpdate", "action=notifyOvertaken")
 10.1310 -                    status = notifyOvertaken(session, state, partner, NULL);
 10.1311 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1312 -                        return (int) invalid_out_of_memory;
 10.1313 -                    if (status != PEP_STATUS_OK)
 10.1314 -                        return (int) invalid_action;
 10.1315 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=GroupUpdate", "action=storeGroupUpdate")
 10.1316 -                    status = storeGroupUpdate(session, state, partner, keys);
 10.1317 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1318 -                        return (int) invalid_out_of_memory;
 10.1319 -                    if (status != PEP_STATUS_OK)
 10.1320 -                        return (int) invalid_action;
 10.1321 -                    assert(session->sync_state_payload);
 10.1322 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1323 -                    free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1324 -                    free(session->sync_state_payload);
 10.1325 -                    session->sync_state_payload = NULL;
 10.1326 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=GroupUpdate", "target=Grouped")
 10.1327 -                    return Grouped;
 10.1328 -                }
 10.1329 -                case Timeout:
 10.1330 -                {
 10.1331 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Timeout")
 10.1332 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Timeout", "action=notifyTimeout")
 10.1333 -                    status = notifyTimeout(session, state, expected, NULL);
 10.1334 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1335 -                        return (int) invalid_out_of_memory;
 10.1336 -                    if (status != PEP_STATUS_OK)
 10.1337 -                        return (int) invalid_action;
 10.1338 -                    assert(session->sync_state_payload);
 10.1339 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1340 -                    free_identity(((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1341 -                    free(session->sync_state_payload);
 10.1342 -                    session->sync_state_payload = NULL;
 10.1343 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=Timeout", "target=Grouped")
 10.1344 -                    return Grouped;
 10.1345 -                }
 10.1346 -                default:
 10.1347 -                    return (DeviceState_state) invalid_event;
 10.1348 -            }
 10.1349 -            break;
 10.1350 -        }
 10.1351 -        case WaitForGroupKeysGrouped:
 10.1352 -        {
 10.1353 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=WaitForGroupKeysGrouped")
 10.1354 -            assert(session->sync_state_payload);
 10.1355 -            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1356 -            Identity expected = ((WaitForGroupKeysGrouped_state_payload_t*)session->sync_state_payload)->expected;
 10.1357 -            switch (event) {
 10.1358 -                case Init: 
 10.1359 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysGrouped", "event=Init") 
 10.1360 -                    *timeout = 600;
 10.1361 -                    break;
 10.1362 -                case GroupKeys:
 10.1363 -                {
 10.1364 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysGrouped", "event=GroupKeys")
 10.1365 -                    group_keys_extra_t* groupkeys = (group_keys_extra_t*)extra;
 10.1366 -                    {
 10.1367 -                        int cond_result = sameIdentities(session, partner, expected);
 10.1368 -                        #ifndef NDEBUG
 10.1369 -                        char resstr[11] = {0,};
 10.1370 -                        snprintf(resstr,10,"result=%d",cond_result);
 10.1371 -                        #endif
 10.1372 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys, condition=sameIdentities", resstr)
 10.1373 -                        if (cond_result < 0)
 10.1374 -                            return cond_result;
 10.1375 -                        if (cond_result) {
 10.1376 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "action=storeGroupKeys")
 10.1377 -                        status = storeGroupKeys(session, state, partner, groupkeys);
 10.1378 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1379 -                            return (int) invalid_out_of_memory;
 10.1380 -                        if (status != PEP_STATUS_OK)
 10.1381 -                            return (int) invalid_action;
 10.1382 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "action=sendGroupUpdate")
 10.1383 -                        status = sendGroupUpdate(session, state, NULL, NULL);
 10.1384 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1385 -                            return (int) invalid_out_of_memory;
 10.1386 -                        if (status != PEP_STATUS_OK)
 10.1387 -                            return (int) invalid_action;
 10.1388 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "action=renewUUID")
 10.1389 -                        status = renewUUID(session, state, NULL, NULL);
 10.1390 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1391 -                            return (int) invalid_out_of_memory;
 10.1392 -                        if (status != PEP_STATUS_OK)
 10.1393 -                            return (int) invalid_action;
 10.1394 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "action=notifyAcceptedDeviceMoved")
 10.1395 -                        status = notifyAcceptedDeviceMoved(session, state, partner, NULL);
 10.1396 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1397 -                            return (int) invalid_out_of_memory;
 10.1398 -                        if (status != PEP_STATUS_OK)
 10.1399 -                            return (int) invalid_action;
 10.1400 -                        assert(session->sync_state_payload);
 10.1401 -                        if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1402 -                        free_identity(((WaitForGroupKeysGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1403 -                        free(session->sync_state_payload);
 10.1404 -                        session->sync_state_payload = NULL;
 10.1405 -                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupKeys", "target=Grouped")
 10.1406 -                        return Grouped;
 10.1407 -                        }
 10.1408 -                    }
 10.1409 -                    break;
 10.1410 -                }
 10.1411 -                case GroupUpdate:
 10.1412 -                {
 10.1413 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysGrouped", "event=GroupUpdate")
 10.1414 -                    identity_list* keys = (identity_list*)extra;
 10.1415 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupUpdate", "action=notifyOvertaken")
 10.1416 -                    status = notifyOvertaken(session, state, partner, NULL);
 10.1417 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1418 -                        return (int) invalid_out_of_memory;
 10.1419 -                    if (status != PEP_STATUS_OK)
 10.1420 -                        return (int) invalid_action;
 10.1421 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupUpdate", "action=storeGroupUpdate")
 10.1422 -                    status = storeGroupUpdate(session, state, partner, keys);
 10.1423 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1424 -                        return (int) invalid_out_of_memory;
 10.1425 -                    if (status != PEP_STATUS_OK)
 10.1426 -                        return (int) invalid_action;
 10.1427 -                    assert(session->sync_state_payload);
 10.1428 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1429 -                    free_identity(((WaitForGroupKeysGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1430 -                    free(session->sync_state_payload);
 10.1431 -                    session->sync_state_payload = NULL;
 10.1432 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=GroupUpdate", "target=Grouped")
 10.1433 -                    return Grouped;
 10.1434 -                }
 10.1435 -                case Timeout:
 10.1436 -                {
 10.1437 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysGrouped", "event=Timeout")
 10.1438 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=Timeout", "action=notifyTimeout")
 10.1439 -                    status = notifyTimeout(session, state, expected, NULL);
 10.1440 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1441 -                        return (int) invalid_out_of_memory;
 10.1442 -                    if (status != PEP_STATUS_OK)
 10.1443 -                        return (int) invalid_action;
 10.1444 -                    assert(session->sync_state_payload);
 10.1445 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1446 -                    free_identity(((WaitForGroupKeysGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1447 -                    free(session->sync_state_payload);
 10.1448 -                    session->sync_state_payload = NULL;
 10.1449 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysGrouped, event=Timeout", "target=Grouped")
 10.1450 -                    return Grouped;
 10.1451 -                }
 10.1452 -                default:
 10.1453 -                    return (DeviceState_state) invalid_event;
 10.1454 -            }
 10.1455 -            break;
 10.1456 -        }
 10.1457 -        case WaitForAcceptGrouped:
 10.1458 -        {
 10.1459 -            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=WaitForAcceptGrouped")
 10.1460 -            assert(session->sync_state_payload);
 10.1461 -            if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1462 -            Identity expected = ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected;
 10.1463 -            group_keys_extra_t* groupkeys = ((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->groupkeys;
 10.1464 -            switch (event) {
 10.1465 -                case Init: 
 10.1466 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=Init") 
 10.1467 -                    *timeout = 600;
 10.1468 -                    break;
 10.1469 -                case HandshakeRejected:
 10.1470 -                {
 10.1471 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=HandshakeRejected")
 10.1472 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeRejected", "action=rejectHandshake")
 10.1473 -                    status = rejectHandshake(session, state, partner, NULL);
 10.1474 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1475 -                        return (int) invalid_out_of_memory;
 10.1476 -                    if (status != PEP_STATUS_OK)
 10.1477 -                        return (int) invalid_action;
 10.1478 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeRejected", "action=sendGroupUpdate")
 10.1479 -                    status = sendGroupUpdate(session, state, NULL, NULL);
 10.1480 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1481 -                        return (int) invalid_out_of_memory;
 10.1482 -                    if (status != PEP_STATUS_OK)
 10.1483 -                        return (int) invalid_action;
 10.1484 -                    assert(session->sync_state_payload);
 10.1485 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1486 -                    free_identity(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1487 -                    free_group_keys_extra(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->groupkeys);
 10.1488 -                    free(session->sync_state_payload);
 10.1489 -                    session->sync_state_payload = NULL;
 10.1490 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeRejected", "target=Grouped")
 10.1491 -                    return Grouped;
 10.1492 -                }
 10.1493 -                case HandshakeAccepted:
 10.1494 -                {
 10.1495 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=HandshakeAccepted")
 10.1496 -                    {
 10.1497 -                        int cond_result = sameIdentities(session, partner, expected);
 10.1498 -                        #ifndef NDEBUG
 10.1499 -                        char resstr[11] = {0,};
 10.1500 -                        snprintf(resstr,10,"result=%d",cond_result);
 10.1501 -                        #endif
 10.1502 -                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted, condition=sameIdentities", resstr)
 10.1503 -                        if (cond_result < 0)
 10.1504 -                            return cond_result;
 10.1505 -                        if (cond_result) {
 10.1506 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=acceptHandshake")
 10.1507 -                        status = acceptHandshake(session, state, partner, NULL);
 10.1508 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1509 -                            return (int) invalid_out_of_memory;
 10.1510 -                        if (status != PEP_STATUS_OK)
 10.1511 -                            return (int) invalid_action;
 10.1512 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=storeGroupKeys")
 10.1513 -                        status = storeGroupKeys(session, state, partner, groupkeys);
 10.1514 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1515 -                            return (int) invalid_out_of_memory;
 10.1516 -                        if (status != PEP_STATUS_OK)
 10.1517 -                            return (int) invalid_action;
 10.1518 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=sendGroupUpdate")
 10.1519 -                        status = sendGroupUpdate(session, state, NULL, NULL);
 10.1520 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1521 -                            return (int) invalid_out_of_memory;
 10.1522 -                        if (status != PEP_STATUS_OK)
 10.1523 -                            return (int) invalid_action;
 10.1524 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=renewUUID")
 10.1525 -                        status = renewUUID(session, state, NULL, NULL);
 10.1526 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1527 -                            return (int) invalid_out_of_memory;
 10.1528 -                        if (status != PEP_STATUS_OK)
 10.1529 -                            return (int) invalid_action;
 10.1530 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "action=notifyAcceptedDeviceMoved")
 10.1531 -                        status = notifyAcceptedDeviceMoved(session, state, partner, NULL);
 10.1532 -                        if (status == PEP_OUT_OF_MEMORY)
 10.1533 -                            return (int) invalid_out_of_memory;
 10.1534 -                        if (status != PEP_STATUS_OK)
 10.1535 -                            return (int) invalid_action;
 10.1536 -                        }
 10.1537 -                    }
 10.1538 -                    assert(session->sync_state_payload);
 10.1539 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1540 -                    free_identity(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1541 -                    free_group_keys_extra(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->groupkeys);
 10.1542 -                    free(session->sync_state_payload);
 10.1543 -                    session->sync_state_payload = NULL;
 10.1544 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptGrouped, event=HandshakeAccepted", "target=Grouped")
 10.1545 -                    return Grouped;
 10.1546 -                }
 10.1547 -                case Cancel:
 10.1548 -                {
 10.1549 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=Cancel")
 10.1550 -                    assert(session->sync_state_payload);
 10.1551 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1552 -                    free_identity(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1553 -                    free_group_keys_extra(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->groupkeys);
 10.1554 -                    free(session->sync_state_payload);
 10.1555 -                    session->sync_state_payload = NULL;
 10.1556 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptGrouped, event=Cancel", "target=Grouped")
 10.1557 -                    return Grouped;
 10.1558 -                }
 10.1559 -                case GroupUpdate:
 10.1560 -                {
 10.1561 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=GroupUpdate")
 10.1562 -                    identity_list* keys = (identity_list*)extra;
 10.1563 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=GroupUpdate", "action=notifyOvertaken")
 10.1564 -                    status = notifyOvertaken(session, state, partner, NULL);
 10.1565 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1566 -                        return (int) invalid_out_of_memory;
 10.1567 -                    if (status != PEP_STATUS_OK)
 10.1568 -                        return (int) invalid_action;
 10.1569 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=GroupUpdate", "action=storeGroupUpdate")
 10.1570 -                    status = storeGroupUpdate(session, state, partner, keys);
 10.1571 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1572 -                        return (int) invalid_out_of_memory;
 10.1573 -                    if (status != PEP_STATUS_OK)
 10.1574 -                        return (int) invalid_action;
 10.1575 -                    assert(session->sync_state_payload);
 10.1576 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1577 -                    free_identity(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1578 -                    free_group_keys_extra(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->groupkeys);
 10.1579 -                    free(session->sync_state_payload);
 10.1580 -                    session->sync_state_payload = NULL;
 10.1581 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptGrouped, event=GroupUpdate", "target=Grouped")
 10.1582 -                    return Grouped;
 10.1583 -                }
 10.1584 -                case Timeout:
 10.1585 -                {
 10.1586 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForAcceptGrouped", "event=Timeout")
 10.1587 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForAcceptGrouped, event=Timeout", "action=notifyTimeout")
 10.1588 -                    status = notifyTimeout(session, state, expected, NULL);
 10.1589 -                    if (status == PEP_OUT_OF_MEMORY)
 10.1590 -                        return (int) invalid_out_of_memory;
 10.1591 -                    if (status != PEP_STATUS_OK)
 10.1592 -                        return (int) invalid_action;
 10.1593 -                    assert(session->sync_state_payload);
 10.1594 -                    if(!session->sync_state_payload) return (DeviceState_state) invalid_state;
 10.1595 -                    free_identity(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->expected);
 10.1596 -                    free_group_keys_extra(((WaitForAcceptGrouped_state_payload_t*)session->sync_state_payload)->groupkeys);
 10.1597 -                    free(session->sync_state_payload);
 10.1598 -                    session->sync_state_payload = NULL;
 10.1599 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForAcceptGrouped, event=Timeout", "target=Grouped")
 10.1600 -                    return Grouped;
 10.1601 -                }
 10.1602 -                default:
 10.1603 -                    return (DeviceState_state) invalid_event;
 10.1604 -            }
 10.1605 -            break;
 10.1606 -        }
 10.1607 -        default:
 10.1608 -            return (DeviceState_state) invalid_state;
 10.1609 -    }
 10.1610 -
 10.1611 -    return state;
 10.1612 -}
 10.1613 -
    11.1 --- a/sync/generated/sync_fsm.h	Thu Aug 09 12:15:44 2018 +0200
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,145 +0,0 @@
    11.4 -#pragma once
    11.5 -
    11.6 -// state machine for DeviceState
    11.7 -
    11.8 -#include "message_api.h"
    11.9 -
   11.10 -#ifdef __cplusplus
   11.11 -extern "C" {
   11.12 -#endif
   11.13 -
   11.14 -// types
   11.15 -
   11.16 -typedef pEp_identity * Identity;
   11.17 -typedef stringlist_t * Stringlist;
   11.18 -
   11.19 -// error values
   11.20 -
   11.21 -typedef enum _fsm_error {
   11.22 -    // these error values are corresponding to
   11.23 -    // PEP_SYNC_STATEMACHINE_ERROR - value
   11.24 -    invalid_state = -2,
   11.25 -    invalid_event = -3,
   11.26 -    invalid_condition = -4,
   11.27 -    invalid_action = -5,
   11.28 -
   11.29 -    // out of memory condition
   11.30 -    invalid_out_of_memory = -128
   11.31 -} fsm_error;
   11.32 -
   11.33 -// conditions
   11.34 -
   11.35 -int deviceGrouped(PEP_SESSION session);
   11.36 -int keyElectionWon(PEP_SESSION session, Identity partner);
   11.37 -int sameIdentities(PEP_SESSION session, Identity a, Identity b);
   11.38 -int sameKeyAndAddress(PEP_SESSION session, Identity a, Identity b);
   11.39 -
   11.40 -// states
   11.41 -
   11.42 -typedef enum _DeviceState_state {
   11.43 -    // error values also in this namespace
   11.44 -    DeviceState_state_invalid_state = (int) invalid_state,
   11.45 -    DeviceState_state_invalid_event = (int) invalid_event,
   11.46 -    DeviceState_state_invalid_condition = (int) invalid_condition,
   11.47 -    DeviceState_state_invalid_action = (int) invalid_action,
   11.48 -    DeviceState_state_invalid_out_of_memory = (int) invalid_out_of_memory,
   11.49 -
   11.50 -    DeviceState_state_NONE = 0,
   11.51 -    InitState, 
   11.52 -    Sole, 
   11.53 -    SoleWaiting, 
   11.54 -    SoleBeaconed, 
   11.55 -    HandshakingSole, 
   11.56 -    WaitForGroupKeysSole, 
   11.57 -    WaitForAcceptSole, 
   11.58 -    Grouped, 
   11.59 -    GroupWaiting, 
   11.60 -    GroupedBeaconed, 
   11.61 -    HandshakingGrouped, 
   11.62 -    WaitForGroupKeysGrouped, 
   11.63 -    WaitForAcceptGrouped
   11.64 -} DeviceState_state;
   11.65 -
   11.66 -// events
   11.67 -
   11.68 -typedef enum _DeviceState_event {
   11.69 -    DeviceState_event_NONE = 0,
   11.70 -    Init = 1,
   11.71 -    Beacon = 2,
   11.72 -    HandshakeRequest = 3,
   11.73 -    GroupKeys = 4,
   11.74 -    KeyGen, 
   11.75 -    CannotDecrypt, 
   11.76 -    Timeout, 
   11.77 -    HandshakeRejected, 
   11.78 -    HandshakeAccepted, 
   11.79 -    Cancel, 
   11.80 -    UpdateRequest, 
   11.81 -    GroupUpdate
   11.82 -} DeviceState_event;
   11.83 -
   11.84 -// actions
   11.85 -
   11.86 -PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.87 -PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.88 -PEP_STATUS notifyInitFormGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.89 -PEP_STATUS notifyInitAddOurDevice(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.90 -PEP_STATUS rejectHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.91 -PEP_STATUS acceptHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.92 -PEP_STATUS makeGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.93 -PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.94 -PEP_STATUS renewUUID(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.95 -PEP_STATUS notifyAcceptedGroupCreated(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.96 -PEP_STATUS notifyTimeout(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.97 -PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.98 -PEP_STATUS sendGroupUpdate(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
   11.99 -PEP_STATUS notifyAcceptedDeviceAdded(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
  11.100 -PEP_STATUS sendUpdateRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
  11.101 -PEP_STATUS storeGroupUpdate(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
  11.102 -PEP_STATUS notifyInitAddOtherDevice(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
  11.103 -PEP_STATUS notifyInitMoveOurDevice(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
  11.104 -PEP_STATUS notifyOvertaken(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
  11.105 -PEP_STATUS notifyAcceptedDeviceMoved(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
  11.106 -
  11.107 -// event injector
  11.108 -
  11.109 -PEP_STATUS inject_DeviceState_event(
  11.110 -    PEP_SESSION session, 
  11.111 -    DeviceState_event event,
  11.112 -    Identity partner,
  11.113 -    void *extra);
  11.114 -
  11.115 -// message receiver
  11.116 -
  11.117 -PEP_STATUS receive_DeviceState_msg(
  11.118 -        PEP_SESSION session, 
  11.119 -        message *src, 
  11.120 -        PEP_rating rating, 
  11.121 -        stringlist_t *keylist
  11.122 -    );
  11.123 -
  11.124 -// state machine
  11.125 -
  11.126 -DeviceState_state fsm_DeviceState(
  11.127 -        PEP_SESSION session,
  11.128 -        DeviceState_state state,
  11.129 -        DeviceState_event event,
  11.130 -        Identity partner,
  11.131 -        void *extra,
  11.132 -        time_t *timeout
  11.133 -    );
  11.134 -
  11.135 -// driver
  11.136 -
  11.137 -DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
  11.138 -        PEP_SESSION session,
  11.139 -        DeviceState_event event,
  11.140 -        Identity partner,
  11.141 -        void *extra,
  11.142 -        time_t *timeout
  11.143 -    );
  11.144 -
  11.145 -#ifdef __cplusplus
  11.146 -}
  11.147 -#endif
  11.148 -
    12.1 --- a/sync/generated/sync_send_actions.c	Thu Aug 09 12:15:44 2018 +0200
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,521 +0,0 @@
    12.4 -// Send Actions for DeviceState state machine
    12.5 -
    12.6 -#include <assert.h>
    12.7 -#include "pEp_internal.h"
    12.8 -#include "keymanagement.h"
    12.9 -#include "message.h"
   12.10 -#include "sync_fsm.h"
   12.11 -#include "baseprotocol.h"
   12.12 -#include "map_asn1.h"
   12.13 -#include "../asn.1/DeviceGroup-Protocol.h"
   12.14 -#include "sync_impl.h"
   12.15 -#include "../asn.1/Beacon.h"
   12.16 -#include "../asn.1/HandshakeRequest.h"
   12.17 -#include "../asn.1/GroupKeys.h"
   12.18 -#include "../asn.1/GroupUpdate.h"
   12.19 -#include "../asn.1/UpdateRequest.h"
   12.20 -
   12.21 -
   12.22 -// sendBeacon() - send Beacon message
   12.23 -//
   12.24 -//  params:
   12.25 -//      session (in)        session handle
   12.26 -//      state (in)          state the state machine is in
   12.27 -//      partner (in)        (must be NULL)
   12.28 -//
   12.29 -//  returns:
   12.30 -//      PEP_STATUS_OK or any other value on error
   12.31 -
   12.32 -PEP_STATUS sendBeacon(
   12.33 -        PEP_SESSION session,
   12.34 -        DeviceState_state state,
   12.35 -        Identity partner,
   12.36 -        void *extra
   12.37 -    )
   12.38 -{
   12.39 -    assert(session && state);
   12.40 -    if (!(session && state))
   12.41 -        return PEP_ILLEGAL_VALUE;
   12.42 -
   12.43 -    PEP_STATUS status = PEP_STATUS_OK;
   12.44 -
   12.45 -    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_beacon);
   12.46 -    if (!msg)
   12.47 -        goto enomem;
   12.48 -
   12.49 -    bool encrypted = false;
   12.50 -    status = multicast_self_msg(session, state, msg, encrypted);
   12.51 -    if (status != PEP_STATUS_OK)
   12.52 -        goto error;
   12.53 -
   12.54 -    free_DeviceGroup_Protocol_msg(msg);
   12.55 -    return PEP_STATUS_OK;
   12.56 -
   12.57 -enomem:
   12.58 -    status = PEP_OUT_OF_MEMORY;
   12.59 -error:
   12.60 -    free_DeviceGroup_Protocol_msg(msg);
   12.61 -    return status;
   12.62 -}
   12.63 -
   12.64 -
   12.65 -// sendHandshakeRequest() - send HandshakeRequest message
   12.66 -//
   12.67 -//  params:
   12.68 -//      session (in)        session handle
   12.69 -//      state (in)          state the state machine is in
   12.70 -//      partner (in)        partner to communicate with
   12.71 -//
   12.72 -//  returns:
   12.73 -//      PEP_STATUS_OK or any other value on error
   12.74 -
   12.75 -PEP_STATUS sendHandshakeRequest(
   12.76 -        PEP_SESSION session,
   12.77 -        DeviceState_state state,
   12.78 -        Identity partner,
   12.79 -        void *extra
   12.80 -    )
   12.81 -{
   12.82 -    assert(session && state);
   12.83 -    if (!(session && state))
   12.84 -        return PEP_ILLEGAL_VALUE;
   12.85 -
   12.86 -    PEP_STATUS status = PEP_STATUS_OK;
   12.87 -
   12.88 -    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_handshakeRequest);
   12.89 -    if (!msg)
   12.90 -        goto enomem;
   12.91 -
   12.92 -    msg->payload.choice.handshakeRequest.partner_id = 
   12.93 -        OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
   12.94 -                                 partner->user_id, -1);
   12.95 -    if (partner->user_id && !msg->payload.choice.handshakeRequest.partner_id)
   12.96 -       goto enomem;
   12.97 -
   12.98 -    char *devgrp = NULL;
   12.99 -    status = get_device_group(session, &devgrp);
  12.100 -    if (status == PEP_STATUS_OK && devgrp && devgrp[0])
  12.101 -    msg->payload.choice.handshakeRequest.group_id = 
  12.102 -        OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
  12.103 -                                 devgrp, -1);
  12.104 -    free(devgrp);
  12.105 -    if (devgrp && !msg->payload.choice.handshakeRequest.partner_id)
  12.106 -       goto enomem;
  12.107 -
  12.108 -    bool encrypted = true;
  12.109 -    status = unicast_msg(session, partner, state, msg, encrypted);
  12.110 -    if (status != PEP_STATUS_OK)
  12.111 -        goto error;
  12.112 -
  12.113 -    free_DeviceGroup_Protocol_msg(msg);
  12.114 -    return PEP_STATUS_OK;
  12.115 -
  12.116 -enomem:
  12.117 -    status = PEP_OUT_OF_MEMORY;
  12.118 -error:
  12.119 -    free_DeviceGroup_Protocol_msg(msg);
  12.120 -    return status;
  12.121 -}
  12.122 -
  12.123 -
  12.124 -// sendGroupKeys() - send GroupKeys message
  12.125 -//
  12.126 -//  params:
  12.127 -//      session (in)        session handle
  12.128 -//      state (in)          state the state machine is in
  12.129 -//      partner (in)        partner to communicate with
  12.130 -//
  12.131 -//  returns:
  12.132 -//      PEP_STATUS_OK or any other value on error
  12.133 -
  12.134 -PEP_STATUS sendGroupKeys(
  12.135 -        PEP_SESSION session,
  12.136 -        DeviceState_state state,
  12.137 -        Identity partner,
  12.138 -        void *extra
  12.139 -    )
  12.140 -{
  12.141 -    assert(session && state);
  12.142 -    if (!(session && state))
  12.143 -        return PEP_ILLEGAL_VALUE;
  12.144 -
  12.145 -    PEP_STATUS status = PEP_STATUS_OK;
  12.146 -    identity_list *kl = new_identity_list(NULL);
  12.147 -
  12.148 -    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupKeys);
  12.149 -    if (!msg)
  12.150 -        goto enomem;
  12.151 -
  12.152 -    status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
  12.153 -    if (status != PEP_STATUS_OK)
  12.154 -        goto error;
  12.155 -    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
  12.156 -        goto enomem;
  12.157 -
  12.158 -    msg->payload.choice.groupKeys.partner_id = 
  12.159 -        OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
  12.160 -                                 partner->user_id, -1);
  12.161 -    if (partner->user_id && !msg->payload.choice.groupKeys.partner_id)
  12.162 -       goto enomem;
  12.163 -
  12.164 -    char *devgrp = NULL;
  12.165 -    status = get_device_group(session, &devgrp);
  12.166 -    if (status == PEP_STATUS_OK && devgrp && devgrp[0])
  12.167 -    msg->payload.choice.groupKeys.group_id = 
  12.168 -        OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
  12.169 -                                 devgrp, -1);
  12.170 -    free(devgrp);
  12.171 -    if (devgrp && !msg->payload.choice.groupKeys.partner_id)
  12.172 -       goto enomem;
  12.173 -
  12.174 -    bool encrypted = true;
  12.175 -    status = unicast_msg(session, partner, state, msg, encrypted);
  12.176 -    if (status != PEP_STATUS_OK)
  12.177 -        goto error;
  12.178 -
  12.179 -    free_identity_list(kl);
  12.180 -    free_DeviceGroup_Protocol_msg(msg);
  12.181 -    return PEP_STATUS_OK;
  12.182 -
  12.183 -enomem:
  12.184 -    status = PEP_OUT_OF_MEMORY;
  12.185 -error:
  12.186 -    free_DeviceGroup_Protocol_msg(msg);
  12.187 -    free_identity_list(kl);
  12.188 -    return status;
  12.189 -}
  12.190 -
  12.191 -
  12.192 -// sendGroupUpdate() - send GroupUpdate message
  12.193 -//
  12.194 -//  params:
  12.195 -//      session (in)        session handle
  12.196 -//      state (in)          state the state machine is in
  12.197 -//      partner (in)        (must be NULL)
  12.198 -//
  12.199 -//  returns:
  12.200 -//      PEP_STATUS_OK or any other value on error
  12.201 -
  12.202 -PEP_STATUS sendGroupUpdate(
  12.203 -        PEP_SESSION session,
  12.204 -        DeviceState_state state,
  12.205 -        Identity partner,
  12.206 -        void *extra
  12.207 -    )
  12.208 -{
  12.209 -    assert(session && state);
  12.210 -    if (!(session && state))
  12.211 -        return PEP_ILLEGAL_VALUE;
  12.212 -
  12.213 -    PEP_STATUS status = PEP_STATUS_OK;
  12.214 -    identity_list *kl = new_identity_list(NULL);
  12.215 -
  12.216 -    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_groupUpdate);
  12.217 -    if (!msg)
  12.218 -        goto enomem;
  12.219 -
  12.220 -    status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
  12.221 -    if (status != PEP_STATUS_OK)
  12.222 -        goto error;
  12.223 -    if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupUpdate.ownIdentities) == NULL)
  12.224 -        goto enomem;
  12.225 -
  12.226 -    bool encrypted = true;
  12.227 -    status = multicast_self_msg(session, state, msg, encrypted);
  12.228 -    if (status != PEP_STATUS_OK)
  12.229 -        goto error;
  12.230 -
  12.231 -    free_identity_list(kl);
  12.232 -    free_DeviceGroup_Protocol_msg(msg);
  12.233 -    return PEP_STATUS_OK;
  12.234 -
  12.235 -enomem:
  12.236 -    status = PEP_OUT_OF_MEMORY;
  12.237 -error:
  12.238 -    free_DeviceGroup_Protocol_msg(msg);
  12.239 -    return status;
  12.240 -}
  12.241 -
  12.242 -
  12.243 -// sendUpdateRequest() - send UpdateRequest message
  12.244 -//
  12.245 -//  params:
  12.246 -//      session (in)        session handle
  12.247 -//      state (in)          state the state machine is in
  12.248 -//      partner (in)        (must be NULL)
  12.249 -//
  12.250 -//  returns:
  12.251 -//      PEP_STATUS_OK or any other value on error
  12.252 -
  12.253 -PEP_STATUS sendUpdateRequest(
  12.254 -        PEP_SESSION session,
  12.255 -        DeviceState_state state,
  12.256 -        Identity partner,
  12.257 -        void *extra
  12.258 -    )
  12.259 -{
  12.260 -    assert(session && state);
  12.261 -    if (!(session && state))
  12.262 -        return PEP_ILLEGAL_VALUE;
  12.263 -
  12.264 -    PEP_STATUS status = PEP_STATUS_OK;
  12.265 -
  12.266 -    DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_updateRequest);
  12.267 -    if (!msg)
  12.268 -        goto enomem;
  12.269 -
  12.270 -    bool encrypted = true;
  12.271 -    status = multicast_self_msg(session, state, msg, encrypted);
  12.272 -    if (status != PEP_STATUS_OK)
  12.273 -        goto error;
  12.274 -
  12.275 -    free_DeviceGroup_Protocol_msg(msg);
  12.276 -    return PEP_STATUS_OK;
  12.277 -
  12.278 -enomem:
  12.279 -    status = PEP_OUT_OF_MEMORY;
  12.280 -error:
  12.281 -    free_DeviceGroup_Protocol_msg(msg);
  12.282 -    return status;
  12.283 -}
  12.284 -
  12.285 -
  12.286 -PEP_STATUS _notifyHandshake(
  12.287 -        PEP_SESSION session,
  12.288 -        Identity partner,
  12.289 -        sync_handshake_signal signal
  12.290 -    );
  12.291 -
  12.292 -// notifyInitFormGroup() - notify InitFormGroup to app
  12.293 -//
  12.294 -//  params:
  12.295 -//      session (in)        session handle
  12.296 -//      state (in)          state the state machine is in
  12.297 -//      partner (in)        partner to communicate with
  12.298 -//
  12.299 -//  returns:
  12.300 -//      PEP_STATUS_OK or any other value on error
  12.301 -
  12.302 -PEP_STATUS notifyInitFormGroup(
  12.303 -        PEP_SESSION session,
  12.304 -        DeviceState_state state,
  12.305 -        Identity partner,
  12.306 -        void *extra
  12.307 -    )
  12.308 -{
  12.309 -    assert(session && state);
  12.310 -    assert(extra == NULL);
  12.311 -    if (!(session && state && extra == NULL))
  12.312 -        return PEP_ILLEGAL_VALUE;
  12.313 -
  12.314 -    return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_FORM_GROUP);
  12.315 -}
  12.316 -
  12.317 -
  12.318 -// notifyInitAddOurDevice() - notify InitAddOurDevice to app
  12.319 -//
  12.320 -//  params:
  12.321 -//      session (in)        session handle
  12.322 -//      state (in)          state the state machine is in
  12.323 -//      partner (in)        partner to communicate with
  12.324 -//
  12.325 -//  returns:
  12.326 -//      PEP_STATUS_OK or any other value on error
  12.327 -
  12.328 -PEP_STATUS notifyInitAddOurDevice(
  12.329 -        PEP_SESSION session,
  12.330 -        DeviceState_state state,
  12.331 -        Identity partner,
  12.332 -        void *extra
  12.333 -    )
  12.334 -{
  12.335 -    assert(session && state);
  12.336 -    assert(extra == NULL);
  12.337 -    if (!(session && state && extra == NULL))
  12.338 -        return PEP_ILLEGAL_VALUE;
  12.339 -
  12.340 -    return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_ADD_OUR_DEVICE);
  12.341 -}
  12.342 -
  12.343 -
  12.344 -// notifyAcceptedGroupCreated() - notify AcceptedGroupCreated to app
  12.345 -//
  12.346 -//  params:
  12.347 -//      session (in)        session handle
  12.348 -//      state (in)          state the state machine is in
  12.349 -//      partner (in)        partner to communicate with
  12.350 -//
  12.351 -//  returns:
  12.352 -//      PEP_STATUS_OK or any other value on error
  12.353 -
  12.354 -PEP_STATUS notifyAcceptedGroupCreated(
  12.355 -        PEP_SESSION session,
  12.356 -        DeviceState_state state,
  12.357 -        Identity partner,
  12.358 -        void *extra
  12.359 -    )
  12.360 -{
  12.361 -    assert(session && state);
  12.362 -    assert(extra == NULL);
  12.363 -    if (!(session && state && extra == NULL))
  12.364 -        return PEP_ILLEGAL_VALUE;
  12.365 -
  12.366 -    return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_GROUP_CREATED);
  12.367 -}
  12.368 -
  12.369 -
  12.370 -// notifyTimeout() - notify Timeout to app
  12.371 -//
  12.372 -//  params:
  12.373 -//      session (in)        session handle
  12.374 -//      state (in)          state the state machine is in
  12.375 -//      partner (in)        partner to communicate with
  12.376 -//
  12.377 -//  returns:
  12.378 -//      PEP_STATUS_OK or any other value on error
  12.379 -
  12.380 -PEP_STATUS notifyTimeout(
  12.381 -        PEP_SESSION session,
  12.382 -        DeviceState_state state,
  12.383 -        Identity partner,
  12.384 -        void *extra
  12.385 -    )
  12.386 -{
  12.387 -    assert(session && state);
  12.388 -    assert(extra == NULL);
  12.389 -    if (!(session && state && extra == NULL))
  12.390 -        return PEP_ILLEGAL_VALUE;
  12.391 -
  12.392 -    return _notifyHandshake(session, partner, SYNC_NOTIFY_TIMEOUT);
  12.393 -}
  12.394 -
  12.395 -
  12.396 -// notifyAcceptedDeviceAdded() - notify AcceptedDeviceAdded to app
  12.397 -//
  12.398 -//  params:
  12.399 -//      session (in)        session handle
  12.400 -//      state (in)          state the state machine is in
  12.401 -//      partner (in)        partner to communicate with
  12.402 -//
  12.403 -//  returns:
  12.404 -//      PEP_STATUS_OK or any other value on error
  12.405 -
  12.406 -PEP_STATUS notifyAcceptedDeviceAdded(
  12.407 -        PEP_SESSION session,
  12.408 -        DeviceState_state state,
  12.409 -        Identity partner,
  12.410 -        void *extra
  12.411 -    )
  12.412 -{
  12.413 -    assert(session && state);
  12.414 -    assert(extra == NULL);
  12.415 -    if (!(session && state && extra == NULL))
  12.416 -        return PEP_ILLEGAL_VALUE;
  12.417 -
  12.418 -    return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED);
  12.419 -}
  12.420 -
  12.421 -
  12.422 -// notifyInitAddOtherDevice() - notify InitAddOtherDevice to app
  12.423 -//
  12.424 -//  params:
  12.425 -//      session (in)        session handle
  12.426 -//      state (in)          state the state machine is in
  12.427 -//      partner (in)        partner to communicate with
  12.428 -//
  12.429 -//  returns:
  12.430 -//      PEP_STATUS_OK or any other value on error
  12.431 -
  12.432 -PEP_STATUS notifyInitAddOtherDevice(
  12.433 -        PEP_SESSION session,
  12.434 -        DeviceState_state state,
  12.435 -        Identity partner,
  12.436 -        void *extra
  12.437 -    )
  12.438 -{
  12.439 -    assert(session && state);
  12.440 -    assert(extra == NULL);
  12.441 -    if (!(session && state && extra == NULL))
  12.442 -        return PEP_ILLEGAL_VALUE;
  12.443 -
  12.444 -    return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE);
  12.445 -}
  12.446 -
  12.447 -
  12.448 -// notifyInitMoveOurDevice() - notify InitMoveOurDevice to app
  12.449 -//
  12.450 -//  params:
  12.451 -//      session (in)        session handle
  12.452 -//      state (in)          state the state machine is in
  12.453 -//      partner (in)        partner to communicate with
  12.454 -//
  12.455 -//  returns:
  12.456 -//      PEP_STATUS_OK or any other value on error
  12.457 -
  12.458 -PEP_STATUS notifyInitMoveOurDevice(
  12.459 -        PEP_SESSION session,
  12.460 -        DeviceState_state state,
  12.461 -        Identity partner,
  12.462 -        void *extra
  12.463 -    )
  12.464 -{
  12.465 -    assert(session && state);
  12.466 -    assert(extra == NULL);
  12.467 -    if (!(session && state && extra == NULL))
  12.468 -        return PEP_ILLEGAL_VALUE;
  12.469 -
  12.470 -    return _notifyHandshake(session, partner, SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE);
  12.471 -}
  12.472 -
  12.473 -
  12.474 -// notifyOvertaken() - notify Overtaken to app
  12.475 -//
  12.476 -//  params:
  12.477 -//      session (in)        session handle
  12.478 -//      state (in)          state the state machine is in
  12.479 -//      partner (in)        partner to communicate with
  12.480 -//
  12.481 -//  returns:
  12.482 -//      PEP_STATUS_OK or any other value on error
  12.483 -
  12.484 -PEP_STATUS notifyOvertaken(
  12.485 -        PEP_SESSION session,
  12.486 -        DeviceState_state state,
  12.487 -        Identity partner,
  12.488 -        void *extra
  12.489 -    )
  12.490 -{
  12.491 -    assert(session && state);
  12.492 -    assert(extra == NULL);
  12.493 -    if (!(session && state && extra == NULL))
  12.494 -        return PEP_ILLEGAL_VALUE;
  12.495 -
  12.496 -    return _notifyHandshake(session, partner, SYNC_NOTIFY_OVERTAKEN);
  12.497 -}
  12.498 -
  12.499 -
  12.500 -// notifyAcceptedDeviceMoved() - notify AcceptedDeviceMoved to app
  12.501 -//
  12.502 -//  params:
  12.503 -//      session (in)        session handle
  12.504 -//      state (in)          state the state machine is in
  12.505 -//      partner (in)        partner to communicate with
  12.506 -//
  12.507 -//  returns:
  12.508 -//      PEP_STATUS_OK or any other value on error
  12.509 -
  12.510 -PEP_STATUS notifyAcceptedDeviceMoved(
  12.511 -        PEP_SESSION session,
  12.512 -        DeviceState_state state,
  12.513 -        Identity partner,
  12.514 -        void *extra
  12.515 -    )
  12.516 -{
  12.517 -    assert(session && state);
  12.518 -    assert(extra == NULL);
  12.519 -    if (!(session && state && extra == NULL))
  12.520 -        return PEP_ILLEGAL_VALUE;
  12.521 -
  12.522 -    return _notifyHandshake(session, partner, SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED);
  12.523 -}
  12.524 -
    13.1 --- a/sync/skeletons/sync_actions.c	Thu Aug 09 12:15:44 2018 +0200
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,564 +0,0 @@
    13.4 -// Actions for DeviceState state machine
    13.5 -
    13.6 -#include <assert.h>
    13.7 -#include "pEp_internal.h"
    13.8 -#include "keymanagement.h"
    13.9 -#include "message.h"
   13.10 -#include "sync_fsm.h"
   13.11 -#include "../asn.1/DeviceGroup-Protocol.h"
   13.12 -
   13.13 -
   13.14 -// notifyInitFormGroup() - 
   13.15 -//
   13.16 -//  params:
   13.17 -//      session (in)        session handle
   13.18 -//      state (in)          state the state machine is in
   13.19 -//      partner (in)        partner to communicate with
   13.20 -//
   13.21 -//  returns:
   13.22 -//      PEP_STATUS_OK or any other value on error
   13.23 -
   13.24 -PEP_STATUS notifyInitFormGroup(
   13.25 -        PEP_SESSION session,
   13.26 -        DeviceState_state state,
   13.27 -        Identity partner,
   13.28 -        void *extra
   13.29 -    )
   13.30 -{
   13.31 -    PEP_STATUS status = PEP_STATUS_OK;
   13.32 -
   13.33 -    assert(session);
   13.34 -    assert(!partner);
   13.35 -    if (!(session && !partner))
   13.36 -        return PEP_ILLEGAL_VALUE;
   13.37 -
   13.38 -    // working code
   13.39 -
   13.40 -    // free extra
   13.41 -    return status;
   13.42 -
   13.43 -enomem:
   13.44 -    status = PEP_OUT_OF_MEMORY;
   13.45 -error:
   13.46 -    // free extra
   13.47 -    return status;
   13.48 -}
   13.49 -
   13.50 -
   13.51 -// notifyInitAddOurDevice() - 
   13.52 -//
   13.53 -//  params:
   13.54 -//      session (in)        session handle
   13.55 -//      state (in)          state the state machine is in
   13.56 -//      partner (in)        partner to communicate with
   13.57 -//
   13.58 -//  returns:
   13.59 -//      PEP_STATUS_OK or any other value on error
   13.60 -
   13.61 -PEP_STATUS notifyInitAddOurDevice(
   13.62 -        PEP_SESSION session,
   13.63 -        DeviceState_state state,
   13.64 -        Identity partner,
   13.65 -        void *extra
   13.66 -    )
   13.67 -{
   13.68 -    PEP_STATUS status = PEP_STATUS_OK;
   13.69 -
   13.70 -    assert(session);
   13.71 -    assert(!partner);
   13.72 -    if (!(session && !partner))
   13.73 -        return PEP_ILLEGAL_VALUE;
   13.74 -
   13.75 -    // working code
   13.76 -
   13.77 -    // free extra
   13.78 -    return status;
   13.79 -
   13.80 -enomem:
   13.81 -    status = PEP_OUT_OF_MEMORY;
   13.82 -error:
   13.83 -    // free extra
   13.84 -    return status;
   13.85 -}
   13.86 -
   13.87 -
   13.88 -// rejectHandshake() - 
   13.89 -//
   13.90 -//  params:
   13.91 -//      session (in)        session handle
   13.92 -//      state (in)          state the state machine is in
   13.93 -//      partner (in)        partner to communicate with
   13.94 -//
   13.95 -//  returns:
   13.96 -//      PEP_STATUS_OK or any other value on error
   13.97 -
   13.98 -PEP_STATUS rejectHandshake(
   13.99 -        PEP_SESSION session,
  13.100 -        DeviceState_state state,
  13.101 -        Identity partner,
  13.102 -        void *extra
  13.103 -    )
  13.104 -{
  13.105 -    PEP_STATUS status = PEP_STATUS_OK;
  13.106 -
  13.107 -    assert(session);
  13.108 -    assert(partner);
  13.109 -    if (!(session && partner))
  13.110 -        return PEP_ILLEGAL_VALUE;
  13.111 -
  13.112 -    // working code
  13.113 -
  13.114 -    // free extra
  13.115 -    return status;
  13.116 -
  13.117 -enomem:
  13.118 -    status = PEP_OUT_OF_MEMORY;
  13.119 -error:
  13.120 -    // free extra
  13.121 -    return status;
  13.122 -}
  13.123 -
  13.124 -
  13.125 -// acceptHandshake() - 
  13.126 -//
  13.127 -//  params:
  13.128 -//      session (in)        session handle
  13.129 -//      state (in)          state the state machine is in
  13.130 -//      partner (in)        partner to communicate with
  13.131 -//
  13.132 -//  returns:
  13.133 -//      PEP_STATUS_OK or any other value on error
  13.134 -
  13.135 -PEP_STATUS acceptHandshake(
  13.136 -        PEP_SESSION session,
  13.137 -        DeviceState_state state,
  13.138 -        Identity partner,
  13.139 -        void *extra
  13.140 -    )
  13.141 -{
  13.142 -    PEP_STATUS status = PEP_STATUS_OK;
  13.143 -
  13.144 -    assert(session);
  13.145 -    assert(partner);
  13.146 -    if (!(session && partner))
  13.147 -        return PEP_ILLEGAL_VALUE;
  13.148 -
  13.149 -    // working code
  13.150 -
  13.151 -    // free extra
  13.152 -    return status;
  13.153 -
  13.154 -enomem:
  13.155 -    status = PEP_OUT_OF_MEMORY;
  13.156 -error:
  13.157 -    // free extra
  13.158 -    return status;
  13.159 -}
  13.160 -
  13.161 -
  13.162 -// makeGroup() - 
  13.163 -//
  13.164 -//  params:
  13.165 -//      session (in)        session handle
  13.166 -//      state (in)          state the state machine is in
  13.167 -//      partner (in)        (must be NULL)
  13.168 -//
  13.169 -//  returns:
  13.170 -//      PEP_STATUS_OK or any other value on error
  13.171 -
  13.172 -PEP_STATUS makeGroup(
  13.173 -        PEP_SESSION session,
  13.174 -        DeviceState_state state,
  13.175 -        Identity partner,
  13.176 -        void *extra
  13.177 -    )
  13.178 -{
  13.179 -    PEP_STATUS status = PEP_STATUS_OK;
  13.180 -
  13.181 -    assert(session);
  13.182 -    assert(!partner);
  13.183 -    if (!(session && !partner))
  13.184 -        return PEP_ILLEGAL_VALUE;
  13.185 -
  13.186 -    // working code
  13.187 -
  13.188 -    // free extra
  13.189 -    return status;
  13.190 -
  13.191 -enomem:
  13.192 -    status = PEP_OUT_OF_MEMORY;
  13.193 -error:
  13.194 -    // free extra
  13.195 -    return status;
  13.196 -}
  13.197 -
  13.198 -
  13.199 -// renewUUID() - 
  13.200 -//
  13.201 -//  params:
  13.202 -//      session (in)        session handle
  13.203 -//      state (in)          state the state machine is in
  13.204 -//      partner (in)        (must be NULL)
  13.205 -//
  13.206 -//  returns:
  13.207 -//      PEP_STATUS_OK or any other value on error
  13.208 -
  13.209 -PEP_STATUS renewUUID(
  13.210 -        PEP_SESSION session,
  13.211 -        DeviceState_state state,
  13.212 -        Identity partner,
  13.213 -        void *extra
  13.214 -    )
  13.215 -{
  13.216 -    PEP_STATUS status = PEP_STATUS_OK;
  13.217 -
  13.218 -    assert(session);
  13.219 -    assert(!partner);
  13.220 -    if (!(session && !partner))
  13.221 -        return PEP_ILLEGAL_VALUE;
  13.222 -
  13.223 -    // working code
  13.224 -
  13.225 -    // free extra
  13.226 -    return status;
  13.227 -
  13.228 -enomem:
  13.229 -    status = PEP_OUT_OF_MEMORY;
  13.230 -error:
  13.231 -    // free extra
  13.232 -    return status;
  13.233 -}
  13.234 -
  13.235 -
  13.236 -// notifyAcceptedGroupCreated() - 
  13.237 -//
  13.238 -//  params:
  13.239 -//      session (in)        session handle
  13.240 -//      state (in)          state the state machine is in
  13.241 -//      partner (in)        partner to communicate with
  13.242 -//
  13.243 -//  returns:
  13.244 -//      PEP_STATUS_OK or any other value on error
  13.245 -
  13.246 -PEP_STATUS notifyAcceptedGroupCreated(
  13.247 -        PEP_SESSION session,
  13.248 -        DeviceState_state state,
  13.249 -        Identity partner,
  13.250 -        void *extra
  13.251 -    )
  13.252 -{
  13.253 -    PEP_STATUS status = PEP_STATUS_OK;
  13.254 -
  13.255 -    assert(session);
  13.256 -    assert(partner);
  13.257 -    if (!(session && partner))
  13.258 -        return PEP_ILLEGAL_VALUE;
  13.259 -
  13.260 -    // working code
  13.261 -
  13.262 -    // free extra
  13.263 -    return status;
  13.264 -
  13.265 -enomem:
  13.266 -    status = PEP_OUT_OF_MEMORY;
  13.267 -error:
  13.268 -    // free extra
  13.269 -    return status;
  13.270 -}
  13.271 -
  13.272 -
  13.273 -// notifyTimeout() - 
  13.274 -//
  13.275 -//  params:
  13.276 -//      session (in)        session handle
  13.277 -//      state (in)          state the state machine is in
  13.278 -//      partner (in)        partner to communicate with
  13.279 -//
  13.280 -//  returns:
  13.281 -//      PEP_STATUS_OK or any other value on error
  13.282 -
  13.283 -PEP_STATUS notifyTimeout(
  13.284 -        PEP_SESSION session,
  13.285 -        DeviceState_state state,
  13.286 -        Identity partner,
  13.287 -        void *extra
  13.288 -    )
  13.289 -{
  13.290 -    PEP_STATUS status = PEP_STATUS_OK;
  13.291 -
  13.292 -    assert(session);
  13.293 -    assert(!partner);
  13.294 -    if (!(session && !partner))
  13.295 -        return PEP_ILLEGAL_VALUE;
  13.296 -
  13.297 -    // working code
  13.298 -
  13.299 -    // free extra
  13.300 -    return status;
  13.301 -
  13.302 -enomem:
  13.303 -    status = PEP_OUT_OF_MEMORY;
  13.304 -error:
  13.305 -    // free extra
  13.306 -    return status;
  13.307 -}
  13.308 -
  13.309 -
  13.310 -// storeGroupKeys() - 
  13.311 -//
  13.312 -//  params:
  13.313 -//      session (in)        session handle
  13.314 -//      state (in)          state the state machine is in
  13.315 -//      partner (in)        partner to communicate with
  13.316 -//
  13.317 -//  returns:
  13.318 -//      PEP_STATUS_OK or any other value on error
  13.319 -
  13.320 -PEP_STATUS storeGroupKeys(
  13.321 -        PEP_SESSION session,
  13.322 -        DeviceState_state state,
  13.323 -        Identity partner,
  13.324 -        void *extra
  13.325 -    )
  13.326 -{
  13.327 -    PEP_STATUS status = PEP_STATUS_OK;
  13.328 -
  13.329 -    assert(session);
  13.330 -    assert(partner);
  13.331 -    if (!(session && partner))
  13.332 -        return PEP_ILLEGAL_VALUE;
  13.333 -
  13.334 -    // working code
  13.335 -
  13.336 -    // free extra
  13.337 -    return status;
  13.338 -
  13.339 -enomem:
  13.340 -    status = PEP_OUT_OF_MEMORY;
  13.341 -error:
  13.342 -    // free extra
  13.343 -    return status;
  13.344 -}
  13.345 -
  13.346 -
  13.347 -// notifyAcceptedDeviceAdded() - 
  13.348 -//
  13.349 -//  params:
  13.350 -//      session (in)        session handle
  13.351 -//      state (in)          state the state machine is in
  13.352 -//      partner (in)        partner to communicate with
  13.353 -//
  13.354 -//  returns:
  13.355 -//      PEP_STATUS_OK or any other value on error
  13.356 -
  13.357 -PEP_STATUS notifyAcceptedDeviceAdded(
  13.358 -        PEP_SESSION session,
  13.359 -        DeviceState_state state,
  13.360 -        Identity partner,
  13.361 -        void *extra
  13.362 -    )
  13.363 -{
  13.364 -    PEP_STATUS status = PEP_STATUS_OK;
  13.365 -
  13.366 -    assert(session);
  13.367 -    assert(partner);
  13.368 -    if (!(session && partner))
  13.369 -        return PEP_ILLEGAL_VALUE;
  13.370 -
  13.371 -    // working code
  13.372 -
  13.373 -    // free extra
  13.374 -    return status;
  13.375 -
  13.376 -enomem:
  13.377 -    status = PEP_OUT_OF_MEMORY;
  13.378 -error:
  13.379 -    // free extra
  13.380 -    return status;
  13.381 -}
  13.382 -
  13.383 -
  13.384 -// storeGroupUpdate() - 
  13.385 -//
  13.386 -//  params:
  13.387 -//      session (in)        session handle
  13.388 -//      state (in)          state the state machine is in
  13.389 -//      partner (in)        partner to communicate with
  13.390 -//
  13.391 -//  returns:
  13.392 -//      PEP_STATUS_OK or any other value on error
  13.393 -
  13.394 -PEP_STATUS storeGroupUpdate(
  13.395 -        PEP_SESSION session,
  13.396 -        DeviceState_state state,
  13.397 -        Identity partner,
  13.398 -        void *extra
  13.399 -    )
  13.400 -{
  13.401 -    PEP_STATUS status = PEP_STATUS_OK;
  13.402 -
  13.403 -    assert(session);
  13.404 -    assert(partner);
  13.405 -    if (!(session && partner))
  13.406 -        return PEP_ILLEGAL_VALUE;
  13.407 -
  13.408 -    // working code
  13.409 -
  13.410 -    // free extra
  13.411 -    return status;
  13.412 -
  13.413 -enomem:
  13.414 -    status = PEP_OUT_OF_MEMORY;
  13.415 -error:
  13.416 -    // free extra
  13.417 -    return status;
  13.418 -}
  13.419 -
  13.420 -
  13.421 -// notifyInitAddOtherDevice() - 
  13.422 -//
  13.423 -//  params:
  13.424 -//      session (in)        session handle
  13.425 -//      state (in)          state the state machine is in
  13.426 -//      partner (in)        partner to communicate with
  13.427 -//
  13.428 -//  returns:
  13.429 -//      PEP_STATUS_OK or any other value on error
  13.430 -
  13.431 -PEP_STATUS notifyInitAddOtherDevice(
  13.432 -        PEP_SESSION session,
  13.433 -        DeviceState_state state,
  13.434 -        Identity partner,
  13.435 -        void *extra
  13.436 -    )
  13.437 -{
  13.438 -    PEP_STATUS status = PEP_STATUS_OK;
  13.439 -
  13.440 -    assert(session);
  13.441 -    assert(partner);
  13.442 -    if (!(session && partner))
  13.443 -        return PEP_ILLEGAL_VALUE;
  13.444 -
  13.445 -    // working code
  13.446 -
  13.447 -    // free extra
  13.448 -    return status;
  13.449 -
  13.450 -enomem:
  13.451 -    status = PEP_OUT_OF_MEMORY;
  13.452 -error:
  13.453 -    // free extra
  13.454 -    return status;
  13.455 -}
  13.456 -
  13.457 -
  13.458 -// notifyInitMoveOurDevice() - 
  13.459 -//
  13.460 -//  params:
  13.461 -//      session (in)        session handle
  13.462 -//      state (in)          state the state machine is in
  13.463 -//      partner (in)        partner to communicate with
  13.464 -//
  13.465 -//  returns:
  13.466 -//      PEP_STATUS_OK or any other value on error
  13.467 -
  13.468 -PEP_STATUS notifyInitMoveOurDevice(
  13.469 -        PEP_SESSION session,
  13.470 -        DeviceState_state state,
  13.471 -        Identity partner,
  13.472 -        void *extra
  13.473 -    )
  13.474 -{
  13.475 -    PEP_STATUS status = PEP_STATUS_OK;
  13.476 -
  13.477 -    assert(session);
  13.478 -    assert(partner);
  13.479 -    if (!(session && partner))
  13.480 -        return PEP_ILLEGAL_VALUE;
  13.481 -
  13.482 -    // working code
  13.483 -
  13.484 -    // free extra
  13.485 -    return status;
  13.486 -
  13.487 -enomem:
  13.488 -    status = PEP_OUT_OF_MEMORY;
  13.489 -error:
  13.490 -    // free extra
  13.491 -    return status;
  13.492 -}
  13.493 -
  13.494 -
  13.495 -// notifyOvertaken() - 
  13.496 -//
  13.497 -//  params:
  13.498 -//      session (in)        session handle
  13.499 -//      state (in)          state the state machine is in
  13.500 -//      partner (in)        partner to communicate with
  13.501 -//
  13.502 -//  returns:
  13.503 -//      PEP_STATUS_OK or any other value on error
  13.504 -
  13.505 -PEP_STATUS notifyOvertaken(
  13.506 -        PEP_SESSION session,
  13.507 -        DeviceState_state state,
  13.508 -        Identity partner,
  13.509 -        void *extra
  13.510 -    )
  13.511 -{
  13.512 -    PEP_STATUS status = PEP_STATUS_OK;
  13.513 -
  13.514 -    assert(session);
  13.515 -    assert(partner);
  13.516 -    if (!(session && partner))
  13.517 -        return PEP_ILLEGAL_VALUE;
  13.518 -
  13.519 -    // working code
  13.520 -
  13.521 -    // free extra
  13.522 -    return status;
  13.523 -
  13.524 -enomem:
  13.525 -    status = PEP_OUT_OF_MEMORY;
  13.526 -error:
  13.527 -    // free extra
  13.528 -    return status;
  13.529 -}
  13.530 -
  13.531 -
  13.532 -// notifyAcceptedDeviceMoved() - 
  13.533 -//
  13.534 -//  params:
  13.535 -//      session (in)        session handle
  13.536 -//      state (in)          state the state machine is in
  13.537 -//      partner (in)        partner to communicate with
  13.538 -//
  13.539 -//  returns:
  13.540 -//      PEP_STATUS_OK or any other value on error
  13.541 -
  13.542 -PEP_STATUS notifyAcceptedDeviceMoved(
  13.543 -        PEP_SESSION session,
  13.544 -        DeviceState_state state,
  13.545 -        Identity partner,
  13.546 -        void *extra
  13.547 -    )
  13.548 -{
  13.549 -    PEP_STATUS status = PEP_STATUS_OK;
  13.550 -
  13.551 -    assert(session);
  13.552 -    assert(partner);
  13.553 -    if (!(session && partner))
  13.554 -        return PEP_ILLEGAL_VALUE;
  13.555 -
  13.556 -    // working code
  13.557 -
  13.558 -    // free extra
  13.559 -    return status;
  13.560 -
  13.561 -enomem:
  13.562 -    status = PEP_OUT_OF_MEMORY;
  13.563 -error:
  13.564 -    // free extra
  13.565 -    return status;
  13.566 -}
  13.567 -
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/sync/sync.fsm	Thu Aug 09 12:26:53 2018 +0200
    14.3 @@ -0,0 +1,349 @@
    14.4 +// This file is under BSD License 2.0
    14.5 +
    14.6 +// Sync protocol for p≡p
    14.7 +// Copyright (c) 2016, 2017 p≡p foundation
    14.8 +
    14.9 +// Written by Volker Birk
   14.10 +
   14.11 +include ./fsm.yml2
   14.12 +
   14.13 +protocol Sync 1 {
   14.14 +    // all messages have a timestamp, time out and are removed after timeout
   14.15 +
   14.16 +    unencrypted sendBeacon;
   14.17 +    acceptUnencrypted Beacon;
   14.18 +
   14.19 +    acceptUntrusted HandshakeRequest;
   14.20 +    acceptUntrusted Rollback;
   14.21 +    acceptUntrusted CommitReject;
   14.22 +
   14.23 +    fsm KeySync 1 {
   14.24 +        version 1, 2;
   14.25 +        state InitState {
   14.26 +            on Init {
   14.27 +                if deviceGrouped
   14.28 +                    go Grouped;
   14.29 +                do sendBeacon;
   14.30 +                go Sole;
   14.31 +            }
   14.32 +        }
   14.33 +
   14.34 +        state Sole {
   14.35 +            on Init {
   14.36 +                do closeHandshakeDialog;
   14.37 +                do openChallenge; // own challenge
   14.38 +            }
   14.39 +
   14.40 +            on KeyGen
   14.41 +                do sendBeacon;
   14.42 +
   14.43 +            on CannotDecrypt // cry baby
   14.44 +                do sendBeacon;
   14.45 +
   14.46 +            on Beacon {
   14.47 +                do storeChallenge; // partner's challenge
   14.48 +                do openTransaction;
   14.49 +                do storeTransaction;
   14.50 +                do sendHandshakeRequest;
   14.51 +            }
   14.52 +
   14.53 +            on HandshakeRequest {
   14.54 +                if challengeAccepted {
   14.55 +                    do storeTransaction;
   14.56 +                    do sendHandshakeAnswer;
   14.57 +                    if partnerIsGrouped
   14.58 +                        go HandshakingWithGroup;
   14.59 +
   14.60 +                    go HandshakingNew();
   14.61 +                }
   14.62 +            }
   14.63 +
   14.64 +            on HandshakeAnswer
   14.65 +                go HandshakingNew();
   14.66 +        }
   14.67 +
   14.68 +        // handshaking without existing Device group
   14.69 +        state HandshakingNew {
   14.70 +            on Init
   14.71 +                do showSoleHandshake;
   14.72 +
   14.73 +            // Cancel is Rollback
   14.74 +            on Cancel {
   14.75 +                do sendRollback;
   14.76 +                go Sole;
   14.77 +            }
   14.78 +
   14.79 +            on Rollback
   14.80 +                go Sole;
   14.81 +
   14.82 +            // Reject is CommitReject
   14.83 +            on Reject {
   14.84 +                do sendCommitReject;
   14.85 +                do disable;
   14.86 +                go End;
   14.87 +            }
   14.88 +
   14.89 +            on CommitReject {
   14.90 +                do disable;
   14.91 +                go End;
   14.92 +            }
   14.93 +
   14.94 +            // Accept is Phase1Commit
   14.95 +            on Accept {
   14.96 +                do sendCommitAccept;
   14.97 +                go HandshakingNewPhase1;
   14.98 +            }
   14.99 +
  14.100 +            on CommitAccept
  14.101 +                go HandshakingNewPhase1Own;
  14.102 +        }
  14.103 +
  14.104 +        state HandshakingNewPhase1 {
  14.105 +            on Rollback
  14.106 +                go Sole;
  14.107 +            
  14.108 +            on CommitReject {
  14.109 +                do disable;
  14.110 +                go End;
  14.111 +            }
  14.112 +
  14.113 +            on CommitAccept
  14.114 +                go NewGroup;
  14.115 +        }
  14.116 +
  14.117 +        state HandshakingNewPhase1Own {
  14.118 +            on Cancel {
  14.119 +                do sendRollback;
  14.120 +                go Sole;
  14.121 +            }
  14.122 +
  14.123 +            on Reject {
  14.124 +                do sendCommitReject;
  14.125 +                do disable;
  14.126 +                go End;
  14.127 +            }
  14.128 +
  14.129 +            on Accept
  14.130 +                go NewGroup;
  14.131 +        }
  14.132 +
  14.133 +        state NewGroup {
  14.134 +            on Init
  14.135 +                do sendGroupKeysAndClose; // we're not grouped yet, this is our own keys
  14.136 +
  14.137 +            on GroupKeysAndClose {
  14.138 +                do saveGroupKeys;
  14.139 +                if keyElectionWon {
  14.140 +                    do ownKeysAreGroupKeys;
  14.141 +                    go Grouped;
  14.142 +                }
  14.143 +                // do receivedKeysAreGroupKeys; -- implicit
  14.144 +                go Grouped;
  14.145 +            }
  14.146 +        }
  14.147 +
  14.148 +        state HandshakingWithGroup {
  14.149 +            on Init
  14.150 +                do showJoinGroupHandshake;
  14.151 +
  14.152 +            // Cancel is Rollback
  14.153 +            on Cancel {
  14.154 +                do sendRollback;
  14.155 +                go Sole;
  14.156 +            }
  14.157 +
  14.158 +            on Rollback
  14.159 +                go Sole;
  14.160 +
  14.161 +            // Reject is CommitReject
  14.162 +            on Reject {
  14.163 +                do sendCommitReject;
  14.164 +                do disable;
  14.165 +                go End;
  14.166 +            }
  14.167 +
  14.168 +            on CommitReject {
  14.169 +                do disable;
  14.170 +                go End;
  14.171 +            }
  14.172 +
  14.173 +            // Accept is Phase1Commit
  14.174 +            on Accept {
  14.175 +                do sendCommitAccept;
  14.176 +                go HandshakingJoinPhase1;
  14.177 +            }
  14.178 +
  14.179 +            on CommitAccept
  14.180 +                go HandshakingJoinPhase1Own;
  14.181 +        }
  14.182 +
  14.183 +        state HandshakingJoinPhase1 {
  14.184 +            on Rollback
  14.185 +                go Sole;
  14.186 +            
  14.187 +            on CommitReject {
  14.188 +                do disable;
  14.189 +                go End;
  14.190 +            }
  14.191 +
  14.192 +            on CommitAccept
  14.193 +                go JoinGroup;
  14.194 +        }
  14.195 +
  14.196 +        state HandshakingJoinPhase1Own {
  14.197 +            on Cancel {
  14.198 +                do sendRollback;
  14.199 +                go Sole;
  14.200 +            }
  14.201 +
  14.202 +            on Reject {
  14.203 +                do sendCommitReject;
  14.204 +                do disable;
  14.205 +                go End;
  14.206 +            }
  14.207 +
  14.208 +            on Accept
  14.209 +                go JoinGroup;
  14.210 +        }
  14.211 +
  14.212 +        state JoinGroup {
  14.213 +            on GroupKeysAndClose {
  14.214 +                do sendGroupKeys; // first send own keys
  14.215 +                do saveGroupKeys; // then store new group keys
  14.216 +                go Grouped;
  14.217 +            }
  14.218 +        }
  14.219 +
  14.220 +        state Grouped {
  14.221 +            on Init
  14.222 +                do closeHandshakeDialog;
  14.223 +
  14.224 +            on GroupKeys
  14.225 +                do saveGroupKeys;
  14.226 +
  14.227 +            on KeyGen
  14.228 +                do sendGroupKeys;
  14.229 +
  14.230 +            on Beacon
  14.231 +                do sendHandshakeRequest;
  14.232 +
  14.233 +            on HandshakeAnswer
  14.234 +                go HandshakingGrouped;
  14.235 +        }
  14.236 +
  14.237 +        state HandshakingGrouped {
  14.238 +            on Init
  14.239 +                do showGroupedHandshake;
  14.240 +    
  14.241 +            // Cancel is Rollback
  14.242 +            on Cancel {
  14.243 +                do sendRollback;
  14.244 +                go Grouped;
  14.245 +            }
  14.246 +
  14.247 +            on Rollback
  14.248 +                go Grouped;
  14.249 +
  14.250 +            // Reject is CommitReject
  14.251 +            on Reject {
  14.252 +                do sendCommitReject;
  14.253 +                go Grouped;
  14.254 +            }
  14.255 +
  14.256 +            on CommitReject
  14.257 +                go Grouped;
  14.258 +
  14.259 +            // Accept is Phase1Commit
  14.260 +            on Accept {
  14.261 +                do sendCommitAccept;
  14.262 +                go HandshakingGroupedPhase1;
  14.263 +            }
  14.264 +
  14.265 +            on CommitAccept
  14.266 +                go HandshakingGroupedPhase1Own;
  14.267 +
  14.268 +            on GroupKeys
  14.269 +                do saveGroupKeys;
  14.270 +        }
  14.271 +
  14.272 +        state HandshakingGroupedPhase1 {
  14.273 +            on Rollback
  14.274 +                go Grouped;
  14.275 +
  14.276 +            on CommitReject
  14.277 +                go Grouped;
  14.278 +
  14.279 +            on CommitAccept {
  14.280 +                do sendGroupKeysAndClose;
  14.281 +                go Grouped;
  14.282 +            }
  14.283 +
  14.284 +            on GroupKeys
  14.285 +                do saveGroupKeys;
  14.286 +        }
  14.287 +
  14.288 +        state HandshakingGroupedPhase1Own {
  14.289 +            on Cancel {
  14.290 +                do sendRollback;
  14.291 +                go Grouped;
  14.292 +            }
  14.293 +
  14.294 +            on Reject {
  14.295 +                do sendCommitReject;
  14.296 +                go Grouped;
  14.297 +            }
  14.298 +
  14.299 +            on Accept {
  14.300 +                do sendGroupKeysAndClose;
  14.301 +                go Grouped;
  14.302 +            }
  14.303 +
  14.304 +            on GroupKeys
  14.305 +                do saveGroupKeys;
  14.306 +        }
  14.307 + 
  14.308 +        external Accept 30;
  14.309 +        external Reject 31;
  14.310 +        external Cancel 32;
  14.311 +
  14.312 +        message Beacon 2 {
  14.313 +            field TID challenge;
  14.314 +            auto Version version;
  14.315 +        }
  14.316 +
  14.317 +        message HandshakeRequest 3 {
  14.318 +            field TID challenge;
  14.319 +            auto Version version;
  14.320 +            field TID transaction;
  14.321 +            field Hash fpr;
  14.322 +            field bool is_group;
  14.323 +        }
  14.324 +
  14.325 +        message HandshakeAnswer 4 {
  14.326 +            field TID transaction;
  14.327 +            field Hash fpr;
  14.328 +        }
  14.329 +
  14.330 +        message Rollback 5 {
  14.331 +            field TID transaction;
  14.332 +        }
  14.333 +
  14.334 +        message CommitReject 6 {
  14.335 +            field TID transaction;
  14.336 +        }
  14.337 +
  14.338 +        message CommitAccept 7 {
  14.339 +            field TID transaction;
  14.340 +        }
  14.341 +
  14.342 +        message GroupKeysAndClose 8 {
  14.343 +            field TID transaction;
  14.344 +            field IdentityList identities;
  14.345 +        }
  14.346 +
  14.347 +        message GroupKeys 9 {
  14.348 +            field IdentityList identities;
  14.349 +        }
  14.350 +    }
  14.351 +}
  14.352 +
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/sync/sync_protocol.txt	Thu Aug 09 12:26:53 2018 +0200
    15.3 @@ -0,0 +1,39 @@
    15.4 +p≡p Sync protocol
    15.5 +=================
    15.6 +
    15.7 +1. Protocol Stack
    15.8 +-----------------
    15.9 +
   15.10 +Trust Sync | Contact Sync | Task Sync
   15.11 +Sync | Key Sync
   15.12 +Baseprotocol
   15.13 +Transport
   15.14 +
   15.15 +1. Device View
   15.16 +--------------
   15.17 +
   15.18 +1.1 State Sole
   15.19 +
   15.20 +A Device is in state Sole when it is not member of a Device group and when it
   15.21 +is not part of a Negotiation.
   15.22 +
   15.23 +1.1 State Grouped
   15.24 +
   15.25 +A Device is in state Grouped when it is member of a Device group and when it is
   15.26 +not part of a Negotiation.
   15.27 +
   15.28 +1.1 State Handshaking
   15.29 +
   15.30 +A Device is in state Handshaking when it is triggered by receiving a Beacon.
   15.31 +
   15.32 +1.1 State SentCommit
   15.33 +
   15.34 +1.1 State ReceivedCommit
   15.35 +
   15.36 +1. Transaction View for Negotiation
   15.37 +-----------------------------------
   15.38 +
   15.39 +A Negotiation is identified by the FPR of the Key of the Identity, which is
   15.40 +used for transport. 
   15.41 +
   15.42 +
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/sync/sync_ux.txt	Thu Aug 09 12:26:53 2018 +0200
    16.3 @@ -0,0 +1,102 @@
    16.4 +p≡p Sync UX
    16.5 +===========
    16.6 +
    16.7 +Sync is a protocol to form one device group. It first is driving a
    16.8 +transaction named the Negotiation. There are two situations Sync can be
    16.9 +in:
   16.10 +
   16.11 +1) either there is no device group yet
   16.12 +2) or there is already a device group
   16.13 +
   16.14 +Case 1):
   16.15 +--------
   16.16 +
   16.17 +In case 1) we have two devices in the state Sole. When the user
   16.18 +configures the first device, nothing happens. When the user configures
   16.19 +the second device, it will detect that there is another device being in
   16.20 +state Sole.
   16.21 +
   16.22 +The two devices detect each other. Both are showing a dialog asking the
   16.23 +user: “There is another device detected. Shell we form a device group?”
   16.24 +
   16.25 +There are three possible answers:
   16.26 +
   16.27 +a) Accept
   16.28 +b) Reject
   16.29 +c) Cancel
   16.30 +
   16.31 +If one of the devices gets a Cancel, then the device group is NOT
   16.32 +formed. Sync remains enabled on both devices. This is corresponding with
   16.33 +a ROLLBACK of the Negotiation.
   16.34 +
   16.35 +If one of the devices gets a Reject, then the device group is NOT
   16.36 +formed. Sync then is disabled on both devices. This is corresponding
   16.37 +with a COMMIT of the Negotiation with the result REJECT.
   16.38 +
   16.39 +If both devices get an Accept, then the device group is formed. Sync is
   16.40 +then enabled on both devices. This is corresponding with a two-phase
   16.41 +COMMIT of the Negotiation with the result ACCEPT.
   16.42 +
   16.43 +Case 2):
   16.44 +
   16.45 +In case 2) we have at least two devices forming a device group already
   16.46 +(named “old devices”), being in state Grouped. And we have one device,
   16.47 +which is not yet in a device group (named “new device”), being in state
   16.48 +Sole.
   16.49 +
   16.50 +The new device and the old devices detect that there is a new device,
   16.51 +which could join the existing device group. The new device is showing
   16.52 +a dialog with “There is already a device group. Shell this device join?”
   16.53 +Possible answers are Join/Accept, Reject and Cancel. The old devices are
   16.54 +ALL showing a dialog with “A new device is detected. Shell we accept
   16.55 +the new device as new member in our device group?” Possible answers are
   16.56 +Accept, Reject and Cancel.
   16.57 +
   16.58 +If one of the devices gets a Cancel, then the new device is NOT added to
   16.59 +the device group. Sync remains enabled on all devices. This is
   16.60 +corresponding with a ROLLBACK of the Negotiation.
   16.61 +
   16.62 +If one of the devices gets a Reject, then the new device is NOT added to
   16.63 +the device group. Sync remains enabled on the old devices, but gets
   16.64 +disabled on the new device. This is corresponding with a COMMIT of the
   16.65 +Negotiation with the result REJECT.
   16.66 +
   16.67 +Only if the new device gets an Accept and at least one of the old
   16.68 +devices gets an Accept, then the new device is added to the device group.
   16.69 +Sync then remains enabled on the old devices, and gets enabled on the
   16.70 +new device. This is corresponding with a COMMIT of the Negotiation with
   16.71 +the result ACCEPT.
   16.72 +
   16.73 +Key sync is starting while Sync is taking place. The Sync dialog is a
   16.74 +Trustwords dialog offering Trustwords to check for the user. User's
   16.75 +decision is not only based on if she/he wants to have a device group in
   16.76 +case 1) – or – if she/he wants to add a new device to an existing device
   16.77 +group in case 2), but also on the question, if the Trustwords on the
   16.78 +two handled devices (either the two Sole ones or the new one and one of
   16.79 +the old ones) are identical.
   16.80 +
   16.81 +Because there is a Trustwords check, from then on the connection is
   16.82 +becoming green, and secret keys will be sent and shared on all devices
   16.83 +being member of the same device group.
   16.84 +
   16.85 +When Sync is switched off on a device, then it leaves the device group
   16.86 +it is in. A Key reset is needed then on the remaining devices, dealing
   16.87 +out new group keys for all own identities.
   16.88 +
   16.89 +Sync can be switched on in two ways:
   16.90 +
   16.91 +1) Switched on for all (default in p≡p apps)
   16.92 +2) Switched on only for a list of accounts (reached by switching it off
   16.93 +   first)
   16.94 +
   16.95 +If Sync is enabled in 1) then adding a new account will have Sync for
   16.96 +this account, too, implicitely.
   16.97 +
   16.98 +If Sync is enabled in 2) then adding a new account will have Sync
   16.99 +switched off for this account by default.
  16.100 +
  16.101 +Yours,
  16.102 +VB.
  16.103 +-- 
  16.104 +Volker Birk, p≡p project
  16.105 +mailto:vb@pep-project.org  https://pep-project.org
    17.1 --- a/test/Makefile	Thu Aug 09 12:15:44 2018 +0200
    17.2 +++ b/test/Makefile	Thu Aug 09 12:26:53 2018 +0200
    17.3 @@ -113,7 +113,7 @@
    17.4  .PHONY: clean
    17.5  clean:
    17.6  	$(RM) $(TARGET) $(OBJS) $(DEPS)
    17.7 -	$(RM) $(HERE)/*Tests
    17.8 +	$(RM) $(HERE)/*Tests msg_2.0.asc
    17.9  
   17.10  
   17.11