src/pgp_netpgp.c
author Edouard Tisserant
Sat, 04 Apr 2015 01:01:22 +0200
changeset 180 6008e35e7735
parent 179 112fadcf74b9
child 182 2b286e499c94
permissions -rw-r--r--
netpgp : decrypt and verify. Fixing needed in netpgp. netpgp cannot decrypt msg encrypted with gpg. netpgp can decrypt its own msg, but cannot verify own clearsign msg
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@180
    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@179
   115
    mem = pgp_decrypt_buf(netpgp->io, ctext, csize,
Edouard@179
   116
                netpgp->secring, netpgp->pubring,
Edouard@179
   117
                1 /* armoured */,
Edouard@179
   118
                0 /* sshkeys */,
Edouard@180
   119
                NULL, -1, NULL  /* pass fp,attempts,cb */);
Edouard@179
   120
    if (mem == NULL) {
Edouard@179
   121
        return PEP_OUT_OF_MEMORY;
Edouard@179
   122
    }
Edouard@179
   123
Edouard@180
   124
	_psize = pgp_mem_len(mem);
Edouard@180
   125
	if ((_ptext = calloc(1, _psize)) == NULL) {
Edouard@179
   126
        return PEP_OUT_OF_MEMORY;
Edouard@179
   127
	}
Edouard@180
   128
	memcpy(_ptext, pgp_mem_data(mem), _psize);
Edouard@179
   129
Edouard@179
   130
    result = PEP_DECRYPTED;
Edouard@179
   131
Edouard@180
   132
    cat = pgp_memory_new();
Edouard@180
   133
Edouard@174
   134
    /* if recognized */
Edouard@174
   135
    /* decrypt */
Edouard@174
   136
    /* if OK, verify */
Edouard@174
   137
    /*
Edouard@174
   138
    result = PEP_DECRYPTED_AND_VERIFIED;
Edouard@174
   139
    result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
Edouard@174
   140
    result = PEP_DECRYPTED;
Edouard@174
   141
    result = PEP_DECRYPT_WRONG_FORMAT;
Edouard@174
   142
    result = PEP_DECRYPT_NO_KEY;
Edouard@174
   143
    return PEP_OUT_OF_MEMORY;
Edouard@174
   144
    */
Edouard@180
   145
	(void) memset(&vresult, 0x0, sizeof(vresult));
Edouard@180
   146
	ret = pgp_validate_mem(io, &vresult, mem,
Edouard@180
   147
				&cat, 1, netpgp->pubring);
Edouard@180
   148
Edouard@180
   149
	// pgp_memory_free(mem) done by pgp_validate_mem
Edouard@180
   150
Edouard@180
   151
	if (ret) {
Edouard@180
   152
		// resultp(io, "<stdin>", &vresult, netpgp->pubring);
Edouard@180
   153
	    // signedmem is freed from pgp_validate_mem
Edouard@180
   154
        result = PEP_DECRYPTED_AND_VERIFIED;
Edouard@180
   155
	}else{
Edouard@180
   156
        if (vresult.validc + vresult.invalidc + vresult.unknownc == 0) {
Edouard@180
   157
            // No signatures found - is this memory signed?
Edouard@180
   158
            result = PEP_DECRYPT_NO_KEY;
Edouard@180
   159
        } else if (vresult.invalidc == 0 && vresult.unknownc == 0) {
Edouard@180
   160
            // memory verification failure: invalid signature time
Edouard@180
   161
            result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
Edouard@180
   162
        } else {
Edouard@180
   163
            // memory verification failure: 
Edouard@180
   164
            // invalid signatures result.invalidc
Edouard@180
   165
            // unknown signatures result.unknownc
Edouard@180
   166
            result = PEP_DECRYPT_WRONG_FORMAT;
Edouard@180
   167
        }
Edouard@180
   168
    }
Edouard@179
   169
    //result = PEP_UNKNOWN_ERROR;
Edouard@179
   170
    //            stringlist_t *k;
Edouard@179
   171
    //            _keylist = new_stringlist(NULL);
Edouard@179
   172
    //            assert(_keylist);
Edouard@179
   173
    //            if (_keylist == NULL) {
Edouard@179
   174
    //                /* TODO */
Edouard@179
   175
    //                return PEP_OUT_OF_MEMORY;
Edouard@179
   176
    //            }
Edouard@179
   177
    //            k = _keylist;
Edouard@179
   178
    //            do {
Edouard@179
   179
    //                    k = stringlist_add(k, "SIGNATURE FPR"/*TODO*/);
Edouard@179
   180
    //            } while (0 /* TODO sign next*/);
Edouard@174
   181
Edouard@180
   182
    pgp_memory_free(cat);
Edouard@180
   183
Edouard@180
   184
    if (result == PEP_DECRYPTED_AND_VERIFIED
Edouard@180
   185
        || result == PEP_DECRYPTED) {
Edouard@180
   186
        *ptext = _ptext;
Edouard@180
   187
        *psize = _psize;
Edouard@180
   188
        (*ptext)[*psize] = 0; // safeguard for naive users
Edouard@180
   189
        // *keylist = _keylist;
Edouard@180
   190
    }
Edouard@180
   191
    else {
Edouard@180
   192
        // free_stringlist(_keylist);
Edouard@180
   193
        free(_ptext);
Edouard@180
   194
    }
Edouard@174
   195
    return result;
Edouard@174
   196
}
Edouard@174
   197
Edouard@174
   198
PEP_STATUS pgp_verify_text(
Edouard@174
   199
    PEP_SESSION session, const char *text, size_t size,
Edouard@174
   200
    const char *signature, size_t sig_size, stringlist_t **keylist
Edouard@174
   201
    )
Edouard@174
   202
{
Edouard@174
   203
    PEP_STATUS result;
Edouard@174
   204
    stringlist_t *_keylist;
Edouard@174
   205
Edouard@174
   206
    assert(session);
Edouard@174
   207
    assert(text);
Edouard@174
   208
    assert(size);
Edouard@174
   209
    assert(signature);
Edouard@174
   210
    assert(sig_size);
Edouard@174
   211
    assert(keylist);
Edouard@174
   212
Edouard@174
   213
    *keylist = NULL;
Edouard@174
   214
    /* if OK, verify */
Edouard@174
   215
            stringlist_t *k;
Edouard@174
   216
            k = _keylist;
Edouard@174
   217
            result = PEP_VERIFIED;
Edouard@174
   218
            do {
Edouard@174
   219
                k = stringlist_add(k, "TODO");
Edouard@174
   220
                if (k == NULL) {
Edouard@174
   221
                    free_stringlist(_keylist);
Edouard@174
   222
                    /* TODO */
Edouard@174
   223
                    return PEP_OUT_OF_MEMORY;
Edouard@174
   224
                }
Edouard@174
   225
            } while (0 /*TODO*/);
Edouard@174
   226
            *keylist = _keylist;
Edouard@174
   227
    /*
Edouard@174
   228
    result = PEP_UNENCRYPTED;
Edouard@174
   229
    result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
Edouard@174
   230
    result = PEP_VERIFIED_AND_TRUSTED;
Edouard@174
   231
    result = PEP_VERIFY_NO_KEY;
Edouard@174
   232
    result = PEP_UNENCRYPTED;
Edouard@174
   233
    result = PEP_DECRYPT_WRONG_FORMAT;
Edouard@174
   234
    return PEP_OUT_OF_MEMORY;
Edouard@174
   235
    */
Edouard@174
   236
    result = PEP_UNKNOWN_ERROR;
Edouard@174
   237
Edouard@174
   238
    return result;
Edouard@174
   239
}
Edouard@174
   240
Edouard@174
   241
PEP_STATUS pgp_encrypt_and_sign(
Edouard@174
   242
    PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
Edouard@174
   243
    size_t psize, char **ctext, size_t *csize
Edouard@174
   244
    )
Edouard@174
   245
{
Edouard@174
   246
    PEP_STATUS result;
Edouard@174
   247
    const stringlist_t *_keylist;
Edouard@174
   248
    int i, j;
Edouard@174
   249
Edouard@174
   250
    assert(session);
Edouard@174
   251
    assert(keylist);
Edouard@174
   252
    assert(ptext);
Edouard@174
   253
    assert(psize);
Edouard@174
   254
    assert(ctext);
Edouard@174
   255
    assert(csize);
Edouard@174
   256
Edouard@174
   257
    *ctext = NULL;
Edouard@174
   258
    *csize = 0;
Edouard@174
   259
Edouard@174
   260
    for (_keylist = keylist, i = 0; _keylist != NULL; _keylist = _keylist->next, i++) {
Edouard@174
   261
        assert(_keylist->value);
Edouard@174
   262
        /* TODO */
Edouard@174
   263
        /* get key from  _keylist->value */
Edouard@174
   264
        /* add key to recipients/signers */
Edouard@174
   265
    }
Edouard@174
   266
Edouard@174
   267
    /* Do encrypt and sign */ 
Edouard@175
   268
    char *_buffer = NULL;
Edouard@175
   269
    size_t length = /* TODO length*/ 0;
Edouard@175
   270
    assert(length != -1);
Edouard@174
   271
Edouard@175
   272
    /* Allocate transferable buffer */
Edouard@175
   273
    _buffer = malloc(length + 1);
Edouard@175
   274
    assert(_buffer);
Edouard@175
   275
    if (_buffer == NULL) {
Edouard@175
   276
        /* TODO clean */
Edouard@175
   277
        return PEP_OUT_OF_MEMORY;
Edouard@174
   278
    }
Edouard@174
   279
Edouard@175
   280
    *ctext = _buffer;
Edouard@175
   281
    *csize = length;
Edouard@175
   282
    (*ctext)[*csize] = 0; // safeguard for naive users
Edouard@175
   283
    result = PEP_STATUS_OK;
Edouard@175
   284
Edouard@174
   285
    
Edouard@175
   286
    result = PEP_UNKNOWN_ERROR;
Edouard@174
   287
    return result;
Edouard@174
   288
}
Edouard@174
   289
Edouard@174
   290
PEP_STATUS pgp_generate_keypair(
Edouard@174
   291
    PEP_SESSION session, pEp_identity *identity
Edouard@174
   292
    )
Edouard@174
   293
{
Edouard@174
   294
    char *parms;
Edouard@174
   295
    const char *template =
Edouard@174
   296
        "Key-Type: RSA\n"
Edouard@174
   297
        "Key-Length: 4096\n"
Edouard@174
   298
        "Name-Real: %s\n"
Edouard@174
   299
        "Name-Email: %s\n"
Edouard@174
   300
        /* "Passphrase: %s\n" */
Edouard@174
   301
        "Expire-Date: 1y\n";
Edouard@174
   302
    int result;
Edouard@174
   303
Edouard@174
   304
    assert(session);
Edouard@174
   305
    assert(identity);
Edouard@174
   306
    assert(identity->address);
Edouard@174
   307
    assert(identity->fpr == NULL);
Edouard@174
   308
    assert(identity->username);
Edouard@174
   309
Edouard@174
   310
    parms = calloc(1, PARMS_MAX);
Edouard@174
   311
    assert(parms);
Edouard@174
   312
    if (parms == NULL)
Edouard@174
   313
        return PEP_OUT_OF_MEMORY;
Edouard@174
   314
Edouard@174
   315
    result = snprintf(parms, PARMS_MAX, template, identity->username,
Edouard@174
   316
        identity->address);
Edouard@174
   317
    assert(result < PARMS_MAX);
Edouard@174
   318
    if (result >= PARMS_MAX) {
Edouard@174
   319
        free(parms);
Edouard@174
   320
        return PEP_BUFFER_TOO_SMALL;
Edouard@174
   321
    }
Edouard@174
   322
Edouard@174
   323
    /* TODO generate key */
Edouard@174
   324
Edouard@174
   325
    free(parms);
Edouard@174
   326
Edouard@174
   327
        return PEP_UNKNOWN_ERROR;
Edouard@174
   328
        return PEP_ILLEGAL_VALUE;
Edouard@174
   329
        return PEP_CANNOT_CREATE_KEY;
Edouard@174
   330
Edouard@174
   331
    identity->fpr = strdup("TODO generated key fpr");
Edouard@174
   332
Edouard@174
   333
    return PEP_STATUS_OK;
Edouard@174
   334
}
Edouard@174
   335
Edouard@174
   336
PEP_STATUS pgp_delete_keypair(PEP_SESSION session, const char *fpr)
Edouard@174
   337
{
Edouard@174
   338
    assert(session);
Edouard@174
   339
    assert(fpr);
Edouard@174
   340
Edouard@174
   341
    /* TODO get key with given fpr */
Edouard@174
   342
        return PEP_KEY_NOT_FOUND;
Edouard@174
   343
        return PEP_ILLEGAL_VALUE;
Edouard@174
   344
        return PEP_KEY_HAS_AMBIG_NAME;
Edouard@174
   345
        return PEP_OUT_OF_MEMORY;
Edouard@174
   346
        return PEP_UNKNOWN_ERROR;
Edouard@174
   347
Edouard@174
   348
    /* TODO delete that key */
Edouard@174
   349
        return PEP_UNKNOWN_ERROR;
Edouard@174
   350
        return PEP_KEY_NOT_FOUND;
Edouard@174
   351
        return PEP_KEY_HAS_AMBIG_NAME;
Edouard@174
   352
        return PEP_UNKNOWN_ERROR;
Edouard@174
   353
Edouard@174
   354
    return PEP_STATUS_OK;
Edouard@174
   355
}
Edouard@174
   356
Edouard@179
   357
PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data, size_t size)
Edouard@174
   358
{
Edouard@174
   359
    assert(session);
Edouard@174
   360
    assert(key_data);
Edouard@174
   361
Edouard@174
   362
    /* TODO import */
Edouard@174
   363
        return PEP_UNKNOWN_ERROR;
Edouard@174
   364
        return PEP_ILLEGAL_VALUE;
Edouard@174
   365
        return PEP_UNKNOWN_ERROR;
Edouard@174
   366
    return PEP_STATUS_OK;
Edouard@174
   367
}
Edouard@174
   368
Edouard@179
   369
PEP_STATUS pgp_export_keydata(
Edouard@174
   370
    PEP_SESSION session, const char *fpr, char **key_data, size_t *size
Edouard@174
   371
    )
Edouard@174
   372
{
Edouard@174
   373
    size_t _size;
Edouard@174
   374
    char *buffer;
Edouard@174
   375
    int reading;
Edouard@174
   376
Edouard@174
   377
    assert(session);
Edouard@174
   378
    assert(fpr);
Edouard@174
   379
    assert(key_data);
Edouard@174
   380
    assert(size);
Edouard@174
   381
Edouard@174
   382
Edouard@174
   383
    /* TODO export */
Edouard@174
   384
        return PEP_KEY_NOT_FOUND;
Edouard@174
   385
        return PEP_UNKNOWN_ERROR;
Edouard@174
   386
        return PEP_UNKNOWN_ERROR;
Edouard@174
   387
Edouard@174
   388
    _size = /* TODO */ 0;
Edouard@174
   389
    assert(_size != -1);
Edouard@174
   390
Edouard@174
   391
    buffer = malloc(_size + 1);
Edouard@174
   392
    assert(buffer);
Edouard@174
   393
    if (buffer == NULL) {
Edouard@174
   394
        /* TODO clean */
Edouard@174
   395
        return PEP_OUT_OF_MEMORY;
Edouard@174
   396
    }
Edouard@174
   397
Edouard@174
   398
    // safeguard for the naive user
Edouard@174
   399
    buffer[_size] = 0;
Edouard@174
   400
Edouard@174
   401
    *key_data = buffer;
Edouard@174
   402
    *size = _size;
Edouard@174
   403
Edouard@174
   404
    return PEP_STATUS_OK;
Edouard@174
   405
}
Edouard@174
   406
Edouard@175
   407
// "keyserver"
Edouard@175
   408
// "hkp://keys.gnupg.net"
Edouard@174
   409
PEP_STATUS pgp_recv_key(PEP_SESSION session, const char *pattern)
Edouard@174
   410
{
Edouard@174
   411
    assert(session);
Edouard@174
   412
    assert(pattern);
Edouard@174
   413
Edouard@174
   414
    /* TODO ask for key */
Edouard@174
   415
        return PEP_UNKNOWN_ERROR;
Edouard@174
   416
        return PEP_GET_KEY_FAILED;
Edouard@174
   417
Edouard@174
   418
    do {
Edouard@174
   419
Edouard@174
   420
        /* For each key */
Edouard@174
   421
        /* import key */
Edouard@174
   422
    } while (0);
Edouard@174
   423
Edouard@174
   424
    return PEP_STATUS_OK;
Edouard@174
   425
}
Edouard@174
   426
Edouard@174
   427
PEP_STATUS pgp_find_keys(
Edouard@174
   428
    PEP_SESSION session, const char *pattern, stringlist_t **keylist
Edouard@174
   429
    )
Edouard@174
   430
{
Edouard@174
   431
    stringlist_t *_keylist;
Edouard@174
   432
    char *fpr;
Edouard@174
   433
Edouard@174
   434
    assert(session);
Edouard@174
   435
    assert(pattern);
Edouard@174
   436
    assert(keylist);
Edouard@174
   437
Edouard@174
   438
    *keylist = NULL;
Edouard@174
   439
Edouard@174
   440
    /* Ask for key */
Edouard@174
   441
        return PEP_UNKNOWN_ERROR;
Edouard@174
   442
        return PEP_GET_KEY_FAILED;
Edouard@174
   443
Edouard@174
   444
    _keylist = new_stringlist(NULL);
Edouard@174
   445
    stringlist_t *_k = _keylist;
Edouard@174
   446
Edouard@174
   447
    do {
Edouard@174
   448
            fpr = "TODO key->subkeys->fpr";
Edouard@174
   449
            assert(fpr);
Edouard@174
   450
            _k = stringlist_add(_k, fpr);
Edouard@174
   451
            assert(_k);
Edouard@174
   452
            if (_k == NULL){
Edouard@174
   453
                free_stringlist(_keylist);
Edouard@174
   454
                return PEP_OUT_OF_MEMORY;
Edouard@174
   455
            }
Edouard@174
   456
    } while (0);
Edouard@174
   457
Edouard@174
   458
    *keylist = _keylist;
Edouard@174
   459
    return PEP_STATUS_OK;
Edouard@174
   460
}
Edouard@174
   461
Edouard@174
   462
PEP_STATUS pgp_send_key(PEP_SESSION session, const char *pattern)
Edouard@174
   463
{
Edouard@174
   464
    assert(session);
Edouard@174
   465
    assert(pattern);
Edouard@174
   466
Edouard@174
   467
    /* TODO send key */
Edouard@174
   468
Edouard@174
   469
        return PEP_CANNOT_SEND_KEY;
Edouard@174
   470
        return PEP_STATUS_OK;
Edouard@174
   471
}
Edouard@174
   472
Edouard@174
   473
Edouard@174
   474
PEP_STATUS pgp_get_key_rating(
Edouard@174
   475
    PEP_SESSION session,
Edouard@174
   476
    const char *fpr,
Edouard@174
   477
    PEP_comm_type *comm_type
Edouard@174
   478
    )
Edouard@174
   479
{
Edouard@174
   480
    PEP_STATUS status = PEP_STATUS_OK;
Edouard@174
   481
Edouard@174
   482
    assert(session);
Edouard@174
   483
    assert(fpr);
Edouard@174
   484
    assert(comm_type);
Edouard@174
   485
Edouard@174
   486
    *comm_type = PEP_ct_unknown;
Edouard@174
   487
Edouard@174
   488
    /* TODO get key from fpr */
Edouard@174
   489
    return PEP_UNKNOWN_ERROR;
Edouard@174
   490
    return PEP_GET_KEY_FAILED;
Edouard@174
   491
Edouard@174
   492
    switch (/*TODO key->protocol*/ 4) {
Edouard@174
   493
    case /* TODO  OpenPGP */0:
Edouard@174
   494
    case /* TODO DEFAULT */1:
Edouard@174
   495
        *comm_type = PEP_ct_OpenPGP_unconfirmed;
Edouard@174
   496
        break;
Edouard@174
   497
    case /* TODO CMS */2:
Edouard@174
   498
        *comm_type = PEP_ct_CMS_unconfirmed;
Edouard@174
   499
        break;
Edouard@174
   500
    default:
Edouard@174
   501
        *comm_type = PEP_ct_unknown;
Edouard@174
   502
        return PEP_STATUS_OK;
Edouard@174
   503
    }
Edouard@174
   504
Edouard@174
   505
        for (; 1 == 0; /* Each subkeys */ ) {
Edouard@174
   506
            if (/* TODO length */0 < 1024)
Edouard@174
   507
                *comm_type = PEP_ct_key_too_short;
Edouard@174
   508
            else if (
Edouard@174
   509
                (
Edouard@174
   510
                (   /* TODO pubkey_algo == RSA  */ 0)
Edouard@174
   511
                || (/* TODO pubkey_algo == RSA_E*/ 0)
Edouard@174
   512
                || (/* TODO pubkey_algo == RSA_S*/ 0)
Edouard@174
   513
                )
Edouard@174
   514
                && /* sk->length */0 == 1024
Edouard@174
   515
                )
Edouard@174
   516
                *comm_type = PEP_ct_OpenPGP_weak_unconfirmed;
Edouard@174
   517
Edouard@174
   518
            if (/* TODO invalid */ 1) {
Edouard@174
   519
                *comm_type = PEP_ct_key_b0rken;
Edouard@174
   520
                break;
Edouard@174
   521
            }
Edouard@174
   522
            if (/* TODO expired */ 1) {
Edouard@174
   523
                *comm_type = PEP_ct_key_expired;
Edouard@174
   524
                break;
Edouard@174
   525
            }
Edouard@175
   526
            if (/* TODO revoked*/ 1) {
Edouard@174
   527
                *comm_type = PEP_ct_key_revoked;
Edouard@174
   528
                break;
Edouard@174
   529
            }
Edouard@174
   530
        }
Edouard@174
   531
        *comm_type = PEP_ct_unknown;
Edouard@174
   532
        return PEP_OUT_OF_MEMORY;
Edouard@174
   533
        return PEP_UNKNOWN_ERROR;
Edouard@174
   534
Edouard@174
   535
Edouard@174
   536
    return status;
Edouard@174
   537
}