src/message_api.c
author Volker Birk <vb@pep-project.org>
Wed, 06 May 2015 20:16:53 +0200
changeset 251 dba7f09db1ed
parent 250 ace6314d8e64
child 256 0232e3d7d77c
permissions -rw-r--r--
completing rating
vb@125
     1
#include "pEp_internal.h"
vb@37
     2
#include "message_api.h"
vb@37
     3
vb@130
     4
#include "platform.h"
vb@220
     5
#include "mime.h"
vb@85
     6
vb@37
     7
#include <assert.h>
vb@37
     8
#include <string.h>
vb@39
     9
#include <stdlib.h>
vb@39
    10
vb@190
    11
#ifndef MIN
vb@190
    12
#define MIN(A, B) ((B) > (A) ? (A) : (B))
vb@190
    13
#endif
vb@190
    14
vb@235
    15
vb@235
    16
static bool string_equality(const char *s1, const char *s2)
vb@235
    17
{
vb@235
    18
    if (s1 == NULL || s2 == NULL)
vb@235
    19
        return false;
vb@235
    20
vb@235
    21
    assert(s1 && s2);
vb@235
    22
vb@235
    23
    return strcmp(s1, s2) == 0;
vb@235
    24
}
vb@235
    25
vb@235
    26
static bool is_mime_type(const bloblist_t *bl, const char *mt)
vb@235
    27
{
vb@235
    28
    assert(mt);
vb@235
    29
vb@235
    30
    return bl && string_equality(bl->mime_type, mt);
vb@235
    31
}
vb@235
    32
vb@235
    33
static bool is_fileending(const bloblist_t *bl, const char *fe)
vb@235
    34
{
vb@235
    35
    assert(fe);
vb@235
    36
vb@235
    37
    if (bl == NULL || bl->filename == NULL)
vb@235
    38
        return false;
vb@235
    39
vb@235
    40
    assert(bl && bl->filename);
vb@235
    41
vb@235
    42
    size_t fe_len = strlen(fe);
vb@235
    43
    size_t fn_len = strlen(bl->filename);
vb@235
    44
vb@235
    45
    if (fn_len <= fe_len)
vb@235
    46
        return false;
vb@235
    47
vb@235
    48
    assert(fn_len > fe_len);
vb@235
    49
vb@235
    50
    return strcmp(bl->filename + (fn_len - fe_len), fe) == 0;
vb@235
    51
}
vb@235
    52
vb@235
    53
void import_attached_keys(PEP_SESSION session, const message *msg)
vb@235
    54
{
vb@236
    55
    assert(session);
vb@235
    56
    assert(msg);
vb@235
    57
vb@235
    58
    bloblist_t *bl;
vb@235
    59
    for (bl = msg->attachments; bl && bl->data; bl = bl->next) {
vb@235
    60
        assert(bl && bl->data && bl->size);
vb@235
    61
vb@235
    62
        if (bl->mime_type == NULL ||
vb@235
    63
                    is_mime_type(bl, "application/octet-stream")) {
vb@235
    64
            if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
vb@235
    65
                    is_fileending(bl, ".key") ||
vb@235
    66
                    string_equality(bl->filename, "key.asc"))
vb@235
    67
                import_key(session, bl->data, bl->size);
vb@235
    68
        }
vb@235
    69
        else if (is_mime_type(bl, "application/pgp-keys")) {
vb@235
    70
            import_key(session, bl->data, bl->size);
vb@235
    71
        }
vb@235
    72
        else if (is_mime_type(bl, "text/plain")) {
vb@235
    73
            if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
vb@235
    74
                    is_fileending(bl, ".key") || is_fileending(bl, ".asc"))
vb@235
    75
                import_key(session, bl->data, bl->size);
vb@235
    76
        }
vb@235
    77
    }
vb@235
    78
}
vb@235
    79
vb@236
    80
void attach_own_key(PEP_SESSION session, message *msg)
vb@236
    81
{
vb@236
    82
    char *keydata;
vb@236
    83
    size_t size;
vb@236
    84
    bloblist_t *bl;
vb@236
    85
vb@236
    86
    assert(session);
vb@236
    87
    assert(msg);
vb@236
    88
vb@236
    89
    if (msg->dir == PEP_dir_incoming)
vb@236
    90
        return;
vb@236
    91
vb@236
    92
    assert(msg->from && msg->from->fpr);
vb@236
    93
    if (msg->from == NULL || msg->from->fpr == NULL)
vb@236
    94
        return;
vb@236
    95
vb@236
    96
    PEP_STATUS status = export_key(session, msg->from->fpr, &keydata, &size);
vb@236
    97
    assert(status == PEP_STATUS_OK);
vb@236
    98
    if (status != PEP_STATUS_OK)
vb@236
    99
        return;
vb@236
   100
    assert(size);
vb@236
   101
vb@236
   102
    bl = bloblist_add(msg->attachments, keydata, size, "application/pgp-keys",
vb@236
   103
            "pEp_key.asc");
vb@236
   104
    if (bl)
vb@236
   105
        msg->attachments = bl;
vb@236
   106
}
vb@236
   107
vb@250
   108
void determine_encryption_format(message *msg)
vb@250
   109
{
vb@250
   110
    assert(msg);
vb@250
   111
vb@250
   112
    if (msg->enc_format != PEP_enc_none)
vb@250
   113
        return;
vb@250
   114
vb@250
   115
    if (is_PGP_message_text(msg->longmsg))
vb@250
   116
        msg->enc_format = PEP_enc_pieces;
vb@250
   117
    else if (msg->attachments && msg->attachments->next &&
vb@250
   118
            is_mime_type(msg->attachments, "multipart/encrypted") &&
vb@250
   119
            is_PGP_message_text(msg->attachments->next->data)
vb@250
   120
        )
vb@250
   121
        msg->enc_format = PEP_enc_PGP_MIME;
vb@250
   122
}
vb@250
   123
vb@83
   124
static char * combine_short_and_long(const char *shortmsg, const char *longmsg)
vb@62
   125
{
vb@62
   126
    char * ptext;
vb@81
   127
vb@83
   128
    assert(shortmsg);
vb@83
   129
    assert(strcmp(shortmsg, "pEp") != 0);
vb@62
   130
vb@83
   131
    if (longmsg == NULL)
vb@63
   132
        longmsg = "";
vb@63
   133
vb@83
   134
    ptext = calloc(1, strlen(shortmsg) + strlen(longmsg) + 12);
vb@109
   135
    assert(ptext);
vb@62
   136
    if (ptext == NULL)
vb@62
   137
        return NULL;
vb@62
   138
vb@85
   139
    strcpy(ptext, "Subject: ");
vb@83
   140
    strcat(ptext, shortmsg);
vb@62
   141
    strcat(ptext, "\n\n");
vb@63
   142
    strcat(ptext, longmsg);
vb@62
   143
vb@62
   144
    return ptext;
vb@62
   145
}
vb@44
   146
vb@82
   147
static int seperate_short_and_long(const char *src, char **shortmsg, char **longmsg)
vb@82
   148
{
vb@82
   149
    char *_shortmsg = NULL;
vb@82
   150
    char *_longmsg = NULL;
vb@82
   151
vb@82
   152
    assert(src);
vb@82
   153
    assert(shortmsg);
vb@82
   154
    assert(longmsg);
vb@82
   155
vb@82
   156
    *shortmsg = NULL;
vb@82
   157
    *longmsg = NULL;
vb@82
   158
vb@85
   159
    if (strncasecmp(src, "subject: ", 9) == 0) {
vb@82
   160
        char *line_end = strchr(src, '\n');
vb@82
   161
        
vb@82
   162
        if (line_end == NULL) {
vb@82
   163
            _shortmsg = strdup(src + 9);
vb@82
   164
            if (_shortmsg == NULL)
vb@82
   165
                goto enomem;
vb@82
   166
            // _longmsg = NULL;
vb@82
   167
        }
vb@82
   168
        else {
vb@82
   169
            size_t n = line_end - src;
vb@166
   170
vb@82
   171
            if (*(line_end - 1) == '\r')
vb@166
   172
                _shortmsg = strndup(src + 9, n - 10);
vb@82
   173
            else
vb@166
   174
                _shortmsg = strndup(src + 9, n - 9);
vb@166
   175
vb@82
   176
            if (_shortmsg == NULL)
vb@82
   177
                goto enomem;
vb@166
   178
vb@166
   179
            while (*(src + n) && (*(src + n) == '\n' || *(src + n) == '\r'))
vb@166
   180
                ++n;
vb@166
   181
vb@166
   182
            if (*(src + n)) {
vb@166
   183
                _longmsg = strdup(src + n);
vb@166
   184
                if (_longmsg == NULL)
vb@166
   185
                    goto enomem;
vb@166
   186
            }
vb@82
   187
        }
vb@82
   188
    }
vb@82
   189
    else {
vb@113
   190
        _shortmsg = strdup("");
vb@82
   191
        if (_shortmsg == NULL)
vb@82
   192
            goto enomem;
vb@82
   193
        _longmsg = strdup(src);
vb@82
   194
        if (_longmsg == NULL)
vb@82
   195
            goto enomem;
vb@82
   196
    }
vb@82
   197
    
vb@82
   198
    *shortmsg = _shortmsg;
vb@82
   199
    *longmsg = _longmsg;
vb@82
   200
vb@82
   201
    return 0;
vb@82
   202
vb@82
   203
enomem:
vb@82
   204
    free(_shortmsg);
vb@82
   205
    free(_longmsg);
vb@82
   206
vb@82
   207
    return -1;
vb@82
   208
}
vb@82
   209
vb@113
   210
static PEP_STATUS copy_fields(message *dst, const message *src)
vb@113
   211
{
vb@164
   212
    assert(dst);
vb@164
   213
    assert(src);
vb@164
   214
vb@113
   215
    free_timestamp(dst->sent);
vb@113
   216
    dst->sent = NULL;
vb@113
   217
    if (src->sent) {
vb@113
   218
        dst->sent = timestamp_dup(src->sent);
vb@113
   219
        if (dst->sent == NULL)
vb@113
   220
            return PEP_OUT_OF_MEMORY;
vb@113
   221
    }
vb@113
   222
vb@113
   223
    free_timestamp(dst->recv);
vb@113
   224
    dst->recv = NULL;
vb@113
   225
    if (src->recv) {
vb@113
   226
        dst->recv = timestamp_dup(src->recv);
vb@113
   227
        if (dst->recv == NULL)
vb@113
   228
            return PEP_OUT_OF_MEMORY;
vb@113
   229
    }
vb@113
   230
vb@113
   231
    free_identity(dst->from);
vb@113
   232
    dst->from = NULL;
vb@113
   233
    if (src->from) {
vb@113
   234
        dst->from = identity_dup(src->from);
vb@113
   235
        if (dst->from == NULL)
vb@113
   236
            return PEP_OUT_OF_MEMORY;
vb@113
   237
    }
vb@113
   238
vb@113
   239
    free_identity_list(dst->to);
vb@113
   240
    dst->to = NULL;
vb@113
   241
    if (src->to) {
vb@113
   242
        dst->to = identity_list_dup(src->to);
vb@113
   243
        if (dst->to == NULL)
vb@113
   244
            return PEP_OUT_OF_MEMORY;
vb@113
   245
    }
vb@113
   246
vb@113
   247
    free_identity(dst->recv_by);
vb@113
   248
    dst->recv_by = NULL;
vb@113
   249
    if (src->recv_by) {
vb@113
   250
        dst->recv_by = identity_dup(src->recv_by);
vb@113
   251
        if (dst->recv_by == NULL)
vb@113
   252
            return PEP_OUT_OF_MEMORY;
vb@113
   253
    }
vb@113
   254
vb@113
   255
    free_identity_list(dst->cc);
vb@113
   256
    dst->cc = NULL;
vb@113
   257
    if (src->cc) {
vb@113
   258
        dst->cc = identity_list_dup(src->cc);
vb@113
   259
        if (dst->cc == NULL)
vb@113
   260
            return PEP_OUT_OF_MEMORY;
vb@113
   261
    }
vb@113
   262
vb@113
   263
    free_identity_list(dst->bcc);
vb@113
   264
    dst->bcc = NULL;
vb@113
   265
    if (src->bcc) {
vb@113
   266
        dst->bcc = identity_list_dup(src->bcc);
vb@113
   267
        if (dst->bcc == NULL)
vb@113
   268
            return PEP_OUT_OF_MEMORY;
vb@113
   269
    }
vb@113
   270
vb@113
   271
    free_identity_list(dst->reply_to);
vb@113
   272
    dst->reply_to = NULL;
vb@113
   273
    if (src->reply_to) {
vb@113
   274
        dst->reply_to = identity_list_dup(src->reply_to);
vb@113
   275
        if (dst->reply_to == NULL)
vb@113
   276
            return PEP_OUT_OF_MEMORY;
vb@113
   277
    }
vb@113
   278
vb@113
   279
    free_stringlist(dst->in_reply_to);
vb@113
   280
    dst->in_reply_to = NULL;
vb@113
   281
    if (src->in_reply_to) {
vb@113
   282
        dst->in_reply_to = stringlist_dup(src->in_reply_to);
vb@113
   283
        if (dst->in_reply_to == NULL)
vb@113
   284
            return PEP_OUT_OF_MEMORY;
vb@113
   285
    }
vb@113
   286
vb@113
   287
    free_stringlist(dst->references);
vb@113
   288
    dst->references = NULL;
vb@113
   289
    if (src->references) {
vb@113
   290
        dst->references = stringlist_dup(src->references);
vb@113
   291
        if (dst->references == NULL)
vb@113
   292
            return PEP_OUT_OF_MEMORY;
vb@113
   293
    }
vb@113
   294
vb@113
   295
    free_stringlist(dst->keywords);
vb@113
   296
    dst->keywords = NULL;
vb@113
   297
    if (src->keywords) {
vb@113
   298
        dst->keywords = stringlist_dup(src->keywords);
vb@113
   299
        if (dst->keywords == NULL)
vb@113
   300
            return PEP_OUT_OF_MEMORY;
vb@113
   301
    }
vb@113
   302
vb@113
   303
    free(dst->comments);
vb@113
   304
    dst->comments = NULL;
vb@113
   305
    if (src->comments) {
vb@113
   306
        dst->comments = strdup(src->comments);
vb@113
   307
        assert(dst->comments);
vb@113
   308
        if (dst->comments == NULL)
vb@113
   309
            return PEP_OUT_OF_MEMORY;
vb@113
   310
    }
vb@113
   311
vb@113
   312
    return PEP_STATUS_OK;
vb@113
   313
}
vb@113
   314
vb@81
   315
static message * clone_to_empty_message(const message * src)
vb@80
   316
{
vb@113
   317
    PEP_STATUS status;
vb@80
   318
    message * msg = NULL;
vb@80
   319
vb@81
   320
    assert(src);
vb@81
   321
vb@113
   322
    msg = calloc(1, sizeof(message));
vb@113
   323
    assert(msg);
vb@80
   324
    if (msg == NULL)
vb@80
   325
        goto enomem;
vb@80
   326
vb@82
   327
    msg->dir = src->dir;
vb@82
   328
vb@113
   329
    status = copy_fields(msg, src);
vb@113
   330
    if (status != PEP_STATUS_OK)
vb@113
   331
        goto enomem;
vb@81
   332
vb@80
   333
    return msg;
vb@80
   334
vb@80
   335
enomem:
vb@113
   336
    free_message(msg);
vb@80
   337
    return NULL;
vb@80
   338
}
vb@80
   339
vb@48
   340
DYNAMIC_API PEP_STATUS encrypt_message(
vb@37
   341
        PEP_SESSION session,
vb@113
   342
        message *src,
vb@37
   343
        stringlist_t * extra,
vb@38
   344
        message **dst,
vb@81
   345
        PEP_enc_format enc_format
vb@37
   346
    )
vb@37
   347
{
vb@37
   348
    PEP_STATUS status = PEP_STATUS_OK;
vb@63
   349
    message * msg = NULL;
vb@63
   350
    stringlist_t * keys = NULL;
vb@113
   351
    bool free_src = false;
vb@37
   352
vb@37
   353
    assert(session);
vb@37
   354
    assert(src);
vb@37
   355
    assert(dst);
vb@81
   356
    assert(enc_format >= PEP_enc_pieces);
vb@81
   357
vb@191
   358
    if (!(session && src && dst && (enc_format >= PEP_enc_pieces)))
vb@191
   359
        return PEP_ILLEGAL_VALUE;
vb@191
   360
vb@37
   361
    *dst = NULL;
vb@67
   362
vb@250
   363
    determine_encryption_format(src);
vb@235
   364
    import_attached_keys(session, src);
vb@235
   365
vb@81
   366
    if (src->enc_format >= PEP_enc_pieces) {
vb@81
   367
        if (src->enc_format == enc_format) {
vb@113
   368
            assert(0); // the message is encrypted this way already
vb@81
   369
            msg = message_dup(src);
vb@81
   370
            if (msg == NULL)
vb@81
   371
                goto enomem;
vb@81
   372
            *dst = msg;
vb@81
   373
            return PEP_STATUS_OK;
vb@81
   374
        }
vb@81
   375
        else {
vb@113
   376
            // decrypt and re-encrypt again
vb@113
   377
            message * _dst = NULL;
vb@241
   378
            stringlist_t *_keylist = NULL;
vb@113
   379
            PEP_MIME_format mime = (enc_format == PEP_enc_PEP) ? PEP_MIME :
vb@113
   380
                    PEP_MIME_fields_omitted;
vb@113
   381
vb@251
   382
            PEP_color color;
vb@251
   383
            status = decrypt_message(session, src, mime, &_dst, &_keylist, &color);
vb@113
   384
            if (status != PEP_STATUS_OK)
vb@113
   385
                goto pep_error;
vb@241
   386
            free_stringlist(_keylist);
vb@113
   387
vb@113
   388
            src = _dst;
vb@113
   389
            free_src = true;
vb@81
   390
        }
vb@67
   391
    }
vb@37
   392
vb@236
   393
    status = myself(session, src->from);
vb@236
   394
    if (status != PEP_STATUS_OK)
vb@236
   395
        goto pep_error;
vb@236
   396
vb@81
   397
    msg = clone_to_empty_message(src);
vb@80
   398
    if (msg == NULL)
vb@63
   399
        goto enomem;
vb@40
   400
vb@80
   401
    keys = new_stringlist(src->from->fpr);
vb@63
   402
    if (keys == NULL)
vb@63
   403
        goto enomem;
vb@37
   404
vb@39
   405
    stringlist_t *_k = keys;
vb@39
   406
vb@39
   407
    if (extra) {
vb@39
   408
        _k = stringlist_append(_k, extra);
vb@63
   409
        if (_k == NULL)
vb@63
   410
            goto enomem;
vb@37
   411
    }
vb@39
   412
vb@39
   413
    bool dest_keys_found = false;
vb@37
   414
    identity_list * _il;
vb@80
   415
    for (_il = msg->to; _il && _il->ident; _il = _il->next) {
vb@63
   416
        PEP_STATUS status = update_identity(session, _il->ident);
vb@63
   417
        if (status != PEP_STATUS_OK)
vb@63
   418
            goto pep_error;
vb@63
   419
vb@37
   420
        if (_il->ident->fpr) {
vb@39
   421
            dest_keys_found = true;
vb@39
   422
            _k = stringlist_add(_k, _il->ident->fpr);
vb@63
   423
            if (_k == NULL)
vb@63
   424
                goto enomem;
vb@37
   425
        }
vb@37
   426
        else
vb@37
   427
            status = PEP_KEY_NOT_FOUND;
vb@37
   428
    }
vb@37
   429
vb@39
   430
    if (dest_keys_found) {
vb@38
   431
        char *ptext;
vb@37
   432
        char *ctext = NULL;
vb@37
   433
        size_t csize = 0;
vb@37
   434
vb@81
   435
        switch (enc_format) {
vb@112
   436
        case PEP_enc_PGP_MIME: {
vb@62
   437
            bool free_ptext = false;
vb@64
   438
vb@112
   439
            msg->enc_format = PEP_enc_PGP_MIME;
vb@37
   440
vb@113
   441
            if (src->mime == PEP_MIME) {
vb@113
   442
                message *_src = NULL;
vb@113
   443
                assert(src->longmsg);
vb@113
   444
                status = mime_decode_message(src->longmsg, &_src);
vb@113
   445
                if (status != PEP_STATUS_OK)
vb@113
   446
                    goto pep_error;
vb@113
   447
                if (free_src)
vb@113
   448
                    free_message(src);
vb@113
   449
                src = _src;
vb@113
   450
                free_src = true;
vb@62
   451
            }
vb@62
   452
vb@113
   453
            if (src->mime == PEP_MIME_none) {
vb@113
   454
                if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0) {
vb@113
   455
                    ptext = combine_short_and_long(src->shortmsg, src->longmsg);
vb@113
   456
                    if (ptext == NULL)
vb@113
   457
                        goto enomem;
vb@113
   458
                    free_ptext = true;
vb@113
   459
                }
vb@113
   460
                else if (src->longmsg) {
vb@113
   461
                    ptext = src->longmsg;
vb@113
   462
                }
vb@125
   463
                else {
vb@125
   464
                    ptext = "pEp";
vb@125
   465
                }
vb@113
   466
vb@113
   467
                message *_src = calloc(1, sizeof(message));
vb@89
   468
                assert(_src);
vb@89
   469
                if (_src == NULL)
vb@89
   470
                    goto enomem;
vb@89
   471
                _src->longmsg = ptext;
vb@113
   472
                _src->longmsg_formatted = src->longmsg_formatted;
vb@113
   473
                _src->attachments = src->attachments;
vb@113
   474
                _src->enc_format = PEP_enc_PGP_MIME;
vb@113
   475
                status = mime_encode_message(_src, true, &ptext);
vb@67
   476
                assert(status == PEP_STATUS_OK);
vb@67
   477
                if (free_ptext)
vb@89
   478
                    free(_src->longmsg);
vb@89
   479
                free(_src);
vb@67
   480
                assert(ptext);
vb@67
   481
                if (ptext == NULL)
vb@67
   482
                    goto pep_error;
vb@67
   483
                free_ptext = true;
vb@67
   484
            }
vb@113
   485
            else /* if (src->mime == PEP_MIME_fields_omitted) */ {
vb@67
   486
                ptext = src->longmsg;
vb@67
   487
            }
vb@67
   488
vb@67
   489
            status = encrypt_and_sign(session, keys, ptext, strlen(ptext),
vb@67
   490
                    &ctext, &csize);
vb@62
   491
            if (free_ptext)
vb@62
   492
                free(ptext);
vb@113
   493
            if (ctext == NULL)
vb@63
   494
                goto pep_error;
vb@113
   495
vb@113
   496
            msg->longmsg = strdup(ctext);
vb@113
   497
            if (msg->longmsg == NULL)
vb@113
   498
                goto enomem;
vb@62
   499
        }
vb@63
   500
        break;
vb@62
   501
vb@62
   502
        case PEP_enc_pieces:
vb@64
   503
            msg->enc_format = PEP_enc_pieces;
vb@64
   504
vb@63
   505
            if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0) {
vb@83
   506
                ptext = combine_short_and_long(src->shortmsg, src->longmsg);
vb@63
   507
                if (ptext == NULL)
vb@63
   508
                    goto enomem;
vb@63
   509
vb@39
   510
                status = encrypt_and_sign(session, keys, ptext, strlen(ptext),
vb@39
   511
                        &ctext, &csize);
vb@40
   512
                free(ptext);
vb@38
   513
                if (ctext) {
vb@40
   514
                    msg->longmsg = strdup(ctext);
vb@64
   515
                    if (msg->longmsg == NULL)
vb@63
   516
                        goto enomem;
vb@38
   517
                }
vb@38
   518
                else {
vb@63
   519
                    goto pep_error;
vb@38
   520
                }
vb@38
   521
            }
vb@38
   522
            else if (src->longmsg) {
vb@38
   523
                ptext = src->longmsg;
vb@39
   524
                status = encrypt_and_sign(session, keys, ptext, strlen(ptext),
vb@39
   525
                        &ctext, &csize);
vb@38
   526
                if (ctext) {
vb@40
   527
                    msg->longmsg = strdup(ctext);
vb@64
   528
                    if (msg->longmsg == NULL)
vb@63
   529
                        goto enomem;
vb@38
   530
                }
vb@38
   531
                else {
vb@63
   532
                    goto pep_error;
vb@38
   533
                }
vb@38
   534
            }
vb@63
   535
vb@63
   536
            if (msg->longmsg_formatted) {
vb@38
   537
                ptext = src->longmsg_formatted;
vb@39
   538
                status = encrypt_and_sign(session, keys, ptext, strlen(ptext),
vb@39
   539
                        &ctext, &csize);
vb@38
   540
                if (ctext) {
vb@40
   541
                    msg->longmsg_formatted = strdup(ctext);
vb@63
   542
                    if (msg->longmsg_formatted == NULL)
vb@63
   543
                        goto enomem;
vb@63
   544
                }
vb@63
   545
                else {
vb@63
   546
                    goto pep_error;
vb@63
   547
                }
vb@63
   548
            }
vb@63
   549
vb@63
   550
            if (src->attachments) {
vb@63
   551
                bloblist_t *_s;
vb@63
   552
                bloblist_t *_d = new_bloblist(NULL, 0, NULL, NULL);
vb@63
   553
                if (_d == NULL)
vb@63
   554
                    goto enomem;
vb@63
   555
vb@63
   556
                msg->attachments = _d;
vb@63
   557
                for (_s = src->attachments; _s && _s->data; _s = _s->next) {
vb@63
   558
                    int psize = _s->size;
vb@63
   559
                    ptext = _s->data;
vb@63
   560
                    status = encrypt_and_sign(session, keys, ptext, psize,
vb@63
   561
                            &ctext, &csize);
vb@63
   562
                    if (ctext) {
vb@63
   563
                        char * _c = strdup(ctext);
vb@63
   564
                        if (_c == NULL)
vb@63
   565
                            goto enomem;
vb@63
   566
vb@63
   567
                        _d = bloblist_add(_d, _c, csize, _s->mime_type,
vb@113
   568
                                _s->filename);
vb@63
   569
                        if (_d == NULL)
vb@63
   570
                            goto enomem;
vb@63
   571
                    }
vb@63
   572
                    else {
vb@63
   573
                        goto pep_error;
vb@40
   574
                    }
vb@38
   575
                }
vb@38
   576
            }
vb@38
   577
            break;
vb@38
   578
vb@81
   579
        case PEP_enc_PEP:
vb@81
   580
            // TODO: implement
vb@81
   581
            NOT_IMPLEMENTED
vb@81
   582
vb@38
   583
        default:
vb@38
   584
            assert(0);
vb@63
   585
            status = PEP_ILLEGAL_VALUE;
vb@63
   586
            goto pep_error;
vb@37
   587
        }
vb@37
   588
    }
vb@37
   589
vb@37
   590
    free_stringlist(keys);
vb@113
   591
    if (free_src)
vb@113
   592
        free_message(src);
vb@63
   593
vb@64
   594
    if (msg->shortmsg == NULL)
vb@64
   595
        msg->shortmsg = strdup("pEp");
vb@64
   596
vb@236
   597
    attach_own_key(session, msg);
vb@235
   598
vb@63
   599
    *dst = msg;
vb@63
   600
    return PEP_STATUS_OK;
vb@63
   601
vb@63
   602
enomem:
vb@63
   603
    status = PEP_OUT_OF_MEMORY;
vb@63
   604
vb@63
   605
pep_error:
vb@63
   606
    free_stringlist(keys);
vb@63
   607
    free_message(msg);
vb@113
   608
    if (free_src)
vb@113
   609
        free_message(src);
vb@63
   610
vb@37
   611
    return status;
vb@37
   612
}
vb@37
   613
vb@113
   614
static bool is_encrypted_attachment(const bloblist_t *blob)
vb@113
   615
{
vb@113
   616
    char *ext;
vb@113
   617
 
vb@113
   618
    assert(blob);
vb@113
   619
vb@113
   620
    if (blob->filename == NULL)
vb@113
   621
        return false;
vb@113
   622
vb@113
   623
    ext = strrchr(blob->filename, '.');
vb@113
   624
    if (ext == NULL)
vb@113
   625
        return false;
vb@113
   626
vb@113
   627
    if (strcmp(blob->mime_type, "application/octet-stream")) {
vb@113
   628
        if (strcmp(ext, ".pgp") == 0 || strcmp(ext, ".gpg") == 0 ||
vb@113
   629
                strcmp(ext, ".asc") == 0)
vb@113
   630
            return true;
vb@113
   631
    }
vb@164
   632
    else if (strcmp(blob->mime_type, "text/plain")) {
vb@113
   633
        if (strcmp(ext, ".asc") == 0)
vb@113
   634
            return true;
vb@113
   635
    }
vb@113
   636
vb@113
   637
    return false;
vb@113
   638
}
vb@113
   639
vb@113
   640
static bool is_encrypted_html_attachment(const bloblist_t *blob)
vb@113
   641
{
vb@113
   642
    assert(blob);
vb@113
   643
    assert(blob->filename);
vb@113
   644
vb@113
   645
    if (strncmp(blob->filename, "PGPexch.htm.", 12) == 0) {
vb@113
   646
        if (strcmp(blob->filename + 11, ".pgp") == 0 ||
vb@113
   647
                strcmp(blob->filename + 11, ".asc") == 0)
vb@113
   648
            return true;
vb@113
   649
    }
vb@113
   650
vb@113
   651
    return false;
vb@113
   652
}
vb@113
   653
vb@159
   654
static char * without_double_ending(const char *filename)
vb@113
   655
{
vb@113
   656
    char *ext;
vb@113
   657
vb@113
   658
    assert(filename);
vb@113
   659
vb@113
   660
    ext = strrchr(filename, '.');
vb@113
   661
    if (ext == NULL)
vb@113
   662
        return NULL;
vb@113
   663
vb@113
   664
    return strndup(filename, ext - filename);
vb@113
   665
}
vb@113
   666
vb@251
   667
static PEP_color decrypt_color(PEP_STATUS status)
vb@251
   668
{
vb@251
   669
    switch (status) {
vb@251
   670
        case PEP_UNENCRYPTED:
vb@251
   671
        case PEP_VERIFIED:
vb@251
   672
        case PEP_VERIFY_NO_KEY:
vb@251
   673
        case PEP_VERIFIED_AND_TRUSTED:
vb@251
   674
            return PEP_rating_unencrypted;
vb@251
   675
vb@251
   676
        case PEP_DECRYPTED:
vb@251
   677
            return PEP_rating_unreliable;
vb@251
   678
vb@251
   679
        case PEP_DECRYPTED_AND_VERIFIED:
vb@251
   680
            return PEP_rating_reliable;
vb@251
   681
vb@251
   682
        case PEP_DECRYPT_WRONG_FORMAT:
vb@251
   683
        case PEP_DECRYPT_NO_KEY:
vb@251
   684
        case PEP_CANNOT_DECRYPT_UNKNOWN:
vb@251
   685
            return PEP_rating_cannot_decrypt;
vb@251
   686
vb@251
   687
        default:
vb@251
   688
            return PEP_rating_undefined;
vb@251
   689
    }
vb@251
   690
}
vb@251
   691
vb@251
   692
static PEP_color _rating(PEP_comm_type ct)
vb@251
   693
{
vb@251
   694
    if (ct == PEP_ct_unknown)
vb@251
   695
        return PEP_rating_undefined;
vb@251
   696
vb@251
   697
    else if (ct == PEP_ct_compromized)
vb@251
   698
        return PEP_rating_under_attack;
vb@251
   699
vb@251
   700
    else if (ct >= PEP_ct_confirmed_enc_anon)
vb@251
   701
        return PEP_rating_trusted_and_anonymized;
vb@251
   702
vb@251
   703
    else if (ct >= PEP_ct_strong_encryption)
vb@251
   704
        return PEP_rating_trusted;
vb@251
   705
vb@251
   706
    else if (ct >= PEP_ct_strong_but_unconfirmed && ct < PEP_ct_confirmed)
vb@251
   707
        return PEP_rating_reliable;
vb@251
   708
    
vb@251
   709
    else if (ct == PEP_ct_no_encryption || ct == PEP_ct_no_encrypted_channel)
vb@251
   710
        return PEP_rating_unencrypted;
vb@251
   711
vb@251
   712
    else
vb@251
   713
        return PEP_rating_unreliable;
vb@251
   714
}
vb@251
   715
vb@251
   716
static PEP_color key_color(PEP_SESSION session, const char *fpr) {
vb@251
   717
    PEP_comm_type comm_type = PEP_ct_unknown;
vb@251
   718
vb@251
   719
    assert(session);
vb@251
   720
    assert(fpr);
vb@251
   721
vb@251
   722
    PEP_STATUS status = get_key_rating(session, fpr, &comm_type);
vb@251
   723
    if (status != PEP_STATUS_OK)
vb@251
   724
        return PEP_rating_undefined;
vb@251
   725
vb@251
   726
    return _rating(comm_type);
vb@251
   727
}
vb@251
   728
vb@251
   729
static PEP_color keylist_color(PEP_SESSION session, stringlist_t *keylist)
vb@251
   730
{
vb@251
   731
    PEP_color color = PEP_rating_reliable;
vb@251
   732
vb@251
   733
    assert(keylist && keylist->value);
vb@251
   734
    if (keylist == NULL || keylist->value == NULL)
vb@251
   735
        return PEP_rating_unencrypted;
vb@251
   736
vb@251
   737
    stringlist_t *_kl;
vb@251
   738
    for (_kl = keylist; _kl && _kl->value; _kl = _kl->next) {
vb@251
   739
        PEP_comm_type ct;
vb@251
   740
        PEP_STATUS status;
vb@251
   741
        PEP_color _color;
vb@251
   742
vb@251
   743
        _color = key_color(session, _kl->value);
vb@251
   744
        if (_color == PEP_rating_under_attack)
vb@251
   745
            return PEP_rating_under_attack;
vb@251
   746
vb@251
   747
        color = MIN(color, _color);
vb@251
   748
vb@251
   749
        status = least_trust(session, _kl->value, &ct);
vb@251
   750
        if (status != PEP_STATUS_OK)
vb@251
   751
            return PEP_rating_undefined;
vb@251
   752
vb@251
   753
        _color = _rating(ct);
vb@251
   754
        if (_color == PEP_rating_under_attack)
vb@251
   755
            return PEP_rating_under_attack;
vb@251
   756
vb@251
   757
        color = MIN(color, _color);
vb@251
   758
    }
vb@251
   759
vb@251
   760
    return color;
vb@251
   761
}
vb@251
   762
vb@48
   763
DYNAMIC_API PEP_STATUS decrypt_message(
vb@37
   764
        PEP_SESSION session,
vb@113
   765
        message *src,
vb@113
   766
        PEP_MIME_format mime,
vb@241
   767
        message **dst,
vb@251
   768
        stringlist_t **keylist,
vb@251
   769
        PEP_color *color
vb@37
   770
    )
vb@37
   771
{
vb@37
   772
    PEP_STATUS status = PEP_STATUS_OK;
vb@73
   773
    message *msg = NULL;
vb@112
   774
    char *ctext;
vb@112
   775
    size_t csize;
vb@112
   776
    char *ptext;
vb@112
   777
    size_t psize;
vb@241
   778
    stringlist_t *_keylist = NULL;
vb@113
   779
    bool free_src = false;
vb@37
   780
vb@74
   781
    assert(session);
vb@74
   782
    assert(src);
vb@74
   783
    assert(dst);
vb@241
   784
    assert(keylist);
vb@251
   785
    assert(color);
vb@73
   786
vb@251
   787
    if (!(session && src && dst && keylist && color))
vb@191
   788
        return PEP_ILLEGAL_VALUE;
vb@191
   789
vb@74
   790
    *dst = NULL;
vb@251
   791
    *keylist = NULL;
vb@251
   792
    *color = PEP_rating_undefined;
vb@81
   793
 
vb@250
   794
    determine_encryption_format(src);
vb@235
   795
    import_attached_keys(session, src);
vb@235
   796
vb@113
   797
    if (src->mime == PEP_MIME_fields_omitted || src->mime == PEP_MIME) {
vb@113
   798
        message *_src = NULL;
vb@113
   799
        status = mime_decode_message(src->longmsg, &_src);
vb@113
   800
        if (status != PEP_STATUS_OK)
vb@113
   801
            goto pep_error;
vb@81
   802
vb@113
   803
        if ( src->mime == PEP_MIME_fields_omitted) {
vb@113
   804
            status = copy_fields(_src, src);
vb@113
   805
            if (status != PEP_STATUS_OK) {
vb@113
   806
                free_message(_src);
vb@113
   807
                goto pep_error;
vb@113
   808
            }
vb@113
   809
        }
vb@113
   810
vb@113
   811
        src = _src;
vb@113
   812
        free_src = true;
vb@113
   813
    }
vb@113
   814
vb@119
   815
    // src message is not MIME encoded (any more)
vb@113
   816
    assert(src->mime == PEP_MIME_none);
vb@113
   817
vb@117
   818
    if (!is_PGP_message_text(src->longmsg)) {
vb@117
   819
        status = PEP_UNENCRYPTED;
vb@117
   820
        goto pep_error;
vb@117
   821
    }
vb@117
   822
vb@113
   823
    ctext = src->longmsg;
vb@113
   824
    csize = strlen(src->longmsg);
vb@113
   825
vb@113
   826
    status = decrypt_and_verify(session, ctext, csize, &ptext, &psize,
vb@241
   827
            &_keylist);
vb@251
   828
    *color = decrypt_color(status);
vb@113
   829
    if (ptext == NULL)
vb@113
   830
        goto pep_error;
vb@113
   831
vb@251
   832
    if (*color != PEP_rating_under_attack) {
vb@251
   833
        PEP_color _color = keylist_color(session, _keylist);
vb@251
   834
        if (_color == PEP_rating_under_attack)
vb@251
   835
            *color = PEP_rating_under_attack;
vb@251
   836
        else
vb@251
   837
            *color = MIN(*color, _color);
vb@251
   838
    }
vb@251
   839
vb@113
   840
    switch (src->enc_format) {
vb@113
   841
        case PEP_enc_PGP_MIME:
vb@113
   842
            status = mime_decode_message(ptext, &msg);
vb@113
   843
            if (status != PEP_STATUS_OK)
vb@113
   844
                goto pep_error;
vb@113
   845
vb@113
   846
            break;
vb@113
   847
vb@113
   848
        case PEP_enc_pieces:
vb@113
   849
            msg = clone_to_empty_message(src);
vb@113
   850
            if (msg == NULL)
vb@113
   851
                goto enomem;
vb@113
   852
vb@113
   853
            msg->longmsg = strdup(ptext);
vb@113
   854
            if (msg->longmsg == NULL)
vb@113
   855
                goto enomem;
vb@113
   856
vb@113
   857
            bloblist_t *_m = msg->attachments;
vb@113
   858
            bloblist_t *_s;
vb@113
   859
            for (_s = src->attachments; _s; _s = _s->next) {
vb@113
   860
                if (is_encrypted_attachment(_s)) {
vb@241
   861
                    stringlist_t *_keylist = NULL;
vb@113
   862
                    ctext = _s->data;
vb@113
   863
                    csize = _s->size;
vb@113
   864
vb@113
   865
                    status = decrypt_and_verify(session, ctext, csize, &ptext,
vb@241
   866
                            &psize, &_keylist);
vb@113
   867
                    if (ptext == NULL)
vb@113
   868
                        goto pep_error;
vb@241
   869
                    free_stringlist(_keylist);
vb@241
   870
vb@113
   871
                    if (is_encrypted_html_attachment(_s)) {
vb@113
   872
                        msg->longmsg_formatted = strdup(ptext);
vb@113
   873
                        if (msg->longmsg_formatted == NULL)
vb@113
   874
                            goto pep_error;
vb@113
   875
                    }
vb@113
   876
                    else {
vb@113
   877
                        char * mime_type = "application/octet-stream";
vb@113
   878
                        char * filename = without_double_ending(_s->filename);
vb@113
   879
                        if (filename == NULL)
vb@113
   880
                            goto enomem;
vb@113
   881
vb@113
   882
                        _m = bloblist_add(_m, ptext, psize, mime_type, filename);
vb@113
   883
                        if (_m == NULL)
vb@113
   884
                            goto enomem;
vb@113
   885
vb@113
   886
                       if (msg->attachments == NULL)
vb@113
   887
                            msg->attachments = _m;
vb@113
   888
                    }
vb@113
   889
                }
vb@82
   890
            }
vb@82
   891
vb@81
   892
            break;
vb@81
   893
vb@81
   894
        default:
vb@113
   895
            // BUG: must implement more
vb@113
   896
            NOT_IMPLEMENTED
vb@81
   897
    }
vb@74
   898
vb@113
   899
    switch (src->enc_format) {
vb@113
   900
        case PEP_enc_PGP_MIME:
vb@113
   901
        case PEP_enc_pieces:
vb@113
   902
            status = copy_fields(msg, src);
vb@113
   903
            if (status != PEP_STATUS_OK)
vb@113
   904
                goto pep_error;
vb@113
   905
vb@166
   906
            if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0) {
vb@113
   907
                free(msg->shortmsg);
vb@113
   908
                msg->shortmsg = strdup(src->shortmsg);
vb@113
   909
                if (msg->shortmsg == NULL)
vb@113
   910
                    goto enomem;
vb@113
   911
            }
vb@113
   912
vb@113
   913
            if (msg->shortmsg == NULL || strcmp(msg->shortmsg, "pEp") == 0)
vb@113
   914
            {
vb@113
   915
                char * shortmsg;
vb@113
   916
                char * longmsg;
vb@113
   917
vb@113
   918
                int r = seperate_short_and_long(msg->longmsg, &shortmsg,
vb@113
   919
                        &longmsg);
vb@113
   920
                if (r == -1)
vb@113
   921
                    goto enomem;
vb@113
   922
vb@113
   923
                free(msg->shortmsg);
vb@113
   924
                free(msg->longmsg);
vb@113
   925
vb@113
   926
                msg->shortmsg = shortmsg;
vb@113
   927
                msg->longmsg = longmsg;
vb@113
   928
            }
vb@113
   929
            else {
vb@113
   930
                msg->shortmsg = strdup(src->shortmsg);
vb@113
   931
                if (msg->shortmsg == NULL)
vb@113
   932
                    goto enomem;
vb@113
   933
                msg->longmsg = ptext;
vb@113
   934
            }
vb@166
   935
            break;
vb@113
   936
vb@113
   937
        default:
vb@113
   938
            // BUG: must implement more
vb@113
   939
            NOT_IMPLEMENTED
vb@113
   940
    }
vb@113
   941
vb@113
   942
    switch (mime) {
vb@113
   943
        case PEP_MIME_none:
vb@113
   944
            break;
vb@113
   945
vb@113
   946
        case PEP_MIME:
vb@113
   947
        case PEP_MIME_fields_omitted:
vb@113
   948
            {
vb@113
   949
                char *text = NULL;
vb@113
   950
                status = mime_encode_message(msg,
vb@113
   951
                        mime == PEP_MIME_fields_omitted, &text);
vb@113
   952
                if (status != PEP_STATUS_OK)
vb@113
   953
                    goto pep_error;
vb@113
   954
vb@113
   955
                message *_msg = clone_to_empty_message(msg);
vb@113
   956
                if (_msg == NULL) {
vb@113
   957
                    free(text);
vb@113
   958
                    goto enomem;
vb@113
   959
                }
vb@113
   960
                _msg->longmsg = text;
vb@113
   961
                _msg->shortmsg = strdup(msg->shortmsg);
vb@113
   962
                if (msg->shortmsg == NULL)
vb@113
   963
                    goto enomem;
vb@113
   964
vb@113
   965
                free_message(msg);
vb@113
   966
                msg = _msg;
vb@113
   967
            }
vb@167
   968
            break;
vb@113
   969
    }
vb@113
   970
vb@113
   971
    if (free_src)
vb@113
   972
        free_message(src);
vb@235
   973
vb@235
   974
    import_attached_keys(session, msg);
vb@235
   975
vb@74
   976
    *dst = msg;
vb@241
   977
    *keylist = _keylist;
vb@241
   978
vb@74
   979
    return PEP_STATUS_OK;
vb@73
   980
vb@73
   981
enomem:
vb@73
   982
    status = PEP_OUT_OF_MEMORY;
vb@73
   983
vb@73
   984
pep_error:
vb@73
   985
    free_message(msg);
vb@241
   986
    free_stringlist(_keylist);
vb@113
   987
    if (free_src)
vb@113
   988
        free_message(src);
vb@39
   989
vb@37
   990
    return status;
vb@37
   991
}
vb@37
   992
vb@190
   993
static PEP_comm_type _get_comm_type(
vb@190
   994
        PEP_SESSION session,
vb@190
   995
        PEP_comm_type max_comm_type,
vb@190
   996
        pEp_identity *ident
vb@190
   997
    )
vb@190
   998
{
vb@190
   999
    PEP_STATUS status = update_identity(session, ident);
vb@190
  1000
vb@190
  1001
    if (max_comm_type == PEP_ct_compromized)
vb@190
  1002
        return PEP_ct_compromized;
vb@190
  1003
vb@190
  1004
    if (status == PEP_STATUS_OK) {
vb@190
  1005
        if (ident->comm_type == PEP_ct_compromized)
vb@190
  1006
            return PEP_ct_compromized;
vb@190
  1007
        else
vb@190
  1008
            return MIN(max_comm_type, ident->comm_type);
vb@190
  1009
    }
vb@190
  1010
    else {
vb@190
  1011
        return PEP_ct_unknown;
vb@190
  1012
    }
vb@190
  1013
}
vb@190
  1014
vb@251
  1015
DYNAMIC_API PEP_STATUS outgoing_message_color(
vb@190
  1016
        PEP_SESSION session,
vb@190
  1017
        message *msg,
vb@232
  1018
        PEP_color *color
vb@190
  1019
    )
vb@190
  1020
{
vb@190
  1021
    PEP_STATUS status = PEP_STATUS_OK;
vb@190
  1022
    PEP_comm_type max_comm_type = PEP_ct_pEp;
vb@190
  1023
    bool comm_type_determined = false;
vb@190
  1024
    identity_list * il;
vb@190
  1025
vb@190
  1026
    assert(session);
vb@190
  1027
    assert(msg);
vb@251
  1028
    assert(msg->from);
vb@251
  1029
    assert(msg->dir == PEP_dir_outgoing);
vb@190
  1030
    assert(color);
vb@190
  1031
vb@191
  1032
    if (!(session && msg && color))
vb@191
  1033
        return PEP_ILLEGAL_VALUE;
vb@191
  1034
vb@251
  1035
    if (msg->from == NULL || msg->dir != PEP_dir_outgoing)
vb@251
  1036
        return PEP_ILLEGAL_VALUE;
vb@251
  1037
vb@237
  1038
    *color = PEP_rating_undefined;
vb@190
  1039
vb@190
  1040
    assert(msg->from);
vb@190
  1041
    if (msg->from == NULL)
vb@190
  1042
        return PEP_ILLEGAL_VALUE;
vb@190
  1043
vb@251
  1044
    status = myself(session, msg->from);
vb@251
  1045
    if (status != PEP_STATUS_OK)
vb@251
  1046
        return status;
vb@251
  1047
vb@251
  1048
    for (il = msg->to; il != NULL; il = il->next) {
vb@251
  1049
        if (il->ident) {
vb@251
  1050
            max_comm_type = _get_comm_type(session, max_comm_type,
vb@251
  1051
                    il->ident);
vb@190
  1052
            comm_type_determined = true;
vb@251
  1053
        }
vb@251
  1054
    }
vb@190
  1055
vb@251
  1056
    for (il = msg->cc; il != NULL; il = il->next) {
vb@251
  1057
        if (il->ident) {
vb@251
  1058
            max_comm_type = _get_comm_type(session, max_comm_type,
vb@251
  1059
                    il->ident);
vb@251
  1060
            comm_type_determined = true;
vb@251
  1061
        }
vb@190
  1062
    }
vb@190
  1063
vb@190
  1064
    if (comm_type_determined == false)
vb@237
  1065
        *color = PEP_rating_undefined;
vb@190
  1066
    else
vb@239
  1067
        *color = _rating(max_comm_type);
vb@190
  1068
vb@190
  1069
    return PEP_STATUS_OK;
vb@190
  1070
}
vb@190
  1071
vb@240
  1072
DYNAMIC_API PEP_STATUS identity_color(
vb@239
  1073
        PEP_SESSION session,
vb@239
  1074
        pEp_identity *ident,
vb@239
  1075
        PEP_color *color
vb@239
  1076
    )
vb@239
  1077
{
vb@239
  1078
    PEP_STATUS status = PEP_STATUS_OK;
vb@239
  1079
vb@239
  1080
    assert(session);
vb@239
  1081
    assert(ident);
vb@239
  1082
    assert(color);
vb@239
  1083
vb@239
  1084
    if (!(session && ident && color))
vb@239
  1085
        return PEP_ILLEGAL_VALUE;
vb@239
  1086
vb@239
  1087
    if (ident->me)
vb@239
  1088
        status = myself(session, ident);
vb@239
  1089
    else
vb@239
  1090
        status = update_identity(session, ident);
vb@239
  1091
vb@239
  1092
    if (status == PEP_STATUS_OK)
vb@239
  1093
        *color = _rating(ident->comm_type);
vb@239
  1094
vb@239
  1095
    return status;
vb@239
  1096
}
vb@239
  1097