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