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