ENGINE-448: made key removal much less aggressive. NetPGP will still be a problem, but versions built against gpg will now only remove actual keys
1 // This file is under GNU General Public License 3.0
10 #include "pEpEngine.h"
13 #include "message_api.h"
14 #include "keymanagement.h"
15 #include "test_util.h"
18 #include "EngineTestSessionSuite.h"
19 #include "MessageTwoPointOhTests.h"
23 MessageTwoPointOhTests::MessageTwoPointOhTests(string suitename, string test_home_dir) :
24 EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
25 add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("MessageTwoPointOhTests::check_message_two_point_oh"),
26 static_cast<Func>(&MessageTwoPointOhTests::check_message_two_point_oh)));
29 void MessageTwoPointOhTests::check_message_two_point_oh() {
31 PEP_comm_type carol_comm_type = PEP_ct_OpenPGP_unconfirmed;
33 // message_api test code
35 const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
36 const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
37 const string carol_pub_key = slurp("test_keys/pub/pep-test-carol-0x42A85A42_pub.asc");
38 const string carol_priv_key = slurp("test_keys/priv/pep-test-carol-0x42A85A42_priv.asc");
40 PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
41 PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
42 TEST_ASSERT_MSG((statuspub == PEP_KEY_IMPORTED), "statuspub == PEP_STATUS_OK");
43 TEST_ASSERT_MSG((statuspriv == PEP_KEY_IMPORTED), "statuspriv == PEP_STATUS_OK");
44 statuspub = import_key(session, carol_pub_key.c_str(), carol_pub_key.length(), NULL);
45 statuspriv = import_key(session, carol_priv_key.c_str(), carol_priv_key.length(), NULL);
46 TEST_ASSERT_MSG((statuspub == PEP_KEY_IMPORTED), "statuspub == PEP_STATUS_OK");
47 TEST_ASSERT_MSG((statuspriv == PEP_KEY_IMPORTED), "statuspriv == PEP_STATUS_OK");
49 cout << "creating message…\n";
50 pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", PEP_OWN_USERID, "Alice Test");
51 pEp_identity* carol = new_identity("pep-test-carol@pep-project.org", NULL, "TOFU_pep-test-carol@pep-project.org", "Carol Test");
53 PEP_STATUS alice_status = update_identity(session, alice);
54 PEP_STATUS carol_status = update_identity(session, carol);
56 PEP_STATUS status = update_trust_for_fpr(session, alice->fpr, PEP_ct_pEp);
57 status = update_trust_for_fpr(session, carol->fpr, carol_comm_type);
59 PEP_STATUS mystatus = myself(session, alice);
60 TEST_ASSERT_MSG((mystatus == PEP_STATUS_OK), "mystatus == PEP_STATUS_OK");
61 alice_status = update_identity(session, alice);
62 alice_status = update_identity(session, carol);
63 TEST_ASSERT_MSG((alice->comm_type == PEP_ct_pEp), "alice->comm_type == PEP_ct_pEp");
64 TEST_ASSERT_MSG((carol->comm_type == carol_comm_type), "carol->comm_type == carol_comm_type");
66 identity_list* to_list = new_identity_list(carol); // to carol
67 message* outgoing_message = new_message(PEP_dir_outgoing);
68 TEST_ASSERT_MSG((outgoing_message), "outgoing_message");
69 outgoing_message->from = alice;
70 outgoing_message->to = to_list;
71 outgoing_message->shortmsg = strdup("Greetings, humans!");
72 outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
73 outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
74 // outgoing_message->id = strdup("blahblahyourmama@pep-project.org");
75 outgoing_message->references = new_stringlist("one-839274982347239847@pep-project.org");
76 stringlist_add(outgoing_message->references, "two-dfddffd839274982347239847@pep-project.org");
77 stringlist_add(outgoing_message->references, "three-OMGWTFBBQ.edfddffd839274982347239847@pep-project.org");
79 cout << "message created.\n";
81 char* encoded_text = nullptr;
82 status = mime_encode_message(outgoing_message, false, &encoded_text);
83 TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
84 TEST_ASSERT_MSG((encoded_text), "encoded_text");
86 cout << "unencrypted:\n\n";
87 cout << encoded_text << "\n";
91 cout << "encrypting message as MIME multipart…\n";
92 message* encrypted_msg = nullptr;
93 cout << "calling encrypt_message\n";
94 status = encrypt_message(session, outgoing_message, NULL,
95 &encrypted_msg, PEP_enc_PGP_MIME, 0);
96 cout << "encrypt_message() returns " << tl_status_string(status) << '.' << endl;
97 TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
98 TEST_ASSERT_MSG((encrypted_msg), "encrypted_msg");
99 cout << "message encrypted.\n";
101 encrypted_msg->enc_format = PEP_enc_none;
102 status = mime_encode_message(encrypted_msg, false, &encoded_text);
103 TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
104 TEST_ASSERT_MSG((encoded_text), "encoded_text");
106 cout << "encrypted:\n\n";
107 cout << encoded_text << "\n";
109 char* decrypted_text;
111 message* decrypted_msg = nullptr;
112 stringlist_t* keylist_used = nullptr;
115 PEP_decrypt_flags_t flags = 0;
117 // MIME_decrypt_message(session, encoded_text, strlen(encoded_text), &decrypted_text, &keylist_used, &rating, &flags);
119 // cout << "HEY!" << endl;
120 // cout << decrypted_text << endl;
122 message* decoded_msg = nullptr;
123 status = mime_decode_message(encoded_text, strlen(encoded_text), &decoded_msg);
124 TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
125 const string string3 = encoded_text;
127 unlink("msg_2.0.asc");
128 ofstream outFile3("msg_2.0.asc");
129 outFile3.write(string3.c_str(), string3.size());
132 // message* decrypted_msg = nullptr;
133 // stringlist_t* keylist_used = nullptr;
135 // PEP_rating rating;
136 // PEP_decrypt_flags_t flags;
138 stringpair_t* autoconsume = new_stringpair("pEp-auto-consume", "yes");
139 stringpair_list_add(encrypted_msg->opt_fields, autoconsume);
141 status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
142 TEST_ASSERT_MSG((decrypted_msg), "decrypted_msg");
143 TEST_ASSERT_MSG((keylist_used), "keylist_used");
144 TEST_ASSERT_MSG((rating), "rating");
145 //TEST_ASSERT_MSG((status == PEP_STATUS_OK && rating == PEP_rating_reliable), "status == PEP_STATUS_OK && rating == PEP_rating_reliable");
146 //PEP_comm_type ct = encrypted_msg->from->comm_type;
147 //TEST_ASSERT_MSG((ct == PEP_ct_pEp), "ct == PEP_ct_pEp");
149 cout << "keys used:\n";
151 for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
153 cout << "\t " << kl4->value << endl;
156 decrypted_msg->enc_format = PEP_enc_none;
157 status = _mime_encode_message_internal(decrypted_msg, false, &encoded_text, false);
158 TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
159 TEST_ASSERT_MSG((encoded_text), "encoded_text");
160 cout << "Decrypted message: " << endl;
161 cout << encoded_text << endl;
163 cout << "freeing messages…\n";
164 free_message(encrypted_msg);
165 free_message(decrypted_msg);
166 free_message(outgoing_message);