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