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