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