src/key_reset.c
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 19 Mar 2019 18:38:28 +0100
branchsync
changeset 3347 1572cabb0cc4
parent 3174 ca08de2591b7
child 3495 b4d3e47eab14
permissions -rw-r--r--
ENGINE-527: sync merge
krista@2947
     1
// This file is under GNU General Public License 3.0
krista@2947
     2
// see LICENSE.txt
krista@2947
     3
krista@2947
     4
#include "pEp_internal.h"
krista@2947
     5
#include "dynamic_api.h"
krista@2947
     6
#include "message_api.h"
krista@2947
     7
krista@2947
     8
#include <string.h>
krista@2947
     9
#include <stdlib.h>
krista@2947
    10
krista@2947
    11
PEP_STATUS has_key_reset_been_sent(
krista@2947
    12
        PEP_SESSION session, 
krista@2947
    13
        const char* user_id, 
krista@2947
    14
        const char* revoked_fpr,
krista@2947
    15
        bool* contacted)
krista@2947
    16
{
krista@2947
    17
    assert(session);
krista@2947
    18
    assert(contacted);
krista@2947
    19
    assert(user_id);
krista@2947
    20
    assert(revoked_fpr);
krista@2947
    21
    assert(!EMPTYSTR(user_id));
krista@2947
    22
krista@2947
    23
    if (!session || !contacted || EMPTYSTR(revoked_fpr) || EMPTYSTR(user_id))
krista@2947
    24
        return PEP_ILLEGAL_VALUE;
krista@2947
    25
    
krista@2947
    26
    *contacted = false;
krista@2947
    27
                    
krista@2947
    28
    char* alias_default = NULL;
krista@2947
    29
    
krista@2947
    30
    PEP_STATUS status = get_userid_alias_default(session, user_id, &alias_default);
krista@2947
    31
    
krista@2947
    32
    if (status == PEP_CANNOT_FIND_ALIAS || EMPTYSTR(alias_default)) {
krista@2947
    33
        free(alias_default);
krista@2947
    34
        alias_default = strdup(user_id);
krista@2947
    35
    }
krista@2947
    36
    
krista@2947
    37
    sqlite3_reset(session->was_id_for_revoke_contacted);
krista@2947
    38
    sqlite3_bind_text(session->was_id_for_revoke_contacted, 1, revoked_fpr, -1,
krista@2947
    39
            SQLITE_STATIC);
krista@2947
    40
    sqlite3_bind_text(session->was_id_for_revoke_contacted, 2, user_id, -1,
krista@2947
    41
            SQLITE_STATIC);        
krista@2947
    42
    int result = sqlite3_step(session->was_id_for_revoke_contacted);
krista@2947
    43
    switch (result) {
krista@2947
    44
        case SQLITE_ROW: {
krista@2947
    45
            *contacted = (sqlite3_column_int(session->was_id_for_revoke_contacted, 0) != 0);
krista@2947
    46
            break;
krista@2947
    47
        }
krista@2947
    48
        default:
krista@2947
    49
            sqlite3_reset(session->was_id_for_revoke_contacted);
krista@2947
    50
            free(alias_default);
krista@2947
    51
            return PEP_UNKNOWN_DB_ERROR;
krista@2947
    52
    }
krista@2947
    53
krista@2947
    54
    sqlite3_reset(session->was_id_for_revoke_contacted);
krista@2947
    55
    return PEP_STATUS_OK;
krista@2947
    56
}
krista@2947
    57
krista@2947
    58
//static const char *sql_set_revoke_contact_as_notified =
krista@2947
    59
//    "insert or replace into revocation_contact_list(fpr, contact_id) values (?1, ?2) ;";
krista@2947
    60
krista@2947
    61
PEP_STATUS set_reset_contact_notified(
krista@2947
    62
        PEP_SESSION session,
krista@2947
    63
        const char* revoke_fpr,
krista@2947
    64
        const char* contact_id
krista@2947
    65
    )
krista@2947
    66
{
krista@2947
    67
    PEP_STATUS status = PEP_STATUS_OK;
krista@2947
    68
    
krista@2947
    69
    assert(session && !EMPTYSTR(revoke_fpr) && !EMPTYSTR(contact_id));
krista@2947
    70
    
krista@2947
    71
    if (!session || EMPTYSTR(revoke_fpr) || EMPTYSTR(contact_id))
krista@2947
    72
        return PEP_ILLEGAL_VALUE;
krista@2947
    73
    
krista@2947
    74
    sqlite3_reset(session->set_revoke_contact_as_notified);
krista@2947
    75
    sqlite3_bind_text(session->set_revoke_contact_as_notified, 1, revoke_fpr, -1, 
krista@2947
    76
            SQLITE_STATIC);
krista@2947
    77
    sqlite3_bind_text(session->set_revoke_contact_as_notified, 2, contact_id, -1,
krista@2947
    78
            SQLITE_STATIC);
krista@2947
    79
krista@2947
    80
    int result;
krista@2947
    81
    
krista@2947
    82
    result = sqlite3_step(session->set_revoke_contact_as_notified);
krista@2947
    83
    switch (result) {
krista@2947
    84
        case SQLITE_DONE:
krista@2947
    85
            status = PEP_STATUS_OK;
krista@2947
    86
            break;
krista@2947
    87
            
krista@2947
    88
        default:
krista@2947
    89
            status = PEP_UNKNOWN_DB_ERROR;
krista@2947
    90
    }
krista@2947
    91
    
krista@2947
    92
    sqlite3_reset(session->set_revoke_contact_as_notified);
krista@2947
    93
    return status;    
krista@2947
    94
}
krista@2947
    95
krista@2947
    96
krista@2947
    97
PEP_STATUS receive_key_reset(PEP_SESSION session,
krista@2947
    98
                             message* reset_msg) {
krista@2947
    99
krista@2947
   100
    if (!session || !reset_msg)
krista@2947
   101
        return PEP_ILLEGAL_VALUE;
krista@2947
   102
krista@2947
   103
    pEp_identity* sender_id = reset_msg->from;
krista@2947
   104
                
krista@2947
   105
    if (!sender_id)
krista@2947
   106
        return PEP_MALFORMED_KEY_RESET_MSG;
krista@2947
   107
        
krista@2947
   108
    PEP_STATUS status = update_identity(session, sender_id);
krista@2947
   109
    if (!sender_id->user_id)
krista@2947
   110
        return PEP_UNKNOWN_ERROR;
krista@2947
   111
        
krista@2947
   112
    if (is_me(session, sender_id))
krista@2947
   113
        return PEP_ILLEGAL_VALUE;    
krista@2947
   114
        
krista@2947
   115
    if (!reset_msg->longmsg || strncmp(reset_msg->longmsg, "OLD: ", 5) != 0) 
krista@2947
   116
        return PEP_MALFORMED_KEY_RESET_MSG;
krista@2947
   117
krista@2947
   118
    status = PEP_STATUS_OK;
krista@2947
   119
    char* old_fpr = NULL;
krista@2947
   120
    char* new_fpr = NULL;
krista@2947
   121
    
krista@2947
   122
    stringlist_t* keylist = NULL;
krista@2947
   123
    pEp_identity* temp_ident = identity_dup(sender_id);
krista@2947
   124
    if (!temp_ident) {
krista@2947
   125
        status = PEP_OUT_OF_MEMORY;
krista@2956
   126
        goto pEp_free;
krista@2947
   127
    }        
krista@2947
   128
            
krista@2947
   129
    char* rest = NULL;
krista@2947
   130
    char* p = strtok_r(reset_msg->longmsg, "\r\n", &rest);
krista@2947
   131
    if (!EMPTYSTR(p + 5))
krista@2947
   132
        old_fpr = strdup(p + 5);
krista@2947
   133
    else {
krista@2947
   134
        status = PEP_MALFORMED_KEY_RESET_MSG;
krista@2956
   135
        goto pEp_free;
krista@2947
   136
    }
krista@2947
   137
    
krista@2947
   138
    bool own_key = false;
krista@2947
   139
    status = is_own_key(session, old_fpr, &own_key);
krista@2947
   140
    
krista@2947
   141
    if (own_key) {
krista@2947
   142
        // Nope, no one can make us our own default. If we want to do that,
krista@2947
   143
        // that's keysync, NOT key reset.
krista@2947
   144
        status = PEP_ILLEGAL_VALUE;
krista@2956
   145
        goto pEp_free;
krista@2947
   146
    }
krista@2947
   147
            
krista@2947
   148
    p = strtok_r(NULL, "\r\n", &rest); 
krista@2947
   149
    if (strncmp(p, "NEW: ", 5) != 0  || EMPTYSTR(p + 5)) {
krista@2947
   150
        status = PEP_MALFORMED_KEY_RESET_MSG;
krista@2956
   151
        goto pEp_free;
krista@2947
   152
    }
krista@2947
   153
krista@2947
   154
    new_fpr = strdup(p + 5);
krista@2947
   155
        
krista@2947
   156
    // Reset the original key
krista@2947
   157
    status = key_reset(session, old_fpr, temp_ident);
krista@2947
   158
    if (status != PEP_STATUS_OK)
krista@2956
   159
        goto pEp_free;
krista@2947
   160
        
krista@2947
   161
    status = find_keys(session, new_fpr, &keylist);
krista@2947
   162
    if (status != PEP_STATUS_OK)
krista@2956
   163
        goto pEp_free;
krista@2947
   164
        
krista@2947
   165
    if (!keylist) {
krista@2947
   166
        status = PEP_KEY_NOT_FOUND;
krista@2956
   167
        goto pEp_free;
krista@2947
   168
    }
krista@2947
   169
krista@2947
   170
    // alright, we've checked as best we can. Let's set that baby.
krista@2947
   171
    sender_id->fpr = new_fpr;
krista@2947
   172
    
krista@2947
   173
    // This only sets as the default, does NOT TRUST IN ANY WAY
krista@2947
   174
    sender_id->comm_type = sender_id->comm_type & (~PEP_ct_confirmed);
krista@2947
   175
    status = set_identity(session, sender_id);
krista@2947
   176
    
krista@2947
   177
    sender_id->fpr = NULL; // ownership for free
krista@2956
   178
pEp_free:    
krista@2947
   179
    free_stringlist(keylist);    
krista@2947
   180
    free(old_fpr);
krista@2947
   181
    free(new_fpr);
krista@2947
   182
    free_identity(temp_ident);
krista@2947
   183
    return status;
krista@2947
   184
}
krista@2947
   185
krista@2947
   186
PEP_STATUS create_standalone_key_reset_message(PEP_SESSION session,
krista@2947
   187
                                               message** dst, 
krista@2947
   188
                                               pEp_identity* recip,
krista@2947
   189
                                               const char* old_fpr,
krista@2947
   190
                                               const char* new_fpr) {
krista@2947
   191
                                                   
krista@2947
   192
    if (!dst || !recip->user_id || !recip->address)
krista@2947
   193
        return PEP_ILLEGAL_VALUE;
krista@2947
   194
krista@2947
   195
    if (!old_fpr || !new_fpr)
krista@2947
   196
        return PEP_ILLEGAL_VALUE;
krista@2947
   197
        
krista@2947
   198
    *dst = NULL;
krista@2947
   199
    // Get own identity user has corresponded with
krista@2947
   200
    pEp_identity* own_identity = NULL;
krista@2947
   201
    
krista@2947
   202
    PEP_STATUS status = get_own_ident_for_contact_id(session,
krista@2947
   203
                                                     recip,
krista@2947
   204
                                                     &own_identity);                                                       
krista@2947
   205
    if (status != PEP_STATUS_OK)
krista@2947
   206
        return status;
krista@2947
   207
        
krista@2947
   208
    message* reset_message = new_message(PEP_dir_outgoing);
krista@2947
   209
    reset_message->from = own_identity;
krista@2947
   210
    reset_message->to = new_identity_list(identity_dup(recip)); // ?
krista@2947
   211
    
krista@2947
   212
    const char* oldtag = "OLD: ";
krista@2947
   213
    const char* newtag = "\nNEW: ";
krista@2947
   214
    const size_t taglens = 11;
krista@2947
   215
    size_t full_len = taglens + strlen(old_fpr) + strlen(new_fpr) + 2; // \n and \0
krista@2947
   216
    char* longmsg = calloc(full_len, 1);
krista@2947
   217
    strlcpy(longmsg, oldtag, full_len);
krista@2947
   218
    strlcat(longmsg, old_fpr, full_len);
krista@2947
   219
    strlcat(longmsg, newtag, full_len);
krista@2947
   220
    strlcat(longmsg, new_fpr, full_len);
krista@2947
   221
    strlcat(longmsg, "\n", full_len);
krista@2947
   222
    reset_message->longmsg = longmsg; 
krista@2947
   223
    reset_message->shortmsg = strdup("Key reset");    
krista@2947
   224
    
krista@2947
   225
    message* output_msg = NULL;
krista@2947
   226
    
krista@2947
   227
    status = encrypt_message(session, reset_message, NULL,
krista@2947
   228
                             &output_msg, PEP_enc_PGP_MIME,
krista@2947
   229
                             PEP_encrypt_flag_key_reset_only);
krista@2947
   230
krista@2947
   231
    if (status == PEP_STATUS_OK)
krista@2947
   232
        *dst = output_msg;
krista@2947
   233
        
krista@2947
   234
    free_message(reset_message);
krista@2947
   235
    return status;
krista@2947
   236
}
krista@2947
   237
krista@2947
   238
PEP_STATUS send_key_reset_to_recents(PEP_SESSION session,
krista@2947
   239
                                     const char* old_fpr, 
krista@2947
   240
                                     const char* new_fpr) {
krista@2947
   241
    assert(old_fpr);
krista@2947
   242
    assert(new_fpr);
krista@2947
   243
    assert(session);
krista@2956
   244
    assert(session->messageToSend);
krista@2947
   245
    
krista@2947
   246
    if (!session || !old_fpr || !new_fpr)
krista@2947
   247
        return PEP_ILLEGAL_VALUE;
krista@2947
   248
krista@2956
   249
    messageToSend_t send_cb = session->messageToSend;
krista@2947
   250
    if (!send_cb)
krista@2947
   251
        return PEP_SYNC_NO_MESSAGE_SEND_CALLBACK;
krista@2947
   252
        
krista@2947
   253
    identity_list* recent_contacts = NULL;
krista@2947
   254
    message* reset_msg = NULL;
krista@2947
   255
krista@2947
   256
    PEP_STATUS status = get_last_contacted(session, &recent_contacts);
krista@2947
   257
    
krista@2947
   258
    if (status != PEP_STATUS_OK)
krista@2956
   259
        goto pEp_free;
krista@2947
   260
                    
krista@2947
   261
    identity_list* curr_id_ptr = recent_contacts;
krista@2947
   262
krista@2947
   263
    for (curr_id_ptr = recent_contacts; curr_id_ptr; curr_id_ptr = curr_id_ptr->next) {
krista@2947
   264
        pEp_identity* curr_id = curr_id_ptr->ident;
krista@2947
   265
        
krista@2947
   266
        if (!curr_id)
krista@2947
   267
            break;
krista@2947
   268
    
krista@2947
   269
        const char* user_id = curr_id->user_id;
krista@2947
   270
        
krista@2947
   271
        // Should be impossible, but?
krista@2947
   272
        if (!user_id)
krista@2947
   273
            continue;
krista@2947
   274
        
krista@2947
   275
        // Check if it's us - if so, pointless...
krista@2947
   276
        if (is_me(session, curr_id))
krista@2947
   277
            continue;
krista@2947
   278
            
krista@2947
   279
        // Check if they've already been told - this shouldn't be the case, but...
krista@2947
   280
        bool contacted = false;
krista@2947
   281
        status = has_key_reset_been_sent(session, user_id, old_fpr, &contacted);
krista@2947
   282
        if (status != PEP_STATUS_OK)
krista@2956
   283
            goto pEp_free;
krista@2947
   284
    
krista@2947
   285
        if (contacted)
krista@2947
   286
            continue;
krista@2947
   287
            
krista@2947
   288
        // if not, make em a message    
krista@2947
   289
        reset_msg = NULL;
krista@2947
   290
        
krista@2947
   291
        status = create_standalone_key_reset_message(session,
krista@2947
   292
                                                     &reset_msg,
krista@2947
   293
                                                     curr_id,
krista@2947
   294
                                                     old_fpr,
krista@2947
   295
                                                     new_fpr);
krista@2947
   296
krista@2947
   297
        if (status == PEP_CANNOT_FIND_IDENTITY) { // this is ok, just means we never mailed them 
krista@2947
   298
            status = PEP_STATUS_OK;
krista@2947
   299
            continue; 
krista@2947
   300
        }
krista@2947
   301
            
krista@2947
   302
        if (status != PEP_STATUS_OK) {
krista@2947
   303
            free(reset_msg);
krista@2956
   304
            goto pEp_free;
krista@2947
   305
        }
krista@2947
   306
        
krista@2947
   307
        // insert into queue
krista@2956
   308
        status = send_cb(reset_msg);
krista@2947
   309
krista@2947
   310
        if (status != PEP_STATUS_OK) {
krista@2947
   311
            free(reset_msg);
krista@2956
   312
            goto pEp_free;            
krista@2947
   313
        }
krista@2947
   314
            
krista@2947
   315
        // Put into notified DB
krista@2947
   316
        status = set_reset_contact_notified(session, old_fpr, user_id);
krista@2947
   317
        if (status != PEP_STATUS_OK)
krista@2956
   318
            goto pEp_free;            
krista@2947
   319
    }
krista@2947
   320
    
krista@2956
   321
pEp_free:
krista@2947
   322
    free_identity_list(recent_contacts);
krista@2947
   323
    return status;
krista@2947
   324
}
krista@2947
   325
krista@2947
   326
DYNAMIC_API PEP_STATUS key_reset(
krista@2947
   327
        PEP_SESSION session,
krista@2947
   328
        const char* key_id,
krista@2947
   329
        pEp_identity* ident
krista@2947
   330
    )
krista@2947
   331
{
krista@2947
   332
    if (!session)
krista@2947
   333
        return PEP_ILLEGAL_VALUE;
krista@2947
   334
        
krista@2947
   335
    PEP_STATUS status = PEP_STATUS_OK;
krista@2947
   336
        
krista@2947
   337
    char* fpr_copy = NULL;
krista@2947
   338
    char* own_id = NULL;
krista@2947
   339
    char* new_key = NULL;
krista@2947
   340
    identity_list* key_idents = NULL;
krista@2947
   341
    stringlist_t* keys = NULL;
krista@2947
   342
    
krista@2947
   343
    if (!EMPTYSTR(key_id)) {
krista@2947
   344
        fpr_copy = strdup(key_id);
krista@2947
   345
        if (!fpr_copy)
krista@2947
   346
            return PEP_OUT_OF_MEMORY;
krista@2947
   347
    }
krista@2947
   348
        
krista@2947
   349
    if (!ident) {
krista@2947
   350
        // Get list of own identities
krista@2947
   351
        status = get_default_own_userid(session, &own_id);
krista@2947
   352
        if (status != PEP_STATUS_OK)
krista@2956
   353
            goto pEp_free;
krista@2947
   354
            
krista@2947
   355
        if (EMPTYSTR(fpr_copy)) {
krista@2947
   356
            status = get_all_keys_for_user(session, own_id, &keys);
krista@2947
   357
            if (status == PEP_STATUS_OK) {
krista@2947
   358
                stringlist_t* curr_key;
krista@2947
   359
                for (curr_key = keys; curr_key && curr_key->value; curr_key = curr_key->next) {
krista@2947
   360
                    status = key_reset(session, curr_key->value, NULL);
krista@2947
   361
                    if (status != PEP_STATUS_OK)
krista@2947
   362
                        break;
krista@2947
   363
                }
krista@2947
   364
            }
krista@2956
   365
            goto pEp_free;
krista@2947
   366
        } // otherwise, we have a specific fpr to process
krista@2947
   367
krista@2947
   368
        // fpr_copy exists, so... let's go.
krista@2947
   369
        // Process own identities with this fpr
krista@2947
   370
        status = get_identities_by_main_key_id(session, fpr_copy, &key_idents);
krista@2947
   371
        
krista@2947
   372
        if (status == PEP_STATUS_OK) {
krista@2947
   373
            // have ident list, or should
krista@2947
   374
            identity_list* curr_ident;
krista@2947
   375
            for (curr_ident = key_idents; curr_ident && curr_ident->ident; 
krista@2947
   376
                 curr_ident = curr_ident->next) {
krista@2947
   377
                pEp_identity* this_identity = curr_ident->ident;
krista@2947
   378
                status = key_reset(session, fpr_copy, this_identity);
krista@2947
   379
                if (status != PEP_STATUS_OK)
krista@2947
   380
                    break;                    
krista@2947
   381
            }
krista@2947
   382
        }
krista@3174
   383
        else if (status == PEP_CANNOT_FIND_IDENTITY) // not an error
krista@3174
   384
            status = PEP_STATUS_OK;
krista@3174
   385
            
krista@2956
   386
        goto pEp_free;
krista@2947
   387
    }
krista@2947
   388
    else { // an identity was specified.       
krista@2947
   389
        if (is_me(session, ident)) {            
krista@2947
   390
            // FIXME: make sure this IS our fpr?
krista@2947
   391
            
krista@2947
   392
            // If it got sent in with an empty fpr...
krista@2947
   393
            if (EMPTYSTR(fpr_copy)) {
krista@2947
   394
                //
krista@2947
   395
                // if (!EMPTYSTR(ident->fpr))
krista@2947
   396
                //     fpr_copy = strdup(ident->fpr);
krista@3347
   397
                status = _myself(session, ident, false, true, true);
krista@2947
   398
                if (status == PEP_STATUS_OK && ident->fpr)
krista@2947
   399
                    fpr_copy = strdup(ident->fpr);
krista@2947
   400
                else {
krista@2947
   401
                    // last resort?
krista@2947
   402
                    // Get list of own identities
krista@2947
   403
                    char* own_id = NULL;
krista@2947
   404
                    status = get_default_own_userid(session, &own_id);
krista@2947
   405
                    if (status == PEP_STATUS_OK)
krista@2947
   406
                        status = get_user_default_key(session, own_id, &fpr_copy);
krista@2947
   407
                    if (status != PEP_STATUS_OK || EMPTYSTR(fpr_copy))  {
krista@2947
   408
                        free(own_id);
krista@2947
   409
                        return (status == PEP_STATUS_OK ? PEP_KEY_NOT_FOUND : status);
krista@2947
   410
                    }
krista@2947
   411
                }
krista@2947
   412
            }
krista@2947
   413
                        
krista@2947
   414
            free(ident->fpr);
krista@2947
   415
            ident->fpr = fpr_copy;            
krista@2947
   416
            // Create revocation
krista@2947
   417
            status = revoke_key(session, fpr_copy, NULL);
krista@2947
   418
            // generate new key
krista@2947
   419
            if (status == PEP_STATUS_OK) {
krista@2947
   420
                ident->fpr = NULL;
krista@2947
   421
                status = generate_keypair(session, ident);
krista@2947
   422
            }
krista@2947
   423
            if (status == PEP_STATUS_OK) {
krista@2947
   424
                new_key = strdup(ident->fpr);
krista@2947
   425
                status = set_own_key(session, ident, new_key);
krista@2947
   426
            }
krista@2947
   427
            // mistrust fpr from trust
krista@2947
   428
            ident->fpr = fpr_copy;
krista@2947
   429
            
krista@2947
   430
            ident->comm_type = PEP_ct_mistrusted;
krista@2947
   431
            status = set_trust(session, ident);
krista@2947
   432
            ident->fpr = NULL;
krista@2947
   433
            
krista@2947
   434
            // Done with old use of ident.
krista@2947
   435
            if (status == PEP_STATUS_OK) {
krista@2947
   436
                // Update fpr for outgoing
krista@2947
   437
                status = myself(session, ident);
krista@2947
   438
            }
krista@2947
   439
            
krista@2947
   440
            if (status == PEP_STATUS_OK)
krista@2947
   441
                // cascade that mistrust for anyone using this key
krista@2947
   442
                status = mark_as_compromised(session, fpr_copy);
krista@2947
   443
            if (status == PEP_STATUS_OK)
krista@2947
   444
                status = remove_fpr_as_default(session, fpr_copy);
krista@2947
   445
            if (status == PEP_STATUS_OK)
krista@2947
   446
                status = add_mistrusted_key(session, fpr_copy);
krista@2947
   447
            // add to revocation list 
krista@2947
   448
            if (status == PEP_STATUS_OK) 
krista@2947
   449
                status = set_revoked(session, fpr_copy, new_key, time(NULL));            
krista@2947
   450
            // for all active communication partners:
krista@2947
   451
            //      active_send revocation
krista@2947
   452
            if (status == PEP_STATUS_OK)
krista@2947
   453
                status = send_key_reset_to_recents(session, fpr_copy, new_key);
krista@2947
   454
                
krista@2947
   455
        }
krista@2947
   456
        else { // not is_me
krista@2948
   457
            // TODO: Decide what this means. We have a non-own identity, we don't
krista@2948
   458
            //       have an fpr. Do we reset all keys for that identity?
krista@2948
   459
            if (EMPTYSTR(fpr_copy)) {
krista@2948
   460
                NOT_IMPLEMENTED
krista@2948
   461
            }
krista@2948
   462
                
krista@2947
   463
            // remove fpr from all identities
krista@2947
   464
            // remove fpr from all users
krista@2947
   465
            if (status == PEP_STATUS_OK)
krista@2947
   466
                status = remove_fpr_as_default(session, fpr_copy);
krista@2947
   467
            // delete key from DB
krista@2948
   468
            if (status == PEP_STATUS_OK) {
krista@2948
   469
                status = remove_key(session, fpr_copy);
krista@2948
   470
            };
krista@2947
   471
        }
krista@2947
   472
    }
krista@2947
   473
    
krista@2956
   474
pEp_free:
krista@2947
   475
    free(fpr_copy);
krista@2947
   476
    free(own_id);
krista@2947
   477
    free_identity_list(key_idents);
krista@2947
   478
    free_stringlist(keys);
krista@2947
   479
    free(new_key);    
krista@2947
   480
    return status;
krista@2947
   481
}