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