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