sync/cond_act_sync.yml2
author Volker Birk <vb@pep-project.org>
Mon, 09 Dec 2019 16:36:46 +0100
branchsync
changeset 4244 8d4faa88ddcf
parent 4243 37161269898d
child 4287 159969298292
permissions -rw-r--r--
...
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@3605
   111
vb@3605
   112
            assert(src->size == 16);
vb@3605
   113
            if (!(src->size == 16))
vb@3605
   114
                return PEP_UNKNOWN_ERROR;
vb@3605
   115
vb@3605
   116
            OCTET_STRING_fromBuf(dst, (char *) src->buf, src->size);
vb@3605
   117
        }
vb@3605
   118
    ||
vb@3605
   119
}
vb@2831
   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@2831
   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;
krista@4228
   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);
krista@4228
   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@3524
   321
action showDeviceAdded
vb@3524
   322
    call "show_handshake" with "type" > SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED
vb@3524
   323
vb@4167
   324
action showDeviceAccepted
vb@4167
   325
    call "show_handshake" with "type" > SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED
vb@4167
   326
vb@3524
   327
action showGroupCreated
vb@3524
   328
    call "show_handshake" with "type" > SYNC_NOTIFY_ACCEPTED_GROUP_CREATED
vb@3524
   329
vb@3525
   330
action showBeingSole
vb@3525
   331
    call "show_handshake" with "type" > SYNC_NOTIFY_SOLE
vb@3525
   332
vb@3525
   333
action showBeingInGroup
vb@3525
   334
    call "show_handshake" with "type" > SYNC_NOTIFY_IN_GROUP
vb@3525
   335
vb@2914
   336
timeout KeySync
vb@2913
   337
    call "show_handshake" with "type" > SYNC_NOTIFY_TIMEOUT
vb@2913
   338
vb@3390
   339
action prepareOwnKeys
vb@3390
   340
||
vb@3390
   341
    stringlist_t *own_keys;
krista@3583
   342
    PEP_STATUS status = _own_keys_retrieve(session, &own_keys, PEP_idf_not_for_sync, true);
vb@3390
   343
    if (status)
vb@3390
   344
        return status;
vb@3390
   345
vb@3772
   346
    if (session->sync_state.own.keys)
vb@3772
   347
        free_stringlist(session->sync_state.own.keys);
vb@3772
   348
    session->sync_state.own.keys = own_keys;
vb@3394
   349
vb@3394
   350
    identity_list *il;
vb@3394
   351
    status = _own_identities_retrieve(session, &il, PEP_idf_not_for_sync);
vb@3394
   352
    if (status)
vb@3394
   353
        return status;
vb@3394
   354
vb@3773
   355
    IdentityList_from_identity_list(il, &session->sync_state.keysync.ownIdentities);
vb@3609
   356
    free_identity_list(il);
vb@3390
   357
||
vb@3390
   358
vb@2831
   359
action saveGroupKeys
vb@2831
   360
||
vb@3790
   361
    char *user_id = NULL;
vb@3790
   362
    PEP_STATUS status = get_default_own_userid(session, &user_id);
vb@3790
   363
    if (status)
vb@3790
   364
        return status;
vb@3790
   365
vb@3773
   366
    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
vb@3794
   367
    if (!il) {
vb@3794
   368
        free(user_id);
vb@2831
   369
        return PEP_OUT_OF_MEMORY;
vb@3794
   370
    }
krista@4186
   371
    status = set_all_userids_to_own(session, il);
krista@4186
   372
    if (status != PEP_STATUS_OK) {
krista@4186
   373
        free(user_id);
krista@4186
   374
        return status;
krista@4186
   375
    }
krista@4228
   376
vb@3786
   377
    identity_list *oil = session->sync_state.own.identities;
vb@3786
   378
vb@2831
   379
    // BUG: this should be a transaction and been rolled back completely on error
vb@2831
   380
    for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
vb@3785
   381
        pEp_identity *ident = _il->ident;
vb@3785
   382
        bool is_own_already = false;
vb@3785
   383
vb@3790
   384
        status = is_own_address(session, ident->address, &is_own_already);
vb@3786
   385
        if (status) {
vb@3786
   386
            free_identity_list(il);
vb@3794
   387
            free(user_id);
vb@3786
   388
            return status;
vb@3786
   389
        }
vb@3786
   390
vb@3786
   391
        free(ident->user_id);
vb@3794
   392
        ident->user_id = strdup(user_id);
vb@3794
   393
        assert(ident->user_id);
vb@3794
   394
        if (!ident->user_id) {
vb@3794
   395
            free_identity_list(il);
vb@3794
   396
            free(user_id);
vb@3794
   397
            return PEP_OUT_OF_MEMORY;
vb@3794
   398
        }
vb@3786
   399
vb@3785
   400
        if (is_own_already) {
vb@3786
   401
            ident->comm_type = PEP_ct_pEp;
vb@3786
   402
            status = set_trust(session, ident);
vb@3785
   403
        }
vb@3785
   404
        else {
vb@3786
   405
            oil = identity_list_add(oil, ident);
vb@3786
   406
            if (!oil) {
vb@3786
   407
                free_identity_list(il);
vb@3794
   408
                free(user_id);
vb@3786
   409
                return PEP_OUT_OF_MEMORY;
vb@3786
   410
            }
vb@3785
   411
            status = myself(session, ident);
vb@3785
   412
        }
vb@2831
   413
        if (status) {
vb@2831
   414
            free_identity_list(il);
vb@3794
   415
            free(user_id);
vb@2831
   416
            return status;
vb@2831
   417
        }
vb@2831
   418
    }
vb@2831
   419
vb@3794
   420
    free(user_id);
krista@4228
   421
    // NO! This contains the references we add above and belongs to
krista@4228
   422
    // session->sync_state.own.identities!
krista@4228
   423
    // free_identity_list(il);
vb@2831
   424
||
vb@2831
   425
vb@3815
   426
action ownKeysAreDefaultKeys
vb@3434
   427
||
vb@3434
   428
    PEP_STATUS status = PEP_STATUS_OK;
vb@2831
   429
vb@3786
   430
    // set flag for all keys; don't change anything else
vb@3772
   431
    for (identity_list *il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
vb@3434
   432
        if (!(il->ident->flags && PEP_idf_not_for_sync)) {
vb@3434
   433
            status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
vb@3434
   434
            if (status)
vb@3434
   435
                return status;
vb@3434
   436
        }
vb@3434
   437
    }
vb@3434
   438
||
vb@2831
   439
vb@3815
   440
action receivedKeysAreDefaultKeys
vb@3525
   441
||
vb@3525
   442
    PEP_STATUS status = PEP_STATUS_OK;
vb@3786
   443
    // set flag for all keys
vb@3772
   444
    for (identity_list *il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
vb@3527
   445
        if (!(il->ident->flags && PEP_idf_not_for_sync)) {
krista@4228
   446
vb@3527
   447
            status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
vb@3527
   448
            if (status)
vb@3527
   449
                return status;
vb@3527
   450
        }
vb@3527
   451
    }
vb@3527
   452
vb@3786
   453
    char *user_id = NULL;
vb@3786
   454
    status = get_default_own_userid(session, &user_id);
vb@3786
   455
    if (status)
vb@3786
   456
        return status;
vb@3786
   457
vb@3773
   458
    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
vb@3525
   459
    if (!il)
vb@3525
   460
        return PEP_OUT_OF_MEMORY;
vb@3525
   461
krista@4186
   462
    status = set_all_userids_to_own(session, il);
krista@4186
   463
    if (status != PEP_STATUS_OK) {
krista@4186
   464
        free(user_id);
krista@4186
   465
        return status;
krista@4186
   466
    }
krista@4186
   467
vb@3786
   468
    for (identity_list *_il = il; _il && _il->ident ; _il = _il->next) {
vb@3525
   469
        // replace partner's user_id with own user_id
vb@3786
   470
        free(_il->ident->user_id);
vb@3786
   471
        _il->ident->user_id = strdup(user_id);
vb@3786
   472
        assert(_il->ident->user_id);
vb@3786
   473
        if (!_il->ident->user_id) {
vb@3525
   474
            free_identity_list(il);
vb@3786
   475
            free(user_id);
vb@3525
   476
            return PEP_OUT_OF_MEMORY;
vb@3525
   477
        }
krista@4228
   478
vb@3786
   479
        const char *own_key = _il->ident->fpr;
vb@3786
   480
        _il->ident->fpr = NULL;
vb@3786
   481
        status = set_own_key(session, _il->ident, own_key);
vb@3525
   482
        if (status) {
vb@3525
   483
            free_identity_list(il);
vb@3786
   484
            free(user_id);
vb@3525
   485
            return status;
vb@3525
   486
        }
vb@3525
   487
    }
vb@3525
   488
vb@3525
   489
    free_identity_list(il);
vb@3786
   490
    free(user_id);
vb@3525
   491
||
vb@3406
   492
vb@4132
   493
action useThisKey
vb@4132
   494
||
vb@4132
   495
    assert(session->sync_state.comm_partner.sender_fpr);
vb@4132
   496
    if (!session->sync_state.comm_partner.sender_fpr)
vb@4132
   497
        return PEP_ILLEGAL_VALUE;
vb@4132
   498
vb@4132
   499
    const char *fpr = session->sync_state.comm_partner.sender_fpr;
vb@4132
   500
    OCTET_STRING_fromBuf(&session->sync_state.keysync.key, fpr, strlen(fpr));
vb@4132
   501
||
vb@4132
   502
vb@4132
   503
action storeThisKey
vb@4132
   504
||
vb@4141
   505
    assert(session->sync_state.keysync.key.size);
vb@4141
   506
    if (!session->sync_state.keysync.key.size)
vb@4132
   507
        return PEP_ILLEGAL_VALUE;
vb@4132
   508
vb@4166
   509
    char *fpr = strndup((const char *) session->sync_state.keysync.key.buf, session->sync_state.keysync.key.size);
vb@4132
   510
    assert(fpr);
vb@4132
   511
    if (!fpr)
vb@4132
   512
        return PEP_OUT_OF_MEMORY;
vb@4132
   513
vb@4132
   514
    free(session->sync_state.comm_partner.sender_fpr);
vb@4132
   515
    session->sync_state.comm_partner.sender_fpr = fpr;
vb@4132
   516
||
vb@4132
   517
vb@3516
   518
action trustThisKey
vb@3516
   519
||
vb@3779
   520
    assert(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr);
vb@3779
   521
    if (!(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr))
vb@3516
   522
        return PEP_ILLEGAL_VALUE;
vb@3516
   523
vb@3779
   524
    pEp_identity *ident = identity_dup(session->sync_state.transport.from);
vb@3754
   525
    if (!ident)
vb@3754
   526
        return PEP_OUT_OF_MEMORY;
vb@3516
   527
    free(ident->fpr);
vb@3779
   528
    ident->fpr = strdup(session->sync_state.comm_partner.sender_fpr);
vb@3516
   529
    assert(ident->fpr);
vb@3754
   530
    if (!ident->fpr) {
vb@3754
   531
        free_identity(ident);
vb@3516
   532
        return PEP_OUT_OF_MEMORY;
vb@3754
   533
    }
vb@3516
   534
vb@3516
   535
    PEP_STATUS status = trust_own_key(session, ident);
vb@3754
   536
    if (status) {
vb@3754
   537
        free_identity(ident);
vb@3516
   538
        return status;
vb@3754
   539
    }
vb@3523
   540
vb@3773
   541
    OCTET_STRING_fromBuf(&session->sync_state.keysync.key, ident->fpr, strlen(ident->fpr));
vb@3754
   542
    free_identity(ident);
vb@3516
   543
||
vb@3516
   544
vb@3524
   545
action untrustThisKey
vb@3524
   546
||
vb@3779
   547
    assert(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr);
vb@3779
   548
    if (!(session->sync_state.transport.from && session->sync_state.comm_partner.sender_fpr))
vb@3524
   549
        return PEP_ILLEGAL_VALUE;
vb@3524
   550
vb@3779
   551
    pEp_identity *ident = session->sync_state.transport.from;
vb@3524
   552
    free(ident->fpr);
vb@3779
   553
    ident->fpr = strdup(session->sync_state.comm_partner.sender_fpr);
vb@3524
   554
    assert(ident->fpr);
vb@3524
   555
    if (!ident->fpr)
vb@3524
   556
        return PEP_OUT_OF_MEMORY;
vb@3524
   557
vb@3524
   558
    PEP_STATUS status = key_reset_trust(session, ident);
vb@3524
   559
    if (status)
vb@3524
   560
        return status;
vb@3524
   561
vb@3773
   562
    OCTET_STRING_fromBuf(&session->sync_state.keysync.key, "", 0);
vb@3524
   563
||
vb@3524
   564
vb@3518
   565
action tellWeAreGrouped
vb@3518
   566
||
vb@3773
   567
    session->sync_state.keysync.is_group = true;
vb@3518
   568
||
vb@3518
   569
vb@3518
   570
action tellWeAreNotGrouped
vb@3518
   571
||
vb@3773
   572
    session->sync_state.keysync.is_group = false;
vb@3518
   573
||
vb@3518
   574
vb@4053
   575
action disable
vb@4053
   576
||
krista@4243
   577
    disable_sync(session);
vb@4240
   578
||