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