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