From da99a8dd1493ff9f91d533be8bd4e61d12b7cdba Mon Sep 17 00:00:00 2001 From: Krista Bennett Date: Tue, 13 Jul 2021 14:57:02 +0200 Subject: [PATCH] Removed all MIME_encrypt/decrypt functions from tests and aux_mime_msg.* from the source. App builds may need to adjust! --- src/Makefile | 2 +- src/aux_mime_msg.c | 286 ----------------- src/aux_mime_msg.h | 187 ----------- .../CheckRenewedExpiredKeyTrustStatusTest.cc | 17 +- .../src/DecryptAttachPrivateKeyTrustedTest.cc | 20 +- .../DecryptAttachPrivateKeyUntrustedTest.cc | 26 +- test/src/EncryptForIdentityTest.cc | 114 +------ test/src/Engine463Test.cc | 26 +- test/src/KeyResetMessageTest.cc | 47 ++- test/src/Message2_1Test.cc | 38 +-- test/src/MessageNullFromTest.cc | 37 +-- test/src/MessageTwoPointOhTest.cc | 5 - test/src/OldMessageApiTest.cc | 40 +-- test/src/PassphraseTest.cc | 52 ++-- test/src/ReencryptPlusExtraKeysTest.cc | 18 +- test/src/TestUtilities.cc | 292 ++---------------- test/src/TestUtilities.h | 228 ++++---------- test/src/UnencryptedPepMailTest.cc | 26 +- test/src/VerifyTest.cc | 15 +- 19 files changed, 233 insertions(+), 1243 deletions(-) delete mode 100644 src/aux_mime_msg.c delete mode 100644 src/aux_mime_msg.h diff --git a/src/Makefile b/src/Makefile index a139e00a..b18b8eda 100644 --- a/src/Makefile +++ b/src/Makefile @@ -106,7 +106,7 @@ install_headers: $(TARGET) timestamp.h identity_list.h bloblist.h stringpair.h message.h mime.h group.h \ cryptotech.h sync_api.h pEp_string.h openpgp_compat.h engine_sql.h \ labeled_int_list.h key_reset.h base64.h sync_codec.h distribution_codec.h storage_codec.h \ - status_to_string.h aux_mime_msg.h keyreset_command.h platform.h platform_unix.h ../asn.1/*.h \ + status_to_string.h keyreset_command.h platform.h platform_unix.h ../asn.1/*.h \ $(DESTDIR)$(PREFIX)/include/pEp/ # FIXME: Does anyone but Roker use install_headers? Otherwise, remove the dependency. diff --git a/src/aux_mime_msg.c b/src/aux_mime_msg.c deleted file mode 100644 index a097abf3..00000000 --- a/src/aux_mime_msg.c +++ /dev/null @@ -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 -#include -#include - -#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 diff --git a/src/aux_mime_msg.h b/src/aux_mime_msg.h deleted file mode 100644 index f187a30a..00000000 --- a/src/aux_mime_msg.h +++ /dev/null @@ -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 - -/** - * - * - * @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 -); - - -/** - * - * - * @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 -); - - - -/** - * - * - * @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 diff --git a/test/src/CheckRenewedExpiredKeyTrustStatusTest.cc b/test/src/CheckRenewedExpiredKeyTrustStatusTest.cc index cd5223fd..070f0916 100644 --- a/test/src/CheckRenewedExpiredKeyTrustStatusTest.cc +++ b/test/src/CheckRenewedExpiredKeyTrustStatusTest.cc @@ -424,20 +424,12 @@ TEST_F(CheckRenewedExpiredKeyTrustStatusTest, check_renewed_expired_key_trust_st // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH // the expired key: - const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml"); - - char* decrypted_msg = NULL; - stringlist_t* keylist_used = nullptr; - char* modified_src = NULL; - - PEP_rating rating; - PEP_decrypt_flags_t flags = 0; - - status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src); + message* decrypted_msg = NULL; + status = vanilla_read_file_and_decrypt(session, &decrypted_msg, "test_mails/ENGINE-463-attempt-numero-dos.eml"); ASSERT_EQ(status , PEP_DECRYPTED); - free(decrypted_msg); - decrypted_msg = NULL; + free_message(decrypted_msg); + ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc"); ASSERT_TRUE(ok); @@ -449,6 +441,7 @@ TEST_F(CheckRenewedExpiredKeyTrustStatusTest, check_renewed_expired_key_trust_st ASSERT_EQ(expired_inquisitor1->comm_type, PEP_ct_pEp); message* msg2 = new_message(PEP_dir_outgoing); + PEP_rating rating = PEP_rating_undefined; msg2->from = alice_from; msg2->to = new_identity_list(expired_inquisitor1); diff --git a/test/src/DecryptAttachPrivateKeyTrustedTest.cc b/test/src/DecryptAttachPrivateKeyTrustedTest.cc index 92bb81fe..640b9666 100644 --- a/test/src/DecryptAttachPrivateKeyTrustedTest.cc +++ b/test/src/DecryptAttachPrivateKeyTrustedTest.cc @@ -147,23 +147,22 @@ TEST_F(DecryptAttachPrivateKeyTrustedTest, check_decrypt_attach_private_key_trus output_stream << "Reading in message..." << endl; - string encoded_text = slurp("test_mails/priv_key_attach.eml"); + message* encoded_text = slurp_message_file_into_struct("test_mails/priv_key_attach.eml"); output_stream << "Starting test..." << endl; + // Case 1: // Same address, same user_id, untrusted output_stream << "decrypt with attached private key: Same address, same user_id, trusted" << endl; - char* decrypted_text = NULL; + message* decrypted_text = NULL; stringlist_t* keylist_used = NULL; PEP_rating rating; PEP_decrypt_flags_t flags = 0; - char* modified_src = NULL; output_stream << "Trusting own key for " << same_addr_same_uid->user_id << " and " << same_addr_same_uid->fpr << endl; status = trust_own_key(session, same_addr_same_uid); output_stream << "Status is " << tl_status_string(status) << endl; ASSERT_EQ(status, PEP_STATUS_OK); - free(decrypted_text); decrypted_text = NULL; status = get_trust(session, same_addr_same_uid); @@ -172,19 +171,16 @@ TEST_F(DecryptAttachPrivateKeyTrustedTest, check_decrypt_attach_private_key_trus ASSERT_EQ(same_addr_same_uid->comm_type, PEP_ct_pEp); flags = 0; - status = MIME_decrypt_message(session, encoded_text.c_str(), - encoded_text.size(), &decrypted_text, - &keylist_used, &rating, &flags, - &modified_src); + status = decrypt_message(session, encoded_text, &decrypted_text, + &keylist_used, &rating, &flags); status = get_trust(session, same_addr_same_uid); ASSERT_EQ(same_addr_same_uid->comm_type, PEP_ct_pEp); + wipe_message_ptr(&decrypted_text); flags = 0; - status = MIME_decrypt_message(session, encoded_text.c_str(), - encoded_text.size(), &decrypted_text, - &keylist_used, &rating, &flags, - &modified_src); + status = decrypt_message(session, encoded_text, &decrypted_text, + &keylist_used, &rating, &flags); output_stream << "Status: " << tl_status_string(status) << endl; ASSERT_EQ(status, PEP_STATUS_OK); diff --git a/test/src/DecryptAttachPrivateKeyUntrustedTest.cc b/test/src/DecryptAttachPrivateKeyUntrustedTest.cc index 4fa2ba19..bd0d07e6 100644 --- a/test/src/DecryptAttachPrivateKeyUntrustedTest.cc +++ b/test/src/DecryptAttachPrivateKeyUntrustedTest.cc @@ -152,17 +152,19 @@ TEST_F(DecryptAttachPrivateKeyUntrustedTest, check_decrypt_attach_private_key_un output_stream << "Reading in message..." << endl; - string encoded_text = slurp("test_mails/priv_key_attach.eml"); + output_stream << "Reading in message..." << endl; + + message* encoded_text = slurp_message_file_into_struct("test_mails/priv_key_attach.eml"); + + output_stream << "Starting test..." << endl; - output_stream << "Starting tests..." << endl; // Case 1: // Same address, same user_id, untrusted output_stream << "Same address, same user_id, untrusted" << endl; - char* decrypted_text = NULL; + message* decrypted_text = NULL; stringlist_t* keylist_used = NULL; PEP_rating rating; - PEP_decrypt_flags_t flags; - char* modified_src = NULL; + PEP_decrypt_flags_t flags = 0; status = get_trust(session, same_addr_same_uid); output_stream << tl_ct_string(same_addr_same_uid->comm_type) << endl; @@ -170,10 +172,13 @@ TEST_F(DecryptAttachPrivateKeyUntrustedTest, check_decrypt_attach_private_key_un ASSERT_NE(same_addr_same_uid->comm_type & PEP_ct_confirmed, PEP_ct_confirmed); flags = 0; - status = MIME_decrypt_message(session, encoded_text.c_str(), - encoded_text.size(), &decrypted_text, - &keylist_used, &rating, &flags, - &modified_src); + output_stream << tl_ct_string(same_addr_same_uid->comm_type) << endl; + + ASSERT_NE(same_addr_same_uid->comm_type & PEP_ct_confirmed, PEP_ct_confirmed); + + flags = 0; + status = decrypt_message(session, encoded_text, &decrypted_text, + &keylist_used, &rating, &flags); status = get_trust(session, same_addr_same_uid); ASSERT_EQ(same_addr_same_uid->comm_type, PEP_ct_pEp_unconfirmed); @@ -183,8 +188,9 @@ TEST_F(DecryptAttachPrivateKeyUntrustedTest, check_decrypt_attach_private_key_un output_stream << "PASS!" << endl; // Case 2: - output_stream << decrypted_text << endl; status = key_reset_trust(session, main_me); status = key_reset_trust(session, same_addr_same_uid); + + // FIXME: This looks unfinished??? } diff --git a/test/src/EncryptForIdentityTest.cc b/test/src/EncryptForIdentityTest.cc index 040f54a8..ecc31a70 100644 --- a/test/src/EncryptForIdentityTest.cc +++ b/test/src/EncryptForIdentityTest.cc @@ -288,57 +288,44 @@ TEST_F(EncryptForIdentityTest, check_encrypt_for_identity) { keylist_used = NULL; - output_stream << "*** Now testing MIME_encrypt_for_self ***" << endl; + output_stream << "*** Now testing encrypt_for_self ***" << endl; alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test"); bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test"); output_stream << "Reading in alice_bob_encrypt_test_plaintext_mime.eml..." << endl; - const string mimetext = slurp("test_mails/alice_bob_encrypt_test_plaintext_mime.eml"); + message* dec_msg = slurp_message_file_into_struct("test_mails/alice_bob_encrypt_test_plaintext_mime.eml"); + message* enc_msg = NULL; - output_stream << "Text read:" << endl; - output_stream << mimetext.c_str() << endl; - char* encrypted_mimetext = nullptr; - - output_stream << "Calling MIME_encrypt_message_for_self" << endl; - status = MIME_encrypt_message_for_self(session, alice, mimetext.c_str(), - mimetext.size(), - NULL, - &encrypted_mimetext, - PEP_enc_PGP_MIME, - PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key); + output_stream << "Calling encrypt_message_for_self" << endl; + status = encrypt_message_for_self(session, alice, dec_msg, NULL, &enc_msg,PEP_enc_PGP_MIME, + PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key); output_stream << "Encrypted message:" << endl; - output_stream << encrypted_mimetext << endl; + print_mail(enc_msg); + wipe_message_ptr(&dec_msg); - output_stream << "Calling MIME_decrypt_message" << endl; + output_stream << "Calling decrypt_message" << endl; - char* decrypted_mimetext = nullptr; free_stringlist(keylist_used); keylist_used = nullptr; PEP_decrypt_flags_t mimeflags; PEP_rating mimerating; - char* modified_src = NULL; mimeflags = 0; - status = MIME_decrypt_message(session, - encrypted_mimetext, - strlen(encrypted_mimetext), - &decrypted_mimetext, - &keylist_used, - &mimerating, - &mimeflags, - &modified_src); - - ASSERT_NOTNULL(decrypted_mimetext); + status = decrypt_message(session, enc_msg, &dec_msg, &keylist_used, &mimerating, &mimeflags); + + ASSERT_NOTNULL(dec_msg); ASSERT_NOTNULL(keylist_used); ASSERT_NE(mimerating, 0); ASSERT_TRUE(status == PEP_DECRYPTED && mimerating == PEP_rating_unreliable); output_stream << "Decrypted message:" << endl; - output_stream << decrypted_mimetext << endl; + print_mail(dec_msg); + wipe_message_ptr(&dec_msg); + wipe_message_ptr(&enc_msg); output_stream << "keys used:\n"; @@ -558,75 +545,4 @@ TEST_F(EncryptForIdentityTest, check_encrypt_for_identity_with_URI) { decrypted_msg = NULL; free_stringlist(keylist_used); keylist_used = NULL; - - - output_stream << "*** Now testing MIME_encrypt_for_self ***" << endl; - - alice = new_identity("payto://BIC/SYSTEMA", NULL, PEP_OWN_USERID, "Alice Test"); - bob = new_identity("payto://BIC/SYSTEMB", NULL, "42", "Bob Test"); - - output_stream << "Reading in alice_bob_encrypt_test_plaintext_mime.eml..." << endl; - - const string mimetext = slurp("test_mails/alice_bob_encrypt_test_plaintext_mime.eml"); - - output_stream << "Text read:" << endl; - output_stream << mimetext.c_str() << endl; - char* encrypted_mimetext = nullptr; - - output_stream << "Calling MIME_encrypt_message_for_self" << endl; - status = MIME_encrypt_message_for_self(session, alice, mimetext.c_str(), - mimetext.size(), - NULL, - &encrypted_mimetext, - PEP_enc_PGP_MIME, - PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key); - - output_stream << "Encrypted message:" << endl; - output_stream << encrypted_mimetext << endl; - - output_stream << "Calling MIME_decrypt_message" << endl; - - char* decrypted_mimetext = nullptr; - free_stringlist(keylist_used); - keylist_used = nullptr; - PEP_decrypt_flags_t mimeflags; - PEP_rating mimerating; - char* modified_src = NULL; - - mimeflags = 0; - status = MIME_decrypt_message(session, - encrypted_mimetext, - strlen(encrypted_mimetext), - &decrypted_mimetext, - &keylist_used, - &mimerating, - &mimeflags, - &modified_src); - - ASSERT_NOTNULL(decrypted_mimetext); - ASSERT_NOTNULL(keylist_used); - ASSERT_NE(mimerating, 0); - - ASSERT_TRUE(status == PEP_DECRYPTED && mimerating == PEP_rating_unreliable); - - output_stream << "Decrypted message:" << endl; - output_stream << decrypted_mimetext << endl; - - output_stream << "keys used:\n"; - - i = 0; - - for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++) - { - if (i == 0) { - ASSERT_STRCASEEQ("",kl4->value); - } - else { - output_stream << "\t " << kl4->value << endl; - ASSERT_STRCASEEQ("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value); - output_stream << "Encrypted for Alice! Yay! It worked!" << endl; - } - ASSERT_LT(i , 2); - } - output_stream << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl; } diff --git a/test/src/Engine463Test.cc b/test/src/Engine463Test.cc index 0e00ca85..79617127 100644 --- a/test/src/Engine463Test.cc +++ b/test/src/Engine463Test.cc @@ -95,16 +95,14 @@ TEST_F(Engine463Test, check_engine_463_no_own_key) { ASSERT_EQ(status , PEP_TEST_KEY_IMPORT_SUCCESS); // Ok, bring in message, decrypt, and see what happens. - const string msg = slurp("test_mails/notfound-alt.msg"); + message* msg = slurp_message_file_into_struct("test_mails/notfound-alt.msg"); - char* decrypted_msg = NULL; + message* decrypted_msg = NULL; stringlist_t* keylist_used = nullptr; - char* modified_src = NULL; - PEP_rating rating; PEP_decrypt_flags_t flags = 0; - status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src); + status = decrypt_message(session, msg, &decrypted_msg, &keylist_used, &rating, &flags); ASSERT_OK; } @@ -124,16 +122,14 @@ TEST_F(Engine463Test, check_engine_463_sender_expired_and_renewed) { // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH // the expired key: - const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml"); + message* msg = slurp_message_file_into_struct("test_mails/ENGINE-463-attempt-numero-dos.eml"); - char* decrypted_msg = NULL; + message* decrypted_msg = NULL; stringlist_t* keylist_used = nullptr; - char* modified_src = NULL; - PEP_rating rating; PEP_decrypt_flags_t flags = 0; - status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src); + status = decrypt_message(session, msg, &decrypted_msg, &keylist_used, &rating, &flags); ASSERT_EQ(status , PEP_DECRYPTED); free(decrypted_msg); @@ -149,7 +145,7 @@ TEST_F(Engine463Test, check_engine_463_sender_expired_and_renewed) { flags = 0; - status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src); + status = decrypt_message(session, msg, &decrypted_msg, &keylist_used, &rating, &flags); ASSERT_NOTNULL(decrypted_msg); ASSERT_OK; ASSERT_EQ(rating , PEP_rating_reliable); @@ -180,16 +176,14 @@ TEST_F(Engine463Test, check_engine_463_sender_expired_and_renewed) { // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH // the expired key: - const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml"); + message* msg = slurp_message_file_into_struct("test_mails/ENGINE-463-attempt-numero-dos.eml"); - char* decrypted_msg = NULL; + message* decrypted_msg = NULL; stringlist_t* keylist_used = nullptr; - char* modified_src = NULL; - PEP_rating rating; PEP_decrypt_flags_t flags = 0; - status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src); + status = decrypt_message(session, msg, &decrypted_msg, &keylist_used, &rating, &flags); ASSERT_EQ(status , PEP_DECRYPTED); free(decrypted_msg); diff --git a/test/src/KeyResetMessageTest.cc b/test/src/KeyResetMessageTest.cc index dfb776ef..134743fe 100644 --- a/test/src/KeyResetMessageTest.cc +++ b/test/src/KeyResetMessageTest.cc @@ -424,8 +424,6 @@ TEST_F(KeyResetMessageTest, check_non_reset_receive_revoked) { status = mime_decode_message(received_mail.c_str(), received_mail.size(), &enc_msg_obj, NULL); ASSERT_OK; status = decrypt_message(session, enc_msg_obj, &dec_msg_obj, &keylist, &rating, &flags); -// status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(), -// &decrypted_msg, &keylist, &rating, &flags, &modified_src); ASSERT_OK; @@ -472,14 +470,13 @@ TEST_F(KeyResetMessageTest, check_reset_receive_revoked) { ASSERT_OK; ASSERT_STREQ(alice_fpr, alice_ident->fpr); - string received_mail = slurp("test_files/398_reset_from_alice_to_fenris.eml"); - char* decrypted_msg = NULL; - char* modified_src = NULL; + message* received_mail = slurp_message_file_into_struct("test_files/398_reset_from_alice_to_fenris.eml"); + message* decrypted_msg = NULL; stringlist_t* keylist = NULL; PEP_rating rating; PEP_decrypt_flags_t flags = 0; - status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(), - &decrypted_msg, &keylist, &rating, &flags, &modified_src); + status = decrypt_message(session, received_mail, + &decrypted_msg, &keylist, &rating, &flags); ASSERT_OK; ASSERT_NOTNULL(keylist); @@ -544,17 +541,16 @@ TEST_F(KeyResetMessageTest, check_receive_message_to_revoked_key_from_unknown) { ASSERT_OK; m_queue.clear(); - string received_mail = slurp("test_files/398_gabrielle_to_alice.eml"); - char* decrypted_msg = NULL; - char* modified_src = NULL; + message* received_mail = slurp_message_file_into_struct("test_files/398_gabrielle_to_alice.eml"); + message* decrypted_msg = NULL; stringlist_t* keylist = NULL; PEP_rating rating; PEP_decrypt_flags_t flags = 0; - status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(), - &decrypted_msg, &keylist, &rating, &flags, &modified_src); + status = decrypt_message(session, received_mail, + &decrypted_msg, &keylist, &rating, &flags); ASSERT_EQ(m_queue.size() , 0); - free(decrypted_msg); - free(modified_src); + free_message(decrypted_msg); + free_message(received_mail); free_stringlist(keylist); free_identity(from_ident); } @@ -612,14 +608,18 @@ TEST_F(KeyResetMessageTest, check_receive_message_to_revoked_key_from_contact) { // Now we get mail from Gabi, who only has our old key AND has become // a pEp user in the meantime... - string received_mail = slurp("test_files/398_gabrielle_to_alice.eml"); - char* decrypted_msg = NULL; - char* modified_src = NULL; + message* received_mail = slurp_message_file_into_struct("test_files/398_gabrielle_to_alice.eml"); + message* decrypted_msg = NULL; stringlist_t* keylist = NULL; PEP_rating rating; PEP_decrypt_flags_t flags = 0; - status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(), - &decrypted_msg, &keylist, &rating, &flags, &modified_src); + + // We expect the app to provide user_ids wherever it has them on incoming messages, and since it breaks things + // here if we don't put it there, we do now. + received_mail->to->ident->user_id = strdup(PEP_OWN_USERID); + + status = decrypt_message(session, received_mail, + &decrypted_msg, &keylist, &rating, &flags); ASSERT_EQ(m_queue.size() , 1); vector::iterator it = m_queue.begin(); @@ -771,14 +771,13 @@ TEST_F(KeyResetMessageTest, check_reset_grouped_own_recv) { status = myself(session, alice); ASSERT_OK; - string received_mail = slurp("test_mails/check_reset_grouped_own_recv.eml"); - char* decrypted_msg = NULL; - char* modified_src = NULL; + message* received_mail = slurp_message_file_into_struct("test_mails/check_reset_grouped_own_recv.eml"); + message* decrypted_msg = NULL; stringlist_t* keylist = NULL; PEP_rating rating; PEP_decrypt_flags_t flags = 0; - status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(), - &decrypted_msg, &keylist, &rating, &flags, &modified_src); + status = decrypt_message(session, received_mail, + &decrypted_msg, &keylist, &rating, &flags); status = myself(session, alice); ASSERT_OK; diff --git a/test/src/Message2_1Test.cc b/test/src/Message2_1Test.cc index 4c935b2f..8df2891b 100644 --- a/test/src/Message2_1Test.cc +++ b/test/src/Message2_1Test.cc @@ -296,15 +296,8 @@ TEST_F(Message2_1Test, check_message2_1_recip_1_0_from_msg_OpenPGP) { ASSERT_NOTNULL(alex); // receive 1.0 message from OpenPGP - string incoming = slurp("test_mails/From_M1_0.eml"); - - char* dec_msg; - char* mod_src = NULL; - PEP_decrypt_flags_t flags = 0; - stringlist_t* keylist_used = NULL; - PEP_rating rating; - - status = MIME_decrypt_message(session, incoming.c_str(), incoming.size(), &dec_msg, &keylist_used, &rating, &flags, &mod_src); + message* dec_msg; + status = vanilla_read_file_and_decrypt(session, &dec_msg, "test_mails/From_M1_0.eml"); ASSERT_OK; // generate message @@ -329,7 +322,7 @@ TEST_F(Message2_1Test, check_message2_1_recip_1_0_from_msg_OpenPGP) { free_message(msg); free_message(enc_msg); free(dec_msg); - free(mod_src); + } // Note, this will now create a 2.1 message ANYWAY. @@ -344,15 +337,8 @@ TEST_F(Message2_1Test, check_message2_1_recip_2_0_from_msg) { ASSERT_NOTNULL(carol); // receive 1.0 message from OpenPGP - string incoming = slurp("test_mails/2_0_msg.eml"); - - char* dec_msg; - char* mod_src = NULL; - PEP_decrypt_flags_t flags = 0; - stringlist_t* keylist_used = NULL; - PEP_rating rating; - - status = MIME_decrypt_message(session, incoming.c_str(), incoming.size(), &dec_msg, &keylist_used, &rating, &flags, &mod_src); + message* dec_msg; + status = vanilla_read_file_and_decrypt(session, &dec_msg, "test_mails/2_0_msg.eml"); ASSERT_OK; // generate message @@ -377,7 +363,6 @@ TEST_F(Message2_1Test, check_message2_1_recip_2_0_from_msg) { free_message(msg); free_message(enc_msg); free(dec_msg); - free(mod_src); } TEST_F(Message2_1Test, check_message2_1_recip_2_1_from_msg) { @@ -391,15 +376,8 @@ TEST_F(Message2_1Test, check_message2_1_recip_2_1_from_msg) { ASSERT_NOTNULL(carol); // receive 1.0 message from OpenPGP - string incoming = slurp("test_mails/From_M2_1.eml"); - - char* dec_msg; - char* mod_src = NULL; - PEP_decrypt_flags_t flags = 0; - stringlist_t* keylist_used = NULL; - PEP_rating rating; - - status = MIME_decrypt_message(session, incoming.c_str(), incoming.size(), &dec_msg, &keylist_used, &rating, &flags, &mod_src); + message* dec_msg; + status = vanilla_read_file_and_decrypt(session, &dec_msg, "test_mails/From_M2_1.eml"); ASSERT_OK; // generate message @@ -429,7 +407,7 @@ TEST_F(Message2_1Test, check_message2_1_recip_2_1_from_msg) { free_message(msg); free_message(enc_msg); free(dec_msg); - free(mod_src); + } TEST_F(Message2_1Test, check_message2_1_recip_mixed_2_0) { diff --git a/test/src/MessageNullFromTest.cc b/test/src/MessageNullFromTest.cc index b2d7a85c..7463148b 100644 --- a/test/src/MessageNullFromTest.cc +++ b/test/src/MessageNullFromTest.cc @@ -130,40 +130,17 @@ TEST_F(MessageNullFromTest, check_message_null_from_header_key_unencrypted) { TEST_F(MessageNullFromTest, check_message_null_from_encrypted_not_signed) { import_alice_pub(); - string null_from_msg = slurp("test_files/432_no_from_encrypted_not_signed.eml"); - output_stream << null_from_msg << endl; - stringlist_t* keylist = NULL; - PEP_decrypt_flags_t flags = 0; - PEP_rating rating; - char* mime_plaintext = NULL; - char* modified_src = NULL; - PEP_STATUS status = MIME_decrypt_message(session, null_from_msg.c_str(), - null_from_msg.size(), - &mime_plaintext, - &keylist, - &rating, - &flags, - &modified_src); + message* plaintext_msg = NULL; + PEP_STATUS status = vanilla_read_file_and_decrypt(session, &plaintext_msg, "test_files/432_no_from_encrypted_not_signed.eml"); ASSERT_EQ(status , PEP_DECRYPTED); - ASSERT_NOTNULL(mime_plaintext); + ASSERT_NOTNULL(plaintext_msg); + free_message(plaintext_msg); } TEST_F(MessageNullFromTest, check_message_null_from_encrypted_and_signed) { import_alice_pub(); - string null_from_msg = slurp("test_files/432_no_from_encrypted_and_signed.eml"); - output_stream << null_from_msg << endl; - stringlist_t* keylist = NULL; - PEP_decrypt_flags_t flags = 0; - PEP_rating rating; - char* mime_plaintext = NULL; - char* modified_src = NULL; - PEP_STATUS status = MIME_decrypt_message(session, null_from_msg.c_str(), - null_from_msg.size(), - &mime_plaintext, - &keylist, - &rating, - &flags, - &modified_src); + message* plaintext_msg = NULL; + PEP_STATUS status = vanilla_read_file_and_decrypt(session, &plaintext_msg, "test_files/432_no_from_encrypted_and_signed.eml"); ASSERT_OK; - ASSERT_NOTNULL(mime_plaintext); + ASSERT_NOTNULL(plaintext_msg); } diff --git a/test/src/MessageTwoPointOhTest.cc b/test/src/MessageTwoPointOhTest.cc index 8c541a2f..2de93243 100644 --- a/test/src/MessageTwoPointOhTest.cc +++ b/test/src/MessageTwoPointOhTest.cc @@ -182,11 +182,6 @@ TEST_F(MessageTwoPointOhTest, check_message_two_point_oh) { PEP_rating rating; PEP_decrypt_flags_t flags = 0; -// MIME_decrypt_message(session, encoded_text, strlen(encoded_text), &decrypted_text, &keylist_used, &rating, &flags); - -// output_stream << "HEY!" << endl; -// output_stream << decrypted_text << endl; - message* decoded_msg = nullptr; status = mime_decode_message(encoded_text, strlen(encoded_text), &decoded_msg, NULL); ASSERT_OK; diff --git a/test/src/OldMessageApiTest.cc b/test/src/OldMessageApiTest.cc index 7f536b17..d0c982cd 100644 --- a/test/src/OldMessageApiTest.cc +++ b/test/src/OldMessageApiTest.cc @@ -223,45 +223,30 @@ TEST_F(OldMessageApiTest, check_message_api) { output_stream << "rating :" << rating2 << "\n"; free_stringlist(keylist5); - output_stream << "\nTesting MIME_encrypt_message / MIME_decrypt_message...\n\n"; + output_stream << "\nTesting encrypt_message / decrypt_message...\n\n"; output_stream << "opening alice_bob_encrypt_test_plaintext_mime.eml for reading\n"; - ifstream inFile4 ("test_mails/alice_bob_encrypt_test_plaintext_mime.eml"); - ASSERT_TRUE(inFile4.is_open()); - string text4; + message* dec_msg = slurp_message_file_into_struct("test_mails/alice_bob_encrypt_test_plaintext_mime.eml", PEP_dir_outgoing); + message* enc_msg = NULL; - output_stream << "reading alice_bob_encrypt_test_plaintext_mime.eml sample\n"; - while (!inFile4.eof()) { - static string line; - getline(inFile4, line); - text4 += line + "\r\n"; - } - inFile4.close(); - - const char* out_msg_plain = text4.c_str(); - -// const char* out_msg_plain = "From: krista@kgrothoff.org\nTo: Volker \nSubject: Test\nContent-Type: text/plain; charset=utf-8\nContent-Language: en-US\nContent-Transfer-Encoding:quoted-printable\n\ngaga\n\n"; - char* enc_msg = NULL; - char* dec_msg = NULL; - - PEP_STATUS status7 = MIME_encrypt_message(session, text4.c_str(), text4.length(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0); -// PEP_STATUS status7 = MIME_encrypt_message(session, out_msg_plain, strlen(out_msg_plain), NULL, &enc_msg, PEP_enc_PGP_MIME, 0); + PEP_STATUS status7 = encrypt_message(session, dec_msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0); ASSERT_EQ(status7 , PEP_STATUS_OK); - output_stream << enc_msg << endl; - - string text5 = enc_msg; + print_mail(enc_msg); + wipe_message_ptr(&dec_msg); PEP_decrypt_flags_t dec_flags; stringlist_t* keys_used; dec_flags = 0; - char* modified_src = NULL; - PEP_STATUS status8 = MIME_decrypt_message(session, text5.c_str(), text5.length(), &dec_msg, &keys_used, &rating, &dec_flags, &modified_src); + + PEP_STATUS status8 = decrypt_message(session, enc_msg, &dec_msg, &keys_used, &rating, &dec_flags); ASSERT_EQ(status8 , PEP_STATUS_OK); - output_stream << dec_msg << endl; + print_mail(dec_msg); + wipe_message_ptr(&dec_msg); + wipe_message_ptr(&enc_msg); output_stream << "\nTesting encrypt_message() with enc_format = PEP_enc_none\n\n"; @@ -293,7 +278,4 @@ TEST_F(OldMessageApiTest, check_message_api) { free_message(msg2); free_message(enc_msg2); output_stream << "done.\n"; - - free(enc_msg); - free(dec_msg); } diff --git a/test/src/PassphraseTest.cc b/test/src/PassphraseTest.cc index 8cbb34f8..d2f7c3bb 100644 --- a/test/src/PassphraseTest.cc +++ b/test/src/PassphraseTest.cc @@ -637,18 +637,17 @@ TEST_F(PassphraseTest, check_bob_primary_pass_subkey_no_passphrase_nopass_decryp status = set_identity(session, to_ident); ASSERT_EQ(status, PEP_STATUS_OK); - string msg = slurp("test_mails/encrypt_to_bob.eml"); - char* decrypted_msg = NULL; - char* modified_src = NULL; + message* enc_msg = slurp_message_file_into_struct("test_mails/encrypt_to_bob.eml"); + message* decrypted_msg = NULL; stringlist_t* keylist_used = NULL; PEP_rating rating; PEP_decrypt_flags_t flags = 0; - status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src); + status = decrypt_message(session, enc_msg, &decrypted_msg, &keylist_used, &rating, &flags); ASSERT_EQ(status, PEP_STATUS_OK); ASSERT_NOTNULL(decrypted_msg); - - free(decrypted_msg); - free(modified_src); + + free_message(enc_msg); + free_message(decrypted_msg); free_stringlist(keylist_used); } @@ -678,18 +677,17 @@ TEST_F(PassphraseTest, check_carol_primary_unenc_subkeys_passphrase_nopass_decry status = set_identity(session, to_ident); ASSERT_EQ(status, PEP_STATUS_OK); - string msg = slurp("test_mails/encrypt_to_carol.eml"); - char* decrypted_msg = NULL; - char* modified_src = NULL; + message* enc_msg = slurp_message_file_into_struct("test_mails/encrypt_to_carol.eml"); + message* decrypted_msg = NULL; stringlist_t* keylist_used = NULL; PEP_rating rating; PEP_decrypt_flags_t flags = 0; - status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src); + status = decrypt_message(session, enc_msg, &decrypted_msg, &keylist_used, &rating, &flags); ASSERT_EQ(status, PEP_PASSPHRASE_REQUIRED); ASSERT_NULL(decrypted_msg); - - free(decrypted_msg); - free(modified_src); + + free_message(enc_msg); + free_message(decrypted_msg); free_stringlist(keylist_used); } @@ -962,18 +960,17 @@ TEST_F(PassphraseTest, check_carol_primary_unenc_subkeys_passphrase_withpass_dec status = config_passphrase(session, pass); ASSERT_EQ(status, PEP_STATUS_OK); - string msg = slurp("test_mails/encrypt_to_carol.eml"); - char* decrypted_msg = NULL; - char* modified_src = NULL; + message* enc_msg = slurp_message_file_into_struct("test_mails/encrypt_to_carol.eml"); + message* decrypted_msg = NULL; stringlist_t* keylist_used = NULL; PEP_rating rating; PEP_decrypt_flags_t flags = 0; - status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src); + status = decrypt_message(session, enc_msg, &decrypted_msg, &keylist_used, &rating, &flags); ASSERT_EQ(status, PEP_STATUS_OK); ASSERT_NOTNULL(decrypted_msg); - - free(decrypted_msg); - free(modified_src); + + free_message(enc_msg); + free_message(decrypted_msg); free_stringlist(keylist_used); } @@ -1007,18 +1004,17 @@ TEST_F(PassphraseTest, check_carol_primary_unenc_subkeys_passphrase_wrongpass_de status = config_passphrase(session, pass); ASSERT_EQ(status, PEP_STATUS_OK); - string msg = slurp("test_mails/encrypt_to_carol.eml"); - char* decrypted_msg = NULL; - char* modified_src = NULL; + message* enc_msg = slurp_message_file_into_struct("test_mails/encrypt_to_carol.eml"); + message* decrypted_msg = NULL; stringlist_t* keylist_used = NULL; PEP_rating rating; PEP_decrypt_flags_t flags = 0; - status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src); + status = decrypt_message(session, enc_msg, &decrypted_msg, &keylist_used, &rating, &flags); ASSERT_EQ(status, PEP_WRONG_PASSPHRASE); ASSERT_NULL(decrypted_msg); - - free(decrypted_msg); - free(modified_src); + + free_message(enc_msg); + free_message(decrypted_msg); free_stringlist(keylist_used); } diff --git a/test/src/ReencryptPlusExtraKeysTest.cc b/test/src/ReencryptPlusExtraKeysTest.cc index be49b1ba..4a675f12 100644 --- a/test/src/ReencryptPlusExtraKeysTest.cc +++ b/test/src/ReencryptPlusExtraKeysTest.cc @@ -550,7 +550,7 @@ TEST_F(ReencryptPlusExtraKeysTest, check_reencrypt_plus_extra_keys) { const string to_reencrypt_from_enigmail_BCC = slurp("test_mails/reencrypt_BCC_sent_by_enigmail.eml"); const string to_reencrypt_from_pEp = slurp("test_mails/reencrypt_encrypted_through_pEp.eml"); - output_stream << endl << "Case 1a: Calling MIME_decrypt_message with reencrypt flag set on message sent from enigmail for recip 2 with no extra keys." << endl; + output_stream << endl << "Case 1a: Calling decrypt_message with reencrypt flag set on message sent from enigmail for recip 2 with no extra keys." << endl; char* decrypted_text = nullptr; @@ -581,7 +581,7 @@ TEST_F(ReencryptPlusExtraKeysTest, check_reencrypt_plus_extra_keys) { output_stream << "Case 1a: PASS" << endl << endl; - output_stream << "Case 1b: Calling MIME_decrypt_message with reencrypt flag set on message sent from enigmail for recip 2 extra keys." << endl; + output_stream << "Case 1b: Calling decrypt_message with reencrypt flag set on message sent from enigmail for recip 2 extra keys." << endl; // In: extra keys; Out: keys that were used to encrypt this. free_stringlist(keys); @@ -661,7 +661,7 @@ TEST_F(ReencryptPlusExtraKeysTest, check_reencrypt_plus_extra_keys) { output_stream << "Case 1b: PASS" << endl << endl; - output_stream << "Case 2a: Calling MIME_decrypt_message with reencrypt flag set on message sent with recip 2 in BCC from enigmail with no extra keys." << endl; + output_stream << "Case 2a: Calling decrypt_message with reencrypt flag set on message sent with recip 2 in BCC from enigmail with no extra keys." << endl; free(modified_src); modified_src = NULL; @@ -690,7 +690,7 @@ TEST_F(ReencryptPlusExtraKeysTest, check_reencrypt_plus_extra_keys) { output_stream << "Case 2a: PASS" << endl << endl; - output_stream << "Case 2b: Calling MIME_decrypt_message with reencrypt flag set on message sent with recip 2 in BCC from enigmail with extra keys." << endl; + output_stream << "Case 2b: Calling decrypt_message with reencrypt flag set on message sent with recip 2 in BCC from enigmail with extra keys." << endl; free_stringlist(keys); keys = new_stringlist(fpr_pub_extra_key_0); @@ -768,7 +768,7 @@ TEST_F(ReencryptPlusExtraKeysTest, check_reencrypt_plus_extra_keys) { output_stream << "Case 2b: PASS" << endl << endl; - output_stream << "Case 3a: Calling MIME_decrypt_message with reencrypt flag set on message generated by pEp (message 2.0) with no extra keys." << endl; + output_stream << "Case 3a: Calling decrypt_message with reencrypt flag set on message generated by pEp (message 2.0) with no extra keys." << endl; free_stringlist(keys); keys = NULL; @@ -805,7 +805,7 @@ TEST_F(ReencryptPlusExtraKeysTest, check_reencrypt_plus_extra_keys) { output_stream << "Case 3a: PASS" << endl << endl; - output_stream << "Case 3b: Calling MIME_decrypt_message with reencrypt flag set on message generated by pEp (message 2.0) with extra keys." << endl; + output_stream << "Case 3b: Calling decrypt_message with reencrypt flag set on message generated by pEp (message 2.0) with extra keys." << endl; free_stringlist(keys); keys = new_stringlist(fpr_pub_extra_key_0); @@ -885,7 +885,7 @@ TEST_F(ReencryptPlusExtraKeysTest, check_reencrypt_plus_extra_keys) { TEST_F(ReencryptPlusExtraKeysTest, check_efficient_reencrypt_from_enigmail) { - output_stream << "Call MIME_decrypt_message with reencrypt flag set on message sent from enigmail for recip 2 extra keys." << endl; + output_stream << "Call decrypt_message with reencrypt flag set on message sent from enigmail for recip 2 extra keys." << endl; PEP_STATUS status = PEP_STATUS_OK; @@ -964,7 +964,7 @@ TEST_F(ReencryptPlusExtraKeysTest, check_efficient_reencrypt_from_enigmail) { } TEST_F(ReencryptPlusExtraKeysTest, check_efficient_reencrypt_from_enigmail_w_own_recip_in_bcc) { - output_stream << "Call MIME_decrypt_message with reencrypt flag set on message sent with recip 2 in BCC from enigmail with extra keys." << endl; + output_stream << "Call decrypt_message with reencrypt flag set on message sent with recip 2 in BCC from enigmail with extra keys." << endl; PEP_STATUS status = PEP_STATUS_OK; @@ -1045,7 +1045,7 @@ TEST_F(ReencryptPlusExtraKeysTest, check_efficient_reencrypt_from_enigmail_w_own } TEST_F(ReencryptPlusExtraKeysTest, check_efficient_reencrypt_from_pEp_2_0) { - output_stream << "Call MIME_decrypt_message with reencrypt flag set on message generated by pEp (message 2.0) with extra keys." << endl; + output_stream << "Call decrypt_message with reencrypt flag set on message generated by pEp (message 2.0) with extra keys." << endl; PEP_STATUS status = PEP_STATUS_OK; /* import all the keys */ diff --git a/test/src/TestUtilities.cc b/test/src/TestUtilities.cc index 26ab59b8..af0059ba 100644 --- a/test/src/TestUtilities.cc +++ b/test/src/TestUtilities.cc @@ -505,6 +505,19 @@ bool slurp_message_and_import_key(PEP_SESSION session, const char* message_fname return ok; } +message* slurp_message_file_into_struct(std::string infile, PEP_msg_direction direction) { + message* retval = NULL; + string msg_txt = slurp(infile); + PEP_STATUS status = mime_decode_message(msg_txt.c_str(), msg_txt.size(), &retval, NULL); + if (status != PEP_STATUS_OK) { + free(retval); + retval = NULL; + } + if (retval) + retval->dir = direction; + return retval; +} + char* message_to_str(message* msg) { char* retval = NULL; mime_encode_message(msg, false, &retval, false); @@ -553,12 +566,10 @@ PEP_STATUS vanilla_read_file_and_decrypt_with_rating(PEP_SESSION session, messag if (!session || !msg || !filename || !rating) return PEP_ILLEGAL_VALUE; PEP_STATUS status = PEP_STATUS_OK; - std::string inbox = slurp(filename); - if (inbox.empty()) - return PEP_UNKNOWN_ERROR; - message* enc_msg = NULL; - mime_decode_message(inbox.c_str(), inbox.size(), &enc_msg, NULL); + message* enc_msg = slurp_message_file_into_struct(filename); + if (!enc_msg) + return PEP_UNKNOWN_ERROR; message* dec_msg = NULL; stringlist_t* keylist = NULL; @@ -572,6 +583,12 @@ PEP_STATUS vanilla_read_file_and_decrypt_with_rating(PEP_SESSION session, messag return status; } +void wipe_message_ptr(message** msg_ptr) { + if (msg_ptr) { + free_message(*msg_ptr); + *msg_ptr = NULL; + } +} int util_delete_filepath(const char *filepath, const struct stat *file_stat, @@ -608,271 +625,6 @@ PEP_STATUS config_valid_passphrase(PEP_SESSION session, const char* fpr, std::ve return status; } -#ifndef ENIGMAIL_MAY_USE_THIS - -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; -} - -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; - PEP_STATUS decrypt_status = PEP_CANNOT_DECRYPT_UNKNOWN; - - 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) - 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; - - 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; -} - -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; - -} - -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; -} - -#endif - PEP_STATUS set_default_fpr_for_test(PEP_SESSION session, pEp_identity* ident, bool unconditional) { if (EMPTYSTR(ident->fpr)) return PEP_ILLEGAL_VALUE; diff --git a/test/src/TestUtilities.h b/test/src/TestUtilities.h index e62750d8..83b4e023 100644 --- a/test/src/TestUtilities.h +++ b/test/src/TestUtilities.h @@ -10,15 +10,31 @@ #include "pEpEngine.h" #include "message_api.h" -#include "aux_mime_msg.h" #include "mime.h" #include +std::string get_main_test_home_dir(); void test_init(); - bool file_exists(std::string filename); bool is_pEpmsg(const message *msg); // duplicates static func in message_api.c, fyi +int util_delete_filepath(const char *filepath, + const struct stat *file_stat, + int ftw_info, + struct FTW * ftw_struct); + +// string equality (case and non-case sensitive) +bool _streq(const char* str1, const char* str2); +bool _strceq(const char* str1, const char* str2); + +// Generate random ASCII string of a certain length +std::string random_string( size_t length ); +// Grabs a new uuid for your randomish string needs. +char* get_new_uuid(); + +/************************************************************************************ + * Expansion of googletest ASSERT defines + */ #ifndef ASSERT_OK #define ASSERT_OK ASSERT_EQ(status, PEP_STATUS_OK) @@ -39,12 +55,12 @@ bool is_pEpmsg(const message *msg); // duplicates static func in message_api.c, extern std::string _main_test_home_dir; -#ifndef DEBUG_OUTPUT -extern std::ostream output_stream; -#else -#define output_stream std::cerr -#endif - +/************************************************************************************ + * This is a cleanup of some preset functions we had set up before. It's still clunky, but + * can be used as a way to avoid code duplication and have some standard identities with + * which we have some already set up keys, etc. This could be done way better, frankly, but + * taking the time to refactor right now isn't possible. + */ class TestUtilsPreset { public: @@ -147,10 +163,7 @@ public: static const IdentityInfo presets[]; }; -std::string get_main_test_home_dir(); -std::string random_string( size_t length ); - -PEP_STATUS read_file_and_import_key(PEP_SESSION session, const char* fname); +// FIXME: Refactor tests from above PEP_STATUS set_up_ident_from_scratch(PEP_SESSION session, const char* key_fname, const char* address, @@ -160,188 +173,59 @@ PEP_STATUS set_up_ident_from_scratch(PEP_SESSION session, pEp_identity** ret_ident, bool is_priv); -// string equality (case and non-case sensitive) -bool _streq(const char* str1, const char* str2); -bool _strceq(const char* str1, const char* str2); // reads a whole file and returns it as std::string // throws std::runtime_error() if the file cannot be read. Empty file is not an error. std::string slurp(const std::string& filename); - // dumps char* to file // throws std::runtime_error() if the file cannot be opened. void dump_out(const char* filename, const char* outdata); +void print_mail(message* msg); -// Returns the string value of the input rating enum value. -const char* tl_rating_string(PEP_rating rating); - -// Returns the string value of the input comm_type enum value. -const char* tl_ct_string(PEP_comm_type ct); - -// Returns the string value of the input status enum value. -const char* tl_status_string(PEP_STATUS status); - -std::string tl_ident_flags_String(identity_flags_t fl); - -// Grabs a new uuid for your randomish string needs. -char* get_new_uuid(); - +// Read in a keyfile and import it +// FIXME: why do we have two of these? Is it just the status returns? +PEP_STATUS read_file_and_import_key(PEP_SESSION session, const char* fname); bool slurp_and_import_key(PEP_SESSION session, const char* key_filename); - bool slurp_message_and_import_key(PEP_SESSION session, const char* message_fname, std::string& message, const char* key_filename); +message* slurp_message_file_into_struct(std::string infile, PEP_msg_direction direction=PEP_dir_incoming); -char* message_to_str(message* msg); -message* string_to_msg(std::string infile); +void wipe_message_ptr(message** msg_ptr); // For when you ONLY care about the message PEP_STATUS vanilla_encrypt_and_write_to_file(PEP_SESSION session, message* msg, const char* filename, PEP_encrypt_flags_t flags = 0); PEP_STATUS vanilla_read_file_and_decrypt(PEP_SESSION session, message** msg, const char* filename); PEP_STATUS vanilla_read_file_and_decrypt_with_rating(PEP_SESSION session, message** msg, const char* filename, PEP_rating* rating); -int util_delete_filepath(const char *filepath, - const struct stat *file_stat, - int ftw_info, - struct FTW * ftw_struct); - -class NullBuffer : public std::streambuf { - public: - int overflow(int c); -}; - PEP_STATUS config_valid_passphrase(PEP_SESSION session, const char* fpr, std::vector passphrases); PEP_STATUS set_default_fpr_for_test(PEP_SESSION session, pEp_identity* ident, bool unconditional); PEP_STATUS set_fpr_preserve_ident(PEP_SESSION session, const pEp_identity* ident, const char* fpr, bool valid_only); -void print_mail(message* msg); +// Returns the string value of the input rating enum value. +const char* tl_rating_string(PEP_rating rating); +// Returns the string value of the input comm_type enum value. +const char* tl_ct_string(PEP_comm_type ct); +// Returns the string value of the input status enum value. +const char* tl_status_string(PEP_STATUS status); +// Returns the string value of identity flags +std::string tl_ident_flags_String(identity_flags_t fl); -#ifndef ENIGMAIL_MAY_USE_THIS - -// MIME_decrypt_message() - decrypt a MIME message, with MIME output -// -// parameters: -// session (in) session handle -// mimetext (in) MIME encoded text to decrypt -// size (in) size of mime text to decode (in order to decrypt) -// mime_plaintext (out) decrypted, encoded message -// keylist (inout) in: stringlist with additional keyids for reencryption if needed -// (will be freed and replaced with output keylist) -// out: stringlist with keyids -// rating (out) rating for the message -// flags (inout) flags to signal special decryption features (see below) -// modified_src (out) modified source string, if decrypt had reason to change it -// -// return value: -// decrypt status if everything worked with MIME encode/decode, -// the status of the decryption is returned -// (PEP_STATUS_OK or decryption error status) -// PEP_BUFFER_TOO_SMALL if encoded message size is too big to handle -// PEP_CANNOT_CREATE_TEMP_FILE -// if there are issues with temp files; in -// this case errno will contain the underlying -// error -// PEP_OUT_OF_MEMORY if not enough memory could be allocated -// -// flag values: -// in: -// 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. -// out: -// 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 -// PEP_decrypt_flag_ignore -// used by sync -// -// caveat: -// the decrypted, encoded mime text will go to the ownership of the caller; mimetext -// will remain in the ownership of the caller -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 -); - -// MIME_encrypt_message() - encrypt a MIME message, with MIME output -// -// parameters: -// session (in) session handle -// mimetext (in) MIME encoded text to encrypt -// size (in) size of input mime text -// extra (in) extra keys for encryption -// mime_ciphertext (out) encrypted, encoded message -// enc_format (in) encrypted format -// flags (in) flags to set special encryption features -// -// return value: -// PEP_STATUS_OK if everything worked -// PEP_BUFFER_TOO_SMALL if encoded message size is too big to handle -// PEP_CANNOT_CREATE_TEMP_FILE -// if there are issues with temp files; in -// this case errno will contain the underlying -// error -// PEP_OUT_OF_MEMORY if not enough memory could be allocated -// -// caveat: -// the encrypted, encoded mime text will go to the ownership of the caller; 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() - encrypt MIME message for user's identity only, -// ignoring recipients and other identities from -// the message, with MIME output -// parameters: -// session (in) session handle -// target_id (in) self identity this message should be encrypted for -// mimetext (in) MIME encoded text to encrypt -// size (in) size of input mime text -// extra (in) extra keys for encryption -// mime_ciphertext (out) encrypted, encoded message -// enc_format (in) encrypted format -// flags (in) flags to set special encryption features -// -// return value: -// PEP_STATUS_OK if everything worked -// PEP_BUFFER_TOO_SMALL if encoded message size is too big to handle -// PEP_CANNOT_CREATE_TEMP_FILE -// if there are issues with temp files; in -// this case errno will contain the underlying -// error -// PEP_OUT_OF_MEMORY if not enough memory could be allocated -// -// caveat: -// the encrypted, encoded mime text will go to the ownership of the caller; mimetext -// will remain in the ownership of the caller -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 -); +char* message_to_str(message* msg); +message* string_to_msg(std::string infile); +/************************************************************************************ + * We try not to use cout / cerr explicitly unless we set the compile option. This + * is a null error stream that can be used to reduce spam and is set by default. + * Use -DDEBUG_OUTPUT in compilation if you want output_stream to send output to stderr + */ +#ifndef DEBUG_OUTPUT +extern std::ostream output_stream; +#else +#define output_stream std::cerr #endif + +class NullBuffer : public std::streambuf { + public: + int overflow(int c); +}; + #endif diff --git a/test/src/UnencryptedPepMailTest.cc b/test/src/UnencryptedPepMailTest.cc index 548ffc6f..0eb456f9 100644 --- a/test/src/UnencryptedPepMailTest.cc +++ b/test/src/UnencryptedPepMailTest.cc @@ -139,17 +139,6 @@ TEST_F(UnencryptedPepMailTest, check_unencrypted_pep_mail_outgoing_MIME) { ASSERT_EQ(status, PEP_STATUS_OK); ASSERT_NOTNULL(alice); -/* -PEP_STATUS set_up_preset(PEP_SESSION session, - ident_preset preset_name, - bool set_ident, - bool set_pep, - bool trust, - bool set_own, - bool setup_private, - pEp_identity** ident) { -*/ - dave = new_identity("pep-test-dave@pep-project.org", NULL, NULL, "The Hoff"); @@ -161,19 +150,16 @@ PEP_STATUS set_up_preset(PEP_SESSION session, msg->longmsg = strdup("Look, Dave... it's creepy. I'm not getting into your car.\n\n" "I do not want a cup of 'Hoffee', and you are not singlehandedly\n" "responsible for bringing down the Berlin Wall.\n\nGo away. - Alice"); - char* outmsg = NULL; - mime_encode_message(msg, false, &outmsg, false); - char* encmsg = NULL; + + message* encmsg = NULL; - status = MIME_encrypt_message(session, outmsg, strlen(outmsg), NULL, &encmsg, PEP_enc_PGP_MIME, 0); + status = encrypt_message(session, msg, NULL, &encmsg, PEP_enc_PGP_MIME, 0); ASSERT_EQ(status, PEP_UNENCRYPTED); - ASSERT_NOTNULL(encmsg); - + const char* contains = NULL; - contains = strstr(encmsg, "X-pEp-Version"); - ASSERT_NOTNULL(encmsg); - + const stringpair_list_t* sp = stringpair_list_find(msg->opt_fields, X_PEP_MSG_VER_KEY); + // char* outmsg = NULL; // mime_encode_message(msg, false, &outmsg, false); // ofstream outfile; diff --git a/test/src/VerifyTest.cc b/test/src/VerifyTest.cc index b67e8ac4..a8f8cba6 100644 --- a/test/src/VerifyTest.cc +++ b/test/src/VerifyTest.cc @@ -292,15 +292,24 @@ TEST_F(VerifyTest, check_expired_signing_key) { // Let's try again though, this time doing the whole thing, because we should get // an unreliable rating back. + + // Note: we have to add a "from" here or Volker's new ratings tests will scream on + // asserts. I don't want to get into another discussion on our "check by assert" problems - it's a lost + // cause - but we'll miss testing code failure paths unless you guys find a way to run in debug mode + // with asserts off. free(plaintext); plaintext = NULL; free_stringlist(keylist); keylist = NULL; PEP_decrypt_flags_t flags = 0; PEP_rating rating; - char* mod_src = NULL; - MIME_decrypt_message(session, ciphertext.c_str(), ciphertext.size(), - &plaintext, &keylist, &rating, &flags, &mod_src); + message* msg = new_message(PEP_dir_incoming); + msg->longmsg = strdup(ciphertext.c_str()); + msg->from = new_identity("1960@example.org", NULL, "MARY", "Mary Susan Maria Karen Lisa Linda Donna Patricia Smith"); + message* pt_msg = NULL; + decrypt_message(session, msg, &pt_msg, &keylist, &rating, &flags); + free_message(msg); + free_message(pt_msg); ASSERT_EQ(rating, PEP_rating_unreliable); string text = slurp("test_files/pep-test-mary-signed.txt");