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