src/pEpEngine.h
author vb
Mon, 01 Sep 2014 13:02:23 +0200
changeset 23 dba569e54163
parent 20 63ff31d0cfbd
child 25 5af1602f5c66
permissions -rw-r--r--
adding the concepts of transports and cryptotech
vb@23
     1
#pragma once
vb@23
     2
vb@0
     3
#ifdef __cplusplus
vb@0
     4
extern "C" {
vb@0
     5
#endif
vb@0
     6
vb@0
     7
#include <stdint.h>
vb@0
     8
#include <stdbool.h>
vb@0
     9
vb@0
    10
#ifdef WIN32
vb@0
    11
#ifdef _EXPORT_PEP_ENGINE_DLL
vb@0
    12
#define DYNAMIC_API __declspec(dllexport)
vb@0
    13
#else
vb@0
    14
#define DYNAMIC_API __declspec(dllimport)
vb@0
    15
#endif
vb@0
    16
#else
vb@0
    17
#define DYNAMIC_API
vb@0
    18
#endif
vb@0
    19
vb@0
    20
vb@0
    21
// pEp Engine API
vb@0
    22
vb@0
    23
//  caveat:
vb@0
    24
//      Unicode data has to be normalized to NFC before calling
vb@0
    25
//      UTF-8 strings are UTF-8 encoded C strings (zero terminated)
vb@0
    26
vb@0
    27
vb@0
    28
typedef void * PEP_SESSION;
vb@0
    29
vb@0
    30
typedef enum {
vb@0
    31
	PEP_STATUS_OK									= 0,
vb@0
    32
vb@0
    33
	PEP_INIT_CANNOT_LOAD_GPGME						= 0x0110,
vb@0
    34
	PEP_INIT_GPGME_INIT_FAILED						= 0x0111,
vb@0
    35
vb@0
    36
	PEP_INIT_SQLITE3_WITHOUT_MUTEX					= 0x0120,
vb@0
    37
	PEP_INIT_CANNOT_OPEN_DB							= 0x0121,
vb@0
    38
	PEP_INIT_CANNOT_OPEN_SYSTEM_DB					= 0x0122,
vb@0
    39
	
vb@0
    40
	PEP_KEY_NOT_FOUND						        = 0x0201,
vb@0
    41
	PEP_KEY_HAS_AMBIG_NAME					        = 0x0202,
vb@0
    42
	PEP_GET_KEY_FAILED						        = 0x0203,
vb@0
    43
	
vb@0
    44
	PEP_CANNOT_FIND_IDENTITY						= 0x0301,
vb@0
    45
	PEP_CANNOT_SET_PERSON							= 0x0381,
vb@0
    46
	PEP_CANNOT_SET_PGP_KEYPAIR						= 0x0382,
vb@0
    47
	PEP_CANNOT_SET_IDENTITY							= 0x0383,
vb@0
    48
	
vb@0
    49
	PEP_UNENCRYPTED									= 0x0400,
vb@0
    50
	PEP_VERIFIED									= 0x0401,
vb@0
    51
	PEP_DECRYPTED									= 0x0402,
vb@0
    52
	PEP_DECRYPTED_AND_VERIFIED						= 0x0403,
vb@0
    53
	PEP_DECRYPT_WRONG_FORMAT						= 0x0404,
vb@0
    54
	PEP_DECRYPT_NO_KEY								= 0x0405,
vb@0
    55
	PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH			= 0x0406,
vb@0
    56
    PEP_VERIFY_NO_KEY                               = 0x0407,
vb@0
    57
    PEP_VERIFIED_AND_TRUSTED                        = 0x0408,
vb@0
    58
	PEP_CANNOT_DECRYPT_UNKNOWN						= 0x04ff,
vb@0
    59
vb@0
    60
	PEP_SAFEWORD_NOT_FOUND							= 0x0501,
vb@0
    61
vb@0
    62
    PEP_CANNOT_CREATE_KEY                           = 0x0601,
vb@0
    63
    PEP_CANNOT_SEND_KEY                             = 0x0602,
vb@0
    64
vb@0
    65
	PEP_COMMIT_FAILED								= 0xff01,
vb@0
    66
vb@0
    67
    PEP_ILLEGAL_VALUE                               = -4,
vb@0
    68
    PEP_BUFFER_TOO_SMALL                            = -3,
vb@0
    69
	PEP_OUT_OF_MEMORY								= -2,
vb@0
    70
	PEP_UNKNOWN_ERROR								= -1
vb@0
    71
} PEP_STATUS;
vb@0
    72
vb@0
    73
vb@0
    74
// INIT_STATUS init() - initialize pEpEngine for a thread
vb@0
    75
//
vb@0
    76
//  parameters:
vb@0
    77
//		session (out)	init() allocates session memory and returns a pointer
vb@0
    78
//		                as a handle
vb@0
    79
//
vb@0
    80
//  return value:
vb@0
    81
//		PEP_STATUS_OK = 0					if init() succeeds
vb@0
    82
//		PEP_INIT_SQLITE3_WITHOUT_MUTEX		if SQLite3 was compiled with
vb@0
    83
//		                                    SQLITE_THREADSAFE 0
vb@0
    84
//		PEP_INIT_CANNOT_LOAD_GPGME			if libgpgme.dll cannot be found
vb@0
    85
//		PEP_INIT_GPGME_INIT_FAILED			if GPGME init fails
vb@0
    86
//		PEP_INIT_CANNOT_OPEN_DB				if user's management db cannot be
vb@0
    87
//		                                    opened
vb@0
    88
//		PEP_INIT_CANNOT_OPEN_SYSTEM_DB		if system's management db cannot be
vb@0
    89
//		                                    opened
vb@0
    90
//
vb@0
    91
//  caveat:
vb@0
    92
//      the pointer is valid only if the return value is PEP_STATUS_OK
vb@0
    93
//      in other case a NULL pointer will be returned; a valid handle must
vb@0
    94
//      be released using release() when it's no longer needed
vb@0
    95
vb@0
    96
DYNAMIC_API PEP_STATUS init(PEP_SESSION *session);
vb@0
    97
vb@0
    98
vb@0
    99
// void release() - release thread session handle
vb@0
   100
//
vb@0
   101
//  parameters:
vb@0
   102
//		session (in)	session handle to release
vb@0
   103
vb@0
   104
DYNAMIC_API void release(PEP_SESSION session);
vb@0
   105
vb@0
   106
vb@0
   107
typedef struct _stringlist_t {
vb@0
   108
    char *value;
vb@0
   109
    struct _stringlist_t *next;
vb@0
   110
} stringlist_t;
vb@0
   111
vb@0
   112
vb@0
   113
// new_stringlist() - allocate a new stringlist
vb@0
   114
//
vb@0
   115
//  parameters:
vb@0
   116
//      value (in)        initial value as C string or NULL for empty list
vb@0
   117
//
vb@0
   118
//  return value:
vb@0
   119
//      pointer to stringlist_t object or NULL if out of memory
vb@0
   120
//
vb@0
   121
//  caveat:
vb@0
   122
//      the value is being copied before being added to the list
vb@0
   123
//      the original string is still being owned by the caller
vb@0
   124
vb@0
   125
DYNAMIC_API stringlist_t *new_stringlist(const char *value);
vb@0
   126
vb@0
   127
vb@0
   128
// stringlist_add() - add key to stringlist
vb@0
   129
//
vb@0
   130
//  parameters:
vb@0
   131
//      stringlist (in)     stringlist struct or NULL to create a new one
vb@0
   132
//      value (in)          value as C string
vb@0
   133
//
vb@0
   134
//  return value:
vb@0
   135
//      pointer to last element in stringlist or NULL if out of memory
vb@0
   136
//
vb@0
   137
//  caveat:
vb@0
   138
//      the value is being copied before being added to the list
vb@0
   139
//      the original string is still being owned by the caller
vb@0
   140
vb@0
   141
DYNAMIC_API stringlist_t *stringlist_add(stringlist_t *stringlist, const char *value);
vb@0
   142
vb@0
   143
vb@0
   144
// stringlist_length() - get length of stringlist
vb@0
   145
//
vb@0
   146
//  parameters:
vb@0
   147
//      stringlist (in)     stringlist struct to determine length of
vb@0
   148
//
vb@0
   149
//  return value:
vb@0
   150
//      length of stringlist in number of elements
vb@0
   151
vb@0
   152
DYNAMIC_API int stringlist_length(const stringlist_t *stringlist);
vb@0
   153
vb@0
   154
vb@0
   155
// free_stringlist() - free memory occupied by stringlist
vb@0
   156
//
vb@0
   157
//  parameters:
vb@0
   158
//      stringlist (in)    stringlist to free
vb@0
   159
vb@0
   160
DYNAMIC_API void free_stringlist(stringlist_t *stringlist);
vb@0
   161
vb@0
   162
vb@0
   163
// decrypt_and_verify() - decrypt and/or verify a message
vb@0
   164
//
vb@0
   165
//	parameters:
vb@0
   166
//		session (in)	session handle
vb@0
   167
//		ctext (in)		cipher text to decrypt and/or verify
vb@0
   168
//		csize (in)		size of cipher text
vb@0
   169
//		ptext (out)		pointer to internal buffer with plain text
vb@0
   170
//		psize (out)		size of plain text
vb@15
   171
//		keylist (out)	list of key ids which where used to encrypt
vb@0
   172
//
vb@0
   173
//	return value:
vb@0
   174
//		PEP_UNENCRYPTED				message was unencrypted and not signed
vb@0
   175
//		PEP_VERIFIED				message was unencrypted, signature matches
vb@0
   176
//		PEP_DECRYPTED				message is decrypted now, no signature
vb@0
   177
//		PEP_DECRYPTED_AND_VERIFIED	message is decrypted now and verified
vb@0
   178
//		PEP_DECRYPT_WRONG_FORMAT	message has wrong format to handle
vb@0
   179
//		PEP_DECRYPT_NO_KEY			key not available to decrypt and/or verify
vb@0
   180
//		PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH	wrong signature
vb@0
   181
//
vb@0
   182
//	caveat:
vb@0
   183
//	    the ownerships of ptext as well as keylist are going to the caller
vb@0
   184
//	    the caller must use free() (or an Windoze pEp_free()) and
vb@0
   185
//	    free_stringlist() to free them
vb@15
   186
//
vb@15
   187
//      if this function failes an error message may be the first element of
vb@15
   188
//      keylist and the other elements may be the keys used for encryption
vb@0
   189
vb@0
   190
DYNAMIC_API PEP_STATUS decrypt_and_verify(
vb@0
   191
        PEP_SESSION session, const char *ctext, size_t csize,
vb@0
   192
        char **ptext, size_t *psize, stringlist_t **keylist
vb@0
   193
    );
vb@0
   194
vb@0
   195
vb@0
   196
// verify_text() - verfy plain text with a digital signature
vb@0
   197
//
vb@0
   198
//  parameters:
vb@0
   199
//      session (in)    session handle
vb@0
   200
//      text (in)       text to verify
vb@0
   201
//      size (in)       size of text
vb@0
   202
//      signature (in)  signature text
vb@0
   203
//      sig_size (in)   size of signature
vb@6
   204
//		keylist (out)	list of key ids which where used to encrypt or NULL on
vb@0
   205
//		                error
vb@0
   206
//
vb@0
   207
//  return value:
vb@0
   208
//		PEP_VERIFIED				message was unencrypted, signature matches
vb@0
   209
//		PEP_DECRYPT_NO_KEY			key not available to decrypt and/or verify
vb@0
   210
//		PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH	wrong signature
vb@0
   211
vb@0
   212
DYNAMIC_API PEP_STATUS verify_text(
vb@0
   213
        PEP_SESSION session, const char *text, size_t size,
vb@0
   214
        const char *signature, size_t sig_size, stringlist_t **keylist
vb@0
   215
    );
vb@0
   216
vb@0
   217
vb@0
   218
// encrypt_and_sign() - encrypt and sign a message
vb@0
   219
//
vb@0
   220
//	parameters:
vb@0
   221
//		session (in)	session handle
vb@6
   222
//		keylist (in)	list of key ids to encrypt with as C strings
vb@0
   223
//		ptext (in)		plain text to decrypt and/or verify
vb@0
   224
//		psize (in)		size of plain text
vb@0
   225
//		ctext (out)		pointer to internal buffer with cipher text
vb@0
   226
//		csize (out)		size of cipher text
vb@0
   227
//
vb@0
   228
//	return value:
vb@0
   229
//		PEP_STATUS_OK = 0				encryption and signing succeeded
vb@0
   230
//		PEP_KEY_NOT_FOUND	            at least one of the receipient keys
vb@0
   231
//		                                could not be found
vb@0
   232
//		PEP_KEY_HAS_AMBIG_NAME          at least one of the receipient keys has
vb@0
   233
//		                                an ambiguous name
vb@0
   234
//		PEP_GET_KEY_FAILED		        cannot retrieve key
vb@0
   235
//
vb@0
   236
//	caveat:
vb@0
   237
//	    the ownership of ctext is going to the caller
vb@0
   238
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@20
   239
//      the first key in keylist is being used to sign the message
vb@20
   240
//      this implies there has to be a private key for that keypair
vb@0
   241
vb@0
   242
DYNAMIC_API PEP_STATUS encrypt_and_sign(
vb@0
   243
        PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
vb@0
   244
        size_t psize, char **ctext, size_t *csize
vb@0
   245
    );
vb@0
   246
vb@0
   247
vb@0
   248
// log_event() - log a user defined event defined by UTF-8 encoded strings into
vb@0
   249
// management log
vb@0
   250
//
vb@0
   251
//	parameters:
vb@0
   252
//		session (in)		session handle
vb@0
   253
//		title (in)			C string with event name
vb@0
   254
//		entity (in)			C string with name of entity which is logging
vb@0
   255
//		description (in)	C string with long description for event or NULL if
vb@0
   256
//		                    omitted
vb@0
   257
//		comment (in)		C string with user defined comment or NULL if
vb@0
   258
//		                    omitted
vb@0
   259
//
vb@0
   260
//	return value:
vb@0
   261
//	    PEP_STATUS_OK       log entry created
vb@0
   262
vb@0
   263
DYNAMIC_API PEP_STATUS log_event(
vb@0
   264
        PEP_SESSION session, const char *title, const char *entity,
vb@0
   265
        const char *description, const char *comment
vb@0
   266
    );
vb@0
   267
vb@0
   268
vb@0
   269
// safeword() - get the corresponding safeword for a 16 bit value
vb@0
   270
//
vb@0
   271
//	parameters:
vb@0
   272
//		session (in)		    session handle
vb@0
   273
//		value (in)			    value to find a safeword for
vb@0
   274
//		lang (in)			    C string with ISO 3166-1 ALPHA-2 language code
vb@0
   275
//		word (out)			    pointer to C string with safeword UTF-8 encoded
vb@0
   276
//							    NULL if language is not supported or safeword
vb@0
   277
//							    wordlist is damaged or unavailable
vb@0
   278
//		wsize (out)			    length of safeword
vb@0
   279
//
vb@0
   280
//	return value:
vb@0
   281
//	    PEP_STATUS_OK           safeword retrieved
vb@0
   282
//	    PEP_SAFEWORD_NOT_FOUND  safeword not found
vb@0
   283
//
vb@0
   284
//	caveat:
vb@0
   285
//		the word pointer goes to the ownership of the caller
vb@0
   286
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   287
vb@0
   288
DYNAMIC_API PEP_STATUS safeword(
vb@0
   289
            PEP_SESSION session, uint16_t value, const char *lang,
vb@0
   290
            char **word, size_t *wsize
vb@0
   291
        );
vb@0
   292
vb@0
   293
vb@0
   294
// safewords() - get safewords for a string of hex values of a fingerprint
vb@0
   295
//
vb@0
   296
//	parameters:
vb@0
   297
//		session (in)		session handle
vb@0
   298
//		fingerprint (in)	C string with hex values to find safewords for
vb@0
   299
//		lang (in)			C string with ISO 3166-1 ALPHA-2 language code
vb@0
   300
//		words (out)			pointer to C string with safewords UTF-8 encoded,
vb@0
   301
//		                    separated by a blank each
vb@0
   302
//							NULL if language is not supported or safeword
vb@0
   303
//							wordlist is damaged or unavailable
vb@0
   304
//		wsize (out)			length of safewords string
vb@0
   305
//		max_words (in)		only generate a string with max_words;
vb@0
   306
//							if max_words == 0 there is no such limit
vb@0
   307
//
vb@0
   308
//	return value:
vb@0
   309
//	    PEP_STATUS_OK           safewords retrieved
vb@0
   310
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   311
//	    PEP_SAFEWORD_NOT_FOUND  at least one safeword not found
vb@0
   312
//
vb@0
   313
//	caveat:
vb@0
   314
//		the word pointer goes to the ownership of the caller
vb@0
   315
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   316
//
vb@0
   317
//  DON'T USE THIS FUNCTION FROM HIGH LEVEL LANGUAGES!
vb@0
   318
//
vb@0
   319
//  Better implement a simple one in the adapter yourself using safeword(), and
vb@0
   320
//  return a list of safewords.
vb@0
   321
//  This function is provided for being used by C and C++ programs only.
vb@0
   322
vb@0
   323
DYNAMIC_API PEP_STATUS safewords(
vb@0
   324
        PEP_SESSION session, const char *fingerprint, const char *lang,
vb@0
   325
        char **words, size_t *wsize, int max_words
vb@0
   326
    );
vb@0
   327
vb@0
   328
vb@0
   329
typedef enum _PEP_comm_type {
vb@9
   330
    PEP_ct_unknown = 0,
vb@0
   331
vb@9
   332
    // range 0x01 to 0x09: no encryption, 0x0a to 0x0e: nothing reasonable
vb@0
   333
vb@9
   334
    PEP_ct_no_encryption = 0x01,                // generic
vb@9
   335
    PEP_ct_no_encrypted_channel = 0x02,
vb@9
   336
    PEP_ct_key_not_found = 0x03,
vb@9
   337
    PEP_ct_key_expired = 0x04,
vb@9
   338
    PEP_ct_key_revoked = 0x05,
vb@9
   339
    PEP_ct_key_b0rken = 0x06,
vb@9
   340
    PEP_ct_my_key_not_included = 0x09,
vb@9
   341
vb@9
   342
    PEP_ct_security_by_obscurity = 0x0a,
vb@9
   343
    PEP_ct_b0rken_crypto = 0x0b,
vb@9
   344
    PEP_ct_key_too_short = 0x0e,
vb@9
   345
vb@0
   346
    PEP_ct_compromized = 0x0f,                  // known compromized connection
vb@0
   347
vb@9
   348
    // range 0x10 to 0x3f: unconfirmed encryption
vb@0
   349
vb@0
   350
    PEP_ct_unconfirmed_encryption = 0x10,       // generic
vb@9
   351
    PEP_ct_OpenPGP_1024_RSA_unconfirmed = 0x11,	// RSA 1024 is weak
vb@23
   352
    PEP_ct_SMIME_unconfirmed = 0x20,
vb@9
   353
    PEP_ct_CMS_unconfirmed = 0x30,
vb@9
   354
    PEP_ct_OpenPGP_unconfirmed = 0x3f,          // key at least 2048 bit RSA
vb@9
   355
    // or 1024 bit DSA
vb@0
   356
vb@9
   357
    // range 0x40 to 0x7f: unconfirmed encryption and anonymization
vb@0
   358
vb@0
   359
    PEP_ct_unconfirmed_enc_anon = 0x40,         // generic
vb@9
   360
    PEP_ct_PEP_unconfirmed = 0x7f,
vb@0
   361
vb@9
   362
    PEP_ct_confirmed = 0x80,                    // this bit decides if trust is confirmed
vb@9
   363
vb@9
   364
    // range 0x81 to 0x8f: reserved
vb@9
   365
    // range 0x90 to 0xbf: confirmed encryption
vb@0
   366
vb@0
   367
    PEP_ct_confirmed_encryption = 0x90,         // generic
vb@0
   368
	PEP_ct_OpenPGP_1024_RSA = 0x91, // RSA 1024 is weak
vb@23
   369
    PEP_ct_SMIME = 0xa0,
vb@9
   370
    PEP_ct_CMS = 0xb0,
vb@0
   371
	PEP_ct_OpenPGP = 0xbf, // key at least 2048 bit RSA or 1024 bit DSA
vb@0
   372
vb@0
   373
    // range 0xc0 to 0xff: confirmed encryption and anonymization
vb@0
   374
vb@0
   375
    PEP_ct_confirmed_enc_anon = 0xc0,           // generic
vb@0
   376
	PEP_ct_pEp = 0xff
vb@0
   377
} PEP_comm_type;
vb@0
   378
vb@0
   379
typedef struct _pEp_identity {
vb@0
   380
	size_t struct_size;			// size of whole struct
vb@0
   381
	char *address;		        // C string with address UTF-8 encoded
vb@0
   382
	size_t address_size;		// size of address
vb@0
   383
	char *fpr;			        // C string with fingerprint UTF-8 encoded
vb@0
   384
	size_t fpr_size;			// size of fingerprint
vb@0
   385
	char *user_id;		        // C string with user ID UTF-8 encoded
vb@0
   386
	size_t user_id_size;		// size of user ID
vb@0
   387
	char *username;		        // C string with user name UTF-8 encoded
vb@0
   388
	size_t username_size;		// size of user name
vb@0
   389
	PEP_comm_type comm_type;	// type of communication with this ID
vb@0
   390
    char lang[3];				// language of conversation
vb@0
   391
                                // ISO 639-1 ALPHA-2, last byte is 0
vb@0
   392
    bool me;                    // if this is the local user herself/himself
vb@0
   393
} pEp_identity;
vb@0
   394
vb@0
   395
vb@0
   396
// new_identity() - allocate memory and set the string and size fields
vb@0
   397
//
vb@0
   398
//  parameters:
vb@0
   399
//      address (in)        UTF-8 string or NULL 
vb@0
   400
//      fpr (in)            UTF-8 string or NULL 
vb@0
   401
//      user_id (in)        UTF-8 string or NULL 
vb@0
   402
//      username (in)       UTF-8 string or NULL 
vb@0
   403
//
vb@0
   404
//  return value:
vb@0
   405
//      pEp_identity struct with correct size values or NULL if out of memory
vb@0
   406
//
vb@0
   407
//  caveat:
vb@0
   408
//      the strings are copied; the original strings are still being owned by
vb@0
   409
//      the caller
vb@0
   410
vb@0
   411
DYNAMIC_API pEp_identity *new_identity(
vb@0
   412
        const char *address, const char *fpr, const char *user_id,
vb@0
   413
        const char *username
vb@0
   414
    );
vb@0
   415
vb@0
   416
vb@0
   417
// free_identity() - free all memory being occupied by a pEp_identity struct
vb@0
   418
//
vb@0
   419
//  parameters:
vb@0
   420
//      identity (in)       struct to release
vb@0
   421
//
vb@0
   422
//  caveat:
vb@0
   423
//      not only the struct but also all string memory referenced by the
vb@0
   424
//      struct is being freed; all pointers inside are invalid afterwards
vb@0
   425
vb@0
   426
DYNAMIC_API void free_identity(pEp_identity *identity);
vb@0
   427
vb@0
   428
vb@0
   429
// get_identity() - get identity information
vb@0
   430
//
vb@0
   431
//	parameters:
vb@0
   432
//		session (in)		session handle
vb@0
   433
//		address (in)		C string with communication address, UTF-8 encoded
vb@0
   434
//		identity (out)		pointer to pEp_identity structure with results or
vb@0
   435
//		                    NULL if failure
vb@0
   436
//
vb@0
   437
//	caveat:
vb@0
   438
//	    the address string is being copied; the original string remains in the
vb@0
   439
//	    ownership of the caller
vb@0
   440
//		the resulting pEp_identity structure goes to the ownership of the
vb@0
   441
//		caller and has to be freed with free_identity() when not in use any
vb@0
   442
//		more
vb@0
   443
vb@0
   444
DYNAMIC_API PEP_STATUS get_identity(
vb@0
   445
        PEP_SESSION session, const char *address,
vb@0
   446
        pEp_identity **identity
vb@0
   447
    );
vb@0
   448
vb@0
   449
vb@0
   450
// set_identity() - set identity information
vb@0
   451
//
vb@0
   452
//	parameters:
vb@0
   453
//		session (in)		session handle
vb@0
   454
//		identity (in)		pointer to pEp_identity structure
vb@0
   455
//
vb@0
   456
//	return value:
vb@0
   457
//		PEP_STATUS_OK = 0			    encryption and signing succeeded
vb@0
   458
//		PEP_CANNOT_SET_PERSON		    writing to table person failed
vb@0
   459
//		PEP_CANNOT_SET_PGP_KEYPAIR	    writing to table pgp_keypair failed
vb@0
   460
//		PEP_CANNOT_SET_IDENTITY		    writing to table identity failed
vb@0
   461
//		PEP_COMMIT_FAILED			    SQL commit failed
vb@0
   462
//
vb@0
   463
//	caveat:
vb@0
   464
//		in the identity structure you need to set the const char * fields to
vb@0
   465
//		UTF-8 C strings
vb@0
   466
//		the size fields are ignored
vb@0
   467
vb@0
   468
DYNAMIC_API PEP_STATUS set_identity(
vb@0
   469
        PEP_SESSION session, const pEp_identity *identity
vb@0
   470
    );
vb@0
   471
vb@0
   472
vb@0
   473
// generate_keypair() - generate a new key pair and add it to the key ring
vb@0
   474
//
vb@0
   475
//  parameters:
vb@0
   476
//      session (in)            session handle
vb@0
   477
//		identity (inout)	    pointer to pEp_identity structure
vb@0
   478
//
vb@0
   479
//	return value:
vb@0
   480
//		PEP_STATUS_OK = 0	    encryption and signing succeeded
vb@0
   481
//		PEP_ILLEGAL_VALUE       illegal values for identity fields given
vb@0
   482
//		PEP_CANNOT_CREATE_KEY   key engine is on strike
vb@0
   483
//
vb@0
   484
//  caveat:
vb@0
   485
//      address and username fields must be set to UTF-8 strings
vb@0
   486
//      the fpr field must be set to NULL
vb@0
   487
//
vb@0
   488
//      this function allocates a string and sets set fpr field of identity
vb@0
   489
//      the caller is responsible to call free() for that string or use
vb@0
   490
//      free_identity() on the struct
vb@0
   491
vb@0
   492
DYNAMIC_API PEP_STATUS generate_keypair(
vb@0
   493
        PEP_SESSION session, pEp_identity *identity
vb@0
   494
    );
vb@0
   495
vb@0
   496
vb@0
   497
// delete_keypair() - delete a public key or a key pair from the key ring
vb@0
   498
//
vb@0
   499
//  parameters:
vb@0
   500
//      session (in)            session handle
vb@0
   501
//      fpr (in)                C string with key id or fingerprint of the
vb@0
   502
//                              public key
vb@0
   503
//
vb@0
   504
//  return value:
vb@0
   505
//      PEP_STATUS_OK = 0       key was successfully deleted
vb@0
   506
//      PEP_KEY_NOT_FOUND       key not found
vb@0
   507
//      PEP_ILLEGAL_VALUE       not a valid key id or fingerprint
vb@0
   508
//      PEP_KEY_HAS_AMBIG_NAME  fpr does not uniquely identify a key
vb@0
   509
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   510
vb@0
   511
DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr);
vb@0
   512
vb@0
   513
vb@0
   514
// import_key() - import key from data
vb@0
   515
//
vb@0
   516
//  parameters:
vb@0
   517
//      session (in)            session handle
vb@0
   518
//      key_data (in)           key data, i.e. ASCII armored OpenPGP key
vb@0
   519
//      size (in)               amount of data to handle
vb@0
   520
//
vb@0
   521
//  return value:
vb@0
   522
//      PEP_STATUS_OK = 0       key was successfully imported
vb@0
   523
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   524
//      PEP_ILLEGAL_VALUE       there is no key data to import
vb@0
   525
vb@0
   526
DYNAMIC_API PEP_STATUS import_key(PEP_SESSION session, const char *key_data, size_t size);
vb@0
   527
vb@0
   528
vb@0
   529
// export_key() - export ascii armored key
vb@0
   530
//
vb@0
   531
//  parameters:
vb@0
   532
//      session (in)            session handle
vb@0
   533
//      fpr (in)                key id or fingerprint of key
vb@0
   534
//      key_data (out)          ASCII armored OpenPGP key
vb@0
   535
//      size (out)               amount of data to handle
vb@0
   536
//
vb@0
   537
//  return value:
vb@0
   538
//      PEP_STATUS_OK = 0       key was successfully exported
vb@0
   539
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   540
//      PEP_KEY_NOT_FOUND       key not found
vb@0
   541
//
vb@0
   542
//  caveat:
vb@0
   543
//      the key_data goes to the ownership of the caller
vb@0
   544
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   545
vb@0
   546
DYNAMIC_API PEP_STATUS export_key(
vb@0
   547
        PEP_SESSION session, const char *fpr, char **key_data, size_t *size
vb@0
   548
    );
vb@0
   549
vb@0
   550
vb@0
   551
// recv_key() - update key(s) from keyserver
vb@0
   552
//
vb@0
   553
//  parameters:
vb@0
   554
//      session (in)            session handle
vb@0
   555
//      pattern (in)            key id, user id or address to search for as
vb@0
   556
//                              UTF-8 string
vb@0
   557
vb@0
   558
DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern);
vb@0
   559
vb@0
   560
vb@0
   561
// find_keys() - find keys in keyring
vb@0
   562
//
vb@0
   563
//  parameters:
vb@0
   564
//      session (in)            session handle
vb@0
   565
//      pattern (in)            key id, user id or address to search for as
vb@0
   566
//                              UTF-8 string
vb@0
   567
//      keylist (out)           list of fingerprints found or NULL on error
vb@0
   568
//
vb@0
   569
//  caveat:
vb@0
   570
//	    the ownerships of keylist isgoing to the caller
vb@0
   571
//	    the caller must use free_stringlist() to free it
vb@0
   572
vb@0
   573
vb@0
   574
DYNAMIC_API PEP_STATUS find_keys(
vb@0
   575
        PEP_SESSION session, const char *pattern, stringlist_t **keylist
vb@0
   576
    );
vb@0
   577
vb@0
   578
vb@0
   579
// send_key() - send key(s) to keyserver
vb@0
   580
//
vb@0
   581
//  parameters:
vb@0
   582
//      session (in)            session handle
vb@0
   583
//      pattern (in)            key id, user id or address to search for as
vb@0
   584
//                              UTF-8 string
vb@0
   585
vb@0
   586
DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern);
vb@0
   587
vb@0
   588
vb@0
   589
// pEp_free() - free memory allocated by pEp engine
vb@0
   590
//
vb@0
   591
//  parameters:
vb@0
   592
//      p (in)                  pointer to free
vb@0
   593
//
vb@0
   594
//  The reason for this function is that heap management can be a pretty
vb@0
   595
//  complex task with Windoze. This free() version calls the free()
vb@0
   596
//  implementation of the C runtime library which was used to build pEp engine,
vb@0
   597
//  so you're using the correct heap. For more information, see:
vb@0
   598
//  <http://msdn.microsoft.com/en-us/library/windows/desktop/aa366711(v=vs.85).aspx>
vb@0
   599
vb@0
   600
DYNAMIC_API void pEp_free(void *p);
vb@0
   601
vb@8
   602
vb@8
   603
// get_trust() - get the trust level a key has for a person
vb@8
   604
//
vb@8
   605
//  parameters:
vb@8
   606
//      session (in)            session handle
vb@8
   607
//      identity (inout)        user_id and fpr to check as UTF-8 strings (in)
vb@8
   608
//                              user_id and comm_type as result (out)
vb@8
   609
//
vb@14
   610
//  this function modifies the given identity struct; the struct remains in
vb@14
   611
// the ownership of the caller
vb@14
   612
//  if the trust level cannot be determined identity->comm_type is set
vb@14
   613
//  to PEP_ct_unknown
vb@8
   614
vb@8
   615
DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity);
vb@8
   616
vb@8
   617
vb@9
   618
// get_key_rating() - get the rating a bare key has
vb@9
   619
//
vb@9
   620
//  parameters:
vb@9
   621
//      session (in)            session handle
vb@9
   622
//      fpr (in)                unique identifyer for key as UTF-8 string
vb@9
   623
//      comm_type (out)         key rating
vb@10
   624
//
vb@14
   625
//  if an error occurs, *comm_type is set to PEP_ct_unknown and an error
vb@10
   626
//  is returned
vb@9
   627
vb@9
   628
DYNAMIC_API PEP_STATUS get_key_rating(
vb@14
   629
        PEP_SESSION session,
vb@14
   630
        const char *fpr,
vb@14
   631
        PEP_comm_type *comm_type
vb@9
   632
    );
vb@9
   633
vb@9
   634
vb@0
   635
#ifdef __cplusplus
vb@0
   636
}
vb@0
   637
#endif