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