src/pEpEngine.h
author Volker Birk <vb@pep-project.org>
Wed, 18 May 2016 12:21:06 +0200
changeset 652 ccc02be8a27d
parent 632 a213fafe3f4f
child 659 37bdde68b914
permissions -rw-r--r--
int32_t for sequence
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@25
     7
#include <stddef.h>
vb@0
     8
#include <stdint.h>
vb@0
     9
#include <stdbool.h>
vb@0
    10
vb@98
    11
#include "dynamic_api.h"
vb@98
    12
#include "stringlist.h"
vb@201
    13
#include "timestamp.h"
vb@0
    14
vb@94
    15
#define PEP_VERSION "1.0"
vb@94
    16
vb@0
    17
// pEp Engine API
vb@0
    18
vb@0
    19
//  caveat:
vb@0
    20
//      Unicode data has to be normalized to NFC before calling
vb@0
    21
//      UTF-8 strings are UTF-8 encoded C strings (zero terminated)
vb@0
    22
vb@0
    23
vb@46
    24
struct _pEpSession;
vb@46
    25
typedef struct _pEpSession * PEP_SESSION;
vb@0
    26
vb@0
    27
typedef enum {
roker@529
    28
    PEP_STATUS_OK                                   = 0,
vb@0
    29
roker@529
    30
    PEP_INIT_CANNOT_LOAD_GPGME                      = 0x0110,
roker@529
    31
    PEP_INIT_GPGME_INIT_FAILED                      = 0x0111,
roker@529
    32
    PEP_INIT_NO_GPG_HOME                            = 0x0112,
roker@529
    33
    PEP_INIT_NETPGP_INIT_FAILED                     = 0x0113,
vb@0
    34
roker@529
    35
    PEP_INIT_SQLITE3_WITHOUT_MUTEX                  = 0x0120,
roker@529
    36
    PEP_INIT_CANNOT_OPEN_DB                         = 0x0121,
roker@529
    37
    PEP_INIT_CANNOT_OPEN_SYSTEM_DB                  = 0x0122,
roker@529
    38
    
roker@529
    39
    PEP_KEY_NOT_FOUND                               = 0x0201,
roker@529
    40
    PEP_KEY_HAS_AMBIG_NAME                          = 0x0202,
roker@529
    41
    PEP_GET_KEY_FAILED                              = 0x0203,
roker@529
    42
    
roker@529
    43
    PEP_CANNOT_FIND_IDENTITY                        = 0x0301,
roker@529
    44
    PEP_CANNOT_SET_PERSON                           = 0x0381,
roker@529
    45
    PEP_CANNOT_SET_PGP_KEYPAIR                      = 0x0382,
roker@529
    46
    PEP_CANNOT_SET_IDENTITY                         = 0x0383,
vb@370
    47
    PEP_CANNOT_SET_TRUST                            = 0x0384,
vb@515
    48
    PEP_KEY_BLACKLISTED                             = 0x0385,
roker@529
    49
    
roker@529
    50
    PEP_UNENCRYPTED                                 = 0x0400,
roker@529
    51
    PEP_VERIFIED                                    = 0x0401,
roker@529
    52
    PEP_DECRYPTED                                   = 0x0402,
roker@529
    53
    PEP_DECRYPTED_AND_VERIFIED                      = 0x0403,
roker@529
    54
    PEP_DECRYPT_WRONG_FORMAT                        = 0x0404,
roker@529
    55
    PEP_DECRYPT_NO_KEY                              = 0x0405,
roker@529
    56
    PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH            = 0x0406,
vb@0
    57
    PEP_VERIFY_NO_KEY                               = 0x0407,
vb@0
    58
    PEP_VERIFIED_AND_TRUSTED                        = 0x0408,
roker@529
    59
    PEP_CANNOT_DECRYPT_UNKNOWN                      = 0x04ff,
vb@0
    60
roker@529
    61
    PEP_TRUSTWORD_NOT_FOUND                         = 0x0501,
vb@0
    62
vb@0
    63
    PEP_CANNOT_CREATE_KEY                           = 0x0601,
vb@0
    64
    PEP_CANNOT_SEND_KEY                             = 0x0602,
vb@0
    65
vb@458
    66
    PEP_PHRASE_NOT_FOUND                            = 0x0701,
vb@458
    67
roker@529
    68
    PEP_COMMIT_FAILED                               = 0xff01,
vb@0
    69
vb@44
    70
    PEP_CANNOT_CREATE_TEMP_FILE                     = -5,
vb@0
    71
    PEP_ILLEGAL_VALUE                               = -4,
vb@0
    72
    PEP_BUFFER_TOO_SMALL                            = -3,
roker@529
    73
    PEP_OUT_OF_MEMORY                               = -2,
roker@529
    74
    PEP_UNKNOWN_ERROR                               = -1
vb@0
    75
} PEP_STATUS;
vb@0
    76
vb@0
    77
vb@0
    78
// INIT_STATUS init() - initialize pEpEngine for a thread
vb@0
    79
//
vb@0
    80
//  parameters:
roker@529
    81
//        session (out)   init() allocates session memory and returns a pointer
roker@529
    82
//                        as a handle
vb@0
    83
//
vb@0
    84
//  return value:
roker@529
    85
//        PEP_STATUS_OK = 0                 if init() succeeds
roker@529
    86
//        PEP_INIT_SQLITE3_WITHOUT_MUTEX    if SQLite3 was compiled with
roker@529
    87
//                                            SQLITE_THREADSAFE 0
roker@529
    88
//        PEP_INIT_CANNOT_LOAD_GPGME        if libgpgme.dll cannot be found
roker@529
    89
//        PEP_INIT_GPGME_INIT_FAILED        if GPGME init fails
roker@529
    90
//        PEP_INIT_CANNOT_OPEN_DB           if user's management db cannot be
roker@529
    91
//                                            opened
roker@529
    92
//        PEP_INIT_CANNOT_OPEN_SYSTEM_DB    if system's management db cannot be
roker@529
    93
//                                            opened
vb@0
    94
//
vb@0
    95
//  caveat:
vb@0
    96
//      the pointer is valid only if the return value is PEP_STATUS_OK
vb@0
    97
//      in other case a NULL pointer will be returned; a valid handle must
vb@0
    98
//      be released using release() when it's no longer needed
vb@62
    99
//
vb@62
   100
//      the caller has to guarantee that the first call to this function
vb@62
   101
//      will succeed before further calls can be done
vb@0
   102
vb@0
   103
DYNAMIC_API PEP_STATUS init(PEP_SESSION *session);
vb@0
   104
vb@0
   105
vb@0
   106
// void release() - release thread session handle
vb@0
   107
//
vb@0
   108
//  parameters:
roker@529
   109
//        session (in)    session handle to release
vb@62
   110
//
roker@529
   111
//    caveat:
roker@529
   112
//        the last release() can be called only when all other release() calls
roker@529
   113
//        are done
vb@0
   114
vb@0
   115
DYNAMIC_API void release(PEP_SESSION session);
vb@0
   116
vb@0
   117
vb@464
   118
// config_passive_mode() - enable passive mode
vb@464
   119
//
vb@464
   120
//  parameters:
vb@464
   121
//      session (in)    session handle
vb@467
   122
//      enable (in)     flag if enabled or disabled
vb@464
   123
vb@467
   124
DYNAMIC_API void config_passive_mode(PEP_SESSION session, bool enable);
vb@467
   125
vb@467
   126
vb@553
   127
// config_unencrypted_subject() - disable subject encryption
vb@467
   128
//
vb@467
   129
//  parameters:
vb@467
   130
//      session (in)    session handle
vb@467
   131
//      enable (in)     flag if enabled or disabled
vb@467
   132
vb@467
   133
DYNAMIC_API void config_unencrypted_subject(PEP_SESSION session, bool enable);
vb@464
   134
vb@464
   135
vb@0
   136
// decrypt_and_verify() - decrypt and/or verify a message
vb@0
   137
//
roker@529
   138
//    parameters:
roker@529
   139
//        session (in)    session handle
roker@529
   140
//        ctext (in)      cipher text to decrypt and/or verify
roker@529
   141
//        csize (in)      size of cipher text
roker@529
   142
//        ptext (out)     pointer to internal buffer with plain text
roker@529
   143
//        psize (out)     size of plain text
roker@529
   144
//        keylist (out)   list of key ids which where used to encrypt
vb@0
   145
//
roker@529
   146
//    return value:
roker@529
   147
//        PEP_UNENCRYPTED               message was unencrypted and not signed
roker@529
   148
//        PEP_VERIFIED                  message was unencrypted, signature matches
roker@529
   149
//        PEP_DECRYPTED                 message is decrypted now, no signature
roker@529
   150
//        PEP_DECRYPTED_AND_VERIFIED    message is decrypted now and verified
roker@529
   151
//        PEP_DECRYPT_WRONG_FORMAT      message has wrong format to handle
roker@529
   152
//        PEP_DECRYPT_NO_KEY            key not available to decrypt and/or verify
roker@529
   153
//        PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH    wrong signature
vb@0
   154
//
roker@529
   155
//    caveat:
roker@529
   156
//        the ownerships of ptext as well as keylist are going to the caller
roker@529
   157
//        the caller must use free() (or an Windoze pEp_free()) and
roker@529
   158
//        free_stringlist() to free them
vb@15
   159
//
vb@15
   160
//      if this function failes an error message may be the first element of
vb@15
   161
//      keylist and the other elements may be the keys used for encryption
vb@0
   162
vb@0
   163
DYNAMIC_API PEP_STATUS decrypt_and_verify(
vb@0
   164
        PEP_SESSION session, const char *ctext, size_t csize,
vb@0
   165
        char **ptext, size_t *psize, stringlist_t **keylist
vb@0
   166
    );
vb@0
   167
vb@0
   168
vb@0
   169
// verify_text() - verfy plain text with a digital signature
vb@0
   170
//
vb@0
   171
//  parameters:
vb@0
   172
//      session (in)    session handle
vb@0
   173
//      text (in)       text to verify
vb@0
   174
//      size (in)       size of text
vb@0
   175
//      signature (in)  signature text
vb@0
   176
//      sig_size (in)   size of signature
roker@529
   177
//      keylist (out)   list of key ids which where used to encrypt or NULL on
roker@529
   178
//                        error
vb@0
   179
//
vb@0
   180
//  return value:
roker@529
   181
//        PEP_VERIFIED                message was unencrypted, signature matches
roker@529
   182
//        PEP_DECRYPT_NO_KEY          key not available to decrypt and/or verify
roker@529
   183
//        PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH    wrong signature
vb@0
   184
vb@0
   185
DYNAMIC_API PEP_STATUS verify_text(
vb@0
   186
        PEP_SESSION session, const char *text, size_t size,
vb@0
   187
        const char *signature, size_t sig_size, stringlist_t **keylist
vb@0
   188
    );
vb@0
   189
vb@0
   190
vb@0
   191
// encrypt_and_sign() - encrypt and sign a message
vb@0
   192
//
roker@529
   193
//    parameters:
roker@529
   194
//        session (in)    session handle
roker@529
   195
//        keylist (in)    list of key ids to encrypt with as C strings
roker@529
   196
//        ptext (in)      plain text to decrypt and/or verify
roker@529
   197
//        psize (in)      size of plain text
roker@529
   198
//        ctext (out)     pointer to internal buffer with cipher text
roker@529
   199
//        csize (out)     size of cipher text
vb@0
   200
//
roker@529
   201
//    return value:
roker@529
   202
//        PEP_STATUS_OK = 0            encryption and signing succeeded
roker@529
   203
//        PEP_KEY_NOT_FOUND            at least one of the receipient keys
roker@529
   204
//                                     could not be found
roker@529
   205
//        PEP_KEY_HAS_AMBIG_NAME       at least one of the receipient keys has
roker@529
   206
//                                     an ambiguous name
roker@529
   207
//        PEP_GET_KEY_FAILED           cannot retrieve key
vb@0
   208
//
roker@529
   209
//    caveat:
roker@529
   210
//      the ownership of ctext is going to the caller
vb@0
   211
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@20
   212
//      the first key in keylist is being used to sign the message
vb@20
   213
//      this implies there has to be a private key for that keypair
vb@0
   214
vb@0
   215
DYNAMIC_API PEP_STATUS encrypt_and_sign(
vb@0
   216
        PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
vb@0
   217
        size_t psize, char **ctext, size_t *csize
vb@0
   218
    );
vb@0
   219
vb@0
   220
vb@0
   221
// log_event() - log a user defined event defined by UTF-8 encoded strings into
vb@0
   222
// management log
vb@0
   223
//
roker@529
   224
//    parameters:
roker@529
   225
//        session (in)        session handle
roker@529
   226
//        title (in)          C string with event name
roker@529
   227
//        entity (in)         C string with name of entity which is logging
roker@529
   228
//        description (in)    C string with long description for event or NULL if
roker@529
   229
//                            omitted
roker@529
   230
//        comment (in)        C string with user defined comment or NULL if
roker@529
   231
//                            omitted
vb@0
   232
//
roker@529
   233
//    return value:
roker@529
   234
//        PEP_STATUS_OK       log entry created
vb@0
   235
vb@0
   236
DYNAMIC_API PEP_STATUS log_event(
vb@450
   237
        PEP_SESSION session,
vb@451
   238
        const char *title,
vb@451
   239
        const char *entity,
vb@451
   240
        const char *description,
vb@451
   241
        const char *comment
vb@0
   242
    );
vb@0
   243
vb@0
   244
vb@233
   245
// trustword() - get the corresponding trustword for a 16 bit value
vb@0
   246
//
roker@529
   247
//    parameters:
roker@529
   248
//        session (in)            session handle
roker@529
   249
//        value (in)              value to find a trustword for
roker@529
   250
//        lang (in)               C string with ISO 639-1 language code
roker@529
   251
//        word (out)              pointer to C string with trustword UTF-8 encoded
roker@529
   252
//                                NULL if language is not supported or trustword
roker@529
   253
//                                wordlist is damaged or unavailable
roker@529
   254
//        wsize (out)             length of trustword
vb@0
   255
//
roker@529
   256
//    return value:
roker@529
   257
//        PEP_STATUS_OK            trustword retrieved
roker@529
   258
//        PEP_TRUSTWORD_NOT_FOUND  trustword not found
vb@0
   259
//
roker@529
   260
//    caveat:
roker@529
   261
//        the word pointer goes to the ownership of the caller
vb@0
   262
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   263
vb@233
   264
DYNAMIC_API PEP_STATUS trustword(
vb@0
   265
            PEP_SESSION session, uint16_t value, const char *lang,
vb@0
   266
            char **word, size_t *wsize
vb@0
   267
        );
vb@0
   268
vb@0
   269
vb@233
   270
// trustwords() - get trustwords for a string of hex values of a fingerprint
vb@0
   271
//
roker@529
   272
//    parameters:
roker@529
   273
//        session (in)        session handle
roker@529
   274
//        fingerprint (in)    C string with hex values to find trustwords for
roker@529
   275
//        lang (in)           C string with ISO 639-1 language code
roker@529
   276
//        words (out)         pointer to C string with trustwords UTF-8 encoded,
roker@529
   277
//                            separated by a blank each
roker@529
   278
//                            NULL if language is not supported or trustword
roker@529
   279
//                            wordlist is damaged or unavailable
roker@529
   280
//        wsize (out)         length of trustwords string
roker@529
   281
//        max_words (in)      only generate a string with max_words;
roker@529
   282
//                            if max_words == 0 there is no such limit
vb@0
   283
//
roker@529
   284
//    return value:
roker@529
   285
//        PEP_STATUS_OK            trustwords retrieved
roker@529
   286
//        PEP_OUT_OF_MEMORY        out of memory
roker@529
   287
//        PEP_TRUSTWORD_NOT_FOUND  at least one trustword not found
vb@0
   288
//
roker@529
   289
//    caveat:
roker@529
   290
//        the word pointer goes to the ownership of the caller
vb@0
   291
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   292
//
vb@0
   293
//  DON'T USE THIS FUNCTION FROM HIGH LEVEL LANGUAGES!
vb@0
   294
//
vb@233
   295
//  Better implement a simple one in the adapter yourself using trustword(), and
vb@233
   296
//  return a list of trustwords.
vb@0
   297
//  This function is provided for being used by C and C++ programs only.
vb@0
   298
vb@233
   299
DYNAMIC_API PEP_STATUS trustwords(
vb@0
   300
        PEP_SESSION session, const char *fingerprint, const char *lang,
vb@0
   301
        char **words, size_t *wsize, int max_words
vb@0
   302
    );
vb@0
   303
vb@0
   304
vb@0
   305
typedef enum _PEP_comm_type {
vb@9
   306
    PEP_ct_unknown = 0,
vb@0
   307
vb@9
   308
    // range 0x01 to 0x09: no encryption, 0x0a to 0x0e: nothing reasonable
vb@0
   309
vb@9
   310
    PEP_ct_no_encryption = 0x01,                // generic
vb@9
   311
    PEP_ct_no_encrypted_channel = 0x02,
vb@9
   312
    PEP_ct_key_not_found = 0x03,
vb@9
   313
    PEP_ct_key_expired = 0x04,
vb@9
   314
    PEP_ct_key_revoked = 0x05,
vb@9
   315
    PEP_ct_key_b0rken = 0x06,
vb@9
   316
    PEP_ct_my_key_not_included = 0x09,
vb@9
   317
vb@9
   318
    PEP_ct_security_by_obscurity = 0x0a,
vb@9
   319
    PEP_ct_b0rken_crypto = 0x0b,
Edouard@442
   320
    PEP_ct_key_too_short = 0x0c,
vb@9
   321
Edouard@442
   322
    PEP_ct_compromized = 0x0e,                  // known compromized connection
Edouard@442
   323
    PEP_ct_mistrusted = 0x0f,                   // known mistrusted key
vb@0
   324
vb@9
   325
    // range 0x10 to 0x3f: unconfirmed encryption
vb@0
   326
vb@0
   327
    PEP_ct_unconfirmed_encryption = 0x10,       // generic
roker@529
   328
    PEP_ct_OpenPGP_weak_unconfirmed = 0x11,     // RSA 1024 is weak
vb@190
   329
vb@190
   330
    PEP_ct_to_be_checked = 0x20,                // generic
vb@190
   331
    PEP_ct_SMIME_unconfirmed = 0x21,
vb@190
   332
    PEP_ct_CMS_unconfirmed = 0x22,
vb@190
   333
vb@190
   334
    PEP_ct_strong_but_unconfirmed = 0x30,       // generic
vb@122
   335
    PEP_ct_OpenPGP_unconfirmed = 0x38,          // key at least 2048 bit RSA or EC
vb@122
   336
    PEP_ct_OTR_unconfirmed = 0x3a,
vb@0
   337
vb@9
   338
    // range 0x40 to 0x7f: unconfirmed encryption and anonymization
vb@0
   339
vb@0
   340
    PEP_ct_unconfirmed_enc_anon = 0x40,         // generic
vb@9
   341
    PEP_ct_PEP_unconfirmed = 0x7f,
vb@0
   342
vb@9
   343
    PEP_ct_confirmed = 0x80,                    // this bit decides if trust is confirmed
vb@9
   344
vb@9
   345
    // range 0x81 to 0x8f: reserved
vb@9
   346
    // range 0x90 to 0xbf: confirmed encryption
vb@0
   347
vb@0
   348
    PEP_ct_confirmed_encryption = 0x90,         // generic
roker@529
   349
    PEP_ct_OpenPGP_weak = 0x91,                 // RSA 1024 is weak
vb@190
   350
vb@190
   351
    PEP_ct_to_be_checked_confirmed = 0xa0,      //generic
vb@190
   352
    PEP_ct_SMIME = 0xa1,
vb@190
   353
    PEP_ct_CMS = 0xa2,
vb@190
   354
vb@190
   355
    PEP_ct_strong_encryption = 0xb0,            // generic
roker@529
   356
    PEP_ct_OpenPGP = 0xb8,                      // key at least 2048 bit RSA or EC
roker@529
   357
    PEP_ct_OTR = 0xba,
vb@0
   358
vb@0
   359
    // range 0xc0 to 0xff: confirmed encryption and anonymization
vb@0
   360
vb@0
   361
    PEP_ct_confirmed_enc_anon = 0xc0,           // generic
roker@529
   362
    PEP_ct_pEp = 0xff
vb@0
   363
} PEP_comm_type;
vb@0
   364
vb@0
   365
typedef struct _pEp_identity {
roker@529
   366
    char *address;              // C string with address UTF-8 encoded
roker@529
   367
    char *fpr;                  // C string with fingerprint UTF-8 encoded
roker@529
   368
    char *user_id;              // C string with user ID UTF-8 encoded
roker@529
   369
    char *username;             // C string with user name UTF-8 encoded
roker@529
   370
    PEP_comm_type comm_type;    // type of communication with this ID
roker@529
   371
    char lang[3];               // language of conversation
vb@0
   372
                                // ISO 639-1 ALPHA-2, last byte is 0
vb@0
   373
    bool me;                    // if this is the local user herself/himself
vb@0
   374
} pEp_identity;
vb@0
   375
vb@0
   376
vb@0
   377
// new_identity() - allocate memory and set the string and size fields
vb@0
   378
//
vb@0
   379
//  parameters:
vb@0
   380
//      address (in)        UTF-8 string or NULL 
vb@0
   381
//      fpr (in)            UTF-8 string or NULL 
vb@0
   382
//      user_id (in)        UTF-8 string or NULL 
vb@0
   383
//      username (in)       UTF-8 string or NULL 
vb@0
   384
//
vb@0
   385
//  return value:
vb@0
   386
//      pEp_identity struct with correct size values or NULL if out of memory
vb@0
   387
//
vb@0
   388
//  caveat:
vb@0
   389
//      the strings are copied; the original strings are still being owned by
vb@0
   390
//      the caller
vb@0
   391
vb@0
   392
DYNAMIC_API pEp_identity *new_identity(
vb@0
   393
        const char *address, const char *fpr, const char *user_id,
vb@0
   394
        const char *username
vb@0
   395
    );
vb@0
   396
vb@0
   397
vb@37
   398
// identity_dup() - allocate memory and set the string and size fields
vb@37
   399
//
vb@37
   400
//  parameters:
vb@37
   401
//      src (in)            identity to duplicate
vb@37
   402
//
vb@37
   403
//  return value:
vb@37
   404
//      pEp_identity struct with correct size values or NULL if out of memory
vb@37
   405
//
vb@37
   406
//  caveat:
vb@37
   407
//      the strings are copied; the original strings are still being owned by
vb@37
   408
//      the caller
vb@37
   409
vb@37
   410
DYNAMIC_API pEp_identity *identity_dup(const pEp_identity *src);
vb@37
   411
vb@37
   412
vb@0
   413
// free_identity() - free all memory being occupied by a pEp_identity struct
vb@0
   414
//
vb@0
   415
//  parameters:
vb@0
   416
//      identity (in)       struct to release
vb@0
   417
//
vb@0
   418
//  caveat:
vb@0
   419
//      not only the struct but also all string memory referenced by the
vb@0
   420
//      struct is being freed; all pointers inside are invalid afterwards
vb@0
   421
vb@0
   422
DYNAMIC_API void free_identity(pEp_identity *identity);
vb@0
   423
vb@0
   424
vb@0
   425
// get_identity() - get identity information
vb@0
   426
//
roker@529
   427
//    parameters:
roker@529
   428
//        session (in)        session handle
roker@529
   429
//        address (in)        C string with communication address, UTF-8 encoded
Edouard@562
   430
//        user_id (in)        unique C string to identify person that identity
Edouard@562
   431
//                            is refering to
roker@529
   432
//        identity (out)      pointer to pEp_identity structure with results or
roker@529
   433
//                            NULL if failure
vb@0
   434
//
roker@529
   435
//    caveat:
roker@529
   436
//        the address string is being copied; the original string remains in the
roker@529
   437
//        ownership of the caller
roker@529
   438
//        the resulting pEp_identity structure goes to the ownership of the
roker@529
   439
//        caller and has to be freed with free_identity() when not in use any
roker@529
   440
//        more
vb@0
   441
vb@0
   442
DYNAMIC_API PEP_STATUS get_identity(
Edouard@559
   443
        PEP_SESSION session,
Edouard@559
   444
        const char *address,
Edouard@559
   445
        const char *user_id,
vb@0
   446
        pEp_identity **identity
vb@0
   447
    );
vb@0
   448
vb@0
   449
// set_identity() - set identity information
vb@0
   450
//
roker@529
   451
//    parameters:
roker@529
   452
//        session (in)        session handle
roker@529
   453
//        identity (in)       pointer to pEp_identity structure
vb@0
   454
//
roker@529
   455
//    return value:
roker@529
   456
//        PEP_STATUS_OK = 0             encryption and signing succeeded
roker@529
   457
//        PEP_CANNOT_SET_PERSON         writing to table person failed
roker@529
   458
//        PEP_CANNOT_SET_PGP_KEYPAIR    writing to table pgp_keypair failed
roker@529
   459
//        PEP_CANNOT_SET_IDENTITY       writing to table identity failed
roker@529
   460
//        PEP_COMMIT_FAILED             SQL commit failed
vb@515
   461
//      PEP_KEY_BLACKLISTED             Key blacklisted, cannot set identity
vb@0
   462
//
roker@529
   463
//    caveat:
roker@529
   464
//        in the identity structure you need to set the const char * fields to
roker@529
   465
//        UTF-8 C strings
roker@529
   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@357
   473
// mark_as_compromized() - mark key in trust db as compromized
vb@357
   474
//
roker@529
   475
//    parameters:
roker@529
   476
//        session (in)        session handle
roker@529
   477
//        fpr (in)            fingerprint of key to mark
vb@357
   478
vb@357
   479
DYNAMIC_API PEP_STATUS mark_as_compromized(
vb@357
   480
        PEP_SESSION session,
vb@357
   481
        const char *fpr
vb@357
   482
    );
vb@357
   483
vb@357
   484
vb@0
   485
// generate_keypair() - generate a new key pair and add it to the key ring
vb@0
   486
//
vb@0
   487
//  parameters:
vb@0
   488
//      session (in)            session handle
roker@529
   489
//        identity (inout)      pointer to pEp_identity structure
vb@0
   490
//
roker@529
   491
//    return value:
roker@529
   492
//        PEP_STATUS_OK = 0       encryption and signing succeeded
roker@529
   493
//        PEP_ILLEGAL_VALUE       illegal values for identity fields given
roker@529
   494
//        PEP_CANNOT_CREATE_KEY   key engine is on strike
vb@0
   495
//
vb@0
   496
//  caveat:
vb@0
   497
//      address and username fields must be set to UTF-8 strings
vb@0
   498
//      the fpr field must be set to NULL
vb@0
   499
//
vb@0
   500
//      this function allocates a string and sets set fpr field of identity
vb@0
   501
//      the caller is responsible to call free() for that string or use
vb@0
   502
//      free_identity() on the struct
vb@0
   503
vb@0
   504
DYNAMIC_API PEP_STATUS generate_keypair(
vb@0
   505
        PEP_SESSION session, pEp_identity *identity
vb@0
   506
    );
vb@0
   507
vb@0
   508
vb@0
   509
// delete_keypair() - delete a public key or a key pair from the key ring
vb@0
   510
//
vb@0
   511
//  parameters:
vb@0
   512
//      session (in)            session handle
vb@0
   513
//      fpr (in)                C string with key id or fingerprint of the
vb@0
   514
//                              public key
vb@0
   515
//
vb@0
   516
//  return value:
vb@0
   517
//      PEP_STATUS_OK = 0       key was successfully deleted
vb@0
   518
//      PEP_KEY_NOT_FOUND       key not found
vb@0
   519
//      PEP_ILLEGAL_VALUE       not a valid key id or fingerprint
vb@0
   520
//      PEP_KEY_HAS_AMBIG_NAME  fpr does not uniquely identify a key
vb@0
   521
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   522
vb@0
   523
DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr);
vb@0
   524
vb@0
   525
vb@0
   526
// import_key() - import key from data
vb@0
   527
//
vb@0
   528
//  parameters:
vb@0
   529
//      session (in)            session handle
vb@0
   530
//      key_data (in)           key data, i.e. ASCII armored OpenPGP key
vb@0
   531
//      size (in)               amount of data to handle
vb@0
   532
//
vb@0
   533
//  return value:
vb@0
   534
//      PEP_STATUS_OK = 0       key was successfully imported
vb@0
   535
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   536
//      PEP_ILLEGAL_VALUE       there is no key data to import
vb@0
   537
vb@0
   538
DYNAMIC_API PEP_STATUS import_key(PEP_SESSION session, const char *key_data, size_t size);
vb@0
   539
vb@0
   540
vb@0
   541
// export_key() - export ascii armored key
vb@0
   542
//
vb@0
   543
//  parameters:
vb@0
   544
//      session (in)            session handle
vb@0
   545
//      fpr (in)                key id or fingerprint of key
vb@0
   546
//      key_data (out)          ASCII armored OpenPGP key
roker@529
   547
//      size (out)              amount of data to handle
vb@0
   548
//
vb@0
   549
//  return value:
vb@0
   550
//      PEP_STATUS_OK = 0       key was successfully exported
vb@0
   551
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   552
//      PEP_KEY_NOT_FOUND       key not found
vb@0
   553
//
vb@0
   554
//  caveat:
vb@0
   555
//      the key_data goes to the ownership of the caller
vb@0
   556
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   557
vb@0
   558
DYNAMIC_API PEP_STATUS export_key(
vb@0
   559
        PEP_SESSION session, const char *fpr, char **key_data, size_t *size
vb@0
   560
    );
vb@0
   561
vb@0
   562
vb@0
   563
// recv_key() - update key(s) from keyserver
vb@0
   564
//
vb@0
   565
//  parameters:
vb@0
   566
//      session (in)            session handle
vb@0
   567
//      pattern (in)            key id, user id or address to search for as
vb@0
   568
//                              UTF-8 string
vb@0
   569
vb@0
   570
DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern);
vb@0
   571
vb@0
   572
vb@0
   573
// find_keys() - find keys in keyring
vb@0
   574
//
vb@0
   575
//  parameters:
vb@0
   576
//      session (in)            session handle
vb@0
   577
//      pattern (in)            key id, user id or address to search for as
vb@0
   578
//                              UTF-8 string
vb@0
   579
//      keylist (out)           list of fingerprints found or NULL on error
vb@0
   580
//
vb@0
   581
//  caveat:
roker@529
   582
//        the ownerships of keylist isgoing to the caller
roker@529
   583
//        the caller must use free_stringlist() to free it
vb@0
   584
vb@0
   585
vb@0
   586
DYNAMIC_API PEP_STATUS find_keys(
vb@0
   587
        PEP_SESSION session, const char *pattern, stringlist_t **keylist
vb@0
   588
    );
vb@0
   589
vb@0
   590
vb@0
   591
// send_key() - send key(s) to keyserver
vb@0
   592
//
vb@0
   593
//  parameters:
vb@0
   594
//      session (in)            session handle
vb@0
   595
//      pattern (in)            key id, user id or address to search for as
vb@0
   596
//                              UTF-8 string
vb@0
   597
vb@0
   598
DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern);
vb@0
   599
vb@0
   600
vb@0
   601
// pEp_free() - free memory allocated by pEp engine
vb@0
   602
//
vb@0
   603
//  parameters:
vb@0
   604
//      p (in)                  pointer to free
vb@0
   605
//
vb@0
   606
//  The reason for this function is that heap management can be a pretty
vb@0
   607
//  complex task with Windoze. This free() version calls the free()
vb@0
   608
//  implementation of the C runtime library which was used to build pEp engine,
vb@0
   609
//  so you're using the correct heap. For more information, see:
vb@0
   610
//  <http://msdn.microsoft.com/en-us/library/windows/desktop/aa366711(v=vs.85).aspx>
vb@0
   611
vb@0
   612
DYNAMIC_API void pEp_free(void *p);
vb@0
   613
vb@8
   614
vb@8
   615
// get_trust() - get the trust level a key has for a person
vb@8
   616
//
vb@8
   617
//  parameters:
vb@8
   618
//      session (in)            session handle
vb@8
   619
//      identity (inout)        user_id and fpr to check as UTF-8 strings (in)
vb@8
   620
//                              user_id and comm_type as result (out)
vb@8
   621
//
vb@14
   622
//  this function modifies the given identity struct; the struct remains in
vb@251
   623
//  the ownership of the caller
vb@14
   624
//  if the trust level cannot be determined identity->comm_type is set
vb@14
   625
//  to PEP_ct_unknown
vb@8
   626
vb@8
   627
DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity);
vb@8
   628
vb@8
   629
vb@251
   630
// least_trust() - get the least known trust level for a key in the database
vb@251
   631
//
vb@251
   632
//  parameters:
vb@251
   633
//      session (in)            session handle
vb@251
   634
//      fpr (in)                fingerprint of key to check
vb@251
   635
//      comm_type (out)         least comm_type as result (out)
vb@251
   636
//
vb@251
   637
//  if the trust level cannot be determined comm_type is set to PEP_ct_unknown
vb@251
   638
vb@251
   639
DYNAMIC_API PEP_STATUS least_trust(
vb@251
   640
        PEP_SESSION session,
vb@251
   641
        const char *fpr,
vb@251
   642
        PEP_comm_type *comm_type
vb@251
   643
    );
vb@251
   644
vb@251
   645
vb@9
   646
// get_key_rating() - get the rating a bare key has
vb@9
   647
//
vb@9
   648
//  parameters:
vb@9
   649
//      session (in)            session handle
vb@9
   650
//      fpr (in)                unique identifyer for key as UTF-8 string
vb@9
   651
//      comm_type (out)         key rating
vb@10
   652
//
vb@14
   653
//  if an error occurs, *comm_type is set to PEP_ct_unknown and an error
vb@10
   654
//  is returned
vb@9
   655
vb@9
   656
DYNAMIC_API PEP_STATUS get_key_rating(
vb@14
   657
        PEP_SESSION session,
vb@14
   658
        const char *fpr,
vb@14
   659
        PEP_comm_type *comm_type
vb@9
   660
    );
vb@9
   661
vb@9
   662
vb@198
   663
// renew_key() - renew an expired key
vb@196
   664
//
vb@196
   665
//  parameters:
vb@196
   666
//      session (in)            session handle
vb@214
   667
//      fpr (in)                ID of key to renew as UTF-8 string
vb@201
   668
//      ts (in)                 timestamp when key should expire or NULL for
vb@201
   669
//                              default
vb@196
   670
vb@201
   671
DYNAMIC_API PEP_STATUS renew_key(
vb@201
   672
        PEP_SESSION session,
vb@201
   673
        const char *fpr,
vb@201
   674
        const timestamp *ts
vb@201
   675
    );
vb@196
   676
vb@196
   677
vb@224
   678
// revoke_key() - revoke a key
vb@197
   679
//
vb@197
   680
//  parameters:
vb@197
   681
//      session (in)            session handle
vb@214
   682
//      fpr (in)                ID of key to revoke as UTF-8 string
vb@211
   683
//      reason (in)             text with reason for revoke as UTF-8 string
vb@211
   684
//                              or NULL if reason unknown
vb@211
   685
//
vb@211
   686
//  caveat:
vb@211
   687
//      reason text must not include empty lines
vb@224
   688
//      this function is meant for internal use only; better use
vb@224
   689
//      key_compromized() of keymanagement API
vb@197
   690
vb@211
   691
DYNAMIC_API PEP_STATUS revoke_key(
vb@211
   692
        PEP_SESSION session,
vb@211
   693
        const char *fpr,
vb@211
   694
        const char *reason
vb@211
   695
    );
vb@197
   696
vb@197
   697
vb@214
   698
// key_expired() - flags if a key is already expired
vb@214
   699
//
vb@214
   700
//  parameters:
vb@214
   701
//      session (in)            session handle
vb@214
   702
//      fpr (in)                ID of key to check as UTF-8 string
vb@214
   703
//      expired (out)           flag if key expired
vb@214
   704
vb@214
   705
DYNAMIC_API PEP_STATUS key_expired(
vb@214
   706
        PEP_SESSION session,
vb@214
   707
        const char *fpr,
vb@214
   708
        bool *expired
vb@214
   709
    );
vb@214
   710
vb@214
   711
vb@450
   712
// get_crashdump_log() - get the last log messages out
vb@450
   713
//
vb@450
   714
//  parameters:
vb@450
   715
//      session (in)            session handle
vb@450
   716
//      maxlines (in)           maximum number of lines (0 for default)
vb@458
   717
//      logdata (out)           logdata as string in double quoted CSV format
vb@463
   718
//                              column1 is title
vb@463
   719
//                              column2 is entity
vb@463
   720
//                              column3 is description
vb@463
   721
//                              column4 is comment
vb@462
   722
//
vb@462
   723
//  caveat:
vb@462
   724
//      the ownership of logdata goes to the caller
vb@450
   725
vb@450
   726
DYNAMIC_API PEP_STATUS get_crashdump_log(
vb@450
   727
        PEP_SESSION session,
vb@450
   728
        int maxlines,
vb@450
   729
        char **logdata
vb@450
   730
    );
vb@450
   731
vb@450
   732
dirk@501
   733
// get_languagelist() - get the list of languages
vb@458
   734
//
vb@458
   735
//  parameters:
vb@458
   736
//      session (in)            session handle
vb@458
   737
//      languages (out)         languages as string in double quoted CSV format
vb@463
   738
//                              column 1 is the ISO 639-1 language code
vb@463
   739
//                              column 2 is the name of the language
vb@462
   740
//
vb@462
   741
//  caveat:
vb@462
   742
//      the ownership of languages goes to the caller
vb@458
   743
vb@458
   744
DYNAMIC_API PEP_STATUS get_languagelist(
vb@458
   745
        PEP_SESSION session,
vb@458
   746
        char **languages
vb@458
   747
    );
vb@458
   748
vb@458
   749
vb@458
   750
// get_phrase() - get phrase in a dedicated language through i18n
vb@458
   751
//
vb@458
   752
//  parameters:
vb@458
   753
//      session (in)            session handle
roker@529
   754
//      lang (in)               C string with ISO 639-1 language code
vb@458
   755
//      phrase_id (in)          id of phrase in i18n
vb@458
   756
//      phrase (out)            phrase as UTF-8 string
vb@462
   757
//
vb@462
   758
//  caveat:
vb@462
   759
//      the ownership of phrase goes to the caller
vb@458
   760
vb@458
   761
DYNAMIC_API PEP_STATUS get_phrase(
vb@458
   762
        PEP_SESSION session,
vb@458
   763
        const char *lang,
vb@458
   764
        int phrase_id,
vb@458
   765
        char **phrase
vb@458
   766
    );
vb@458
   767
vb@458
   768
vb@632
   769
// sequence_value() - raise the value of a named sequence and retrieve it
vb@632
   770
//
vb@632
   771
//  parameters:
vb@632
   772
//      session (in)            session handle
vb@632
   773
//      name (in)               name of sequence
vb@632
   774
//      value (out)             value of sequence
vb@632
   775
vb@632
   776
DYNAMIC_API PEP_STATUS sequence_value(
vb@632
   777
        PEP_SESSION session,
vb@632
   778
        const char *name,
vb@652
   779
        int32_t *value
vb@632
   780
    );
vb@632
   781
vb@632
   782
vb@482
   783
DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session);
vb@482
   784
vb@0
   785
#ifdef __cplusplus
vb@0
   786
}
vb@0
   787
#endif