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