src/pEpEngine.c
author Volker Birk <vb@pep-project.org>
Mon, 28 Sep 2015 15:06:07 +0200
changeset 357 9b796d54b0ea
parent 339 a6485dc4f7af
child 385 0e3078a4dc37
permissions -rw-r--r--
key_compromized() added
vb@125
     1
#include "pEp_internal.h"
vb@98
     2
#include "dynamic_api.h"
vb@28
     3
#include "cryptotech.h"
vb@28
     4
#include "transport.h"
vb@0
     5
vb@221
     6
static int init_count = -1;
vb@62
     7
vb@0
     8
DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
vb@0
     9
{
vb@65
    10
    PEP_STATUS status = PEP_STATUS_OK;
vb@0
    11
	int int_result;
vb@62
    12
	static const char *sql_log;
vb@233
    13
	static const char *sql_trustword;
vb@62
    14
	static const char *sql_get_identity;
vb@62
    15
	static const char *sql_set_person;
vb@62
    16
	static const char *sql_set_pgp_keypair;
vb@62
    17
	static const char *sql_set_identity;
vb@62
    18
	static const char *sql_set_trust;
vb@62
    19
    static const char *sql_get_trust;
vb@251
    20
    static const char *sql_least_trust;
vb@357
    21
    static const char *sql_mark_as_compromized;
vb@62
    22
    bool in_first = false;
vb@8
    23
vb@62
    24
    assert(sqlite3_threadsafe());
vb@62
    25
    if (!sqlite3_threadsafe())
vb@62
    26
        return PEP_INIT_SQLITE3_WITHOUT_MUTEX;
vb@62
    27
vb@62
    28
    // a little race condition - but still a race condition
vb@113
    29
    // mitigated by calling caveat (see documentation)
vb@62
    30
vb@62
    31
    ++init_count;
vb@67
    32
    if (init_count == 0)
vb@62
    33
        in_first = true;
vb@0
    34
vb@0
    35
	assert(session);
vb@191
    36
    if (session == NULL)
vb@191
    37
        return PEP_ILLEGAL_VALUE;
vb@191
    38
vb@0
    39
	*session = NULL;
vb@0
    40
vb@107
    41
    pEpSession *_session = calloc(1, sizeof(pEpSession));
vb@0
    42
	assert(_session);
vb@0
    43
	if (_session == NULL)
vb@65
    44
		goto enomem;
vb@62
    45
vb@0
    46
	_session->version = PEP_ENGINE_VERSION;
vb@0
    47
vb@0
    48
    assert(LOCAL_DB);
vb@0
    49
    if (LOCAL_DB == NULL) {
vb@65
    50
        status = PEP_INIT_CANNOT_OPEN_DB;
vb@65
    51
        goto pep_error;
vb@0
    52
    }
vb@0
    53
vb@0
    54
	int_result = sqlite3_open_v2(
vb@0
    55
			LOCAL_DB,
vb@0
    56
			&_session->db,
vb@0
    57
			SQLITE_OPEN_READWRITE
vb@0
    58
				| SQLITE_OPEN_CREATE
vb@0
    59
				| SQLITE_OPEN_FULLMUTEX
vb@0
    60
				| SQLITE_OPEN_PRIVATECACHE,
vb@0
    61
			NULL 
vb@0
    62
		);
vb@0
    63
vb@0
    64
	if (int_result != SQLITE_OK) {
vb@65
    65
		status = PEP_INIT_CANNOT_OPEN_DB;
vb@65
    66
        goto pep_error;
vb@0
    67
	}
vb@0
    68
vb@0
    69
	sqlite3_busy_timeout(_session->db, BUSY_WAIT_TIME);
vb@0
    70
vb@0
    71
    assert(SYSTEM_DB);
vb@0
    72
    if (SYSTEM_DB == NULL) {
vb@65
    73
		status = PEP_INIT_CANNOT_OPEN_SYSTEM_DB;
vb@65
    74
        goto pep_error;
vb@0
    75
    }
vb@0
    76
vb@0
    77
	int_result = sqlite3_open_v2(
vb@0
    78
			SYSTEM_DB, &_session->system_db,
vb@0
    79
			SQLITE_OPEN_READONLY
vb@0
    80
				| SQLITE_OPEN_FULLMUTEX
vb@0
    81
				| SQLITE_OPEN_SHAREDCACHE,
vb@0
    82
			NULL
vb@0
    83
		);
vb@0
    84
vb@0
    85
	if (int_result != SQLITE_OK) {
vb@65
    86
		status = PEP_INIT_CANNOT_OPEN_SYSTEM_DB;
vb@65
    87
        goto pep_error;
vb@0
    88
	}
vb@0
    89
vb@0
    90
	sqlite3_busy_timeout(_session->system_db, 1000);
vb@0
    91
vb@62
    92
    if (in_first) {
vb@62
    93
        int_result = sqlite3_exec(
vb@62
    94
            _session->db,
vb@62
    95
                "create table if not exists version_info ("
vb@62
    96
                "	id integer primary key,"
vb@62
    97
                "	timestamp integer default (datetime('now')) ,"
vb@62
    98
                "	version text,"
vb@62
    99
                "	comment text"
vb@62
   100
                ");"
vb@62
   101
                "create table if not exists log ("
vb@62
   102
                "	timestamp integer default (datetime('now')) ,"
vb@62
   103
                "	title text not null,"
vb@62
   104
                "	entity text not null,"
vb@62
   105
                "	description text,"
vb@62
   106
                "	comment text"
vb@62
   107
                ");"
vb@62
   108
                "create index if not exists log_timestamp on log ("
vb@62
   109
                "	timestamp"
vb@62
   110
                ");"
vb@62
   111
                "create table if not exists pgp_keypair ("
vb@62
   112
                "	fpr text primary key,"
vb@62
   113
                "	public_id text unique,"
vb@62
   114
                "   private_id text,"
vb@62
   115
                "	created integer,"
vb@62
   116
                "	expires integer,"
vb@62
   117
                "	comment text"
vb@62
   118
                ");"
vb@62
   119
                "create index if not exists pgp_keypair_expires on pgp_keypair ("
vb@62
   120
                "	expires"
vb@62
   121
                ");"
vb@62
   122
                "create table if not exists person ("
vb@62
   123
                "	id text primary key,"
vb@62
   124
                "	username text not null,"
vb@62
   125
                "	main_key_id text"
vb@62
   126
                "		references pgp_keypair (fpr)"
vb@62
   127
                "		on delete set null,"
vb@62
   128
                "   lang text,"
vb@62
   129
                "	comment text"
vb@62
   130
                ");"
vb@62
   131
                "create table if not exists identity ("
vb@62
   132
                "	address text primary key,"
vb@62
   133
                "	user_id text"
vb@62
   134
                "		references person (id)"
vb@62
   135
                "		on delete cascade,"
vb@62
   136
                "	main_key_id text"
vb@62
   137
                "		references pgp_keypair (fpr)"
vb@62
   138
                "		on delete set null,"
vb@62
   139
                "	comment text"
vb@62
   140
                ");"
vb@62
   141
                "create table if not exists trust ("
vb@62
   142
                "   user_id text not null"
vb@62
   143
                "       references person (id)"
vb@62
   144
                "		on delete cascade,"
vb@62
   145
                "   pgp_keypair_fpr text not null"
vb@62
   146
                "       references pgp_keypair (fpr)"
vb@62
   147
                "       on delete cascade,"
vb@62
   148
                "   comm_type integer not null,"
vb@62
   149
                "	comment text"
vb@62
   150
                ");"
vb@62
   151
                "create unique index if not exists trust_index on trust ("
vb@62
   152
                "   user_id,"
vb@62
   153
                "   pgp_keypair_fpr"
vb@62
   154
                ");",
vb@62
   155
            NULL,
vb@62
   156
            NULL,
vb@62
   157
            NULL
vb@62
   158
        );
vb@62
   159
        assert(int_result == SQLITE_OK);
vb@0
   160
vb@62
   161
        int_result = sqlite3_exec(
vb@62
   162
            _session->db,
vb@62
   163
            "insert or replace into version_info (id, version) values (1, '1.0');",
vb@62
   164
            NULL,
vb@62
   165
            NULL,
vb@62
   166
            NULL
vb@62
   167
        );
vb@62
   168
        assert(int_result == SQLITE_OK);
vb@0
   169
vb@62
   170
        sql_log = "insert into log (title, entity, description, comment)"
vb@62
   171
                  "values (?1, ?2, ?3, ?4);";
vb@62
   172
vb@62
   173
        sql_get_identity =	"select fpr, identity.user_id, username, comm_type, lang"
vb@62
   174
                            "   from identity"
vb@62
   175
                            "   join person on id = identity.user_id"
vb@62
   176
                            "   join pgp_keypair on fpr = identity.main_key_id"
vb@62
   177
                            "   join trust on id = trust.user_id"
vb@62
   178
                            "       and pgp_keypair_fpr = identity.main_key_id"
vb@62
   179
                            "   where address = ?1 ;";
vb@62
   180
vb@233
   181
        sql_trustword = "select id, word from wordlist where lang = lower(?1) "
vb@62
   182
                       "and id = ?2 ;";
vb@62
   183
vb@62
   184
        sql_set_person = "insert or replace into person (id, username, lang) "
vb@62
   185
                         "values (?1, ?2, ?3) ;";
vb@62
   186
vb@62
   187
        sql_set_pgp_keypair = "insert or replace into pgp_keypair (fpr) "
vb@62
   188
                              "values (?1) ;";
vb@62
   189
vb@62
   190
        sql_set_identity = "insert or replace into identity (address, main_key_id, "
vb@62
   191
                           "user_id) values (?1, ?2, ?3) ;";
vb@62
   192
vb@62
   193
        sql_set_trust = "insert or replace into trust (user_id, pgp_keypair_fpr, comm_type) "
vb@62
   194
                        "values (?1, ?2, ?3) ;";
vb@62
   195
vb@62
   196
        sql_get_trust = "select user_id, comm_type from trust where user_id = ?1 "
vb@62
   197
                        "and pgp_keypair_fpr = ?2 ;";
vb@251
   198
vb@251
   199
        sql_least_trust = "select min(comm_type) from trust where pgp_keypair_fpr = ?1 ;";
vb@357
   200
vb@357
   201
        sql_mark_as_compromized = "update trust set comm_type = 15 where pgp_keypair_fpr = ?1 ;";
vb@62
   202
    }
vb@62
   203
vb@0
   204
    int_result = sqlite3_prepare_v2(_session->db, sql_log, strlen(sql_log),
vb@0
   205
            &_session->log, NULL);
vb@0
   206
	assert(int_result == SQLITE_OK);
vb@0
   207
vb@233
   208
    int_result = sqlite3_prepare_v2(_session->system_db, sql_trustword,
vb@233
   209
            strlen(sql_trustword), &_session->trustword, NULL);
vb@0
   210
	assert(int_result == SQLITE_OK);
vb@0
   211
vb@0
   212
    int_result = sqlite3_prepare_v2(_session->db, sql_get_identity,
vb@0
   213
            strlen(sql_get_identity), &_session->get_identity, NULL);
vb@0
   214
	assert(int_result == SQLITE_OK);
vb@0
   215
vb@0
   216
    int_result = sqlite3_prepare_v2(_session->db, sql_set_person,
vb@0
   217
            strlen(sql_set_person), &_session->set_person, NULL);
vb@0
   218
    assert(int_result == SQLITE_OK);
vb@62
   219
vb@0
   220
    int_result = sqlite3_prepare_v2(_session->db, sql_set_pgp_keypair,
vb@0
   221
            strlen(sql_set_pgp_keypair), &_session->set_pgp_keypair, NULL);
vb@0
   222
	assert(int_result == SQLITE_OK);
vb@62
   223
vb@0
   224
    int_result = sqlite3_prepare_v2(_session->db, sql_set_identity,
vb@0
   225
            strlen(sql_set_identity), &_session->set_identity, NULL);
vb@0
   226
	assert(int_result == SQLITE_OK);
vb@62
   227
vb@0
   228
    int_result = sqlite3_prepare_v2(_session->db, sql_set_trust,
vb@0
   229
            strlen(sql_set_trust), &_session->set_trust, NULL);
vb@0
   230
	assert(int_result == SQLITE_OK);
vb@62
   231
vb@8
   232
    int_result = sqlite3_prepare_v2(_session->db, sql_get_trust,
vb@8
   233
            strlen(sql_get_trust), &_session->get_trust, NULL);
vb@8
   234
    assert(int_result == SQLITE_OK);
vb@0
   235
vb@251
   236
    int_result = sqlite3_prepare_v2(_session->db, sql_least_trust,
vb@251
   237
            strlen(sql_least_trust), &_session->least_trust, NULL);
vb@251
   238
    assert(int_result == SQLITE_OK);
vb@251
   239
vb@357
   240
    int_result = sqlite3_prepare_v2(_session->db, sql_mark_as_compromized,
vb@357
   241
            strlen(sql_mark_as_compromized), &_session->mark_compromized, NULL);
vb@357
   242
    assert(int_result == SQLITE_OK);
vb@357
   243
vb@65
   244
    status = init_cryptotech(_session, in_first);
vb@65
   245
    if (status != PEP_STATUS_OK)
vb@65
   246
        goto pep_error;
vb@0
   247
vb@65
   248
    status = init_transport_system(_session, in_first);
vb@65
   249
    if (status != PEP_STATUS_OK)
vb@65
   250
        goto pep_error;
vb@62
   251
vb@65
   252
    status = log_event(_session, "init", "pEp " PEP_ENGINE_VERSION, NULL, NULL);
vb@65
   253
    if (status != PEP_STATUS_OK)
vb@65
   254
        goto pep_error;
vb@65
   255
vb@65
   256
	*session = _session;
vb@0
   257
	return PEP_STATUS_OK;
vb@65
   258
vb@65
   259
enomem:
vb@65
   260
    status = PEP_OUT_OF_MEMORY;
vb@65
   261
vb@65
   262
pep_error:
vb@65
   263
    release(_session);
vb@65
   264
    return status;
vb@0
   265
}
vb@0
   266
vb@0
   267
DYNAMIC_API void release(PEP_SESSION session)
vb@0
   268
{
vb@62
   269
    bool out_last = false;
vb@62
   270
vb@62
   271
    assert(init_count >= 0);
vb@0
   272
	assert(session);
vb@0
   273
vb@191
   274
    if (!(init_count && session))
vb@191
   275
        return;
vb@191
   276
vb@62
   277
    // a small race condition but still a race condition
vb@113
   278
    // mitigated by calling caveat (see documentation)
vb@62
   279
vb@62
   280
    if (init_count == 0)
vb@62
   281
        out_last = true;
vb@62
   282
    --init_count;
vb@62
   283
vb@46
   284
	if (session) {
vb@46
   285
		if (session->db) {
vb@233
   286
            if (session->trustword)
vb@233
   287
                sqlite3_finalize(session->trustword);
vb@65
   288
            if (session->log)
vb@65
   289
                sqlite3_finalize(session->log);
vb@65
   290
            if (session->get_identity)
vb@65
   291
                sqlite3_finalize(session->get_identity);
vb@65
   292
            if (session->set_identity)
vb@65
   293
                sqlite3_finalize(session->set_identity);
vb@65
   294
            if (session->set_person)
vb@65
   295
                sqlite3_finalize(session->set_person);
vb@65
   296
            if (session->set_pgp_keypair)
vb@65
   297
                sqlite3_finalize(session->set_pgp_keypair);
vb@65
   298
            if (session->set_trust)
vb@65
   299
                sqlite3_finalize(session->set_trust);
vb@65
   300
            if (session->get_trust)
vb@65
   301
                sqlite3_finalize(session->get_trust);
vb@251
   302
            if (session->least_trust)
vb@251
   303
                sqlite3_finalize(session->least_trust);
vb@26
   304
vb@65
   305
            if (session->db)
vb@65
   306
                sqlite3_close_v2(session->db);
vb@65
   307
            if (session->system_db)
vb@65
   308
                sqlite3_close_v2(session->system_db);
vb@0
   309
		}
vb@65
   310
vb@65
   311
        release_transport_system(session, out_last);
vb@65
   312
        release_cryptotech(session, out_last);
vb@65
   313
vb@65
   314
        free(session);
vb@62
   315
    }
vb@0
   316
}
vb@0
   317
vb@0
   318
DYNAMIC_API PEP_STATUS log_event(
vb@0
   319
        PEP_SESSION session, const char *title, const char *entity,
vb@0
   320
        const char *description, const char *comment
vb@0
   321
    )
vb@0
   322
{
vb@0
   323
	PEP_STATUS status = PEP_STATUS_OK;
vb@0
   324
	int result;
vb@0
   325
vb@46
   326
	assert(session);
vb@0
   327
	assert(title);
vb@0
   328
	assert(entity);
vb@0
   329
vb@191
   330
    if (!(session && title && entity))
vb@191
   331
        return PEP_ILLEGAL_VALUE;
vb@191
   332
vb@46
   333
	sqlite3_reset(session->log);
vb@46
   334
	sqlite3_bind_text(session->log, 1, title, -1, SQLITE_STATIC);
vb@46
   335
	sqlite3_bind_text(session->log, 2, entity, -1, SQLITE_STATIC);
vb@0
   336
	if (description)
vb@46
   337
        sqlite3_bind_text(session->log, 3, description, -1, SQLITE_STATIC);
vb@0
   338
	else
vb@46
   339
		sqlite3_bind_null(session->log, 3);
vb@0
   340
	if (comment)
vb@46
   341
		sqlite3_bind_text(session->log, 4, comment, -1, SQLITE_STATIC);
vb@0
   342
	else
vb@46
   343
		sqlite3_bind_null(session->log, 4);
vb@0
   344
	do {
vb@46
   345
		result = sqlite3_step(session->log);
vb@0
   346
		assert(result == SQLITE_DONE || result == SQLITE_BUSY);
vb@0
   347
		if (result != SQLITE_DONE && result != SQLITE_BUSY)
vb@0
   348
			status = PEP_UNKNOWN_ERROR;
vb@0
   349
	} while (result == SQLITE_BUSY);
vb@46
   350
	sqlite3_reset(session->log);
vb@0
   351
vb@0
   352
	return status;
vb@0
   353
}
vb@0
   354
vb@233
   355
DYNAMIC_API PEP_STATUS trustword(
vb@0
   356
            PEP_SESSION session, uint16_t value, const char *lang,
vb@0
   357
            char **word, size_t *wsize
vb@0
   358
        )
vb@0
   359
{
vb@0
   360
	PEP_STATUS status = PEP_STATUS_OK;
vb@0
   361
	int result;
vb@0
   362
vb@46
   363
	assert(session);
vb@0
   364
	assert(word);
vb@0
   365
	assert(wsize);
vb@0
   366
vb@191
   367
    if (!(session && word && wsize))
vb@191
   368
        return PEP_ILLEGAL_VALUE;
vb@191
   369
vb@0
   370
	*word = NULL;
vb@0
   371
	*wsize = 0;
vb@0
   372
vb@0
   373
	if (lang == NULL)
vb@0
   374
		lang = "en";
vb@0
   375
vb@0
   376
	assert((lang[0] >= 'A' && lang[0] <= 'Z')
vb@0
   377
            || (lang[0] >= 'a' && lang[0] <= 'z'));
vb@0
   378
	assert((lang[1] >= 'A' && lang[1] <= 'Z')
vb@0
   379
            || (lang[1] >= 'a' && lang[1] <= 'z'));
vb@0
   380
	assert(lang[2] == 0);
vb@0
   381
vb@233
   382
	sqlite3_reset(session->trustword);
vb@233
   383
    sqlite3_bind_text(session->trustword, 1, lang, -1, SQLITE_STATIC);
vb@233
   384
	sqlite3_bind_int(session->trustword, 2, value);
vb@0
   385
vb@233
   386
	result = sqlite3_step(session->trustword);
vb@0
   387
	if (result == SQLITE_ROW) {
vb@233
   388
        *word = strdup((const char *) sqlite3_column_text(session->trustword,
vb@0
   389
                    1));
vb@0
   390
		if (*word)
vb@233
   391
            *wsize = sqlite3_column_bytes(session->trustword, 1);
vb@0
   392
		else
vb@251
   393
			status = PEP_TRUSTWORD_NOT_FOUND;
vb@0
   394
	} else
vb@251
   395
		status = PEP_TRUSTWORD_NOT_FOUND;
vb@0
   396
vb@233
   397
	sqlite3_reset(session->trustword);
vb@0
   398
	return status;
vb@0
   399
}
vb@0
   400
vb@233
   401
DYNAMIC_API PEP_STATUS trustwords(
vb@0
   402
        PEP_SESSION session, const char *fingerprint, const char *lang,
vb@0
   403
        char **words, size_t *wsize, int max_words
vb@0
   404
    )
vb@0
   405
{
vb@0
   406
	const char *source = fingerprint;
vb@109
   407
	char *buffer;
vb@125
   408
	char *dest;
vb@0
   409
	size_t fsize;
vb@0
   410
    PEP_STATUS _status;
vb@0
   411
vb@0
   412
	assert(session);
vb@0
   413
	assert(fingerprint);
vb@0
   414
	assert(words);
vb@0
   415
	assert(wsize);
vb@0
   416
	assert(max_words >= 0);
vb@0
   417
vb@191
   418
    if (!(session && fingerprint && words && wsize && max_words >= 0))
vb@191
   419
        return PEP_ILLEGAL_VALUE;
vb@191
   420
vb@0
   421
	*words = NULL;
vb@0
   422
	*wsize = 0;
vb@0
   423
vb@251
   424
    buffer = calloc(1, MAX_TRUSTWORDS_SPACE);
vb@0
   425
    assert(buffer);
vb@0
   426
    if (buffer == NULL)
vb@0
   427
        return PEP_OUT_OF_MEMORY;
vb@125
   428
    dest = buffer;
vb@0
   429
vb@0
   430
	fsize = strlen(fingerprint);
vb@0
   431
vb@339
   432
	if (!lang || !lang[0])
vb@0
   433
		lang = "en";
vb@0
   434
vb@0
   435
	assert((lang[0] >= 'A' && lang[0] <= 'Z')
vb@0
   436
            || (lang[0] >= 'a' && lang[0] <= 'z'));
vb@0
   437
	assert((lang[1] >= 'A' && lang[1] <= 'Z')
vb@0
   438
            || (lang[1] >= 'a' && lang[1] <= 'z'));
vb@0
   439
	assert(lang[2] == 0);
vb@0
   440
vb@0
   441
	int n_words = 0;
vb@0
   442
	while (source < fingerprint + fsize) {
vb@0
   443
		uint16_t value;
vb@0
   444
		char *word;
vb@0
   445
		size_t _wsize;
vb@0
   446
		int j;
vb@0
   447
vb@0
   448
        for (value=0, j=0; j < 4 && source < fingerprint + fsize; ) {
vb@0
   449
			if (*source >= 'a' && *source <= 'f')
vb@0
   450
				value += (*source - 'a' + 10) << (3 - j++) * 4;
vb@0
   451
			else if (*source >= 'A' && *source <= 'F')
vb@0
   452
				value += (*source - 'A' + 10) << (3 - j++) * 4;
vb@0
   453
			else if (*source >= '0' && *source <= '9')
vb@0
   454
				value += (*source - '0') << (3 - j++) * 4;
vb@0
   455
			
vb@0
   456
			source++;
vb@0
   457
		}
vb@0
   458
vb@233
   459
		_status = trustword(session, value, lang, &word, &_wsize);
vb@0
   460
        if (_status == PEP_OUT_OF_MEMORY) {
vb@0
   461
            free(buffer);
vb@0
   462
            return PEP_OUT_OF_MEMORY;
vb@0
   463
        }
vb@0
   464
		if (word == NULL) {
vb@0
   465
            free(buffer);
vb@251
   466
			return PEP_TRUSTWORD_NOT_FOUND;
vb@0
   467
        }
vb@0
   468
vb@251
   469
		if (dest + _wsize < buffer + MAX_TRUSTWORDS_SPACE - 1) {
vb@0
   470
			strncpy(dest, word, _wsize);
vb@0
   471
            free(word);
vb@0
   472
			dest += _wsize;
vb@0
   473
		}
vb@0
   474
		else {
vb@0
   475
            free(word);
vb@0
   476
			break; // buffer full
vb@0
   477
        }
vb@0
   478
vb@0
   479
		if (source < fingerprint + fsize
vb@251
   480
                && dest + _wsize < buffer + MAX_TRUSTWORDS_SPACE - 1)
vb@0
   481
			*dest++ = ' ';
vb@0
   482
vb@0
   483
		++n_words;
vb@0
   484
		if (max_words && n_words >= max_words)
vb@0
   485
			break;
vb@0
   486
	}
vb@0
   487
vb@0
   488
	*words = buffer;
vb@0
   489
	*wsize = dest - buffer;
vb@0
   490
	return PEP_STATUS_OK;
vb@0
   491
}
vb@0
   492
vb@0
   493
pEp_identity *new_identity(
vb@0
   494
        const char *address, const char *fpr, const char *user_id,
vb@0
   495
        const char *username
vb@0
   496
    )
vb@0
   497
{
vb@0
   498
    pEp_identity *result = calloc(1, sizeof(pEp_identity));
vb@0
   499
    assert(result);
vb@0
   500
    if (result) {
vb@0
   501
        if (address) {
vb@0
   502
            result->address = strdup(address);
vb@0
   503
            assert(result->address);
vb@0
   504
            if (result->address == NULL) {
vb@0
   505
                free(result);
vb@0
   506
                return NULL;
vb@0
   507
            }
vb@0
   508
            result->address_size = strlen(address);
vb@0
   509
        }
vb@0
   510
        if (fpr) {
vb@0
   511
            result->fpr = strdup(fpr);
vb@0
   512
            assert(result->fpr);
vb@0
   513
            if (result->fpr == NULL) {
vb@0
   514
                free_identity(result);
vb@0
   515
                return NULL;
vb@0
   516
            }
vb@0
   517
            result->fpr_size = strlen(fpr);
vb@0
   518
        }
vb@0
   519
        if (user_id) {
vb@0
   520
            result->user_id = strdup(user_id);
vb@0
   521
            assert(result->user_id);
vb@0
   522
            if (result->user_id == NULL) {
vb@0
   523
                free_identity(result);
vb@0
   524
                return NULL;
vb@0
   525
            }
vb@0
   526
            result->user_id_size = strlen(user_id);
vb@0
   527
        }
vb@0
   528
        if (username) {
vb@0
   529
            result->username = strdup(username);
vb@0
   530
            assert(result->username);
vb@0
   531
            if (result->username == NULL) {
vb@0
   532
                free_identity(result);
vb@0
   533
                return NULL;
vb@0
   534
            }
vb@0
   535
            result->username_size = strlen(username);
vb@0
   536
        }
vb@0
   537
        result->struct_size = sizeof(pEp_identity);
vb@0
   538
    }
vb@0
   539
    return result;
vb@0
   540
}
vb@0
   541
vb@37
   542
pEp_identity *identity_dup(const pEp_identity *src)
vb@37
   543
{
vb@37
   544
    assert(src);
vb@37
   545
vb@37
   546
    pEp_identity *dup = new_identity(src->address, src->fpr, src->user_id, src->username);
vb@37
   547
    assert(dup);
vb@37
   548
    if (dup == NULL)
vb@37
   549
        return NULL;
vb@37
   550
    
vb@37
   551
    dup->comm_type = src->comm_type;
vb@37
   552
    dup->lang[0] = src->lang[0];
vb@37
   553
    dup->lang[1] = src->lang[1];
vb@37
   554
    dup->lang[2] = 0;
vb@37
   555
    dup->me = src->me;
vb@37
   556
vb@37
   557
    return dup;
vb@37
   558
}
vb@37
   559
vb@0
   560
void free_identity(pEp_identity *identity)
vb@0
   561
{
vb@0
   562
    if (identity) {
vb@0
   563
        free(identity->address);
vb@0
   564
        free(identity->fpr);
vb@0
   565
        free(identity->user_id);
vb@0
   566
        free(identity->username);
vb@0
   567
        free(identity);
vb@0
   568
    }
vb@0
   569
}
vb@0
   570
vb@0
   571
DYNAMIC_API PEP_STATUS get_identity(
vb@0
   572
        PEP_SESSION session, const char *address,
vb@0
   573
        pEp_identity **identity
vb@0
   574
    )
vb@0
   575
{
vb@0
   576
	PEP_STATUS status = PEP_STATUS_OK;
vb@0
   577
	static pEp_identity *_identity;
vb@0
   578
	int result;
vb@0
   579
	const char *_lang;
vb@0
   580
vb@0
   581
	assert(session);
vb@0
   582
	assert(address);
vb@8
   583
    assert(address[0]);
vb@0
   584
vb@191
   585
    if (!(session && address && address[0]))
vb@191
   586
        return PEP_ILLEGAL_VALUE;
vb@191
   587
vb@46
   588
    sqlite3_reset(session->get_identity);
vb@46
   589
    sqlite3_bind_text(session->get_identity, 1, address, -1, SQLITE_STATIC);
vb@0
   590
vb@46
   591
    result = sqlite3_step(session->get_identity);
vb@0
   592
	switch (result) {
vb@0
   593
	case SQLITE_ROW:
vb@0
   594
        _identity = new_identity(
vb@0
   595
                address,
vb@46
   596
                (const char *) sqlite3_column_text(session->get_identity, 0),
vb@46
   597
                (const char *) sqlite3_column_text(session->get_identity, 1),
vb@46
   598
                (const char *) sqlite3_column_text(session->get_identity, 2)
vb@0
   599
                );
vb@0
   600
        assert(_identity);
vb@0
   601
        if (_identity == NULL)
vb@0
   602
            return PEP_OUT_OF_MEMORY;
vb@0
   603
vb@46
   604
        _identity->comm_type = (PEP_comm_type) sqlite3_column_int(session->get_identity, 3);
vb@46
   605
        _lang = (const char *) sqlite3_column_text(session->get_identity, 4);
vb@0
   606
        if (_lang && _lang[0]) {
vb@0
   607
			assert(_lang[0] >= 'a' && _lang[0] <= 'z');
vb@0
   608
			assert(_lang[1] >= 'a' && _lang[1] <= 'z');
vb@0
   609
			assert(_lang[2] == 0);
vb@0
   610
			_identity->lang[0] = _lang[0];
vb@0
   611
			_identity->lang[1] = _lang[1];
vb@0
   612
            _identity->lang[2] = 0;
vb@0
   613
		}
vb@0
   614
		*identity = _identity;
vb@0
   615
		break;
vb@0
   616
	default:
vb@0
   617
        status = PEP_CANNOT_FIND_IDENTITY;
vb@0
   618
		*identity = NULL;
vb@0
   619
	}
vb@0
   620
vb@46
   621
    sqlite3_reset(session->get_identity);
vb@0
   622
	return status;
vb@0
   623
}
vb@0
   624
vb@0
   625
DYNAMIC_API PEP_STATUS set_identity(
vb@0
   626
        PEP_SESSION session, const pEp_identity *identity
vb@0
   627
    )
vb@0
   628
{
vb@0
   629
	int result;
vb@0
   630
vb@0
   631
	assert(session);
vb@0
   632
	assert(identity);
vb@0
   633
	assert(identity->address);
vb@0
   634
	assert(identity->fpr);
vb@0
   635
	assert(identity->user_id);
vb@0
   636
	assert(identity->username);
vb@0
   637
vb@191
   638
    if (!(session && identity && identity->address && identity->fpr &&
vb@191
   639
                identity->user_id && identity->username))
vb@191
   640
        return PEP_ILLEGAL_VALUE;
vb@191
   641
vb@46
   642
	sqlite3_exec(session->db, "BEGIN ;", NULL, NULL, NULL);
vb@0
   643
vb@46
   644
	sqlite3_reset(session->set_person);
vb@46
   645
    sqlite3_bind_text(session->set_person, 1, identity->user_id, -1,
vb@0
   646
            SQLITE_STATIC);
vb@46
   647
    sqlite3_bind_text(session->set_person, 2, identity->username, -1,
vb@0
   648
            SQLITE_STATIC);
vb@0
   649
	if (identity->lang[0])
vb@46
   650
        sqlite3_bind_text(session->set_person, 3, identity->lang, 1,
vb@0
   651
                SQLITE_STATIC);
vb@0
   652
	else
vb@46
   653
		sqlite3_bind_null(session->set_person, 3);
vb@46
   654
	result = sqlite3_step(session->set_person);
vb@46
   655
	sqlite3_reset(session->set_person);
vb@0
   656
	if (result != SQLITE_DONE) {
vb@46
   657
		sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
vb@0
   658
		return PEP_CANNOT_SET_PERSON;
vb@0
   659
	}
vb@0
   660
vb@46
   661
	sqlite3_reset(session->set_pgp_keypair);
vb@46
   662
    sqlite3_bind_text(session->set_pgp_keypair, 1, identity->fpr, -1,
vb@0
   663
            SQLITE_STATIC);
vb@46
   664
	result = sqlite3_step(session->set_pgp_keypair);
vb@46
   665
	sqlite3_reset(session->set_pgp_keypair);
vb@0
   666
	if (result != SQLITE_DONE) {
vb@46
   667
		sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
vb@0
   668
		return PEP_CANNOT_SET_PGP_KEYPAIR;
vb@0
   669
	}
vb@0
   670
vb@46
   671
	sqlite3_reset(session->set_identity);
vb@46
   672
    sqlite3_bind_text(session->set_identity, 1, identity->address, -1,
vb@0
   673
            SQLITE_STATIC);
vb@46
   674
    sqlite3_bind_text(session->set_identity, 2, identity->fpr, -1,
vb@0
   675
            SQLITE_STATIC);
vb@46
   676
    sqlite3_bind_text(session->set_identity, 3, identity->user_id, -1,
vb@0
   677
            SQLITE_STATIC);
vb@46
   678
	result = sqlite3_step(session->set_identity);
vb@46
   679
	sqlite3_reset(session->set_identity);
vb@0
   680
	if (result != SQLITE_DONE) {
vb@46
   681
		sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
vb@0
   682
		return PEP_CANNOT_SET_IDENTITY;
vb@0
   683
	}
vb@0
   684
vb@46
   685
	sqlite3_reset(session->set_trust);
vb@46
   686
    sqlite3_bind_text(session->set_trust, 1, identity->user_id, -1,
vb@0
   687
            SQLITE_STATIC);
vb@46
   688
    sqlite3_bind_text(session->set_trust, 2, identity->fpr, -1,
vb@0
   689
            SQLITE_STATIC);
vb@46
   690
	sqlite3_bind_int(session->set_trust, 3, identity->comm_type);
vb@46
   691
	result = sqlite3_step(session->set_trust);
vb@46
   692
	sqlite3_reset(session->set_trust);
vb@0
   693
	if (result != SQLITE_DONE) {
vb@46
   694
		sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
vb@0
   695
		return PEP_CANNOT_SET_IDENTITY;
vb@0
   696
	}
vb@0
   697
vb@46
   698
    result = sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
vb@0
   699
	if (result == SQLITE_OK)
vb@0
   700
		return PEP_STATUS_OK;
vb@0
   701
	else
vb@0
   702
		return PEP_COMMIT_FAILED;
vb@0
   703
}
vb@0
   704
vb@357
   705
DYNAMIC_API PEP_STATUS mark_as_compromized(
vb@357
   706
        PEP_SESSION session,
vb@357
   707
        const char *fpr
vb@357
   708
    )
vb@357
   709
{
vb@357
   710
	int result;
vb@357
   711
vb@357
   712
	assert(session);
vb@357
   713
    assert(fpr && fpr[0]);
vb@357
   714
vb@357
   715
    if (!(session && fpr && fpr[0]))
vb@357
   716
        return PEP_ILLEGAL_VALUE;
vb@357
   717
vb@357
   718
	sqlite3_reset(session->mark_compromized);
vb@357
   719
    sqlite3_bind_text(session->mark_compromized, 1, fpr, -1,
vb@357
   720
            SQLITE_STATIC);
vb@357
   721
    result = sqlite3_step(session->mark_compromized);
vb@357
   722
	sqlite3_reset(session->mark_compromized);
vb@357
   723
vb@357
   724
    if (result != SQLITE_DONE)
vb@357
   725
        return PEP_CANNOT_SET_IDENTITY;
vb@357
   726
vb@357
   727
    return PEP_STATUS_OK;
vb@357
   728
}
vb@357
   729
vb@0
   730
void pEp_free(void *p)
vb@0
   731
{
vb@0
   732
    free(p);
vb@0
   733
}
vb@0
   734
vb@8
   735
DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity)
vb@8
   736
{
vb@8
   737
    PEP_STATUS status = PEP_STATUS_OK;
vb@8
   738
    int result;
vb@8
   739
vb@8
   740
    assert(session);
vb@8
   741
    assert(identity);
vb@8
   742
    assert(identity->user_id);
vb@8
   743
    assert(identity->user_id[0]);
vb@8
   744
    assert(identity->fpr);
vb@8
   745
    assert(identity->fpr[0]);
vb@8
   746
vb@191
   747
    if (!(session && identity && identity->user_id && identity->user_id[0] &&
vb@191
   748
                identity->fpr && identity->fpr[0]))
vb@191
   749
        return PEP_ILLEGAL_VALUE;
vb@191
   750
vb@8
   751
    identity->comm_type = PEP_ct_unknown;
vb@8
   752
vb@46
   753
    sqlite3_reset(session->get_trust);
vb@46
   754
    sqlite3_bind_text(session->get_trust, 1, identity->user_id, -1, SQLITE_STATIC);
vb@46
   755
    sqlite3_bind_text(session->get_trust, 2, identity->fpr, -1, SQLITE_STATIC);
vb@8
   756
vb@46
   757
    result = sqlite3_step(session->get_trust);
vb@8
   758
    switch (result) {
vb@8
   759
    case SQLITE_ROW: {
vb@259
   760
        const char * user_id = (const char *) sqlite3_column_text(session->get_trust, 0);
vb@259
   761
        int comm_type = (PEP_comm_type) sqlite3_column_int(session->get_trust, 1);
vb@8
   762
vb@8
   763
        if (strcmp(user_id, identity->user_id) != 0) {
vb@8
   764
            free(identity->user_id);
vb@8
   765
            identity->user_id = strdup(user_id);
vb@8
   766
            assert(identity->user_id);
vb@8
   767
            if (identity->user_id == NULL)
vb@8
   768
                return PEP_OUT_OF_MEMORY;
vb@8
   769
        }
vb@8
   770
        identity->comm_type = comm_type;
vb@8
   771
        break;
vb@8
   772
    }
vb@8
   773
 
vb@8
   774
    default:
vb@8
   775
        status = PEP_CANNOT_FIND_IDENTITY;
vb@8
   776
    }
vb@8
   777
vb@46
   778
    sqlite3_reset(session->get_trust);
vb@8
   779
    return status;
vb@9
   780
}
vb@9
   781
vb@251
   782
DYNAMIC_API PEP_STATUS least_trust(
vb@251
   783
        PEP_SESSION session,
vb@251
   784
        const char *fpr,
vb@251
   785
        PEP_comm_type *comm_type
vb@251
   786
    )
vb@251
   787
{
vb@251
   788
    PEP_STATUS status = PEP_STATUS_OK;
vb@251
   789
    int result;
vb@251
   790
vb@251
   791
    assert(session);
vb@251
   792
    assert(fpr);
vb@251
   793
    assert(comm_type);
vb@251
   794
vb@259
   795
    *comm_type = PEP_ct_unknown;
vb@259
   796
vb@251
   797
    if (!(session && fpr && comm_type))
vb@251
   798
        return PEP_ILLEGAL_VALUE;
vb@251
   799
vb@251
   800
    sqlite3_reset(session->least_trust);
vb@251
   801
    sqlite3_bind_text(session->least_trust, 1, fpr, -1, SQLITE_STATIC);
vb@251
   802
vb@251
   803
    result = sqlite3_step(session->least_trust);
vb@251
   804
    switch (result) {
vb@251
   805
        case SQLITE_ROW: {
vb@259
   806
            int _comm_type = sqlite3_column_int(session->least_trust, 0);
vb@259
   807
            *comm_type = (PEP_comm_type) _comm_type;
vb@251
   808
            break;
vb@251
   809
        }
vb@251
   810
        default:
vb@251
   811
            status = PEP_CANNOT_FIND_IDENTITY;
vb@251
   812
    }
vb@251
   813
vb@251
   814
    sqlite3_reset(session->least_trust);
vb@251
   815
    return status;
vb@251
   816
}
vb@251
   817
vb@24
   818
DYNAMIC_API PEP_STATUS decrypt_and_verify(
vb@24
   819
    PEP_SESSION session, const char *ctext, size_t csize,
vb@24
   820
    char **ptext, size_t *psize, stringlist_t **keylist
vb@24
   821
    )
vb@24
   822
{
vb@191
   823
    assert(session);
vb@191
   824
    assert(ctext);
vb@191
   825
    assert(csize);
vb@191
   826
    assert(ptext);
vb@191
   827
    assert(psize);
vb@191
   828
    assert(keylist);
vb@191
   829
vb@191
   830
    if (!(session && ctext && csize && ptext && psize && keylist && keylist))
vb@191
   831
        return PEP_ILLEGAL_VALUE;
vb@191
   832
vb@46
   833
    return session->cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify(session, ctext, csize, ptext, psize, keylist);
vb@24
   834
}
vb@24
   835
vb@24
   836
DYNAMIC_API PEP_STATUS encrypt_and_sign(
vb@24
   837
    PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
vb@24
   838
    size_t psize, char **ctext, size_t *csize
vb@24
   839
    )
vb@24
   840
{
vb@191
   841
    assert(session);
vb@191
   842
    assert(keylist);
vb@191
   843
    assert(ptext);
vb@191
   844
    assert(psize);
vb@191
   845
    assert(ctext);
vb@191
   846
    assert(csize);
vb@191
   847
vb@191
   848
    if (!(session && keylist && ptext && psize && ctext && csize))
vb@191
   849
        return PEP_ILLEGAL_VALUE;
vb@191
   850
vb@46
   851
    return session->cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign(session, keylist, ptext, psize, ctext, csize);
vb@24
   852
}
vb@24
   853
vb@24
   854
DYNAMIC_API PEP_STATUS verify_text(
vb@24
   855
    PEP_SESSION session, const char *text, size_t size,
vb@24
   856
    const char *signature, size_t sig_size, stringlist_t **keylist
vb@24
   857
    )
vb@24
   858
{
vb@191
   859
    assert(session);
vb@191
   860
    assert(text);
vb@191
   861
    assert(size);
vb@191
   862
    assert(signature);
vb@191
   863
    assert(sig_size);
vb@191
   864
    assert(keylist);
vb@191
   865
vb@191
   866
    if (!(session && text && size && signature && sig_size && keylist))
vb@191
   867
        return PEP_ILLEGAL_VALUE;
vb@191
   868
vb@46
   869
    return session->cryptotech[PEP_crypt_OpenPGP].verify_text(session, text, size, signature, sig_size, keylist);
vb@24
   870
}
vb@24
   871
vb@24
   872
DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr)
vb@24
   873
{
vb@191
   874
    assert(session);
vb@191
   875
    assert(fpr);
vb@191
   876
vb@191
   877
    if (!(session && fpr))
vb@191
   878
        return PEP_ILLEGAL_VALUE;
vb@191
   879
vb@46
   880
    return session->cryptotech[PEP_crypt_OpenPGP].delete_keypair(session, fpr);
vb@24
   881
}
vb@24
   882
vb@24
   883
DYNAMIC_API PEP_STATUS export_key(
vb@46
   884
        PEP_SESSION session, const char *fpr, char **key_data, size_t *size
vb@24
   885
    )
vb@24
   886
{
vb@191
   887
    assert(session);
vb@191
   888
    assert(fpr);
vb@191
   889
    assert(key_data);
vb@191
   890
    assert(size);
vb@191
   891
vb@191
   892
    if (!(session && fpr && key_data && size))
vb@191
   893
        return PEP_ILLEGAL_VALUE;
vb@191
   894
vb@46
   895
    return session->cryptotech[PEP_crypt_OpenPGP].export_key(session, fpr, key_data, size);
vb@24
   896
}
vb@24
   897
vb@24
   898
DYNAMIC_API PEP_STATUS find_keys(
vb@46
   899
        PEP_SESSION session, const char *pattern, stringlist_t **keylist
vb@24
   900
    )
vb@24
   901
{
vb@191
   902
    assert(session);
vb@191
   903
    assert(pattern);
vb@191
   904
    assert(keylist);
vb@191
   905
vb@191
   906
    if (!(session && pattern && keylist))
vb@191
   907
        return PEP_ILLEGAL_VALUE;
vb@191
   908
vb@46
   909
    return session->cryptotech[PEP_crypt_OpenPGP].find_keys(session, pattern, keylist);
vb@24
   910
}
vb@24
   911
vb@24
   912
DYNAMIC_API PEP_STATUS generate_keypair(
vb@46
   913
        PEP_SESSION session, pEp_identity *identity
vb@24
   914
    )
vb@24
   915
{
vb@191
   916
    assert(session);
vb@191
   917
    assert(identity);
vb@191
   918
    assert(identity->address);
vb@298
   919
    assert(identity->fpr == NULL || identity->fpr[0] == 0);
vb@191
   920
    assert(identity->username);
vb@191
   921
vb@298
   922
    if (!(session && identity && identity->address &&
vb@298
   923
        (identity->fpr == NULL || identity->fpr[0] == 0) && identity->username))
vb@191
   924
        return PEP_ILLEGAL_VALUE;
vb@191
   925
vb@46
   926
    return session->cryptotech[PEP_crypt_OpenPGP].generate_keypair(session, identity);
vb@24
   927
}
vb@24
   928
vb@9
   929
DYNAMIC_API PEP_STATUS get_key_rating(
vb@46
   930
        PEP_SESSION session,
vb@46
   931
        const char *fpr,
vb@46
   932
        PEP_comm_type *comm_type
vb@9
   933
    )
vb@9
   934
{
vb@191
   935
    assert(session);
vb@191
   936
    assert(fpr);
vb@191
   937
    assert(comm_type);
vb@191
   938
vb@191
   939
    if (!(session && fpr && comm_type))
vb@191
   940
        return PEP_ILLEGAL_VALUE;
vb@191
   941
vb@46
   942
    return session->cryptotech[PEP_crypt_OpenPGP].get_key_rating(session, fpr, comm_type);
vb@24
   943
}
vb@9
   944
vb@24
   945
DYNAMIC_API PEP_STATUS import_key(PEP_SESSION session, const char *key_data, size_t size)
vb@24
   946
{
vb@191
   947
    assert(session);
vb@191
   948
    assert(key_data);
vb@191
   949
vb@191
   950
    if (!(session && key_data))
vb@191
   951
        return PEP_ILLEGAL_VALUE;
vb@191
   952
vb@46
   953
    return session->cryptotech[PEP_crypt_OpenPGP].import_key(session, key_data, size);
vb@24
   954
}
vb@9
   955
vb@24
   956
DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern)
vb@24
   957
{
vb@191
   958
    assert(session);
vb@191
   959
    assert(pattern);
vb@191
   960
vb@191
   961
    if (!(session && pattern))
vb@191
   962
        return PEP_ILLEGAL_VALUE;
vb@191
   963
vb@46
   964
    return session->cryptotech[PEP_crypt_OpenPGP].recv_key(session, pattern);
vb@24
   965
}
vb@9
   966
vb@24
   967
DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern)
vb@24
   968
{
vb@191
   969
    assert(session);
vb@191
   970
    assert(pattern);
vb@191
   971
vb@191
   972
    if (!(session && pattern))
vb@191
   973
        return PEP_ILLEGAL_VALUE;
vb@191
   974
vb@46
   975
    return session->cryptotech[PEP_crypt_OpenPGP].send_key(session, pattern);
vb@14
   976
}
vb@196
   977
vb@201
   978
DYNAMIC_API PEP_STATUS renew_key(
vb@201
   979
        PEP_SESSION session,
vb@201
   980
        const char *fpr,
vb@201
   981
        const timestamp *ts
vb@201
   982
    )
vb@196
   983
{
vb@196
   984
    assert(session);
vb@200
   985
    assert(fpr);
vb@196
   986
vb@200
   987
    if (!(session && fpr))
vb@196
   988
        return PEP_ILLEGAL_VALUE;
vb@196
   989
vb@201
   990
    return session->cryptotech[PEP_crypt_OpenPGP].renew_key(session, fpr, ts);
vb@196
   991
}
vb@196
   992
vb@211
   993
DYNAMIC_API PEP_STATUS revoke_key(
vb@211
   994
        PEP_SESSION session,
vb@211
   995
        const char *fpr,
vb@211
   996
        const char *reason
vb@211
   997
    )
vb@197
   998
{
vb@197
   999
    assert(session);
vb@200
  1000
    assert(fpr);
vb@197
  1001
vb@200
  1002
    if (!(session && fpr))
vb@197
  1003
        return PEP_ILLEGAL_VALUE;
vb@197
  1004
vb@214
  1005
    return session->cryptotech[PEP_crypt_OpenPGP].revoke_key(session, fpr,
vb@214
  1006
            reason);
vb@197
  1007
}
vb@197
  1008
vb@214
  1009
DYNAMIC_API PEP_STATUS key_expired(
vb@214
  1010
        PEP_SESSION session,
vb@214
  1011
        const char *fpr,
vb@214
  1012
        bool *expired
vb@214
  1013
    )
vb@214
  1014
{
vb@214
  1015
    assert(session);
vb@214
  1016
    assert(fpr);
vb@214
  1017
    assert(expired);
vb@214
  1018
vb@214
  1019
    if (!(session && fpr && expired))
vb@214
  1020
        return PEP_ILLEGAL_VALUE;
vb@214
  1021
vb@214
  1022
    return session->cryptotech[PEP_crypt_OpenPGP].key_expired(session, fpr,
vb@214
  1023
            expired);
vb@214
  1024
}
vb@214
  1025