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