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