Removed all MIME_encrypt/decrypt functions from tests and aux_mime_msg.* from the source. App builds may need to adjust!
parent
747cb3b0a2
commit
da99a8dd14
@ -1,286 +0,0 @@
|
||||
/** @file */
|
||||
/** @brief File description for doxygen missing. FIXME */
|
||||
|
||||
// This file is under GNU General Public License 3.0
|
||||
// see LICENSE.txt
|
||||
|
||||
#ifdef ENIGMAIL_MAY_USE_THIS
|
||||
|
||||
#include "pEp_internal.h"
|
||||
#include "message_api.h"
|
||||
#include "mime.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "aux_mime_msg.h"
|
||||
|
||||
|
||||
static PEP_STATUS update_identity_recip_list(PEP_SESSION session,
|
||||
identity_list* list) {
|
||||
|
||||
PEP_STATUS status = PEP_STATUS_OK;
|
||||
|
||||
if (!session)
|
||||
return PEP_UNKNOWN_ERROR;
|
||||
|
||||
identity_list* id_list_ptr = NULL;
|
||||
|
||||
for (id_list_ptr = list; id_list_ptr; id_list_ptr = id_list_ptr->next) {
|
||||
pEp_identity* curr_identity = id_list_ptr->ident;
|
||||
if (curr_identity) {
|
||||
if (!is_me(session, curr_identity)) {
|
||||
char* name_bak = curr_identity->username;
|
||||
curr_identity->username = NULL;
|
||||
status = update_identity(session, curr_identity);
|
||||
if (name_bak &&
|
||||
(EMPTYSTR(curr_identity->username) || strcmp(name_bak, curr_identity->username) != 0)) {
|
||||
free(curr_identity->username);
|
||||
curr_identity->username = name_bak;
|
||||
}
|
||||
}
|
||||
else
|
||||
status = _myself(session, curr_identity, false, false, false, true);
|
||||
if (status == PEP_ILLEGAL_VALUE || status == PEP_OUT_OF_MEMORY)
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
return PEP_STATUS_OK;
|
||||
}
|
||||
|
||||
DYNAMIC_API PEP_STATUS MIME_decrypt_message(
|
||||
PEP_SESSION session,
|
||||
const char *mimetext,
|
||||
size_t size,
|
||||
char** mime_plaintext,
|
||||
stringlist_t **keylist,
|
||||
PEP_rating *rating,
|
||||
PEP_decrypt_flags_t *flags,
|
||||
char** modified_src
|
||||
)
|
||||
{
|
||||
assert(mimetext);
|
||||
assert(mime_plaintext);
|
||||
assert(keylist);
|
||||
assert(rating);
|
||||
assert(flags);
|
||||
assert(modified_src);
|
||||
|
||||
if (!(mimetext && mime_plaintext && keylist && rating && flags && modified_src))
|
||||
return PEP_ILLEGAL_VALUE;
|
||||
|
||||
PEP_STATUS status = PEP_STATUS_OK;
|
||||
message* tmp_msg = NULL;
|
||||
message* dec_msg = NULL;
|
||||
*mime_plaintext = NULL;
|
||||
|
||||
status = mime_decode_message(mimetext, size, &tmp_msg, NULL);
|
||||
if (status != PEP_STATUS_OK)
|
||||
goto pEp_error;
|
||||
|
||||
tmp_msg->dir = PEP_dir_incoming;
|
||||
// MIME decode message delivers only addresses. We need more.
|
||||
if (tmp_msg->from) {
|
||||
if (!is_me(session, tmp_msg->from))
|
||||
status = update_identity(session, (tmp_msg->from));
|
||||
else
|
||||
status = _myself(session, tmp_msg->from, false, true, false, true);
|
||||
|
||||
if (status == PEP_ILLEGAL_VALUE || status == PEP_OUT_OF_MEMORY || PASS_ERROR(status))
|
||||
goto pEp_error;
|
||||
}
|
||||
|
||||
status = update_identity_recip_list(session, tmp_msg->to);
|
||||
if (status != PEP_STATUS_OK)
|
||||
goto pEp_error;
|
||||
|
||||
status = update_identity_recip_list(session, tmp_msg->cc);
|
||||
if (status != PEP_STATUS_OK)
|
||||
goto pEp_error;
|
||||
|
||||
status = update_identity_recip_list(session, tmp_msg->bcc);
|
||||
if (status != PEP_STATUS_OK)
|
||||
goto pEp_error;
|
||||
|
||||
PEP_STATUS decrypt_status = decrypt_message(session,
|
||||
tmp_msg,
|
||||
&dec_msg,
|
||||
keylist,
|
||||
rating,
|
||||
flags);
|
||||
|
||||
|
||||
if (!dec_msg && (decrypt_status == PEP_UNENCRYPTED || decrypt_status == PEP_VERIFIED)) {
|
||||
dec_msg = message_dup(tmp_msg);
|
||||
}
|
||||
|
||||
if (decrypt_status > PEP_CANNOT_DECRYPT_UNKNOWN || !dec_msg)
|
||||
{
|
||||
status = decrypt_status;
|
||||
goto pEp_error;
|
||||
}
|
||||
|
||||
if (*flags & PEP_decrypt_flag_src_modified) {
|
||||
mime_encode_message(tmp_msg, false, modified_src, false);
|
||||
if (!modified_src) {
|
||||
*flags &= (~PEP_decrypt_flag_src_modified);
|
||||
decrypt_status = PEP_CANNOT_REENCRYPT; // Because we couldn't return it, I guess.
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: test with att
|
||||
status = mime_encode_message(dec_msg, false, mime_plaintext, false);
|
||||
|
||||
if (status == PEP_STATUS_OK)
|
||||
{
|
||||
free(tmp_msg);
|
||||
free(dec_msg);
|
||||
return decrypt_status;
|
||||
}
|
||||
|
||||
pEp_error:
|
||||
free_message(tmp_msg);
|
||||
free_message(dec_msg);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
DYNAMIC_API PEP_STATUS MIME_encrypt_message(
|
||||
PEP_SESSION session,
|
||||
const char *mimetext,
|
||||
size_t size,
|
||||
stringlist_t* extra,
|
||||
char** mime_ciphertext,
|
||||
PEP_enc_format enc_format,
|
||||
PEP_encrypt_flags_t flags
|
||||
)
|
||||
{
|
||||
PEP_STATUS status = PEP_STATUS_OK;
|
||||
PEP_STATUS tmp_status = PEP_STATUS_OK;
|
||||
message* tmp_msg = NULL;
|
||||
message* enc_msg = NULL;
|
||||
message* ret_msg = NULL;
|
||||
|
||||
status = mime_decode_message(mimetext, size, &tmp_msg, NULL);
|
||||
if (status != PEP_STATUS_OK)
|
||||
goto pEp_error;
|
||||
|
||||
// MIME decode message delivers only addresses. We need more.
|
||||
if (tmp_msg->from) {
|
||||
char* own_id = NULL;
|
||||
status = get_default_own_userid(session, &own_id);
|
||||
free(tmp_msg->from->user_id);
|
||||
|
||||
if (status != PEP_STATUS_OK || !own_id) {
|
||||
tmp_msg->from->user_id = strdup(PEP_OWN_USERID);
|
||||
}
|
||||
else {
|
||||
tmp_msg->from->user_id = own_id; // ownership transfer
|
||||
}
|
||||
|
||||
status = myself(session, tmp_msg->from);
|
||||
if (status != PEP_STATUS_OK)
|
||||
goto pEp_error;
|
||||
}
|
||||
|
||||
// Own identities can be retrieved here where they would otherwise
|
||||
// fail because we lack all other information. This is ok and even
|
||||
// desired. FIXME: IS it?
|
||||
status = update_identity_recip_list(session, tmp_msg->to);
|
||||
if (status != PEP_STATUS_OK)
|
||||
goto pEp_error;
|
||||
|
||||
status = update_identity_recip_list(session, tmp_msg->cc);
|
||||
if (status != PEP_STATUS_OK)
|
||||
goto pEp_error;
|
||||
|
||||
status = update_identity_recip_list(session, tmp_msg->bcc);
|
||||
if (status != PEP_STATUS_OK)
|
||||
goto pEp_error;
|
||||
|
||||
// This isn't incoming, though... so we need to reverse the direction
|
||||
tmp_msg->dir = PEP_dir_outgoing;
|
||||
status = encrypt_message(session,
|
||||
tmp_msg,
|
||||
extra,
|
||||
&enc_msg,
|
||||
enc_format,
|
||||
flags);
|
||||
|
||||
if (status == PEP_STATUS_OK || status == PEP_UNENCRYPTED)
|
||||
ret_msg = (status == PEP_STATUS_OK ? enc_msg : tmp_msg);
|
||||
else
|
||||
goto pEp_error;
|
||||
|
||||
if (status == PEP_STATUS_OK && !enc_msg) {
|
||||
status = PEP_UNKNOWN_ERROR;
|
||||
goto pEp_error;
|
||||
}
|
||||
|
||||
tmp_status = mime_encode_message(ret_msg,
|
||||
false,
|
||||
mime_ciphertext,
|
||||
false);
|
||||
|
||||
if (tmp_status != PEP_STATUS_OK)
|
||||
status = tmp_status;
|
||||
|
||||
pEp_error:
|
||||
free_message(tmp_msg);
|
||||
free_message(enc_msg);
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
DYNAMIC_API PEP_STATUS MIME_encrypt_message_for_self(
|
||||
PEP_SESSION session,
|
||||
pEp_identity* target_id,
|
||||
const char *mimetext,
|
||||
size_t size,
|
||||
stringlist_t* extra,
|
||||
char** mime_ciphertext,
|
||||
PEP_enc_format enc_format,
|
||||
PEP_encrypt_flags_t flags
|
||||
)
|
||||
{
|
||||
PEP_STATUS status = PEP_STATUS_OK;
|
||||
message* tmp_msg = NULL;
|
||||
message* enc_msg = NULL;
|
||||
|
||||
status = mime_decode_message(mimetext, size, &tmp_msg, NULL);
|
||||
if (status != PEP_STATUS_OK)
|
||||
goto pEp_error;
|
||||
|
||||
// This isn't incoming, though... so we need to reverse the direction
|
||||
tmp_msg->dir = PEP_dir_outgoing;
|
||||
status = encrypt_message_for_self(session,
|
||||
target_id,
|
||||
tmp_msg,
|
||||
extra,
|
||||
&enc_msg,
|
||||
enc_format,
|
||||
flags);
|
||||
if (status != PEP_STATUS_OK)
|
||||
goto pEp_error;
|
||||
|
||||
if (!enc_msg) {
|
||||
status = PEP_UNKNOWN_ERROR;
|
||||
goto pEp_error;
|
||||
}
|
||||
|
||||
status = mime_encode_message(enc_msg, false, mime_ciphertext, false);
|
||||
|
||||
pEp_error:
|
||||
free_message(tmp_msg);
|
||||
free_message(enc_msg);
|
||||
|
||||
return status;
|
||||
}
|
||||
#else
|
||||
// This is here to please ISO C - it needs a compilation unit. Value will never be used.
|
||||
const int the_answer_my_friend = 42;
|
||||
#endif
|
@ -1,187 +0,0 @@
|
||||
/**
|
||||
* @file aux_mime_msg.h
|
||||
*
|
||||
* @brief Auxiliary file which provides the MIME* functions for the enigmail/pEp implementation and some tests.
|
||||
* Provides access to pEp functions for messages fed in in MIME string format instead of
|
||||
* through the message struct.
|
||||
*
|
||||
* @deprecated These functions should no longer be used, and these files will be removed shortly.
|
||||
*
|
||||
* @warning No version of the engine which implements pEp sync should use these functions
|
||||
*
|
||||
* @license GNU General Public License 3.0 - see LICENSE.txt
|
||||
*/
|
||||
|
||||
#ifndef AUX_MIME_MSG_H
|
||||
#define AUX_MIME_MSG_H
|
||||
|
||||
#ifdef ENIGMAIL_MAY_USE_THIS
|
||||
|
||||
#include "pEpEngine.h"
|
||||
#include "keymanagement.h"
|
||||
#include "message.h"
|
||||
#include "cryptotech.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* <!-- MIME_encrypt_message() -->
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @brief Encrypt a MIME message, with MIME output
|
||||
*
|
||||
* @param[in] session session handle
|
||||
* @param[in] mimetext MIME encoded text to encrypt
|
||||
* @param[in] size size of input mime text
|
||||
* @param[in] extra extra keys for encryption
|
||||
* @param[out] mime_ciphertext encrypted, encoded message
|
||||
* @param[in] enc_format encrypted format
|
||||
* @param[in] flags flags to set special encryption features
|
||||
*
|
||||
* @retval PEP_STATUS_OK if everything worked
|
||||
* @retval PEP_BUFFER_TOO_SMALL if encoded message size is too big to handle
|
||||
* @retval PEP_CANNOT_CREATE_TEMP_FILE if there are issues with temp files; in
|
||||
* this case errno will contain the underlying
|
||||
* error
|
||||
* @retval PEP_OUT_OF_MEMORY if not enough memory could be allocated
|
||||
*
|
||||
* @ownership
|
||||
* - the encrypted, encoded mime text will go to the ownership of the caller
|
||||
* - the original mimetext will remain in the ownership of the caller
|
||||
*
|
||||
*/
|
||||
DYNAMIC_API PEP_STATUS MIME_encrypt_message(
|
||||
PEP_SESSION session,
|
||||
const char *mimetext,
|
||||
size_t size,
|
||||
stringlist_t* extra,
|
||||
char** mime_ciphertext,
|
||||
PEP_enc_format enc_format,
|
||||
PEP_encrypt_flags_t flags
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* <!-- MIME_encrypt_message_for_self() -->
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @brief Encrypt MIME message for user's identity only,
|
||||
* ignoring recipients and other identities from
|
||||
* the message, with MIME output
|
||||
*
|
||||
* @param[in] session session handle
|
||||
* @param[in] target_id self identity this message should be encrypted for
|
||||
* @param[in] mimetext MIME encoded text to encrypt
|
||||
* @param[in] size size of input mime text
|
||||
* @param[in] extra extra keys for encryption
|
||||
* @param[out] mime_ciphertext encrypted, encoded message
|
||||
* @param[in] enc_format encrypted format
|
||||
* @param[in] flags flags to set special encryption features
|
||||
*
|
||||
* @retval PEP_STATUS_OK if everything worked
|
||||
* @retval PEP_BUFFER_TOO_SMALL if encoded message size is too big to handle
|
||||
* @retval PEP_CANNOT_CREATE_TEMP_FILE if there are issues with temp files; in
|
||||
* this case errno will contain the underlying
|
||||
* error
|
||||
* @retval PEP_OUT_OF_MEMORY if not enough memory could be allocated
|
||||
*
|
||||
* @ownership
|
||||
* - the encrypted, encoded mime text will go to the ownership of the caller
|
||||
* - the original mimetext will remain in the ownership of the caller
|
||||
*
|
||||
*/
|
||||
DYNAMIC_API PEP_STATUS MIME_encrypt_message_for_self(
|
||||
PEP_SESSION session,
|
||||
pEp_identity* target_id,
|
||||
const char *mimetext,
|
||||
size_t size,
|
||||
stringlist_t* extra,
|
||||
char** mime_ciphertext,
|
||||
PEP_enc_format enc_format,
|
||||
PEP_encrypt_flags_t flags
|
||||
);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <!-- MIME_decrypt_message() -->
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @brief Decrypt a MIME message, with MIME output
|
||||
*
|
||||
* @param[in] session session handle
|
||||
* @param[in] mimetext MIME encoded text to decrypt
|
||||
* @param[in] size size of mime text to decode (in order to decrypt)
|
||||
* @param[out] mime_plaintext decrypted, encoded message
|
||||
* @param[in,out] keylist in: stringlist with additional keyids for reencryption if needed
|
||||
* (will be freed and replaced with output keylist)
|
||||
* out: stringlist with keyids
|
||||
* @param[out] rating rating for the message
|
||||
* @param[in,out] flags flags to signal special decryption features (see below)
|
||||
* @param[out] modified_src modified source string, if decrypt had reason to change it
|
||||
*
|
||||
* @retval decrypt status if everything worked with MIME encode/decode,
|
||||
* the status of the decryption is returned
|
||||
* (PEP_STATUS_OK or decryption error status)
|
||||
* @retval PEP_BUFFER_TOO_SMALL if encoded message size is too big to handle
|
||||
* @retval PEP_CANNOT_CREATE_TEMP_FILE if there are issues with temp files; in
|
||||
* this case errno will contain the underlying
|
||||
* error
|
||||
* @retval PEP_OUT_OF_MEMORY if not enough memory could be allocated
|
||||
*
|
||||
* @note Flags above are as follows:
|
||||
* @verbatim
|
||||
* ---------------------------------------------------------------------------------------------|
|
||||
* Incoming flags |
|
||||
* ---------------------------------------------------------------------------------------------|
|
||||
* Flag | Description |
|
||||
* --------------------------------------|------------------------------------------------------|
|
||||
* PEP_decrypt_flag_untrusted_server | used to signal that decrypt function should engage |
|
||||
* | in behaviour specified for when the server storing |
|
||||
* | the source is untrusted. |
|
||||
* ---------------------------------------------------------------------------------------------|
|
||||
* Outgoing flags |
|
||||
* ---------------------------------------------------------------------------------------------|
|
||||
* PEP_decrypt_flag_own_private_key | private key was imported for one of our addresses |
|
||||
* | (NOT trusted or set to be used - handshake/trust is |
|
||||
* | required for that) |
|
||||
* | |
|
||||
* PEP_decrypt_flag_src_modified | indicates that the modified_src field should contain |
|
||||
* | a modified version of the source, at the moment |
|
||||
* | always as a result of the input flags. |
|
||||
* | |
|
||||
* PEP_decrypt_flag_consume | used by sync to indicate this was a pEp internal |
|
||||
* | message and should be consumed externally without |
|
||||
* | showing it as a normal message to the user |
|
||||
* | |
|
||||
* PEP_decrypt_flag_ignore | used by sync |
|
||||
* ---------------------------------------------------------------------------------------------| @endverbatim
|
||||
*
|
||||
* @ownership
|
||||
* - the decrypted, encoded mime text will go to the ownership of the caller
|
||||
* - the original mimetext will remain in the ownership of the caller
|
||||
*
|
||||
*/
|
||||
DYNAMIC_API PEP_STATUS MIME_decrypt_message(
|
||||
PEP_SESSION session,
|
||||
const char *mimetext,
|
||||
size_t size,
|
||||
char** mime_plaintext,
|
||||
stringlist_t **keylist,
|
||||
PEP_rating *rating,
|
||||
PEP_decrypt_flags_t *flags,
|
||||
char** modified_src
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|