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