src/pEpEngine.h
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 29 Jan 2019 19:19:30 +0100
branchENGINE-448
changeset 3254 6e7f6bc9460a
parent 3071 aae2e2a9ad63
child 3271 9425e2da65e4
child 3270 d8aea79654c3
permissions -rw-r--r--
ENGINE-448: made key removal much less aggressive. NetPGP will still be a problem, but versions built against gpg will now only remove actual keys
vb@1517
     1
// This file is under GNU General Public License 3.0
vb@1517
     2
// see LICENSE.txt
vb@1517
     3
vb@23
     4
#pragma once
vb@23
     5
vb@0
     6
#ifdef __cplusplus
vb@0
     7
extern "C" {
vb@0
     8
#endif
vb@0
     9
vb@25
    10
#include <stddef.h>
vb@0
    11
#include <stdint.h>
vb@0
    12
#include <stdbool.h>
vb@0
    13
vb@98
    14
#include "dynamic_api.h"
vb@98
    15
#include "stringlist.h"
krista@2967
    16
#include "stringpair.h"
krista@2967
    17
#include "labeled_int_list.h"    
vb@201
    18
#include "timestamp.h"
vb@0
    19
krista@2152
    20
#define PEP_VERSION "2.0" // protocol version
vb@94
    21
Edouard@658
    22
#define PEP_OWN_USERID "pEp_own_userId"
Edouard@658
    23
    
vb@0
    24
// pEp Engine API
vb@0
    25
vb@0
    26
//  caveat:
vb@0
    27
//      Unicode data has to be normalized to NFC before calling
vb@0
    28
//      UTF-8 strings are UTF-8 encoded C strings (zero terminated)
vb@0
    29
vb@0
    30
vb@46
    31
struct _pEpSession;
vb@46
    32
typedef struct _pEpSession * PEP_SESSION;
vb@0
    33
vb@0
    34
typedef enum {
roker@529
    35
    PEP_STATUS_OK                                   = 0,
vb@0
    36
roker@529
    37
    PEP_INIT_CANNOT_LOAD_GPGME                      = 0x0110,
roker@529
    38
    PEP_INIT_GPGME_INIT_FAILED                      = 0x0111,
roker@529
    39
    PEP_INIT_NO_GPG_HOME                            = 0x0112,
roker@529
    40
    PEP_INIT_NETPGP_INIT_FAILED                     = 0x0113,
krista@2461
    41
    PEP_INIT_CANNOT_DETERMINE_GPG_VERSION           = 0x0114,
krista@2461
    42
    PEP_INIT_UNSUPPORTED_GPG_VERSION                = 0x0115,
krista@2461
    43
    PEP_INIT_CANNOT_CONFIG_GPG_AGENT                = 0x0116,
vb@0
    44
roker@529
    45
    PEP_INIT_SQLITE3_WITHOUT_MUTEX                  = 0x0120,
roker@529
    46
    PEP_INIT_CANNOT_OPEN_DB                         = 0x0121,
roker@529
    47
    PEP_INIT_CANNOT_OPEN_SYSTEM_DB                  = 0x0122,
roker@529
    48
    
roker@529
    49
    PEP_KEY_NOT_FOUND                               = 0x0201,
roker@529
    50
    PEP_KEY_HAS_AMBIG_NAME                          = 0x0202,
roker@529
    51
    PEP_GET_KEY_FAILED                              = 0x0203,
vb@1103
    52
    PEP_CANNOT_EXPORT_KEY                           = 0x0204,
edouard@1802
    53
    PEP_CANNOT_EDIT_KEY                             = 0x0205,
krista@2461
    54
    PEP_KEY_UNSUITABLE                              = 0x0206,
krista@3254
    55
krista@3254
    56
    PEP_KEY_IMPORTED                                = 0x0210,
krista@3254
    57
    PEP_NO_KEY_IMPORTED                             = 0x0211,
krista@3254
    58
    PEP_KEY_IMPORT_STATUS_UNKNOWN                   = 0x0212,
roker@529
    59
    
roker@529
    60
    PEP_CANNOT_FIND_IDENTITY                        = 0x0301,
roker@529
    61
    PEP_CANNOT_SET_PERSON                           = 0x0381,
roker@529
    62
    PEP_CANNOT_SET_PGP_KEYPAIR                      = 0x0382,
roker@529
    63
    PEP_CANNOT_SET_IDENTITY                         = 0x0383,
vb@370
    64
    PEP_CANNOT_SET_TRUST                            = 0x0384,
vb@515
    65
    PEP_KEY_BLACKLISTED                             = 0x0385,
krista@2461
    66
    PEP_CANNOT_FIND_PERSON                          = 0x0386,
krista@2461
    67
    
krista@2461
    68
    PEP_CANNOT_FIND_ALIAS                           = 0x0391,
krista@2461
    69
    PEP_CANNOT_SET_ALIAS                            = 0x0392,
roker@529
    70
    
roker@529
    71
    PEP_UNENCRYPTED                                 = 0x0400,
roker@529
    72
    PEP_VERIFIED                                    = 0x0401,
roker@529
    73
    PEP_DECRYPTED                                   = 0x0402,
roker@529
    74
    PEP_DECRYPTED_AND_VERIFIED                      = 0x0403,
roker@529
    75
    PEP_DECRYPT_WRONG_FORMAT                        = 0x0404,
roker@529
    76
    PEP_DECRYPT_NO_KEY                              = 0x0405,
roker@529
    77
    PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH            = 0x0406,
vb@0
    78
    PEP_VERIFY_NO_KEY                               = 0x0407,
vb@0
    79
    PEP_VERIFIED_AND_TRUSTED                        = 0x0408,
krista@2615
    80
    PEP_CANNOT_REENCRYPT                            = 0x0409,
roker@529
    81
    PEP_CANNOT_DECRYPT_UNKNOWN                      = 0x04ff,
vb@0
    82
roker@529
    83
    PEP_TRUSTWORD_NOT_FOUND                         = 0x0501,
krista@1312
    84
    PEP_TRUSTWORDS_FPR_WRONG_LENGTH                 = 0x0502,
krista@1864
    85
    PEP_TRUSTWORDS_DUPLICATE_FPR                    = 0x0503,
vb@0
    86
vb@0
    87
    PEP_CANNOT_CREATE_KEY                           = 0x0601,
vb@0
    88
    PEP_CANNOT_SEND_KEY                             = 0x0602,
vb@0
    89
vb@458
    90
    PEP_PHRASE_NOT_FOUND                            = 0x0701,
vb@458
    91
vb@690
    92
    PEP_SEND_FUNCTION_NOT_REGISTERED                = 0x0801,
vb@691
    93
    PEP_CONTRAINTS_VIOLATED                         = 0x0802,
vb@691
    94
    PEP_CANNOT_ENCODE                               = 0x0803,
vb@690
    95
edouard@1467
    96
    PEP_SYNC_NO_NOTIFY_CALLBACK                     = 0x0901,
vb@951
    97
    PEP_SYNC_ILLEGAL_MESSAGE                        = 0x0902,
vb@1105
    98
    PEP_SYNC_NO_INJECT_CALLBACK                     = 0x0903,
vb@884
    99
vb@1085
   100
    PEP_SEQUENCE_VIOLATED                           = 0x0970,
vb@1085
   101
    PEP_CANNOT_INCREASE_SEQUENCE                    = 0x0971,
vb@1087
   102
    PEP_CANNOT_SET_SEQUENCE_VALUE                   = 0x0972,
vb@1087
   103
    PEP_OWN_SEQUENCE                                = 0x097f,
vb@1085
   104
vb@964
   105
    PEP_SYNC_STATEMACHINE_ERROR                     = 0x0980,
vb@1101
   106
    PEP_SYNC_NO_TRUST                               = 0x0981,
vb@964
   107
    PEP_STATEMACHINE_INVALID_STATE                  = 0x0982,
vb@964
   108
    PEP_STATEMACHINE_INVALID_EVENT                  = 0x0983,
vb@964
   109
    PEP_STATEMACHINE_INVALID_CONDITION              = 0x0984,
vb@964
   110
    PEP_STATEMACHINE_INVALID_ACTION                 = 0x0985,
edouard@1316
   111
    PEP_STATEMACHINE_INHIBITED_EVENT                = 0x0986,
vb@884
   112
roker@529
   113
    PEP_COMMIT_FAILED                               = 0xff01,
vb@1391
   114
    PEP_MESSAGE_CONSUME                             = 0xff02,
vb@1391
   115
    PEP_MESSAGE_IGNORE                              = 0xff03,
vb@0
   116
vb@1091
   117
    PEP_RECORD_NOT_FOUND                            = -6,
vb@44
   118
    PEP_CANNOT_CREATE_TEMP_FILE                     = -5,
vb@0
   119
    PEP_ILLEGAL_VALUE                               = -4,
vb@0
   120
    PEP_BUFFER_TOO_SMALL                            = -3,
roker@529
   121
    PEP_OUT_OF_MEMORY                               = -2,
krista@1914
   122
    PEP_UNKNOWN_ERROR                               = -1,
krista@1914
   123
    
krista@1914
   124
    PEP_VERSION_MISMATCH                            = -7,
vb@0
   125
} PEP_STATUS;
vb@0
   126
vb@0
   127
vb@0
   128
// INIT_STATUS init() - initialize pEpEngine for a thread
vb@0
   129
//
vb@0
   130
//  parameters:
roker@529
   131
//        session (out)   init() allocates session memory and returns a pointer
roker@529
   132
//                        as a handle
vb@0
   133
//
vb@0
   134
//  return value:
roker@529
   135
//        PEP_STATUS_OK = 0                 if init() succeeds
roker@529
   136
//        PEP_INIT_SQLITE3_WITHOUT_MUTEX    if SQLite3 was compiled with
roker@529
   137
//                                            SQLITE_THREADSAFE 0
roker@529
   138
//        PEP_INIT_CANNOT_LOAD_GPGME        if libgpgme.dll cannot be found
roker@529
   139
//        PEP_INIT_GPGME_INIT_FAILED        if GPGME init fails
roker@529
   140
//        PEP_INIT_CANNOT_OPEN_DB           if user's management db cannot be
roker@529
   141
//                                            opened
roker@529
   142
//        PEP_INIT_CANNOT_OPEN_SYSTEM_DB    if system's management db cannot be
roker@529
   143
//                                            opened
vb@0
   144
//
vb@0
   145
//  caveat:
krista@2126
   146
//      THE CALLER MUST GUARD THIS CALL EXTERNALLY WITH A MUTEX. release() should
krista@2126
   147
//      be similarly guarded.
krista@2126
   148
//
vb@0
   149
//      the pointer is valid only if the return value is PEP_STATUS_OK
vb@0
   150
//      in other case a NULL pointer will be returned; a valid handle must
vb@0
   151
//      be released using release() when it's no longer needed
vb@62
   152
//
vb@62
   153
//      the caller has to guarantee that the first call to this function
vb@62
   154
//      will succeed before further calls can be done
vb@0
   155
vb@0
   156
DYNAMIC_API PEP_STATUS init(PEP_SESSION *session);
vb@0
   157
vb@0
   158
vb@0
   159
// void release() - release thread session handle
vb@0
   160
//
vb@0
   161
//  parameters:
roker@529
   162
//        session (in)    session handle to release
vb@62
   163
//
roker@529
   164
//    caveat:
krista@2126
   165
//        THE CALLER MUST GUARD THIS CALL EXTERNALLY WITH A MUTEX. init() should
krista@2126
   166
//        be similarly guarded.
krista@2126
   167
//       
roker@529
   168
//        the last release() can be called only when all other release() calls
roker@529
   169
//        are done
vb@0
   170
vb@0
   171
DYNAMIC_API void release(PEP_SESSION session);
vb@0
   172
vb@0
   173
roker@1722
   174
// const stringlist_t* get_errorstack(PEP_SESSION) - get the error stack for that session, if any
roker@1722
   175
//
roker@1722
   176
//  parameters:
roker@1722
   177
//        session (in)    session handle
roker@1722
   178
//
roker@1722
   179
//    caveat:
roker@1722
   180
//        To get a useful error stack you have to compile with -DDEBUG_ERRORSTACK
roker@1722
   181
//        The error stack belongs to the session. Do no not change it!
roker@1722
   182
DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session);
roker@1722
   183
roker@1778
   184
roker@1777
   185
// void clear_errorstack(PEP_SESSION) - clear the error stack for that session, if any
roker@1777
   186
//
roker@1777
   187
//  parameters:
roker@1777
   188
//        session (in)    session handle
roker@1777
   189
//
roker@1777
   190
DYNAMIC_API void clear_errorstack(PEP_SESSION session);
roker@1777
   191
roker@1722
   192
vb@464
   193
// config_passive_mode() - enable passive mode
vb@464
   194
//
vb@464
   195
//  parameters:
vb@464
   196
//      session (in)    session handle
vb@467
   197
//      enable (in)     flag if enabled or disabled
vb@467
   198
vb@467
   199
DYNAMIC_API void config_passive_mode(PEP_SESSION session, bool enable);
vb@467
   200
vb@464
   201
vb@553
   202
// config_unencrypted_subject() - disable subject encryption
vb@467
   203
//
vb@467
   204
//  parameters:
vb@467
   205
//      session (in)    session handle
vb@467
   206
//      enable (in)     flag if enabled or disabled
vb@467
   207
vb@467
   208
DYNAMIC_API void config_unencrypted_subject(PEP_SESSION session, bool enable);
vb@464
   209
vb@464
   210
Edouard@721
   211
// config_use_only_own_private_keys() - enable passive mode
Edouard@721
   212
//
Edouard@721
   213
//  parameters:
Edouard@721
   214
//      session (in)    session handle
Edouard@721
   215
//      enable (in)     flag if enabled or disabled
Edouard@721
   216
Edouard@721
   217
DYNAMIC_API void config_use_only_own_private_keys(PEP_SESSION session, bool enable);
Edouard@721
   218
Edouard@721
   219
vb@1110
   220
// config_keep_sync_msg() - do not remove sync messages (for debugging purposes)
vb@1109
   221
//
vb@1109
   222
//      session (in)    session handle
vb@1109
   223
//      enable (in)     flag if enabled or disabled
vb@1109
   224
vb@1110
   225
DYNAMIC_API void config_keep_sync_msg(PEP_SESSION session, bool enable);
vb@1109
   226
vb@1109
   227
vb@1819
   228
// config_service_log() - log more for service purposes
vb@1819
   229
//
vb@1819
   230
//      session (in)    session handle
vb@1819
   231
//      enable (in)     flag if enabled or disabled
vb@1819
   232
vb@1819
   233
DYNAMIC_API void config_service_log(PEP_SESSION session, bool enable);
vb@1819
   234
vb@1819
   235
vb@0
   236
// decrypt_and_verify() - decrypt and/or verify a message
vb@0
   237
//
roker@529
   238
//    parameters:
krista@2978
   239
//        session (in)          session handle
krista@2978
   240
//        ctext (in)            cipher text to decrypt and/or verify
krista@2978
   241
//        csize (in)            size of cipher text
krista@2978
   242
//        dsigtext (in)         if extant, *detached* signature text for this
krista@2978
   243
//                              message (or NULL if not)
krista@2978
   244
//        dsize (in)            size of *detached* signature text for this
krista@2978
   245
//                              message (0, if no detached sig exists)
krista@2978
   246
//        ptext (out)           pointer to internal buffer with plain text
krista@2978
   247
//        psize (out)           size of plain text
krista@2978
   248
//        keylist (out)         list of key ids which where used to encrypt
krista@2978
   249
//        filename_ptr (out)    mails produced by certain PGP implementations 
krista@2978
   250
//                              may return a decrypted filename here for attachments. 
krista@2978
   251
//                              Externally, this can generally be NULL, and is an optional
krista@2978
   252
//                              parameter.
vb@0
   253
//
roker@529
   254
//    return value:
roker@529
   255
//        PEP_UNENCRYPTED               message was unencrypted and not signed
roker@529
   256
//        PEP_VERIFIED                  message was unencrypted, signature matches
roker@529
   257
//        PEP_DECRYPTED                 message is decrypted now, no signature
roker@529
   258
//        PEP_DECRYPTED_AND_VERIFIED    message is decrypted now and verified
roker@529
   259
//        PEP_DECRYPT_WRONG_FORMAT      message has wrong format to handle
roker@529
   260
//        PEP_DECRYPT_NO_KEY            key not available to decrypt and/or verify
roker@529
   261
//        PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH    wrong signature
vb@0
   262
//
roker@529
   263
//    caveat:
roker@529
   264
//        the ownerships of ptext as well as keylist are going to the caller
roker@529
   265
//        the caller must use free() (or an Windoze pEp_free()) and
roker@529
   266
//        free_stringlist() to free them
vb@15
   267
//
vb@15
   268
//      if this function failes an error message may be the first element of
vb@15
   269
//      keylist and the other elements may be the keys used for encryption
vb@0
   270
vb@0
   271
DYNAMIC_API PEP_STATUS decrypt_and_verify(
vb@0
   272
        PEP_SESSION session, const char *ctext, size_t csize,
krista@1397
   273
        const char *dsigtext, size_t dsigsize,
krista@2978
   274
        char **ptext, size_t *psize, stringlist_t **keylist,
krista@2978
   275
        char ** filename_ptr
vb@0
   276
    );
vb@0
   277
vb@0
   278
vb@0
   279
// verify_text() - verfy plain text with a digital signature
vb@0
   280
//
vb@0
   281
//  parameters:
vb@0
   282
//      session (in)    session handle
vb@0
   283
//      text (in)       text to verify
vb@0
   284
//      size (in)       size of text
vb@0
   285
//      signature (in)  signature text
vb@0
   286
//      sig_size (in)   size of signature
roker@529
   287
//      keylist (out)   list of key ids which where used to encrypt or NULL on
roker@529
   288
//                        error
vb@0
   289
//
vb@0
   290
//  return value:
roker@529
   291
//        PEP_VERIFIED                message was unencrypted, signature matches
roker@529
   292
//        PEP_DECRYPT_NO_KEY          key not available to decrypt and/or verify
roker@529
   293
//        PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH    wrong signature
vb@0
   294
vb@0
   295
DYNAMIC_API PEP_STATUS verify_text(
vb@0
   296
        PEP_SESSION session, const char *text, size_t size,
vb@0
   297
        const char *signature, size_t sig_size, stringlist_t **keylist
vb@0
   298
    );
vb@0
   299
vb@0
   300
vb@0
   301
// encrypt_and_sign() - encrypt and sign a message
vb@0
   302
//
roker@529
   303
//    parameters:
roker@529
   304
//        session (in)    session handle
roker@529
   305
//        keylist (in)    list of key ids to encrypt with as C strings
roker@529
   306
//        ptext (in)      plain text to decrypt and/or verify
roker@529
   307
//        psize (in)      size of plain text
roker@529
   308
//        ctext (out)     pointer to internal buffer with cipher text
roker@529
   309
//        csize (out)     size of cipher text
vb@0
   310
//
roker@529
   311
//    return value:
roker@529
   312
//        PEP_STATUS_OK = 0            encryption and signing succeeded
hernani@2771
   313
//        PEP_KEY_NOT_FOUND            at least one of the recipient keys
roker@529
   314
//                                     could not be found
hernani@2771
   315
//        PEP_KEY_HAS_AMBIG_NAME       at least one of the recipient keys has
roker@529
   316
//                                     an ambiguous name
roker@529
   317
//        PEP_GET_KEY_FAILED           cannot retrieve key
vb@0
   318
//
roker@529
   319
//    caveat:
roker@529
   320
//      the ownership of ctext is going to the caller
vb@0
   321
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@20
   322
//      the first key in keylist is being used to sign the message
vb@20
   323
//      this implies there has to be a private key for that keypair
vb@0
   324
vb@0
   325
DYNAMIC_API PEP_STATUS encrypt_and_sign(
vb@0
   326
        PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
vb@0
   327
        size_t psize, char **ctext, size_t *csize
vb@0
   328
    );
vb@0
   329
vb@0
   330
vb@0
   331
// log_event() - log a user defined event defined by UTF-8 encoded strings into
vb@0
   332
// management log
vb@0
   333
//
roker@529
   334
//    parameters:
roker@529
   335
//        session (in)        session handle
roker@529
   336
//        title (in)          C string with event name
roker@529
   337
//        entity (in)         C string with name of entity which is logging
roker@529
   338
//        description (in)    C string with long description for event or NULL if
roker@529
   339
//                            omitted
roker@529
   340
//        comment (in)        C string with user defined comment or NULL if
roker@529
   341
//                            omitted
vb@0
   342
//
roker@529
   343
//    return value:
roker@529
   344
//        PEP_STATUS_OK       log entry created
vb@0
   345
vb@0
   346
DYNAMIC_API PEP_STATUS log_event(
vb@450
   347
        PEP_SESSION session,
vb@451
   348
        const char *title,
vb@451
   349
        const char *entity,
vb@451
   350
        const char *description,
vb@451
   351
        const char *comment
vb@0
   352
    );
vb@0
   353
vb@0
   354
vb@1819
   355
DYNAMIC_API PEP_STATUS log_service(PEP_SESSION session, const char *title,
vb@1819
   356
        const char *entity, const char *description, const char *comment);
vb@1819
   357
vb@1819
   358
#define _STR_(x) #x
vb@1819
   359
#define _D_STR_(x) _STR_(x)
vb@1819
   360
#define S_LINE _D_STR_(__LINE__)
vb@1819
   361
vb@1819
   362
#define SERVICE_LOG(session, title, entity, desc) \
vb@1819
   363
    log_service((session), (title), (entity), (desc), "service " __FILE__ ":" S_LINE)
vb@1819
   364
vb@1819
   365
vb@233
   366
// trustword() - get the corresponding trustword for a 16 bit value
vb@0
   367
//
roker@529
   368
//    parameters:
roker@529
   369
//        session (in)            session handle
roker@529
   370
//        value (in)              value to find a trustword for
roker@529
   371
//        lang (in)               C string with ISO 639-1 language code
roker@529
   372
//        word (out)              pointer to C string with trustword UTF-8 encoded
roker@529
   373
//                                NULL if language is not supported or trustword
roker@529
   374
//                                wordlist is damaged or unavailable
roker@529
   375
//        wsize (out)             length of trustword
vb@0
   376
//
roker@529
   377
//    return value:
roker@529
   378
//        PEP_STATUS_OK            trustword retrieved
roker@529
   379
//        PEP_TRUSTWORD_NOT_FOUND  trustword not found
vb@0
   380
//
roker@529
   381
//    caveat:
roker@529
   382
//        the word pointer goes to the ownership of the caller
vb@0
   383
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   384
vb@233
   385
DYNAMIC_API PEP_STATUS trustword(
vb@0
   386
            PEP_SESSION session, uint16_t value, const char *lang,
vb@0
   387
            char **word, size_t *wsize
vb@0
   388
        );
vb@0
   389
vb@0
   390
vb@233
   391
// trustwords() - get trustwords for a string of hex values of a fingerprint
vb@0
   392
//
roker@529
   393
//    parameters:
roker@529
   394
//        session (in)        session handle
roker@529
   395
//        fingerprint (in)    C string with hex values to find trustwords for
roker@529
   396
//        lang (in)           C string with ISO 639-1 language code
roker@529
   397
//        words (out)         pointer to C string with trustwords UTF-8 encoded,
roker@529
   398
//                            separated by a blank each
roker@529
   399
//                            NULL if language is not supported or trustword
roker@529
   400
//                            wordlist is damaged or unavailable
roker@529
   401
//        wsize (out)         length of trustwords string
roker@529
   402
//        max_words (in)      only generate a string with max_words;
roker@529
   403
//                            if max_words == 0 there is no such limit
vb@0
   404
//
roker@529
   405
//    return value:
roker@529
   406
//        PEP_STATUS_OK            trustwords retrieved
roker@529
   407
//        PEP_OUT_OF_MEMORY        out of memory
roker@529
   408
//        PEP_TRUSTWORD_NOT_FOUND  at least one trustword not found
vb@0
   409
//
roker@529
   410
//    caveat:
roker@529
   411
//        the word pointer goes to the ownership of the caller
vb@0
   412
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   413
//
vb@0
   414
//  DON'T USE THIS FUNCTION FROM HIGH LEVEL LANGUAGES!
vb@0
   415
//
vb@233
   416
//  Better implement a simple one in the adapter yourself using trustword(), and
vb@233
   417
//  return a list of trustwords.
vb@0
   418
//  This function is provided for being used by C and C++ programs only.
vb@0
   419
vb@233
   420
DYNAMIC_API PEP_STATUS trustwords(
vb@0
   421
        PEP_SESSION session, const char *fingerprint, const char *lang,
vb@0
   422
        char **words, size_t *wsize, int max_words
vb@0
   423
    );
vb@0
   424
vb@0
   425
vb@951
   426
// TODO: increase versions in pEp.asn1 if rating changes
vb@951
   427
vb@0
   428
typedef enum _PEP_comm_type {
vb@9
   429
    PEP_ct_unknown = 0,
vb@0
   430
vb@9
   431
    // range 0x01 to 0x09: no encryption, 0x0a to 0x0e: nothing reasonable
vb@0
   432
vb@9
   433
    PEP_ct_no_encryption = 0x01,                // generic
vb@9
   434
    PEP_ct_no_encrypted_channel = 0x02,
vb@9
   435
    PEP_ct_key_not_found = 0x03,
vb@9
   436
    PEP_ct_key_expired = 0x04,
vb@9
   437
    PEP_ct_key_revoked = 0x05,
vb@9
   438
    PEP_ct_key_b0rken = 0x06,
krista@3071
   439
    PEP_ct_key_expired_but_confirmed = 0x07, // NOT with confirmed bit. Just retaining info here in case of renewal.
vb@9
   440
    PEP_ct_my_key_not_included = 0x09,
vb@9
   441
vb@9
   442
    PEP_ct_security_by_obscurity = 0x0a,
vb@9
   443
    PEP_ct_b0rken_crypto = 0x0b,
Edouard@442
   444
    PEP_ct_key_too_short = 0x0c,
vb@9
   445
krista@2593
   446
    PEP_ct_compromised = 0x0e,                  // known compromised connection
krista@2593
   447
    PEP_ct_compromized = 0x0e,                  // deprecated misspelling
Edouard@442
   448
    PEP_ct_mistrusted = 0x0f,                   // known mistrusted key
vb@0
   449
vb@9
   450
    // range 0x10 to 0x3f: unconfirmed encryption
vb@0
   451
vb@0
   452
    PEP_ct_unconfirmed_encryption = 0x10,       // generic
roker@529
   453
    PEP_ct_OpenPGP_weak_unconfirmed = 0x11,     // RSA 1024 is weak
vb@190
   454
vb@190
   455
    PEP_ct_to_be_checked = 0x20,                // generic
vb@190
   456
    PEP_ct_SMIME_unconfirmed = 0x21,
vb@190
   457
    PEP_ct_CMS_unconfirmed = 0x22,
vb@190
   458
vb@190
   459
    PEP_ct_strong_but_unconfirmed = 0x30,       // generic
vb@122
   460
    PEP_ct_OpenPGP_unconfirmed = 0x38,          // key at least 2048 bit RSA or EC
vb@122
   461
    PEP_ct_OTR_unconfirmed = 0x3a,
vb@0
   462
vb@9
   463
    // range 0x40 to 0x7f: unconfirmed encryption and anonymization
vb@0
   464
vb@0
   465
    PEP_ct_unconfirmed_enc_anon = 0x40,         // generic
lix@710
   466
    PEP_ct_pEp_unconfirmed = 0x7f,
vb@0
   467
vb@9
   468
    PEP_ct_confirmed = 0x80,                    // this bit decides if trust is confirmed
vb@9
   469
vb@9
   470
    // range 0x81 to 0x8f: reserved
vb@9
   471
    // range 0x90 to 0xbf: confirmed encryption
vb@0
   472
vb@0
   473
    PEP_ct_confirmed_encryption = 0x90,         // generic
edouard@1635
   474
    PEP_ct_OpenPGP_weak = 0x91,                 // RSA 1024 is weak (unused)
vb@190
   475
hernani@2772
   476
    PEP_ct_to_be_checked_confirmed = 0xa0,      // generic
vb@190
   477
    PEP_ct_SMIME = 0xa1,
vb@190
   478
    PEP_ct_CMS = 0xa2,
vb@190
   479
vb@190
   480
    PEP_ct_strong_encryption = 0xb0,            // generic
roker@529
   481
    PEP_ct_OpenPGP = 0xb8,                      // key at least 2048 bit RSA or EC
roker@529
   482
    PEP_ct_OTR = 0xba,
vb@0
   483
vb@0
   484
    // range 0xc0 to 0xff: confirmed encryption and anonymization
vb@0
   485
vb@0
   486
    PEP_ct_confirmed_enc_anon = 0xc0,           // generic
roker@529
   487
    PEP_ct_pEp = 0xff
vb@0
   488
} PEP_comm_type;
vb@0
   489
vb@928
   490
typedef enum _identity_flags {
vb@951
   491
    // the first octet flags are app defined settings
edouard@1394
   492
    PEP_idf_not_for_sync = 0x0001,   // don't use this identity for sync
edouard@1394
   493
    PEP_idf_list = 0x0002,           // identity of list of persons
vb@951
   494
    // the second octet flags are calculated
edouard@1394
   495
    PEP_idf_devicegroup = 0x0100     // identity of a device group member
vb@928
   496
} identity_flags;
vb@928
   497
vb@944
   498
typedef unsigned int identity_flags_t;
vb@944
   499
edouard@1394
   500
// typedef enum _keypair_flags {
edouard@1394
   501
// } keypair_flags;
edouard@1364
   502
edouard@1364
   503
typedef unsigned int keypair_flags_t;
edouard@1364
   504
vb@0
   505
typedef struct _pEp_identity {
roker@529
   506
    char *address;              // C string with address UTF-8 encoded
roker@529
   507
    char *fpr;                  // C string with fingerprint UTF-8 encoded
roker@529
   508
    char *user_id;              // C string with user ID UTF-8 encoded
krista@2461
   509
                                // user_id MIGHT be set to "pEp_own_userId"
edouard@1946
   510
                                // (use PEP_OWN_USERID preprocessor define)
edouard@1946
   511
                                // if this is own user's identity.
krista@2461
   512
                                // But it is not REQUIRED to be.
roker@529
   513
    char *username;             // C string with user name UTF-8 encoded
roker@529
   514
    PEP_comm_type comm_type;    // type of communication with this ID
roker@529
   515
    char lang[3];               // language of conversation
vb@0
   516
                                // ISO 639-1 ALPHA-2, last byte is 0
krista@2461
   517
    bool me;                    // if this is the local user herself/himself
vb@944
   518
    identity_flags_t flags;     // identity_flag1 | identity_flag2 | ...
vb@0
   519
} pEp_identity;
vb@0
   520
Edouard@730
   521
typedef struct _identity_list {
Edouard@730
   522
    pEp_identity *ident;
Edouard@730
   523
    struct _identity_list *next;
Edouard@730
   524
} identity_list;
Edouard@730
   525
vb@0
   526
vb@0
   527
// new_identity() - allocate memory and set the string and size fields
vb@0
   528
//
vb@0
   529
//  parameters:
vb@0
   530
//      address (in)        UTF-8 string or NULL 
vb@0
   531
//      fpr (in)            UTF-8 string or NULL 
vb@0
   532
//      user_id (in)        UTF-8 string or NULL 
vb@0
   533
//      username (in)       UTF-8 string or NULL 
vb@0
   534
//
vb@0
   535
//  return value:
vb@932
   536
//      pEp_identity struct or NULL if out of memory
vb@0
   537
//
vb@0
   538
//  caveat:
vb@0
   539
//      the strings are copied; the original strings are still being owned by
vb@0
   540
//      the caller
vb@0
   541
vb@0
   542
DYNAMIC_API pEp_identity *new_identity(
vb@0
   543
        const char *address, const char *fpr, const char *user_id,
vb@0
   544
        const char *username
vb@0
   545
    );
vb@0
   546
vb@0
   547
vb@932
   548
// identity_dup() - allocate memory and duplicate
vb@37
   549
//
vb@37
   550
//  parameters:
vb@37
   551
//      src (in)            identity to duplicate
vb@37
   552
//
vb@37
   553
//  return value:
vb@932
   554
//      pEp_identity struct or NULL if out of memory
vb@37
   555
//
vb@37
   556
//  caveat:
vb@37
   557
//      the strings are copied; the original strings are still being owned by
vb@37
   558
//      the caller
vb@37
   559
vb@37
   560
DYNAMIC_API pEp_identity *identity_dup(const pEp_identity *src);
vb@37
   561
vb@37
   562
vb@0
   563
// free_identity() - free all memory being occupied by a pEp_identity struct
vb@0
   564
//
vb@0
   565
//  parameters:
vb@0
   566
//      identity (in)       struct to release
vb@0
   567
//
vb@0
   568
//  caveat:
vb@0
   569
//      not only the struct but also all string memory referenced by the
vb@0
   570
//      struct is being freed; all pointers inside are invalid afterwards
vb@0
   571
vb@0
   572
DYNAMIC_API void free_identity(pEp_identity *identity);
vb@0
   573
vb@0
   574
vb@0
   575
// get_identity() - get identity information
vb@0
   576
//
roker@529
   577
//    parameters:
roker@529
   578
//        session (in)        session handle
roker@529
   579
//        address (in)        C string with communication address, UTF-8 encoded
Edouard@562
   580
//        user_id (in)        unique C string to identify person that identity
Edouard@562
   581
//                            is refering to
roker@529
   582
//        identity (out)      pointer to pEp_identity structure with results or
roker@529
   583
//                            NULL if failure
vb@0
   584
//
roker@529
   585
//    caveat:
vb@951
   586
//        address and user_id are being copied; the original strings remains in
vb@951
   587
//        the ownership of the caller
roker@529
   588
//        the resulting pEp_identity structure goes to the ownership of the
roker@529
   589
//        caller and has to be freed with free_identity() when not in use any
roker@529
   590
//        more
vb@0
   591
vb@0
   592
DYNAMIC_API PEP_STATUS get_identity(
Edouard@559
   593
        PEP_SESSION session,
Edouard@559
   594
        const char *address,
Edouard@559
   595
        const char *user_id,
vb@0
   596
        pEp_identity **identity
vb@0
   597
    );
vb@0
   598
krista@1799
   599
PEP_STATUS replace_identities_fpr(PEP_SESSION session, 
krista@1799
   600
                                 const char* old_fpr, 
krista@1799
   601
                                 const char* new_fpr); 
krista@1797
   602
krista@1797
   603
vb@0
   604
// set_identity() - set identity information
vb@0
   605
//
roker@529
   606
//    parameters:
roker@529
   607
//        session (in)        session handle
roker@529
   608
//        identity (in)       pointer to pEp_identity structure
vb@0
   609
//
roker@529
   610
//    return value:
roker@529
   611
//        PEP_STATUS_OK = 0             encryption and signing succeeded
roker@529
   612
//        PEP_CANNOT_SET_PERSON         writing to table person failed
roker@529
   613
//        PEP_CANNOT_SET_PGP_KEYPAIR    writing to table pgp_keypair failed
roker@529
   614
//        PEP_CANNOT_SET_IDENTITY       writing to table identity failed
roker@529
   615
//        PEP_COMMIT_FAILED             SQL commit failed
vb@0
   616
//
roker@529
   617
//    caveat:
vb@932
   618
//        address, fpr, user_id and username must be given
vb@0
   619
vb@0
   620
DYNAMIC_API PEP_STATUS set_identity(
vb@0
   621
        PEP_SESSION session, const pEp_identity *identity
vb@0
   622
    );
vb@0
   623
krista@2461
   624
// get_default own_userid() - get the user_id of the own user
krista@2461
   625
//
krista@2461
   626
//    parameters:
krista@2461
   627
//        session (in)        session handle
krista@2461
   628
//        userid  (out)       own user id (if it exists)
krista@2461
   629
//
krista@2461
   630
//    return value:
krista@2461
   631
//        PEP_STATUS_OK = 0             userid was found
krista@2461
   632
//        PEP_CANNOT_FIND_IDENTITY      no own_user found in the DB
krista@2461
   633
//        PEP_UNKNOWN_ERROR             results were returned, but no ID
krista@2461
   634
//                                      found (no reason this should ever occur)
krista@2461
   635
//    caveat:
krista@2461
   636
//        userid will be NULL if not found; otherwise, returned string
krista@2461
   637
//        belongs to the caller.
krista@2461
   638
krista@2461
   639
DYNAMIC_API PEP_STATUS get_default_own_userid(
krista@2461
   640
        PEP_SESSION session, 
krista@2461
   641
        char** userid
krista@2461
   642
    );
krista@2461
   643
krista@2461
   644
// get_userid_alias_default() - get the default user_id which corresponds
krista@2461
   645
//                              to an alias
krista@2461
   646
//    parameters:
krista@2461
   647
//        session (in)        session handle
krista@2461
   648
//        alias_id (in)       the user_id which may be an alias for a default id
krista@2461
   649
//        default_id (out)    the default id for this alias, if the alias
krista@2461
   650
//                            is in the DB as an alias, else NULL
krista@2461
   651
//    return value:
krista@2461
   652
//        PEP_STATUS_OK = 0             userid was found
krista@2461
   653
//        PEP_CANNOT_FIND_ALIAS         this userid is not listed as an 
krista@2461
   654
//                                      alias in the DB
krista@2461
   655
//        PEP_UNKNOWN_ERROR             results were returned, but no ID
krista@2461
   656
//                                      found (no reason this should ever occur)
krista@2461
   657
//    caveat:
krista@2461
   658
//        default_id will be NULL if not found; otherwise, returned string
krista@2461
   659
//        belongs to the caller.
krista@2461
   660
//        also, current implementation does NOT check to see if this userid
krista@2461
   661
//        IS a default.
krista@2461
   662
krista@2461
   663
DYNAMIC_API PEP_STATUS get_userid_alias_default(
krista@2461
   664
        PEP_SESSION session, 
krista@2461
   665
        const char* alias_id,
krista@2461
   666
        char** default_id);
krista@2461
   667
krista@2461
   668
// set_userid_alias() - set an alias to correspond to a default id
krista@2461
   669
//    parameters:
krista@2461
   670
//        session (in)        session handle
krista@2461
   671
//        default_id (in)     the default id for this alias. This must
krista@2461
   672
//                            correspond to the default user_id for an
krista@2461
   673
//                            entry in the person (user) table.
krista@2461
   674
//        alias_id (in)       the alias to be set for this default id
krista@2461
   675
//    return value:
krista@2461
   676
//        PEP_STATUS_OK = 0             userid was found
krista@2461
   677
//        PEP_CANNOT_SET_ALIAS          there was an error setting this
krista@2461
   678
krista@2461
   679
DYNAMIC_API PEP_STATUS set_userid_alias (
krista@2461
   680
        PEP_SESSION session, 
krista@2461
   681
        const char* default_id,
krista@2461
   682
        const char* alias_id);
krista@2461
   683
krista@2461
   684
edouard@1234
   685
// set_device_group() - update own person's device group
edouard@1234
   686
//
edouard@1234
   687
//    parameters:
edouard@1234
   688
//        session (in)        session handle
edouard@1234
   689
//        group_name (in)     new group name
edouard@1234
   690
//
edouard@1234
   691
//    return value:
edouard@1235
   692
//        PEP_STATUS_OK = 0             device group was updated
edouard@1234
   693
//        PEP_CANNOT_SET_PERSON         update failed
edouard@1234
   694
edouard@1234
   695
DYNAMIC_API PEP_STATUS set_device_group(
edouard@1234
   696
        PEP_SESSION session,
edouard@1234
   697
        const char *group_name
edouard@1234
   698
    );
vb@0
   699
edouard@1235
   700
// get_device_group() - get own person's device group
edouard@1235
   701
//
edouard@1235
   702
//    parameters:
edouard@1235
   703
//        session (in)        session handle
edouard@1235
   704
//        group_name (in)     new group name
edouard@1235
   705
//
edouard@1235
   706
//    return value:
edouard@1235
   707
//        PEP_STATUS_OK = 0             couldn't get device group
edouard@1235
   708
//        PEP_RECORD_NOT_FOUND          update failed
edouard@1235
   709
//
edouard@1235
   710
//    caveat:
edouard@1235
   711
//        the ownerships of group_name is going to the caller
edouard@1235
   712
edouard@1235
   713
DYNAMIC_API PEP_STATUS get_device_group(
edouard@1235
   714
        PEP_SESSION session, 
edouard@1235
   715
        char **group_name
edouard@1235
   716
    );
edouard@1235
   717
vb@932
   718
// set_identity_flags() - update identity flags on existing identity
vb@932
   719
//
vb@932
   720
//    parameters:
vb@932
   721
//        session (in)        session handle
vb@934
   722
//        identity (in,out)   pointer to pEp_identity structure
vb@934
   723
//        flags (in)          new value for flags
vb@932
   724
//
vb@932
   725
//    return value:
vb@932
   726
//        PEP_STATUS_OK = 0             encryption and signing succeeded
vb@932
   727
//        PEP_CANNOT_SET_IDENTITY       update of identity failed
vb@932
   728
//
vb@932
   729
//    caveat:
vb@934
   730
//        address and user_id must be given in identity
vb@932
   731
vb@932
   732
DYNAMIC_API PEP_STATUS set_identity_flags(
vb@934
   733
        PEP_SESSION session,
vb@934
   734
        pEp_identity *identity,
vb@1425
   735
        identity_flags_t flags
vb@932
   736
    );
vb@932
   737
edouard@1406
   738
// unset_identity_flags() - update identity flags on existing identity
edouard@1406
   739
//
edouard@1406
   740
//    parameters:
edouard@1406
   741
//        session (in)        session handle
edouard@1406
   742
//        identity (in,out)   pointer to pEp_identity structure
edouard@1406
   743
//        flags (in)          new value for flags
edouard@1406
   744
//
edouard@1406
   745
//    return value:
edouard@1406
   746
//        PEP_STATUS_OK = 0             encryption and signing succeeded
edouard@1406
   747
//        PEP_CANNOT_SET_IDENTITY       update of identity failed
edouard@1406
   748
//
edouard@1406
   749
//    caveat:
edouard@1406
   750
//        address and user_id must be given in identity
edouard@1406
   751
edouard@1406
   752
DYNAMIC_API PEP_STATUS unset_identity_flags(
edouard@1406
   753
        PEP_SESSION session,
edouard@1406
   754
        pEp_identity *identity,
vb@1425
   755
        identity_flags_t flags
edouard@1406
   756
    );
vb@932
   757
krista@2593
   758
// mark_as_compromised() - mark key in trust db as compromised
vb@357
   759
//
roker@529
   760
//    parameters:
roker@529
   761
//        session (in)        session handle
roker@529
   762
//        fpr (in)            fingerprint of key to mark
vb@357
   763
krista@2593
   764
DYNAMIC_API PEP_STATUS mark_as_compromised(
krista@2593
   765
        PEP_SESSION session,
krista@2593
   766
        const char *fpr
krista@2593
   767
    );
krista@2593
   768
krista@2593
   769
krista@2593
   770
// mark_as_compromized() - deprecated to fix misspelling. Please move to
krista@2593
   771
//                         mark_as_compromised();
krista@2593
   772
vb@357
   773
DYNAMIC_API PEP_STATUS mark_as_compromized(
vb@357
   774
        PEP_SESSION session,
vb@357
   775
        const char *fpr
vb@357
   776
    );
vb@357
   777
vb@357
   778
vb@0
   779
// generate_keypair() - generate a new key pair and add it to the key ring
vb@0
   780
//
vb@0
   781
//  parameters:
vb@0
   782
//      session (in)            session handle
roker@529
   783
//        identity (inout)      pointer to pEp_identity structure
vb@0
   784
//
roker@529
   785
//    return value:
roker@529
   786
//        PEP_STATUS_OK = 0       encryption and signing succeeded
roker@529
   787
//        PEP_ILLEGAL_VALUE       illegal values for identity fields given
roker@529
   788
//        PEP_CANNOT_CREATE_KEY   key engine is on strike
vb@0
   789
//
vb@0
   790
//  caveat:
vb@0
   791
//      address and username fields must be set to UTF-8 strings
vb@0
   792
//      the fpr field must be set to NULL
vb@0
   793
//
vb@0
   794
//      this function allocates a string and sets set fpr field of identity
vb@0
   795
//      the caller is responsible to call free() for that string or use
vb@0
   796
//      free_identity() on the struct
vb@0
   797
vb@0
   798
DYNAMIC_API PEP_STATUS generate_keypair(
vb@0
   799
        PEP_SESSION session, pEp_identity *identity
vb@0
   800
    );
vb@0
   801
vb@0
   802
vb@0
   803
// delete_keypair() - delete a public key or a key pair from the key ring
vb@0
   804
//
vb@0
   805
//  parameters:
vb@0
   806
//      session (in)            session handle
vb@0
   807
//      fpr (in)                C string with key id or fingerprint of the
vb@0
   808
//                              public key
vb@0
   809
//
vb@0
   810
//  return value:
vb@0
   811
//      PEP_STATUS_OK = 0       key was successfully deleted
vb@0
   812
//      PEP_KEY_NOT_FOUND       key not found
vb@0
   813
//      PEP_ILLEGAL_VALUE       not a valid key id or fingerprint
vb@0
   814
//      PEP_KEY_HAS_AMBIG_NAME  fpr does not uniquely identify a key
vb@0
   815
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   816
vb@0
   817
DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr);
vb@0
   818
vb@0
   819
vb@0
   820
// import_key() - import key from data
vb@0
   821
//
vb@0
   822
//  parameters:
vb@0
   823
//      session (in)            session handle
vb@0
   824
//      key_data (in)           key data, i.e. ASCII armored OpenPGP key
vb@0
   825
//      size (in)               amount of data to handle
Edouard@772
   826
//      private_keys (out)      list of private keys that have been imported
vb@0
   827
//
vb@0
   828
//  return value:
vb@0
   829
//      PEP_STATUS_OK = 0       key was successfully imported
vb@0
   830
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   831
//      PEP_ILLEGAL_VALUE       there is no key data to import
Edouard@772
   832
//
Edouard@772
   833
//  caveat:
Edouard@772
   834
//      private_keys goes to the ownership of the caller
Edouard@772
   835
//      private_keys can be left NULL, it is then ignored
vb@0
   836
Edouard@728
   837
DYNAMIC_API PEP_STATUS import_key(
Edouard@728
   838
        PEP_SESSION session,
Edouard@728
   839
        const char *key_data,
Edouard@728
   840
        size_t size,
Edouard@728
   841
        identity_list **private_keys
Edouard@728
   842
    );
vb@0
   843
vb@0
   844
vb@0
   845
// export_key() - export ascii armored key
vb@0
   846
//
vb@0
   847
//  parameters:
vb@0
   848
//      session (in)            session handle
vb@0
   849
//      fpr (in)                key id or fingerprint of key
vb@0
   850
//      key_data (out)          ASCII armored OpenPGP key
roker@529
   851
//      size (out)              amount of data to handle
vb@0
   852
//
vb@0
   853
//  return value:
vb@0
   854
//      PEP_STATUS_OK = 0       key was successfully exported
vb@0
   855
//      PEP_OUT_OF_MEMORY       out of memory
vb@0
   856
//      PEP_KEY_NOT_FOUND       key not found
vb@0
   857
//
vb@0
   858
//  caveat:
vb@0
   859
//      the key_data goes to the ownership of the caller
vb@0
   860
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@0
   861
vb@0
   862
DYNAMIC_API PEP_STATUS export_key(
vb@0
   863
        PEP_SESSION session, const char *fpr, char **key_data, size_t *size
vb@0
   864
    );
vb@0
   865
vb@0
   866
vb@1103
   867
// export_secret_key() - export secret key ascii armored
vb@1103
   868
//
vb@1103
   869
//  parameters:
vb@1103
   870
//      session (in)            session handle
vb@1103
   871
//      fpr (in)                fingerprint of key, at least 16 hex digits
vb@1103
   872
//      key_data (out)          ASCII armored OpenPGP secret key
vb@1103
   873
//      size (out)              amount of data to handle
vb@1103
   874
//
vb@1103
   875
//  return value:
vb@1103
   876
//      PEP_STATUS_OK = 0       key was successfully exported
vb@1103
   877
//      PEP_OUT_OF_MEMORY       out of memory
vb@1103
   878
//      PEP_KEY_NOT_FOUND       key not found
vb@1103
   879
//      PEP_CANNOT_EXPORT_KEY   cannot export secret key (i.e. it's on an HKS)
vb@1103
   880
//
vb@1103
   881
//  caveat:
vb@1103
   882
//      the key_data goes to the ownership of the caller
vb@1103
   883
//      the caller is responsible to free() it (on Windoze use pEp_free())
vb@1103
   884
//      beware of leaking secret key data - overwrite it in memory after use
vb@1103
   885
krista@2593
   886
DYNAMIC_API PEP_STATUS export_secret_key(
krista@2593
   887
        PEP_SESSION session, const char *fpr, char **key_data, size_t *size
krista@2593
   888
    );
krista@2593
   889
krista@2593
   890
krista@2593
   891
// export_secrect_key() - deprecated misspelled function. Please replace with
krista@2593
   892
//                        export_secret_key
krista@2593
   893
vb@1103
   894
DYNAMIC_API PEP_STATUS export_secrect_key(
vb@1103
   895
        PEP_SESSION session, const char *fpr, char **key_data, size_t *size
vb@1103
   896
    );
vb@1103
   897
vb@1103
   898
vb@0
   899
// recv_key() - update key(s) from keyserver
vb@0
   900
//
vb@0
   901
//  parameters:
vb@0
   902
//      session (in)            session handle
vb@0
   903
//      pattern (in)            key id, user id or address to search for as
vb@0
   904
//                              UTF-8 string
vb@0
   905
vb@0
   906
DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern);
vb@0
   907
vb@0
   908
vb@0
   909
// find_keys() - find keys in keyring
vb@0
   910
//
vb@0
   911
//  parameters:
vb@0
   912
//      session (in)            session handle
vb@0
   913
//      pattern (in)            key id, user id or address to search for as
vb@0
   914
//                              UTF-8 string
vb@0
   915
//      keylist (out)           list of fingerprints found or NULL on error
vb@0
   916
//
vb@0
   917
//  caveat:
roker@529
   918
//        the ownerships of keylist isgoing to the caller
roker@529
   919
//        the caller must use free_stringlist() to free it
vb@0
   920
vb@0
   921
vb@0
   922
DYNAMIC_API PEP_STATUS find_keys(
vb@0
   923
        PEP_SESSION session, const char *pattern, stringlist_t **keylist
vb@0
   924
    );
vb@0
   925
vb@0
   926
// send_key() - send key(s) to keyserver
vb@0
   927
//
vb@0
   928
//  parameters:
vb@0
   929
//      session (in)            session handle
vb@0
   930
//      pattern (in)            key id, user id or address to search for as
vb@0
   931
//                              UTF-8 string
vb@0
   932
vb@0
   933
DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern);
vb@0
   934
vb@0
   935
vb@0
   936
// pEp_free() - free memory allocated by pEp engine
vb@0
   937
//
vb@0
   938
//  parameters:
vb@0
   939
//      p (in)                  pointer to free
vb@0
   940
//
vb@0
   941
//  The reason for this function is that heap management can be a pretty
vb@0
   942
//  complex task with Windoze. This free() version calls the free()
vb@0
   943
//  implementation of the C runtime library which was used to build pEp engine,
vb@0
   944
//  so you're using the correct heap. For more information, see:
vb@0
   945
//  <http://msdn.microsoft.com/en-us/library/windows/desktop/aa366711(v=vs.85).aspx>
vb@0
   946
vb@0
   947
DYNAMIC_API void pEp_free(void *p);
vb@0
   948
vb@8
   949
vb@8
   950
// get_trust() - get the trust level a key has for a person
vb@8
   951
//
vb@8
   952
//  parameters:
vb@8
   953
//      session (in)            session handle
vb@8
   954
//      identity (inout)        user_id and fpr to check as UTF-8 strings (in)
krista@2461
   955
//                              comm_type as result (out)
vb@8
   956
//
vb@14
   957
//  this function modifies the given identity struct; the struct remains in
vb@251
   958
//  the ownership of the caller
vb@14
   959
//  if the trust level cannot be determined identity->comm_type is set
vb@14
   960
//  to PEP_ct_unknown
vb@8
   961
vb@8
   962
DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity);
vb@8
   963
krista@2129
   964
krista@1797
   965
PEP_STATUS set_trust(PEP_SESSION session, 
krista@2480
   966
                     pEp_identity* identity);
krista@1805
   967
                            
krista@1805
   968
PEP_STATUS update_trust_for_fpr(PEP_SESSION session, 
krista@1805
   969
                                const char* fpr, 
krista@1805
   970
                                PEP_comm_type comm_type);
vb@8
   971
vb@251
   972
// least_trust() - get the least known trust level for a key in the database
vb@251
   973
//
vb@251
   974
//  parameters:
vb@251
   975
//      session (in)            session handle
vb@251
   976
//      fpr (in)                fingerprint of key to check
vb@251
   977
//      comm_type (out)         least comm_type as result (out)
vb@251
   978
//
vb@251
   979
//  if the trust level cannot be determined comm_type is set to PEP_ct_unknown
vb@251
   980
vb@251
   981
DYNAMIC_API PEP_STATUS least_trust(
vb@251
   982
        PEP_SESSION session,
vb@251
   983
        const char *fpr,
vb@251
   984
        PEP_comm_type *comm_type
vb@251
   985
    );
vb@251
   986
vb@251
   987
vb@9
   988
// get_key_rating() - get the rating a bare key has
vb@9
   989
//
vb@9
   990
//  parameters:
vb@9
   991
//      session (in)            session handle
vb@9
   992
//      fpr (in)                unique identifyer for key as UTF-8 string
vb@9
   993
//      comm_type (out)         key rating
vb@10
   994
//
vb@14
   995
//  if an error occurs, *comm_type is set to PEP_ct_unknown and an error
vb@10
   996
//  is returned
vb@9
   997
vb@9
   998
DYNAMIC_API PEP_STATUS get_key_rating(
vb@14
   999
        PEP_SESSION session,
vb@14
  1000
        const char *fpr,
vb@14
  1001
        PEP_comm_type *comm_type
vb@9
  1002
    );
vb@9
  1003
vb@9
  1004
vb@198
  1005
// renew_key() - renew an expired key
vb@196
  1006
//
vb@196
  1007
//  parameters:
vb@196
  1008
//      session (in)            session handle
vb@214
  1009
//      fpr (in)                ID of key to renew as UTF-8 string
vb@201
  1010
//      ts (in)                 timestamp when key should expire or NULL for
vb@201
  1011
//                              default
vb@196
  1012
vb@201
  1013
DYNAMIC_API PEP_STATUS renew_key(
vb@201
  1014
        PEP_SESSION session,
vb@201
  1015
        const char *fpr,
vb@201
  1016
        const timestamp *ts
vb@201
  1017
    );
vb@196
  1018
vb@196
  1019
vb@224
  1020
// revoke_key() - revoke a key
vb@197
  1021
//
vb@197
  1022
//  parameters:
vb@197
  1023
//      session (in)            session handle
vb@214
  1024
//      fpr (in)                ID of key to revoke as UTF-8 string
vb@211
  1025
//      reason (in)             text with reason for revoke as UTF-8 string
vb@211
  1026
//                              or NULL if reason unknown
vb@211
  1027
//
vb@211
  1028
//  caveat:
vb@211
  1029
//      reason text must not include empty lines
vb@224
  1030
//      this function is meant for internal use only; better use
krista@1213
  1031
//      key_mistrusted() of keymanagement API
vb@197
  1032
vb@211
  1033
DYNAMIC_API PEP_STATUS revoke_key(
vb@211
  1034
        PEP_SESSION session,
vb@211
  1035
        const char *fpr,
vb@211
  1036
        const char *reason
vb@211
  1037
    );
vb@197
  1038
vb@197
  1039
vb@214
  1040
// key_expired() - flags if a key is already expired
vb@214
  1041
//
vb@214
  1042
//  parameters:
vb@214
  1043
//      session (in)            session handle
vb@214
  1044
//      fpr (in)                ID of key to check as UTF-8 string
Edouard@701
  1045
//      when (in)               UTC time of when should expiry be considered
vb@214
  1046
//      expired (out)           flag if key expired
vb@214
  1047
vb@214
  1048
DYNAMIC_API PEP_STATUS key_expired(
vb@214
  1049
        PEP_SESSION session,
vb@214
  1050
        const char *fpr,
Edouard@701
  1051
        const time_t when,
vb@214
  1052
        bool *expired
vb@214
  1053
    );
vb@214
  1054
Edouard@694
  1055
    
Edouard@694
  1056
// key_revoked() - flags if a key is already revoked
Edouard@694
  1057
//
Edouard@694
  1058
//  parameters:
Edouard@694
  1059
//      session (in)            session handle
Edouard@694
  1060
//      fpr (in)                ID of key to check as UTF-8 string
Edouard@694
  1061
//      revoked (out)           flag if key revoked
Edouard@694
  1062
Edouard@694
  1063
DYNAMIC_API PEP_STATUS key_revoked(
Edouard@694
  1064
        PEP_SESSION session,
Edouard@694
  1065
        const char *fpr,
Edouard@694
  1066
        bool *revoked
Edouard@694
  1067
    );
Edouard@694
  1068
krista@1797
  1069
PEP_STATUS get_key_userids(
krista@1797
  1070
        PEP_SESSION session,
krista@1797
  1071
        const char* fpr,
krista@1797
  1072
        stringlist_t** keylist
krista@1797
  1073
    );
krista@1797
  1074
vb@214
  1075
vb@450
  1076
// get_crashdump_log() - get the last log messages out
vb@450
  1077
//
vb@450
  1078
//  parameters:
vb@450
  1079
//      session (in)            session handle
vb@450
  1080
//      maxlines (in)           maximum number of lines (0 for default)
vb@458
  1081
//      logdata (out)           logdata as string in double quoted CSV format
vb@463
  1082
//                              column1 is title
vb@463
  1083
//                              column2 is entity
vb@463
  1084
//                              column3 is description
vb@463
  1085
//                              column4 is comment
vb@462
  1086
//
vb@462
  1087
//  caveat:
vb@462
  1088
//      the ownership of logdata goes to the caller
vb@450
  1089
vb@450
  1090
DYNAMIC_API PEP_STATUS get_crashdump_log(
vb@450
  1091
        PEP_SESSION session,
vb@450
  1092
        int maxlines,
vb@450
  1093
        char **logdata
vb@450
  1094
    );
vb@450
  1095
vb@450
  1096
dirk@501
  1097
// get_languagelist() - get the list of languages
vb@458
  1098
//
vb@458
  1099
//  parameters:
vb@458
  1100
//      session (in)            session handle
vb@458
  1101
//      languages (out)         languages as string in double quoted CSV format
vb@463
  1102
//                              column 1 is the ISO 639-1 language code
vb@463
  1103
//                              column 2 is the name of the language
vb@462
  1104
//
vb@462
  1105
//  caveat:
vb@462
  1106
//      the ownership of languages goes to the caller
vb@458
  1107
vb@458
  1108
DYNAMIC_API PEP_STATUS get_languagelist(
vb@458
  1109
        PEP_SESSION session,
vb@458
  1110
        char **languages
vb@458
  1111
    );
vb@458
  1112
vb@458
  1113
vb@458
  1114
// get_phrase() - get phrase in a dedicated language through i18n
vb@458
  1115
//
vb@458
  1116
//  parameters:
vb@458
  1117
//      session (in)            session handle
roker@529
  1118
//      lang (in)               C string with ISO 639-1 language code
vb@458
  1119
//      phrase_id (in)          id of phrase in i18n
vb@458
  1120
//      phrase (out)            phrase as UTF-8 string
vb@462
  1121
//
vb@462
  1122
//  caveat:
vb@462
  1123
//      the ownership of phrase goes to the caller
vb@458
  1124
vb@458
  1125
DYNAMIC_API PEP_STATUS get_phrase(
vb@458
  1126
        PEP_SESSION session,
vb@458
  1127
        const char *lang,
vb@458
  1128
        int phrase_id,
vb@458
  1129
        char **phrase
vb@458
  1130
    );
vb@458
  1131
vb@458
  1132
vb@632
  1133
// sequence_value() - raise the value of a named sequence and retrieve it
vb@632
  1134
//
vb@632
  1135
//  parameters:
vb@632
  1136
//      session (in)            session handle
vb@1085
  1137
//      name (inout)            name of sequence or char[37] set to {0, }
vb@1086
  1138
//                              for new own sequence named as UUID
vb@1085
  1139
//      value (inout)           value of sequence value to test or 0 for
vb@1085
  1140
//                              getting next value
vb@1085
  1141
//
vb@1085
  1142
//  returns:
vb@1086
  1143
//      PEP_STATUS_OK                   no error, not own sequence
vb@1086
  1144
//      PEP_SEQUENCE_VIOLATED           if sequence violated
vb@1086
  1145
//      PEP_CANNOT_INCREASE_SEQUENCE    if sequence cannot be increased
vb@1086
  1146
//      PEP_OWN_SEQUENCE                if own sequence
vb@632
  1147
vb@632
  1148
DYNAMIC_API PEP_STATUS sequence_value(
vb@632
  1149
        PEP_SESSION session,
vb@1085
  1150
        char *name,
vb@652
  1151
        int32_t *value
vb@632
  1152
    );
vb@632
  1153
vb@1044
  1154
Edouard@694
  1155
// set_revoked() - records relation between a revoked key and its replacement
Edouard@694
  1156
//
Edouard@694
  1157
//  parameters:
Edouard@694
  1158
//      session (in)            session handle
Edouard@694
  1159
//      revoked_fpr (in)        revoked fingerprint
Edouard@694
  1160
//      replacement_fpr (in)    replacement key fingerprint
Edouard@694
  1161
//      revocation_date (in)    revocation date
Edouard@694
  1162
Edouard@693
  1163
DYNAMIC_API PEP_STATUS set_revoked(
Edouard@693
  1164
       PEP_SESSION session,
Edouard@693
  1165
       const char *revoked_fpr,
Edouard@693
  1166
       const char *replacement_fpr,
Edouard@693
  1167
       const uint64_t revocation_date
Edouard@693
  1168
    );
Edouard@693
  1169
vb@958
  1170
Edouard@694
  1171
// get_revoked() - find revoked key that may have been replaced by given key, if any
Edouard@694
  1172
//
Edouard@694
  1173
//  parameters:
Edouard@694
  1174
//      session (in)            session handle
Edouard@694
  1175
//      fpr (in)                given fingerprint
Edouard@694
  1176
//      revoked_fpr (out)       revoked fingerprint
Edouard@694
  1177
//      revocation_date (out)   revocation date
Edouard@694
  1178
    
Edouard@693
  1179
DYNAMIC_API PEP_STATUS get_revoked(
Edouard@693
  1180
        PEP_SESSION session,
Edouard@693
  1181
        const char *fpr,
Edouard@693
  1182
        char **revoked_fpr,
Edouard@693
  1183
        uint64_t *revocation_date
Edouard@693
  1184
    );
Edouard@693
  1185
vb@632
  1186
vb@958
  1187
// key_created() - get creation date of a key
vb@958
  1188
//
vb@958
  1189
//  parameters:
vb@958
  1190
//      session (in)            session handle
vb@958
  1191
//      fpr (in)                fingerprint of key
vb@958
  1192
//      created (out)           date of creation
vb@958
  1193
vb@958
  1194
PEP_STATUS key_created(
vb@958
  1195
        PEP_SESSION session,
vb@958
  1196
        const char *fpr,
vb@958
  1197
        time_t *created
vb@958
  1198
    );
vb@958
  1199
vb@958
  1200
krista@1377
  1201
// find_private_keys() - find keys in keyring
krista@1357
  1202
//
krista@1357
  1203
//  parameters:
krista@1357
  1204
//      session (in)            session handle
krista@1357
  1205
//      pattern (in)            key id, user id or address to search for as
krista@1357
  1206
//                              UTF-8 string
krista@1357
  1207
//      keylist (out)           list of fingerprints found or NULL on error
krista@1357
  1208
//
krista@1357
  1209
//  caveat:
krista@1357
  1210
//        the ownerships of keylist isgoing to the caller
krista@1357
  1211
//        the caller must use free_stringlist() to free it
krista@1357
  1212
PEP_STATUS find_private_keys(PEP_SESSION session, const char* pattern,
krista@1357
  1213
                             stringlist_t **keylist);
krista@1357
  1214
krista@1011
  1215
// get_engine_version() - returns the current version of pEpEngine (this is different
krista@1011
  1216
//                        from the pEp protocol version!)
krista@1011
  1217
//
krista@1011
  1218
//  parameters: none
krista@1011
  1219
//
krista@1011
  1220
//  return_value: const char* to the engine version string constant
krista@1011
  1221
//
krista@1011
  1222
DYNAMIC_API const char* get_engine_version();
krista@1011
  1223
krista@2490
  1224
// is_pep_user() - returns true if the USER corresponding to this identity 
krista@2490
  1225
//                 has been listed in the *person* table as a pEp user. 
krista@2490
  1226
//
krista@2490
  1227
//  parameters:
krista@2490
  1228
//      identity (in) - identity containing the user_id to check (this is
krista@2490
  1229
//                      the only part of the struct we require to be set)
krista@2490
  1230
//      is_pep (out)  - boolean pointer - will return true or false by
krista@2490
  1231
//                      reference with respect to whether or not user is
krista@2490
  1232
//                      a known pep user
krista@2490
  1233
//
krista@2490
  1234
//  return_value: PEP_STATUS_OK if user found in person table
krista@2490
  1235
//                PEP_ILLEGAL_VALUE if no user_id in input
krista@2490
  1236
//                PEP_CANNOT_FIND_PERSON if user_id doesn't exist
krista@2490
  1237
//
krista@2490
  1238
//  caveat: This *does not check comm_type*
krista@2490
  1239
//                         
krista@2490
  1240
DYNAMIC_API PEP_STATUS is_pep_user(PEP_SESSION session, 
krista@2490
  1241
                                   pEp_identity *identity, 
krista@2490
  1242
                                   bool* is_pep);
krista@2490
  1243
krista@2490
  1244
krista@1307
  1245
vb@482
  1246
DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session);
vb@482
  1247
krista@2461
  1248
// This is used internally when there is a temporary identity to be retrieved
krista@2461
  1249
// that may not yet have an FPR attached. See get_identity() for functionality,
krista@2461
  1250
// params and caveats.
krista@2461
  1251
PEP_STATUS get_identity_without_trust_check(
krista@2461
  1252
        PEP_SESSION session,
krista@2461
  1253
        const char *address,
krista@2461
  1254
        const char *user_id,
krista@2461
  1255
        pEp_identity **identity
krista@2461
  1256
    );
krista@2461
  1257
    
krista@2461
  1258
PEP_STATUS get_identities_by_address(
krista@2461
  1259
        PEP_SESSION session,
krista@2461
  1260
        const char *address,
krista@2461
  1261
        identity_list** id_list
krista@2461
  1262
    );
krista@2461
  1263
        
krista@2461
  1264
PEP_STATUS replace_userid(PEP_SESSION session, const char* old_uid,
krista@2461
  1265
                              const char* new_uid);
krista@2461
  1266
                              
krista@2461
  1267
PEP_STATUS remove_fpr_as_default(PEP_SESSION session, 
krista@2461
  1268
                                    const char* fpr);
krista@2461
  1269
                              
krista@2461
  1270
                                    
krista@2461
  1271
PEP_STATUS get_main_user_fpr(PEP_SESSION session, 
krista@2461
  1272
                             const char* user_id,
krista@2461
  1273
                             char** main_fpr);
krista@2461
  1274
krista@2461
  1275
PEP_STATUS replace_main_user_fpr(PEP_SESSION session, const char* user_id,
krista@2461
  1276
                              const char* new_fpr);
krista@2461
  1277
    
krista@2461
  1278
PEP_STATUS refresh_userid_default_key(PEP_SESSION session, const char* user_id);
krista@2461
  1279
krista@2468
  1280
// This ONLY sets the *user* flag, and creates a shell identity if necessary.
krista@2468
  1281
PEP_STATUS set_as_pep_user(PEP_SESSION session, pEp_identity* user);
krista@2468
  1282
krista@2480
  1283
// returns true (by reference) if a person with this user_id exists; 
krista@2480
  1284
// Also replaces aliased user_ids by defaults in identity.
krista@2480
  1285
PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity, bool* exists);
krista@2468
  1286
krista@2477
  1287
PEP_STATUS set_pgp_keypair(PEP_SESSION session, const char* fpr);
krista@2468
  1288
krista@2995
  1289
// exposed for testing
krista@2995
  1290
PEP_STATUS set_person(PEP_SESSION session, pEp_identity* identity,
krista@2995
  1291
                      bool guard_transaction);
krista@2995
  1292
vb@0
  1293
#ifdef __cplusplus
vb@0
  1294
}
vb@0
  1295
#endif