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