src/pgp_netpgp.c
author Edouard Tisserant
Wed, 08 Apr 2015 22:51:03 +0200
changeset 184 da3973ecb7b6
parent 183 e83ac06e2d6d
child 185 f3142e40d9e7
permissions -rw-r--r--
netpgp : safer dereferencing valid sig list
Edouard@174
     1
#include "pEp_internal.h"
Edouard@174
     2
#include "pgp_netpgp.h"
Edouard@174
     3
Edouard@174
     4
#include <limits.h>
Edouard@174
     5
Edouard@174
     6
#include "wrappers.h"
Edouard@174
     7
Edouard@174
     8
#include <netpgp.h>
Edouard@179
     9
#include <netpgp/config.h>
Edouard@179
    10
#include <netpgp/memory.h>
Edouard@179
    11
#include <netpgp/crypto.h>
Edouard@180
    12
#include <netpgp/netpgpsdk.h>
Edouard@180
    13
#include <netpgp/validate.h>
Edouard@179
    14
Edouard@174
    15
PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
Edouard@174
    16
{
Edouard@179
    17
    netpgp_t *netpgp;
Edouard@174
    18
    PEP_STATUS status = PEP_STATUS_OK;
Edouard@175
    19
    const char *home = NULL;
Edouard@179
    20
Edouard@179
    21
    assert(session);
Edouard@179
    22
    if(!session) return PEP_UNKNOWN_ERROR;
Edouard@179
    23
Edouard@179
    24
    netpgp = &session->ctx;
Edouard@174
    25
   
Edouard@174
    26
    if (in_first) {
Edouard@175
    27
        if (strcmp(setlocale(LC_ALL, NULL), "C") == 0)
Edouard@175
    28
            setlocale(LC_ALL, "");
Edouard@174
    29
    }
Edouard@174
    30
Edouard@179
    31
	memset(netpgp, 0x0, sizeof(session->ctx));
Edouard@174
    32
Edouard@180
    33
    // netpgp_setvar(netpgp, "max mem alloc", "4194304");
Edouard@180
    34
    netpgp_setvar(netpgp, "need seckey", "1");
Edouard@180
    35
    netpgp_setvar(netpgp, "need userid", "1");
Edouard@180
    36
Edouard@175
    37
    // NetPGP shares home with GPG
Edouard@175
    38
    home = gpg_home();
Edouard@175
    39
    if(home){
Edouard@179
    40
        netpgp_set_homedir(netpgp,(char*)home, NULL, 0);
Edouard@175
    41
    }else{
Edouard@175
    42
        status = PEP_INIT_NO_GPG_HOME;
Edouard@175
    43
        goto pep_error;
Edouard@174
    44
    }
Edouard@174
    45
Edouard@175
    46
    // pair with gpg's cert-digest-algo
Edouard@179
    47
	netpgp_setvar(netpgp, "hash", "SHA256");
Edouard@175
    48
Edouard@175
    49
    // subset of gpg's personal-cipher-preferences
Edouard@175
    50
    // here only one cipher can be selected
Edouard@179
    51
    netpgp_setvar(netpgp, "cipher", "AES256");
Edouard@175
    52
Edouard@179
    53
	if (!netpgp_init(netpgp)) {
Edouard@175
    54
        status = PEP_INIT_NETPGP_INIT_FAILED;
Edouard@174
    55
        goto pep_error;
Edouard@174
    56
    }
Edouard@174
    57
Edouard@174
    58
    return PEP_STATUS_OK;
Edouard@174
    59
Edouard@174
    60
pep_error:
Edouard@174
    61
    pgp_release(session, in_first);
Edouard@174
    62
    return status;
Edouard@174
    63
}
Edouard@174
    64
Edouard@174
    65
void pgp_release(PEP_SESSION session, bool out_last)
Edouard@174
    66
{
Edouard@179
    67
    netpgp_t *netpgp;
Edouard@179
    68
Edouard@179
    69
    assert(session);
Edouard@179
    70
    if(!session) return;
Edouard@179
    71
Edouard@179
    72
    netpgp = &session->ctx;
Edouard@179
    73
Edouard@179
    74
	netpgp_end(netpgp);
Edouard@179
    75
	memset(netpgp, 0x0, sizeof(session->ctx));
Edouard@174
    76
Edouard@175
    77
    // out_last unused here
Edouard@174
    78
}
Edouard@174
    79
Edouard@174
    80
PEP_STATUS pgp_decrypt_and_verify(
Edouard@174
    81
    PEP_SESSION session, const char *ctext, size_t csize,
Edouard@174
    82
    char **ptext, size_t *psize, stringlist_t **keylist
Edouard@174
    83
    )
Edouard@174
    84
{
Edouard@179
    85
    netpgp_t *netpgp;
Edouard@179
    86
	pgp_memory_t *mem;
Edouard@180
    87
	pgp_memory_t *cat;
Edouard@183
    88
	pgp_validation_t *vresult;
Edouard@179
    89
	pgp_io_t *io;
Edouard@180
    90
    char *_ptext = NULL;
Edouard@180
    91
    size_t _psize = 0;
Edouard@180
    92
	int ret;
Edouard@179
    93
Edouard@174
    94
    PEP_STATUS result;
Edouard@174
    95
    stringlist_t *_keylist = NULL;
Edouard@174
    96
    int i_key = 0;
Edouard@174
    97
Edouard@174
    98
    assert(session);
Edouard@174
    99
    assert(ctext);
Edouard@174
   100
    assert(csize);
Edouard@174
   101
    assert(ptext);
Edouard@174
   102
    assert(psize);
Edouard@174
   103
    assert(keylist);
Edouard@174
   104
Edouard@179
   105
    if(!session || !ctext || !csize || !ptext || !psize || !keylist) 
Edouard@179
   106
        return PEP_UNKNOWN_ERROR;
Edouard@179
   107
Edouard@179
   108
    netpgp = &session->ctx;
Edouard@179
   109
	io = netpgp->io;
Edouard@179
   110
Edouard@174
   111
    *ptext = NULL;
Edouard@174
   112
    *psize = 0;
Edouard@174
   113
    *keylist = NULL;
Edouard@174
   114
Edouard@183
   115
    vresult = malloc(sizeof(pgp_validation_t));
Edouard@183
   116
	memset(vresult, 0x0, sizeof(pgp_validation_t));
Edouard@182
   117
Edouard@183
   118
    mem = pgp_decrypt_and_validate_buf(netpgp->io, vresult, ctext, csize,
Edouard@179
   119
                netpgp->secring, netpgp->pubring,
Edouard@179
   120
                1 /* armoured */,
Edouard@179
   121
                0 /* sshkeys */,
Edouard@180
   122
                NULL, -1, NULL  /* pass fp,attempts,cb */);
Edouard@179
   123
    if (mem == NULL) {
Edouard@179
   124
        return PEP_OUT_OF_MEMORY;
Edouard@179
   125
    }
Edouard@179
   126
Edouard@180
   127
	_psize = pgp_mem_len(mem);
Edouard@182
   128
    if (_psize){
Edouard@182
   129
        if ((_ptext = calloc(1, _psize)) == NULL) {
Edouard@183
   130
            result = PEP_OUT_OF_MEMORY;
Edouard@183
   131
            goto free_pgp;
Edouard@182
   132
        }
Edouard@183
   133
	    memcpy(_ptext, pgp_mem_data(mem), _psize);
Edouard@182
   134
        result = PEP_DECRYPTED;
Edouard@182
   135
    }else{
Edouard@183
   136
        result = PEP_DECRYPT_NO_KEY;
Edouard@183
   137
        goto free_pgp;
Edouard@182
   138
    }
Edouard@180
   139
Edouard@183
   140
    if (result == PEP_DECRYPTED &&
Edouard@184
   141
        vresult->validc && vresult->valid_sigs &&
Edouard@184
   142
        !vresult->invalidc && !vresult->unknownc ) {
Edouard@183
   143
        unsigned	n;
Edouard@183
   144
        stringlist_t *k;
Edouard@183
   145
        _keylist = new_stringlist(NULL);
Edouard@183
   146
        assert(_keylist);
Edouard@183
   147
        if (_keylist == NULL) {
Edouard@183
   148
            result = PEP_OUT_OF_MEMORY;
Edouard@183
   149
            goto free_keylist;
Edouard@183
   150
        }
Edouard@183
   151
        k = _keylist;
Edouard@183
   152
        for (n = 0; n < vresult->validc; ++n) {
Edouard@183
   153
            int i;
Edouard@183
   154
            static const char *hexes = "0123456789abcdef";
Edouard@184
   155
            char id[MAX_ID_LENGTH + 1];
Edouard@183
   156
            const uint8_t *userid = vresult->valid_sigs[n].signer_id;
Edouard@180
   157
Edouard@183
   158
            for (i = 0; i < 8 ; i++) {
Edouard@183
   159
                id[i * 2] = hexes[(unsigned)(userid[i] & 0xf0) >> 4];
Edouard@183
   160
                id[(i * 2) + 1] = hexes[userid[i] & 0xf];
Edouard@183
   161
            }
Edouard@183
   162
            id[8 * 2] = 0x0;
Edouard@183
   163
            k = stringlist_add(k, id);
Edouard@183
   164
        }
Edouard@180
   165
        result = PEP_DECRYPTED_AND_VERIFIED;
Edouard@180
   166
	}else{
Edouard@183
   167
        if (vresult->validc + vresult->invalidc + vresult->unknownc == 0) {
Edouard@180
   168
            // No signatures found - is this memory signed?
Edouard@182
   169
            result = PEP_VERIFY_NO_KEY; 
Edouard@183
   170
            goto free_ptext;
Edouard@183
   171
        } else if (vresult->invalidc) {
Edouard@183
   172
            // invalid memory
Edouard@180
   173
            result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
Edouard@183
   174
            goto free_ptext;
Edouard@180
   175
        } else {
Edouard@183
   176
            // only unknown sigs
Edouard@184
   177
            // or valid sig not provided in result
Edouard@180
   178
            result = PEP_DECRYPT_WRONG_FORMAT;
Edouard@183
   179
            goto free_ptext;
Edouard@180
   180
        }
Edouard@180
   181
    }
Edouard@174
   182
Edouard@180
   183
    if (result == PEP_DECRYPTED_AND_VERIFIED
Edouard@180
   184
        || result == PEP_DECRYPTED) {
Edouard@180
   185
        *ptext = _ptext;
Edouard@180
   186
        *psize = _psize;
Edouard@180
   187
        (*ptext)[*psize] = 0; // safeguard for naive users
Edouard@183
   188
        *keylist = _keylist;
Edouard@183
   189
Edouard@183
   190
        /* _ptext and _keylist ownership transfer, don't free */
Edouard@183
   191
        goto free_pgp;
Edouard@180
   192
    }
Edouard@183
   193
Edouard@183
   194
free_keylist:
Edouard@183
   195
    free_stringlist(_keylist);
Edouard@183
   196
Edouard@183
   197
free_ptext:
Edouard@183
   198
    free(_ptext);
Edouard@183
   199
Edouard@183
   200
free_pgp:
Edouard@183
   201
	pgp_memory_free(mem);
Edouard@183
   202
    pgp_validate_result_free(vresult);
Edouard@183
   203
Edouard@174
   204
    return result;
Edouard@174
   205
}
Edouard@174
   206
Edouard@174
   207
PEP_STATUS pgp_verify_text(
Edouard@174
   208
    PEP_SESSION session, const char *text, size_t size,
Edouard@174
   209
    const char *signature, size_t sig_size, stringlist_t **keylist
Edouard@174
   210
    )
Edouard@174
   211
{
Edouard@174
   212
    PEP_STATUS result;
Edouard@174
   213
    stringlist_t *_keylist;
Edouard@174
   214
Edouard@174
   215
    assert(session);
Edouard@174
   216
    assert(text);
Edouard@174
   217
    assert(size);
Edouard@174
   218
    assert(signature);
Edouard@174
   219
    assert(sig_size);
Edouard@174
   220
    assert(keylist);
Edouard@174
   221
Edouard@174
   222
    *keylist = NULL;
Edouard@174
   223
    /* if OK, verify */
Edouard@174
   224
            stringlist_t *k;
Edouard@174
   225
            k = _keylist;
Edouard@174
   226
            result = PEP_VERIFIED;
Edouard@174
   227
            do {
Edouard@174
   228
                k = stringlist_add(k, "TODO");
Edouard@174
   229
                if (k == NULL) {
Edouard@174
   230
                    free_stringlist(_keylist);
Edouard@174
   231
                    /* TODO */
Edouard@174
   232
                    return PEP_OUT_OF_MEMORY;
Edouard@174
   233
                }
Edouard@174
   234
            } while (0 /*TODO*/);
Edouard@174
   235
            *keylist = _keylist;
Edouard@174
   236
    /*
Edouard@174
   237
    result = PEP_UNENCRYPTED;
Edouard@174
   238
    result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
Edouard@174
   239
    result = PEP_VERIFIED_AND_TRUSTED;
Edouard@174
   240
    result = PEP_VERIFY_NO_KEY;
Edouard@174
   241
    result = PEP_UNENCRYPTED;
Edouard@174
   242
    result = PEP_DECRYPT_WRONG_FORMAT;
Edouard@174
   243
    return PEP_OUT_OF_MEMORY;
Edouard@174
   244
    */
Edouard@174
   245
    result = PEP_UNKNOWN_ERROR;
Edouard@174
   246
Edouard@174
   247
    return result;
Edouard@174
   248
}
Edouard@174
   249
Edouard@174
   250
PEP_STATUS pgp_encrypt_and_sign(
Edouard@174
   251
    PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
Edouard@174
   252
    size_t psize, char **ctext, size_t *csize
Edouard@174
   253
    )
Edouard@174
   254
{
Edouard@174
   255
    PEP_STATUS result;
Edouard@174
   256
    const stringlist_t *_keylist;
Edouard@174
   257
    int i, j;
Edouard@174
   258
Edouard@174
   259
    assert(session);
Edouard@174
   260
    assert(keylist);
Edouard@174
   261
    assert(ptext);
Edouard@174
   262
    assert(psize);
Edouard@174
   263
    assert(ctext);
Edouard@174
   264
    assert(csize);
Edouard@174
   265
Edouard@174
   266
    *ctext = NULL;
Edouard@174
   267
    *csize = 0;
Edouard@174
   268
Edouard@174
   269
    for (_keylist = keylist, i = 0; _keylist != NULL; _keylist = _keylist->next, i++) {
Edouard@174
   270
        assert(_keylist->value);
Edouard@174
   271
        /* TODO */
Edouard@174
   272
        /* get key from  _keylist->value */
Edouard@174
   273
        /* add key to recipients/signers */
Edouard@174
   274
    }
Edouard@174
   275
Edouard@174
   276
    /* Do encrypt and sign */ 
Edouard@175
   277
    char *_buffer = NULL;
Edouard@175
   278
    size_t length = /* TODO length*/ 0;
Edouard@175
   279
    assert(length != -1);
Edouard@174
   280
Edouard@175
   281
    /* Allocate transferable buffer */
Edouard@175
   282
    _buffer = malloc(length + 1);
Edouard@175
   283
    assert(_buffer);
Edouard@175
   284
    if (_buffer == NULL) {
Edouard@175
   285
        /* TODO clean */
Edouard@175
   286
        return PEP_OUT_OF_MEMORY;
Edouard@174
   287
    }
Edouard@174
   288
Edouard@175
   289
    *ctext = _buffer;
Edouard@175
   290
    *csize = length;
Edouard@175
   291
    (*ctext)[*csize] = 0; // safeguard for naive users
Edouard@175
   292
    result = PEP_STATUS_OK;
Edouard@175
   293
Edouard@174
   294
    
Edouard@175
   295
    result = PEP_UNKNOWN_ERROR;
Edouard@174
   296
    return result;
Edouard@174
   297
}
Edouard@174
   298
Edouard@174
   299
PEP_STATUS pgp_generate_keypair(
Edouard@174
   300
    PEP_SESSION session, pEp_identity *identity
Edouard@174
   301
    )
Edouard@174
   302
{
Edouard@174
   303
    char *parms;
Edouard@174
   304
    const char *template =
Edouard@174
   305
        "Key-Type: RSA\n"
Edouard@174
   306
        "Key-Length: 4096\n"
Edouard@174
   307
        "Name-Real: %s\n"
Edouard@174
   308
        "Name-Email: %s\n"
Edouard@174
   309
        /* "Passphrase: %s\n" */
Edouard@174
   310
        "Expire-Date: 1y\n";
Edouard@174
   311
    int result;
Edouard@174
   312
Edouard@174
   313
    assert(session);
Edouard@174
   314
    assert(identity);
Edouard@174
   315
    assert(identity->address);
Edouard@174
   316
    assert(identity->fpr == NULL);
Edouard@174
   317
    assert(identity->username);
Edouard@174
   318
Edouard@174
   319
    parms = calloc(1, PARMS_MAX);
Edouard@174
   320
    assert(parms);
Edouard@174
   321
    if (parms == NULL)
Edouard@174
   322
        return PEP_OUT_OF_MEMORY;
Edouard@174
   323
Edouard@174
   324
    result = snprintf(parms, PARMS_MAX, template, identity->username,
Edouard@174
   325
        identity->address);
Edouard@174
   326
    assert(result < PARMS_MAX);
Edouard@174
   327
    if (result >= PARMS_MAX) {
Edouard@174
   328
        free(parms);
Edouard@174
   329
        return PEP_BUFFER_TOO_SMALL;
Edouard@174
   330
    }
Edouard@174
   331
Edouard@174
   332
    /* TODO generate key */
Edouard@174
   333
Edouard@174
   334
    free(parms);
Edouard@174
   335
Edouard@174
   336
        return PEP_UNKNOWN_ERROR;
Edouard@174
   337
        return PEP_ILLEGAL_VALUE;
Edouard@174
   338
        return PEP_CANNOT_CREATE_KEY;
Edouard@174
   339
Edouard@174
   340
    identity->fpr = strdup("TODO generated key fpr");
Edouard@174
   341
Edouard@174
   342
    return PEP_STATUS_OK;
Edouard@174
   343
}
Edouard@174
   344
Edouard@174
   345
PEP_STATUS pgp_delete_keypair(PEP_SESSION session, const char *fpr)
Edouard@174
   346
{
Edouard@174
   347
    assert(session);
Edouard@174
   348
    assert(fpr);
Edouard@174
   349
Edouard@174
   350
    /* TODO get key with given fpr */
Edouard@174
   351
        return PEP_KEY_NOT_FOUND;
Edouard@174
   352
        return PEP_ILLEGAL_VALUE;
Edouard@174
   353
        return PEP_KEY_HAS_AMBIG_NAME;
Edouard@174
   354
        return PEP_OUT_OF_MEMORY;
Edouard@174
   355
        return PEP_UNKNOWN_ERROR;
Edouard@174
   356
Edouard@174
   357
    /* TODO delete that key */
Edouard@174
   358
        return PEP_UNKNOWN_ERROR;
Edouard@174
   359
        return PEP_KEY_NOT_FOUND;
Edouard@174
   360
        return PEP_KEY_HAS_AMBIG_NAME;
Edouard@174
   361
        return PEP_UNKNOWN_ERROR;
Edouard@174
   362
Edouard@174
   363
    return PEP_STATUS_OK;
Edouard@174
   364
}
Edouard@174
   365
Edouard@179
   366
PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data, size_t size)
Edouard@174
   367
{
Edouard@174
   368
    assert(session);
Edouard@174
   369
    assert(key_data);
Edouard@174
   370
Edouard@174
   371
    /* TODO import */
Edouard@174
   372
        return PEP_UNKNOWN_ERROR;
Edouard@174
   373
        return PEP_ILLEGAL_VALUE;
Edouard@174
   374
        return PEP_UNKNOWN_ERROR;
Edouard@174
   375
    return PEP_STATUS_OK;
Edouard@174
   376
}
Edouard@174
   377
Edouard@179
   378
PEP_STATUS pgp_export_keydata(
Edouard@174
   379
    PEP_SESSION session, const char *fpr, char **key_data, size_t *size
Edouard@174
   380
    )
Edouard@174
   381
{
Edouard@174
   382
    size_t _size;
Edouard@174
   383
    char *buffer;
Edouard@174
   384
    int reading;
Edouard@174
   385
Edouard@174
   386
    assert(session);
Edouard@174
   387
    assert(fpr);
Edouard@174
   388
    assert(key_data);
Edouard@174
   389
    assert(size);
Edouard@174
   390
Edouard@174
   391
Edouard@174
   392
    /* TODO export */
Edouard@174
   393
        return PEP_KEY_NOT_FOUND;
Edouard@174
   394
        return PEP_UNKNOWN_ERROR;
Edouard@174
   395
        return PEP_UNKNOWN_ERROR;
Edouard@174
   396
Edouard@174
   397
    _size = /* TODO */ 0;
Edouard@174
   398
    assert(_size != -1);
Edouard@174
   399
Edouard@174
   400
    buffer = malloc(_size + 1);
Edouard@174
   401
    assert(buffer);
Edouard@174
   402
    if (buffer == NULL) {
Edouard@174
   403
        /* TODO clean */
Edouard@174
   404
        return PEP_OUT_OF_MEMORY;
Edouard@174
   405
    }
Edouard@174
   406
Edouard@174
   407
    // safeguard for the naive user
Edouard@174
   408
    buffer[_size] = 0;
Edouard@174
   409
Edouard@174
   410
    *key_data = buffer;
Edouard@174
   411
    *size = _size;
Edouard@174
   412
Edouard@174
   413
    return PEP_STATUS_OK;
Edouard@174
   414
}
Edouard@174
   415
Edouard@175
   416
// "keyserver"
Edouard@175
   417
// "hkp://keys.gnupg.net"
Edouard@174
   418
PEP_STATUS pgp_recv_key(PEP_SESSION session, const char *pattern)
Edouard@174
   419
{
Edouard@174
   420
    assert(session);
Edouard@174
   421
    assert(pattern);
Edouard@174
   422
Edouard@174
   423
    /* TODO ask for key */
Edouard@174
   424
        return PEP_UNKNOWN_ERROR;
Edouard@174
   425
        return PEP_GET_KEY_FAILED;
Edouard@174
   426
Edouard@174
   427
    do {
Edouard@174
   428
Edouard@174
   429
        /* For each key */
Edouard@174
   430
        /* import key */
Edouard@174
   431
    } while (0);
Edouard@174
   432
Edouard@174
   433
    return PEP_STATUS_OK;
Edouard@174
   434
}
Edouard@174
   435
Edouard@174
   436
PEP_STATUS pgp_find_keys(
Edouard@174
   437
    PEP_SESSION session, const char *pattern, stringlist_t **keylist
Edouard@174
   438
    )
Edouard@174
   439
{
Edouard@174
   440
    stringlist_t *_keylist;
Edouard@174
   441
    char *fpr;
Edouard@174
   442
Edouard@174
   443
    assert(session);
Edouard@174
   444
    assert(pattern);
Edouard@174
   445
    assert(keylist);
Edouard@174
   446
Edouard@174
   447
    *keylist = NULL;
Edouard@174
   448
Edouard@174
   449
    /* Ask for key */
Edouard@174
   450
        return PEP_UNKNOWN_ERROR;
Edouard@174
   451
        return PEP_GET_KEY_FAILED;
Edouard@174
   452
Edouard@174
   453
    _keylist = new_stringlist(NULL);
Edouard@174
   454
    stringlist_t *_k = _keylist;
Edouard@174
   455
Edouard@174
   456
    do {
Edouard@174
   457
            fpr = "TODO key->subkeys->fpr";
Edouard@174
   458
            assert(fpr);
Edouard@174
   459
            _k = stringlist_add(_k, fpr);
Edouard@174
   460
            assert(_k);
Edouard@174
   461
            if (_k == NULL){
Edouard@174
   462
                free_stringlist(_keylist);
Edouard@174
   463
                return PEP_OUT_OF_MEMORY;
Edouard@174
   464
            }
Edouard@174
   465
    } while (0);
Edouard@174
   466
Edouard@174
   467
    *keylist = _keylist;
Edouard@174
   468
    return PEP_STATUS_OK;
Edouard@174
   469
}
Edouard@174
   470
Edouard@174
   471
PEP_STATUS pgp_send_key(PEP_SESSION session, const char *pattern)
Edouard@174
   472
{
Edouard@174
   473
    assert(session);
Edouard@174
   474
    assert(pattern);
Edouard@174
   475
Edouard@174
   476
    /* TODO send key */
Edouard@174
   477
Edouard@174
   478
        return PEP_CANNOT_SEND_KEY;
Edouard@174
   479
        return PEP_STATUS_OK;
Edouard@174
   480
}
Edouard@174
   481
Edouard@174
   482
Edouard@174
   483
PEP_STATUS pgp_get_key_rating(
Edouard@174
   484
    PEP_SESSION session,
Edouard@174
   485
    const char *fpr,
Edouard@174
   486
    PEP_comm_type *comm_type
Edouard@174
   487
    )
Edouard@174
   488
{
Edouard@174
   489
    PEP_STATUS status = PEP_STATUS_OK;
Edouard@174
   490
Edouard@174
   491
    assert(session);
Edouard@174
   492
    assert(fpr);
Edouard@174
   493
    assert(comm_type);
Edouard@174
   494
Edouard@174
   495
    *comm_type = PEP_ct_unknown;
Edouard@174
   496
Edouard@174
   497
    /* TODO get key from fpr */
Edouard@174
   498
    return PEP_UNKNOWN_ERROR;
Edouard@174
   499
    return PEP_GET_KEY_FAILED;
Edouard@174
   500
Edouard@174
   501
    switch (/*TODO key->protocol*/ 4) {
Edouard@174
   502
    case /* TODO  OpenPGP */0:
Edouard@174
   503
    case /* TODO DEFAULT */1:
Edouard@174
   504
        *comm_type = PEP_ct_OpenPGP_unconfirmed;
Edouard@174
   505
        break;
Edouard@174
   506
    case /* TODO CMS */2:
Edouard@174
   507
        *comm_type = PEP_ct_CMS_unconfirmed;
Edouard@174
   508
        break;
Edouard@174
   509
    default:
Edouard@174
   510
        *comm_type = PEP_ct_unknown;
Edouard@174
   511
        return PEP_STATUS_OK;
Edouard@174
   512
    }
Edouard@174
   513
Edouard@174
   514
        for (; 1 == 0; /* Each subkeys */ ) {
Edouard@174
   515
            if (/* TODO length */0 < 1024)
Edouard@174
   516
                *comm_type = PEP_ct_key_too_short;
Edouard@174
   517
            else if (
Edouard@174
   518
                (
Edouard@174
   519
                (   /* TODO pubkey_algo == RSA  */ 0)
Edouard@174
   520
                || (/* TODO pubkey_algo == RSA_E*/ 0)
Edouard@174
   521
                || (/* TODO pubkey_algo == RSA_S*/ 0)
Edouard@174
   522
                )
Edouard@174
   523
                && /* sk->length */0 == 1024
Edouard@174
   524
                )
Edouard@174
   525
                *comm_type = PEP_ct_OpenPGP_weak_unconfirmed;
Edouard@174
   526
Edouard@174
   527
            if (/* TODO invalid */ 1) {
Edouard@174
   528
                *comm_type = PEP_ct_key_b0rken;
Edouard@174
   529
                break;
Edouard@174
   530
            }
Edouard@174
   531
            if (/* TODO expired */ 1) {
Edouard@174
   532
                *comm_type = PEP_ct_key_expired;
Edouard@174
   533
                break;
Edouard@174
   534
            }
Edouard@175
   535
            if (/* TODO revoked*/ 1) {
Edouard@174
   536
                *comm_type = PEP_ct_key_revoked;
Edouard@174
   537
                break;
Edouard@174
   538
            }
Edouard@174
   539
        }
Edouard@174
   540
        *comm_type = PEP_ct_unknown;
Edouard@174
   541
        return PEP_OUT_OF_MEMORY;
Edouard@174
   542
        return PEP_UNKNOWN_ERROR;
Edouard@174
   543
Edouard@174
   544
Edouard@174
   545
    return status;
Edouard@174
   546
}