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