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