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