src/message_api.h
author Krista Grothoff <krista@pep-project.org>
Wed, 15 Mar 2017 11:02:01 +0100
branchfdik_sync
changeset 1671 78b34f2843d1
parent 1644 6b88877f8885
child 1672 d4820ecaf7a2
permissions -rw-r--r--
function stubs
vb@1513
     1
// This file is under GNU General Public License 3.0
vb@1513
     2
// see LICENSE.txt
vb@1513
     3
vb@39
     4
#pragma once
vb@39
     5
vb@102
     6
#include "pEpEngine.h"
vb@102
     7
#include "keymanagement.h"
vb@101
     8
#include "message.h"
vb@259
     9
#include "cryptotech.h"
vb@101
    10
vb@37
    11
#ifdef __cplusplus
vb@37
    12
extern "C" {
vb@37
    13
#endif
vb@37
    14
vb@39
    15
Edouard@734
    16
bool import_attached_keys(
Edouard@728
    17
        PEP_SESSION session, 
Edouard@728
    18
        const message *msg,
Edouard@728
    19
        identity_list **private_idents
Edouard@728
    20
    );
vb@236
    21
void attach_own_key(PEP_SESSION session, message *msg);
krista@1671
    22
PEP_STATUS sign_message(PEP_SESSION session,
krista@1671
    23
                        message *src,
krista@1671
    24
                        message **dst);
krista@1671
    25
krista@1671
    26
PEP_STATUS check_signed_message(PEP_SESSION session,
krista@1671
    27
                                message *src,
krista@1671
    28
                                char* signing_key);
krista@1671
    29
vb@258
    30
PEP_cryptotech determine_encryption_format(message *msg);
vb@952
    31
void add_opt_field(message *msg, const char *name, const char *value);
Edouard@736
    32
vb@939
    33
typedef enum _PEP_encrypt_flags {
krista@1639
    34
    // "default" means whatever the default behaviour for the function is.
krista@1639
    35
    PEP_encrypt_flag_default = 0x0,
markus@1633
    36
    PEP_encrypt_flag_force_encryption = 0x1,
markus@1633
    37
markus@1633
    38
    // This flag is for special use cases and should not be used
markus@1633
    39
    // by normal pEp clients!
krista@1640
    40
    PEP_encrypt_flag_force_unsigned = 0x2,
krista@1640
    41
    PEP_encrypt_flag_force_no_attached_key = 0x4
vb@939
    42
} PEP_encrypt_flags; 
vb@939
    43
vb@939
    44
typedef unsigned int PEP_encrypt_flags_t;
vb@235
    45
vb@39
    46
// encrypt_message() - encrypt message in memory
vb@39
    47
//
vb@39
    48
//  parameters:
vb@48
    49
//      session (in)        session handle
vb@48
    50
//      src (in)            message to encrypt
vb@48
    51
//      extra (in)          extra keys for encryption
vb@83
    52
//      dst (out)           pointer to new encrypted message or NULL on failure
vb@84
    53
//      enc_format (in)     encrypted format
vb@939
    54
//      flags (in)          flags to set special encryption features
vb@39
    55
//
vb@39
    56
//  return value:
vb@48
    57
//      PEP_STATUS_OK                   on success
vb@48
    58
//		PEP_KEY_NOT_FOUND	            at least one of the receipient keys
vb@48
    59
//		                                could not be found
vb@48
    60
//		PEP_KEY_HAS_AMBIG_NAME          at least one of the receipient keys has
vb@48
    61
//		                                an ambiguous name
vb@48
    62
//		PEP_GET_KEY_FAILED		        cannot retrieve key
vb@83
    63
//
vb@83
    64
//	caveat:
vb@251
    65
//	    the ownershop of src remains with the caller
vb@251
    66
//	    the ownership of dst goes to the caller
vb@38
    67
vb@44
    68
DYNAMIC_API PEP_STATUS encrypt_message(
vb@37
    69
        PEP_SESSION session,
vb@113
    70
        message *src,
vb@37
    71
        stringlist_t *extra,
vb@38
    72
        message **dst,
vb@939
    73
        PEP_enc_format enc_format,
vb@939
    74
        PEP_encrypt_flags_t flags
vb@37
    75
    );
vb@37
    76
krista@1034
    77
// encrypt_message_for_self() - encrypt message in memory for user's identity only,
krista@1034
    78
//                              ignoring recipients and other identities from
krista@1034
    79
//                              the message
krista@994
    80
//  parameters:
krista@994
    81
//      session (in)        session handle
krista@995
    82
//      target_id (in)      self identity this message should be encrypted for
krista@994
    83
//      src (in)            message to encrypt
krista@994
    84
//      dst (out)           pointer to new encrypted message or NULL on failure
krista@994
    85
//      enc_format (in)     encrypted format
markus@1634
    86
//      flags (in)          flags to set special encryption features
krista@994
    87
//
krista@994
    88
//  return value:       (FIXME: This may not be correct or complete)
krista@994
    89
//      PEP_STATUS_OK                   on success
krista@994
    90
//		PEP_KEY_NOT_FOUND	            at least one of the receipient keys
krista@994
    91
//		                                could not be found
krista@994
    92
//		PEP_KEY_HAS_AMBIG_NAME          at least one of the receipient keys has
krista@994
    93
//		                                an ambiguous name
krista@994
    94
//		PEP_GET_KEY_FAILED		        cannot retrieve key
krista@994
    95
//
krista@994
    96
//	caveat:
krista@994
    97
//	    the ownership of src remains with the caller
krista@994
    98
//      the ownership of target_id remains w/ caller            
krista@994
    99
//	    the ownership of dst goes to the caller
krista@995
   100
//      message is NOT encrypted for identities other than the target_id (and then,
krista@995
   101
//          only if the target_id refers to self!)
krista@994
   102
krista@995
   103
DYNAMIC_API PEP_STATUS encrypt_message_for_self(
krista@994
   104
        PEP_SESSION session,
krista@994
   105
        pEp_identity* target_id,
krista@994
   106
        message *src,
krista@994
   107
        message **dst,
markus@1633
   108
        PEP_enc_format enc_format,
markus@1633
   109
        PEP_encrypt_flags_t flags
krista@994
   110
    );
vb@39
   111
krista@1325
   112
// MIME_encrypt_message() - encrypt a MIME message, with MIME output
krista@1325
   113
//
krista@1325
   114
//  parameters:
krista@1325
   115
//      session (in)            session handle
krista@1325
   116
//      mimetext (in)           MIME encoded text to encrypt
krista@1331
   117
//      size (in)               size of input mime text
krista@1325
   118
//      extra (in)              extra keys for encryption
krista@1325
   119
//      mime_ciphertext (out)   encrypted, encoded message
krista@1325
   120
//      enc_format (in)         encrypted format
krista@1325
   121
//      flags (in)              flags to set special encryption features
krista@1325
   122
//
krista@1325
   123
//  return value:
krista@1325
   124
//      PEP_STATUS_OK           if everything worked
krista@1325
   125
//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
krista@1325
   126
//      PEP_CANNOT_CREATE_TEMP_FILE
krista@1325
   127
//                              if there are issues with temp files; in
krista@1325
   128
//                              this case errno will contain the underlying
krista@1325
   129
//                              error
krista@1325
   130
//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
krista@1325
   131
//
krista@1325
   132
//  caveat:
krista@1325
   133
//      the encrypted, encoded mime text will go to the ownership of the caller; mimetext
krista@1325
   134
//      will remain in the ownership of the caller
krista@1325
   135
krista@1325
   136
DYNAMIC_API PEP_STATUS MIME_encrypt_message(
krista@1325
   137
    PEP_SESSION session,
krista@1325
   138
    const char *mimetext,
krista@1325
   139
    size_t size,
krista@1325
   140
    stringlist_t* extra,
krista@1325
   141
    char** mime_ciphertext,
krista@1325
   142
    PEP_enc_format enc_format,
krista@1325
   143
    PEP_encrypt_flags_t flags
krista@1325
   144
);
krista@1325
   145
krista@1641
   146
// MIME_encrypt_message_for_self() - encrypt MIME message for user's identity only,
krista@1641
   147
//                              ignoring recipients and other identities from
krista@1641
   148
//                              the message, with MIME output
krista@1641
   149
//  parameters:
krista@1641
   150
//      session (in)            session handle
krista@1644
   151
//      target_id (in)      self identity this message should be encrypted for
krista@1641
   152
//      mimetext (in)           MIME encoded text to encrypt
krista@1641
   153
//      size (in)               size of input mime text
krista@1641
   154
//      mime_ciphertext (out)   encrypted, encoded message
krista@1641
   155
//      enc_format (in)         encrypted format
krista@1641
   156
//      flags (in)              flags to set special encryption features
krista@1641
   157
//
krista@1641
   158
//  return value:
krista@1641
   159
//      PEP_STATUS_OK           if everything worked
krista@1641
   160
//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
krista@1641
   161
//      PEP_CANNOT_CREATE_TEMP_FILE
krista@1641
   162
//                              if there are issues with temp files; in
krista@1641
   163
//                              this case errno will contain the underlying
krista@1641
   164
//                              error
krista@1641
   165
//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
krista@1641
   166
//
krista@1641
   167
//  caveat:
krista@1641
   168
//      the encrypted, encoded mime text will go to the ownership of the caller; mimetext
krista@1641
   169
//      will remain in the ownership of the caller
krista@1641
   170
krista@1641
   171
DYNAMIC_API PEP_STATUS MIME_encrypt_message_for_self(
krista@1641
   172
    PEP_SESSION session,
krista@1641
   173
    pEp_identity* target_id,
krista@1641
   174
    const char *mimetext,
krista@1641
   175
    size_t size,
krista@1641
   176
    char** mime_ciphertext,
krista@1641
   177
    PEP_enc_format enc_format,
krista@1641
   178
    PEP_encrypt_flags_t flags
krista@1641
   179
);
krista@1641
   180
krista@1641
   181
krista@1641
   182
vb@1004
   183
typedef enum _PEP_rating {
vb@237
   184
    PEP_rating_undefined = 0,
vb@256
   185
    PEP_rating_cannot_decrypt,
vb@267
   186
    PEP_rating_have_no_key,
vb@237
   187
    PEP_rating_unencrypted,
vb@486
   188
    PEP_rating_unencrypted_for_some,
vb@237
   189
    PEP_rating_unreliable,
vb@237
   190
    PEP_rating_reliable,
vb@237
   191
    PEP_rating_trusted,
vb@237
   192
    PEP_rating_trusted_and_anonymized,
vb@237
   193
    PEP_rating_fully_anonymous,   
vb@189
   194
Edouard@442
   195
    PEP_rating_mistrust = -1,
Edouard@442
   196
    PEP_rating_b0rken = -2,
vb@436
   197
    PEP_rating_under_attack = -3
vb@1004
   198
} PEP_rating;
vb@1004
   199
vb@1004
   200
typedef enum _PEP_color {
vb@1004
   201
    PEP_color_no_color = 0,
vb@1004
   202
    PEP_color_yellow,
vb@1004
   203
    PEP_color_green,
vb@1004
   204
    PEP_color_red = -1,
vb@232
   205
} PEP_color;
vb@189
   206
vb@1007
   207
// color_from_rating - calculate color from rating
vb@1007
   208
//
vb@1007
   209
//  parameters:
vb@1007
   210
//      rating (in)         rating
vb@1007
   211
//
vb@1007
   212
//  return value:           color representing that rating
vb@1007
   213
vb@1004
   214
DYNAMIC_API PEP_color color_from_rating(PEP_rating rating);
vb@1004
   215
Edouard@728
   216
typedef enum _PEP_decrypt_flags {
edouard@1355
   217
    PEP_decrypt_flag_own_private_key = 0x1,
edouard@1369
   218
    PEP_decrypt_flag_consume = 0x2,
edouard@1369
   219
    PEP_decrypt_flag_ignore = 0x4
Edouard@728
   220
} PEP_decrypt_flags; 
Edouard@728
   221
vb@939
   222
typedef unsigned int PEP_decrypt_flags_t;
Edouard@728
   223
vb@251
   224
// decrypt_message() - decrypt message in memory
vb@251
   225
//
vb@251
   226
//  parameters:
vb@251
   227
//      session (in)        session handle
vb@251
   228
//      src (in)            message to decrypt
vb@251
   229
//      dst (out)           pointer to new decrypted message or NULL on failure
vb@251
   230
//      keylist (out)       stringlist with keyids
roker@1218
   231
//      rating (out)        rating for the message
vb@939
   232
//      flags (out)         flags to signal special decryption features
vb@251
   233
//
vb@251
   234
//  return value:
vb@251
   235
//      error status or PEP_STATUS_OK on success
vb@251
   236
//
vb@251
   237
//	caveat:
vb@251
   238
//	    the ownership of src remains with the caller
vb@251
   239
//	    the ownership of dst goes to the caller
vb@251
   240
//	    the ownership of keylist goes to the caller
vb@330
   241
//	    if src is unencrypted this function returns PEP_UNENCRYPTED and sets
vb@330
   242
//	    dst to NULL
vb@251
   243
vb@251
   244
DYNAMIC_API PEP_STATUS decrypt_message(
vb@251
   245
        PEP_SESSION session,
vb@251
   246
        message *src,
vb@251
   247
        message **dst,
vb@251
   248
        stringlist_t **keylist,
vb@1004
   249
        PEP_rating *rating,
vb@939
   250
        PEP_decrypt_flags_t *flags
Edouard@728
   251
);
vb@251
   252
krista@1325
   253
// MIME_decrypt_message() - decrypt a MIME message, with MIME output
krista@1325
   254
//
krista@1325
   255
//  parameters:
krista@1325
   256
//      session (in)            session handle
krista@1325
   257
//      mimetext (in)           MIME encoded text to decrypt
krista@1331
   258
//      size (in)               size of mime text to decode (in order to decrypt)
krista@1325
   259
//      mime_plaintext (out)    decrypted, encoded message
krista@1325
   260
//      keylist (out)           stringlist with keyids
krista@1325
   261
//      rating (out)            rating for the message
krista@1325
   262
//      flags (out)             flags to signal special decryption features
krista@1325
   263
//
krista@1325
   264
//  return value:
krista@1644
   265
//      decrypt status          if everything worked with MIME encode/decode, 
krista@1644
   266
//                              the status of the decryption is returned 
krista@1644
   267
//                              (PEP_STATUS_OK or decryption error status)
krista@1325
   268
//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
krista@1325
   269
//      PEP_CANNOT_CREATE_TEMP_FILE
krista@1325
   270
//                              if there are issues with temp files; in
krista@1325
   271
//                              this case errno will contain the underlying
krista@1325
   272
//                              error
krista@1325
   273
//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
krista@1325
   274
//
krista@1325
   275
//  caveat:
krista@1325
   276
//      the decrypted, encoded mime text will go to the ownership of the caller; mimetext
krista@1325
   277
//      will remain in the ownership of the caller
krista@1325
   278
krista@1325
   279
DYNAMIC_API PEP_STATUS MIME_decrypt_message(
krista@1325
   280
    PEP_SESSION session,
krista@1325
   281
    const char *mimetext,
krista@1325
   282
    size_t size,
krista@1325
   283
    char** mime_plaintext,
krista@1325
   284
    stringlist_t **keylist,
krista@1325
   285
    PEP_rating *rating,
krista@1325
   286
    PEP_decrypt_flags_t *flags
krista@1325
   287
);
krista@1325
   288
krista@1325
   289
Edouard@728
   290
// own_message_private_key_details() - details on own key in own message
Edouard@728
   291
//
Edouard@728
   292
//  parameters:
Edouard@728
   293
//      session (in)        session handle
Edouard@728
   294
//      msg (in)            message to decrypt
Edouard@728
   295
//      ident (out)         identity containing uid, address and fpr of key
Edouard@728
   296
//
Edouard@728
   297
//  note:
Edouard@728
   298
//      In order to obtain details about key to be possibly imported
Edouard@728
   299
//      as a replacement of key currently used as own identity, 
Edouard@728
   300
//      application passes message that have been previously flagged by 
Edouard@728
   301
//      decrypt_message() as own message containing own key to this function
Edouard@728
   302
//
Edouard@728
   303
//  return value:
Edouard@728
   304
//      error status or PEP_STATUS_OK on success
Edouard@728
   305
//
Edouard@728
   306
//	caveat:
Edouard@728
   307
//	    the ownership of msg remains with the caller
Edouard@728
   308
//	    the ownership of ident goes to the caller
Edouard@728
   309
//	    msg MUST be encrypted so that this function can check own signature
Edouard@728
   310
Edouard@728
   311
DYNAMIC_API PEP_STATUS own_message_private_key_details(
Edouard@728
   312
        PEP_SESSION session,
Edouard@728
   313
        message *msg,
Edouard@728
   314
        pEp_identity **ident 
Edouard@728
   315
);
vb@251
   316
vb@1009
   317
// outgoing_message_rating() - get rating for an outgoing message
vb@189
   318
//
vb@189
   319
//  parameters:
vb@189
   320
//      session (in)        session handle
vb@1009
   321
//      msg (in)            message to get the rating for
vb@1009
   322
//      rating (out)        rating for the message
vb@189
   323
//
vb@189
   324
//  return value:
vb@189
   325
//      error status or PEP_STATUS_OK on success
vb@190
   326
//
vb@190
   327
//  caveat:
vb@190
   328
//      msg->from must point to a valid pEp_identity
vb@251
   329
//      msg->dir must be PEP_dir_outgoing
vb@251
   330
//      the ownership of msg remains with the caller
vb@189
   331
vb@1009
   332
DYNAMIC_API PEP_STATUS outgoing_message_rating(
vb@189
   333
        PEP_SESSION session,
vb@190
   334
        message *msg,
vb@1004
   335
        PEP_rating *rating
vb@189
   336
    );
vb@189
   337
vb@239
   338
vb@1009
   339
// identity_rating() - get rating for a single identity
vb@239
   340
//
vb@239
   341
//  parameters:
vb@239
   342
//      session (in)        session handle
vb@1009
   343
//      ident (in)          identity to get the rating for
vb@1009
   344
//      rating (out)        rating for the identity
vb@239
   345
//
vb@239
   346
//  return value:
vb@239
   347
//      error status or PEP_STATUS_OK on success
vb@251
   348
//
vb@251
   349
//  caveat:
vb@251
   350
//      the ownership of ident remains with the caller
vb@239
   351
vb@1009
   352
DYNAMIC_API PEP_STATUS identity_rating(
vb@239
   353
        PEP_SESSION session,
vb@239
   354
        pEp_identity *ident,
vb@1004
   355
        PEP_rating *rating
vb@239
   356
    );
vb@239
   357
vb@239
   358
vb@507
   359
// get_binary_path() - retrieve path of cryptotech binary if available
vb@507
   360
//
vb@507
   361
//  parameters:
vb@507
   362
//      tech (in)           cryptotech to get the binary for
vb@507
   363
//      path (out)          path to cryptotech binary or NULL if not available
roker@540
   364
//                          **path is owned by the library, do not change it!
vb@507
   365
DYNAMIC_API PEP_STATUS get_binary_path(PEP_cryptotech tech, const char **path);
vb@507
   366
krista@1307
   367
// get_trustwords() - get full trustwords string for a *pair* of identities
krista@1307
   368
//
krista@1307
   369
//    parameters:
krista@1307
   370
//        session (in)        session handle
krista@1307
   371
//        id1 (in)            identity of first party in communication - fpr can't be NULL  
krista@1307
   372
//        id2 (in)            identity of second party in communication - fpr can't be NULL
krista@1307
   373
//        lang (in)           C string with ISO 639-1 language code
krista@1307
   374
//        words (out)         pointer to C string with all trustwords UTF-8 encoded,
krista@1307
   375
//                            separated by a blank each
krista@1307
   376
//                            NULL if language is not supported or trustword
krista@1307
   377
//                            wordlist is damaged or unavailable
krista@1307
   378
//        wsize (out)         length of full trustwords string
krista@1307
   379
//        full (in)           if true, generate ALL trustwords for these identities.
krista@1307
   380
//                            else, generate a fixed-size subset. (TODO: fixed-minimum-entropy
krista@1307
   381
//                            subset in next version)
krista@1307
   382
//
krista@1307
   383
//    return value:
krista@1307
   384
//        PEP_STATUS_OK            trustwords retrieved
krista@1307
   385
//        PEP_OUT_OF_MEMORY        out of memory
krista@1307
   386
//        PEP_TRUSTWORD_NOT_FOUND  at least one trustword not found
krista@1307
   387
//
krista@1307
   388
//    caveat:
krista@1307
   389
//        the word pointer goes to the ownership of the caller
krista@1307
   390
//        the caller is responsible to free() it (on Windoze use pEp_free())
krista@1307
   391
//
krista@1307
   392
krista@1307
   393
DYNAMIC_API PEP_STATUS get_trustwords(
roker@1509
   394
    PEP_SESSION session, const pEp_identity* id1, const pEp_identity* id2,
krista@1307
   395
    const char* lang, char **words, size_t *wsize, bool full
krista@1307
   396
);
vb@507
   397
edouard@1553
   398
// get_message_trustwords() - get full trustwords string for message sender and reciever identities 
edouard@1553
   399
//
edouard@1553
   400
//    parameters:
edouard@1553
   401
//        session (in)        session handle
edouard@1553
   402
//        msg (in)            message to get sender identity from
edouard@1553
   403
//        keylist (in)        NULL if message to be decrypted,
edouard@1553
   404
//                            keylist returned by decrypt_message() otherwise
edouard@1553
   405
//        received_by (in)    identity for account receiving message can't be NULL
edouard@1553
   406
//        lang (in)           C string with ISO 639-1 language code
edouard@1553
   407
//        words (out)         pointer to C string with all trustwords UTF-8 encoded,
edouard@1553
   408
//                            separated by a blank each
edouard@1553
   409
//                            NULL if language is not supported or trustword
edouard@1553
   410
//                            wordlist is damaged or unavailable
edouard@1553
   411
//        full (in)           if true, generate ALL trustwords for these identities.
edouard@1553
   412
//                            else, generate a fixed-size subset. (TODO: fixed-minimum-entropy
edouard@1553
   413
//                            subset in next version)
edouard@1553
   414
//
edouard@1553
   415
//    return value:
edouard@1553
   416
//        PEP_STATUS_OK            trustwords retrieved
edouard@1553
   417
//        PEP_OUT_OF_MEMORY        out of memory
edouard@1553
   418
//        PEP_TRUSTWORD_NOT_FOUND  at least one trustword not found
edouard@1553
   419
//        error status of decrypt_message() if decryption fails.
edouard@1553
   420
//
edouard@1553
   421
//    caveat:
edouard@1553
   422
//        the word pointer goes to the ownership of the caller
edouard@1553
   423
//        the caller is responsible to free() it (on Windoze use pEp_free())
edouard@1553
   424
//
edouard@1553
   425
DYNAMIC_API PEP_STATUS get_message_trustwords(
edouard@1553
   426
    PEP_SESSION session, 
edouard@1553
   427
    message *msg,
edouard@1553
   428
    stringlist_t *keylist,
edouard@1553
   429
    pEp_identity* received_by,
edouard@1553
   430
    const char* lang, char **words, bool full
edouard@1553
   431
);
edouard@1553
   432
vb@37
   433
#ifdef __cplusplus
vb@37
   434
}
vb@37
   435
#endif