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