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