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