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