Browse Source

Removed all MIME_encrypt/decrypt functions from tests and aux_mime_msg.* from the source. App builds may need to adjust!

IPS-2
Krista Bennett 4 months ago
parent
commit
da99a8dd14
19 changed files with 233 additions and 1243 deletions
  1. +1
    -1
      src/Makefile
  2. +0
    -286
      src/aux_mime_msg.c
  3. +0
    -187
      src/aux_mime_msg.h
  4. +5
    -12
      test/src/CheckRenewedExpiredKeyTrustStatusTest.cc
  5. +8
    -12
      test/src/DecryptAttachPrivateKeyTrustedTest.cc
  6. +16
    -10
      test/src/DecryptAttachPrivateKeyUntrustedTest.cc
  7. +15
    -99
      test/src/EncryptForIdentityTest.cc
  8. +10
    -16
      test/src/Engine463Test.cc
  9. +23
    -24
      test/src/KeyResetMessageTest.cc
  10. +8
    -30
      test/src/Message2_1Test.cc
  11. +7
    -30
      test/src/MessageNullFromTest.cc
  12. +0
    -5
      test/src/MessageTwoPointOhTest.cc
  13. +11
    -29
      test/src/OldMessageApiTest.cc
  14. +24
    -28
      test/src/PassphraseTest.cc
  15. +9
    -9
      test/src/ReencryptPlusExtraKeysTest.cc
  16. +22
    -270
      test/src/TestUtilities.cc
  17. +56
    -172
      test/src/TestUtilities.h
  18. +6
    -20
      test/src/UnencryptedPepMailTest.cc
  19. +12
    -3
      test/src/VerifyTest.cc

+ 1
- 1
src/Makefile View File

@ -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.


+ 0
- 286
src/aux_mime_msg.c View File

@ -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

+ 0
- 187
src/aux_mime_msg.h View File

@ -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

+ 5
- 12
test/src/CheckRenewedExpiredKeyTrustStatusTest.cc View File

@ -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);


+ 8
- 12
test/src/DecryptAttachPrivateKeyTrustedTest.cc View File

@ -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);


+ 16
- 10
test/src/DecryptAttachPrivateKeyUntrustedTest.cc View File

@ -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???
}

+ 15
- 99
test/src/EncryptForIdentityTest.cc View File

@ -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;
}

+ 10
- 16
test/src/Engine463Test.cc View File

@ -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);


+ 23
- 24
test/src/KeyResetMessageTest.cc View File

@ -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<message*>::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;


+ 8
- 30
test/src/Message2_1Test.cc View File

@ -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) {


+ 7
- 30
test/src/MessageNullFromTest.cc View File

@ -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);
}

+ 0
- 5
test/src/MessageTwoPointOhTest.cc View File

@ -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;


+ 11
- 29
test/src/OldMessageApiTest.cc View File

@ -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 <vb@pep-project.org>\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);
}

+ 24
- 28
test/src/PassphraseTest.cc View File

@ -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);
}


+ 9
- 9
test/src/ReencryptPlusExtraKeysTest.cc View File

@ -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 */


+ 22
- 270
test/src/TestUtilities.cc View File

@ -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