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