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