sync/cond_act_sync.yml2
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 16 Oct 2019 16:35:08 +0200
branchENGINE-654
changeset 4118 b0995cc07d02
parent 4068 d676b03d7759
child 4132 bf7b5f139996
permissions -rw-r--r--
merged in sync
vb@2831
     1
// This file is under GNU General Public License 3.0
vb@2831
     2
// see LICENSE.txt
vb@2831
     3
vb@2831
     4
// generate conditions and actions
vb@2831
     5
vb@3512
     6
// Copyleft (c) 2017-2019, p≡p foundation
vb@2831
     7
vb@2831
     8
// Written by Volker Birk
vb@2831
     9
vb@2831
    10
vb@2844
    11
include ./sql_func.yml2
vb@2831
    12
vb@2831
    13
// condition: PEP_STATUS «@name»(PEP_SESSION session, bool *result)
vb@2831
    14
vb@2831
    15
condition deviceGrouped {
vb@2831
    16
    call "exec_sql_int" with "sql"
vb@3525
    17
        > "select count(*) from identity where is_own = 1 and (flags & 0x100) = 0x100;"
vb@2831
    18
    |> *result = _result > 0;
vb@2831
    19
}
vb@2831
    20
vb@3825
    21
condition weAreOfferer
vb@2902
    22
||
vb@3773
    23
    TID_t *t1 = &session->sync_state.keysync.challenge;
vb@3772
    24
    TID_t *t2 = &session->sync_state.own.challenge;
vb@2902
    25
vb@2905
    26
    *result = _TID_greater(t1, t2);
vb@2902
    27
||
vb@2902
    28
vb@2831
    29
condition partnerIsGrouped
vb@3773
    30
|> *result = session->sync_state.keysync.is_group;
vb@2831
    31
vb@3514
    32
condition sameChallenge
vb@3514
    33
||
vb@3773
    34
    TID_t *t1 = &session->sync_state.keysync.challenge;
vb@3772
    35
    TID_t *t2 = &session->sync_state.own.challenge;
vb@3514
    36
vb@3514
    37
    *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
vb@3514
    38
||
vb@3514
    39
vb@3779
    40
condition sameNegotiation
vb@3510
    41
||
vb@3773
    42
    TID_t *t1 = &session->sync_state.keysync.negotiation;
vb@3779
    43
    TID_t *t2 = &session->sync_state.comm_partner.negotiation;
vb@3510
    44
vb@3591
    45
    // test if TID is identical
vb@3510
    46
    *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
vb@3510
    47
||
vb@3510
    48
vb@3779
    49
condition sameNegotiationAndPartner
vb@3591
    50
||
vb@3773
    51
    TID_t *t1 = &session->sync_state.keysync.negotiation;
vb@3779
    52
    TID_t *t2 = &session->sync_state.comm_partner.negotiation;
vb@3591
    53
vb@3779
    54
    const char *s1 = session->sync_state.comm_partner.sender_fpr;
vb@3779
    55
    const char *s2 = session->sync_state.transport.sender_fpr;
vb@3591
    56
vb@3591
    57
    // test if TID is identical
vb@3591
    58
    *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0
vb@3591
    59
    // and test if we're talking to the same sender
vb@3591
    60
            && s1 && s2 && strcmp(s1, s2) == 0;
vb@3591
    61
||
vb@3591
    62
vb@2831
    63
condition keyElectionWon
vb@2831
    64
||
vb@3779
    65
    pEp_identity *from = session->sync_state.transport.from;
vb@3779
    66
    char *sender_fpr = session->sync_state.comm_partner.sender_fpr;
vb@2831
    67
vb@3389
    68
    assert(from && from->address && from->address[0] && from->user_id &&
vb@3389
    69
            from->user_id[0]);
vb@3389
    70
    if (!(from && from->address && from->address[0] && from->user_id &&
vb@3389
    71
            from->user_id[0]))
vb@2831
    72
        return PEP_ILLEGAL_VALUE;
vb@2831
    73
vb@2831
    74
    pEp_identity *me = NULL;
vb@2901
    75
    PEP_STATUS status = get_identity(session, from->address, from->user_id, &me);
vb@2831
    76
    assert(status == PEP_STATUS_OK);
vb@2831
    77
    if (status)
vb@2831
    78
        return status;
vb@2831
    79
vb@2831
    80
    assert(me->fpr && me->fpr[0]);
vb@2831
    81
    if (!(me->fpr && me->fpr[0])) {
vb@2831
    82
        free_identity(me);
vb@2831
    83
        return PEP_ILLEGAL_VALUE;
vb@2831
    84
    }
vb@2831
    85
vb@3779
    86
    size_t len = MIN(strlen(sender_fpr), strlen(me->fpr));
vb@3779
    87
    *result = strncasecmp(sender_fpr, me->fpr, len) > 0;
vb@2831
    88
    free_identity(me);
vb@2831
    89
||
vb@2831
    90
vb@2831
    91
// action: PEP_STATUS «@name»(PEP_SESSION session)
vb@2831
    92
vb@2831
    93
function "new_UUID" {
vb@2831
    94
    param "dst";
vb@2831
    95
    ||
vb@3781
    96
        {
vb@3781
    97
            pEpUUID c;
vb@3781
    98
            uuid_generate_random(c);
vb@2831
    99
vb@3781
   100
            OCTET_STRING_fromBuf(«$dst», (char *) c, 16);
vb@3781
   101
        }
vb@2831
   102
    ||
vb@2831
   103
}
vb@2831
   104
vb@2831
   105
function "copy_UUID" {
vb@2831
   106
    param "src", param "dst";
vb@2831
   107
    ||
vb@3605
   108
        {
vb@3605
   109
            TID_t *src = «$src»;
vb@3605
   110
            TID_t *dst = «$dst»;
vb@2831
   111
vb@3605
   112
            assert(src->size == 16);
vb@3605
   113
            if (!(src->size == 16))
vb@3605
   114
                return PEP_UNKNOWN_ERROR;
vb@2831
   115
vb@3605
   116
            OCTET_STRING_fromBuf(dst, (char *) src->buf, src->size);
vb@3605
   117
        }
vb@3605
   118
    ||
vb@3605
   119
}
vb@3605
   120
vb@3605
   121
function "xor_UUID" {
vb@3605
   122
    param "src", param "dst";
vb@3605
   123
    ||
vb@3605
   124
        {
vb@3605
   125
            TID_t *src = «$src»;
vb@3605
   126
            TID_t *dst = «$dst»;
vb@3605
   127
vb@3605
   128
            assert(src->size == 16 && dst->size == 16);
vb@3605
   129
            if (!(src->size == 16 && dst->size == 16))
vb@3605
   130
                return PEP_UNKNOWN_ERROR;
vb@3605
   131
vb@3605
   132
            for (int i=0; i < src->size; ++i)
vb@3605
   133
                dst->buf[i] ^= src->buf[i];
vb@3605
   134
        }
vb@2831
   135
    ||
vb@2831
   136
}
vb@2831
   137
vb@3781
   138
action newChallengeAndNegotiationBase {
vb@3601
   139
    // random new challenge
vb@3772
   140
    call "new_UUID" with "dst" > &session->sync_state.own.challenge
vb@3781
   141
    call "copy_UUID" {
vb@3781
   142
        with "src" > &session->sync_state.own.challenge
vb@3781
   143
        with "dst" > &session->sync_state.keysync.challenge
vb@3781
   144
    }
vb@2831
   145
vb@3781
   146
    // this is the random data we are using as a base
vb@3781
   147
    call "new_UUID" with "dst" > &session->sync_state.own.negotiation
vb@3782
   148
||
vb@3782
   149
    memset(session->sync_state.keysync.negotiation.buf, 0,
vb@3782
   150
            session->sync_state.keysync.negotiation.size);
vb@3782
   151
    memset(session->sync_state.comm_partner.negotiation.buf, 0,
vb@3782
   152
            session->sync_state.comm_partner.negotiation.size);
vb@3782
   153
||
vb@2831
   154
}
vb@2831
   155
vb@3601
   156
action useOwnChallenge call "copy_UUID" {
vb@3772
   157
    with "src" > &session->sync_state.own.challenge
vb@3773
   158
    with "dst" > &session->sync_state.keysync.challenge
vb@3601
   159
}
vb@3601
   160
vb@3781
   161
action openNegotiation {
vb@3510
   162
||
vb@3590
   163
    // sender key must be stable while transaction
vb@3773
   164
vb@3773
   165
    // we take the actual signature of the last message and store it in our
vb@3773
   166
    // state for the comm partner
vb@3779
   167
    assert(session->sync_state.transport.sender_fpr);
vb@3773
   168
vb@3779
   169
    free(session->sync_state.comm_partner.sender_fpr);
vb@3773
   170
vb@3779
   171
    session->sync_state.comm_partner.sender_fpr
vb@3779
   172
            = strdup(session->sync_state.transport.sender_fpr);
vb@3779
   173
    assert(session->sync_state.comm_partner.sender_fpr);
vb@3779
   174
    if (!session->sync_state.comm_partner.sender_fpr)
vb@3591
   175
        return PEP_OUT_OF_MEMORY;
vb@3590
   176
vb@3779
   177
    // we need a unique TID for the Negotiation with each single comm_partner
vb@3779
   178
    // we identify the comm_partners by their Challenge
vb@3779
   179
    // we derive the actual Negotiation TID by having random data and XORing it
vb@3779
   180
    // with comm_partner's Challenge
vb@3779
   181
vb@3781
   182
    // copy Negotiation base into buffer
vb@3779
   183
vb@3783
   184
||
vb@3605
   185
    call "copy_UUID" {
vb@3779
   186
        with "src" > &session->sync_state.own.negotiation
vb@3779
   187
        with "dst" > &session->sync_state.keysync.negotiation
vb@3779
   188
    }
vb@3783
   189
||
vb@3779
   190
vb@3779
   191
    // we're XORing this with the challenge of the comm_partner, which is in
vb@3779
   192
    // the buffer already
vb@3779
   193
vb@3783
   194
||
vb@3779
   195
    call "xor_UUID" {
vb@3773
   196
        with "src" > &session->sync_state.keysync.challenge
vb@3773
   197
        with "dst" > &session->sync_state.keysync.negotiation
vb@3605
   198
    }
vb@3783
   199
||
vb@3779
   200
vb@3779
   201
    // this is the Negotiation's TID for this comm_partner
vb@3779
   202
vb@3783
   203
||
vb@3591
   204
    call "copy_UUID" {
vb@3773
   205
        with "src" > &session->sync_state.keysync.negotiation
vb@3779
   206
        with "dst" > &session->sync_state.comm_partner.negotiation
vb@3591
   207
    }
vb@3510
   208
}
vb@3510
   209
vb@3779
   210
action storeNegotiation {
vb@3591
   211
||
vb@3591
   212
    // sender key must be stable while transaction
vb@3773
   213
vb@3773
   214
    // we take the actual signature of the last message and store it in our
vb@3773
   215
    // state for the comm partner
vb@3779
   216
    assert(session->sync_state.transport.sender_fpr);
vb@3773
   217
vb@3779
   218
    free(session->sync_state.comm_partner.sender_fpr);
vb@3773
   219
vb@3779
   220
    session->sync_state.comm_partner.sender_fpr
vb@3779
   221
            = strdup(session->sync_state.transport.sender_fpr);
vb@3779
   222
    assert(session->sync_state.comm_partner.sender_fpr);
vb@3779
   223
    if (!session->sync_state.comm_partner.sender_fpr)
vb@3591
   224
        return PEP_OUT_OF_MEMORY;
vb@3591
   225
vb@3591
   226
||
vb@3591
   227
    call "copy_UUID" {
vb@3773
   228
        with "src" > &session->sync_state.keysync.negotiation
vb@3779
   229
        with "dst" > &session->sync_state.comm_partner.negotiation
vb@3591
   230
    }
vb@2831
   231
}
vb@2831
   232
vb@2831
   233
function "show_handshake" {
vb@2831
   234
    param "type";
vb@2831
   235
    ||
vb@2831
   236
        assert(session->notifyHandshake);
vb@2831
   237
        if (!session->notifyHandshake)
vb@2831
   238
            return PEP_SYNC_NO_NOTIFY_CALLBACK;
vb@2831
   239
     
vb@3525
   240
    ||
vb@3525
   241
    choose {
vb@3791
   242
    when "$type = 'SYNC_NOTIFY_INIT_ADD_OUR_DEVICE' or $type = 'SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE' or $type = 'SYNC_NOTIFY_INIT_FORM_GROUP'"
vb@3525
   243
    ||
vb@3779
   244
        assert(session->sync_state.transport.from);
vb@3779
   245
        if (!session->sync_state.transport.from)
vb@2831
   246
            return PEP_ILLEGAL_VALUE;
vb@2831
   247
vb@3779
   248
        pEp_identity *from = session->sync_state.transport.from;
vb@2831
   249
        pEp_identity *me = NULL;
vb@2901
   250
        PEP_STATUS status = get_identity(session, from->address, from->user_id, &me);
vb@2831
   251
        assert(status == PEP_STATUS_OK);
vb@2831
   252
        if (status)
vb@2831
   253
            return status;
vb@3791
   254
        assert(strcmp(me->fpr, session->sync_state.comm_partner.sender_fpr) != 0);
vb@3791
   255
        
vb@2831
   256
        assert(me->fpr && me->fpr[0]);
vb@2831
   257
        if (!(me->fpr && me->fpr[0])) {
vb@2831
   258
            free_identity(me);
vb@2831
   259
            return PEP_ILLEGAL_VALUE;
vb@2831
   260
        }
vb@2831
   261
vb@2831
   262
        pEp_identity *partner = identity_dup(from);
vb@2831
   263
        if (!partner) {
vb@2831
   264
            free_identity(me);
vb@2831
   265
            return PEP_OUT_OF_MEMORY;
vb@2831
   266
        }
vb@3365
   267
vb@3779
   268
        assert(session->sync_state.comm_partner.sender_fpr);
vb@3779
   269
        if (session->sync_state.comm_partner.sender_fpr) {
vb@3379
   270
            free(partner->fpr);
vb@3779
   271
            partner->fpr = strdup(session->sync_state.comm_partner.sender_fpr);
vb@3791
   272
            assert(partner->fpr);
vb@3379
   273
            if (!partner->fpr) {
vb@3379
   274
                free_identity(me);
vb@3379
   275
                free_identity(partner);
vb@3379
   276
                return PEP_OUT_OF_MEMORY;
vb@3379
   277
            }
vb@3364
   278
        }
vb@2831
   279
vb@3722
   280
        free(partner->user_id);
vb@3722
   281
        partner->user_id = strdup("#NV");
vb@3722
   282
        assert(partner->user_id);
vb@3722
   283
        if (!partner->user_id) {
vb@3722
   284
            free_identity(me);
vb@3722
   285
            free_identity(partner);
vb@3722
   286
            return PEP_OUT_OF_MEMORY;
vb@3722
   287
        }
vb@3722
   288
vb@3791
   289
        assert(strcmp(me->fpr, partner->fpr) != 0);
vb@3047
   290
        status = session->notifyHandshake(me, partner, «$type»);
vb@2831
   291
        if (status)
vb@2831
   292
            return status;
vb@2831
   293
    ||
vb@3791
   294
    otherwise
vb@3791
   295
    ||
vb@3791
   296
        pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
vb@3791
   297
        pEp_identity *partner = new_identity(NULL, NULL, NULL, NULL);
vb@3791
   298
        assert(me && partner);
vb@3791
   299
        if (!(me && partner)) {
vb@3791
   300
            free_identity(me);
vb@3791
   301
            free_identity(partner);
vb@3791
   302
            return PEP_OUT_OF_MEMORY;
vb@3791
   303
        }
vb@3791
   304
vb@3791
   305
        PEP_STATUS status = session->notifyHandshake(me, partner, «$type»);
vb@3791
   306
        if (status)
vb@3791
   307
            return status;
vb@3791
   308
    ||
vb@3525
   309
    }
vb@2831
   310
}
vb@2831
   311
vb@2831
   312
action showSoleHandshake
vb@2831
   313
    call "show_handshake" with "type" > SYNC_NOTIFY_INIT_FORM_GROUP
vb@2831
   314
vb@2831
   315
action showJoinGroupHandshake
vb@2831
   316
    call "show_handshake" with "type" > SYNC_NOTIFY_INIT_ADD_OUR_DEVICE
vb@2831
   317
vb@2831
   318
action showGroupedHandshake
vb@2831
   319
    call "show_handshake" with "type" > SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE
vb@2831
   320
vb@3522
   321
action hideHandshakeDialog
vb@3522
   322
    call "show_handshake" with "type" > SYNC_NOTIFY_OVERTAKEN
vb@3522
   323
vb@3524
   324
action showDeviceAdded
vb@3524
   325
    call "show_handshake" with "type" > SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED
vb@3524
   326
vb@3971
   327
action showFormingGroup
vb@3971
   328
    call "show_handshake" with "type" > SYNC_NOTIFY_FORMING_GROUP
vb@3971
   329
    
vb@3524
   330
action showGroupCreated
vb@3524
   331
    call "show_handshake" with "type" > SYNC_NOTIFY_ACCEPTED_GROUP_CREATED
vb@3524
   332
vb@3525
   333
action showBeingSole
vb@3525
   334
    call "show_handshake" with "type" > SYNC_NOTIFY_SOLE
vb@3525
   335
vb@3525
   336
action showBeingInGroup
vb@3525
   337
    call "show_handshake" with "type" > SYNC_NOTIFY_IN_GROUP
vb@3525
   338
vb@2914
   339
timeout KeySync
vb@2913
   340
    call "show_handshake" with "type" > SYNC_NOTIFY_TIMEOUT
vb@2913
   341
vb@3390
   342
action prepareOwnKeys
vb@3390
   343
||
vb@3390
   344
    stringlist_t *own_keys;
krista@3583
   345
    PEP_STATUS status = _own_keys_retrieve(session, &own_keys, PEP_idf_not_for_sync, true);
vb@3390
   346
    if (status)
vb@3390
   347
        return status;
vb@3390
   348
vb@3772
   349
    if (session->sync_state.own.keys)
vb@3772
   350
        free_stringlist(session->sync_state.own.keys);
vb@3772
   351
    session->sync_state.own.keys = own_keys;
vb@3394
   352
vb@3394
   353
    identity_list *il;
vb@3394
   354
    status = _own_identities_retrieve(session, &il, PEP_idf_not_for_sync);
vb@3394
   355
    if (status)
vb@3394
   356
        return status;
vb@3394
   357
vb@3773
   358
    IdentityList_from_identity_list(il, &session->sync_state.keysync.ownIdentities);
vb@3609
   359
    free_identity_list(il);
vb@3390
   360
||
vb@3390
   361
vb@2831
   362
action saveGroupKeys
vb@2831
   363
||
vb@3790
   364
    char *user_id = NULL;
vb@3790
   365
    PEP_STATUS status = get_default_own_userid(session, &user_id);
vb@3790
   366
    if (status)
vb@3790
   367
        return status;
vb@3790
   368
vb@3773
   369
    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
vb@3794
   370
    if (!il) {
vb@3794
   371
        free(user_id);
vb@2831
   372
        return PEP_OUT_OF_MEMORY;
vb@3794
   373
    }
vb@2831
   374
    
vb@3786
   375
    identity_list *oil = session->sync_state.own.identities;
vb@3786
   376
vb@2831
   377
    // BUG: this should be a transaction and been rolled back completely on error
vb@2831
   378
    for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
vb@3785
   379
        pEp_identity *ident = _il->ident;
vb@3785
   380
        bool is_own_already = false;
vb@3785
   381
vb@3790
   382
        status = is_own_address(session, ident->address, &is_own_already);
vb@3786
   383
        if (status) {
vb@3786
   384
            free_identity_list(il);
vb@3794
   385
            free(user_id);
vb@3786
   386
            return status;
vb@3786
   387
        }
vb@3786
   388
vb@3786
   389
        free(ident->user_id);
vb@3794
   390
        ident->user_id = strdup(user_id);
vb@3794
   391
        assert(ident->user_id);
vb@3794
   392
        if (!ident->user_id) {
vb@3794
   393
            free_identity_list(il);
vb@3794
   394
            free(user_id);
vb@3794
   395
            return PEP_OUT_OF_MEMORY;
vb@3794
   396
        }
vb@3786
   397
vb@3785
   398
        if (is_own_already) {
vb@3786
   399
            ident->comm_type = PEP_ct_pEp;
vb@3786
   400
            status = set_trust(session, ident);
vb@3785
   401
        }
vb@3785
   402
        else {
vb@3786
   403
            oil = identity_list_add(oil, ident);
vb@3786
   404
            if (!oil) {
vb@3786
   405
                free_identity_list(il);
vb@3794
   406
                free(user_id);
vb@3786
   407
                return PEP_OUT_OF_MEMORY;
vb@3786
   408
            }
vb@3785
   409
            status = myself(session, ident);
vb@3785
   410
        }
vb@2831
   411
        if (status) {
vb@2831
   412
            free_identity_list(il);
vb@3794
   413
            free(user_id);
vb@2831
   414
            return status;
vb@2831
   415
        }
vb@2831
   416
    }
vb@2831
   417
vb@3794
   418
    free(user_id);
vb@2831
   419
    free_identity_list(il);
vb@2831
   420
||
vb@2831
   421
vb@3815
   422
action ownKeysAreDefaultKeys
vb@3434
   423
||
vb@3434
   424
    PEP_STATUS status = PEP_STATUS_OK;
vb@3434
   425
vb@3786
   426
    // set flag for all keys; don't change anything else
vb@3772
   427
    for (identity_list *il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
vb@3434
   428
        if (!(il->ident->flags && PEP_idf_not_for_sync)) {
vb@3434
   429
            status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
vb@3434
   430
            if (status)
vb@3434
   431
                return status;
vb@3434
   432
        }
vb@2831
   433
    }
vb@3434
   434
||
vb@2831
   435
vb@3815
   436
action receivedKeysAreDefaultKeys
vb@3525
   437
||
vb@3525
   438
    PEP_STATUS status = PEP_STATUS_OK;
vb@3786
   439
    // set flag for all keys
vb@3772
   440
    for (identity_list *il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
vb@3527
   441
        if (!(il->ident->flags && PEP_idf_not_for_sync)) {
vb@3786
   442
            
vb@3527
   443
            status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
vb@3527
   444
            if (status)
vb@3527
   445
                return status;
vb@3527
   446
        }
vb@3527
   447
    }
vb@3527
   448
vb@3786
   449
    char *user_id = NULL;
vb@3786
   450
    status = get_default_own_userid(session, &user_id);
vb@3786
   451
    if (status)
vb@3786
   452
        return status;
vb@3786
   453
vb@3773
   454
    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
vb@3525
   455
    if (!il)
vb@3525
   456
        return PEP_OUT_OF_MEMORY;
vb@3525
   457
vb@3786
   458
    for (identity_list *_il = il; _il && _il->ident ; _il = _il->next) {
vb@3525
   459
        // replace partner's user_id with own user_id
vb@3786
   460
        free(_il->ident->user_id);
vb@3786
   461
        _il->ident->user_id = strdup(user_id);
vb@3786
   462
        assert(_il->ident->user_id);
vb@3786
   463
        if (!_il->ident->user_id) {
vb@3525
   464
            free_identity_list(il);
vb@3786
   465
            free(user_id);
vb@3525
   466
            return PEP_OUT_OF_MEMORY;
vb@3525
   467
        }
vb@3786
   468
    
vb@3786
   469
        const char *own_key = _il->ident->fpr;
vb@3786
   470
        _il->ident->fpr = NULL;
vb@3786
   471
        status = set_own_key(session, _il->ident, own_key);
vb@3525
   472
        if (status) {
vb@3525
   473
            free_identity_list(il);
vb@3786
   474
            free(user_id);
vb@3525
   475
            return status;
vb@3525
   476
        }
vb@3525
   477
    }
vb@3525
   478
vb@3525
   479
    free_identity_list(il);
vb@3786
   480
    free(user_id);
vb@3525
   481
||
vb@3406
   482
vb@3516
   483
action trustThisKey
vb@3516
   484
||
vb@3779
   485
    assert(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr);
vb@3779
   486
    if (!(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr))
vb@3516
   487
        return PEP_ILLEGAL_VALUE;
vb@3516
   488
vb@3779
   489
    pEp_identity *ident = identity_dup(session->sync_state.transport.from);
vb@3754
   490
    if (!ident)
vb@3754
   491
        return PEP_OUT_OF_MEMORY;
vb@3516
   492
    free(ident->fpr);
vb@3779
   493
    ident->fpr = strdup(session->sync_state.comm_partner.sender_fpr);
vb@3516
   494
    assert(ident->fpr);
vb@3754
   495
    if (!ident->fpr) {
vb@3754
   496
        free_identity(ident);
vb@3516
   497
        return PEP_OUT_OF_MEMORY;
vb@3754
   498
    }
vb@3516
   499
vb@3516
   500
    PEP_STATUS status = trust_own_key(session, ident);
vb@3754
   501
    if (status) {
vb@3754
   502
        free_identity(ident);
vb@3516
   503
        return status;
vb@3754
   504
    }
vb@3523
   505
vb@3773
   506
    OCTET_STRING_fromBuf(&session->sync_state.keysync.key, ident->fpr, strlen(ident->fpr));
vb@3754
   507
    free_identity(ident);
vb@3516
   508
||
vb@3516
   509
vb@3524
   510
action untrustThisKey
vb@3524
   511
||
vb@3779
   512
    assert(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr);
vb@3779
   513
    if (!(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr))
vb@3524
   514
        return PEP_ILLEGAL_VALUE;
vb@3524
   515
vb@3779
   516
    pEp_identity *ident = session->sync_state.transport.from;
vb@3524
   517
    free(ident->fpr);
vb@3779
   518
    ident->fpr = strdup(session->sync_state.comm_partner.sender_fpr);
vb@3524
   519
    assert(ident->fpr);
vb@3524
   520
    if (!ident->fpr)
vb@3524
   521
        return PEP_OUT_OF_MEMORY;
vb@3524
   522
vb@3524
   523
    PEP_STATUS status = key_reset_trust(session, ident);
vb@3524
   524
    if (status)
vb@3524
   525
        return status;
vb@3524
   526
vb@3773
   527
    OCTET_STRING_fromBuf(&session->sync_state.keysync.key, "", 0);
vb@3524
   528
||
vb@3524
   529
vb@3518
   530
action tellWeAreGrouped
vb@3518
   531
||
vb@3773
   532
    session->sync_state.keysync.is_group = true;
vb@3518
   533
||
vb@3518
   534
vb@3518
   535
action tellWeAreNotGrouped
vb@3518
   536
||
vb@3773
   537
    session->sync_state.keysync.is_group = false;
vb@3518
   538
||
vb@3518
   539
vb@4053
   540
action disable
vb@4053
   541
||
vb@4053
   542
    leave_device_group(session);
vb@4053
   543
    // ignore the result, disable anyway
vb@4053
   544
vb@4053
   545
    if (!session->inject_sync_event)
vb@4053
   546
        return PEP_SYNC_NO_INJECT_CALLBACK;
vb@4053
   547
vb@4068
   548
    session->inject_sync_event((void *) SHUTDOWN, NULL);
vb@4053
   549
||