src/keymanagement.c
author Edouard Tisserant <edouard@pep-project.org>
Sat, 12 Nov 2016 00:24:14 +0100
changeset 1385 5f54184b1e94
parent 1381 f84211f27e5b
child 1394 8659157b681f
permissions -rw-r--r--
No more _update_indentiy() and with_myself parameter. Rather, added a _myself(), with a do_keygen parameter. Now, only explicit call to myself(), key_mistrusted(), encrypt_message(), encrypt_message_to_self() may trigger keygen, not outgoing_message_rating() or update_identity()
vb@130
     1
#include "platform.h"
vb@0
     2
vb@0
     3
#include <string.h>
vb@0
     4
#include <stdio.h>
vb@0
     5
#include <stdlib.h>
vb@0
     6
#include <assert.h>
Edouard@512
     7
#include <ctype.h>
vb@0
     8
vb@217
     9
#include "pEp_internal.h"
vb@0
    10
#include "keymanagement.h"
vb@0
    11
edouard@1195
    12
#include "sync_fsm.h"
krista@1253
    13
#include "blacklist.h"
edouard@1195
    14
Edouard@439
    15
#ifndef EMPTYSTR
roker@500
    16
#define EMPTYSTR(STR) ((STR) == NULL || (STR)[0] == '\0')
vb@8
    17
#endif
vb@8
    18
vb@214
    19
#define KEY_EXPIRE_DELTA (60 * 60 * 24 * 365)
vb@214
    20
Edouard@774
    21
PEP_STATUS elect_pubkey(
Edouard@755
    22
        PEP_SESSION session, pEp_identity * identity
Edouard@755
    23
    )
Edouard@755
    24
{
Edouard@755
    25
    PEP_STATUS status;
Edouard@755
    26
    stringlist_t *keylist;
krista@1342
    27
    char *_fpr = "";
Edouard@755
    28
    identity->comm_type = PEP_ct_unknown;
Edouard@755
    29
Edouard@755
    30
    status = find_keys(session, identity->address, &keylist);
Edouard@755
    31
    assert(status != PEP_OUT_OF_MEMORY);
Edouard@755
    32
    if (status == PEP_OUT_OF_MEMORY)
Edouard@755
    33
        return PEP_OUT_OF_MEMORY;
Edouard@755
    34
Edouard@755
    35
    stringlist_t *_keylist;
Edouard@755
    36
    for (_keylist = keylist; _keylist && _keylist->value; _keylist = _keylist->next) {
Edouard@755
    37
        PEP_comm_type _comm_type_key;
Edouard@755
    38
Edouard@755
    39
        status = get_key_rating(session, _keylist->value, &_comm_type_key);
Edouard@755
    40
        assert(status != PEP_OUT_OF_MEMORY);
Edouard@755
    41
        if (status == PEP_OUT_OF_MEMORY) {
Edouard@755
    42
            free_stringlist(keylist);
Edouard@755
    43
            return PEP_OUT_OF_MEMORY;
Edouard@755
    44
        }
Edouard@755
    45
Edouard@755
    46
        if (_comm_type_key != PEP_ct_compromized &&
Edouard@755
    47
            _comm_type_key != PEP_ct_unknown)
Edouard@755
    48
        {
Edouard@755
    49
            if (identity->comm_type == PEP_ct_unknown ||
Edouard@755
    50
                _comm_type_key > identity->comm_type)
Edouard@755
    51
            {
krista@1275
    52
                bool blacklisted;
krista@1275
    53
                status = blacklist_is_listed(session, _keylist->value, &blacklisted);
krista@1275
    54
                if (status == PEP_STATUS_OK && !blacklisted) {
krista@1275
    55
                    identity->comm_type = _comm_type_key;
krista@1275
    56
                    _fpr = _keylist->value;
krista@1275
    57
                }
Edouard@755
    58
            }
Edouard@755
    59
        }
Edouard@755
    60
    }
Edouard@755
    61
krista@1342
    62
    
krista@1342
    63
//    if (_fpr) {
krista@1342
    64
    free(identity->fpr);
Edouard@755
    65
krista@1342
    66
    identity->fpr = strdup(_fpr);
krista@1342
    67
    if (identity->fpr == NULL) {
krista@1342
    68
        free_stringlist(keylist);
krista@1342
    69
        return PEP_OUT_OF_MEMORY;
Edouard@755
    70
    }
krista@1342
    71
//    }
Edouard@755
    72
    free_stringlist(keylist);
Edouard@755
    73
    return PEP_STATUS_OK;
Edouard@755
    74
}
Edouard@755
    75
edouard@1385
    76
PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen);
edouard@1385
    77
edouard@1385
    78
DYNAMIC_API PEP_STATUS update_identity(
edouard@1385
    79
        PEP_SESSION session, pEp_identity * identity
vb@0
    80
    )
vb@0
    81
{
vb@0
    82
    pEp_identity *stored_identity;
krista@1224
    83
    pEp_identity* temp_id = NULL;
vb@0
    84
    PEP_STATUS status;
vb@0
    85
vb@0
    86
    assert(session);
vb@0
    87
    assert(identity);
Edouard@439
    88
    assert(!EMPTYSTR(identity->address));
vb@0
    89
Edouard@439
    90
    if (!(session && identity && !EMPTYSTR(identity->address)))
vb@191
    91
        return PEP_ILLEGAL_VALUE;
vb@191
    92
vb@1078
    93
    if (identity->me || (identity->user_id && strcmp(identity->user_id, PEP_OWN_USERID) == 0)) {
edouard@1385
    94
        identity->me = true;
edouard@1385
    95
        return _myself(session, identity, false);
vb@1078
    96
    }
vb@1078
    97
Edouard@559
    98
    int _no_user_id = EMPTYSTR(identity->user_id);
edouard@1164
    99
    int _did_elect_new_key = 0;
Edouard@559
   100
Edouard@559
   101
    if (_no_user_id)
Edouard@559
   102
    {
vb@1015
   103
        status = get_identity(session, identity->address, PEP_OWN_USERID,
vb@1015
   104
                &stored_identity);
vb@1015
   105
        if (status == PEP_STATUS_OK) {
vb@1015
   106
            free_identity(stored_identity);
edouard@1385
   107
            return _myself(session, identity, false);
vb@1015
   108
        }
vb@1015
   109
Edouard@559
   110
        free(identity->user_id);
Edouard@559
   111
vb@591
   112
        identity->user_id = calloc(1, strlen(identity->address) + 6);
Edouard@562
   113
        if (!identity->user_id)
Edouard@562
   114
        {
Edouard@562
   115
            return PEP_OUT_OF_MEMORY;
Edouard@562
   116
        }
vb@983
   117
        snprintf(identity->user_id, strlen(identity->address) + 6,
Edouard@562
   118
                 "TOFU_%s", identity->address);
Edouard@559
   119
    }
vb@934
   120
 
Edouard@559
   121
    status = get_identity(session,
Edouard@559
   122
                          identity->address,
Edouard@559
   123
                          identity->user_id,
Edouard@559
   124
                          &stored_identity);
Edouard@559
   125
    
vb@0
   126
    assert(status != PEP_OUT_OF_MEMORY);
vb@0
   127
    if (status == PEP_OUT_OF_MEMORY)
Edouard@829
   128
        goto exit_free;
vb@0
   129
krista@1188
   130
    /* We elect a pubkey first in case there's no acceptable stored fpr */
krista@1224
   131
    temp_id = identity_dup(identity);
krista@1220
   132
    
krista@1220
   133
    status = elect_pubkey(session, temp_id);
krista@1185
   134
    if (status != PEP_STATUS_OK)
krista@1185
   135
        goto exit_free;
krista@1188
   136
        
vb@14
   137
    if (stored_identity) {
vb@14
   138
        PEP_comm_type _comm_type_key;
krista@1188
   139
        
krista@1255
   140
        bool dont_use_fpr = true;
krista@1220
   141
krista@1220
   142
        /* if we have a stored_identity fpr */
krista@1342
   143
        if (!EMPTYSTR(stored_identity->fpr) && !EMPTYSTR(temp_id->fpr)) {
krista@1220
   144
            status = blacklist_is_listed(session, stored_identity->fpr, &dont_use_fpr);
krista@1220
   145
            if (status != PEP_STATUS_OK)
krista@1220
   146
                dont_use_fpr = true; 
krista@1220
   147
        }
krista@1188
   148
            
krista@1220
   149
krista@1220
   150
        if (!dont_use_fpr) {
krista@1220
   151
            free(temp_id->fpr);
krista@1220
   152
            temp_id->fpr = strdup(stored_identity->fpr);
krista@1220
   153
            assert(temp_id->fpr);
krista@1220
   154
            if (temp_id->fpr == NULL) {
krista@1220
   155
                status = PEP_OUT_OF_MEMORY;
krista@1188
   156
                goto exit_free;
krista@1220
   157
            }
krista@1220
   158
        }
krista@1220
   159
        else if (!EMPTYSTR(temp_id->fpr)) {
krista@1220
   160
            status = blacklist_is_listed(session, temp_id->fpr, &dont_use_fpr);
krista@1188
   161
            if (dont_use_fpr) {
krista@1220
   162
                free(temp_id->fpr);
krista@1220
   163
                temp_id->fpr = strdup("");
krista@1188
   164
            }
krista@1188
   165
            else {
krista@1188
   166
                _did_elect_new_key = 1;
krista@1188
   167
            }
krista@1188
   168
        }
krista@1188
   169
        else {
krista@1220
   170
            if (temp_id->fpr == NULL)
krista@1220
   171
                temp_id->fpr = strdup("");
krista@1188
   172
        }
krista@1188
   173
        
krista@1220
   174
        /* ok, from here on out, use temp_id */
krista@1220
   175
        
krista@1220
   176
        
krista@1220
   177
        /* At this point, we either have a non-blacklisted fpr we can work */
krista@1220
   178
        /* with, or we've got nada.                                        */        
krista@1220
   179
        if (!EMPTYSTR(temp_id->fpr)) {
krista@1220
   180
            status = get_key_rating(session, temp_id->fpr, &_comm_type_key);
krista@1188
   181
            assert(status != PEP_OUT_OF_MEMORY);
krista@1188
   182
            if (status == PEP_OUT_OF_MEMORY)
krista@1188
   183
                goto exit_free;
krista@1188
   184
            if (_comm_type_key < PEP_ct_unconfirmed_encryption) {
krista@1220
   185
                temp_id->comm_type = _comm_type_key;
krista@1188
   186
            } else{
krista@1220
   187
                temp_id->comm_type = stored_identity->comm_type;
krista@1220
   188
                if (temp_id->comm_type == PEP_ct_unknown) {
krista@1220
   189
                    temp_id->comm_type = _comm_type_key;
krista@1188
   190
                }
krista@1188
   191
            }
krista@1188
   192
        }
krista@1243
   193
        else {
krista@1243
   194
            /* Set comm_type accordingly */
krista@1243
   195
            temp_id->comm_type = PEP_ct_key_not_found;
krista@1243
   196
        }
krista@1243
   197
        
krista@1220
   198
        if (EMPTYSTR(temp_id->username)) {
krista@1220
   199
            free(temp_id->username);
krista@1220
   200
            temp_id->username = strdup(stored_identity->username);
krista@1220
   201
            assert(temp_id->username);
krista@1220
   202
            if (temp_id->username == NULL){
Edouard@829
   203
                status = PEP_OUT_OF_MEMORY;
Edouard@829
   204
                goto exit_free;
Edouard@829
   205
            }
vb@22
   206
        }
vb@22
   207
krista@1220
   208
        if (temp_id->lang[0] == 0) {
krista@1220
   209
            temp_id->lang[0] = stored_identity->lang[0];
krista@1220
   210
            temp_id->lang[1] = stored_identity->lang[1];
krista@1220
   211
            temp_id->lang[2] = 0;
vb@21
   212
        }
vb@932
   213
krista@1220
   214
        temp_id->flags = stored_identity->flags;
vb@21
   215
    }
vb@21
   216
    else /* stored_identity == NULL */ {
krista@1220
   217
        temp_id->flags = 0;
vb@934
   218
krista@1188
   219
        /* Work with the elected key from above */
krista@1220
   220
        if (!EMPTYSTR(temp_id->fpr)) {
krista@1196
   221
            
krista@1196
   222
            bool dont_use_fpr = true;
krista@1220
   223
            status = blacklist_is_listed(session, temp_id->fpr, &dont_use_fpr);
krista@1196
   224
            if (status != PEP_STATUS_OK)
krista@1196
   225
                dont_use_fpr = true; 
vb@21
   226
krista@1196
   227
            if (!dont_use_fpr) {
krista@1196
   228
                PEP_comm_type _comm_type_key;
vb@21
   229
krista@1220
   230
                status = get_key_rating(session, temp_id->fpr, &_comm_type_key);
krista@1196
   231
                assert(status != PEP_OUT_OF_MEMORY);
krista@1196
   232
                if (status == PEP_OUT_OF_MEMORY)
krista@1196
   233
                    goto exit_free;
krista@1196
   234
krista@1220
   235
                temp_id->comm_type = _comm_type_key;
krista@1196
   236
            }
krista@1196
   237
            else {
krista@1220
   238
                free(temp_id->fpr);
krista@1220
   239
                temp_id->fpr = strdup("");
krista@1196
   240
            }
vb@21
   241
        }
vb@21
   242
    }
vb@21
   243
krista@1220
   244
    if (temp_id->fpr == NULL)
krista@1220
   245
        temp_id->fpr = strdup("");
krista@1193
   246
    
krista@1193
   247
    
vb@21
   248
    status = PEP_STATUS_OK;
vb@21
   249
krista@1220
   250
    if (temp_id->comm_type != PEP_ct_unknown && !EMPTYSTR(temp_id->user_id)) {
krista@1220
   251
        assert(!EMPTYSTR(temp_id->username)); // this should not happen
vb@22
   252
krista@1220
   253
        if (EMPTYSTR(temp_id->username)) { // mitigate
krista@1220
   254
            free(temp_id->username);
krista@1220
   255
            temp_id->username = strdup("anonymous");
krista@1220
   256
            assert(temp_id->username);
krista@1220
   257
            if (temp_id->username == NULL){
Edouard@829
   258
                status = PEP_OUT_OF_MEMORY;
Edouard@829
   259
                goto exit_free;
Edouard@829
   260
            }
vb@0
   261
        }
vb@8
   262
Edouard@755
   263
        // Identity doesn't get stored if call was just about checking existing
Edouard@755
   264
        // user by address (i.e. no user id given but already stored)
krista@1223
   265
        if (!(_no_user_id && stored_identity) || _did_elect_new_key)
Edouard@559
   266
        {
krista@1220
   267
            status = set_identity(session, temp_id);
Edouard@559
   268
            assert(status == PEP_STATUS_OK);
Edouard@559
   269
            if (status != PEP_STATUS_OK) {
Edouard@829
   270
                goto exit_free;
Edouard@559
   271
            }
Edouard@499
   272
        }
vb@8
   273
    }
vb@8
   274
krista@1220
   275
    if (temp_id->comm_type != PEP_ct_compromized &&
krista@1220
   276
            temp_id->comm_type < PEP_ct_strong_but_unconfirmed)
vb@297
   277
        if (session->examine_identity)
krista@1220
   278
            session->examine_identity(temp_id, session->examine_management);
krista@1220
   279
    
krista@1220
   280
    /* ok, we got to the end. So we can assign the output identity */
krista@1220
   281
    free(identity->address);
krista@1220
   282
    identity->address = strdup(temp_id->address);
krista@1220
   283
    free(identity->fpr);
krista@1220
   284
    identity->fpr = strdup(temp_id->fpr);
krista@1220
   285
    free(identity->user_id);
krista@1220
   286
    identity->user_id = strdup(temp_id->user_id);
krista@1220
   287
    free(identity->username);
krista@1220
   288
    identity->username = strdup(temp_id->username);
krista@1220
   289
    identity->comm_type = temp_id->comm_type;
krista@1220
   290
    identity->lang[0] = temp_id->lang[0];
krista@1220
   291
    identity->lang[1] = temp_id->lang[1];
krista@1220
   292
    identity->lang[2] = 0;
krista@1220
   293
    identity->me = temp_id->me;
krista@1220
   294
    identity->flags = temp_id->flags;
vb@297
   295
Edouard@829
   296
exit_free :
Edouard@829
   297
    
Edouard@829
   298
    if (stored_identity){
Edouard@829
   299
        free_identity(stored_identity);
Edouard@829
   300
    }
Edouard@829
   301
krista@1220
   302
    if (temp_id)
krista@1220
   303
        free_identity(temp_id);
krista@1220
   304
    
vb@8
   305
    return status;
vb@0
   306
}
vb@0
   307
Edouard@774
   308
PEP_STATUS elect_ownkey(
krista@1194
   309
        PEP_SESSION session, pEp_identity * identity
Edouard@774
   310
    )
Edouard@774
   311
{
Edouard@774
   312
    PEP_STATUS status;
Edouard@774
   313
    stringlist_t *keylist = NULL;
Edouard@774
   314
Edouard@774
   315
    free(identity->fpr);
Edouard@774
   316
    identity->fpr = NULL;
Edouard@774
   317
krista@1357
   318
    status = find_private_keys(session, identity->address, &keylist);
Edouard@774
   319
    assert(status != PEP_OUT_OF_MEMORY);
Edouard@774
   320
    if (status == PEP_OUT_OF_MEMORY)
Edouard@774
   321
        return PEP_OUT_OF_MEMORY;
Edouard@774
   322
    
Edouard@774
   323
    if (keylist != NULL && keylist->value != NULL)
Edouard@774
   324
    {
Edouard@774
   325
        char *_fpr = NULL;
Edouard@774
   326
        identity->comm_type = PEP_ct_unknown;
Edouard@774
   327
Edouard@774
   328
        stringlist_t *_keylist;
Edouard@774
   329
        for (_keylist = keylist; _keylist && _keylist->value; _keylist = _keylist->next) {
Edouard@774
   330
            bool is_own = false;
Edouard@774
   331
            
Edouard@774
   332
            if (session->use_only_own_private_keys)
Edouard@774
   333
            {
Edouard@774
   334
                status = own_key_is_listed(session, _keylist->value, &is_own);
Edouard@774
   335
                assert(status == PEP_STATUS_OK);
Edouard@774
   336
                if (status != PEP_STATUS_OK) {
Edouard@774
   337
                    free_stringlist(keylist);
Edouard@774
   338
                    return status;
Edouard@774
   339
                }
Edouard@774
   340
            }
Edouard@774
   341
Edouard@774
   342
            // TODO : also accept synchronized device group keys ?
Edouard@774
   343
            
Edouard@774
   344
            if (!session->use_only_own_private_keys || is_own)
Edouard@774
   345
            {
Edouard@774
   346
                PEP_comm_type _comm_type_key;
Edouard@774
   347
                
Edouard@774
   348
                status = get_key_rating(session, _keylist->value, &_comm_type_key);
Edouard@774
   349
                assert(status != PEP_OUT_OF_MEMORY);
Edouard@774
   350
                if (status == PEP_OUT_OF_MEMORY) {
Edouard@774
   351
                    free_stringlist(keylist);
Edouard@774
   352
                    return PEP_OUT_OF_MEMORY;
Edouard@774
   353
                }
Edouard@774
   354
                
Edouard@774
   355
                if (_comm_type_key != PEP_ct_compromized &&
Edouard@774
   356
                    _comm_type_key != PEP_ct_unknown)
Edouard@774
   357
                {
Edouard@774
   358
                    if (identity->comm_type == PEP_ct_unknown ||
Edouard@774
   359
                        _comm_type_key > identity->comm_type)
Edouard@774
   360
                    {
Edouard@774
   361
                        identity->comm_type = _comm_type_key;
Edouard@774
   362
                        _fpr = _keylist->value;
Edouard@774
   363
                    }
Edouard@774
   364
                }
Edouard@774
   365
            }
Edouard@774
   366
        }
Edouard@774
   367
        
Edouard@774
   368
        if (_fpr)
Edouard@774
   369
        {
Edouard@774
   370
            identity->fpr = strdup(_fpr);
Edouard@774
   371
            assert(identity->fpr);
Edouard@774
   372
            if (identity->fpr == NULL)
Edouard@774
   373
            {
Edouard@774
   374
                free_stringlist(keylist);
Edouard@774
   375
                return PEP_OUT_OF_MEMORY;
Edouard@774
   376
            }
Edouard@774
   377
        }
Edouard@774
   378
        free_stringlist(keylist);
Edouard@774
   379
    }
Edouard@774
   380
    return PEP_STATUS_OK;
Edouard@774
   381
}
Edouard@774
   382
krista@1357
   383
PEP_STATUS _has_usable_priv_key(PEP_SESSION session, char* fpr,
krista@1357
   384
                                bool* is_usable) {
krista@1357
   385
    
krista@1357
   386
    bool dont_use_fpr = true;
krista@1357
   387
    
krista@1357
   388
    PEP_STATUS status = blacklist_is_listed(session, fpr, &dont_use_fpr);
krista@1371
   389
    if (status == PEP_STATUS_OK && !dont_use_fpr) {
krista@1357
   390
        // Make sure there is a *private* key associated with this fpr
krista@1357
   391
        bool has_private = false;
krista@1357
   392
        status = contains_priv_key(session, fpr, &has_private);
krista@1371
   393
krista@1371
   394
        if (status == PEP_STATUS_OK)
krista@1371
   395
            dont_use_fpr = !has_private;
krista@1357
   396
    }
krista@1357
   397
    
krista@1357
   398
    *is_usable = !dont_use_fpr;
krista@1357
   399
    
krista@1357
   400
    return status;
krista@1357
   401
}
krista@1357
   402
edouard@1385
   403
PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen)
vb@0
   404
{
Edouard@560
   405
    pEp_identity *stored_identity;
vb@0
   406
    PEP_STATUS status;
vb@0
   407
vb@0
   408
    assert(session);
vb@0
   409
    assert(identity);
vb@1044
   410
    assert(!EMPTYSTR(identity->address));
vb@1043
   411
Edouard@658
   412
    assert(EMPTYSTR(identity->user_id) ||
Edouard@658
   413
           strcmp(identity->user_id, PEP_OWN_USERID) == 0);
vb@0
   414
vb@1044
   415
    if (!(session && identity && !EMPTYSTR(identity->address) &&
vb@1043
   416
            (EMPTYSTR(identity->user_id) ||
vb@1043
   417
            strcmp(identity->user_id, PEP_OWN_USERID) == 0)))
vb@191
   418
        return PEP_ILLEGAL_VALUE;
vb@191
   419
vb@0
   420
    identity->comm_type = PEP_ct_pEp;
vb@0
   421
    identity->me = true;
Edouard@658
   422
    
vb@1043
   423
    if (EMPTYSTR(identity->user_id))
Edouard@658
   424
    {
Edouard@658
   425
        free(identity->user_id);
Edouard@658
   426
        identity->user_id = strdup(PEP_OWN_USERID);
Edouard@658
   427
        assert(identity->user_id);
Edouard@658
   428
        if (identity->user_id == NULL)
Edouard@658
   429
            return PEP_OUT_OF_MEMORY;
Edouard@658
   430
    }
vb@0
   431
vb@215
   432
    DEBUG_LOG("myself", "debug", identity->address);
vb@1044
   433
 
Edouard@560
   434
    status = get_identity(session,
Edouard@560
   435
                          identity->address,
Edouard@560
   436
                          identity->user_id,
Edouard@560
   437
                          &stored_identity);
Edouard@560
   438
    
vb@0
   439
    assert(status != PEP_OUT_OF_MEMORY);
vb@0
   440
    if (status == PEP_OUT_OF_MEMORY)
vb@0
   441
        return PEP_OUT_OF_MEMORY;
krista@1357
   442
krista@1357
   443
    bool dont_use_stored_fpr = true;
krista@1357
   444
    bool dont_use_input_fpr = true;
krista@1359
   445
        
Edouard@560
   446
    if (stored_identity)
Edouard@560
   447
    {
Edouard@560
   448
        if (EMPTYSTR(identity->fpr)) {
krista@1352
   449
            
krista@1357
   450
            bool has_private = false;
krista@1352
   451
            
krista@1357
   452
            status = _has_usable_priv_key(session, stored_identity->fpr, &has_private); 
krista@1352
   453
            
krista@1371
   454
            // N.B. has_private is never true if the returned status is not PEP_STATUS_OK
krista@1357
   455
            if (has_private) {
krista@1357
   456
                identity->fpr = strdup(stored_identity->fpr);
krista@1357
   457
                assert(identity->fpr);
krista@1357
   458
                if (identity->fpr == NULL)
krista@1357
   459
                {
krista@1357
   460
                    return PEP_OUT_OF_MEMORY;
krista@1357
   461
                }
krista@1357
   462
                dont_use_stored_fpr = false;
Edouard@560
   463
            }
Edouard@560
   464
        }
krista@1357
   465
        
vb@932
   466
        identity->flags = stored_identity->flags;
edouard@1367
   467
edouard@1367
   468
        free_identity(stored_identity);
Edouard@588
   469
    }
krista@1357
   470
    
krista@1357
   471
    if (dont_use_stored_fpr && !EMPTYSTR(identity->fpr))
Edouard@588
   472
    {
Edouard@588
   473
        // App must have a good reason to give fpr, such as explicit
Edouard@588
   474
        // import of private key, or similar.
Edouard@588
   475
Edouard@658
   476
        // Take given fpr as-is.
vb@934
   477
krista@1357
   478
        // BUT:
krista@1357
   479
        // First check to see if it's blacklisted or private part is missing?
krista@1357
   480
        bool has_private = false;
krista@1357
   481
        
krista@1357
   482
        status = _has_usable_priv_key(session, identity->fpr, &has_private); 
krista@1357
   483
        
krista@1371
   484
        // N.B. has_private is never true if the returned status is not PEP_STATUS_OK
krista@1357
   485
        if (has_private) {
krista@1357
   486
            identity->flags = 0;
krista@1357
   487
            dont_use_input_fpr = false;
krista@1357
   488
        }
Edouard@560
   489
    }
krista@1357
   490
    
krista@1357
   491
    // Ok, we failed to get keys either way, so let's elect one.
krista@1357
   492
    if (dont_use_input_fpr && dont_use_stored_fpr)
Edouard@560
   493
    {
Edouard@774
   494
        status = elect_ownkey(session, identity);
Edouard@774
   495
        assert(status == PEP_STATUS_OK);
Edouard@774
   496
        if (status != PEP_STATUS_OK) {
Edouard@774
   497
            return status;
Edouard@560
   498
        }
vb@934
   499
krista@1357
   500
        bool has_private = false;
krista@1359
   501
        if (identity->fpr) {
krista@1359
   502
            // ok, we elected something.
krista@1359
   503
            // elect_ownkey only returns private keys, so we don't check again.
krista@1359
   504
            // Check to see if it's blacklisted
krista@1359
   505
            bool listed;
krista@1359
   506
            status = blacklist_is_listed(session, identity->fpr, &listed); 
krista@1371
   507
krista@1371
   508
            if (status == PEP_STATUS_OK)
krista@1371
   509
                has_private = !listed;
krista@1359
   510
        }
krista@1357
   511
        
krista@1357
   512
        if (has_private) {
krista@1357
   513
            identity->flags = 0;
krista@1357
   514
            dont_use_input_fpr = false;
krista@1357
   515
        }
krista@1357
   516
        else { // OK, we've tried everything. Time to generate new keys.
krista@1359
   517
            free(identity->fpr); // It can stay in this state (unallocated) because we'll generate a new key 
krista@1359
   518
            identity->fpr = NULL;
krista@1357
   519
        }
Edouard@560
   520
    }
Edouard@695
   521
Edouard@695
   522
    bool revoked = false;
Edouard@695
   523
    char *r_fpr = NULL;
Edouard@695
   524
    if (!EMPTYSTR(identity->fpr))
Edouard@695
   525
    {
Edouard@695
   526
        status = key_revoked(session, identity->fpr, &revoked);
Edouard@775
   527
Edouard@775
   528
        // Forces re-election if key is missing and own-key-only not forced
Edouard@775
   529
        if (!session->use_only_own_private_keys && status == PEP_KEY_NOT_FOUND) 
Edouard@775
   530
        {
Edouard@775
   531
            status = elect_ownkey(session, identity);
Edouard@775
   532
            assert(status == PEP_STATUS_OK);
Edouard@775
   533
            if (status != PEP_STATUS_OK) {
Edouard@775
   534
                return status;
Edouard@775
   535
            }
Edouard@775
   536
        } 
Edouard@775
   537
        else if (status != PEP_STATUS_OK) 
Edouard@775
   538
        {
Edouard@695
   539
            return status;
Edouard@695
   540
        }
Edouard@695
   541
    }
edouard@1140
   542
   
edouard@1140
   543
    bool new_key_generated = false;
edouard@1140
   544
Edouard@695
   545
    if (EMPTYSTR(identity->fpr) || revoked)
Edouard@695
   546
    {        
edouard@1385
   547
        if(!do_keygen){
edouard@1385
   548
            return PEP_GET_KEY_FAILED;
edouard@1385
   549
        }
edouard@1385
   550
Edouard@695
   551
        if(revoked)
Edouard@695
   552
        {
Edouard@697
   553
            r_fpr = identity->fpr;
Edouard@697
   554
            identity->fpr = NULL;
Edouard@695
   555
        }
Edouard@560
   556
        
vb@215
   557
        DEBUG_LOG("generating key pair", "debug", identity->address);
vb@0
   558
        status = generate_keypair(session, identity);
vb@0
   559
        assert(status != PEP_OUT_OF_MEMORY);
vb@0
   560
        if (status != PEP_STATUS_OK) {
vb@0
   561
            char buf[11];
vb@0
   562
            snprintf(buf, 11, "%d", status);
vb@215
   563
            DEBUG_LOG("generating key pair failed", "debug", buf);
Edouard@695
   564
            if(revoked && r_fpr)
Edouard@695
   565
                free(r_fpr);
vb@0
   566
            return status;
vb@0
   567
        }
edouard@1140
   568
edouard@1140
   569
        new_key_generated = true;
Edouard@560
   570
        
Edouard@695
   571
        if(revoked)
Edouard@695
   572
        {
Edouard@695
   573
            status = set_revoked(session, r_fpr,
Edouard@695
   574
                                 identity->fpr, time(NULL));
Edouard@695
   575
            free(r_fpr);
Edouard@695
   576
            if (status != PEP_STATUS_OK) {
Edouard@695
   577
                return status;
Edouard@695
   578
            }
Edouard@588
   579
        }
vb@0
   580
    }
Edouard@560
   581
    else
Edouard@560
   582
    {
vb@214
   583
        bool expired;
Edouard@701
   584
        status = key_expired(session, identity->fpr, 
Edouard@701
   585
                             time(NULL) + (7*24*3600), // In a week
Edouard@701
   586
                             &expired);
Edouard@701
   587
vb@214
   588
        assert(status == PEP_STATUS_OK);
Edouard@499
   589
        if (status != PEP_STATUS_OK) {
Edouard@588
   590
            return status;
Edouard@499
   591
        }
vb@214
   592
vb@214
   593
        if (status == PEP_STATUS_OK && expired) {
vb@214
   594
            timestamp *ts = new_timestamp(time(NULL) + KEY_EXPIRE_DELTA);
Edouard@560
   595
            renew_key(session, identity->fpr, ts);
vb@214
   596
            free_timestamp(ts);
vb@214
   597
        }
vb@214
   598
    }
vb@0
   599
krista@1353
   600
    if (!identity->username)
krista@1353
   601
        identity->username = strdup("");
krista@1353
   602
    
vb@0
   603
    status = set_identity(session, identity);
vb@0
   604
    assert(status == PEP_STATUS_OK);
Edouard@499
   605
    if (status != PEP_STATUS_OK) {
Edouard@588
   606
        return status;
Edouard@499
   607
    }
vb@0
   608
edouard@1145
   609
    if(new_key_generated)
edouard@1145
   610
    {
edouard@1145
   611
        // if a state machine for keysync is in place, inject notify
edouard@1195
   612
        status = inject_DeviceState_event(session, KeyGen, NULL, NULL);
edouard@1299
   613
        if (status == PEP_OUT_OF_MEMORY){
edouard@1299
   614
            return PEP_OUT_OF_MEMORY;
edouard@1299
   615
        }
edouard@1145
   616
    }
edouard@1140
   617
vb@0
   618
    return PEP_STATUS_OK;
Edouard@499
   619
vb@0
   620
}
vb@0
   621
edouard@1385
   622
DYNAMIC_API PEP_STATUS myself(PEP_SESSION session, pEp_identity * identity)
edouard@1385
   623
{
edouard@1385
   624
    return _myself(session, identity, true);
edouard@1385
   625
}
edouard@1385
   626
vb@296
   627
DYNAMIC_API PEP_STATUS register_examine_function(
vb@292
   628
        PEP_SESSION session, 
vb@292
   629
        examine_identity_t examine_identity,
vb@292
   630
        void *management
vb@292
   631
    )
vb@292
   632
{
vb@292
   633
    assert(session);
vb@292
   634
    if (!session)
vb@292
   635
        return PEP_ILLEGAL_VALUE;
vb@292
   636
vb@292
   637
    session->examine_management = management;
vb@292
   638
    session->examine_identity = examine_identity;
vb@292
   639
vb@292
   640
    return PEP_STATUS_OK;
vb@292
   641
}
vb@292
   642
vb@0
   643
DYNAMIC_API PEP_STATUS do_keymanagement(
vb@0
   644
        retrieve_next_identity_t retrieve_next_identity,
vb@0
   645
        void *management
vb@0
   646
    )
vb@0
   647
{
vb@0
   648
    PEP_SESSION session;
vb@0
   649
    pEp_identity *identity;
Edouard@499
   650
    PEP_STATUS status;
vb@0
   651
Edouard@499
   652
    assert(retrieve_next_identity);
Edouard@499
   653
    assert(management);
Edouard@499
   654
Edouard@499
   655
    if (!retrieve_next_identity || !management)
Edouard@499
   656
        return PEP_ILLEGAL_VALUE;
Edouard@499
   657
Edouard@499
   658
    status = init(&session);
vb@0
   659
    assert(status == PEP_STATUS_OK);
vb@0
   660
    if (status != PEP_STATUS_OK)
vb@0
   661
        return status;
vb@0
   662
vb@0
   663
    log_event(session, "keymanagement thread started", "pEp engine", NULL, NULL);
vb@0
   664
Edouard@499
   665
    while ((identity = retrieve_next_identity(management))) 
Edouard@499
   666
    {
vb@0
   667
        assert(identity->address);
Edouard@499
   668
        if(identity->address)
Edouard@499
   669
        {
Edouard@499
   670
            DEBUG_LOG("do_keymanagement", "retrieve_next_identity", identity->address);
Edouard@499
   671
Edouard@499
   672
            if (identity->me) {
Edouard@499
   673
                status = myself(session, identity);
Edouard@499
   674
            } else {
Edouard@499
   675
                status = recv_key(session, identity->address);
Edouard@499
   676
            }
Edouard@499
   677
vb@0
   678
            assert(status != PEP_OUT_OF_MEMORY);
Edouard@499
   679
            if(status == PEP_OUT_OF_MEMORY)
Edouard@499
   680
                return PEP_OUT_OF_MEMORY;
vb@0
   681
        }
vb@0
   682
        free_identity(identity);
vb@0
   683
    }
vb@0
   684
vb@0
   685
    log_event(session, "keymanagement thread shutdown", "pEp engine", NULL, NULL);
vb@0
   686
vb@0
   687
    release(session);
vb@0
   688
    return PEP_STATUS_OK;
vb@0
   689
}
vb@0
   690
krista@1213
   691
DYNAMIC_API PEP_STATUS key_mistrusted(
vb@357
   692
        PEP_SESSION session,
vb@357
   693
        pEp_identity *ident
vb@357
   694
    )
vb@215
   695
{
vb@218
   696
    PEP_STATUS status = PEP_STATUS_OK;
vb@218
   697
vb@215
   698
    assert(session);
vb@357
   699
    assert(ident);
Edouard@439
   700
    assert(!EMPTYSTR(ident->fpr));
vb@215
   701
vb@357
   702
    if (!(session && ident && ident->fpr))
vb@215
   703
        return PEP_ILLEGAL_VALUE;
vb@215
   704
vb@357
   705
    if (ident->me)
Edouard@697
   706
    {
vb@357
   707
        revoke_key(session, ident->fpr, NULL);
Edouard@697
   708
        myself(session, ident);
Edouard@697
   709
    }
Edouard@697
   710
    else
Edouard@697
   711
    {
Edouard@697
   712
        status = mark_as_compromized(session, ident->fpr);
Edouard@697
   713
    }
vb@218
   714
vb@218
   715
    return status;
vb@215
   716
}
vb@215
   717
Edouard@410
   718
DYNAMIC_API PEP_STATUS key_reset_trust(
Edouard@410
   719
        PEP_SESSION session,
Edouard@410
   720
        pEp_identity *ident
Edouard@410
   721
    )
Edouard@410
   722
{
Edouard@410
   723
    PEP_STATUS status = PEP_STATUS_OK;
Edouard@410
   724
Edouard@410
   725
    assert(session);
Edouard@410
   726
    assert(ident);
vb@420
   727
    assert(!ident->me);
Edouard@439
   728
    assert(!EMPTYSTR(ident->fpr));
Edouard@439
   729
    assert(!EMPTYSTR(ident->address));
Edouard@439
   730
    assert(!EMPTYSTR(ident->user_id));
Edouard@410
   731
vb@420
   732
    if (!(session && ident && !ident->me && ident->fpr && ident->address &&
vb@420
   733
            ident->user_id))
Edouard@410
   734
        return PEP_ILLEGAL_VALUE;
Edouard@410
   735
vb@420
   736
    status = update_identity(session, ident);
vb@420
   737
    if (status != PEP_STATUS_OK)
vb@420
   738
        return status;
Edouard@410
   739
Edouard@442
   740
    if (ident->comm_type == PEP_ct_mistrusted)
vb@421
   741
        ident->comm_type = PEP_ct_unknown;
vb@421
   742
    else
vb@421
   743
        ident->comm_type &= ~PEP_ct_confirmed;
vb@421
   744
vb@420
   745
    status = set_identity(session, ident);
vb@421
   746
    if (status != PEP_STATUS_OK)
vb@421
   747
        return status;
vb@421
   748
vb@422
   749
    if (ident->comm_type == PEP_ct_unknown)
vb@422
   750
        status = update_identity(session, ident);
Edouard@410
   751
    return status;
Edouard@410
   752
}
Edouard@410
   753
vb@354
   754
DYNAMIC_API PEP_STATUS trust_personal_key(
vb@354
   755
        PEP_SESSION session,
vb@354
   756
        pEp_identity *ident
vb@354
   757
    )
vb@354
   758
{
vb@354
   759
    PEP_STATUS status = PEP_STATUS_OK;
vb@354
   760
vb@354
   761
    assert(session);
vb@354
   762
    assert(ident);
Edouard@439
   763
    assert(!EMPTYSTR(ident->address));
Edouard@439
   764
    assert(!EMPTYSTR(ident->user_id));
Edouard@439
   765
    assert(!EMPTYSTR(ident->fpr));
vb@354
   766
    assert(!ident->me);
vb@354
   767
Edouard@439
   768
    if (!ident || EMPTYSTR(ident->address) || EMPTYSTR(ident->user_id) ||
Edouard@439
   769
            EMPTYSTR(ident->fpr) || ident->me)
vb@354
   770
        return PEP_ILLEGAL_VALUE;
vb@354
   771
vb@354
   772
    status = update_identity(session, ident);
vb@354
   773
    if (status != PEP_STATUS_OK)
vb@354
   774
        return status;
vb@354
   775
vb@356
   776
    if (ident->comm_type > PEP_ct_strong_but_unconfirmed) {
vb@356
   777
        ident->comm_type |= PEP_ct_confirmed;
Edouard@488
   778
        status = set_identity(session, ident);
vb@356
   779
    }
vb@356
   780
    else {
vb@356
   781
        // MISSING: S/MIME has to be handled depending on trusted CAs
vb@370
   782
        status = PEP_CANNOT_SET_TRUST;
vb@356
   783
    }
vb@354
   784
vb@354
   785
    return status;
vb@354
   786
}
vb@354
   787
Edouard@584
   788
DYNAMIC_API PEP_STATUS own_key_is_listed(
vb@955
   789
        PEP_SESSION session,
vb@955
   790
        const char *fpr,
vb@955
   791
        bool *listed
vb@955
   792
    )
Edouard@584
   793
{
Edouard@584
   794
    PEP_STATUS status = PEP_STATUS_OK;
Edouard@584
   795
    int count;
Edouard@584
   796
    
Edouard@584
   797
    assert(session && fpr && fpr[0] && listed);
Edouard@584
   798
    
Edouard@584
   799
    if (!(session && fpr && fpr[0] && listed))
Edouard@584
   800
        return PEP_ILLEGAL_VALUE;
Edouard@584
   801
    
Edouard@584
   802
    *listed = false;
Edouard@584
   803
    
Edouard@584
   804
    sqlite3_reset(session->own_key_is_listed);
Edouard@584
   805
    sqlite3_bind_text(session->own_key_is_listed, 1, fpr, -1, SQLITE_STATIC);
Edouard@584
   806
    
Edouard@584
   807
    int result;
Edouard@584
   808
    
Edouard@584
   809
    result = sqlite3_step(session->own_key_is_listed);
Edouard@584
   810
    switch (result) {
Edouard@584
   811
        case SQLITE_ROW:
Edouard@584
   812
            count = sqlite3_column_int(session->own_key_is_listed, 0);
Edouard@584
   813
            *listed = count > 0;
Edouard@584
   814
            status = PEP_STATUS_OK;
Edouard@584
   815
            break;
Edouard@584
   816
            
Edouard@584
   817
        default:
Edouard@584
   818
            status = PEP_UNKNOWN_ERROR;
Edouard@584
   819
    }
Edouard@584
   820
    
Edouard@584
   821
    sqlite3_reset(session->own_key_is_listed);
Edouard@584
   822
    return status;
Edouard@584
   823
}
Edouard@584
   824
vb@955
   825
DYNAMIC_API PEP_STATUS own_identities_retrieve(
vb@955
   826
        PEP_SESSION session,
vb@955
   827
        identity_list **own_identities
vb@955
   828
      )
Edouard@584
   829
{
Edouard@584
   830
    PEP_STATUS status = PEP_STATUS_OK;
Edouard@584
   831
    
vb@955
   832
    assert(session && own_identities);
vb@955
   833
    if (!(session && own_identities))
Edouard@584
   834
        return PEP_ILLEGAL_VALUE;
Edouard@584
   835
    
vb@955
   836
    *own_identities = NULL;
vb@955
   837
    identity_list *_own_identities = new_identity_list(NULL);
vb@955
   838
    if (_own_identities == NULL)
Edouard@584
   839
        goto enomem;
Edouard@584
   840
    
vb@955
   841
    sqlite3_reset(session->own_identities_retrieve);
Edouard@584
   842
    
Edouard@584
   843
    int result;
vb@955
   844
    // address, fpr, username, user_id, comm_type, lang, flags
vb@955
   845
    const char *address = NULL;
Edouard@584
   846
    const char *fpr = NULL;
vb@955
   847
    const char *username = NULL;
vb@955
   848
    const char *user_id = NULL;
vb@955
   849
    PEP_comm_type comm_type = PEP_ct_unknown;
vb@955
   850
    const char *lang = NULL;
vb@955
   851
    unsigned int flags = 0;
Edouard@584
   852
    
vb@955
   853
    identity_list *_bl = _own_identities;
Edouard@584
   854
    do {
vb@955
   855
        result = sqlite3_step(session->own_identities_retrieve);
Edouard@584
   856
        switch (result) {
Edouard@584
   857
            case SQLITE_ROW:
vb@955
   858
                address = (const char *)
vb@955
   859
                    sqlite3_column_text(session->own_identities_retrieve, 0);
vb@955
   860
                fpr = (const char *)
vb@955
   861
                    sqlite3_column_text(session->own_identities_retrieve, 1);
vb@1071
   862
                user_id = PEP_OWN_USERID;
vb@1071
   863
                username = (const char *)
vb@1069
   864
                    sqlite3_column_text(session->own_identities_retrieve, 2);
vb@1071
   865
                comm_type = PEP_ct_pEp;
vb@1071
   866
                lang = (const char *)
vb@955
   867
                    sqlite3_column_text(session->own_identities_retrieve, 3);
vb@1071
   868
                flags = (unsigned int)
vb@955
   869
                    sqlite3_column_int(session->own_key_is_listed, 4);
vb@955
   870
vb@1078
   871
                pEp_identity *ident = new_identity(address, fpr, user_id, username);
vb@1079
   872
                if (!ident)
Edouard@584
   873
                    goto enomem;
vb@955
   874
                ident->comm_type = comm_type;
vb@955
   875
                if (lang && lang[0]) {
vb@955
   876
                    ident->lang[0] = lang[0];
vb@955
   877
                    ident->lang[1] = lang[1];
vb@1078
   878
                    ident->lang[2] = 0;
vb@955
   879
                }
vb@1068
   880
                ident->me = true;
vb@955
   881
                ident->flags = flags;
vb@955
   882
vb@955
   883
                _bl = identity_list_add(_bl, ident);
vb@1080
   884
                if (_bl == NULL) {
vb@1080
   885
                    free_identity(ident);
vb@983
   886
                    goto enomem;
vb@1080
   887
                }
Edouard@584
   888
                
Edouard@584
   889
                break;
Edouard@584
   890
                
Edouard@584
   891
            case SQLITE_DONE:
Edouard@584
   892
                break;
Edouard@584
   893
                
Edouard@584
   894
            default:
Edouard@584
   895
                status = PEP_UNKNOWN_ERROR;
Edouard@584
   896
                result = SQLITE_DONE;
Edouard@584
   897
        }
Edouard@584
   898
    } while (result != SQLITE_DONE);
Edouard@584
   899
    
vb@955
   900
    sqlite3_reset(session->own_identities_retrieve);
Edouard@584
   901
    if (status == PEP_STATUS_OK)
vb@955
   902
        *own_identities = _own_identities;
Edouard@584
   903
    else
vb@955
   904
        free_identity_list(_own_identities);
Edouard@584
   905
    
Edouard@584
   906
    goto the_end;
Edouard@584
   907
    
Edouard@584
   908
enomem:
vb@955
   909
    free_identity_list(_own_identities);
Edouard@584
   910
    status = PEP_OUT_OF_MEMORY;
Edouard@584
   911
    
Edouard@584
   912
the_end:
Edouard@584
   913
    return status;
Edouard@584
   914
}
vb@955
   915
edouard@1364
   916
DYNAMIC_API PEP_STATUS keys_retrieve_by_flag(
edouard@1364
   917
        PEP_SESSION session,
edouard@1364
   918
        keypair_flags_t flags,
edouard@1364
   919
        stringlist_t **keylist
edouard@1364
   920
      )
edouard@1364
   921
{
edouard@1364
   922
    PEP_STATUS status = PEP_STATUS_OK;
edouard@1364
   923
    
edouard@1364
   924
    assert(session && keylist);
edouard@1364
   925
    if (!(session && keylist))
edouard@1364
   926
        return PEP_ILLEGAL_VALUE;
edouard@1364
   927
    
edouard@1364
   928
    *keylist = NULL;
edouard@1364
   929
    stringlist_t *_keylist = NULL;
edouard@1364
   930
    
edouard@1364
   931
    sqlite3_reset(session->keys_retrieve_by_flag);
edouard@1364
   932
    sqlite3_bind_int(session->keys_retrieve_by_flag, 1, flags);
edouard@1364
   933
    
edouard@1364
   934
    int result;
edouard@1364
   935
    char *fpr = NULL;
edouard@1364
   936
    
edouard@1364
   937
    stringlist_t *_bl = _keylist;
edouard@1364
   938
    do {
edouard@1364
   939
        result = sqlite3_step(session->keys_retrieve_by_flag);
edouard@1364
   940
        switch (result) {
edouard@1364
   941
            case SQLITE_ROW:
edouard@1364
   942
                fpr = strdup((const char *) sqlite3_column_text(session->keys_retrieve_by_flag, 0));
edouard@1364
   943
                if(fpr == NULL)
edouard@1364
   944
                    goto enomem;
edouard@1364
   945
edouard@1364
   946
                _bl = stringlist_add(_bl, fpr);
edouard@1364
   947
                if (_bl == NULL) {
edouard@1364
   948
                    free(fpr);
edouard@1364
   949
                    goto enomem;
edouard@1364
   950
                }
edouard@1364
   951
                if (_keylist == NULL)
edouard@1364
   952
                    _keylist = _bl;
edouard@1364
   953
                
edouard@1364
   954
                break;
edouard@1364
   955
                
edouard@1364
   956
            case SQLITE_DONE:
edouard@1364
   957
                break;
edouard@1364
   958
                
edouard@1364
   959
            default:
edouard@1364
   960
                status = PEP_UNKNOWN_ERROR;
edouard@1364
   961
                result = SQLITE_DONE;
edouard@1364
   962
        }
edouard@1364
   963
    } while (result != SQLITE_DONE);
edouard@1364
   964
    
edouard@1364
   965
    sqlite3_reset(session->keys_retrieve_by_flag);
edouard@1364
   966
    if (status == PEP_STATUS_OK)
edouard@1364
   967
        *keylist = _keylist;
edouard@1364
   968
    else
edouard@1364
   969
        free_stringlist(_keylist);
edouard@1364
   970
    
edouard@1364
   971
    goto the_end;
edouard@1364
   972
    
edouard@1364
   973
enomem:
edouard@1364
   974
    free_stringlist(_keylist);
edouard@1364
   975
    status = PEP_OUT_OF_MEMORY;
edouard@1364
   976
    
edouard@1364
   977
the_end:
edouard@1364
   978
    return status;
edouard@1364
   979
}
edouard@1364
   980
krista@1357
   981
krista@1357
   982
PEP_STATUS contains_priv_key(PEP_SESSION session, const char *fpr,
krista@1357
   983
                             bool *has_private) {
krista@1357
   984
krista@1357
   985
    assert(session);
krista@1357
   986
    assert(fpr);
krista@1357
   987
    assert(has_private);
krista@1357
   988
    
krista@1357
   989
    if (!(session && fpr && has_private))
krista@1357
   990
        return PEP_ILLEGAL_VALUE;
krista@1357
   991
krista@1357
   992
    return session->cryptotech[PEP_crypt_OpenPGP].contains_priv_key(session, fpr, has_private);
edouard@1385
   993
}