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