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