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