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