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