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