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