ENGINE-174: added tests/keys based on Patrick Brunschwig\'s bug description.
5 #include <cstring> // for strcmp()
8 #include "keymanagement.h"
9 #include "message_api.h"
14 int main(int argc, char** argv) {
15 cout << "\n*** least_color_group_test.cc ***\n\n";
17 const char* mailfile = "test_mails/color_test.eml";
19 const char* keynames[] = {"test_keys/priv/pep.color.test.P-0x3EBE215C_priv.asc",
20 "test_keys/pub/pep.color.test.H-0xD17E598E_pub.asc",
21 "test_keys/pub/pep.color.test.L-0xE9CDB4CE_pub.asc",
22 "test_keys/pub/pep.color.test.P-0x3EBE215C_pub.asc",
23 "test_keys/pub/pep.color.test.V-0x71FC6D28_pub.asc"
26 const int num_keyfiles = 5;
30 cout << "calling init()\n";
31 PEP_STATUS status1 = init(&session);
32 assert(status1 == PEP_STATUS_OK);
34 cout << "init() completed.\n";
38 for ( ; i < num_keyfiles; i++) {
39 ifstream infilekey(keynames[i]);
41 while (!infilekey.eof()) {
43 getline(infilekey, line);
44 keytextkey += line + "\n";
47 PEP_STATUS statuskey = import_key(session, keytextkey.c_str(), keytextkey.length(), NULL);
48 assert(statuskey == PEP_STATUS_OK);
51 ifstream infile(mailfile);
53 while (!infile.eof()) {
55 getline(infile, line);
56 mailtext += line + "\n";
60 pEp_identity * me1 = new_identity("pep.color.test.P@kgrothoff.org", NULL,
61 PEP_OWN_USERID, "Pep Color Test P (recip)");
63 PEP_STATUS status = update_identity(session, me1);
64 trust_personal_key(session, me1);
65 status = update_identity(session, me1);
67 pEp_identity * sender1 = new_identity("pep.color.test.V@kgrothoff.org",
68 NULL, "TOFU_pep.color.test.V@kgrothoff.org",
69 "Pep Color Test V (sender)");
72 status = update_identity(session, sender1);
73 trust_personal_key(session, sender1);
74 status = update_identity(session, sender1);
76 message* msg_ptr = nullptr;
77 message* dest_msg = nullptr;
78 message* final_ptr = nullptr;
79 stringlist_t* keylist = nullptr;
81 PEP_decrypt_flags_t flags;
83 status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
84 assert(status == PEP_STATUS_OK);
87 status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
88 final_ptr = dest_msg ? dest_msg : msg_ptr;
90 cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
91 cout << "longmsg: " << final_ptr->longmsg << endl << endl;
92 cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
93 cout << "rating: " << rating << endl << endl;
94 cout << "keys used: " << endl;
96 for (stringlist_t* k = keylist; k; k = k->next) {
98 cout << "\t Signer (key 0):\t" << k->value << endl;
100 cout << "\t #" << i << ":\t" << k->value << endl;
104 // free_identity(me1);
105 if (final_ptr == dest_msg)
106 free_message(dest_msg);
107 free_message(msg_ptr);
108 free_stringlist(keylist);
110 cout << "calling release()\n";