Ok, all tests are in the infrastructure, though we now need to move the auxiliary files somewhere useful and update the tests. local_cpptest
authorKrista Bennett <krista@pep-project.org>
Tue, 08 May 2018 15:43:07 +0200
branchlocal_cpptest
changeset 26612b0b15a718bc
parent 2660 485b9eaf1b5d
child 2662 8179ef5e6b4c
Ok, all tests are in the infrastructure, though we now need to move the auxiliary files somewhere useful and update the tests.
test/convenience_scripts/compile_it.sh
test/convenience_scripts/mime_decrypt.cc
test/convenience_scripts/mime_encrypt.cc
test/convenience_scripts/mime_encrypt_decrypt.cc
test/convenience_scripts/temp_convert_script.py
test/encrypt_missing_private_key_test.cc
test/external_revoke_test.cc
test/i18n_test.cc
test/identity_list_test.cc
test/keyedit_test.cc
test/least_color_group_test.cc
test/least_common_denom_color_test.cc
test/map_asn1_test.cc
test/message_api_test.cc
test/message_two_point_oh_test.cc
test/mime_test.cc
test/mistrust_undo_test.cc
test/new_update_id_and_myself_test.cc
test/pEp_subject_received_test.cc
test/pgp_binary_test.cc
test/pgp_list_keys_test.cc
test/reencrypt_plus_extra_keys_test.cc
test/revoke_regen_attach_test.cc
test/src/engine_tests/EncryptMissingPrivateKeyTests.cc
test/src/engine_tests/ExternalRevokeTests.cc
test/src/engine_tests/I18nTests.cc
test/src/engine_tests/IdentityListTests.cc
test/src/engine_tests/KeyeditTests.cc
test/src/engine_tests/LeastColorGroupTests.cc
test/src/engine_tests/LeastCommonDenomColorTests.cc
test/src/engine_tests/MapAsn1Tests.cc
test/src/engine_tests/MessageApiTests.cc
test/src/engine_tests/MessageTwoPointOhTests.cc
test/src/engine_tests/MimeTests.cc
test/src/engine_tests/MistrustUndoTests.cc
test/src/engine_tests/NewUpdateIdAndMyselfTests.cc
test/src/engine_tests/PepSubjectReceivedTests.cc
test/src/engine_tests/PgpBinaryTests.cc
test/src/engine_tests/PgpListKeysTests.cc
test/src/engine_tests/ReencryptPlusExtraKeysTests.cc
test/src/engine_tests/RevokeRegenAttachTests.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/convenience_scripts/compile_it.sh	Tue May 08 15:43:07 2018 +0200
     1.3 @@ -0,0 +1,6 @@
     1.4 +#!/bin/bash
     1.5 +g++ -std=gnu++11 -pthread -fdiagnostics-color=always -I../src -I../asn.1 -I/home/krista/include -I./include -g -ggdb   -c -o $1.o $1.cc
     1.6 +#g++ -std=gnu++11 -pthread -fdiagnostics-color=always -I../src -I../asn.1 -I/home/krista/include -I./include -g -ggdb   -c -o test_util.o src/util/test_util.cc
     1.7 +g++ -std=gnu++11 -pthread -fdiagnostics-color=always -I../src -I../asn.1 -I/home/krista/include -I./include -g -ggdb   -c -o test_util.o test_util.cc
     1.8 +g++ -std=gnu++11 -pthread $1.o test_util.o  -L/home/krista/lib -L../asn.1 -L../src  -letpan -lpEpEngine -lstdc++ -lasn1 -luuid -lsqlite3 -o $1
     1.9 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/convenience_scripts/mime_decrypt.cc	Tue May 08 15:43:07 2018 +0200
     2.3 @@ -0,0 +1,52 @@
     2.4 +// This file is under GNU General Public License 3.0
     2.5 +// see LICENSE.txt
     2.6 +
     2.7 +#include <stdlib.h>
     2.8 +#include <string.h>
     2.9 +#include "platform.h"
    2.10 +#include <iostream>
    2.11 +#include <fstream>
    2.12 +#include <assert.h>
    2.13 +#include "mime.h"
    2.14 +#include "message_api.h"
    2.15 +#include "keymanagement.h"
    2.16 +#include "test_util.h"
    2.17 +
    2.18 +using namespace std;
    2.19 +
    2.20 +int main(int argc, char* argv[]) {
    2.21 +    cout << "\n*** MIME encrypt and decrypt testing program ***\n\n";
    2.22 +
    2.23 +    PEP_SESSION session;
    2.24 +    
    2.25 +    cout << "calling init()\n";
    2.26 +    PEP_STATUS status = init(&session);
    2.27 +    assert(status == PEP_STATUS_OK);
    2.28 +    assert(session);
    2.29 +    cout << "init() completed.\n";
    2.30 +
    2.31 +    if (argc < 2) {
    2.32 +        cout << "ERROR: filename required." << endl;
    2.33 +        return -1;
    2.34 +    }
    2.35 +        
    2.36 +    const string mailfile = slurp(argv[1]);
    2.37 +    char* dec_msg = NULL;
    2.38 +    
    2.39 +    stringlist_t* keylist = NULL;
    2.40 +    
    2.41 +    PEP_rating rating;
    2.42 +    PEP_decrypt_flags_t flags;
    2.43 +    
    2.44 +    flags = 0;
    2.45 +    char* modified_src = NULL;
    2.46 +    status = MIME_decrypt_message(session, mailfile.c_str(), mailfile.size(), &dec_msg, &keylist, &rating, &flags, &modified_src);
    2.47 +
    2.48 +    cout << dec_msg << endl << endl;
    2.49 +
    2.50 +    cout << "Rating is " << tl_rating_string(rating) << endl;
    2.51 +    
    2.52 +    release(session);
    2.53 +    return 0;
    2.54 +}
    2.55 +    
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/convenience_scripts/mime_encrypt.cc	Tue May 08 15:43:07 2018 +0200
     3.3 @@ -0,0 +1,43 @@
     3.4 +// This file is under GNU General Public License 3.0
     3.5 +// see LICENSE.txt
     3.6 +
     3.7 +#include <stdlib.h>
     3.8 +#include <string.h>
     3.9 +#include "platform.h"
    3.10 +#include <iostream>
    3.11 +#include <fstream>
    3.12 +#include <assert.h>
    3.13 +#include "mime.h"
    3.14 +#include "message_api.h"
    3.15 +#include "keymanagement.h"
    3.16 +#include "test_util.h"
    3.17 +
    3.18 +using namespace std;
    3.19 +
    3.20 +int main(int argc, char* argv[]) {
    3.21 +    cout << "\n*** MIME encrypt and decrypt testing program ***\n\n";
    3.22 +
    3.23 +    PEP_SESSION session;
    3.24 +    
    3.25 +    cout << "calling init()\n";
    3.26 +    PEP_STATUS status = init(&session);
    3.27 +    assert(status == PEP_STATUS_OK);
    3.28 +    assert(session);
    3.29 +    cout << "init() completed.\n";
    3.30 +
    3.31 +    if (argc < 2) {
    3.32 +        cout << "ERROR: filename required." << endl;
    3.33 +        return -1;
    3.34 +    }
    3.35 +        
    3.36 +    const string mailfile = slurp(argv[1]);
    3.37 +    char* enc_msg = NULL;
    3.38 +    
    3.39 +    status = MIME_encrypt_message(session, mailfile.c_str(), mailfile.size(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    3.40 +    
    3.41 +    cout << enc_msg << endl << endl;
    3.42 +
    3.43 +    release(session);
    3.44 +    return 0;
    3.45 +}
    3.46 +    
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/convenience_scripts/mime_encrypt_decrypt.cc	Tue May 08 15:43:07 2018 +0200
     4.3 @@ -0,0 +1,55 @@
     4.4 +// This file is under GNU General Public License 3.0
     4.5 +// see LICENSE.txt
     4.6 +
     4.7 +#include <stdlib.h>
     4.8 +#include <string.h>
     4.9 +#include "platform.h"
    4.10 +#include <iostream>
    4.11 +#include <fstream>
    4.12 +#include <assert.h>
    4.13 +#include "mime.h"
    4.14 +#include "message_api.h"
    4.15 +#include "keymanagement.h"
    4.16 +#include "test_util.h"
    4.17 +
    4.18 +using namespace std;
    4.19 +
    4.20 +int main(int argc, char* argv[]) {
    4.21 +    cout << "\n*** MIME encrypt and decrypt testing program ***\n\n";
    4.22 +
    4.23 +    PEP_SESSION session;
    4.24 +    
    4.25 +    cout << "calling init()\n";
    4.26 +    PEP_STATUS status = init(&session);
    4.27 +    assert(status == PEP_STATUS_OK);
    4.28 +    assert(session);
    4.29 +    cout << "init() completed.\n";
    4.30 +
    4.31 +    if (argc < 2) {
    4.32 +        cout << "ERROR: filename required." << endl;
    4.33 +        return -1;
    4.34 +    }
    4.35 +        
    4.36 +    const string mailfile = slurp(argv[1]);
    4.37 +    char* enc_msg = NULL;
    4.38 +    char* dec_msg = NULL;
    4.39 +    
    4.40 +    status = MIME_encrypt_message(session, mailfile.c_str(), mailfile.size(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    4.41 +    
    4.42 +    cout << enc_msg << endl << endl;
    4.43 +
    4.44 +    stringlist_t* keylist = NULL;
    4.45 +    
    4.46 +    PEP_rating rating;
    4.47 +    PEP_decrypt_flags_t flags;
    4.48 +    char* modified_src = NULL;
    4.49 +    
    4.50 +    flags = 0;
    4.51 +    status = MIME_decrypt_message(session, enc_msg, strlen(enc_msg), &dec_msg, &keylist, &rating, &flags, &modified_src);
    4.52 +
    4.53 +    cout << dec_msg << endl << endl;
    4.54 +    
    4.55 +    release(session);
    4.56 +    return 0;
    4.57 +}
    4.58 +    
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/convenience_scripts/temp_convert_script.py	Tue May 08 15:43:07 2018 +0200
     5.3 @@ -0,0 +1,23 @@
     5.4 +# This file is under GNU General Public License 3.0
     5.5 +# see LICENSE.txt
     5.6 +
     5.7 +from os import listdir, getcwd
     5.8 +from os.path import isfile, join
     5.9 +import re
    5.10 +import string
    5.11 +import subprocess
    5.12 +
    5.13 +srcpath = getcwd()
    5.14 +
    5.15 +ls = listdir(srcpath)
    5.16 +
    5.17 +files = []
    5.18 +
    5.19 +for f in ls:
    5.20 +    if isfile(join(srcpath, f)):
    5.21 +        if (f.endswith("_test.cc")):
    5.22 +            testname = re.sub('_test.cc$', r'', f)
    5.23 +            testname = (string.capwords(testname,'_')).replace("_", "")
    5.24 +            CMD_STR = "python3 ./gentestshell.py -c -s " + testname
    5.25 +            print(CMD_STR)
    5.26 +            subprocess.run(CMD_STR.split(' '))
     6.1 --- a/test/encrypt_missing_private_key_test.cc	Tue May 08 11:09:11 2018 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,79 +0,0 @@
     6.4 -// This file is under GNU General Public License 3.0
     6.5 -// see LICENSE.txt
     6.6 -
     6.7 -#include <iostream>
     6.8 -#include <iostream>
     6.9 -#include <fstream>
    6.10 -#include <string>
    6.11 -#include <cstring> // for strcmp()
    6.12 -#include <assert.h>
    6.13 -#include "blacklist.h"
    6.14 -#include "keymanagement.h"
    6.15 -#include "message_api.h"
    6.16 -#include "mime.h"
    6.17 -#include "test_util.h"
    6.18 -
    6.19 -using namespace std;
    6.20 -
    6.21 -int main() {
    6.22 -    cout << "\n*** encrypt_missing_private_key_test ***\n\n";
    6.23 -
    6.24 -    PEP_SESSION session;
    6.25 -    
    6.26 -    cout << "calling init()\n";
    6.27 -    PEP_STATUS status1 = init(&session);   
    6.28 -    assert(status1 == PEP_STATUS_OK);
    6.29 -    assert(session);
    6.30 -    cout << "init() completed.\n";
    6.31 -    
    6.32 -    pEp_identity* no_key_identity = new_identity("blacklistself@kgrothoff.org",
    6.33 -                                                      NULL,
    6.34 -                                                      PEP_OWN_USERID,
    6.35 -                                                      "Blacklist Self");
    6.36 -    no_key_identity->me = true;
    6.37 -    PEP_STATUS status8 = myself(session, no_key_identity);
    6.38 -    assert (status8 == PEP_STATUS_OK);
    6.39 -
    6.40 -    /* Now let's try to encrypt a message. */
    6.41 -        
    6.42 -    message* tmp_msg = NULL;
    6.43 -    message* enc_msg = NULL;
    6.44 -    
    6.45 -    const string mailtext = slurp("test_mails/blacklist_no_key.eml");
    6.46 -
    6.47 -    PEP_STATUS status = mime_decode_message(mailtext.c_str(), mailtext.length(), &tmp_msg);
    6.48 -    assert(status == PEP_STATUS_OK);
    6.49 -    
    6.50 -    status = update_identity(session, tmp_msg->from);
    6.51 -    identity_list* to_list = tmp_msg->to;
    6.52 -
    6.53 -    while (to_list) {
    6.54 -        if (to_list->ident)
    6.55 -            update_identity(session, to_list->ident);
    6.56 -        to_list = to_list->next;
    6.57 -    }
    6.58 -    
    6.59 -    // This isn't incoming, though... so we need to reverse the direction
    6.60 -    tmp_msg->dir = PEP_dir_outgoing;
    6.61 -    status = encrypt_message(session,
    6.62 -                             tmp_msg,
    6.63 -                             NULL,
    6.64 -                             &enc_msg,
    6.65 -                             PEP_enc_PGP_MIME,
    6.66 -                             0);
    6.67 -    assert(status == PEP_STATUS_OK);
    6.68 -    
    6.69 -
    6.70 -    char* new_key = enc_msg->from->fpr;
    6.71 -    cout << "Encrypted with key " << new_key << endl;
    6.72 -    
    6.73 -    status = delete_keypair(session, new_key);
    6.74 -    PEP_STATUS status14 = myself(session, no_key_identity);
    6.75 -
    6.76 -    free_message(tmp_msg);    
    6.77 -    free_message(enc_msg);
    6.78 -    
    6.79 -    cout << "calling release()\n";
    6.80 -    release(session);
    6.81 -    return 0;
    6.82 -}
     7.1 --- a/test/external_revoke_test.cc	Tue May 08 11:09:11 2018 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,310 +0,0 @@
     7.4 -// This file is under GNU General Public License 3.0
     7.5 -// see LICENSE.txt
     7.6 -
     7.7 -#include <stdlib.h>
     7.8 -#include <string.h>
     7.9 -#include <time.h>
    7.10 -#include "platform.h"
    7.11 -#include <iostream>
    7.12 -#include <fstream>
    7.13 -#include <assert.h>
    7.14 -#include "mime.h"
    7.15 -#include "message_api.h"
    7.16 -#include "test_util.h"
    7.17 -
    7.18 -using namespace std;
    7.19 -
    7.20 -int main() {
    7.21 -    cout << "\n*** external_revoke_test.cc ***\n\n";
    7.22 -
    7.23 -    PEP_SESSION session;
    7.24 -    
    7.25 -    cout << "calling init()\n";
    7.26 -    PEP_STATUS status = init(&session);   
    7.27 -    assert(status == PEP_STATUS_OK);
    7.28 -    assert(session);
    7.29 -    cout << "init() completed.\n";
    7.30 -
    7.31 -#ifndef NETPGP
    7.32 -    char* fprs[2];
    7.33 -
    7.34 -    const string fenris_pub_key = slurp("test_keys/pub/pep.test.fenris-0x4F3D2900_pub.asc");
    7.35 -    const string fenris_priv_key = slurp("test_keys/priv/pep.test.fenris-0x4F3D2900_priv.asc");
    7.36 -
    7.37 -    assert(fenris_pub_key.length() != 0);
    7.38 -    assert(fenris_priv_key.length() != 0);
    7.39 -    
    7.40 -    PEP_STATUS statuspub = import_key(session, fenris_pub_key.c_str(), fenris_pub_key.length(), NULL);
    7.41 -    PEP_STATUS statuspriv = import_key(session, fenris_priv_key.c_str(), fenris_priv_key.length(), NULL);
    7.42 -    assert(statuspub == PEP_STATUS_OK);
    7.43 -    assert(statuspriv == PEP_STATUS_OK);
    7.44 -
    7.45 -    // Create sender ID
    7.46 -    
    7.47 -    pEp_identity * me = new_identity("pep.test.fenris@thisstilldoesntwork.lu", "0969FA229DF21C832A64A04711B1B9804F3D2900", PEP_OWN_USERID, "Fenris Hawke");
    7.48 -    status = myself(session, me);
    7.49 -    
    7.50 -    // Create key
    7.51 -    cout << "Creating new id for : ";
    7.52 -    char *uniqname = strdup("AAAAtestuser@testdomain.org");
    7.53 -    srandom(time(NULL));
    7.54 -    for(int i=0; i < 4;i++)
    7.55 -        uniqname[i] += random() & 0xf;
    7.56 -    
    7.57 -    cout << uniqname << "\n";
    7.58 -    pEp_identity * recip1 = new_identity(uniqname, NULL, NULL, "Test User");
    7.59 -
    7.60 -    status = generate_keypair(session, recip1);
    7.61 -    
    7.62 -    cout << "Generated fingerprint ";
    7.63 -    cout << recip1->fpr << "\n";
    7.64 -
    7.65 -    fprs[0] = strdup(recip1->fpr);
    7.66 -    
    7.67 -    cout << endl << "*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*" << endl;
    7.68 -    cout << "Trust and revoke single key, ensure trust changes, then generate new key and ensure rating is correct." << endl;
    7.69 -    cout << "*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*" << endl << endl;
    7.70 -    
    7.71 -    cout << endl << "---------------------------------------------------------" << endl;
    7.72 -    cout << "1a. Encrypt message for trusted partner." << endl;
    7.73 -    cout << "---------------------------------------------------------" << endl << endl;
    7.74 -
    7.75 -    cout << "Trusting personal key for " << uniqname << endl;
    7.76 -    recip1->me = false;
    7.77 -    // Trust it
    7.78 -    status = update_identity(session, recip1);
    7.79 -    status = trust_personal_key(session, recip1);
    7.80 -    status = update_identity(session, recip1);
    7.81 -    
    7.82 -    // TODO: Check trust?
    7.83 -    cout << "Done! Trusted personal key with fpr " << recip1->fpr << " for " << uniqname << endl;
    7.84 -
    7.85 -    const char* r1_userid = (recip1->user_id ? strdup(recip1->user_id) : NULL);
    7.86 -
    7.87 -    
    7.88 -    // encrypt something to the key
    7.89 -    cout << "Creating message…\n";
    7.90 -    identity_list* to_list = new_identity_list(identity_dup(recip1)); // to bob
    7.91 -    message* outgoing_msg = new_message(PEP_dir_outgoing);
    7.92 -    assert(outgoing_msg);
    7.93 -    outgoing_msg->from = identity_dup(me);
    7.94 -    outgoing_msg->to = to_list;
    7.95 -    outgoing_msg->shortmsg = strdup("Greetings, humans!");
    7.96 -    outgoing_msg->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
    7.97 -    outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
    7.98 -    cout << "Message created.\n";
    7.99 -
   7.100 -    message* encrypted_outgoing_msg = NULL;
   7.101 -
   7.102 -    cout << "Encrypting message to " << uniqname << "…\n";    
   7.103 -    status = encrypt_message(session, outgoing_msg, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
   7.104 -    cout << "Encrypted message with status " << tl_status_string(status) << endl;
   7.105 -    // check status
   7.106 -    assert(status == PEP_STATUS_OK);
   7.107 -    assert(encrypted_outgoing_msg);
   7.108 -
   7.109 -    cout << "Checking message recipient comm_type from message." << endl;
   7.110 -    // check comm_type
   7.111 -    cout << "comm_type: " << tl_ct_string(encrypted_outgoing_msg->to->ident->comm_type) << endl;
   7.112 -    assert(encrypted_outgoing_msg->to->ident->comm_type == PEP_ct_OpenPGP);
   7.113 -    
   7.114 -    status = get_trust(session, recip1);
   7.115 -    
   7.116 -    cout << "Recip's trust DB comm_type = " << hex << tl_ct_string(recip1->comm_type) << endl;
   7.117 -    assert(recip1->comm_type == PEP_ct_OpenPGP); // FIXME: PEP_ct_pEp???
   7.118 -
   7.119 -    // decrypt message
   7.120 -    free_message(outgoing_msg);
   7.121 -    outgoing_msg = NULL;
   7.122 -
   7.123 -    stringlist_t* keylist = nullptr;
   7.124 -    PEP_rating rating;
   7.125 -    PEP_decrypt_flags_t flags;
   7.126 -
   7.127 -    cout << endl << "---------------------------------------------------------" << endl;
   7.128 -    cout << "1b. Decrypt message that was encrypted for trusted partner." << endl;
   7.129 -    cout << "---------------------------------------------------------" << endl << endl;
   7.130 -
   7.131 -    flags = 0;
   7.132 -    cout << "Decrypting message." << endl;
   7.133 -    status = decrypt_message(session, encrypted_outgoing_msg, &outgoing_msg, &keylist, &rating, &flags);
   7.134 -    cout << "Decrypted message with status " << tl_status_string(status) << endl;
   7.135 -    assert(status == PEP_STATUS_OK);
   7.136 -    assert(rating == PEP_rating_trusted);
   7.137 -
   7.138 -    // check rating
   7.139 -    cout << "Rating of decrypted message to trusted recip: " << tl_rating_string(rating) << endl;
   7.140 -    assert(rating == PEP_rating_trusted); // FIXME: trusted and anonymised?
   7.141 -    
   7.142 -    // check comm_type
   7.143 -    status = get_trust(session, recip1);
   7.144 -
   7.145 -    cout << "Recip's trust DB comm_type = " << tl_ct_string(recip1->comm_type) << endl;
   7.146 -    assert(recip1->comm_type == PEP_ct_OpenPGP); // FIXME: PEP_ct_pEp???
   7.147 -
   7.148 -    cout << endl << "---------------------------------------------------------" << endl;
   7.149 -    cout << "2a. Revoke key for (currently) trusted partner." << endl;
   7.150 -    cout << "---------------------------------------------------------" << endl << endl;
   7.151 -    // externally revoke key
   7.152 -    // (note - as of 23.5.17, revoke_key() doesn't touch the trust db, just the keyring, so we can do this)
   7.153 -
   7.154 -    cout << "Revoking key." << endl;
   7.155 -    status = update_identity(session, recip1);    
   7.156 -    status = revoke_key(session, recip1->fpr, "encrypt_for_identity_test");
   7.157 -    cout << "Status of revocation call for " << recip1->fpr << " is "<< tl_status_string(status) << endl;
   7.158 -
   7.159 -    // free messages
   7.160 -    free_message(outgoing_msg);
   7.161 -    free_message(encrypted_outgoing_msg);
   7.162 -    outgoing_msg = NULL;
   7.163 -    encrypted_outgoing_msg = NULL;
   7.164 -    
   7.165 -    // encrypt something to the key
   7.166 -    cout << "creating message…\n";
   7.167 -    to_list = new_identity_list(identity_dup(recip1)); // to bob
   7.168 -    outgoing_msg = new_message(PEP_dir_outgoing);
   7.169 -    assert(outgoing_msg);
   7.170 -    outgoing_msg->from = identity_dup(me);
   7.171 -    outgoing_msg->to = to_list;
   7.172 -    outgoing_msg->shortmsg = strdup("Greetings, humans!");
   7.173 -    outgoing_msg->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   7.174 -    outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   7.175 -    cout << "message created.\n";
   7.176 -
   7.177 -    encrypted_outgoing_msg = NULL;
   7.178 -    message* decrypted_msg = NULL;
   7.179 -
   7.180 -    cout << endl << "---------------------------------------------------------" << endl;
   7.181 -    cout << "2b. Encrypt message for recip whose key has been externally revoked in the keyring, not the app." << endl;
   7.182 -    cout << "---------------------------------------------------------" << endl << endl;
   7.183 -
   7.184 -
   7.185 -    status = encrypt_message(session, outgoing_msg, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
   7.186 -    cout << "Encryption returns with status " << tl_status_string(status) << endl;
   7.187 -    assert (status == PEP_UNENCRYPTED);
   7.188 -    assert (encrypted_outgoing_msg == NULL);
   7.189 -    status = update_identity(session, recip1);
   7.190 -    assert(recip1->comm_type = PEP_ct_key_not_found);
   7.191 -
   7.192 -    cout << endl << "---------------------------------------------------------" << endl;
   7.193 -    cout << "2c. Check trust of recip, whose only key has been revoked, once an encryption attempt has been made." << endl;
   7.194 -    cout << "---------------------------------------------------------" << endl << endl;
   7.195 -
   7.196 -    assert(recip1->fpr == NULL);
   7.197 -    recip1->fpr = fprs[0];
   7.198 -    status = get_trust(session, recip1);
   7.199 -    recip1->fpr = NULL;
   7.200 -
   7.201 -    cout << "Recip's trust DB comm_type = " << hex << tl_ct_string(recip1->comm_type) << endl;
   7.202 -    assert(recip1->comm_type == PEP_ct_unknown || recip1->comm_type == PEP_ct_key_revoked);
   7.203 -
   7.204 -    free_message(decrypted_msg);
   7.205 -    free_message(outgoing_msg);
   7.206 -    outgoing_msg = NULL;
   7.207 -    decrypted_msg = NULL;
   7.208 -
   7.209 -    cout << endl << "---------------------------------------------------------" << endl;
   7.210 -    cout << "3a. Generate new key, but don't explicitly trust it." << endl;
   7.211 -    cout << "---------------------------------------------------------" << endl << endl;
   7.212 -
   7.213 -    // now: generate new key
   7.214 -    free(recip1->fpr);
   7.215 -    recip1->fpr = NULL;
   7.216 -    status = generate_keypair(session, recip1);
   7.217 -    
   7.218 -    cout << "Generated fingerprint \n";
   7.219 -    cout << recip1->fpr << "\n";
   7.220 -    fprs[1] = strdup(recip1->fpr);
   7.221 -
   7.222 -    // try again
   7.223 -    cout << endl << "---------------------------------------------------------" << endl;
   7.224 -    cout << "3b. Try to send something to the email address of our revoked friend, make sure a new key is used to encrypt." << endl;
   7.225 -    cout << "---------------------------------------------------------" << endl << endl;
   7.226 -    
   7.227 -    // encrypt something to the key
   7.228 -    cout << "Creating message…\n";
   7.229 -    
   7.230 -    // cout << "First, update identity though!\n";
   7.231 -    // status = update_identity(session, recip1);
   7.232 -    to_list = new_identity_list(identity_dup(recip1)); // to bob
   7.233 -    outgoing_msg = new_message(PEP_dir_outgoing);
   7.234 -    assert(outgoing_msg);
   7.235 -    outgoing_msg->from = identity_dup(me);
   7.236 -    outgoing_msg->to = to_list;
   7.237 -    outgoing_msg->shortmsg = strdup("Greetings, humans!");
   7.238 -    outgoing_msg->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   7.239 -    outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   7.240 -    cout << "Message created.\n";
   7.241 -
   7.242 -    status = encrypt_message(session, outgoing_msg, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
   7.243 -    PEP_comm_type ct = (encrypted_outgoing_msg ? encrypted_outgoing_msg->to->ident->comm_type : outgoing_msg->to->ident->comm_type);
   7.244 -    
   7.245 -
   7.246 -    // CHECK STATUS???
   7.247 -    cout << "Encryption returns with status " << tl_status_string(status) << endl;
   7.248 -
   7.249 -    // check comm_type
   7.250 -    cout << "comm_type: " << tl_ct_string(ct) << endl;
   7.251 -    assert(ct == PEP_ct_OpenPGP_unconfirmed);
   7.252 -    
   7.253 -    status = get_trust(session, recip1);
   7.254 -
   7.255 -    cout << "Recip's trust DB comm_type (should be unknown, as we're using a keyring-only key, not in DB) = " << hex << tl_ct_string(recip1->comm_type) << endl;
   7.256 -    assert(recip1->comm_type != PEP_ct_OpenPGP_unconfirmed);
   7.257 -
   7.258 -    // decrypt message
   7.259 -//    free_message(outgoing_msg);
   7.260 -//    outgoing_msg = NULL;
   7.261 -
   7.262 -    cout << endl << "---------------------------------------------------------" << endl;
   7.263 -    cout << "3c. Decrypt... that... message!" << endl;
   7.264 -    cout << "---------------------------------------------------------" << endl << endl;
   7.265 -
   7.266 -
   7.267 -    flags = 0;
   7.268 -    status = decrypt_message(session, encrypted_outgoing_msg, &decrypted_msg, &keylist, &rating, &flags);
   7.269 -    cout << "Decryption returns with status " << tl_status_string(status) << endl;
   7.270 -    assert(status == PEP_STATUS_OK);
   7.271 -    assert(decrypted_msg);
   7.272 -    
   7.273 -    // check rating
   7.274 -    cout << "Rating of decrypted message to trusted recip: " << tl_rating_string(rating) << endl;
   7.275 -    assert(rating == PEP_rating_reliable);
   7.276 -
   7.277 -    status = update_identity(session, decrypted_msg->to->ident);
   7.278 -    ct = (decrypted_msg ? decrypted_msg->to->ident->comm_type : outgoing_msg->to->ident->comm_type);
   7.279 -
   7.280 -    cout << "comm_type: " << tl_ct_string(ct) << endl;
   7.281 -    assert(ct == PEP_ct_OpenPGP_unconfirmed);
   7.282 -    
   7.283 -    status = get_trust(session, recip1);
   7.284 -    
   7.285 -    cout << "Recip's trust DB comm_type (should be unknown - there's nothing in the DB) = " << hex << tl_ct_string(recip1->comm_type) << endl;
   7.286 -    assert(recip1->comm_type == PEP_ct_unknown);
   7.287 -
   7.288 -    free_message(encrypted_outgoing_msg);
   7.289 -    free_message(decrypted_msg);
   7.290 -    free_message(outgoing_msg);
   7.291 -    outgoing_msg = NULL;
   7.292 -    decrypted_msg = NULL;
   7.293 -    encrypted_outgoing_msg = NULL;
   7.294 -
   7.295 -    free_identity(me);
   7.296 -    free_identity(recip1);
   7.297 -    free(uniqname);
   7.298 -    
   7.299 -    delete_keypair(session, fprs[0]);    
   7.300 -    delete_keypair(session, fprs[1]);
   7.301 -    
   7.302 -    free(fprs[0]);
   7.303 -    free(fprs[1]);
   7.304 -    
   7.305 -#else
   7.306 -    cout << "Sorry, test is not defined for NETPGP at this time." << endl;
   7.307 -    
   7.308 -#endif
   7.309 -    
   7.310 -    release(session);
   7.311 -
   7.312 -    return 0;
   7.313 -}
     8.1 --- a/test/i18n_test.cc	Tue May 08 11:09:11 2018 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,48 +0,0 @@
     8.4 -// This file is under GNU General Public License 3.0
     8.5 -// see LICENSE.txt
     8.6 -
     8.7 -#include <iostream>
     8.8 -#include <string>
     8.9 -#include <assert.h>
    8.10 -#include "pEpEngine.h"
    8.11 -
    8.12 -using namespace std;
    8.13 -
    8.14 -int main() {
    8.15 -    cout << "\n*** i18n_test ***\n\n";
    8.16 -
    8.17 -    PEP_SESSION session;
    8.18 -    
    8.19 -    cout << "calling init()\n";
    8.20 -    PEP_STATUS status1 = init(&session);   
    8.21 -    assert(status1 == PEP_STATUS_OK);
    8.22 -    assert(session);
    8.23 -    cout << "init() completed.\n";
    8.24 -
    8.25 -    // i18n test code
    8.26 -
    8.27 -    char *languages;
    8.28 -    PEP_STATUS status2 = get_languagelist(session, &languages);
    8.29 -    assert(status2 == PEP_STATUS_OK);
    8.30 -    assert(languages);
    8.31 -
    8.32 -    cout << languages;
    8.33 -    pEp_free(languages);
    8.34 -
    8.35 -    char *phrase;
    8.36 -    PEP_STATUS status3 = get_phrase(session, "de", 1000, &phrase);
    8.37 -    assert(status3 == PEP_STATUS_OK);
    8.38 -    assert(phrase);
    8.39 -
    8.40 -    cout << "\nGerman: " << phrase << "\n";
    8.41 -    pEp_free(phrase);
    8.42 -
    8.43 -    status3 = get_phrase(session, "zz", 1000, &phrase);
    8.44 -    assert(status3 == PEP_PHRASE_NOT_FOUND);
    8.45 -    assert(phrase == NULL);
    8.46 -
    8.47 -    cout << "calling release()\n";
    8.48 -    release(session);
    8.49 -    return 0;
    8.50 -}
    8.51 -
     9.1 --- a/test/identity_list_test.cc	Tue May 08 11:09:11 2018 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,174 +0,0 @@
     9.4 -// This file is under GNU General Public License 3.0
     9.5 -// see LICENSE.txt
     9.6 -
     9.7 -#include <stdlib.h>
     9.8 -#include <string.h>
     9.9 -#include "platform.h"
    9.10 -#include <iostream>
    9.11 -#include <fstream>
    9.12 -#include <assert.h>
    9.13 -
    9.14 -#include "identity_list.h"
    9.15 -
    9.16 -using namespace std;
    9.17 -
    9.18 -/*
    9.19 - *     char *address;              // C string with address UTF-8 encoded
    9.20 -    char *fpr;                  // C string with fingerprint UTF-8 encoded
    9.21 -    char *user_id;              // C string with user ID UTF-8 encoded
    9.22 -    char *username;             // C string with user name UTF-8 encoded
    9.23 -    PEP_comm_type comm_type;    // type of communication with this ID
    9.24 -    char lang[3];               // language of conversation
    9.25 -                                // ISO 639-1 ALPHA-2, last byte is 0
    9.26 --    bool me;                    // if this is the local user herself/himself
    9.27 -    */
    9.28 -
    9.29 -int test_identity_equals(pEp_identity* val1, pEp_identity* val2) {
    9.30 -    assert(val1);
    9.31 -    assert(val2);
    9.32 -    assert(val1->address);
    9.33 -    assert(val2->address);
    9.34 -    assert(val1->fpr);
    9.35 -    assert(val2->fpr);
    9.36 -    assert(val1->username);
    9.37 -    assert(val2->username);
    9.38 -    return((strcmp(val1->address, val2->address) == 0) && (strcmp(val1->fpr, val2->fpr) == 0)
    9.39 -        && (strcmp(val1->username, val2->username) == 0) && (val1->comm_type == val2->comm_type)
    9.40 -        && (val1->lang[0] == val2->lang[0]) && (val1->lang[1] == val2->lang[1])
    9.41 -        && (val1->lang[2] == val2->lang[2]) && (val1->me == val2->me));
    9.42 -}
    9.43 -
    9.44 -int main() {
    9.45 -    cout << "\n*** data structures: identity_list_test ***\n\n";
    9.46 -
    9.47 -    pEp_identity* id1 = new_identity(
    9.48 -        "leon.schumacher@digitalekho.com",
    9.49 -        "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
    9.50 -        "23",
    9.51 -        "Leon Schumacher"
    9.52 -    );
    9.53 -    id1->comm_type = PEP_ct_pEp;
    9.54 -    
    9.55 -    pEp_identity* id2 = new_identity(
    9.56 -        "krista@kgrothoff.org",
    9.57 -        "62D4932086185C15917B72D30571AFBCA5493553",
    9.58 -        "42",
    9.59 -        "Krista Bennett Grothoff"
    9.60 -    );
    9.61 -    
    9.62 -    id2->comm_type = PEP_ct_OpenPGP;
    9.63 -
    9.64 -    pEp_identity* id3 = new_identity(
    9.65 -        "krista@pep-project.org",
    9.66 -        "51BF42D25BB5B154D71BF6CD3CF25B776D149247",
    9.67 -        "10",
    9.68 -        "Krista Grothoff"
    9.69 -    );
    9.70 -    
    9.71 -    id3->comm_type = PEP_ct_OTR;
    9.72 -
    9.73 -    pEp_identity* id4 = new_identity(
    9.74 -        "papa@smurf.lu",
    9.75 -        "00001111222233334444555566667777DEADBEEF",
    9.76 -        "667",
    9.77 -        "Papa Smurf"
    9.78 -    );
    9.79 -    
    9.80 -    id4->comm_type = PEP_ct_key_b0rken;
    9.81 -    
    9.82 -    pEp_identity* id_arr[4] = {id1, id2, id3, id4};
    9.83 -        
    9.84 -    int i;
    9.85 -        
    9.86 -    cout << "creating one-element identity_list...\n";
    9.87 -    
    9.88 -    pEp_identity* new_id = identity_dup(id1);
    9.89 -    assert(new_id);
    9.90 -    identity_list* idlist = new_identity_list(new_id);
    9.91 -    assert(idlist->ident);
    9.92 -    assert(test_identity_equals(id1, idlist->ident));
    9.93 -    assert(idlist->next == NULL);
    9.94 -    cout << "one-element identity_list created, next element is NULL\n\n";
    9.95 -    
    9.96 -    cout << "duplicating one-element list...\n";
    9.97 -    identity_list* duplist = identity_list_dup(idlist);
    9.98 -    pEp_identity* srcid = idlist->ident;
    9.99 -    pEp_identity* dstid = duplist->ident;
   9.100 -    assert(dstid);
   9.101 -    assert(test_identity_equals(srcid, dstid));
   9.102 -    assert(srcid->address != dstid->address);   // test deep copies 
   9.103 -    assert(srcid->fpr != dstid->fpr);
   9.104 -    assert(srcid->username != dstid->username);
   9.105 -    assert(duplist->next == NULL);
   9.106 -    cout << "one-element identity_list duplicated.\n\n";
   9.107 -    
   9.108 -    cout << "freeing identity_lists...\n";
   9.109 -    free_identity_list(idlist); // will free srcid
   9.110 -    free_identity_list(duplist);
   9.111 -    idlist = NULL;
   9.112 -    duplist = NULL;
   9.113 -    srcid = NULL;
   9.114 -    
   9.115 -    identity_list* p;
   9.116 -    cout << "\ncreating four-element list...\n";
   9.117 -    idlist = identity_list_add(idlist, identity_dup(id_arr[0]));
   9.118 -    for (i = 1; i < 4; i++) {
   9.119 -        p = identity_list_add(idlist, identity_dup(id_arr[i]));
   9.120 -        assert(p);
   9.121 -    }
   9.122 -    
   9.123 -    p = idlist;
   9.124 -    
   9.125 -    for (i = 0; i < 4; i++) {
   9.126 -        assert(p);
   9.127 -        
   9.128 -        srcid = p->ident;
   9.129 -        assert(srcid);
   9.130 -        
   9.131 -        assert(test_identity_equals(srcid, id_arr[i]));
   9.132 -        assert(srcid->address != id_arr[i]->address);   // test deep copies
   9.133 -        assert(srcid->fpr != id_arr[i]->fpr);
   9.134 -        assert(srcid->username != id_arr[i]->username);
   9.135 -
   9.136 -        p = p->next;
   9.137 -    }
   9.138 -    assert(p == NULL);
   9.139 -    
   9.140 -    cout << "\nduplicating four-element list...\n\n";
   9.141 -    duplist = identity_list_dup(idlist);
   9.142 -    
   9.143 -    p = idlist;
   9.144 -    identity_list* dup_p = duplist;
   9.145 -    
   9.146 -    while (dup_p) {
   9.147 -        srcid = p->ident;
   9.148 -        dstid = dup_p->ident;
   9.149 -
   9.150 -        assert(dstid);
   9.151 -        
   9.152 -        assert(test_identity_equals(srcid, dstid));
   9.153 -
   9.154 -        assert(srcid != dstid);   // test deep copies
   9.155 -        assert(srcid->address != dstid->address);   // test deep copies
   9.156 -        assert(srcid->fpr != dstid->fpr);
   9.157 -        assert(srcid->username != dstid->username);
   9.158 -        
   9.159 -        i++;
   9.160 -        p = p->next;
   9.161 -
   9.162 -        dup_p = dup_p->next;
   9.163 -        assert((p == NULL) == (dup_p == NULL));
   9.164 -    }
   9.165 -    cout << "\nfour-element identity_list successfully duplicated.\n\n";
   9.166 -
   9.167 -    cout << "freeing identity_lists...\n";
   9.168 -    free_identity_list(idlist); // will free srcid
   9.169 -    free_identity_list(duplist);
   9.170 -    idlist = NULL;
   9.171 -    duplist = NULL;
   9.172 -    
   9.173 -    cout << "done.\n";
   9.174 -        
   9.175 -    
   9.176 -    return 0;
   9.177 -}
    10.1 --- a/test/keyedit_test.cc	Tue May 08 11:09:11 2018 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,74 +0,0 @@
    10.4 -// This file is under GNU General Public License 3.0
    10.5 -// see LICENSE.txt
    10.6 -
    10.7 -#include "platform.h"
    10.8 -
    10.9 -#include <iostream>
   10.10 -#include <fstream>
   10.11 -#include <string>
   10.12 -#include <assert.h>
   10.13 -
   10.14 -#include "pEpEngine.h"
   10.15 -
   10.16 -using namespace std;
   10.17 -
   10.18 -int main() {
   10.19 -    cout << "\n*** keyedit_test ***\n\n";
   10.20 -
   10.21 -    PEP_SESSION session;
   10.22 -    
   10.23 -    cout << "calling init()\n";
   10.24 -    PEP_STATUS status1 = init(&session);   
   10.25 -    assert(status1 == PEP_STATUS_OK);
   10.26 -    assert(session);
   10.27 -    cout << "init() completed.\n";
   10.28 -
   10.29 -    // generate test key
   10.30 -
   10.31 -    cout << "\ngenerating key for keyedit test\n";
   10.32 -    pEp_identity *identity = new_identity(
   10.33 -            "expire@dingens.org",
   10.34 -            NULL,
   10.35 -            "423",
   10.36 -            "expire test key"
   10.37 -        );
   10.38 -    assert(identity);
   10.39 -    PEP_STATUS generate_status = generate_keypair(session, identity);
   10.40 -    cout << "generate_keypair() exits with " << generate_status << "\n";
   10.41 -    assert(generate_status == PEP_STATUS_OK);
   10.42 -    cout << "generated key is " << identity->fpr << "\n";
   10.43 -
   10.44 -    string key(identity->fpr);
   10.45 -    free_identity(identity);
   10.46 -
   10.47 -    // keyedit test code
   10.48 -
   10.49 -    timestamp *ts = new_timestamp(time(0));
   10.50 -    ts->tm_year += 2;
   10.51 -
   10.52 -    cout << "key shell expire on " << asctime(ts) << "\n";
   10.53 -
   10.54 -    PEP_STATUS status2 = renew_key(session, key.c_str(), ts);
   10.55 -    cout << "renew_key() exited with " << status2 << "\n";
   10.56 -    assert(status2 == PEP_STATUS_OK);
   10.57 -    free_timestamp(ts);
   10.58 -
   10.59 -    cout << "key renewed.\n";
   10.60 -
   10.61 -    cout << "key will be revoked\n";
   10.62 -    PEP_STATUS status3 = revoke_key(session, key.c_str(), "revoke test");
   10.63 -    cout << "revoke_key() exited with " << status3 << "\n";
   10.64 -    assert(status3 == PEP_STATUS_OK);
   10.65 -    
   10.66 -    cout << "key revoked.\n";
   10.67 -
   10.68 -    cout << "deleting key pair " << key.c_str() << "\n";
   10.69 -    PEP_STATUS delete_status = delete_keypair(session, key.c_str());
   10.70 -    cout << "delete_keypair() exits with " << delete_status << "\n";
   10.71 -    assert(delete_status == PEP_STATUS_OK);
   10.72 -
   10.73 -    cout << "calling release()\n";
   10.74 -    release(session);
   10.75 -    return 0;
   10.76 -}
   10.77 -
    11.1 --- a/test/least_color_group_test.cc	Tue May 08 11:09:11 2018 +0200
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,99 +0,0 @@
    11.4 -#include <iostream>
    11.5 -#include <iostream>
    11.6 -#include <vector>
    11.7 -#include <cstring> // for strcmp()
    11.8 -#include <assert.h>
    11.9 -#include "blacklist.h"
   11.10 -#include "keymanagement.h"
   11.11 -#include "message_api.h"
   11.12 -#include "mime.h"
   11.13 -#include "test_util.h"
   11.14 -
   11.15 -using namespace std;
   11.16 -
   11.17 -int main(int argc, char** argv) {
   11.18 -    cout << "\n*** least_color_group_test.cc ***\n\n";
   11.19 -    
   11.20 -    const char* mailfile = "test_mails/color_test.eml";
   11.21 -    
   11.22 -    const std::vector<const char*> keynames = {
   11.23 -                              "test_keys/priv/pep.color.test.P-0x3EBE215C_priv.asc",
   11.24 -                              "test_keys/pub/pep.color.test.H-0xD17E598E_pub.asc",
   11.25 -                              "test_keys/pub/pep.color.test.L-0xE9CDB4CE_pub.asc",
   11.26 -                              "test_keys/pub/pep.color.test.P-0x3EBE215C_pub.asc",
   11.27 -                              "test_keys/pub/pep.color.test.V-0x71FC6D28_pub.asc"
   11.28 -                          };
   11.29 -    
   11.30 -    PEP_SESSION session;
   11.31 -    
   11.32 -    cout << "calling init()\n";
   11.33 -    PEP_STATUS status1 = init(&session);   
   11.34 -    assert(status1 == PEP_STATUS_OK);
   11.35 -    assert(session);
   11.36 -    cout << "init() completed.\n";
   11.37 -    
   11.38 -    for (auto name : keynames) {
   11.39 -        cout << "\t read keyfile \"" << name << "\"..." << std::endl;
   11.40 -        const string keytextkey = slurp(name);
   11.41 -        PEP_STATUS statuskey = import_key(session, keytextkey.c_str(), keytextkey.length(), NULL);
   11.42 -        assert(statuskey == PEP_STATUS_OK);
   11.43 -    }
   11.44 -    
   11.45 -    cout << "\t read keyfile mailfile \"" << mailfile << "\"..." << std::endl;
   11.46 -    const string mailtext = slurp(mailfile);
   11.47 -    cout << "\t All files read successfully." << std::endl;
   11.48 -
   11.49 -    pEp_identity * me1 = new_identity("pep.color.test.P@kgrothoff.org", 
   11.50 -                                      "7EE6C60C68851954E1797F81EA59715E3EBE215C", 
   11.51 -                                      PEP_OWN_USERID, "Pep Color Test P (recip)");
   11.52 -    me1->me = true;
   11.53 -    PEP_STATUS status = myself(session, me1);
   11.54 -    
   11.55 -    pEp_identity * sender1 = new_identity("pep.color.test.V@kgrothoff.org",
   11.56 -                                          NULL, "TOFU_pep.color.test.V@kgrothoff.org",
   11.57 -                                          "Pep Color Test V (sender)");
   11.58 -    
   11.59 -    status = update_identity(session, sender1);
   11.60 -    trust_personal_key(session, sender1);
   11.61 -    status = update_identity(session, sender1);
   11.62 -    
   11.63 -    message* msg_ptr = nullptr;
   11.64 -    message* dest_msg = nullptr;
   11.65 -    message* final_ptr = nullptr;
   11.66 -    stringlist_t* keylist = nullptr;
   11.67 -    PEP_rating rating;
   11.68 -    PEP_decrypt_flags_t flags;
   11.69 -    
   11.70 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
   11.71 -    assert(status == PEP_STATUS_OK);
   11.72 -    assert(msg_ptr);
   11.73 -    final_ptr = msg_ptr;
   11.74 -    flags = 0;
   11.75 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   11.76 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
   11.77 -  
   11.78 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
   11.79 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
   11.80 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
   11.81 -    cout << "rating: " << rating << endl << endl;
   11.82 -    cout << "keys used: " << endl;
   11.83 -    
   11.84 -    int i = 0;
   11.85 -    for (stringlist_t* k = keylist; k; k = k->next) {
   11.86 -        if (i == 0)
   11.87 -            cout << "\t Signer (key 0):\t" << k->value << endl;
   11.88 -        else
   11.89 -            cout << "\t #" << i << ":\t" << k->value << endl;
   11.90 -        i++;
   11.91 -    }
   11.92 -    
   11.93 -//    free_identity(me1);
   11.94 -    if (final_ptr == dest_msg)
   11.95 -    	free_message(dest_msg);
   11.96 -    free_message(msg_ptr);
   11.97 -    free_stringlist(keylist);
   11.98 -    
   11.99 -    cout << "calling release()\n";
  11.100 -    release(session);
  11.101 -    return 0;
  11.102 -}
    12.1 --- a/test/least_common_denom_color_test.cc	Tue May 08 11:09:11 2018 +0200
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,139 +0,0 @@
    12.4 -#include <iostream>
    12.5 -#include <iostream>
    12.6 -#include <fstream>
    12.7 -#include <string>
    12.8 -#include <cstring> // for strcmp()
    12.9 -#include <assert.h>
   12.10 -#include "blacklist.h"
   12.11 -#include "keymanagement.h"
   12.12 -#include "message_api.h"
   12.13 -#include "mime.h"
   12.14 -#include "test_util.h"
   12.15 -
   12.16 -using namespace std;
   12.17 -
   12.18 -int main(int argc, char** argv) {
   12.19 -        
   12.20 -    const char* mailfile = "test_mails/Test_Message_JSON-21_Color_Problems.eml";
   12.21 -    
   12.22 -    PEP_SESSION session;
   12.23 -    
   12.24 -    cout << "calling init()\n";
   12.25 -    PEP_STATUS status1 = init(&session);   
   12.26 -    assert(status1 == PEP_STATUS_OK);
   12.27 -    assert(session);
   12.28 -    cout << "init() completed.\n";
   12.29 -    
   12.30 -    // import keys
   12.31 -    const string keytextkey1 = slurp("test_keys/pub/banmeonce-0x07B29090_pub.asc");
   12.32 -    const string keytextkey2 = slurp("test_keys/pub/banmetwice-0x4080C3E7_pub.asc");
   12.33 -    const string keytextkey3 = slurp("test_keys/pub/pep.never.me.test-0x79C11D1D_pub.asc");
   12.34 -    const string keytextkey4 = slurp("test_keys/priv/pep.never.me.test-0x79C11D1D_priv.asc");
   12.35 -
   12.36 -    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
   12.37 -    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
   12.38 -    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
   12.39 -    PEP_STATUS statuskey4 = import_key(session, keytextkey4.c_str(), keytextkey4.length(), NULL);
   12.40 -
   12.41 -    pEp_identity * sender = new_identity("pep.never.me.test@kgrothoff.org", NULL, "TOFU_pep.never.me.test@kgrothoff.org", "pEp Never Me Test");    
   12.42 -    sender->me = false;    
   12.43 -    PEP_STATUS status = update_identity(session, sender);
   12.44 -        
   12.45 -    // reset the trust on both keys before we start
   12.46 -    pEp_identity * recip1 = new_identity("banmeonce@kgrothoff.org", NULL, "TOFU_banmeonce@kgrothoff.org", "Ban Me Once");    
   12.47 -    recip1->me = false;    
   12.48 -    status = update_identity(session, recip1);
   12.49 -    key_reset_trust(session, recip1);
   12.50 -    
   12.51 -    pEp_identity * recip2 = new_identity("banmetwice@kgrothoff.org", NULL, "TOFU_banmetwice@kgrothoff.org", "Ban Me Twice");    
   12.52 -    recip2->me = false;    
   12.53 -    status = update_identity(session, recip2);
   12.54 -    key_reset_trust(session, recip2);
   12.55 -        
   12.56 -    const string mailtext = slurp(mailfile);
   12.57 -
   12.58 -    // trust_personal_key(session, you);
   12.59 -    // 
   12.60 -    // status = update_identity(session, you);
   12.61 -    
   12.62 -    message* msg_ptr = nullptr;
   12.63 -    message* dest_msg = nullptr;
   12.64 -    stringlist_t* keylist = nullptr;
   12.65 -    PEP_rating rating;
   12.66 -    PEP_decrypt_flags_t flags;
   12.67 -    
   12.68 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
   12.69 -    assert(status == PEP_STATUS_OK);
   12.70 -    assert(msg_ptr);
   12.71 -
   12.72 -    flags = 0;
   12.73 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   12.74 -    assert(status == PEP_STATUS_OK);
   12.75 -    assert(dest_msg);
   12.76 -    /* message is signed and no recip is mistrusted... */
   12.77 -    assert(color_from_rating(rating) == PEP_color_yellow);
   12.78 -
   12.79 -    cout << "shortmsg: " << dest_msg->shortmsg << endl << endl;
   12.80 -    cout << "longmsg: " << dest_msg->longmsg << endl << endl;
   12.81 -    cout << "longmsg_formatted: " << (dest_msg->longmsg_formatted ? dest_msg->longmsg_formatted : "(empty)") << endl << endl;
   12.82 -
   12.83 -    PEP_rating decrypt_rating = rating;
   12.84 -    
   12.85 -    /* re-evaluate rating, counting on optional fields */
   12.86 -    status = re_evaluate_message_rating(session, dest_msg, NULL, PEP_rating_undefined, &rating);
   12.87 -    assert(status == PEP_STATUS_OK);
   12.88 -    assert(color_from_rating(rating) == PEP_color_yellow);
   12.89 -
   12.90 -    /* re-evaluate rating, without optional fields */
   12.91 -    status = re_evaluate_message_rating(session, dest_msg, keylist, decrypt_rating, &rating);
   12.92 -    assert(status == PEP_STATUS_OK);
   12.93 -    assert(color_from_rating(rating) == PEP_color_yellow);
   12.94 -
   12.95 -    /* Ok, now mistrust one recip */
   12.96 -    key_mistrusted(session, recip2);
   12.97 -
   12.98 -    /* re-evaluate rating, counting on optional fields */
   12.99 -    status = re_evaluate_message_rating(session, dest_msg, NULL, PEP_rating_undefined, &rating);
  12.100 -    assert(status == PEP_STATUS_OK);
  12.101 -    assert(color_from_rating(rating) == PEP_color_red);
  12.102 -
  12.103 -    /* re-evaluate rating, without optional fields */
  12.104 -    status = re_evaluate_message_rating(session, dest_msg, keylist, decrypt_rating, &rating);
  12.105 -    assert(status == PEP_STATUS_OK);
  12.106 -    assert(color_from_rating(rating) == PEP_color_red);
  12.107 -
  12.108 -    free_message(dest_msg);
  12.109 -    free_message(msg_ptr);
  12.110 -    free_stringlist(keylist);
  12.111 -    
  12.112 -    msg_ptr = nullptr;
  12.113 -    dest_msg = nullptr;
  12.114 -    keylist = nullptr;
  12.115 -    rating = PEP_rating_unreliable;
  12.116 -
  12.117 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  12.118 -    assert(status == PEP_STATUS_OK);
  12.119 -    assert(msg_ptr);
  12.120 -    flags = 0;
  12.121 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  12.122 -  
  12.123 -    cout << "shortmsg: " << dest_msg->shortmsg << endl << endl;
  12.124 -    cout << "longmsg: " << dest_msg->longmsg << endl << endl;
  12.125 -    cout << "longmsg_formatted: " << (dest_msg->longmsg_formatted ? dest_msg->longmsg_formatted : "(empty)") << endl << endl;
  12.126 -
  12.127 -    /* message is signed and no recip is mistrusted... */
  12.128 -    assert(color_from_rating(rating) == PEP_color_red);
  12.129 -
  12.130 -    free_message(dest_msg);
  12.131 -    free_message(msg_ptr);
  12.132 -    free_stringlist(keylist);
  12.133 -
  12.134 -    msg_ptr = nullptr;
  12.135 -    dest_msg = nullptr;
  12.136 -    keylist = nullptr;
  12.137 -    rating = PEP_rating_unreliable;
  12.138 -    
  12.139 -    cout << "calling release()\n";
  12.140 -    release(session);
  12.141 -    return 0;
  12.142 -}
    13.1 --- a/test/map_asn1_test.cc	Tue May 08 11:09:11 2018 +0200
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,50 +0,0 @@
    13.4 -// This file is under GNU General Public License 3.0
    13.5 -// see LICENSE.txt
    13.6 -
    13.7 -#include <iostream>
    13.8 -#include <string>
    13.9 -#include <cstring>
   13.10 -#include <assert.h>
   13.11 -#include "map_asn1.h"
   13.12 -
   13.13 -using namespace std;
   13.14 -
   13.15 -int main() {
   13.16 -    cout << "\n*** map_asn1_test ***\n\n";
   13.17 -
   13.18 -    cout << "creating new identity...\n";
   13.19 -
   13.20 -    pEp_identity *ident1 = new_identity("vb@dingens.org",
   13.21 -            "DB4713183660A12ABAFA7714EBE90D44146F62F4", "42", "Volker Birk");
   13.22 -    assert(ident1);
   13.23 -    ident1->lang[0] = 'd';
   13.24 -    ident1->lang[1] = 'e';
   13.25 -    ident1->comm_type = PEP_ct_pEp;
   13.26 -
   13.27 -    cout << "converting identity to ASN.1...\n";
   13.28 -
   13.29 -    Identity_t *ident_asn1 = Identity_from_Struct(ident1, NULL);
   13.30 -    assert(ident_asn1);
   13.31 -
   13.32 -    cout << "converting identity from ASN.1...\n";
   13.33 -
   13.34 -    pEp_identity *ident2 = Identity_to_Struct(ident_asn1, NULL);
   13.35 -    assert(ident2);
   13.36 -
   13.37 -    assert(strcmp(ident1->address, ident2->address) == 0);
   13.38 -    assert(strcmp(ident1->fpr, ident2->fpr) == 0);
   13.39 -    assert(strcmp(ident1->user_id, ident2->user_id) == 0);
   13.40 -    assert(strcmp(ident1->username, ident2->username) == 0);
   13.41 -    assert(ident2->comm_type == PEP_ct_pEp);
   13.42 -    assert(strcmp(ident2->lang, "de") == 0);
   13.43 -
   13.44 -    cout << "freeing identities...\n";
   13.45 -
   13.46 -    asn_DEF_Identity.free_struct(&asn_DEF_Identity, ident_asn1, 0);
   13.47 -    free_identity(ident1);
   13.48 -    free_identity(ident2);
   13.49 -
   13.50 -
   13.51 -    return 0;
   13.52 -}
   13.53 -
    14.1 --- a/test/message_api_test.cc	Tue May 08 11:09:11 2018 +0200
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,225 +0,0 @@
    14.4 -// This file is under GNU General Public License 3.0
    14.5 -// see LICENSE.txt
    14.6 -
    14.7 -#include <stdlib.h>
    14.8 -#include <string.h>
    14.9 -#include "platform.h"
   14.10 -#include <iostream>
   14.11 -#include <fstream>
   14.12 -#include <assert.h>
   14.13 -#include "mime.h"
   14.14 -#include "message_api.h"
   14.15 -#include "test_util.h"
   14.16 -
   14.17 -using namespace std;
   14.18 -
   14.19 -int main() {
   14.20 -    cout << "\n*** message_api_test ***\n\n";
   14.21 -
   14.22 -    PEP_SESSION session;
   14.23 -    
   14.24 -    cout << "calling init()\n";
   14.25 -    PEP_STATUS status1 = init(&session);
   14.26 -    assert(status1 == PEP_STATUS_OK);
   14.27 -    assert(session);
   14.28 -    cout << "init() completed.\n";
   14.29 -
   14.30 -    cout << "Importing Alice's key " << endl;
   14.31 -    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   14.32 -    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   14.33 -    const string bob_pub_key = slurp("test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
   14.34 -
   14.35 -    PEP_STATUS status0 = import_key(session, alice_pub_key.c_str(), alice_pub_key.size(), NULL);
   14.36 -    assert(status0 == PEP_STATUS_OK);
   14.37 -    status0 = import_key(session, alice_priv_key.c_str(), alice_priv_key.size(), NULL);
   14.38 -    assert(status0 == PEP_STATUS_OK);
   14.39 -    status0 = import_key(session, bob_pub_key.c_str(), bob_pub_key.size(), NULL);
   14.40 -    assert(status0 == PEP_STATUS_OK);
   14.41 -    // message_api test code
   14.42 -
   14.43 -    cout << "creating message…\n";
   14.44 -    pEp_identity * me2 = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
   14.45 -    // pEp_identity * me2 = new_identity("test@nokey.plop", NULL, PEP_OWN_USERID, "Test no key");
   14.46 -    me2->me = true;
   14.47 -    identity_list *to2 = new_identity_list(new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test"));
   14.48 -    // identity_list *to2 = new_identity_list(new_identity("still@nokey.blup", NULL, "42", "Still no key"));
   14.49 -    message *msg2 = new_message(PEP_dir_outgoing);
   14.50 -    assert(msg2);
   14.51 -    msg2->from = me2;
   14.52 -    msg2->to = to2;
   14.53 -    msg2->shortmsg = strdup("hello, world");
   14.54 -    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   14.55 -    cout << "message created.\n";
   14.56 -
   14.57 -    char *text2 = nullptr;
   14.58 -    PEP_STATUS status2 = mime_encode_message(msg2, false, &text2);
   14.59 -    assert(status2 == PEP_STATUS_OK);
   14.60 -    assert(text2);
   14.61 -
   14.62 -    cout << "decrypted:\n\n";
   14.63 -    cout << text2 << "\n";
   14.64 -
   14.65 -    free(text2);
   14.66 -
   14.67 -    cout << "encrypting message as MIME multipart…\n";
   14.68 -    message *enc_msg2 = nullptr;
   14.69 -    cout << "calling encrypt_message()\n";
   14.70 -    status2 = encrypt_message(session, msg2, NULL, &enc_msg2, PEP_enc_PGP_MIME, 0);
   14.71 -    cout << "encrypt_message() returns " << status2 << '.' << endl;
   14.72 -    assert(status2 == PEP_STATUS_OK);
   14.73 -    assert(enc_msg2);
   14.74 -    cout << "message encrypted.\n";
   14.75 -    
   14.76 -    status2 = mime_encode_message(enc_msg2, false, &text2);
   14.77 -    assert(status2 == PEP_STATUS_OK);
   14.78 -    assert(text2);
   14.79 -
   14.80 -    cout << "encrypted:\n\n";
   14.81 -    cout << text2 << "\n";
   14.82 -
   14.83 -    message *msg3 = nullptr;
   14.84 -    PEP_STATUS status3 = mime_decode_message(text2, strlen(text2), &msg3);
   14.85 -    assert(status3 == PEP_STATUS_OK);
   14.86 -    const string string3 = text2;
   14.87 -    //free(text2);
   14.88 -
   14.89 -    unlink("msg4.asc");
   14.90 -    ofstream outFile3("msg4.asc");
   14.91 -    outFile3.write(string3.c_str(), string3.size());
   14.92 -    outFile3.close();
   14.93 -
   14.94 -    message *msg4 = nullptr;
   14.95 -    stringlist_t *keylist4 = nullptr;
   14.96 -    PEP_rating rating;
   14.97 -    PEP_decrypt_flags_t flags;
   14.98 -    
   14.99 -    flags = 0;
  14.100 -    PEP_STATUS status4 = decrypt_message(session, enc_msg2, &msg4, &keylist4, &rating, &flags);
  14.101 -    assert(status4 == PEP_STATUS_OK);
  14.102 -    assert(msg4);
  14.103 -    assert(keylist4);
  14.104 -    assert(rating);
  14.105 -    PEP_comm_type ct = enc_msg2->from->comm_type;
  14.106 -    assert(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed );
  14.107 -
  14.108 -    free_stringpair_list(enc_msg2->opt_fields);
  14.109 -    enc_msg2->opt_fields = NULL;
  14.110 -
  14.111 -    cout << "keys used:";
  14.112 -
  14.113 -    for (stringlist_t* kl4 = keylist4; kl4 && kl4->value; kl4 = kl4->next)
  14.114 -    {
  14.115 -        cout << " " << kl4->value;
  14.116 -    }
  14.117 -    cout << "\n\n";
  14.118 -
  14.119 -    free_stringlist(keylist4);
  14.120 -
  14.121 -    cout << "opening msg_no_key.asc for reading\n";
  14.122 -    ifstream inFile3 ("msg_no_key.asc");
  14.123 -    assert(inFile3.is_open());
  14.124 -
  14.125 -    string text3;
  14.126 -
  14.127 -    cout << "reading msg_no_key.asc sample\n";
  14.128 -    while (!inFile3.eof()) {
  14.129 -        static string line;
  14.130 -        getline(inFile3, line);
  14.131 -        text3 += line + "\r\n";
  14.132 -    }
  14.133 -    inFile3.close();
  14.134 -
  14.135 -    message *msg5 = nullptr;
  14.136 -    PEP_STATUS status5 = mime_decode_message(text3.c_str(), text3.length(), &msg5);
  14.137 -    assert(status5 == PEP_STATUS_OK);
  14.138 -
  14.139 -    message *msg6 = nullptr;
  14.140 -    stringlist_t *keylist5 = nullptr;
  14.141 -    PEP_rating rating2;
  14.142 -    PEP_decrypt_flags_t flags2;
  14.143 -    flags2 = 0;
  14.144 -    PEP_STATUS status6 = decrypt_message(session, msg5, &msg6, &keylist5, &rating2, &flags2);
  14.145 -    assert(status6 == PEP_DECRYPT_NO_KEY);
  14.146 -    assert(msg6 == NULL);
  14.147 -    assert(keylist5 == NULL);
  14.148 -    assert(rating2 == PEP_rating_have_no_key);
  14.149 -    cout << "rating :" << rating2 << "\n";
  14.150 -    free_stringlist(keylist5);
  14.151 -
  14.152 -    cout << "\nTesting MIME_encrypt_message / MIME_decrypt_message...\n\n";
  14.153 -
  14.154 -    cout << "opening alice_bob_encrypt_test_plaintext_mime.eml for reading\n";
  14.155 -    ifstream inFile4 ("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
  14.156 -    assert(inFile4.is_open());
  14.157 -    
  14.158 -    string text4;
  14.159 -    
  14.160 -    cout << "reading alice_bob_encrypt_test_plaintext_mime.eml sample\n";
  14.161 -    while (!inFile4.eof()) {
  14.162 -        static string line;
  14.163 -        getline(inFile4, line);
  14.164 -        text4 += line + "\r\n";
  14.165 -    }
  14.166 -    inFile4.close();
  14.167 -    
  14.168 -    const char* out_msg_plain = text4.c_str();
  14.169 -    
  14.170 -//    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";
  14.171 -    char* enc_msg = NULL;
  14.172 -    char* dec_msg = NULL;
  14.173 -
  14.174 -    PEP_STATUS status7 = MIME_encrypt_message(session, text4.c_str(), text4.length(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  14.175 -//    PEP_STATUS status7 = MIME_encrypt_message(session, out_msg_plain, strlen(out_msg_plain), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  14.176 -    assert(status7 == PEP_STATUS_OK);
  14.177 -    
  14.178 -    cout << enc_msg << endl;
  14.179 -
  14.180 -    string text5 = enc_msg;
  14.181 -    
  14.182 -    PEP_decrypt_flags_t dec_flags;
  14.183 -    stringlist_t* keys_used;
  14.184 -    
  14.185 -    dec_flags = 0;
  14.186 -    char* modified_src = NULL;
  14.187 -    PEP_STATUS status8 = MIME_decrypt_message(session, text5.c_str(), text5.length(), &dec_msg, &keys_used, &rating, &dec_flags, &modified_src);
  14.188 -    assert(status8 == PEP_STATUS_OK);
  14.189 -    
  14.190 -    cout << dec_msg << endl;
  14.191 -    
  14.192 -    cout << "\nTesting encrypt_message() with enc_format = PEP_enc_none\n\n";
  14.193 -
  14.194 -    message *msg7 = new_message(PEP_dir_outgoing);
  14.195 -    pEp_identity * me7 = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
  14.196 -    identity_list *to7 = new_identity_list(new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test"));
  14.197 -    msg7->from = me7;
  14.198 -    msg7->to = to7;
  14.199 -    msg7->shortmsg = strdup("My Subject");
  14.200 -    msg7->longmsg = strdup("This is some text.\n");
  14.201 -
  14.202 -    message *enc7 = nullptr;
  14.203 -    PEP_STATUS status9 = encrypt_message(session, msg7, NULL, &enc7, PEP_enc_none, 0);
  14.204 -	std::cout << "encrypt_message returned " << std::dec << status9 << std::hex << " (0x" << status9 << ")" << std::dec << endl;
  14.205 -    assert(status9 == PEP_UNENCRYPTED);
  14.206 -    assert(enc7 == nullptr);
  14.207 -    assert(msg7->shortmsg && msg7->longmsg);
  14.208 -    cout << msg7->shortmsg << "\n";
  14.209 -    cout << msg7->longmsg << "\n";
  14.210 -    assert(strcmp(msg7->shortmsg, "My Subject") == 0);
  14.211 -    assert(strcmp(msg7->longmsg, "This is some text.\n") == 0);
  14.212 -    
  14.213 -    cout << "\nfreeing messages…\n";
  14.214 -    free_message(msg7);
  14.215 -    free_message(msg6);
  14.216 -    free_message(msg5);
  14.217 -    free_message(msg4);
  14.218 -    free_message(msg3);
  14.219 -    free_message(msg2);
  14.220 -    free_message(enc_msg2);
  14.221 -    cout << "done.\n";
  14.222 -
  14.223 -    free(enc_msg);
  14.224 -    free(dec_msg);
  14.225 -    cout << "calling release()\n";
  14.226 -    release(session);
  14.227 -    return 0;
  14.228 -}
    15.1 --- a/test/message_two_point_oh_test.cc	Tue May 08 11:09:11 2018 +0200
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,169 +0,0 @@
    15.4 -// This file is under GNU General Public License 3.0
    15.5 -// see LICENSE.txt
    15.6 -
    15.7 -#include <stdlib.h>
    15.8 -#include <string.h>
    15.9 -#include "platform.h"
   15.10 -#include <iostream>
   15.11 -#include <fstream>
   15.12 -#include <assert.h>
   15.13 -#include "mime.h"
   15.14 -#include "message_api.h"
   15.15 -#include "keymanagement.h"
   15.16 -#include "test_util.h"
   15.17 -
   15.18 -using namespace std;
   15.19 -
   15.20 -int main() {
   15.21 -    cout << "\n*** message_2.0_test ***\n\n";
   15.22 -
   15.23 -    PEP_SESSION session;
   15.24 -    
   15.25 -    cout << "calling init()\n";
   15.26 -    PEP_STATUS status1 = init(&session);
   15.27 -    assert(status1 == PEP_STATUS_OK);
   15.28 -    assert(session);
   15.29 -    cout << "init() completed.\n";
   15.30 -
   15.31 -    PEP_comm_type carol_comm_type = PEP_ct_OpenPGP_unconfirmed;
   15.32 -
   15.33 -    // message_api test code
   15.34 -
   15.35 -    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   15.36 -    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   15.37 -    const string carol_pub_key = slurp("test_keys/pub/pep-test-carol-0x42A85A42_pub.asc");
   15.38 -    const string carol_priv_key = slurp("test_keys/priv/pep-test-carol-0x42A85A42_priv.asc");
   15.39 -
   15.40 -    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   15.41 -    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
   15.42 -    assert(statuspub == PEP_STATUS_OK);
   15.43 -    assert(statuspriv == PEP_STATUS_OK);
   15.44 -    statuspub = import_key(session, carol_pub_key.c_str(), carol_pub_key.length(), NULL);
   15.45 -    statuspriv = import_key(session, carol_priv_key.c_str(), carol_priv_key.length(), NULL);
   15.46 -    assert(statuspub == PEP_STATUS_OK);
   15.47 -    assert(statuspriv == PEP_STATUS_OK);
   15.48 -
   15.49 -    cout << "creating message…\n";
   15.50 -    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", PEP_OWN_USERID, "Alice Test");
   15.51 -    pEp_identity* carol = new_identity("pep-test-carol@pep-project.org", NULL, "TOFU_pep-test-carol@pep-project.org", "Carol Test");
   15.52 -
   15.53 -    PEP_STATUS alice_status = update_identity(session, alice);
   15.54 -    PEP_STATUS carol_status = update_identity(session, carol);
   15.55 -
   15.56 -    PEP_STATUS status = update_trust_for_fpr(session, alice->fpr, PEP_ct_pEp);
   15.57 -    status = update_trust_for_fpr(session, carol->fpr, carol_comm_type);
   15.58 -    
   15.59 -    PEP_STATUS mystatus = myself(session, alice);
   15.60 -    assert(mystatus == PEP_STATUS_OK);
   15.61 -    alice_status = update_identity(session, alice);
   15.62 -    alice_status = update_identity(session, carol);
   15.63 -    assert(alice->comm_type == PEP_ct_pEp);
   15.64 -    assert(carol->comm_type == carol_comm_type);
   15.65 -    
   15.66 -    identity_list* to_list = new_identity_list(carol); // to carol
   15.67 -    message* outgoing_message = new_message(PEP_dir_outgoing);
   15.68 -    assert(outgoing_message);
   15.69 -    outgoing_message->from = alice;
   15.70 -    outgoing_message->to = to_list;
   15.71 -    outgoing_message->shortmsg = strdup("Greetings, humans!");
   15.72 -    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   15.73 -    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   15.74 -//    outgoing_message->id = strdup("blahblahyourmama@pep-project.org");
   15.75 -    outgoing_message->references = new_stringlist("one-839274982347239847@pep-project.org");
   15.76 -    stringlist_add(outgoing_message->references, "two-dfddffd839274982347239847@pep-project.org");
   15.77 -    stringlist_add(outgoing_message->references, "three-OMGWTFBBQ.edfddffd839274982347239847@pep-project.org");
   15.78 -    
   15.79 -    cout << "message created.\n";
   15.80 -
   15.81 -    char* encoded_text = nullptr;
   15.82 -    status = mime_encode_message(outgoing_message, false, &encoded_text);
   15.83 -    assert(status == PEP_STATUS_OK);
   15.84 -    assert(encoded_text);
   15.85 -
   15.86 -    cout << "unencrypted:\n\n";
   15.87 -    cout << encoded_text << "\n";
   15.88 -
   15.89 -    free(encoded_text);
   15.90 -
   15.91 -    cout << "encrypting message as MIME multipart…\n";
   15.92 -    message* encrypted_msg = nullptr;
   15.93 -    cout << "calling encrypt_message\n";
   15.94 -    status = encrypt_message(session, outgoing_message, NULL, 
   15.95 -        &encrypted_msg, PEP_enc_PGP_MIME, 0);
   15.96 -    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
   15.97 -    assert(status == PEP_STATUS_OK);
   15.98 -    assert(encrypted_msg);
   15.99 -    cout << "message encrypted.\n";
  15.100 -    
  15.101 -    encrypted_msg->enc_format = PEP_enc_none;
  15.102 -    status = mime_encode_message(encrypted_msg, false, &encoded_text);
  15.103 -    assert(status == PEP_STATUS_OK);
  15.104 -    assert(encoded_text);
  15.105 -     
  15.106 -    cout << "encrypted:\n\n";
  15.107 -    cout << encoded_text << "\n";
  15.108 -     
  15.109 -    char* decrypted_text;
  15.110 -    
  15.111 -    message* decrypted_msg = nullptr;
  15.112 -    stringlist_t* keylist_used = nullptr;
  15.113 -    
  15.114 -    PEP_rating rating;
  15.115 -    PEP_decrypt_flags_t flags;
  15.116 -     
  15.117 -//    MIME_decrypt_message(session, encoded_text, strlen(encoded_text), &decrypted_text, &keylist_used, &rating, &flags);
  15.118 -    
  15.119 -//    cout << "HEY!" << endl;
  15.120 -//    cout << decrypted_text << endl;
  15.121 -    
  15.122 -    message* decoded_msg = nullptr;
  15.123 -    status = mime_decode_message(encoded_text, strlen(encoded_text), &decoded_msg);
  15.124 -    assert(status == PEP_STATUS_OK);
  15.125 -    const string string3 = encoded_text;
  15.126 -      
  15.127 -    unlink("msg_2.0.asc");
  15.128 -    ofstream outFile3("msg_2.0.asc");
  15.129 -    outFile3.write(string3.c_str(), string3.size());
  15.130 -    outFile3.close();
  15.131 -    
  15.132 -    // message* decrypted_msg = nullptr;
  15.133 -    // stringlist_t* keylist_used = nullptr;
  15.134 -    // 
  15.135 -    // PEP_rating rating;
  15.136 -    // PEP_decrypt_flags_t flags;
  15.137 -    // 
  15.138 -    stringpair_t* autoconsume = new_stringpair("pEp-auto-consume", "yes");
  15.139 -    stringpair_list_add(encrypted_msg->opt_fields, autoconsume);
  15.140 -    flags = 0;
  15.141 -    status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
  15.142 -    assert(decrypted_msg);
  15.143 -    assert(keylist_used);
  15.144 -    assert(rating);
  15.145 -    //assert(status == PEP_STATUS_OK && rating == PEP_rating_reliable);
  15.146 -    //PEP_comm_type ct = encrypted_msg->from->comm_type;
  15.147 -    //assert(ct == PEP_ct_pEp);
  15.148 -    
  15.149 -    cout << "keys used:\n";
  15.150 -    
  15.151 -    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
  15.152 -    {
  15.153 -       cout << "\t " << kl4->value << endl;
  15.154 -    }
  15.155 -     
  15.156 -    decrypted_msg->enc_format = PEP_enc_none; 
  15.157 -    status = _mime_encode_message_internal(decrypted_msg, false, &encoded_text, false);
  15.158 -    assert(status == PEP_STATUS_OK);
  15.159 -    assert(encoded_text);
  15.160 -    cout << "Decrypted message: " << endl;
  15.161 -    cout << encoded_text << endl;
  15.162 -     
  15.163 -    cout << "freeing messages…\n";
  15.164 -    free_message(encrypted_msg);
  15.165 -    free_message(decrypted_msg);
  15.166 -    free_message(outgoing_message);
  15.167 -    cout << "done.\n";
  15.168 -    
  15.169 -    cout << "calling release()\n";
  15.170 -    release(session);
  15.171 -    return 0;
  15.172 -}
    16.1 --- a/test/mime_test.cc	Tue May 08 11:09:11 2018 +0200
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,104 +0,0 @@
    16.4 -// This file is under GNU General Public License 3.0
    16.5 -// see LICENSE.txt
    16.6 -
    16.7 -#include <stdlib.h>
    16.8 -#include <string.h>
    16.9 -#include "platform.h"
   16.10 -
   16.11 -#include <iostream>
   16.12 -#include <fstream>
   16.13 -#include <string>
   16.14 -#include <assert.h>
   16.15 -
   16.16 -#include "mime.h"
   16.17 -
   16.18 -using namespace std;
   16.19 -
   16.20 -void test_mime_decoding(string filename) {
   16.21 -    cout << "opening " << filename << " for reading\n";
   16.22 -    ifstream inFile3 (filename.c_str());
   16.23 -    assert(inFile3.is_open());
   16.24 -
   16.25 -    string mimetext3;
   16.26 -
   16.27 -    cout << "reading mime sample\n";
   16.28 -    while (!inFile3.eof()) {
   16.29 -        static string line;
   16.30 -        getline(inFile3, line);
   16.31 -        mimetext3 += line + "\n";
   16.32 -    }
   16.33 -    inFile3.close();
   16.34 -
   16.35 -    cout << "decoding message…\n";
   16.36 -    message *msg3;
   16.37 -    PEP_STATUS status3 = mime_decode_message(mimetext3.c_str(), mimetext3.length(), &msg3);
   16.38 -    assert(status3 == PEP_STATUS_OK);
   16.39 -    assert(msg3);
   16.40 -    cout << "decoded.\n\n";
   16.41 -    cout << "Subject: " << msg3->shortmsg << "\n\n";
   16.42 -    if (msg3->longmsg)
   16.43 -        cout << msg3->longmsg << "\n\n";
   16.44 -    if (msg3->longmsg_formatted)
   16.45 -        cout << msg3->longmsg_formatted << "\n\n";
   16.46 -    bloblist_t *_b;
   16.47 -    for (_b = msg3->attachments; _b; _b = _b->next) {
   16.48 -        cout << "attachment of type " << _b->mime_type << "\n";
   16.49 -        if (_b->filename) {
   16.50 -            cout << "filename: " << _b->filename << "\n";
   16.51 -            unlink(_b->filename);
   16.52 -            ofstream outFile3(_b->filename);
   16.53 -            outFile3.write(_b->value, _b->size);
   16.54 -            outFile3.close();
   16.55 -        }
   16.56 -    }
   16.57 -
   16.58 -    free_message(msg3);
   16.59 -}
   16.60 -
   16.61 -int main() {
   16.62 -    cout << "\n*** mime_test ***\n\n";
   16.63 -
   16.64 -    PEP_SESSION session;
   16.65 -    
   16.66 -    cout << "calling init()\n";
   16.67 -    PEP_STATUS status1 = init(&session);   
   16.68 -    assert(status1 == PEP_STATUS_OK);
   16.69 -    assert(session);
   16.70 -    cout << "init() completed.\n";
   16.71 -
   16.72 -    // mime test code
   16.73 -
   16.74 -    // testing multipart/alternative
   16.75 -
   16.76 -    message *msg2 = new_message(PEP_dir_incoming);
   16.77 -    assert(msg2);
   16.78 -    msg2->from = new_identity("vb@dingens.org", NULL, NULL, "Volker Birk");
   16.79 -    msg2->to = new_identity_list(new_identity("trischa@dingens.org", NULL, NULL, "Patricia Bädnar")),
   16.80 -    msg2->shortmsg = strdup("my sübject");
   16.81 -
   16.82 -    string text2 = "my mèssage to yoü";
   16.83 -    msg2->longmsg = strdup(text2.c_str());
   16.84 -    string html2 = "<html><body><p>my message to you</p></body></html>";
   16.85 -    msg2->longmsg_formatted = strdup(html2.c_str());
   16.86 -    assert(msg2->longmsg_formatted);
   16.87 -
   16.88 -    cout << "encoding message…\n";
   16.89 -    char *result2;
   16.90 -    PEP_STATUS status2 = mime_encode_message(msg2, false, &result2);
   16.91 -    assert(result2);
   16.92 -    assert(status2 == PEP_STATUS_OK);
   16.93 -
   16.94 -    cout << "result:\n";
   16.95 -    cout << result2 << "\n";
   16.96 -
   16.97 -    free(result2);
   16.98 -    free_message(msg2);
   16.99 -
  16.100 -    test_mime_decoding("msg1.asc");
  16.101 -    test_mime_decoding("msg2.asc");
  16.102 -    test_mime_decoding("msg3.asc");
  16.103 -
  16.104 -    cout << "calling release()\n";
  16.105 -    release(session);
  16.106 -    return 0;
  16.107 -}
    17.1 --- a/test/mistrust_undo_test.cc	Tue May 08 11:09:11 2018 +0200
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,83 +0,0 @@
    17.4 -// This file is under GNU General Public License 3.0
    17.5 -// see LICENSE.txt
    17.6 -
    17.7 -#include <stdlib.h>
    17.8 -#include <string.h>
    17.9 -#include <time.h>
   17.10 -#include "platform.h"
   17.11 -#include <iostream>
   17.12 -#include <fstream>
   17.13 -#include <assert.h>
   17.14 -#include "mime.h"
   17.15 -#include "message_api.h"
   17.16 -#include "test_util.h"
   17.17 -
   17.18 -using namespace std;
   17.19 -
   17.20 -int main() {
   17.21 -    cout << "\n*** mistrust_undo_test ***\n\n";
   17.22 -
   17.23 -    PEP_SESSION session;
   17.24 -    
   17.25 -    cout << "calling init()\n";
   17.26 -    PEP_STATUS status = init(&session);   
   17.27 -    assert(status == PEP_STATUS_OK);
   17.28 -    assert(session);
   17.29 -    cout << "init() completed.\n";
   17.30 -
   17.31 -    cout << "importing key 0x39E5DAB5." << endl;
   17.32 -    const string pub_key = slurp("test_keys/pub/mistrust.undo.test-0x39E5DAB5_pub.asc");
   17.33 -
   17.34 -    assert(pub_key.length() != 0);
   17.35 -    
   17.36 -    PEP_STATUS statuspub = import_key(session, pub_key.c_str(), pub_key.length(), NULL);
   17.37 -    assert(statuspub == PEP_STATUS_OK);
   17.38 -    cout << "Key imported." << endl << endl;
   17.39 -    
   17.40 -    cout << "Setting up identity for mistrust.undo.test@pep-project.org and making comm_type PEP_ct_pEp."  << endl;
   17.41 -    pEp_identity* recip1 = new_identity("mistrust.undo.test@pep-project.org", NULL, "TOFU_mistrust.undo.test@pep-project.org", "Mistrust Undo");
   17.42 -    status = update_identity(session,recip1);
   17.43 -    assert(status == PEP_STATUS_OK);
   17.44 -    assert(strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0);
   17.45 -    
   17.46 -    // First, we need the fpr to be in the DB system.
   17.47 -    status = set_identity(session,recip1);
   17.48 -    // Then we update the trust.
   17.49 -    // This is not an external function. We use it to expedite the test since we don't do a sync exchange here.
   17.50 -    status = update_trust_for_fpr(session, recip1->fpr, PEP_ct_pEp);
   17.51 -    // Then we retrieve the new trust.
   17.52 -    status = update_identity(session,recip1);
   17.53 -    assert(status == PEP_STATUS_OK);
   17.54 -    assert(recip1->comm_type == PEP_ct_pEp);
   17.55 -    assert(strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0);
   17.56 -    cout << "mistrust.undo.test@pep-project.org set up and comm_type is PEP_ct_pEp."  << endl << endl;
   17.57 -
   17.58 -    // Ok, mistrust away
   17.59 -    cout << "Mistrusting mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5)."  << endl;   
   17.60 -    status = key_mistrusted(session, recip1);
   17.61 -    assert(status == PEP_STATUS_OK);
   17.62 -    status = update_identity(session,recip1);
   17.63 -    assert(status == PEP_STATUS_OK);
   17.64 -    assert(recip1->comm_type == PEP_ct_key_not_found);
   17.65 -    recip1->fpr = strdup("BACC7A60A88A39A25D99B4A545D7542F39E5DAB5");
   17.66 -    status = get_trust(session, recip1);
   17.67 -    assert(recip1->comm_type == PEP_ct_mistrusted);
   17.68 -     
   17.69 -    cout << "Mistrusted mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5) and comm_type IN DB set to PEP_ct_mistrusted)." << endl  << endl;    
   17.70 -    
   17.71 -    cout << "Undo mistrust (restore identity and trust in DB)" << endl;
   17.72 -    // Undo it
   17.73 -    status = undo_last_mistrust(session);
   17.74 -    assert(status == PEP_STATUS_OK);
   17.75 -    status = update_identity(session, recip1);
   17.76 -    assert(recip1->comm_type == PEP_ct_pEp);
   17.77 -    assert(strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0);
   17.78 -    cout << "Undo mistrust (restore identity and trust in DB) - trust is now PEP_ct_pEp." << endl << endl;
   17.79 -
   17.80 -    cout << "Success!!!" << endl << endl;
   17.81 -    
   17.82 -    free_identity(recip1);
   17.83 -    release(session);
   17.84 -
   17.85 -    return 0;
   17.86 -}
    18.1 --- a/test/new_update_id_and_myself_test.cc	Tue May 08 11:09:11 2018 +0200
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,622 +0,0 @@
    18.4 -// This file is under GNU General Public License 3.0
    18.5 -// see LICENSE.txt
    18.6 -
    18.7 -#include <iostream>
    18.8 -#include <iostream>
    18.9 -#include <fstream>
   18.10 -#include <string>
   18.11 -#include <cstring> // for strcmp()
   18.12 -#include <assert.h>
   18.13 -#include "pEpEngine.h"
   18.14 -#include "message_api.h"
   18.15 -#include "keymanagement.h"
   18.16 -#include "test_util.h"
   18.17 -
   18.18 -using namespace std;
   18.19 -
   18.20 -int main() {
   18.21 -    cout << "\n*** test update_identity and myself ***\n\n";
   18.22 -    
   18.23 -    test_init();
   18.24 -    
   18.25 -    PEP_SESSION session;
   18.26 -    
   18.27 -    cout << "calling init()\n";
   18.28 -    PEP_STATUS status = init(&session);
   18.29 -    assert(status == PEP_STATUS_OK);
   18.30 -    assert(session);
   18.31 -    cout << "init() completed.\n";
   18.32 -    cout << endl;
   18.33 -    cout << "***********************************************************************" << endl;
   18.34 -    cout << "* Section I. myself()" << endl;
   18.35 -    cout << "***********************************************************************" << endl << endl;
   18.36 -
   18.37 -    // Create id with no key
   18.38 -    cout << "Creating new own id with no key for : ";
   18.39 -    char *uniqname = strdup("AAAAtestuser@testdomain.org");
   18.40 -    srandom(time(NULL));
   18.41 -    for(int i=0; i < 4;i++)
   18.42 -        uniqname[i] += random() & 0xf;
   18.43 -    
   18.44 -    cout << uniqname << "\n";
   18.45 -    
   18.46 -    const char* own_user_id = get_new_uuid();
   18.47 -    const char* start_username = "Unser Testkandidat";
   18.48 -
   18.49 -    pEp_identity * new_me = new_identity(uniqname, NULL, own_user_id, start_username);
   18.50 -    
   18.51 -    cout << "***********************************************************************" << endl;
   18.52 -    cout << "* I: 1. myself() on id with no record in the DB and no input fpr" << endl;
   18.53 -    cout << "***********************************************************************" << endl << endl;
   18.54 -    status = myself(session, new_me);
   18.55 -    assert(status == PEP_STATUS_OK);
   18.56 -    assert(new_me->fpr);
   18.57 -    
   18.58 -    cout << "PASS: myself() generated fingerprint ";
   18.59 -    cout << new_me->fpr << endl << endl;
   18.60 -
   18.61 -    char* generated_fpr = strdup(new_me->fpr);
   18.62 -    
   18.63 -    assert(new_me->comm_type == PEP_ct_pEp);
   18.64 -    
   18.65 -    free_identity(new_me);
   18.66 -
   18.67 -    cout << "***********************************************************************" << endl;
   18.68 -    cout << "* I: 2. myself() on id with no input fpr and a record in the DB" << endl;
   18.69 -    cout << "***********************************************************************" << endl << endl;
   18.70 -
   18.71 -    new_me = new_identity(uniqname, NULL, own_user_id, NULL);
   18.72 -    status = myself(session, new_me);
   18.73 -    assert(status == PEP_STATUS_OK);
   18.74 -    
   18.75 -    assert(new_me->fpr);
   18.76 -    assert(strcmp(new_me->fpr, generated_fpr) == 0);
   18.77 -    assert(new_me->username);
   18.78 -    assert(strcmp(new_me->username, start_username) == 0);
   18.79 -    assert(new_me->user_id);
   18.80 -    assert(new_me->comm_type == PEP_ct_pEp);
   18.81 -    
   18.82 -    char* default_own_id = NULL;
   18.83 -    status = get_userid_alias_default(session, own_user_id, &default_own_id);
   18.84 -    if (status == PEP_CANNOT_FIND_ALIAS) {
   18.85 -        // Ok, we presume our own id above is the default (should be true if there was no existing DB as in test env)
   18.86 -        default_own_id = strdup(own_user_id);
   18.87 -    }
   18.88 -
   18.89 -    assert(strcmp(new_me->user_id, default_own_id) == 0);
   18.90 -    
   18.91 -    cout << "PASS: myself() retrieved the correct fpr, username and default user id" << endl << endl;
   18.92 -
   18.93 -    free_identity(new_me);
   18.94 -     
   18.95 -    cout << "****************************************************************************************" << endl;
   18.96 -    cout << "* I: 3. myself() on id with no input fpr, a different user_id, and a record in the DB" << endl;
   18.97 -    cout << "****************************************************************************************" << endl << endl;
   18.98 -
   18.99 -    const char* alias_id = "Huss Es El Mejor Presidente Del Mundo!";
  18.100 -
  18.101 -    new_me = new_identity(uniqname, NULL, alias_id, NULL);
  18.102 -    status = myself(session, new_me);
  18.103 -    assert(status == PEP_STATUS_OK);
  18.104 -    
  18.105 -    assert(new_me->fpr);
  18.106 -    assert(strcmp(new_me->fpr, generated_fpr) == 0);
  18.107 -    assert(new_me->username);
  18.108 -    assert(strcmp(new_me->username, start_username) == 0);
  18.109 -    assert(new_me->user_id);
  18.110 -    assert(strcmp(new_me->user_id, default_own_id) == 0);
  18.111 -    assert(new_me->comm_type == PEP_ct_pEp);
  18.112 -    
  18.113 -    char* tmp_def = NULL;
  18.114 -    
  18.115 -    status = get_userid_alias_default(session, alias_id, &tmp_def);
  18.116 -    assert(status == PEP_STATUS_OK);
  18.117 -    assert(strcmp(tmp_def, default_own_id) == 0);
  18.118 -
  18.119 -    cout << "PASS: myself() retrieved the correct fpr, username and default user id, and put the right alias in for the default";
  18.120 -    cout << endl << endl;
  18.121 -    
  18.122 -    free(tmp_def);
  18.123 -    free_identity(new_me);
  18.124 -
  18.125 -    cout << "****************************************************************************************" << endl;
  18.126 -    cout << "* I: 4. myself(), replace fpr" << endl;
  18.127 -    cout << "****************************************************************************************" << endl << endl;
  18.128 -
  18.129 -    new_me = new_identity(uniqname, NULL, alias_id, start_username);
  18.130 -    status = generate_keypair(session, new_me);
  18.131 -    assert(new_me->fpr);
  18.132 -    
  18.133 -    cout << "Generated fingerprint ";
  18.134 -    cout << new_me->fpr << "\n";
  18.135 -
  18.136 -    char* new_fpr = strdup(new_me->fpr);
  18.137 -
  18.138 -    status = set_own_key(session, new_me, new_fpr);
  18.139 -    assert(status == PEP_STATUS_OK);
  18.140 -    assert(new_me->fpr);
  18.141 -    assert(strcmp(new_me->fpr, generated_fpr) != 0);
  18.142 -    assert(strcmp(new_me->fpr, new_fpr) == 0);
  18.143 -    assert(new_me->username);
  18.144 -    assert(strcmp(new_me->username, start_username) == 0);
  18.145 -    assert(new_me->user_id);
  18.146 -    assert(strcmp(new_me->user_id, default_own_id) == 0);
  18.147 -    assert(new_me->me);
  18.148 -    assert(new_me->comm_type == PEP_ct_pEp);
  18.149 -
  18.150 -    cout << "PASS: myself() set and retrieved the new fpr, username and default user id, and put the right alias in for the default";
  18.151 -    cout << endl << endl;
  18.152 -
  18.153 -    // since that worked, we'll set it back as the default
  18.154 -    free(new_me->fpr);
  18.155 -    new_me->fpr = strdup(generated_fpr);
  18.156 -    new_me->comm_type = PEP_ct_unknown;
  18.157 -    status = set_own_key(session, new_me, generated_fpr);
  18.158 -    assert(status == PEP_STATUS_OK);
  18.159 -    assert(strcmp(new_me->fpr, generated_fpr) == 0);
  18.160 -    assert(new_me->comm_type == PEP_ct_pEp);
  18.161 -    
  18.162 -    cout << "****************************************************************************************" << endl;
  18.163 -    cout << "* I: 5. myself(), replace fpr, revoke key" << endl;
  18.164 -    cout << "****************************************************************************************" << endl << endl;
  18.165 -
  18.166 -    status = revoke_key(session, generated_fpr, "Because it's fun");
  18.167 -    assert (status == PEP_STATUS_OK);
  18.168 -    
  18.169 -    new_me = new_identity(uniqname, NULL, alias_id, start_username);
  18.170 -    
  18.171 -    status = set_own_key(session, new_me, new_fpr);
  18.172 -    assert(status == PEP_STATUS_OK);
  18.173 -    assert(new_me->fpr);
  18.174 -    assert(strcmp(new_me->fpr, generated_fpr) != 0);
  18.175 -    assert(new_me->username);
  18.176 -    assert(strcmp(new_me->username, start_username) == 0);
  18.177 -    assert(new_me->user_id);
  18.178 -    assert(strcmp(new_me->user_id, default_own_id) == 0);
  18.179 -    assert(new_me->me);
  18.180 -    assert(new_me->comm_type == PEP_ct_pEp);
  18.181 -    
  18.182 -    cout << "PASS: myself() retrieved the new fpr, username and default user id, and put the right alias in for the default";
  18.183 -    cout << endl << endl;
  18.184 -        
  18.185 -    cout << "***********************************************************************" << endl;
  18.186 -    cout << "* Section II. update_identity()" << endl;
  18.187 -    cout << "***********************************************************************" << endl << endl;
  18.188 -
  18.189 -    cout << "****************************************************************************************" << endl;
  18.190 -    cout << "* II: 1. update_identity() - get identity with matching address and user_id and username" << endl;
  18.191 -    cout << "****************************************************************************************" << endl << endl;    
  18.192 -    // 1. create original identity
  18.193 -    const char* alex_address = "pep.test.alexander@peptest.ch";
  18.194 -    const char* alex_fpr = "3AD9F60FAEB22675DB873A1362D6981326B54E4E";
  18.195 -    const char* alex_userid = "Alex";
  18.196 -    const char* alex_username = "SuperDuperAlex";
  18.197 -    const string alex_pub_key = slurp("test_keys/pub/pep.test.alexander-0x26B54E4E_pub.asc");
  18.198 -    
  18.199 -    PEP_STATUS statuspub = import_key(session, alex_pub_key.c_str(), alex_pub_key.length(), NULL);
  18.200 -    assert(statuspub == PEP_STATUS_OK);
  18.201 -
  18.202 -    pEp_identity* alex = new_identity(alex_address, alex_fpr, alex_userid, alex_username);
  18.203 -
  18.204 -    // 2. set identity
  18.205 -    status = set_identity(session, alex);
  18.206 -    assert(status == PEP_STATUS_OK);
  18.207 -    free_identity(alex);
  18.208 -            
  18.209 -    alex = new_identity(alex_address, NULL, alex_userid, alex_username); 
  18.210 -    status = update_identity(session, alex);
  18.211 -    assert(status == PEP_STATUS_OK);
  18.212 -    assert(alex->fpr);
  18.213 -    assert(strcmp(alex->fpr, alex_fpr) == 0);
  18.214 -    assert(alex->username);
  18.215 -    assert(strcmp(alex->username, alex_username) == 0);
  18.216 -    assert(alex->user_id);
  18.217 -    assert(strcmp(alex->user_id, alex_userid) == 0);
  18.218 -    assert(!alex->me); 
  18.219 -    assert(alex->comm_type == PEP_ct_OpenPGP_unconfirmed);
  18.220 -    assert(strcmp(alex->address, alex_address) == 0);
  18.221 -
  18.222 -    cout << "PASS: update_identity() correctly retrieved extant record with matching address, id, and username" << endl << endl;
  18.223 -    free_identity(alex);
  18.224 -
  18.225 -    cout << "****************************************************************************************" << endl;
  18.226 -    cout << "* II: 2. update_identity() - get identity with matching address and user_id and new username" << endl;
  18.227 -    cout << "****************************************************************************************" << endl << endl;    
  18.228 -
  18.229 -    const char* new_username = "Test Patchy";
  18.230 -            
  18.231 -    alex = new_identity(alex_address, NULL, alex_userid, new_username);
  18.232 -    cout << "Timing is everything" << endl; 
  18.233 -    status = update_identity(session, alex);
  18.234 -    assert(status == PEP_STATUS_OK);
  18.235 -    assert(alex->fpr);
  18.236 -    assert(strcmp(alex->fpr, alex_fpr) == 0);
  18.237 -    assert(alex->username);
  18.238 -    assert(strcmp(alex->username, new_username) == 0);
  18.239 -    assert(alex->user_id);
  18.240 -    assert(strcmp(alex->user_id, alex_userid) == 0);
  18.241 -    assert(!alex->me); 
  18.242 -    assert(alex->comm_type == PEP_ct_OpenPGP_unconfirmed);
  18.243 -    assert(strcmp(alex->address, alex_address) == 0);
  18.244 -
  18.245 -    cout << "PASS: update_identity() correctly retrieved extant record with matching address and id, and patched username" << endl << endl;
  18.246 -    free_identity(alex);
  18.247 -
  18.248 -    cout << "****************************************************************************************" << endl;
  18.249 -    cout << "* II: 3. update_identity() - get identity with matching address and user_id only" << endl;
  18.250 -    cout << "****************************************************************************************" << endl << endl;    
  18.251 -        
  18.252 -    alex = new_identity(alex_address, NULL, alex_userid, NULL); 
  18.253 -    status = update_identity(session, alex);
  18.254 -    assert(status == PEP_STATUS_OK);
  18.255 -    assert(alex->fpr);
  18.256 -    assert(strcmp(alex->fpr, alex_fpr) == 0);
  18.257 -    assert(alex->username);
  18.258 -    assert(strcmp(alex->username, new_username) == 0);
  18.259 -    assert(alex->user_id);
  18.260 -    assert(strcmp(alex->user_id, alex_userid) == 0);
  18.261 -    assert(!alex->me); 
  18.262 -    assert(alex->comm_type == PEP_ct_OpenPGP_unconfirmed);
  18.263 -    assert(strcmp(alex->address, alex_address) == 0);
  18.264 -
  18.265 -    cout << "PASS: update_identity() correctly retrieved extant record with matching address and id, and patched username" << endl << endl;
  18.266 -    free_identity(alex);
  18.267 -
  18.268 -    cout << "****************************************************************************************" << endl;
  18.269 -    cout << "* II: 4. update_identity() - get identity with just address and username" << endl;
  18.270 -    cout << "****************************************************************************************" << endl << endl;    
  18.271 -
  18.272 -    alex = new_identity(alex_address, NULL, NULL, new_username); 
  18.273 -    status = update_identity(session, alex);
  18.274 -    assert(status == PEP_STATUS_OK);
  18.275 -    assert(alex->fpr);
  18.276 -    assert(strcmp(alex->fpr, alex_fpr) == 0);
  18.277 -    assert(alex->username);
  18.278 -    assert(strcmp(alex->username, new_username) == 0);
  18.279 -    assert(alex->user_id);
  18.280 -    assert(strcmp(alex->user_id, alex_userid) == 0);
  18.281 -    assert(!alex->me); 
  18.282 -    assert(alex->comm_type == PEP_ct_OpenPGP_unconfirmed);
  18.283 -    assert(strcmp(alex->address, alex_address) == 0);
  18.284 -
  18.285 -    cout << "PASS: update_identity() correctly retrieved extant record with matching address and username" << endl << endl;
  18.286 -    free_identity(alex);
  18.287 -
  18.288 -    cout << "****************************************************************************************" << endl;
  18.289 -    cout << "* II: 5. update_identity() with just address " << endl;
  18.290 -    cout << "****************************************************************************************" << endl << endl;
  18.291 -    
  18.292 -    alex = new_identity(alex_address, NULL, NULL, NULL); 
  18.293 -    status = update_identity(session, alex);
  18.294 -    assert(status == PEP_STATUS_OK);
  18.295 -    assert(alex->fpr);
  18.296 -    assert(strcmp(alex->fpr, alex_fpr) == 0);
  18.297 -    assert(alex->username);
  18.298 -    assert(strcmp(alex->username, new_username) == 0);
  18.299 -    assert(alex->user_id);
  18.300 -    assert(strcmp(alex->user_id, alex_userid) == 0);
  18.301 -    assert(!alex->me); 
  18.302 -    assert(alex->comm_type == PEP_ct_OpenPGP_unconfirmed);
  18.303 -    assert(strcmp(alex->address, alex_address) == 0);
  18.304 -
  18.305 -    cout << "PASS: update_identity() correctly retrieved extant record with just matching address. Retrieved previously patched username." << endl << endl;
  18.306 -    free_identity(alex);
  18.307 -
  18.308 -
  18.309 -    cout << "****************************************************************************************" << endl;
  18.310 -    cout << "* II: 6. update_identity() with just address on own identity (only case where this is legal)" << endl;
  18.311 -    cout << "****************************************************************************************" << endl << endl;
  18.312 -    
  18.313 -    pEp_identity* somebody = new_identity(uniqname, NULL, NULL, NULL); 
  18.314 -    status = update_identity(session, somebody);
  18.315 -    assert(status == PEP_STATUS_OK);
  18.316 -    myself(session, somebody);
  18.317 -    assert(somebody->fpr);
  18.318 -    assert(strcmp(somebody->fpr, new_fpr) == 0);
  18.319 -    assert(somebody->username);
  18.320 -    assert(strcmp(somebody->username, start_username) == 0);
  18.321 -    assert(somebody->user_id);
  18.322 -    assert(strcmp(somebody->user_id, default_own_id) == 0);
  18.323 -    assert(somebody->me); // true in this case, as it was an own identity
  18.324 -    assert(somebody->comm_type == PEP_ct_pEp);
  18.325 -    assert(strcmp(somebody->address, uniqname) == 0);
  18.326 -    
  18.327 -    cout << "PASS: update_identity() retrieved the right identity information given just an address";
  18.328 -    cout << endl << endl;
  18.329 -
  18.330 -    free_identity(somebody);
  18.331 -
  18.332 -    cout << "****************************************************************************************" << endl;
  18.333 -    cout << "* II: 7. update_identity() for address and user_id that don't exist" << endl;
  18.334 -    cout << "****************************************************************************************" << endl << endl;
  18.335 -
  18.336 -    somebody = new_identity("nope@nope.nope", NULL, "some_user_id", NULL); 
  18.337 -    status = update_identity(session, somebody);
  18.338 -    assert(status == PEP_STATUS_OK);
  18.339 -    assert(!somebody->fpr);
  18.340 -    assert(somebody->comm_type == PEP_ct_key_not_found);
  18.341 -    
  18.342 -    cout << "PASS: update_identity() returns identity with no key and unknown comm type" << endl << endl;
  18.343 -
  18.344 -    free_identity(somebody);
  18.345 -    
  18.346 -    cout << "****************************************************************************************" << endl;
  18.347 -    cout << "* II: 8. update_identity() for address and and username, but non-matching temp user_id" << endl;
  18.348 -    cout << "****************************************************************************************" << endl << endl;
  18.349 -
  18.350 -    // 1. create identity
  18.351 -    const char* bella_address = "pep.test.bella@peptest.ch";
  18.352 -    const char* bella_fpr = "5631BF1357326A02AA470EEEB815EF7FA4516AAE";
  18.353 -    const char* bella_userid = "TOFU_pep.test.bella@peptest.ch"; // simulate temp ID
  18.354 -    const char* bella_username = "Annabella the Great";
  18.355 -    const string bella_pub_key = slurp("test_keys/pub/pep.test.bella-0xAF516AAE_pub.asc");
  18.356 -    
  18.357 -    statuspub = import_key(session, bella_pub_key.c_str(), bella_pub_key.length(), NULL);
  18.358 -    assert(statuspub == PEP_STATUS_OK);
  18.359 -
  18.360 -    pEp_identity* bella = new_identity(bella_address, bella_fpr, bella_userid, bella_username);
  18.361 -    
  18.362 -    // 2. set identity
  18.363 -    status = set_identity(session, bella);
  18.364 -    assert(status == PEP_STATUS_OK);
  18.365 -    free_identity(bella);
  18.366 -    
  18.367 -    const char* not_my_userid = "Bad Company";
  18.368 -            
  18.369 -    bella = new_identity(bella_address, NULL, not_my_userid, bella_username); 
  18.370 -    status = update_identity(session, bella);
  18.371 -    assert(status == PEP_STATUS_OK);
  18.372 -    assert(bella->fpr);
  18.373 -    assert(strcmp(bella->fpr, bella_fpr) == 0);
  18.374 -    assert(bella->username);
  18.375 -    assert(strcmp(bella->username, bella_username) == 0);
  18.376 -    assert(bella->user_id);
  18.377 -    assert(strcmp(bella->user_id, not_my_userid) == 0); // ???
  18.378 -    assert(!bella->me); 
  18.379 -    assert(bella->comm_type == PEP_ct_OpenPGP_unconfirmed);
  18.380 -    assert(strcmp(bella->address, bella_address) == 0);
  18.381 -
  18.382 -    cout << "PASS: update_identity() correctly retrieved extant record with matching address and username; temp user_id in DB patched" << endl << endl;
  18.383 -    free_identity(bella);
  18.384 -
  18.385 -    cout << "****************************************************************************************" << endl;
  18.386 -    cout << "* II: 9. update_identity() for address, username, and user_id, but no matching record" << endl;
  18.387 -    cout << "****************************************************************************************" << endl << endl;
  18.388 -    
  18.389 -    const char* rando_name = "Pickley BoofBoof";
  18.390 -    const char* rando_userid = "Boofy";
  18.391 -    const char* rando_address = "boof@pickles.org";
  18.392 -    somebody = new_identity(rando_address, NULL, rando_userid, rando_name);
  18.393 -    status = update_identity(session, somebody);
  18.394 -
  18.395 -    assert(status == PEP_STATUS_OK);
  18.396 -    assert(!somebody->fpr || somebody->fpr[0] == '\0');
  18.397 -    assert(somebody->username);
  18.398 -    assert(strcmp(somebody->username, rando_name) == 0);
  18.399 -    assert(somebody->user_id);
  18.400 -    assert(strcmp(somebody->user_id, rando_userid) == 0); // ???
  18.401 -    assert(!somebody->me); 
  18.402 -    assert(somebody->comm_type == PEP_ct_key_not_found);
  18.403 -    assert(strcmp(somebody->address, rando_address) == 0);
  18.404 -
  18.405 -    cout << "PASS: update_identity() correctly created record with no key" << endl << endl;
  18.406 -    free_identity(somebody);
  18.407 -    
  18.408 -    cout << "****************************************************************************************" << endl;
  18.409 -    cout << "* II: 10. update_identity() for address, username, but no matching record" << endl;
  18.410 -    cout << "****************************************************************************************" << endl << endl;
  18.411 -
  18.412 -    const char* rando2_name = "Pickles BoofyBoof";
  18.413 -    const char* rando2_address = "boof2@pickles.org";
  18.414 -    somebody = new_identity(rando2_address, NULL, NULL, rando2_name);
  18.415 -    status = update_identity(session, somebody);
  18.416 -    const char* expected_rando2_userid = "TOFU_boof2@pickles.org";
  18.417 -
  18.418 -    assert(status == PEP_STATUS_OK);
  18.419 -    assert(!somebody->fpr || somebody->fpr[0] == '\0');
  18.420 -    assert(somebody->username);
  18.421 -    assert(strcmp(somebody->username, rando2_name) == 0);
  18.422 -    assert(somebody->user_id);
  18.423 -    assert(strcmp(somebody->user_id, expected_rando2_userid) == 0); // ???
  18.424 -    assert(!somebody->me); 
  18.425 -    assert(somebody->comm_type == PEP_ct_key_not_found);
  18.426 -    assert(strcmp(somebody->address, rando2_address) == 0);
  18.427 -
  18.428 -    cout << "PASS: update_identity() correctly created record with no key" << endl << endl;
  18.429 -    free_identity(somebody);
  18.430 -
  18.431 -    cout << "****************************************************************************************" << endl;
  18.432 -    cout << "* II: 11. update_identity() for address only, but multiple matching records" << endl;
  18.433 -    cout << "****************************************************************************************" << endl << endl;
  18.434 -
  18.435 -    const char* bella_id_2 = "Bella2";
  18.436 -    bella = new_identity(bella_address, NULL, bella_id_2, bella_username);
  18.437 -    
  18.438 -    // 2. set identity
  18.439 -    status = set_identity(session, bella);
  18.440 -    assert(status == PEP_STATUS_OK);
  18.441 -    free_identity(bella);
  18.442 -                
  18.443 -    bella = new_identity(bella_address, NULL, NULL, NULL); 
  18.444 -    status = update_identity(session, bella);
  18.445 -    assert(status == PEP_STATUS_OK);
  18.446 -
  18.447 -//    cout << "PASS: update_identity() correctly failed with no matching records (too little info)" << endl << endl;
  18.448 -    
  18.449 -    cout << "****************************************************************************************" << endl;
  18.450 -    cout << "* III: key election " << endl;
  18.451 -    cout << "****************************************************************************************" << endl << endl;
  18.452 -
  18.453 -    cout << "****************************************************************************************" << endl;
  18.454 -    cout << "* III: 1. key election: get identity for user with expired key" << endl;
  18.455 -    cout << "****************************************************************************************" << endl << endl;
  18.456 -
  18.457 -    // 1. create identity
  18.458 -    const char* bernd_address = "bernd.das.brot@darthmama.org";
  18.459 -    const char* bernd_fpr = "F8CE0F7E24EB190A2FCBFD38D4B088A7CAFAA422";
  18.460 -    const char* bernd_userid = "BERND_ID"; // simulate temp ID
  18.461 -    const char* bernd_username = "Bernd das Brot der Ultimative Testkandidat";
  18.462 -    const string bernd_pub_key = slurp("test_keys/pub/bernd.das.brot-0xCAFAA422_pub.asc");
  18.463 -    
  18.464 -    statuspub = import_key(session, bernd_pub_key.c_str(), bernd_pub_key.length(), NULL);
  18.465 -    assert(statuspub == PEP_STATUS_OK);
  18.466 -
  18.467 -    pEp_identity* bernd = new_identity(bernd_address, bernd_fpr, bernd_userid, bernd_username);
  18.468 -    
  18.469 -    // 2. set identity
  18.470 -    status = set_identity(session, bernd);
  18.471 -    assert(status == PEP_STATUS_OK);
  18.472 -    free_identity(bernd);
  18.473 -                
  18.474 -    bernd = new_identity(bernd_address, NULL, bernd_userid, bernd_username); 
  18.475 -    status = update_identity(session, bernd);
  18.476 -    assert(status != PEP_STATUS_OK);
  18.477 -    assert(!bernd->fpr || bernd->fpr[0] == '\0');
  18.478 -    assert(bernd->username);
  18.479 -    assert(strcmp(bernd->username, bernd_username) == 0);
  18.480 -    assert(bernd->user_id);
  18.481 -    assert(strcmp(bernd->user_id, bernd_userid) == 0); // ???
  18.482 -    assert(!bernd->me); 
  18.483 -    assert(bernd->comm_type == PEP_ct_key_expired);
  18.484 -    assert(strcmp(bernd->address, bernd_address) == 0);
  18.485 -
  18.486 -    cout << "PASS: update_identity() correctly rejected expired key with PEP_KEY_UNSUITABLE and PEP_ct_key_expired" << endl << endl;
  18.487 -    free_identity(bernd);
  18.488 -
  18.489 -
  18.490 -    cout << "****************************************************************************************" << endl;
  18.491 -    cout << "* III: 2. key election: get identity for user with only revoked or mistrusted keys " << endl;
  18.492 -    cout << "****************************************************************************************" << endl << endl;
  18.493 -
  18.494 -    // Create id with no key
  18.495 -    cout << "Creating new id with no key for : ";
  18.496 -    char *uniqname_10000 = strdup("AAAAtestuser@testdomain.org");
  18.497 -    srandom(time(NULL));
  18.498 -    for(int i=0; i < 4;i++)
  18.499 -        uniqname_10000[i] += random() & 0xf;
  18.500 -    
  18.501 -    cout << uniqname_10000 << "\n";
  18.502 -
  18.503 -    char* revoke_uuid = get_new_uuid();
  18.504 -
  18.505 -    pEp_identity * revokemaster_3000 = new_identity(uniqname_10000, NULL, revoke_uuid, start_username);
  18.506 -    
  18.507 -    cout << "Generate three keys for "  << uniqname_10000 << " who has user_id " << revoke_uuid << endl; 
  18.508 -
  18.509 -    char* revoke_fpr_arr[3];
  18.510 -    
  18.511 -    status = generate_keypair(session, revokemaster_3000);
  18.512 -    assert(status == PEP_STATUS_OK && revokemaster_3000->fpr);
  18.513 -    revoke_fpr_arr[0] = strdup(revokemaster_3000->fpr);
  18.514 -    free(revokemaster_3000->fpr);
  18.515 -    revokemaster_3000->fpr = NULL;
  18.516 -    
  18.517 -    status = generate_keypair(session, revokemaster_3000);
  18.518 -    assert(status == PEP_STATUS_OK && revokemaster_3000->fpr);
  18.519 -    revoke_fpr_arr[1] = strdup(revokemaster_3000->fpr);
  18.520 -    free(revokemaster_3000->fpr);
  18.521 -    revokemaster_3000->fpr = NULL;
  18.522 -    
  18.523 -    status = generate_keypair(session, revokemaster_3000);
  18.524 -    assert(status == PEP_STATUS_OK && revokemaster_3000->fpr);
  18.525 -    revoke_fpr_arr[2] = strdup(revokemaster_3000->fpr);
  18.526 -    free(revokemaster_3000->fpr);
  18.527 -    revokemaster_3000->fpr = NULL;
  18.528 -    
  18.529 -    cout << "Trust "  << revoke_fpr_arr[2] << " (default for identity) and " << revoke_fpr_arr[0] << endl;
  18.530 -    
  18.531 -    free(revokemaster_3000->fpr);
  18.532 -    revokemaster_3000->fpr = strdup(revoke_fpr_arr[2]);
  18.533 -    status = trust_personal_key(session, revokemaster_3000);
  18.534 -    assert(status == PEP_STATUS_OK);
  18.535 -    status = get_trust(session, revokemaster_3000);
  18.536 -    assert(status == PEP_STATUS_OK);
  18.537 -    assert(revokemaster_3000->comm_type & PEP_ct_confirmed);
  18.538 -
  18.539 -    free(revokemaster_3000->fpr);
  18.540 -    revokemaster_3000->fpr = strdup(revoke_fpr_arr[0]);
  18.541 -    status = trust_personal_key(session, revokemaster_3000);
  18.542 -    assert(status == PEP_STATUS_OK);
  18.543 -    status = get_trust(session, revokemaster_3000);
  18.544 -    assert(status == PEP_STATUS_OK);
  18.545 -    assert(revokemaster_3000->comm_type & PEP_ct_confirmed);
  18.546 -    
  18.547 -    status = update_identity(session, revokemaster_3000);
  18.548 -    assert(status == PEP_STATUS_OK);
  18.549 -    assert(revokemaster_3000->fpr);
  18.550 -    assert(strcmp(revokemaster_3000->fpr, revoke_fpr_arr[2]) == 0);
  18.551 -    assert(revokemaster_3000->comm_type & PEP_ct_confirmed);
  18.552 -
  18.553 -    cout << "update_identity returns the correct identity default." << endl;
  18.554 -    
  18.555 -    cout << "Ok, now... we revoke the default..." << endl;
  18.556 -    
  18.557 -    cout << "Revoking " << revoke_fpr_arr[2] << endl;
  18.558 -
  18.559 -    status = revoke_key(session, revoke_fpr_arr[2], "This little pubkey went to market");
  18.560 -    assert (status == PEP_STATUS_OK);
  18.561 -
  18.562 -    bool is_revoked;
  18.563 -    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);    
  18.564 -    assert(status == PEP_STATUS_OK);
  18.565 -    assert(is_revoked);
  18.566 -
  18.567 -    cout << "Success revoking " << revoke_fpr_arr[2] << "!!! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
  18.568 -    
  18.569 -    cout << "Now see if update_identity gives us " << revoke_fpr_arr[0] << ", the only trusted key left." << endl;
  18.570 -    status = update_identity(session, revokemaster_3000);
  18.571 -    assert(status == PEP_STATUS_OK);
  18.572 -    assert(revokemaster_3000->fpr);
  18.573 -    assert(strcmp(revokemaster_3000->fpr, revoke_fpr_arr[0]) == 0);
  18.574 -    assert(revokemaster_3000->comm_type & PEP_ct_confirmed);    
  18.575 -    
  18.576 -    cout << "Success! So let's mistrust it, because seriously, that key was so uncool." << endl;
  18.577 -    
  18.578 -    status = key_mistrusted(session, revokemaster_3000);
  18.579 -    assert(status == PEP_STATUS_OK);
  18.580 -
  18.581 -    status = get_trust(session, revokemaster_3000);
  18.582 -    assert(status == PEP_STATUS_OK);
  18.583 -    assert(revokemaster_3000->comm_type == PEP_ct_mistrusted);
  18.584 -    
  18.585 -    cout << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
  18.586 -
  18.587 -    cout << "The only fpr left is an untrusted one - let's make sure this is what we get from update_identity." << endl;
  18.588 -
  18.589 -    status = update_identity(session, revokemaster_3000);
  18.590 -    assert(status == PEP_STATUS_OK);
  18.591 -    assert(revokemaster_3000->fpr);
  18.592 -    assert(strcmp(revokemaster_3000->fpr, revoke_fpr_arr[1]) == 0);
  18.593 -    assert(!(revokemaster_3000->comm_type & PEP_ct_confirmed));    
  18.594 -
  18.595 -    cout << "Success! We got " << revoke_fpr_arr[1] << "as the fpr with comm_type " << revokemaster_3000->comm_type << endl;
  18.596 -    
  18.597 -    cout << "But, you know... let's revoke that one too and see what update_identity gives us." << endl;
  18.598 -
  18.599 -    status = revoke_key(session, revoke_fpr_arr[1], "Because it's more fun to revoke ALL of someone's keys");
  18.600 -    assert (status == PEP_STATUS_OK);
  18.601 -
  18.602 -    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);    
  18.603 -    assert(status == PEP_STATUS_OK);
  18.604 -    assert(is_revoked);
  18.605 -    
  18.606 -    cout << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
  18.607 -
  18.608 -    cout << "Call update_identity - we expect nothing, plus an error comm type." << endl;
  18.609 -
  18.610 -    status = update_identity(session, revokemaster_3000);
  18.611 -    assert(status != PEP_STATUS_OK);
  18.612 -    assert(!revokemaster_3000->fpr);
  18.613 -    assert(revokemaster_3000->username);
  18.614 -    assert(strcmp(revokemaster_3000->user_id, revoke_uuid) == 0);
  18.615 -    assert(revokemaster_3000->comm_type == PEP_ct_key_not_found);
  18.616 -    cout << "Success! No key found. The comm_status error was " << revokemaster_3000->comm_type << "and the return status was " << tl_status_string(status) << endl;
  18.617 -
  18.618 -    free_identity(revokemaster_3000);
  18.619 -
  18.620 -    cout << "****************************************************************************************" << endl;
  18.621 -    cout << "* III: 100000000. key election: more to come " << endl;
  18.622 -    cout << "****************************************************************************************" << endl << endl;
  18.623 -
  18.624 -    return 0;
  18.625 -}
    19.1 --- a/test/pEp_subject_received_test.cc	Tue May 08 11:09:11 2018 +0200
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,484 +0,0 @@
    19.4 -#include <iostream>
    19.5 -#include <iostream>
    19.6 -#include <fstream>
    19.7 -#include <string>
    19.8 -#include <cstring> // for strcmp()
    19.9 -#include <assert.h>
   19.10 -#include "blacklist.h"
   19.11 -#include "keymanagement.h"
   19.12 -#include "message_api.h"
   19.13 -#include "mime.h"
   19.14 -#include "test_util.h" // for slurp()
   19.15 -
   19.16 -using namespace std;
   19.17 -
   19.18 -int main(int argc, char** argv) {
   19.19 -
   19.20 -    cout << "\n*** check that p≡p subject is handled properly in received mails ***\n\n";
   19.21 -
   19.22 -    PEP_SESSION session;
   19.23 -    
   19.24 -    cout << "calling init()\n";
   19.25 -    PEP_STATUS status1 = init(&session);   
   19.26 -    assert(status1 == PEP_STATUS_OK);
   19.27 -    assert(session);
   19.28 -    cout << "init() completed.\n";
   19.29 -
   19.30 -    const char* keytexts[3];
   19.31 -
   19.32 -    const string keytextkey1 = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   19.33 -    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
   19.34 -    const string keytextkey3 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
   19.35 -    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
   19.36 -    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
   19.37 -    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
   19.38 -
   19.39 -    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE", PEP_OWN_USERID, "pEp Test Recipient");    
   19.40 -    me->me = true;
   19.41 -    PEP_STATUS status = myself(session, me);
   19.42 -    
   19.43 -    pEp_identity * you = new_identity("pep.test.alice@pep-project.org", NULL, "TOFU_pep.test.alice@pep-project.org", "Alice Test");    
   19.44 -    you->me = false;
   19.45 -
   19.46 -    status = update_identity(session, you);
   19.47 -    trust_personal_key(session, you);
   19.48 -    status = update_identity(session, you);
   19.49 -
   19.50 -    cout << "------------------------------------------------------------------------------------------" << endl;
   19.51 -    cout << "Test 1a: Normal encrypted mail, pEp as substitute subject, regular subject in crypto text." << endl;
   19.52 -    cout << "------------------------------------------------------------------------------------------" << endl;
   19.53 -        
   19.54 -    string mailtext = slurp("test_mails/pEp_subject_normal_1a.eml");
   19.55 -    
   19.56 -    message* msg_ptr = nullptr;
   19.57 -    message* dest_msg = nullptr;
   19.58 -    message* final_ptr = nullptr;
   19.59 -    stringlist_t* keylist = nullptr;
   19.60 -    PEP_rating rating;
   19.61 -    PEP_decrypt_flags_t flags;
   19.62 -    
   19.63 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
   19.64 -    assert(status == PEP_STATUS_OK);
   19.65 -    assert(msg_ptr);
   19.66 -    final_ptr = msg_ptr;
   19.67 -    flags = 0;
   19.68 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   19.69 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
   19.70 -  
   19.71 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
   19.72 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
   19.73 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
   19.74 -
   19.75 -    assert(strcmp("This is the usual pEp subject that should replace the above.", final_ptr->shortmsg) == 0);
   19.76 -
   19.77 -    cout << "Test 1a: Subject replaced as expected." << endl << endl;
   19.78 -
   19.79 -    if (final_ptr == dest_msg)
   19.80 -    	free_message(dest_msg);
   19.81 -    free_message(msg_ptr);
   19.82 -    free_stringlist(keylist);
   19.83 -
   19.84 -    cout << "------------------------------------------------------------------------------------------" << endl;
   19.85 -    cout << "Test 1b: Normal encrypted mail, p≡p as substitute subject, regular subject in crypto text." << endl;
   19.86 -    cout << "------------------------------------------------------------------------------------------" << endl;
   19.87 -        
   19.88 -    mailtext = slurp("test_mails/p3p_subject_normal_1b.eml");
   19.89 -    
   19.90 -    msg_ptr = nullptr;
   19.91 -    dest_msg = nullptr;
   19.92 -    final_ptr = nullptr;
   19.93 -    keylist = nullptr;
   19.94 -    rating = PEP_rating_unreliable;
   19.95 -    
   19.96 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
   19.97 -    assert(status == PEP_STATUS_OK);
   19.98 -    assert(msg_ptr);
   19.99 -    final_ptr = msg_ptr;
  19.100 -    flags = 0;
  19.101 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.102 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.103 -  
  19.104 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.105 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.106 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.107 -
  19.108 -    assert(strcmp("This is the usual pEp subject that should replace the above.", final_ptr->shortmsg) == 0);
  19.109 -
  19.110 -    cout << "Test 1b: Subject replaced as expected." << endl << endl;
  19.111 -
  19.112 -    if (final_ptr == dest_msg)
  19.113 -    	free_message(dest_msg);
  19.114 -    free_message(msg_ptr);
  19.115 -    free_stringlist(keylist);
  19.116 -
  19.117 -    cout << "-------------------------------------------------------------------------------------------------" << endl;
  19.118 -    cout << "Test 2a: Normal encrypted/signed mail, pEp as substitute subject, regular subject in crypto text." << endl;
  19.119 -    cout << "-------------------------------------------------------------------------------------------------" << endl;
  19.120 -
  19.121 -    msg_ptr = nullptr;
  19.122 -    dest_msg = nullptr;
  19.123 -    final_ptr = nullptr;
  19.124 -    keylist = nullptr;
  19.125 -    rating = PEP_rating_unreliable;
  19.126 -    
  19.127 -    mailtext = slurp("test_mails/pEp_subject_normal_signed_2a.eml");
  19.128 -    
  19.129 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  19.130 -    assert(status == PEP_STATUS_OK);
  19.131 -    assert(msg_ptr);
  19.132 -    final_ptr = msg_ptr;
  19.133 -    flags = 0;
  19.134 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.135 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.136 -  
  19.137 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.138 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.139 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.140 -
  19.141 -    assert(strcmp("Now signed!", final_ptr->shortmsg) == 0);
  19.142 -
  19.143 -    cout << "Test 2a: Subject replaced as expected." << endl << endl;
  19.144 -
  19.145 -    if (final_ptr == dest_msg)
  19.146 -        free_message(dest_msg);
  19.147 -    free_message(msg_ptr);
  19.148 -    free_stringlist(keylist);
  19.149 -
  19.150 -    cout << "-------------------------------------------------------------------------------------------------" << endl;
  19.151 -    cout << "Test 2b: Normal encrypted/signed mail, p≡p as substitute subject, regular subject in crypto text." << endl;
  19.152 -    cout << "-------------------------------------------------------------------------------------------------" << endl;
  19.153 -
  19.154 -    msg_ptr = nullptr;
  19.155 -    dest_msg = nullptr;
  19.156 -    final_ptr = nullptr;
  19.157 -    keylist = nullptr;
  19.158 -    rating = PEP_rating_unreliable;
  19.159 -    
  19.160 -    mailtext = slurp("test_mails/p3p_subject_normal_signed_2b.eml");
  19.161 -    
  19.162 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  19.163 -    assert(status == PEP_STATUS_OK);
  19.164 -    assert(msg_ptr);
  19.165 -    final_ptr = msg_ptr;
  19.166 -    flags = 0;
  19.167 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.168 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.169 -  
  19.170 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.171 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.172 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.173 -
  19.174 -    assert(strcmp("Now signed!", final_ptr->shortmsg) == 0);
  19.175 -
  19.176 -    cout << "Test 2b: Subject replaced as expected." << endl << endl;
  19.177 -
  19.178 -    if (final_ptr == dest_msg)
  19.179 -        free_message(dest_msg);
  19.180 -    free_message(msg_ptr);
  19.181 -    free_stringlist(keylist);
  19.182 -
  19.183 -    
  19.184 -    cout << "---------------------------------------------------------------------------" << endl;
  19.185 -    cout << "Test 3a: Encrypted mail, pEp as displayed subject, no subject in body text." << endl;
  19.186 -    cout << "---------------------------------------------------------------------------" << endl;
  19.187 -
  19.188 -    msg_ptr = nullptr;
  19.189 -    dest_msg = nullptr;
  19.190 -    final_ptr = nullptr;
  19.191 -    keylist = nullptr;
  19.192 -    rating = PEP_rating_unreliable;
  19.193 -    
  19.194 -    mailtext = slurp("test_mails/pEp_encrypted_subject_IS_pEp_3a.eml");
  19.195 -    
  19.196 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  19.197 -    assert(status == PEP_STATUS_OK);
  19.198 -    assert(msg_ptr);
  19.199 -    final_ptr = msg_ptr;
  19.200 -    flags = 0;
  19.201 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.202 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.203 -  
  19.204 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.205 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.206 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.207 -
  19.208 -    assert(strcmp("pEp", final_ptr->shortmsg) == 0);
  19.209 -
  19.210 -    cout << "Test 3a: Subject remains intact as desired." << endl << endl;
  19.211 -
  19.212 -    if (final_ptr == dest_msg)
  19.213 -        free_message(dest_msg);
  19.214 -    free_message(msg_ptr);
  19.215 -    free_stringlist(keylist);
  19.216 -
  19.217 -    cout << "---------------------------------------------------------------------------" << endl;
  19.218 -    cout << "Test 3b: Encrypted mail, p≡p as displayed subject, no subject in body text." << endl;
  19.219 -    cout << "---------------------------------------------------------------------------" << endl;
  19.220 -
  19.221 -    msg_ptr = nullptr;
  19.222 -    dest_msg = nullptr;
  19.223 -    final_ptr = nullptr;
  19.224 -    keylist = nullptr;
  19.225 -    rating = PEP_rating_unreliable;
  19.226 -    
  19.227 -    mailtext = slurp("test_mails/p3p_encrypted_subject_IS_pEp_3b.eml");
  19.228 -    
  19.229 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  19.230 -    assert(status == PEP_STATUS_OK);
  19.231 -    assert(msg_ptr);
  19.232 -    final_ptr = msg_ptr;
  19.233 -    flags = 0;
  19.234 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.235 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.236 -  
  19.237 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.238 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.239 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.240 -
  19.241 -    assert(strcmp("p≡p", final_ptr->shortmsg) == 0);
  19.242 -
  19.243 -    cout << "Test 3: Subject remains intact as desired." << endl << endl;
  19.244 -
  19.245 -    if (final_ptr == dest_msg)
  19.246 -        free_message(dest_msg);
  19.247 -    free_message(msg_ptr);
  19.248 -    free_stringlist(keylist);
  19.249 -
  19.250 -
  19.251 -    cout << "----------------------------------------------------------------------------" << endl;
  19.252 -    cout << "Test 4a: Encrypted mail, pEp as displayed subject, pEp subject in body text." << endl;
  19.253 -    cout << "----------------------------------------------------------------------------" << endl;
  19.254 -
  19.255 -    msg_ptr = nullptr;
  19.256 -    dest_msg = nullptr;
  19.257 -    final_ptr = nullptr;
  19.258 -    keylist = nullptr;
  19.259 -    rating = PEP_rating_unreliable;
  19.260 -    
  19.261 -    mailtext = slurp("test_mails/pEp_subject_pEp_replaced_w_pEp_4a.eml");
  19.262 -    
  19.263 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  19.264 -    assert(status == PEP_STATUS_OK);
  19.265 -    assert(msg_ptr);
  19.266 -    final_ptr = msg_ptr;
  19.267 -    flags = 0;
  19.268 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.269 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.270 -  
  19.271 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.272 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.273 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.274 -
  19.275 -    assert(strcmp("pEp", final_ptr->shortmsg) == 0);
  19.276 -
  19.277 -    cout << "Test 4a: Subject correct." << endl << endl;
  19.278 -
  19.279 -    if (final_ptr == dest_msg)
  19.280 -        free_message(dest_msg);
  19.281 -    free_message(msg_ptr);
  19.282 -    free_stringlist(keylist);
  19.283 -
  19.284 -    cout << "----------------------------------------------------------------------------" << endl;
  19.285 -    cout << "Test 4b: Encrypted mail, p≡p as displayed subject, pEp subject in body text." << endl;
  19.286 -    cout << "----------------------------------------------------------------------------" << endl;
  19.287 -
  19.288 -    msg_ptr = nullptr;
  19.289 -    dest_msg = nullptr;
  19.290 -    final_ptr = nullptr;
  19.291 -    keylist = nullptr;
  19.292 -    rating = PEP_rating_unreliable;
  19.293 -    
  19.294 -    mailtext = slurp("test_mails/pEp_subject_pEp_replaced_w_p3p_4b.eml");
  19.295 -    
  19.296 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  19.297 -    assert(status == PEP_STATUS_OK);
  19.298 -    assert(msg_ptr);
  19.299 -    final_ptr = msg_ptr;
  19.300 -    flags = 0;
  19.301 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.302 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.303 -  
  19.304 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.305 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.306 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.307 -
  19.308 -    assert(strcmp("pEp", final_ptr->shortmsg) == 0);
  19.309 -
  19.310 -    cout << "Test 4b: Subject correct." << endl << endl;
  19.311 -
  19.312 -    if (final_ptr == dest_msg)
  19.313 -        free_message(dest_msg);
  19.314 -    free_message(msg_ptr);
  19.315 -    free_stringlist(keylist);
  19.316 -
  19.317 -    cout << "----------------------------------------------------------------------------" << endl;
  19.318 -    cout << "Test 4c: Encrypted mail, pEp as displayed subject, p≡p subject in body text." << endl;
  19.319 -    cout << "----------------------------------------------------------------------------" << endl;
  19.320 -
  19.321 -    msg_ptr = nullptr;
  19.322 -    dest_msg = nullptr;
  19.323 -    final_ptr = nullptr;
  19.324 -    keylist = nullptr;
  19.325 -    rating = PEP_rating_unreliable;
  19.326 -    
  19.327 -    mailtext = slurp("test_mails/pEp_subject_p3p_replaced_w_pEp_4c.eml");
  19.328 -    
  19.329 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  19.330 -    assert(status == PEP_STATUS_OK);
  19.331 -    assert(msg_ptr);
  19.332 -    final_ptr = msg_ptr;
  19.333 -    flags = 0;
  19.334 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.335 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.336 -  
  19.337 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.338 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.339 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.340 -
  19.341 -    assert(strcmp("p≡p", final_ptr->shortmsg) == 0);
  19.342 -
  19.343 -    cout << "Test 4c: Subject correct." << endl << endl;
  19.344 -
  19.345 -    if (final_ptr == dest_msg)
  19.346 -        free_message(dest_msg);
  19.347 -    free_message(msg_ptr);
  19.348 -    free_stringlist(keylist);
  19.349 -
  19.350 -    cout << "----------------------------------------------------------------------------" << endl;
  19.351 -    cout << "Test 4d: Encrypted mail, p≡p as displayed subject, p≡p subject in body text." << endl;
  19.352 -    cout << "----------------------------------------------------------------------------" << endl;
  19.353 -
  19.354 -    msg_ptr = nullptr;
  19.355 -    dest_msg = nullptr;
  19.356 -    final_ptr = nullptr;
  19.357 -    keylist = nullptr;
  19.358 -    rating = PEP_rating_unreliable;
  19.359 -    
  19.360 -    mailtext = slurp("test_mails/pEp_subject_p3p_replaced_w_p3p_4d.eml");
  19.361 -    
  19.362 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  19.363 -    assert(status == PEP_STATUS_OK);
  19.364 -    assert(msg_ptr);
  19.365 -    final_ptr = msg_ptr;
  19.366 -    flags = 0;
  19.367 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.368 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.369 -  
  19.370 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.371 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.372 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.373 -
  19.374 -    assert(strcmp("p≡p", final_ptr->shortmsg) == 0);
  19.375 -
  19.376 -    cout << "Test 4d: Subject correct, in any event." << endl << endl;
  19.377 -
  19.378 -    if (final_ptr == dest_msg)
  19.379 -        free_message(dest_msg);
  19.380 -    free_message(msg_ptr);
  19.381 -    free_stringlist(keylist);
  19.382 -
  19.383 -
  19.384 -    cout << "-------------------------------------------------------------------------" << endl;
  19.385 -    cout << "Test 5a: Unencrypted variant where pEp in the subject line is the subject." << endl;
  19.386 -    cout << "-------------------------------------------------------------------------" << endl;
  19.387 -
  19.388 -    msg_ptr = nullptr;
  19.389 -    dest_msg = nullptr;
  19.390 -    final_ptr = nullptr;
  19.391 -    keylist = nullptr;
  19.392 -    rating = PEP_rating_unreliable;
  19.393 -    
  19.394 -    mailtext = slurp("test_mails/pEp_unencrypted_pEp_subject_5a.eml");
  19.395 -    
  19.396 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  19.397 -    assert(status == PEP_STATUS_OK);
  19.398 -    assert(msg_ptr);
  19.399 -    final_ptr = msg_ptr;
  19.400 -    flags = 0;
  19.401 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.402 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.403 -  
  19.404 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.405 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.406 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.407 -
  19.408 -    assert(strcmp("pEp", final_ptr->shortmsg) == 0);
  19.409 -
  19.410 -    cout << "Test 5a: Subject remains intact." << endl << endl;
  19.411 -
  19.412 -    if (final_ptr == dest_msg)
  19.413 -        free_message(dest_msg);
  19.414 -    free_message(msg_ptr);
  19.415 -    free_stringlist(keylist);
  19.416 -
  19.417 -
  19.418 -    cout << "--------------------------------------------------------------------------" << endl;
  19.419 -    cout << "Test 5b: Unencrypted variant where p≡p in the subject line is the subject." << endl;
  19.420 -    cout << "--------------------------------------------------------------------------" << endl;
  19.421 -
  19.422 -    msg_ptr = nullptr;
  19.423 -    dest_msg = nullptr;
  19.424 -    final_ptr = nullptr;
  19.425 -    keylist = nullptr;
  19.426 -    rating = PEP_rating_unreliable;
  19.427 -    
  19.428 -    mailtext = slurp("test_mails/pEp_unencrypted_p3p_subject_5b.eml");
  19.429 -    
  19.430 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  19.431 -    assert(status == PEP_STATUS_OK);
  19.432 -    assert(msg_ptr);
  19.433 -    final_ptr = msg_ptr;
  19.434 -    flags = 0;
  19.435 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.436 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.437 -  
  19.438 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.439 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.440 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.441 -
  19.442 -    assert(strcmp("p≡p", final_ptr->shortmsg) == 0);
  19.443 -
  19.444 -    cout << "Test 5b: Subject remains intact." << endl << endl;
  19.445 -
  19.446 -    if (final_ptr == dest_msg)
  19.447 -        free_message(dest_msg);
  19.448 -    free_message(msg_ptr);
  19.449 -    free_stringlist(keylist);
  19.450 -
  19.451 -    cout << "----------------------------------------------------------------------------------------------------------------------" << endl;
  19.452 -    cout << "Test 6: Normal unencrypted email where a subject line exists in the text but the subject is not a replacement subject." << endl;
  19.453 -    cout << "----------------------------------------------------------------------------------------------------------------------" << endl;
  19.454 -
  19.455 -    msg_ptr = nullptr;
  19.456 -    dest_msg = nullptr;
  19.457 -    final_ptr = nullptr;
  19.458 -    keylist = nullptr;
  19.459 -    rating = PEP_rating_unreliable;
  19.460 -    
  19.461 -    mailtext = slurp("test_mails/pEp_subject_normal_unencrypted_6.eml");
  19.462 -    
  19.463 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  19.464 -    assert(status == PEP_STATUS_OK);
  19.465 -    assert(msg_ptr);
  19.466 -    final_ptr = msg_ptr;
  19.467 -    flags = 0;
  19.468 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  19.469 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
  19.470 -  
  19.471 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  19.472 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  19.473 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  19.474 -
  19.475 -    assert(strcmp("This is just a normal subject, really", final_ptr->shortmsg) == 0);
  19.476 -
  19.477 -    cout << "Test 6: Subject remains intact." << endl << endl;
  19.478 -
  19.479 -    if (final_ptr == dest_msg)
  19.480 -        free_message(dest_msg);
  19.481 -    free_message(msg_ptr);
  19.482 -    free_stringlist(keylist);
  19.483 -        
  19.484 -    cout << "calling release()\n";
  19.485 -    release(session);
  19.486 -    return 0;
  19.487 -}
    20.1 --- a/test/pgp_binary_test.cc	Tue May 08 11:09:11 2018 +0200
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,39 +0,0 @@
    20.4 -// This file is under GNU General Public License 3.0
    20.5 -// see LICENSE.txt
    20.6 -
    20.7 -#include <iostream>
    20.8 -#include <string>
    20.9 -#include <assert.h>
   20.10 -#include "message_api.h"
   20.11 -
   20.12 -using namespace std;
   20.13 -
   20.14 -int main() {
   20.15 -    cout << "\n*** pgp_binary_test ***\n\n";
   20.16 -
   20.17 -    PEP_SESSION session;
   20.18 -    
   20.19 -    cout << "calling init()\n";
   20.20 -    PEP_STATUS status1 = init(&session);   
   20.21 -    assert(status1 == PEP_STATUS_OK);
   20.22 -    assert(session);
   20.23 -    cout << "init() completed.\n";
   20.24 -
   20.25 -    // pgp_binary test code
   20.26 -
   20.27 -    const char *path;
   20.28 -    PEP_STATUS status2 = get_binary_path(PEP_crypt_OpenPGP, &path);
   20.29 -    assert(status2 == PEP_STATUS_OK);
   20.30 -#ifdef USE_GPG
   20.31 -    assert(path);
   20.32 -#endif
   20.33 -    if (path)
   20.34 -        cout << "PGP binary at " << path << "\n";
   20.35 -    else
   20.36 -        cout << "no PGP binary path available\n";
   20.37 -
   20.38 -    cout << "calling release()\n";
   20.39 -    release(session);
   20.40 -    return 0;
   20.41 -}
   20.42 -
    21.1 --- a/test/pgp_list_keys_test.cc	Tue May 08 11:09:11 2018 +0200
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,74 +0,0 @@
    21.4 -// This file is under GNU General Public License 3.0
    21.5 -// see LICENSE.txt
    21.6 -
    21.7 -#include <iostream>
    21.8 -#include <string>
    21.9 -#include <assert.h>
   21.10 -#include "pEpEngine.h"
   21.11 -#include "stringpair.h"
   21.12 -#include "openpgp_compat.h"
   21.13 -
   21.14 -using namespace std;
   21.15 -
   21.16 -void print_stringpair_list(stringpair_list_t* spl) {
   21.17 -    for ( ; spl != NULL; spl = spl->next) {
   21.18 -        if (spl->value) {
   21.19 -            cout << "Key:" << endl;
   21.20 -            if (spl->value->key)
   21.21 -                cout << "\tFPR: " << spl->value->key << endl;
   21.22 -            if (spl->value->value)
   21.23 -                cout << "\tUID: " << spl->value->value << endl;
   21.24 -        }
   21.25 -    }
   21.26 -}
   21.27 -
   21.28 -int main() {
   21.29 -    cout << "\n*** openpgp_compat test ***\n\n";
   21.30 -
   21.31 -    PEP_SESSION session;
   21.32 -    
   21.33 -    cout << "calling init()\n";
   21.34 -    PEP_STATUS status1 = init(&session);   
   21.35 -    assert(status1 == PEP_STATUS_OK);
   21.36 -    assert(session);
   21.37 -    cout << "init() completed.\n";
   21.38 -
   21.39 -    cout << "Listing all the keys:" << endl;
   21.40 -    stringpair_list_t* all_the_ids = NULL;
   21.41 -    OpenPGP_list_keyinfo(session, "", &all_the_ids);
   21.42 -    print_stringpair_list(all_the_ids);
   21.43 -    free_stringpair_list(all_the_ids);
   21.44 -    
   21.45 -    cout << "**********************" << endl << endl << "Checking on Alice, Bob and John" << endl;
   21.46 -    all_the_ids = NULL;
   21.47 -    OpenPGP_list_keyinfo(session, "pEp Test", &all_the_ids);
   21.48 -    print_stringpair_list(all_the_ids);
   21.49 -    free_stringpair_list(all_the_ids);
   21.50 -
   21.51 -    cout << "**********************" << endl << endl << "Compare to find_keys for Alice, Bob and John" << endl;
   21.52 -    stringlist_t* all_the_keys;
   21.53 -    find_keys(session, "pEp Test", &all_the_keys);
   21.54 -    stringlist_t* i;
   21.55 -    for (i = all_the_keys; i; i = i->next) {
   21.56 -        cout << i->value << endl;
   21.57 -    }
   21.58 -    free_stringlist(all_the_keys);
   21.59 -
   21.60 -    
   21.61 -    cout << "**********************" << endl << endl << "Checking FPR" << endl;
   21.62 -    all_the_ids = NULL;
   21.63 -    OpenPGP_list_keyinfo(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &all_the_ids);
   21.64 -    print_stringpair_list(all_the_ids);
   21.65 -    free_stringpair_list(all_the_ids);
   21.66 -
   21.67 -    cout << "**********************" << endl << endl << "Checking on nothing" << endl;
   21.68 -    all_the_ids = NULL;
   21.69 -    OpenPGP_list_keyinfo(session, "ekhwr89234uh4rknfjsklejfnlskjflselkflkserjs", &all_the_ids);
   21.70 -    print_stringpair_list(all_the_ids);
   21.71 -    free_stringpair_list(all_the_ids);
   21.72 -
   21.73 -    cout << "calling release()\n";
   21.74 -    release(session);
   21.75 -    return 0;
   21.76 -}
   21.77 -
    22.1 --- a/test/reencrypt_plus_extra_keys_test.cc	Tue May 08 11:09:11 2018 +0200
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,534 +0,0 @@
    22.4 -// This file is under GNU General Public License 3.0
    22.5 -// see LICENSE.txt
    22.6 -
    22.7 -#include <stdlib.h>
    22.8 -#include <string.h>
    22.9 -#include "platform.h"
   22.10 -#include <iostream>
   22.11 -#include <fstream>
   22.12 -#include <assert.h>
   22.13 -#include "mime.h"
   22.14 -#include "message_api.h"
   22.15 -#include "keymanagement.h"
   22.16 -#include "test_util.h"
   22.17 -
   22.18 -using namespace std;
   22.19 -
   22.20 -int main() {
   22.21 -    cout << "\n*** reencrypt_plus_extra_keys_test ***\n\n";
   22.22 -
   22.23 -    PEP_SESSION session;
   22.24 -    
   22.25 -    cout << "calling init()\n";
   22.26 -    PEP_STATUS status = init(&session);
   22.27 -    assert(status == PEP_STATUS_OK);
   22.28 -    assert(session);
   22.29 -    cout << "init() completed.\n";
   22.30 -
   22.31 -    /* import all the keys */
   22.32 -    const char* fpr_own_recip_key = "85D022E0CC9BA9F6B922CA7B638E5211B1A2BE89";
   22.33 -    const char* fpr_own_recip_2_key = "7A2EEB933E6FD99207B83E397B6D3751D6E75FFF";
   22.34 -    
   22.35 -    const char* fpr_sender_pub_key = "95FE24B262A34FA5C6A8D0AAF90144FC3B508C8E";
   22.36 -    const char* fpr_recip_2_pub_key = "60701073D138EF622C8F9221B6FC86831EDBE691";
   22.37 -    const char* fpr_recip_0_pub_key = "CDF787C7C9664E02825DD416C6FBCF8D1F4A5986";
   22.38 -    // we're leaving recip_1 out for the Hell of it - D3886D0DF75113BE2799C9374D6B99FE0F8273D8
   22.39 -    const char* fpr_pub_extra_key_0 = "33BB6C92EBFB6F29641C75B5B79D916C828AA789";
   22.40 -
   22.41 -    const char* fpr_pub_extra_key_1 = "3DB93A746785FDD6110798AB3B193A9E8B026AEC";
   22.42 -    const string own_recip_pub_key = slurp("test_keys/pub/reencrypt_recip_0-0xB1A2BE89_pub.asc");
   22.43 -    const string own_recip_priv_key = slurp("test_keys/priv/reencrypt_recip_0-0xB1A2BE89_priv.asc");
   22.44 -    const string own_recip_2_pub_key = slurp("test_keys/pub/reencrypt_recip_numero_deux_test_0-0xD6E75FFF_pub.asc");
   22.45 -    const string own_recip_2_priv_key = slurp("test_keys/priv/reencrypt_recip_numero_deux_test_0-0xD6E75FFF_priv.asc");
   22.46 -    
   22.47 -    const string sender_pub_key = slurp("test_keys/pub/reencrypt_sender_0-0x3B508C8E_pub.asc");
   22.48 -    const string recip_2_pub_key = slurp("test_keys/pub/reencrypt_other_recip_2-0x1EDBE691_pub.asc");
   22.49 -    const string recip_0_pub_key = slurp("test_keys/pub/reencrypt_other_recip_0-0x1F4A5986_pub.asc");
   22.50 -    // we're leaving recip_1 out for the Hell of it
   22.51 -    const string pub_extra_key_0 = slurp("test_keys/pub/reencrypt_extra_keys_0-0x828AA789_pub.asc");
   22.52 -    const string pub_extra_key_1 = slurp("test_keys/pub/reencrypt_extra_keys_1-0x8B026AEC_pub.asc");
   22.53 -
   22.54 -    status = import_key(session, own_recip_pub_key.c_str(), own_recip_pub_key.length(), NULL);
   22.55 -    assert (status == PEP_STATUS_OK);
   22.56 -    status = import_key(session, own_recip_priv_key.c_str(), own_recip_priv_key.length(), NULL);
   22.57 -    assert (status == PEP_STATUS_OK);    
   22.58 -    status = import_key(session, own_recip_2_pub_key.c_str(), own_recip_2_pub_key.length(), NULL);
   22.59 -    assert (status == PEP_STATUS_OK);
   22.60 -    status = import_key(session, own_recip_2_priv_key.c_str(), own_recip_2_priv_key.length(), NULL);
   22.61 -    assert (status == PEP_STATUS_OK);
   22.62 -    
   22.63 -    status = import_key(session, sender_pub_key.c_str(), sender_pub_key.length(), NULL);
   22.64 -    assert (status == PEP_STATUS_OK);
   22.65 -    status = import_key(session, recip_2_pub_key.c_str(), recip_2_pub_key.length(), NULL);
   22.66 -    assert (status == PEP_STATUS_OK);
   22.67 -    status = import_key(session, recip_0_pub_key.c_str(), recip_0_pub_key.length(), NULL);
   22.68 -    assert (status == PEP_STATUS_OK);
   22.69 -    status = import_key(session, pub_extra_key_0.c_str(), pub_extra_key_0.length(), NULL);
   22.70 -    assert (status == PEP_STATUS_OK);
   22.71 -    status = import_key(session, pub_extra_key_1.c_str(), pub_extra_key_1.length(), NULL);
   22.72 -    assert (status == PEP_STATUS_OK);
   22.73 -
   22.74 -    cout << "Keys imported." << endl;
   22.75 -
   22.76 -    pEp_identity* me_recip_1 = new_identity("reencrypt_recip@darthmama.cool", fpr_own_recip_key, PEP_OWN_USERID, "Me Recipient");
   22.77 -    pEp_identity* me_recip_2 = new_identity("reencrypt_recip_numero_deux_test@darthmama.org", fpr_own_recip_2_key, PEP_OWN_USERID, "Me Recipient");
   22.78 -    
   22.79 -    cout << "Inserting own identities and keys into database." << endl;
   22.80 -    status = set_own_key(session, me_recip_2, fpr_own_recip_2_key);
   22.81 -    assert(status == PEP_STATUS_OK);
   22.82 -    cout << "Done: inserting own identities and keys into database." << endl;
   22.83 -
   22.84 -    const string to_reencrypt_from_enigmail = slurp("test_mails/reencrypt_sent_by_enigmail.eml");
   22.85 -    const string to_reencrypt_from_enigmail_BCC = slurp("test_mails/reencrypt_BCC_sent_by_enigmail.eml");
   22.86 -    const string to_reencrypt_from_pEp = slurp("test_mails/reencrypt_encrypted_through_pEp.eml");
   22.87 -
   22.88 -    cout << endl << "Case 1a: Calling MIME_decrypt_message with reencrypt flag set on message sent from enigmail for recip 2 with no extra keys." << endl;
   22.89 -    
   22.90 -    char* decrypted_text = nullptr;
   22.91 -    
   22.92 -    // In: extra keys; Out: keys that were used to encrypt this.
   22.93 -    stringlist_t* keys = NULL;
   22.94 -    PEP_decrypt_flags_t flags;
   22.95 -    PEP_rating rating;
   22.96 -
   22.97 -    flags = PEP_decrypt_flag_untrusted_server;
   22.98 -    char* modified_src = NULL;
   22.99 -    
  22.100 -    status = MIME_decrypt_message(session,
  22.101 -                                  to_reencrypt_from_enigmail.c_str(),
  22.102 -                                  to_reencrypt_from_enigmail.size(),
  22.103 -                                  &decrypted_text,
  22.104 -                                  &keys,
  22.105 -                                  &rating,
  22.106 -                                  &flags, 
  22.107 -                                  &modified_src);
  22.108 -
  22.109 -    cout << decrypted_text << endl;
  22.110 -
  22.111 -    cout << "Status is " << tl_status_string(status) << endl;
  22.112 -    assert(decrypted_text);
  22.113 -    assert(rating);
  22.114 -    assert(!(flags & PEP_decrypt_flag_src_modified));
  22.115 -    
  22.116 -    assert(!modified_src);
  22.117 -    //cout << modified_src << endl;
  22.118 -    
  22.119 -    free(decrypted_text);
  22.120 -    decrypted_text = nullptr;
  22.121 -
  22.122 -    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  22.123 -
  22.124 -    free(decrypted_text);
  22.125 -    decrypted_text = nullptr;
  22.126 -    flags = 0;
  22.127 -    char* throwaway = NULL;
  22.128 -
  22.129 -    status = MIME_decrypt_message(session,
  22.130 -                                  modified_src,
  22.131 -                                  strlen(modified_src),
  22.132 -                                  &decrypted_text,
  22.133 -                                  &keys,
  22.134 -                                  &rating,
  22.135 -                                  &flags,
  22.136 -                                  &throwaway);
  22.137 -
  22.138 -    
  22.139 -    cout << "keys used:\n";
  22.140 -    
  22.141 -    int i = 0;
  22.142 -    
  22.143 -    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  22.144 -    {
  22.145 -        if (i == 0) {
  22.146 -              cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  22.147 -              assert(strcasecmp(fpr_own_recip_2_key,kl->value) == 0);
  22.148 -        }
  22.149 -        else {
  22.150 -            cout << "\t " << kl->value << endl;
  22.151 -            assert(strcasecmp(fpr_own_recip_2_key, kl->value) == 0);
  22.152 -            cout << "Encrypted only for own identity! Yay! It worked!" << endl;
  22.153 -        }
  22.154 -        assert(i < 2);
  22.155 -    }
  22.156 -    cout << "Case 1a: PASS" << endl << endl;
  22.157 -
  22.158 -    cout << "Case 1b: Calling MIME_decrypt_message with reencrypt flag set on message sent from enigmail for recip 2 extra keys." << endl;
  22.159 -        
  22.160 -    // In: extra keys; Out: keys that were used to encrypt this.
  22.161 -    free_stringlist(keys);
  22.162 -    keys = new_stringlist(fpr_pub_extra_key_0);
  22.163 -    stringlist_add(keys, fpr_pub_extra_key_1);    
  22.164 -
  22.165 -    flags = PEP_decrypt_flag_untrusted_server;
  22.166 -    
  22.167 -    status = MIME_decrypt_message(session,
  22.168 -                                  to_reencrypt_from_enigmail.c_str(),
  22.169 -                                  to_reencrypt_from_enigmail.size(),
  22.170 -                                  &decrypted_text,
  22.171 -                                  &keys,
  22.172 -                                  &rating,
  22.173 -                                  &flags,
  22.174 -                                  &modified_src);
  22.175 -
  22.176 -    cout << decrypted_text << endl;
  22.177 -    cout << "Status is " << tl_status_string(status) << endl;
  22.178 -
  22.179 -
  22.180 -    assert(decrypted_text);
  22.181 -    assert(rating);
  22.182 -
  22.183 -    free(decrypted_text);
  22.184 -    decrypted_text = nullptr;
  22.185 -
  22.186 -    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  22.187 -
  22.188 -    free(decrypted_text);
  22.189 -    decrypted_text = nullptr;
  22.190 -    flags = 0;
  22.191 -    throwaway = NULL;
  22.192 -
  22.193 -    status = MIME_decrypt_message(session,
  22.194 -                                  modified_src,
  22.195 -                                  strlen(modified_src),
  22.196 -                                  &decrypted_text,
  22.197 -                                  &keys,
  22.198 -                                  &rating,
  22.199 -                                  &flags,
  22.200 -                                  &throwaway);
  22.201 -    
  22.202 -    cout << "keys used:\n";
  22.203 -    
  22.204 -    bool own_key_found = false;
  22.205 -    bool extra_key_0_found = false;
  22.206 -    bool extra_key_1_found = false;
  22.207 -    
  22.208 -    i = 0;
  22.209 -    
  22.210 -    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  22.211 -    {
  22.212 -        if (i == 0) {
  22.213 -              cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  22.214 -              assert(strcasecmp(fpr_own_recip_2_key,kl->value) == 0);
  22.215 -        }
  22.216 -        else {
  22.217 -            if (strcasecmp(fpr_own_recip_2_key, kl->value) == 0) {
  22.218 -                cout << "Encrypted for us." << endl;
  22.219 -                own_key_found = true;
  22.220 -            }
  22.221 -            else if (strcasecmp(fpr_pub_extra_key_0, kl->value) == 0) {
  22.222 -                cout << "Encrypted for extra key 0." << endl;
  22.223 -                extra_key_0_found = true;
  22.224 -            }
  22.225 -            else if (strcasecmp(fpr_pub_extra_key_1, kl->value) == 0) {
  22.226 -                cout << "Encrypted for extra key 1." << endl;
  22.227 -                extra_key_1_found = true;
  22.228 -            }
  22.229 -            else {
  22.230 -                cout << "FAIL: Encrypted for " << kl->value << ", which it should not be." << endl;
  22.231 -                assert(false);
  22.232 -            }
  22.233 -            cout << "\t " << kl->value << endl;
  22.234 -        }
  22.235 -        assert(i < 4);
  22.236 -    }
  22.237 -    assert (own_key_found && extra_key_0_found && extra_key_1_found);
  22.238 -    cout << "Message was encrypted for all the keys it should be, and none it should not!" << endl;
  22.239 -
  22.240 -    cout << "Case 1b: PASS" << endl << endl;
  22.241 -
  22.242 -    cout << "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;
  22.243 -
  22.244 -    free_stringlist(keys);
  22.245 -    keys = NULL;
  22.246 -
  22.247 -    flags = PEP_decrypt_flag_untrusted_server;
  22.248 -    
  22.249 -    status = MIME_decrypt_message(session,
  22.250 -                                  to_reencrypt_from_enigmail_BCC.c_str(),
  22.251 -                                  to_reencrypt_from_enigmail_BCC.size(),
  22.252 -                                  &decrypted_text,
  22.253 -                                  &keys,
  22.254 -                                  &rating,
  22.255 -                                  &flags,
  22.256 -                                  &modified_src);
  22.257 -
  22.258 -    cout << decrypted_text << endl;
  22.259 -    cout << "Status is " << tl_status_string(status) << endl;
  22.260 -
  22.261 -
  22.262 -    assert(decrypted_text);
  22.263 -    assert(rating);
  22.264 -
  22.265 -    free(decrypted_text);
  22.266 -    decrypted_text = nullptr;
  22.267 -
  22.268 -    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  22.269 -
  22.270 -    free(decrypted_text);
  22.271 -    decrypted_text = nullptr;
  22.272 -    flags = 0;
  22.273 -    throwaway = NULL;
  22.274 -
  22.275 -    status = MIME_decrypt_message(session,
  22.276 -                                  modified_src,
  22.277 -                                  strlen(modified_src),
  22.278 -                                  &decrypted_text,
  22.279 -                                  &keys,
  22.280 -                                  &rating,
  22.281 -                                  &flags,
  22.282 -                                  &throwaway);
  22.283 -    
  22.284 -    cout << "keys used:\n";
  22.285 -        
  22.286 -    i = 0;
  22.287 -    
  22.288 -    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  22.289 -    {
  22.290 -        if (i == 0) {
  22.291 -              cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  22.292 -//              assert(strcasecmp(fpr_own_recip_2_key,kl->value) == 0);
  22.293 -        }
  22.294 -        else {
  22.295 -            cout << "\t " << kl->value << endl;
  22.296 -//            assert(strcasecmp(fpr_own_recip_2_key, kl->value) == 0);
  22.297 -            cout << "Encrypted only for own identity! Yay! It worked!" << endl;
  22.298 -        }
  22.299 -        assert(i < 2);
  22.300 -    }
  22.301 -
  22.302 -    cout << "Case 2a: PASS" << endl << endl;
  22.303 -
  22.304 -    cout << "Case 2b: Calling MIME_decrypt_message with reencrypt flag set on message sent with recip 2 in BCC from enigmail with extra keys." << endl;
  22.305 -
  22.306 -    free_stringlist(keys);
  22.307 -    keys = new_stringlist(fpr_pub_extra_key_0);
  22.308 -    stringlist_add(keys, fpr_pub_extra_key_1);    
  22.309 -
  22.310 -    flags = PEP_decrypt_flag_untrusted_server;
  22.311 -    
  22.312 -    status = MIME_decrypt_message(session,
  22.313 -                                  to_reencrypt_from_enigmail_BCC.c_str(),
  22.314 -                                  to_reencrypt_from_enigmail_BCC.size(),
  22.315 -                                  &decrypted_text,
  22.316 -                                  &keys,
  22.317 -                                  &rating,
  22.318 -                                  &flags,
  22.319 -                                  &modified_src);
  22.320 -
  22.321 -    cout << decrypted_text << endl;
  22.322 -    cout << "Status is " << tl_status_string(status) << endl;
  22.323 -
  22.324 -
  22.325 -    assert(decrypted_text);
  22.326 -    assert(rating);
  22.327 -
  22.328 -    free(decrypted_text);
  22.329 -    decrypted_text = nullptr;
  22.330 -
  22.331 -    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  22.332 -
  22.333 -    free(decrypted_text);
  22.334 -    decrypted_text = nullptr;
  22.335 -    flags = 0;
  22.336 -    throwaway = NULL;
  22.337 -
  22.338 -    status = MIME_decrypt_message(session,
  22.339 -                                  modified_src,
  22.340 -                                  strlen(modified_src),
  22.341 -                                  &decrypted_text,
  22.342 -                                  &keys,
  22.343 -                                  &rating,
  22.344 -                                  &flags,
  22.345 -                                  &throwaway);
  22.346 -    
  22.347 -    cout << "keys used:\n";
  22.348 -    
  22.349 -    own_key_found = false;
  22.350 -    extra_key_0_found = false;
  22.351 -    extra_key_1_found = false;
  22.352 -    
  22.353 -    i = 0;
  22.354 -    
  22.355 -    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  22.356 -    {
  22.357 -        if (i == 0) {
  22.358 -              cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  22.359 -//              assert(strcasecmp(fpr_own_recip_2_key,kl->value) == 0);
  22.360 -        }
  22.361 -        else {
  22.362 -            if (strcasecmp(fpr_own_recip_2_key, kl->value) == 0) {
  22.363 -                cout << "Encrypted for us." << endl;
  22.364 -                own_key_found = true;
  22.365 -            }
  22.366 -            else if (strcasecmp(fpr_pub_extra_key_0, kl->value) == 0) {
  22.367 -                cout << "Encrypted for extra key 0." << endl;
  22.368 -                extra_key_0_found = true;
  22.369 -            }
  22.370 -            else if (strcasecmp(fpr_pub_extra_key_1, kl->value) == 0) {
  22.371 -                cout << "Encrypted for extra key 1." << endl;
  22.372 -                extra_key_1_found = true;
  22.373 -            }
  22.374 -            else {
  22.375 -                cout << "FAIL: Encrypted for " << kl->value << ", which it should not be." << endl;
  22.376 -//                assert(false);
  22.377 -            }
  22.378 -            cout << "\t " << kl->value << endl;
  22.379 -        }
  22.380 -        assert(i < 4);
  22.381 -    }
  22.382 -//    assert (own_key_found && extra_key_0_found && extra_key_1_found);
  22.383 -    cout << "Message was encrypted for all the keys it should be, and none it should not!" << endl;
  22.384 -
  22.385 -    cout << "Case 2b: PASS" << endl << endl;
  22.386 -
  22.387 -    cout << "Case 3a: Calling MIME_decrypt_message with reencrypt flag set on message generated by pEp (message 2.0) with no extra keys." << endl;
  22.388 -    free_stringlist(keys);
  22.389 -    keys = NULL;
  22.390 -
  22.391 -    status = set_own_key(session, me_recip_1, fpr_own_recip_key);
  22.392 -    assert(status == PEP_STATUS_OK);
  22.393 -
  22.394 -    flags = PEP_decrypt_flag_untrusted_server;
  22.395 -    
  22.396 -    status = MIME_decrypt_message(session,
  22.397 -                                  to_reencrypt_from_pEp.c_str(),
  22.398 -                                  to_reencrypt_from_pEp.size(),
  22.399 -                                  &decrypted_text,
  22.400 -                                  &keys,
  22.401 -                                  &rating,
  22.402 -                                  &flags,
  22.403 -                                  &modified_src);
  22.404 -
  22.405 -    cout << decrypted_text << endl;
  22.406 -    cout << "Status is " << tl_status_string(status) << endl;
  22.407 -
  22.408 -
  22.409 -    assert(decrypted_text);
  22.410 -    assert(rating);
  22.411 -
  22.412 -    free(decrypted_text);
  22.413 -    decrypted_text = nullptr;
  22.414 -
  22.415 -    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  22.416 -
  22.417 -    free(decrypted_text);
  22.418 -    decrypted_text = nullptr;
  22.419 -    flags = 0;
  22.420 -    throwaway = NULL;
  22.421 -
  22.422 -    status = MIME_decrypt_message(session,
  22.423 -                                  modified_src,
  22.424 -                                  strlen(modified_src),
  22.425 -                                  &decrypted_text,
  22.426 -                                  &keys,
  22.427 -                                  &rating,
  22.428 -                                  &flags,
  22.429 -                                  &throwaway);
  22.430 -    
  22.431 -    cout << "keys used:\n";
  22.432 -      
  22.433 -    i = 0;
  22.434 -
  22.435 -    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  22.436 -    {
  22.437 -        if (i == 0) {
  22.438 -            cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  22.439 -//            assert(strcasecmp(fpr_own_recip_key,kl->value) == 0);
  22.440 -        }
  22.441 -        else {
  22.442 -            cout << "\t " << kl->value << endl;
  22.443 -//            assert(strcasecmp(fpr_own_recip_key, kl->value) == 0);
  22.444 -            cout << "Encrypted only for own identity! Yay! It worked!" << endl;
  22.445 -        }
  22.446 -        assert(i < 2);
  22.447 -    }
  22.448 -
  22.449 -    cout << "Case 3a: PASS" << endl << endl;
  22.450 -
  22.451 -
  22.452 -    cout << "Case 3b: Calling MIME_decrypt_message with reencrypt flag set on message generated by pEp (message 2.0) with extra keys." << endl;
  22.453 -
  22.454 -    free_stringlist(keys);
  22.455 -    keys = new_stringlist(fpr_pub_extra_key_0);
  22.456 -    stringlist_add(keys, fpr_pub_extra_key_1);    
  22.457 -
  22.458 -    flags = PEP_decrypt_flag_untrusted_server;
  22.459 -    
  22.460 -    status = MIME_decrypt_message(session,
  22.461 -                                  to_reencrypt_from_pEp.c_str(),
  22.462 -                                  to_reencrypt_from_pEp.size(),
  22.463 -                                  &decrypted_text,
  22.464 -                                  &keys,
  22.465 -                                  &rating,
  22.466 -                                  &flags,
  22.467 -                                  &modified_src);
  22.468 -
  22.469 -    cout << decrypted_text << endl;
  22.470 -    cout << "Status is " << tl_status_string(status) << endl;
  22.471 -
  22.472 -    assert(decrypted_text);
  22.473 -    assert(rating);
  22.474 -
  22.475 -    free(decrypted_text);
  22.476 -    decrypted_text = nullptr;
  22.477 -
  22.478 -    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  22.479 -
  22.480 -    free(decrypted_text);
  22.481 -    decrypted_text = nullptr;
  22.482 -    flags = 0;
  22.483 -    throwaway = NULL;
  22.484 -
  22.485 -    status = MIME_decrypt_message(session,
  22.486 -                                  modified_src,
  22.487 -                                  strlen(modified_src),
  22.488 -                                  &decrypted_text,
  22.489 -                                  &keys,
  22.490 -                                  &rating,
  22.491 -                                  &flags,
  22.492 -                                  &throwaway);
  22.493 -    
  22.494 -    cout << "keys used:\n";
  22.495 -    
  22.496 -    own_key_found = false;
  22.497 -    extra_key_0_found = false;
  22.498 -    extra_key_1_found = false;
  22.499 -    
  22.500 -    i = 0;
  22.501 -    
  22.502 -    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  22.503 -    {
  22.504 -        if (i == 0) {
  22.505 -              cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  22.506 -//              assert(strcasecmp(fpr_own_recip_key,kl->value) == 0);
  22.507 -        }
  22.508 -        else {
  22.509 -            if (strcasecmp(fpr_own_recip_key, kl->value) == 0) {
  22.510 -                cout << "Encrypted for us." << endl;
  22.511 -                own_key_found = true;
  22.512 -            }
  22.513 -            else if (strcasecmp(fpr_pub_extra_key_0, kl->value) == 0) {
  22.514 -                cout << "Encrypted for extra key 0." << endl;
  22.515 -                extra_key_0_found = true;
  22.516 -            }
  22.517 -            else if (strcasecmp(fpr_pub_extra_key_1, kl->value) == 0) {
  22.518 -                cout << "Encrypted for extra key 1." << endl;
  22.519 -                extra_key_1_found = true;
  22.520 -            }
  22.521 -            else {
  22.522 -                cout << "FAIL: Encrypted for " << kl->value << ", which it should not be." << endl;
  22.523 -//                assert(false);
  22.524 -            }
  22.525 -            cout << "\t " << kl->value << endl;
  22.526 -        }
  22.527 -        assert(i < 4);
  22.528 -    }
  22.529 -//    assert (own_key_found && extra_key_0_found && extra_key_1_found);
  22.530 -    cout << "Message was encrypted for all the keys it should be, and none it should not!" << endl;
  22.531 -
  22.532 -    cout << "Case 3b: PASS" << endl << endl;
  22.533 -    
  22.534 -    cout << "calling release()\n";
  22.535 -    release(session);
  22.536 -    return 0;
  22.537 -}
    23.1 --- a/test/revoke_regen_attach_test.cc	Tue May 08 11:09:11 2018 +0200
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,95 +0,0 @@
    23.4 -// This file is under GNU General Public License 3.0
    23.5 -// see LICENSE.txt
    23.6 -
    23.7 -#include <stdlib.h>
    23.8 -#include <string.h>
    23.9 -#include <time.h>
   23.10 -#include "platform.h"
   23.11 -#include <iostream>
   23.12 -#include <fstream>
   23.13 -#include <assert.h>
   23.14 -#include "mime.h"
   23.15 -#include "message_api.h"
   23.16 -
   23.17 -using namespace std;
   23.18 -
   23.19 -int main() {
   23.20 -    cout << "\n*** revoke_regen_attach_test ***\n\n";
   23.21 -
   23.22 -    PEP_SESSION session;
   23.23 -    
   23.24 -    cout << "calling init()\n";
   23.25 -    PEP_STATUS status = init(&session);   
   23.26 -    assert(status == PEP_STATUS_OK);
   23.27 -    assert(session);
   23.28 -    cout << "init() completed.\n";
   23.29 -
   23.30 -    cout << "creating own id for : ";
   23.31 -    char *uniqname = strdup("AAAAtestuser@testdomain.org");
   23.32 -    srandom(time(NULL));
   23.33 -    for(int i=0; i < 4;i++)
   23.34 -        uniqname[i] += random() & 0xf;
   23.35 -    
   23.36 -    cout << uniqname << "\n";
   23.37 -    pEp_identity * me = new_identity(uniqname, NULL, PEP_OWN_USERID, "Test User");
   23.38 -    free(uniqname);
   23.39 -    myself(session, me);
   23.40 -
   23.41 -    cout << "generated fingerprint \n";
   23.42 -    cout << me->fpr << "\n";
   23.43 -
   23.44 -    const char *prev_fpr = strdup(me->fpr);
   23.45 -    
   23.46 -    cout << "revoke \n";
   23.47 -    
   23.48 -    key_mistrusted(session, me);
   23.49 -
   23.50 -    cout << "re-generated fingerprint \n";
   23.51 -    free(me->fpr);
   23.52 -    me->fpr = NULL;
   23.53 -    status = myself(session, me);
   23.54 -    assert(status == PEP_STATUS_OK);
   23.55 -    cout << me->fpr << "\n";
   23.56 -    
   23.57 -    assert(me->fpr);
   23.58 -    assert(strcmp(me->fpr, prev_fpr) != 0);
   23.59 -    cout << "New fpr is: " << me->fpr;
   23.60 -    
   23.61 -    me->fpr = NULL;
   23.62 -    me->comm_type = PEP_ct_unknown;
   23.63 -    myself(session, me);
   23.64 -    
   23.65 -    identity_list *to = new_identity_list(new_identity("pep.test.alice@pep-project.org", NULL, "42", "pEp Test Alice (test key don't use)"));
   23.66 -    message *msg = new_message(PEP_dir_outgoing);
   23.67 -    assert(msg);
   23.68 -    msg->from = me;
   23.69 -    msg->to = to;
   23.70 -    msg->shortmsg = strdup("hello, world");
   23.71 -    cout << "message created.\n";
   23.72 -
   23.73 -    cout << "encrypting message as MIME multipart…\n";
   23.74 -    message *enc_msg;
   23.75 -    cout << "calling encrypt_message()\n";
   23.76 -    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   23.77 -    assert(status == PEP_STATUS_OK);
   23.78 -    assert(enc_msg);
   23.79 -    cout << "message encrypted.\n";
   23.80 -
   23.81 -    // cout << msg->attachments->filename;
   23.82 -    // int bl_len = bloblist_length(msg->attachments);
   23.83 -    // cout << "Message contains " << bloblist_length(msg->attachments) << " attachments." << endl;
   23.84 -    // assert(bloblist_length(msg->attachments) == 2);
   23.85 -    // assert(strcmp(msg->attachments->filename, "file://pEpkey.asc") == 0);
   23.86 -    // assert(strcmp(msg->attachments->next->filename, "file://pEpkey.asc") == 0);
   23.87 -    // 
   23.88 -    // cout << "message contains 2 key attachments.\n";
   23.89 -
   23.90 -    free_message(msg);
   23.91 -    free_message(enc_msg);
   23.92 -   
   23.93 -    // TODO: check that revoked key isn't sent after some time.
   23.94 -
   23.95 -    release(session);
   23.96 -
   23.97 -    return 0;
   23.98 -}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/test/src/engine_tests/EncryptMissingPrivateKeyTests.cc	Tue May 08 15:43:07 2018 +0200
    24.3 @@ -0,0 +1,80 @@
    24.4 +// This file is under GNU General Public License 3.0
    24.5 +// see LICENSE.txt
    24.6 +
    24.7 +#include <stdlib.h>
    24.8 +#include <iostream>
    24.9 +#include <fstream>
   24.10 +#include <string>
   24.11 +#include <cstring> // for strcmp()
   24.12 +#include <cpptest.h>
   24.13 +
   24.14 +#include "blacklist.h"
   24.15 +#include "keymanagement.h"
   24.16 +#include "message_api.h"
   24.17 +#include "mime.h"
   24.18 +#include "test_util.h"
   24.19 +
   24.20 +#include "pEpEngine.h"
   24.21 +
   24.22 +using namespace std;
   24.23 +
   24.24 +#include "EngineTestSessionSuite.h"
   24.25 +#include "EncryptMissingPrivateKeyTests.h"
   24.26 +
   24.27 +using namespace std;
   24.28 +
   24.29 +EncryptMissingPrivateKeyTests::EncryptMissingPrivateKeyTests(string suitename, string test_home_dir) :
   24.30 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   24.31 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EncryptMissingPrivateKeyTests::check_encrypt_missing_private_key"),
   24.32 +                                                                      static_cast<Func>(&EncryptMissingPrivateKeyTests::check_encrypt_missing_private_key)));
   24.33 +}
   24.34 +
   24.35 +void EncryptMissingPrivateKeyTests::check_encrypt_missing_private_key() {
   24.36 +    
   24.37 +    pEp_identity* no_key_identity = new_identity("blacklistself@kgrothoff.org",
   24.38 +                                                      NULL,
   24.39 +                                                      PEP_OWN_USERID,
   24.40 +                                                      "Blacklist Self");
   24.41 +    no_key_identity->me = true;
   24.42 +    PEP_STATUS status8 = myself(session, no_key_identity);
   24.43 +    TEST_ASSERT (status8 == PEP_STATUS_OK);
   24.44 +
   24.45 +    /* Now let's try to encrypt a message. */
   24.46 +        
   24.47 +    message* tmp_msg = NULL;
   24.48 +    message* enc_msg = NULL;
   24.49 +    
   24.50 +    const string mailtext = slurp("test_mails/blacklist_no_key.eml");
   24.51 +
   24.52 +    PEP_STATUS status = mime_decode_message(mailtext.c_str(), mailtext.length(), &tmp_msg);
   24.53 +    TEST_ASSERT(status == PEP_STATUS_OK);
   24.54 +    
   24.55 +    status = update_identity(session, tmp_msg->from);
   24.56 +    identity_list* to_list = tmp_msg->to;
   24.57 +
   24.58 +    while (to_list) {
   24.59 +        if (to_list->ident)
   24.60 +            update_identity(session, to_list->ident);
   24.61 +        to_list = to_list->next;
   24.62 +    }
   24.63 +    
   24.64 +    // This isn't incoming, though... so we need to reverse the direction
   24.65 +    tmp_msg->dir = PEP_dir_outgoing;
   24.66 +    status = encrypt_message(session,
   24.67 +                             tmp_msg,
   24.68 +                             NULL,
   24.69 +                             &enc_msg,
   24.70 +                             PEP_enc_PGP_MIME,
   24.71 +                             0);
   24.72 +    TEST_ASSERT(status == PEP_STATUS_OK);
   24.73 +    
   24.74 +
   24.75 +    char* new_key = enc_msg->from->fpr;
   24.76 +    cout << "Encrypted with key " << new_key << endl;
   24.77 +    
   24.78 +    status = delete_keypair(session, new_key);
   24.79 +    PEP_STATUS status14 = myself(session, no_key_identity);
   24.80 +
   24.81 +    free_message(tmp_msg);    
   24.82 +    free_message(enc_msg);
   24.83 +}
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/test/src/engine_tests/ExternalRevokeTests.cc	Tue May 08 15:43:07 2018 +0200
    25.3 @@ -0,0 +1,311 @@
    25.4 +// This file is under GNU General Public License 3.0
    25.5 +// see LICENSE.txt
    25.6 +
    25.7 +#include <stdlib.h>
    25.8 +#include <string>
    25.9 +#include <cstring>
   25.10 +#include <time.h>
   25.11 +#include "platform.h"
   25.12 +#include <iostream>
   25.13 +#include <fstream>
   25.14 +#include "mime.h"
   25.15 +#include "message_api.h"
   25.16 +#include "test_util.h"
   25.17 +
   25.18 +#include "pEpEngine.h"
   25.19 +
   25.20 +#include <cpptest.h>
   25.21 +#include "EngineTestSessionSuite.h"
   25.22 +#include "ExternalRevokeTests.h"
   25.23 +
   25.24 +using namespace std;
   25.25 +
   25.26 +ExternalRevokeTests::ExternalRevokeTests(string suitename, string test_home_dir) :
   25.27 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   25.28 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExternalRevokeTests::check_external_revoke"),
   25.29 +                                                                      static_cast<Func>(&ExternalRevokeTests::check_external_revoke)));
   25.30 +}
   25.31 +
   25.32 +void ExternalRevokeTests::check_external_revoke() {
   25.33 +
   25.34 +    PEP_STATUS status = PEP_STATUS_OK;   
   25.35 +
   25.36 +#ifndef NETPGP
   25.37 +    char* fprs[2];
   25.38 +
   25.39 +    const string fenris_pub_key = slurp("test_keys/pub/pep.test.fenris-0x4F3D2900_pub.asc");
   25.40 +    const string fenris_priv_key = slurp("test_keys/priv/pep.test.fenris-0x4F3D2900_priv.asc");
   25.41 +
   25.42 +    TEST_ASSERT(fenris_pub_key.length() != 0);
   25.43 +    TEST_ASSERT(fenris_priv_key.length() != 0);
   25.44 +    
   25.45 +    PEP_STATUS statuspub = import_key(session, fenris_pub_key.c_str(), fenris_pub_key.length(), NULL);
   25.46 +    PEP_STATUS statuspriv = import_key(session, fenris_priv_key.c_str(), fenris_priv_key.length(), NULL);
   25.47 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
   25.48 +    TEST_ASSERT(statuspriv == PEP_STATUS_OK);
   25.49 +
   25.50 +    // Create sender ID
   25.51 +    
   25.52 +    pEp_identity * me = new_identity("pep.test.fenris@thisstilldoesntwork.lu", "0969FA229DF21C832A64A04711B1B9804F3D2900", PEP_OWN_USERID, "Fenris Hawke");
   25.53 +    status = myself(session, me);
   25.54 +    
   25.55 +    // Create key
   25.56 +    cout << "Creating new id for : ";
   25.57 +    char *uniqname = strdup("AAAAtestuser@testdomain.org");
   25.58 +    srandom(time(NULL));
   25.59 +    for(int i=0; i < 4;i++)
   25.60 +        uniqname[i] += random() & 0xf;
   25.61 +    
   25.62 +    cout << uniqname << "\n";
   25.63 +    pEp_identity * recip1 = new_identity(uniqname, NULL, NULL, "Test User");
   25.64 +
   25.65 +    status = generate_keypair(session, recip1);
   25.66 +    
   25.67 +    cout << "Generated fingerprint ";
   25.68 +    cout << recip1->fpr << "\n";
   25.69 +
   25.70 +    fprs[0] = strdup(recip1->fpr);
   25.71 +    
   25.72 +    cout << endl << "*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*" << endl;
   25.73 +    cout << "Trust and revoke single key, ensure trust changes, then generate new key and ensure rating is correct." << endl;
   25.74 +    cout << "*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*" << endl << endl;
   25.75 +    
   25.76 +    cout << endl << "---------------------------------------------------------" << endl;
   25.77 +    cout << "1a. Encrypt message for trusted partner." << endl;
   25.78 +    cout << "---------------------------------------------------------" << endl << endl;
   25.79 +
   25.80 +    cout << "Trusting personal key for " << uniqname << endl;
   25.81 +    recip1->me = false;
   25.82 +    // Trust it
   25.83 +    status = update_identity(session, recip1);
   25.84 +    status = trust_personal_key(session, recip1);
   25.85 +    status = update_identity(session, recip1);
   25.86 +    
   25.87 +    // TODO: Check trust?
   25.88 +    cout << "Done! Trusted personal key with fpr " << recip1->fpr << " for " << uniqname << endl;
   25.89 +
   25.90 +    const char* r1_userid = (recip1->user_id ? strdup(recip1->user_id) : NULL);
   25.91 +
   25.92 +    
   25.93 +    // encrypt something to the key
   25.94 +    cout << "Creating message…\n";
   25.95 +    identity_list* to_list = new_identity_list(identity_dup(recip1)); // to bob
   25.96 +    message* outgoing_msg = new_message(PEP_dir_outgoing);
   25.97 +    TEST_ASSERT(outgoing_msg);
   25.98 +    outgoing_msg->from = identity_dup(me);
   25.99 +    outgoing_msg->to = to_list;
  25.100 +    outgoing_msg->shortmsg = strdup("Greetings, humans!");
  25.101 +    outgoing_msg->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
  25.102 +    outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  25.103 +    cout << "Message created.\n";
  25.104 +
  25.105 +    message* encrypted_outgoing_msg = NULL;
  25.106 +
  25.107 +    cout << "Encrypting message to " << uniqname << "…\n";    
  25.108 +    status = encrypt_message(session, outgoing_msg, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
  25.109 +    cout << "Encrypted message with status " << tl_status_string(status) << endl;
  25.110 +    // check status
  25.111 +    TEST_ASSERT(status == PEP_STATUS_OK);
  25.112 +    TEST_ASSERT(encrypted_outgoing_msg);
  25.113 +
  25.114 +    cout << "Checking message recipient comm_type from message." << endl;
  25.115 +    // check comm_type
  25.116 +    cout << "comm_type: " << tl_ct_string(encrypted_outgoing_msg->to->ident->comm_type) << endl;
  25.117 +    TEST_ASSERT(encrypted_outgoing_msg->to->ident->comm_type == PEP_ct_OpenPGP);
  25.118 +    
  25.119 +    status = get_trust(session, recip1);
  25.120 +    
  25.121 +    cout << "Recip's trust DB comm_type = " << hex << tl_ct_string(recip1->comm_type) << endl;
  25.122 +    TEST_ASSERT(recip1->comm_type == PEP_ct_OpenPGP); // FIXME: PEP_ct_pEp???
  25.123 +
  25.124 +    // decrypt message
  25.125 +    free_message(outgoing_msg);
  25.126 +    outgoing_msg = NULL;
  25.127 +
  25.128 +    stringlist_t* keylist = nullptr;
  25.129 +    PEP_rating rating;
  25.130 +    PEP_decrypt_flags_t flags;
  25.131 +
  25.132 +    cout << endl << "---------------------------------------------------------" << endl;
  25.133 +    cout << "1b. Decrypt message that was encrypted for trusted partner." << endl;
  25.134 +    cout << "---------------------------------------------------------" << endl << endl;
  25.135 +
  25.136 +    flags = 0;
  25.137 +    cout << "Decrypting message." << endl;
  25.138 +    status = decrypt_message(session, encrypted_outgoing_msg, &outgoing_msg, &keylist, &rating, &flags);
  25.139 +    cout << "Decrypted message with status " << tl_status_string(status) << endl;
  25.140 +    TEST_ASSERT(status == PEP_STATUS_OK);
  25.141 +    TEST_ASSERT(rating == PEP_rating_trusted);
  25.142 +
  25.143 +    // check rating
  25.144 +    cout << "Rating of decrypted message to trusted recip: " << tl_rating_string(rating) << endl;
  25.145 +    TEST_ASSERT(rating == PEP_rating_trusted); // FIXME: trusted and anonymised?
  25.146 +    
  25.147 +    // check comm_type
  25.148 +    status = get_trust(session, recip1);
  25.149 +
  25.150 +    cout << "Recip's trust DB comm_type = " << tl_ct_string(recip1->comm_type) << endl;
  25.151 +    TEST_ASSERT(recip1->comm_type == PEP_ct_OpenPGP); // FIXME: PEP_ct_pEp???
  25.152 +
  25.153 +    cout << endl << "---------------------------------------------------------" << endl;
  25.154 +    cout << "2a. Revoke key for (currently) trusted partner." << endl;
  25.155 +    cout << "---------------------------------------------------------" << endl << endl;
  25.156 +    // externally revoke key
  25.157 +    // (note - as of 23.5.17, revoke_key() doesn't touch the trust db, just the keyring, so we can do this)
  25.158 +
  25.159 +    cout << "Revoking key." << endl;
  25.160 +    status = update_identity(session, recip1);    
  25.161 +    status = revoke_key(session, recip1->fpr, "encrypt_for_identity_test");
  25.162 +    cout << "Status of revocation call for " << recip1->fpr << " is "<< tl_status_string(status) << endl;
  25.163 +
  25.164 +    // free messages
  25.165 +    free_message(outgoing_msg);
  25.166 +    free_message(encrypted_outgoing_msg);
  25.167 +    outgoing_msg = NULL;
  25.168 +    encrypted_outgoing_msg = NULL;
  25.169 +    
  25.170 +    // encrypt something to the key
  25.171 +    cout << "creating message…\n";
  25.172 +    to_list = new_identity_list(identity_dup(recip1)); // to bob
  25.173 +    outgoing_msg = new_message(PEP_dir_outgoing);
  25.174 +    TEST_ASSERT(outgoing_msg);
  25.175 +    outgoing_msg->from = identity_dup(me);
  25.176 +    outgoing_msg->to = to_list;
  25.177 +    outgoing_msg->shortmsg = strdup("Greetings, humans!");
  25.178 +    outgoing_msg->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
  25.179 +    outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  25.180 +    cout << "message created.\n";
  25.181 +
  25.182 +    encrypted_outgoing_msg = NULL;
  25.183 +    message* decrypted_msg = NULL;
  25.184 +
  25.185 +    cout << endl << "---------------------------------------------------------" << endl;
  25.186 +    cout << "2b. Encrypt message for recip whose key has been externally revoked in the keyring, not the app." << endl;
  25.187 +    cout << "---------------------------------------------------------" << endl << endl;
  25.188 +
  25.189 +
  25.190 +    status = encrypt_message(session, outgoing_msg, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
  25.191 +    cout << "Encryption returns with status " << tl_status_string(status) << endl;
  25.192 +    TEST_ASSERT (status == PEP_UNENCRYPTED);
  25.193 +    TEST_ASSERT (encrypted_outgoing_msg == NULL);
  25.194 +    status = update_identity(session, recip1);
  25.195 +    TEST_ASSERT(recip1->comm_type = PEP_ct_key_not_found);
  25.196 +
  25.197 +    cout << endl << "---------------------------------------------------------" << endl;
  25.198 +    cout << "2c. Check trust of recip, whose only key has been revoked, once an encryption attempt has been made." << endl;
  25.199 +    cout << "---------------------------------------------------------" << endl << endl;
  25.200 +
  25.201 +    TEST_ASSERT(recip1->fpr == NULL);
  25.202 +    recip1->fpr = fprs[0];
  25.203 +    status = get_trust(session, recip1);
  25.204 +    recip1->fpr = NULL;
  25.205 +
  25.206 +    cout << "Recip's trust DB comm_type = " << hex << tl_ct_string(recip1->comm_type) << endl;
  25.207 +    TEST_ASSERT(recip1->comm_type == PEP_ct_unknown || recip1->comm_type == PEP_ct_key_revoked);
  25.208 +
  25.209 +    free_message(decrypted_msg);
  25.210 +    free_message(outgoing_msg);
  25.211 +    outgoing_msg = NULL;
  25.212 +    decrypted_msg = NULL;
  25.213 +
  25.214 +    cout << endl << "---------------------------------------------------------" << endl;
  25.215 +    cout << "3a. Generate new key, but don't explicitly trust it." << endl;
  25.216 +    cout << "---------------------------------------------------------" << endl << endl;
  25.217 +
  25.218 +    // now: generate new key
  25.219 +    free(recip1->fpr);
  25.220 +    recip1->fpr = NULL;
  25.221 +    status = generate_keypair(session, recip1);
  25.222 +    
  25.223 +    cout << "Generated fingerprint \n";
  25.224 +    cout << recip1->fpr << "\n";
  25.225 +    fprs[1] = strdup(recip1->fpr);
  25.226 +
  25.227 +    // try again
  25.228 +    cout << endl << "---------------------------------------------------------" << endl;
  25.229 +    cout << "3b. Try to send something to the email address of our revoked friend, make sure a new key is used to encrypt." << endl;
  25.230 +    cout << "---------------------------------------------------------" << endl << endl;
  25.231 +    
  25.232 +    // encrypt something to the key
  25.233 +    cout << "Creating message…\n";
  25.234 +    
  25.235 +    // cout << "First, update identity though!\n";
  25.236 +    // status = update_identity(session, recip1);
  25.237 +    to_list = new_identity_list(identity_dup(recip1)); // to bob
  25.238 +    outgoing_msg = new_message(PEP_dir_outgoing);
  25.239 +    TEST_ASSERT(outgoing_msg);
  25.240 +    outgoing_msg->from = identity_dup(me);
  25.241 +    outgoing_msg->to = to_list;
  25.242 +    outgoing_msg->shortmsg = strdup("Greetings, humans!");
  25.243 +    outgoing_msg->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
  25.244 +    outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  25.245 +    cout << "Message created.\n";
  25.246 +
  25.247 +    status = encrypt_message(session, outgoing_msg, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
  25.248 +    PEP_comm_type ct = (encrypted_outgoing_msg ? encrypted_outgoing_msg->to->ident->comm_type : outgoing_msg->to->ident->comm_type);
  25.249 +    
  25.250 +
  25.251 +    // CHECK STATUS???
  25.252 +    cout << "Encryption returns with status " << tl_status_string(status) << endl;
  25.253 +
  25.254 +    // check comm_type
  25.255 +    cout << "comm_type: " << tl_ct_string(ct) << endl;
  25.256 +    TEST_ASSERT(ct == PEP_ct_OpenPGP_unconfirmed);
  25.257 +    
  25.258 +    status = get_trust(session, recip1);
  25.259 +
  25.260 +    cout << "Recip's trust DB comm_type (should be unknown, as we're using a keyring-only key, not in DB) = " << hex << tl_ct_string(recip1->comm_type) << endl;
  25.261 +    TEST_ASSERT(recip1->comm_type != PEP_ct_OpenPGP_unconfirmed);
  25.262 +
  25.263 +    // decrypt message
  25.264 +//    free_message(outgoing_msg);
  25.265 +//    outgoing_msg = NULL;
  25.266 +
  25.267 +    cout << endl << "---------------------------------------------------------" << endl;
  25.268 +    cout << "3c. Decrypt... that... message!" << endl;
  25.269 +    cout << "---------------------------------------------------------" << endl << endl;
  25.270 +
  25.271 +
  25.272 +    flags = 0;
  25.273 +    status = decrypt_message(session, encrypted_outgoing_msg, &decrypted_msg, &keylist, &rating, &flags);
  25.274 +    cout << "Decryption returns with status " << tl_status_string(status) << endl;
  25.275 +    TEST_ASSERT(status == PEP_STATUS_OK);
  25.276 +    TEST_ASSERT(decrypted_msg);
  25.277 +    
  25.278 +    // check rating
  25.279 +    cout << "Rating of decrypted message to trusted recip: " << tl_rating_string(rating) << endl;
  25.280 +    TEST_ASSERT(rating == PEP_rating_reliable);
  25.281 +
  25.282 +    status = update_identity(session, decrypted_msg->to->ident);
  25.283 +    ct = (decrypted_msg ? decrypted_msg->to->ident->comm_type : outgoing_msg->to->ident->comm_type);
  25.284 +
  25.285 +    cout << "comm_type: " << tl_ct_string(ct) << endl;
  25.286 +    TEST_ASSERT(ct == PEP_ct_OpenPGP_unconfirmed);
  25.287 +    
  25.288 +    status = get_trust(session, recip1);
  25.289 +    
  25.290 +    cout << "Recip's trust DB comm_type (should be unknown - there's nothing in the DB) = " << hex << tl_ct_string(recip1->comm_type) << endl;
  25.291 +    TEST_ASSERT(recip1->comm_type == PEP_ct_unknown);
  25.292 +
  25.293 +    free_message(encrypted_outgoing_msg);
  25.294 +    free_message(decrypted_msg);
  25.295 +    free_message(outgoing_msg);
  25.296 +    outgoing_msg = NULL;
  25.297 +    decrypted_msg = NULL;
  25.298 +    encrypted_outgoing_msg = NULL;
  25.299 +
  25.300 +    free_identity(me);
  25.301 +    free_identity(recip1);
  25.302 +    free(uniqname);
  25.303 +    
  25.304 +    delete_keypair(session, fprs[0]);    
  25.305 +    delete_keypair(session, fprs[1]);
  25.306 +    
  25.307 +    free(fprs[0]);
  25.308 +    free(fprs[1]);
  25.309 +    
  25.310 +#else
  25.311 +    cout << "Sorry, test is not defined for NETPGP at this time." << endl;
  25.312 +    
  25.313 +#endif
  25.314 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/test/src/engine_tests/I18nTests.cc	Tue May 08 15:43:07 2018 +0200
    26.3 @@ -0,0 +1,45 @@
    26.4 +// This file is under GNU General Public License 3.0
    26.5 +// see LICENSE.txt
    26.6 +
    26.7 +#include <stdlib.h>
    26.8 +#include <string>
    26.9 +#include <iostream>
   26.10 +
   26.11 +#include "pEpEngine.h"
   26.12 +
   26.13 +#include <cpptest.h>
   26.14 +#include "EngineTestSessionSuite.h"
   26.15 +#include "I18nTests.h"
   26.16 +
   26.17 +using namespace std;
   26.18 +
   26.19 +I18nTests::I18nTests(string suitename, string test_home_dir) :
   26.20 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   26.21 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("I18nTests::check_i18n"),
   26.22 +                                                                      static_cast<Func>(&I18nTests::check_i18n)));
   26.23 +}
   26.24 +
   26.25 +void I18nTests::check_i18n() {
   26.26 +
   26.27 +    // i18n test code
   26.28 +
   26.29 +    char *languages;
   26.30 +    PEP_STATUS status2 = get_languagelist(session, &languages);
   26.31 +    TEST_ASSERT(status2 == PEP_STATUS_OK);
   26.32 +    TEST_ASSERT(languages);
   26.33 +
   26.34 +    cout << languages;
   26.35 +    pEp_free(languages);
   26.36 +
   26.37 +    char *phrase;
   26.38 +    PEP_STATUS status3 = get_phrase(session, "de", 1000, &phrase);
   26.39 +    TEST_ASSERT(status3 == PEP_STATUS_OK);
   26.40 +    TEST_ASSERT(phrase);
   26.41 +
   26.42 +    cout << "\nGerman: " << phrase << "\n";
   26.43 +    pEp_free(phrase);
   26.44 +
   26.45 +    status3 = get_phrase(session, "zz", 1000, &phrase);
   26.46 +    TEST_ASSERT(status3 == PEP_PHRASE_NOT_FOUND);
   26.47 +    TEST_ASSERT(phrase == NULL);
   26.48 +}
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/test/src/engine_tests/IdentityListTests.cc	Tue May 08 15:43:07 2018 +0200
    27.3 @@ -0,0 +1,174 @@
    27.4 +// This file is under GNU General Public License 3.0
    27.5 +// see LICENSE.txt
    27.6 +
    27.7 +#include <stdlib.h>
    27.8 +#include <string>
    27.9 +#include <cstring>
   27.10 +#include <iostream>
   27.11 +#include <fstream>
   27.12 +#include <assert.h>
   27.13 +
   27.14 +#include "pEpEngine.h"
   27.15 +#include "platform.h"
   27.16 +
   27.17 +#include "identity_list.h"
   27.18 +
   27.19 +#include <cpptest.h>
   27.20 +#include "EngineTestSessionSuite.h"
   27.21 +#include "IdentityListTests.h"
   27.22 +
   27.23 +using namespace std;
   27.24 +
   27.25 +// FIXME
   27.26 +static int test_identity_equals(pEp_identity* val1, pEp_identity* val2) {
   27.27 +    assert(val1);
   27.28 +    assert(val2);
   27.29 +    assert(val1->address);
   27.30 +    assert(val2->address);
   27.31 +    assert(val1->fpr);
   27.32 +    assert(val2->fpr);
   27.33 +    assert(val1->username);
   27.34 +    assert(val2->username);
   27.35 +    return((strcmp(val1->address, val2->address) == 0) && (strcmp(val1->fpr, val2->fpr) == 0)
   27.36 +        && (strcmp(val1->username, val2->username) == 0) && (val1->comm_type == val2->comm_type)
   27.37 +        && (val1->lang[0] == val2->lang[0]) && (val1->lang[1] == val2->lang[1])
   27.38 +        && (val1->lang[2] == val2->lang[2]) && (val1->me == val2->me));
   27.39 +}
   27.40 +
   27.41 +
   27.42 +IdentityListTests::IdentityListTests(string suitename, string test_home_dir) :
   27.43 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   27.44 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("IdentityListTests::check_identity_list"),
   27.45 +                                                                      static_cast<Func>(&IdentityListTests::check_identity_list)));
   27.46 +}
   27.47 +
   27.48 +void IdentityListTests::check_identity_list() {
   27.49 +
   27.50 +    pEp_identity* id1 = new_identity(
   27.51 +        "leon.schumacher@digitalekho.com",
   27.52 +        "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
   27.53 +        "23",
   27.54 +        "Leon Schumacher"
   27.55 +    );
   27.56 +    id1->comm_type = PEP_ct_pEp;
   27.57 +    
   27.58 +    pEp_identity* id2 = new_identity(
   27.59 +        "krista@kgrothoff.org",
   27.60 +        "62D4932086185C15917B72D30571AFBCA5493553",
   27.61 +        "42",
   27.62 +        "Krista Bennett Grothoff"
   27.63 +    );
   27.64 +    
   27.65 +    id2->comm_type = PEP_ct_OpenPGP;
   27.66 +
   27.67 +    pEp_identity* id3 = new_identity(
   27.68 +        "krista@pep-project.org",
   27.69 +        "51BF42D25BB5B154D71BF6CD3CF25B776D149247",
   27.70 +        "10",
   27.71 +        "Krista Grothoff"
   27.72 +    );
   27.73 +    
   27.74 +    id3->comm_type = PEP_ct_OTR;
   27.75 +
   27.76 +    pEp_identity* id4 = new_identity(
   27.77 +        "papa@smurf.lu",
   27.78 +        "00001111222233334444555566667777DEADBEEF",
   27.79 +        "667",
   27.80 +        "Papa Smurf"
   27.81 +    );
   27.82 +    
   27.83 +    id4->comm_type = PEP_ct_key_b0rken;
   27.84 +    
   27.85 +    pEp_identity* id_arr[4] = {id1, id2, id3, id4};
   27.86 +        
   27.87 +    int i;
   27.88 +        
   27.89 +    cout << "creating one-element identity_list...\n";
   27.90 +    
   27.91 +    pEp_identity* new_id = identity_dup(id1);
   27.92 +    TEST_ASSERT(new_id);
   27.93 +    identity_list* idlist = new_identity_list(new_id);
   27.94 +    TEST_ASSERT(idlist->ident);
   27.95 +    TEST_ASSERT(test_identity_equals(id1, idlist->ident));
   27.96 +    TEST_ASSERT(idlist->next == NULL);
   27.97 +    cout << "one-element identity_list created, next element is NULL\n\n";
   27.98 +    
   27.99 +    cout << "duplicating one-element list...\n";
  27.100 +    identity_list* duplist = identity_list_dup(idlist);
  27.101 +    pEp_identity* srcid = idlist->ident;
  27.102 +    pEp_identity* dstid = duplist->ident;
  27.103 +    TEST_ASSERT(dstid);
  27.104 +    TEST_ASSERT(test_identity_equals(srcid, dstid));
  27.105 +    TEST_ASSERT(srcid->address != dstid->address);   // test deep copies 
  27.106 +    TEST_ASSERT(srcid->fpr != dstid->fpr);
  27.107 +    TEST_ASSERT(srcid->username != dstid->username);
  27.108 +    TEST_ASSERT(duplist->next == NULL);
  27.109 +    cout << "one-element identity_list duplicated.\n\n";
  27.110 +    
  27.111 +    cout << "freeing identity_lists...\n";
  27.112 +    free_identity_list(idlist); // will free srcid
  27.113 +    free_identity_list(duplist);
  27.114 +    idlist = NULL;
  27.115 +    duplist = NULL;
  27.116 +    srcid = NULL;
  27.117 +    
  27.118 +    identity_list* p;
  27.119 +    cout << "\ncreating four-element list...\n";
  27.120 +    idlist = identity_list_add(idlist, identity_dup(id_arr[0]));
  27.121 +    for (i = 1; i < 4; i++) {
  27.122 +        p = identity_list_add(idlist, identity_dup(id_arr[i]));
  27.123 +        TEST_ASSERT(p);
  27.124 +    }
  27.125 +    
  27.126 +    p = idlist;
  27.127 +    
  27.128 +    for (i = 0; i < 4; i++) {
  27.129 +        TEST_ASSERT(p);
  27.130 +        
  27.131 +        srcid = p->ident;
  27.132 +        TEST_ASSERT(srcid);
  27.133 +        
  27.134 +        TEST_ASSERT(test_identity_equals(srcid, id_arr[i]));
  27.135 +        TEST_ASSERT(srcid->address != id_arr[i]->address);   // test deep copies
  27.136 +        TEST_ASSERT(srcid->fpr != id_arr[i]->fpr);
  27.137 +        TEST_ASSERT(srcid->username != id_arr[i]->username);
  27.138 +
  27.139 +        p = p->next;
  27.140 +    }
  27.141 +    TEST_ASSERT(p == NULL);
  27.142 +    
  27.143 +    cout << "\nduplicating four-element list...\n\n";
  27.144 +    duplist = identity_list_dup(idlist);
  27.145 +    
  27.146 +    p = idlist;
  27.147 +    identity_list* dup_p = duplist;
  27.148 +    
  27.149 +    while (dup_p) {
  27.150 +        srcid = p->ident;
  27.151 +        dstid = dup_p->ident;
  27.152 +
  27.153 +        TEST_ASSERT(dstid);
  27.154 +        
  27.155 +        TEST_ASSERT(test_identity_equals(srcid, dstid));
  27.156 +
  27.157 +        TEST_ASSERT(srcid != dstid);   // test deep copies
  27.158 +        TEST_ASSERT(srcid->address != dstid->address);   // test deep copies
  27.159 +        TEST_ASSERT(srcid->fpr != dstid->fpr);
  27.160 +        TEST_ASSERT(srcid->username != dstid->username);
  27.161 +        
  27.162 +        i++;
  27.163 +        p = p->next;
  27.164 +
  27.165 +        dup_p = dup_p->next;
  27.166 +        TEST_ASSERT((p == NULL) == (dup_p == NULL));
  27.167 +    }
  27.168 +    cout << "\nfour-element identity_list successfully duplicated.\n\n";
  27.169 +
  27.170 +    cout << "freeing identity_lists...\n";
  27.171 +    free_identity_list(idlist); // will free srcid
  27.172 +    free_identity_list(duplist);
  27.173 +    idlist = NULL;
  27.174 +    duplist = NULL;
  27.175 +    
  27.176 +    cout << "done.\n";
  27.177 +}
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/test/src/engine_tests/KeyeditTests.cc	Tue May 08 15:43:07 2018 +0200
    28.3 @@ -0,0 +1,70 @@
    28.4 +// This file is under GNU General Public License 3.0
    28.5 +// see LICENSE.txt
    28.6 +
    28.7 +#include <stdlib.h>
    28.8 +#include <string>
    28.9 +#include <iostream>
   28.10 +#include <fstream>
   28.11 +#include <cstring>
   28.12 +
   28.13 +#include "pEpEngine.h"
   28.14 +#include "platform.h"
   28.15 +
   28.16 +#include <cpptest.h>
   28.17 +#include "EngineTestSessionSuite.h"
   28.18 +#include "KeyeditTests.h"
   28.19 +
   28.20 +using namespace std;
   28.21 +
   28.22 +KeyeditTests::KeyeditTests(string suitename, string test_home_dir) :
   28.23 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   28.24 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyeditTests::check_keyedit"),
   28.25 +                                                                      static_cast<Func>(&KeyeditTests::check_keyedit)));
   28.26 +}
   28.27 +
   28.28 +void KeyeditTests::check_keyedit() {
   28.29 +
   28.30 +    // generate test key
   28.31 +
   28.32 +    cout << "\ngenerating key for keyedit test\n";
   28.33 +    pEp_identity *identity = new_identity(
   28.34 +            "expire@dingens.org",
   28.35 +            NULL,
   28.36 +            "423",
   28.37 +            "expire test key"
   28.38 +        );
   28.39 +    TEST_ASSERT(identity);
   28.40 +    PEP_STATUS generate_status = generate_keypair(session, identity);
   28.41 +    cout << "generate_keypair() exits with " << generate_status << "\n";
   28.42 +    TEST_ASSERT(generate_status == PEP_STATUS_OK);
   28.43 +    cout << "generated key is " << identity->fpr << "\n";
   28.44 +
   28.45 +    string key(identity->fpr);
   28.46 +    free_identity(identity);
   28.47 +
   28.48 +    // keyedit test code
   28.49 +
   28.50 +    timestamp *ts = new_timestamp(time(0));
   28.51 +    ts->tm_year += 2;
   28.52 +
   28.53 +    cout << "key shell expire on " << asctime(ts) << "\n";
   28.54 +
   28.55 +    PEP_STATUS status2 = renew_key(session, key.c_str(), ts);
   28.56 +    cout << "renew_key() exited with " << status2 << "\n";
   28.57 +    TEST_ASSERT(status2 == PEP_STATUS_OK);
   28.58 +    free_timestamp(ts);
   28.59 +
   28.60 +    cout << "key renewed.\n";
   28.61 +
   28.62 +    cout << "key will be revoked\n";
   28.63 +    PEP_STATUS status3 = revoke_key(session, key.c_str(), "revoke test");
   28.64 +    cout << "revoke_key() exited with " << status3 << "\n";
   28.65 +    TEST_ASSERT(status3 == PEP_STATUS_OK);
   28.66 +    
   28.67 +    cout << "key revoked.\n";
   28.68 +
   28.69 +    cout << "deleting key pair " << key.c_str() << "\n";
   28.70 +    PEP_STATUS delete_status = delete_keypair(session, key.c_str());
   28.71 +    cout << "delete_keypair() exits with " << delete_status << "\n";
   28.72 +    TEST_ASSERT(delete_status == PEP_STATUS_OK);
   28.73 +}
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/test/src/engine_tests/LeastColorGroupTests.cc	Tue May 08 15:43:07 2018 +0200
    29.3 @@ -0,0 +1,100 @@
    29.4 +// This file is under GNU General Public License 3.0
    29.5 +// see LICENSE.txt
    29.6 +
    29.7 +#include <stdlib.h>
    29.8 +#include <string>
    29.9 +#include <iostream>
   29.10 +#include <vector>
   29.11 +#include <cstring> // for strcmp()
   29.12 +#include "keymanagement.h"
   29.13 +#include "message_api.h"
   29.14 +#include "mime.h"
   29.15 +#include "test_util.h"
   29.16 +
   29.17 +#include "pEpEngine.h"
   29.18 +
   29.19 +#include <cpptest.h>
   29.20 +#include "EngineTestSessionSuite.h"
   29.21 +#include "LeastColorGroupTests.h"
   29.22 +
   29.23 +using namespace std;
   29.24 +
   29.25 +LeastColorGroupTests::LeastColorGroupTests(string suitename, string test_home_dir) :
   29.26 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   29.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("LeastColorGroupTests::check_least_color_group"),
   29.28 +                                                                      static_cast<Func>(&LeastColorGroupTests::check_least_color_group)));
   29.29 +}
   29.30 +
   29.31 +void LeastColorGroupTests::check_least_color_group() {
   29.32 +    
   29.33 +    const char* mailfile = "test_mails/color_test.eml";
   29.34 +    
   29.35 +    const std::vector<const char*> keynames = {
   29.36 +                              "test_keys/priv/pep.color.test.P-0x3EBE215C_priv.asc",
   29.37 +                              "test_keys/pub/pep.color.test.H-0xD17E598E_pub.asc",
   29.38 +                              "test_keys/pub/pep.color.test.L-0xE9CDB4CE_pub.asc",
   29.39 +                              "test_keys/pub/pep.color.test.P-0x3EBE215C_pub.asc",
   29.40 +                              "test_keys/pub/pep.color.test.V-0x71FC6D28_pub.asc"
   29.41 +                          };
   29.42 +            
   29.43 +    for (auto name : keynames) {
   29.44 +        cout << "\t read keyfile \"" << name << "\"..." << std::endl;
   29.45 +        const string keytextkey = slurp(name);
   29.46 +        PEP_STATUS statuskey = import_key(session, keytextkey.c_str(), keytextkey.length(), NULL);
   29.47 +        TEST_ASSERT(statuskey == PEP_STATUS_OK);
   29.48 +    }
   29.49 +    
   29.50 +    cout << "\t read keyfile mailfile \"" << mailfile << "\"..." << std::endl;
   29.51 +    const string mailtext = slurp(mailfile);
   29.52 +    cout << "\t All files read successfully." << std::endl;
   29.53 +
   29.54 +    pEp_identity * me1 = new_identity("pep.color.test.P@kgrothoff.org", 
   29.55 +                                      "7EE6C60C68851954E1797F81EA59715E3EBE215C", 
   29.56 +                                      PEP_OWN_USERID, "Pep Color Test P (recip)");
   29.57 +    me1->me = true;
   29.58 +    PEP_STATUS status = myself(session, me1);
   29.59 +    
   29.60 +    pEp_identity * sender1 = new_identity("pep.color.test.V@kgrothoff.org",
   29.61 +                                          NULL, "TOFU_pep.color.test.V@kgrothoff.org",
   29.62 +                                          "Pep Color Test V (sender)");
   29.63 +    
   29.64 +    status = update_identity(session, sender1);
   29.65 +    trust_personal_key(session, sender1);
   29.66 +    status = update_identity(session, sender1);
   29.67 +    
   29.68 +    message* msg_ptr = nullptr;
   29.69 +    message* dest_msg = nullptr;
   29.70 +    message* final_ptr = nullptr;
   29.71 +    stringlist_t* keylist = nullptr;
   29.72 +    PEP_rating rating;
   29.73 +    PEP_decrypt_flags_t flags;
   29.74 +    
   29.75 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
   29.76 +    TEST_ASSERT(status == PEP_STATUS_OK);
   29.77 +    TEST_ASSERT(msg_ptr);
   29.78 +    final_ptr = msg_ptr;
   29.79 +    flags = 0;
   29.80 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   29.81 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
   29.82 +  
   29.83 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
   29.84 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
   29.85 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
   29.86 +    cout << "rating: " << rating << endl << endl;
   29.87 +    cout << "keys used: " << endl;
   29.88 +    
   29.89 +    int i = 0;
   29.90 +    for (stringlist_t* k = keylist; k; k = k->next) {
   29.91 +        if (i == 0)
   29.92 +            cout << "\t Signer (key 0):\t" << k->value << endl;
   29.93 +        else
   29.94 +            cout << "\t #" << i << ":\t" << k->value << endl;
   29.95 +        i++;
   29.96 +    }
   29.97 +    
   29.98 +//    free_identity(me1);
   29.99 +    if (final_ptr == dest_msg)
  29.100 +    	free_message(dest_msg);
  29.101 +    free_message(msg_ptr);
  29.102 +    free_stringlist(keylist);    
  29.103 +}
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/test/src/engine_tests/LeastCommonDenomColorTests.cc	Tue May 08 15:43:07 2018 +0200
    30.3 @@ -0,0 +1,141 @@
    30.4 +// This file is under GNU General Public License 3.0
    30.5 +// see LICENSE.txt
    30.6 +
    30.7 +#include <stdlib.h>
    30.8 +#include <iostream>
    30.9 +#include <fstream>
   30.10 +#include <string>
   30.11 +#include <cstring> // for strcmp()
   30.12 +
   30.13 +#include "pEpEngine.h"
   30.14 +#include "keymanagement.h"
   30.15 +#include "message_api.h"
   30.16 +#include "mime.h"
   30.17 +#include "test_util.h"
   30.18 +
   30.19 +#include <cpptest.h>
   30.20 +#include "EngineTestSessionSuite.h"
   30.21 +#include "LeastCommonDenomColorTests.h"
   30.22 +
   30.23 +using namespace std;
   30.24 +
   30.25 +LeastCommonDenomColorTests::LeastCommonDenomColorTests(string suitename, string test_home_dir) :
   30.26 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   30.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("LeastCommonDenomColorTests::check_least_common_denom_color"),
   30.28 +                                                                      static_cast<Func>(&LeastCommonDenomColorTests::check_least_common_denom_color)));
   30.29 +}
   30.30 +
   30.31 +void LeastCommonDenomColorTests::check_least_common_denom_color() {
   30.32 +        
   30.33 +    const char* mailfile = "test_mails/Test_Message_JSON-21_Color_Problems.eml";
   30.34 +            
   30.35 +    // import keys
   30.36 +    const string keytextkey1 = slurp("test_keys/pub/banmeonce-0x07B29090_pub.asc");
   30.37 +    const string keytextkey2 = slurp("test_keys/pub/banmetwice-0x4080C3E7_pub.asc");
   30.38 +    const string keytextkey3 = slurp("test_keys/pub/pep.never.me.test-0x79C11D1D_pub.asc");
   30.39 +    const string keytextkey4 = slurp("test_keys/priv/pep.never.me.test-0x79C11D1D_priv.asc");
   30.40 +
   30.41 +    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
   30.42 +    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
   30.43 +    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
   30.44 +    PEP_STATUS statuskey4 = import_key(session, keytextkey4.c_str(), keytextkey4.length(), NULL);
   30.45 +
   30.46 +    pEp_identity * sender = new_identity("pep.never.me.test@kgrothoff.org", NULL, "TOFU_pep.never.me.test@kgrothoff.org", "pEp Never Me Test");    
   30.47 +    sender->me = false;    
   30.48 +    PEP_STATUS status = update_identity(session, sender);
   30.49 +        
   30.50 +    // reset the trust on both keys before we start
   30.51 +    pEp_identity * recip1 = new_identity("banmeonce@kgrothoff.org", NULL, "TOFU_banmeonce@kgrothoff.org", "Ban Me Once");    
   30.52 +    recip1->me = false;    
   30.53 +    status = update_identity(session, recip1);
   30.54 +    key_reset_trust(session, recip1);
   30.55 +    
   30.56 +    pEp_identity * recip2 = new_identity("banmetwice@kgrothoff.org", NULL, "TOFU_banmetwice@kgrothoff.org", "Ban Me Twice");    
   30.57 +    recip2->me = false;    
   30.58 +    status = update_identity(session, recip2);
   30.59 +    key_reset_trust(session, recip2);
   30.60 +        
   30.61 +    const string mailtext = slurp(mailfile);
   30.62 +
   30.63 +    // trust_personal_key(session, you);
   30.64 +    // 
   30.65 +    // status = update_identity(session, you);
   30.66 +    
   30.67 +    message* msg_ptr = nullptr;
   30.68 +    message* dest_msg = nullptr;
   30.69 +    stringlist_t* keylist = nullptr;
   30.70 +    PEP_rating rating;
   30.71 +    PEP_decrypt_flags_t flags;
   30.72 +    
   30.73 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
   30.74 +    TEST_ASSERT(status == PEP_STATUS_OK);
   30.75 +    TEST_ASSERT(msg_ptr);
   30.76 +
   30.77 +    flags = 0;
   30.78 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   30.79 +    TEST_ASSERT(status == PEP_STATUS_OK);
   30.80 +    TEST_ASSERT(dest_msg);
   30.81 +    /* message is signed and no recip is mistrusted... */
   30.82 +    TEST_ASSERT(color_from_rating(rating) == PEP_color_yellow);
   30.83 +
   30.84 +    cout << "shortmsg: " << dest_msg->shortmsg << endl << endl;
   30.85 +    cout << "longmsg: " << dest_msg->longmsg << endl << endl;
   30.86 +    cout << "longmsg_formatted: " << (dest_msg->longmsg_formatted ? dest_msg->longmsg_formatted : "(empty)") << endl << endl;
   30.87 +
   30.88 +    PEP_rating decrypt_rating = rating;
   30.89 +    
   30.90 +    /* re-evaluate rating, counting on optional fields */
   30.91 +    status = re_evaluate_message_rating(session, dest_msg, NULL, PEP_rating_undefined, &rating);
   30.92 +    TEST_ASSERT(status == PEP_STATUS_OK);
   30.93 +    TEST_ASSERT(color_from_rating(rating) == PEP_color_yellow);
   30.94 +
   30.95 +    /* re-evaluate rating, without optional fields */
   30.96 +    status = re_evaluate_message_rating(session, dest_msg, keylist, decrypt_rating, &rating);
   30.97 +    TEST_ASSERT(status == PEP_STATUS_OK);
   30.98 +    TEST_ASSERT(color_from_rating(rating) == PEP_color_yellow);
   30.99 +
  30.100 +    /* Ok, now mistrust one recip */
  30.101 +    key_mistrusted(session, recip2);
  30.102 +
  30.103 +    /* re-evaluate rating, counting on optional fields */
  30.104 +    status = re_evaluate_message_rating(session, dest_msg, NULL, PEP_rating_undefined, &rating);
  30.105 +    TEST_ASSERT(status == PEP_STATUS_OK);
  30.106 +    TEST_ASSERT(color_from_rating(rating) == PEP_color_red);
  30.107 +
  30.108 +    /* re-evaluate rating, without optional fields */
  30.109 +    status = re_evaluate_message_rating(session, dest_msg, keylist, decrypt_rating, &rating);
  30.110 +    TEST_ASSERT(status == PEP_STATUS_OK);
  30.111 +    TEST_ASSERT(color_from_rating(rating) == PEP_color_red);
  30.112 +
  30.113 +    free_message(dest_msg);
  30.114 +    free_message(msg_ptr);
  30.115 +    free_stringlist(keylist);
  30.116 +    
  30.117 +    msg_ptr = nullptr;
  30.118 +    dest_msg = nullptr;
  30.119 +    keylist = nullptr;
  30.120 +    rating = PEP_rating_unreliable;
  30.121 +
  30.122 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  30.123 +    TEST_ASSERT(status == PEP_STATUS_OK);
  30.124 +    TEST_ASSERT(msg_ptr);
  30.125 +    flags = 0;
  30.126 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  30.127 +  
  30.128 +    cout << "shortmsg: " << dest_msg->shortmsg << endl << endl;
  30.129 +    cout << "longmsg: " << dest_msg->longmsg << endl << endl;
  30.130 +    cout << "longmsg_formatted: " << (dest_msg->longmsg_formatted ? dest_msg->longmsg_formatted : "(empty)") << endl << endl;
  30.131 +
  30.132 +    /* message is signed and no recip is mistrusted... */
  30.133 +    TEST_ASSERT(color_from_rating(rating) == PEP_color_red);
  30.134 +
  30.135 +    free_message(dest_msg);
  30.136 +    free_message(msg_ptr);
  30.137 +    free_stringlist(keylist);
  30.138 +
  30.139 +    msg_ptr = nullptr;
  30.140 +    dest_msg = nullptr;
  30.141 +    keylist = nullptr;
  30.142 +    rating = PEP_rating_unreliable;
  30.143 +    
  30.144 +}
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/test/src/engine_tests/MapAsn1Tests.cc	Tue May 08 15:43:07 2018 +0200
    31.3 @@ -0,0 +1,57 @@
    31.4 +// This file is under GNU General Public License 3.0
    31.5 +// see LICENSE.txt
    31.6 +
    31.7 +#include <stdlib.h>
    31.8 +#include <iostream>
    31.9 +#include <string>
   31.10 +#include <cstring>
   31.11 +
   31.12 +#include "pEpEngine.h"
   31.13 +#include "map_asn1.h"
   31.14 +
   31.15 +#include <cpptest.h>
   31.16 +#include "EngineTestSessionSuite.h"
   31.17 +#include "MapAsn1Tests.h"
   31.18 +
   31.19 +using namespace std;
   31.20 +
   31.21 +MapAsn1Tests::MapAsn1Tests(string suitename, string test_home_dir) :
   31.22 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   31.23 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("MapAsn1Tests::check_map_asn1"),
   31.24 +                                                                      static_cast<Func>(&MapAsn1Tests::check_map_asn1)));
   31.25 +}
   31.26 +
   31.27 +void MapAsn1Tests::check_map_asn1() {
   31.28 +
   31.29 +    cout << "creating new identity...\n";
   31.30 +
   31.31 +    pEp_identity *ident1 = new_identity("vb@dingens.org",
   31.32 +            "DB4713183660A12ABAFA7714EBE90D44146F62F4", "42", "Volker Birk");
   31.33 +    assert(ident1);
   31.34 +    ident1->lang[0] = 'd';
   31.35 +    ident1->lang[1] = 'e';
   31.36 +    ident1->comm_type = PEP_ct_pEp;
   31.37 +
   31.38 +    cout << "converting identity to ASN.1...\n";
   31.39 +
   31.40 +    Identity_t *ident_asn1 = Identity_from_Struct(ident1, NULL);
   31.41 +    assert(ident_asn1);
   31.42 +
   31.43 +    cout << "converting identity from ASN.1...\n";
   31.44 +
   31.45 +    pEp_identity *ident2 = Identity_to_Struct(ident_asn1, NULL);
   31.46 +    assert(ident2);
   31.47 +
   31.48 +    assert(strcmp(ident1->address, ident2->address) == 0);
   31.49 +    assert(strcmp(ident1->fpr, ident2->fpr) == 0);
   31.50 +    assert(strcmp(ident1->user_id, ident2->user_id) == 0);
   31.51 +    assert(strcmp(ident1->username, ident2->username) == 0);
   31.52 +    assert(ident2->comm_type == PEP_ct_pEp);
   31.53 +    assert(strcmp(ident2->lang, "de") == 0);
   31.54 +
   31.55 +    cout << "freeing identities...\n";
   31.56 +
   31.57 +    asn_DEF_Identity.free_struct(&asn_DEF_Identity, ident_asn1, 0);
   31.58 +    free_identity(ident1);
   31.59 +    free_identity(ident2);
   31.60 +}
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/test/src/engine_tests/MessageApiTests.cc	Tue May 08 15:43:07 2018 +0200
    32.3 @@ -0,0 +1,225 @@
    32.4 +// This file is under GNU General Public License 3.0
    32.5 +// see LICENSE.txt
    32.6 +
    32.7 +#include <stdlib.h>
    32.8 +#include <string>
    32.9 +#include <cstring>
   32.10 +#include <iostream>
   32.11 +#include <fstream>
   32.12 +
   32.13 +#include "pEpEngine.h"
   32.14 +#include "platform.h"
   32.15 +#include "mime.h"
   32.16 +#include "message_api.h"
   32.17 +#include "test_util.h"
   32.18 +
   32.19 +#include <cpptest.h>
   32.20 +#include "EngineTestSessionSuite.h"
   32.21 +#include "MessageApiTests.h"
   32.22 +
   32.23 +using namespace std;
   32.24 +
   32.25 +MessageApiTests::MessageApiTests(string suitename, string test_home_dir) :
   32.26 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   32.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("MessageApiTests::check_message_api"),
   32.28 +                                                                      static_cast<Func>(&MessageApiTests::check_message_api)));
   32.29 +}
   32.30 +
   32.31 +void MessageApiTests::check_message_api() {
   32.32 +
   32.33 +    cout << "Importing Alice's key " << endl;
   32.34 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   32.35 +    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   32.36 +    const string bob_pub_key = slurp("test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
   32.37 +
   32.38 +    PEP_STATUS status0 = import_key(session, alice_pub_key.c_str(), alice_pub_key.size(), NULL);
   32.39 +    TEST_ASSERT(status0 == PEP_STATUS_OK);
   32.40 +    status0 = import_key(session, alice_priv_key.c_str(), alice_priv_key.size(), NULL);
   32.41 +    TEST_ASSERT(status0 == PEP_STATUS_OK);
   32.42 +    status0 = import_key(session, bob_pub_key.c_str(), bob_pub_key.size(), NULL);
   32.43 +    TEST_ASSERT(status0 == PEP_STATUS_OK);
   32.44 +    // message_api test code
   32.45 +
   32.46 +    cout << "creating message…\n";
   32.47 +    pEp_identity * me2 = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
   32.48 +    // pEp_identity * me2 = new_identity("test@nokey.plop", NULL, PEP_OWN_USERID, "Test no key");
   32.49 +    me2->me = true;
   32.50 +    identity_list *to2 = new_identity_list(new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test"));
   32.51 +    // identity_list *to2 = new_identity_list(new_identity("still@nokey.blup", NULL, "42", "Still no key"));
   32.52 +    message *msg2 = new_message(PEP_dir_outgoing);
   32.53 +    TEST_ASSERT(msg2);
   32.54 +    msg2->from = me2;
   32.55 +    msg2->to = to2;
   32.56 +    msg2->shortmsg = strdup("hello, world");
   32.57 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   32.58 +    cout << "message created.\n";
   32.59 +
   32.60 +    char *text2 = nullptr;
   32.61 +    PEP_STATUS status2 = mime_encode_message(msg2, false, &text2);
   32.62 +    TEST_ASSERT(status2 == PEP_STATUS_OK);
   32.63 +    TEST_ASSERT(text2);
   32.64 +
   32.65 +    cout << "decrypted:\n\n";
   32.66 +    cout << text2 << "\n";
   32.67 +
   32.68 +    free(text2);
   32.69 +
   32.70 +    cout << "encrypting message as MIME multipart…\n";
   32.71 +    message *enc_msg2 = nullptr;
   32.72 +    cout << "calling encrypt_message()\n";
   32.73 +    status2 = encrypt_message(session, msg2, NULL, &enc_msg2, PEP_enc_PGP_MIME, 0);
   32.74 +    cout << "encrypt_message() returns " << status2 << '.' << endl;
   32.75 +    TEST_ASSERT(status2 == PEP_STATUS_OK);
   32.76 +    TEST_ASSERT(enc_msg2);
   32.77 +    cout << "message encrypted.\n";
   32.78 +    
   32.79 +    status2 = mime_encode_message(enc_msg2, false, &text2);
   32.80 +    TEST_ASSERT(status2 == PEP_STATUS_OK);
   32.81 +    TEST_ASSERT(text2);
   32.82 +
   32.83 +    cout << "encrypted:\n\n";
   32.84 +    cout << text2 << "\n";
   32.85 +
   32.86 +    message *msg3 = nullptr;
   32.87 +    PEP_STATUS status3 = mime_decode_message(text2, strlen(text2), &msg3);
   32.88 +    TEST_ASSERT(status3 == PEP_STATUS_OK);
   32.89 +    const string string3 = text2;
   32.90 +    //free(text2);
   32.91 +
   32.92 +    unlink("msg4.asc");
   32.93 +    ofstream outFile3("msg4.asc");
   32.94 +    outFile3.write(string3.c_str(), string3.size());
   32.95 +    outFile3.close();
   32.96 +
   32.97 +    message *msg4 = nullptr;
   32.98 +    stringlist_t *keylist4 = nullptr;
   32.99 +    PEP_rating rating;
  32.100 +    PEP_decrypt_flags_t flags;
  32.101 +    
  32.102 +    flags = 0;
  32.103 +    PEP_STATUS status4 = decrypt_message(session, enc_msg2, &msg4, &keylist4, &rating, &flags);
  32.104 +    TEST_ASSERT(status4 == PEP_STATUS_OK);
  32.105 +    TEST_ASSERT(msg4);
  32.106 +    TEST_ASSERT(keylist4);
  32.107 +    TEST_ASSERT(rating);
  32.108 +    PEP_comm_type ct = enc_msg2->from->comm_type;
  32.109 +    TEST_ASSERT(ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed );
  32.110 +
  32.111 +    free_stringpair_list(enc_msg2->opt_fields);
  32.112 +    enc_msg2->opt_fields = NULL;
  32.113 +
  32.114 +    cout << "keys used:";
  32.115 +
  32.116 +    for (stringlist_t* kl4 = keylist4; kl4 && kl4->value; kl4 = kl4->next)
  32.117 +    {
  32.118 +        cout << " " << kl4->value;
  32.119 +    }
  32.120 +    cout << "\n\n";
  32.121 +
  32.122 +    free_stringlist(keylist4);
  32.123 +
  32.124 +    cout << "opening msg_no_key.asc for reading\n";
  32.125 +    ifstream inFile3 ("msg_no_key.asc");
  32.126 +    TEST_ASSERT(inFile3.is_open());
  32.127 +
  32.128 +    string text3;
  32.129 +
  32.130 +    cout << "reading msg_no_key.asc sample\n";
  32.131 +    while (!inFile3.eof()) {
  32.132 +        static string line;
  32.133 +        getline(inFile3, line);
  32.134 +        text3 += line + "\r\n";
  32.135 +    }
  32.136 +    inFile3.close();
  32.137 +
  32.138 +    message *msg5 = nullptr;
  32.139 +    PEP_STATUS status5 = mime_decode_message(text3.c_str(), text3.length(), &msg5);
  32.140 +    TEST_ASSERT(status5 == PEP_STATUS_OK);
  32.141 +
  32.142 +    message *msg6 = nullptr;
  32.143 +    stringlist_t *keylist5 = nullptr;
  32.144 +    PEP_rating rating2;
  32.145 +    PEP_decrypt_flags_t flags2;
  32.146 +    flags2 = 0;
  32.147 +    PEP_STATUS status6 = decrypt_message(session, msg5, &msg6, &keylist5, &rating2, &flags2);
  32.148 +    TEST_ASSERT(status6 == PEP_DECRYPT_NO_KEY);
  32.149 +    TEST_ASSERT(msg6 == NULL);
  32.150 +    TEST_ASSERT(keylist5 == NULL);
  32.151 +    TEST_ASSERT(rating2 == PEP_rating_have_no_key);
  32.152 +    cout << "rating :" << rating2 << "\n";
  32.153 +    free_stringlist(keylist5);
  32.154 +
  32.155 +    cout << "\nTesting MIME_encrypt_message / MIME_decrypt_message...\n\n";
  32.156 +
  32.157 +    cout << "opening alice_bob_encrypt_test_plaintext_mime.eml for reading\n";
  32.158 +    ifstream inFile4 ("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
  32.159 +    TEST_ASSERT(inFile4.is_open());
  32.160 +    
  32.161 +    string text4;
  32.162 +    
  32.163 +    cout << "reading alice_bob_encrypt_test_plaintext_mime.eml sample\n";
  32.164 +    while (!inFile4.eof()) {
  32.165 +        static string line;
  32.166 +        getline(inFile4, line);
  32.167 +        text4 += line + "\r\n";
  32.168 +    }
  32.169 +    inFile4.close();
  32.170 +    
  32.171 +    const char* out_msg_plain = text4.c_str();
  32.172 +    
  32.173 +//    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";
  32.174 +    char* enc_msg = NULL;
  32.175 +    char* dec_msg = NULL;
  32.176 +
  32.177 +    PEP_STATUS status7 = MIME_encrypt_message(session, text4.c_str(), text4.length(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  32.178 +//    PEP_STATUS status7 = MIME_encrypt_message(session, out_msg_plain, strlen(out_msg_plain), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  32.179 +    TEST_ASSERT(status7 == PEP_STATUS_OK);
  32.180 +    
  32.181 +    cout << enc_msg << endl;
  32.182 +
  32.183 +    string text5 = enc_msg;
  32.184 +    
  32.185 +    PEP_decrypt_flags_t dec_flags;
  32.186 +    stringlist_t* keys_used;
  32.187 +    
  32.188 +    dec_flags = 0;
  32.189 +    char* modified_src = NULL;
  32.190 +    PEP_STATUS status8 = MIME_decrypt_message(session, text5.c_str(), text5.length(), &dec_msg, &keys_used, &rating, &dec_flags, &modified_src);
  32.191 +    TEST_ASSERT(status8 == PEP_STATUS_OK);
  32.192 +    
  32.193 +    cout << dec_msg << endl;
  32.194 +    
  32.195 +    cout << "\nTesting encrypt_message() with enc_format = PEP_enc_none\n\n";
  32.196 +
  32.197 +    message *msg7 = new_message(PEP_dir_outgoing);
  32.198 +    pEp_identity * me7 = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
  32.199 +    identity_list *to7 = new_identity_list(new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test"));
  32.200 +    msg7->from = me7;
  32.201 +    msg7->to = to7;
  32.202 +    msg7->shortmsg = strdup("My Subject");
  32.203 +    msg7->longmsg = strdup("This is some text.\n");
  32.204 +
  32.205 +    message *enc7 = nullptr;
  32.206 +    PEP_STATUS status9 = encrypt_message(session, msg7, NULL, &enc7, PEP_enc_none, 0);
  32.207 +	std::cout << "encrypt_message returned " << std::dec << status9 << std::hex << " (0x" << status9 << ")" << std::dec << endl;
  32.208 +    TEST_ASSERT(status9 == PEP_UNENCRYPTED);
  32.209 +    TEST_ASSERT(enc7 == nullptr);
  32.210 +    TEST_ASSERT(msg7->shortmsg && msg7->longmsg);
  32.211 +    cout << msg7->shortmsg << "\n";
  32.212 +    cout << msg7->longmsg << "\n";
  32.213 +    TEST_ASSERT(strcmp(msg7->shortmsg, "My Subject") == 0);
  32.214 +    TEST_ASSERT(strcmp(msg7->longmsg, "This is some text.\n") == 0);
  32.215 +    
  32.216 +    cout << "\nfreeing messages…\n";
  32.217 +    free_message(msg7);
  32.218 +    free_message(msg6);
  32.219 +    free_message(msg5);
  32.220 +    free_message(msg4);
  32.221 +    free_message(msg3);
  32.222 +    free_message(msg2);
  32.223 +    free_message(enc_msg2);
  32.224 +    cout << "done.\n";
  32.225 +
  32.226 +    free(enc_msg);
  32.227 +    free(dec_msg);
  32.228 +}
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/test/src/engine_tests/MessageTwoPointOhTests.cc	Tue May 08 15:43:07 2018 +0200
    33.3 @@ -0,0 +1,168 @@
    33.4 +// This file is under GNU General Public License 3.0
    33.5 +// see LICENSE.txt
    33.6 +
    33.7 +#include <stdlib.h>
    33.8 +#include <string>
    33.9 +#include <cstring>
   33.10 +#include <iostream>
   33.11 +#include <fstream>
   33.12 +
   33.13 +#include "pEpEngine.h"
   33.14 +#include "platform.h"
   33.15 +#include "mime.h"
   33.16 +#include "message_api.h"
   33.17 +#include "keymanagement.h"
   33.18 +#include "test_util.h"
   33.19 +
   33.20 +#include <cpptest.h>
   33.21 +#include "EngineTestSessionSuite.h"
   33.22 +#include "MessageTwoPointOhTests.h"
   33.23 +
   33.24 +using namespace std;
   33.25 +
   33.26 +MessageTwoPointOhTests::MessageTwoPointOhTests(string suitename, string test_home_dir) :
   33.27 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   33.28 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("MessageTwoPointOhTests::check_message_two_point_oh"),
   33.29 +                                                                      static_cast<Func>(&MessageTwoPointOhTests::check_message_two_point_oh)));
   33.30 +}
   33.31 +
   33.32 +void MessageTwoPointOhTests::check_message_two_point_oh() {
   33.33 +
   33.34 +    PEP_comm_type carol_comm_type = PEP_ct_OpenPGP_unconfirmed;
   33.35 +
   33.36 +    // message_api test code
   33.37 +
   33.38 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   33.39 +    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   33.40 +    const string carol_pub_key = slurp("test_keys/pub/pep-test-carol-0x42A85A42_pub.asc");
   33.41 +    const string carol_priv_key = slurp("test_keys/priv/pep-test-carol-0x42A85A42_priv.asc");
   33.42 +
   33.43 +    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   33.44 +    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
   33.45 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
   33.46 +    TEST_ASSERT(statuspriv == PEP_STATUS_OK);
   33.47 +    statuspub = import_key(session, carol_pub_key.c_str(), carol_pub_key.length(), NULL);
   33.48 +    statuspriv = import_key(session, carol_priv_key.c_str(), carol_priv_key.length(), NULL);
   33.49 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
   33.50 +    TEST_ASSERT(statuspriv == PEP_STATUS_OK);
   33.51 +
   33.52 +    cout << "creating message…\n";
   33.53 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", PEP_OWN_USERID, "Alice Test");
   33.54 +    pEp_identity* carol = new_identity("pep-test-carol@pep-project.org", NULL, "TOFU_pep-test-carol@pep-project.org", "Carol Test");
   33.55 +
   33.56 +    PEP_STATUS alice_status = update_identity(session, alice);
   33.57 +    PEP_STATUS carol_status = update_identity(session, carol);
   33.58 +
   33.59 +    PEP_STATUS status = update_trust_for_fpr(session, alice->fpr, PEP_ct_pEp);
   33.60 +    status = update_trust_for_fpr(session, carol->fpr, carol_comm_type);
   33.61 +    
   33.62 +    PEP_STATUS mystatus = myself(session, alice);
   33.63 +    TEST_ASSERT(mystatus == PEP_STATUS_OK);
   33.64 +    alice_status = update_identity(session, alice);
   33.65 +    alice_status = update_identity(session, carol);
   33.66 +    TEST_ASSERT(alice->comm_type == PEP_ct_pEp);
   33.67 +    TEST_ASSERT(carol->comm_type == carol_comm_type);
   33.68 +    
   33.69 +    identity_list* to_list = new_identity_list(carol); // to carol
   33.70 +    message* outgoing_message = new_message(PEP_dir_outgoing);
   33.71 +    TEST_ASSERT(outgoing_message);
   33.72 +    outgoing_message->from = alice;
   33.73 +    outgoing_message->to = to_list;
   33.74 +    outgoing_message->shortmsg = strdup("Greetings, humans!");
   33.75 +    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   33.76 +    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   33.77 +//    outgoing_message->id = strdup("blahblahyourmama@pep-project.org");
   33.78 +    outgoing_message->references = new_stringlist("one-839274982347239847@pep-project.org");
   33.79 +    stringlist_add(outgoing_message->references, "two-dfddffd839274982347239847@pep-project.org");
   33.80 +    stringlist_add(outgoing_message->references, "three-OMGWTFBBQ.edfddffd839274982347239847@pep-project.org");
   33.81 +    
   33.82 +    cout << "message created.\n";
   33.83 +
   33.84 +    char* encoded_text = nullptr;
   33.85 +    status = mime_encode_message(outgoing_message, false, &encoded_text);
   33.86 +    TEST_ASSERT(status == PEP_STATUS_OK);
   33.87 +    TEST_ASSERT(encoded_text);
   33.88 +
   33.89 +    cout << "unencrypted:\n\n";
   33.90 +    cout << encoded_text << "\n";
   33.91 +
   33.92 +    free(encoded_text);
   33.93 +
   33.94 +    cout << "encrypting message as MIME multipart…\n";
   33.95 +    message* encrypted_msg = nullptr;
   33.96 +    cout << "calling encrypt_message\n";
   33.97 +    status = encrypt_message(session, outgoing_message, NULL, 
   33.98 +        &encrypted_msg, PEP_enc_PGP_MIME, 0);
   33.99 +    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
  33.100 +    TEST_ASSERT(status == PEP_STATUS_OK);
  33.101 +    TEST_ASSERT(encrypted_msg);
  33.102 +    cout << "message encrypted.\n";
  33.103 +    
  33.104 +    encrypted_msg->enc_format = PEP_enc_none;
  33.105 +    status = mime_encode_message(encrypted_msg, false, &encoded_text);
  33.106 +    TEST_ASSERT(status == PEP_STATUS_OK);
  33.107 +    TEST_ASSERT(encoded_text);
  33.108 +     
  33.109 +    cout << "encrypted:\n\n";
  33.110 +    cout << encoded_text << "\n";
  33.111 +     
  33.112 +    char* decrypted_text;
  33.113 +    
  33.114 +    message* decrypted_msg = nullptr;
  33.115 +    stringlist_t* keylist_used = nullptr;
  33.116 +    
  33.117 +    PEP_rating rating;
  33.118 +    PEP_decrypt_flags_t flags;
  33.119 +     
  33.120 +//    MIME_decrypt_message(session, encoded_text, strlen(encoded_text), &decrypted_text, &keylist_used, &rating, &flags);
  33.121 +    
  33.122 +//    cout << "HEY!" << endl;
  33.123 +//    cout << decrypted_text << endl;
  33.124 +    
  33.125 +    message* decoded_msg = nullptr;
  33.126 +    status = mime_decode_message(encoded_text, strlen(encoded_text), &decoded_msg);
  33.127 +    TEST_ASSERT(status == PEP_STATUS_OK);
  33.128 +    const string string3 = encoded_text;
  33.129 +      
  33.130 +    unlink("msg_2.0.asc");
  33.131 +    ofstream outFile3("msg_2.0.asc");
  33.132 +    outFile3.write(string3.c_str(), string3.size());
  33.133 +    outFile3.close();
  33.134 +    
  33.135 +    // message* decrypted_msg = nullptr;
  33.136 +    // stringlist_t* keylist_used = nullptr;
  33.137 +    // 
  33.138 +    // PEP_rating rating;
  33.139 +    // PEP_decrypt_flags_t flags;
  33.140 +    // 
  33.141 +    stringpair_t* autoconsume = new_stringpair("pEp-auto-consume", "yes");
  33.142 +    stringpair_list_add(encrypted_msg->opt_fields, autoconsume);
  33.143 +    flags = 0;
  33.144 +    status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
  33.145 +    TEST_ASSERT(decrypted_msg);
  33.146 +    TEST_ASSERT(keylist_used);
  33.147 +    TEST_ASSERT(rating);
  33.148 +    //TEST_ASSERT(status == PEP_STATUS_OK && rating == PEP_rating_reliable);
  33.149 +    //PEP_comm_type ct = encrypted_msg->from->comm_type;
  33.150 +    //TEST_ASSERT(ct == PEP_ct_pEp);
  33.151 +    
  33.152 +    cout << "keys used:\n";
  33.153 +    
  33.154 +    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
  33.155 +    {
  33.156 +       cout << "\t " << kl4->value << endl;
  33.157 +    }
  33.158 +     
  33.159 +    decrypted_msg->enc_format = PEP_enc_none; 
  33.160 +    status = _mime_encode_message_internal(decrypted_msg, false, &encoded_text, false);
  33.161 +    TEST_ASSERT(status == PEP_STATUS_OK);
  33.162 +    TEST_ASSERT(encoded_text);
  33.163 +    cout << "Decrypted message: " << endl;
  33.164 +    cout << encoded_text << endl;
  33.165 +     
  33.166 +    cout << "freeing messages…\n";
  33.167 +    free_message(encrypted_msg);
  33.168 +    free_message(decrypted_msg);
  33.169 +    free_message(outgoing_message);
  33.170 +    cout << "done.\n";
  33.171 +}
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/test/src/engine_tests/MimeTests.cc	Tue May 08 15:43:07 2018 +0200
    34.3 @@ -0,0 +1,113 @@
    34.4 +// This file is under GNU General Public License 3.0
    34.5 +// see LICENSE.txt
    34.6 +
    34.7 +#include <stdlib.h>
    34.8 +#include <string>
    34.9 +#include <cstring>
   34.10 +#include <iostream>
   34.11 +#include <fstream>
   34.12 +#include <assert.h>
   34.13 +
   34.14 +#include "pEpEngine.h"
   34.15 +#include "platform.h"
   34.16 +#include "mime.h"
   34.17 +
   34.18 +#include <cpptest.h>
   34.19 +#include "EngineTestSessionSuite.h"
   34.20 +#include "MimeTests.h"
   34.21 +
   34.22 +using namespace std;
   34.23 +
   34.24 +MimeTests::MimeTests(string suitename, string test_home_dir) :
   34.25 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   34.26 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("MimeTests::check_mime"),
   34.27 +                                                                      static_cast<Func>(&MimeTests::check_mime)));
   34.28 +}
   34.29 +
   34.30 +// FIXME: refactor so we can assert
   34.31 +static void test_mime_decoding(string filename) {
   34.32 +    cout << "opening " << filename << " for reading\n";
   34.33 +    ifstream inFile3 (filename.c_str());
   34.34 +
   34.35 +    assert(inFile3.is_open());
   34.36 +
   34.37 +    string mimetext3;
   34.38 +
   34.39 +    cout << "reading mime sample\n";
   34.40 +    while (!inFile3.eof()) {
   34.41 +        static string line;
   34.42 +        getline(inFile3, line);
   34.43 +        mimetext3 += line + "\n";
   34.44 +    }
   34.45 +    inFile3.close();
   34.46 +
   34.47 +    cout << "decoding message…\n";
   34.48 +    message *msg3;
   34.49 +    PEP_STATUS status3 = mime_decode_message(mimetext3.c_str(), mimetext3.length(), &msg3);
   34.50 +    assert(status3 == PEP_STATUS_OK);
   34.51 +    assert(msg3);
   34.52 +    cout << "decoded.\n\n";
   34.53 +    cout << "Subject: " << msg3->shortmsg << "\n\n";
   34.54 +    if (msg3->longmsg)
   34.55 +        cout << msg3->longmsg << "\n\n";
   34.56 +    if (msg3->longmsg_formatted)
   34.57 +        cout << msg3->longmsg_formatted << "\n\n";
   34.58 +    bloblist_t *_b;
   34.59 +    for (_b = msg3->attachments; _b; _b = _b->next) {
   34.60 +        cout << "attachment of type " << _b->mime_type << "\n";
   34.61 +        if (_b->filename) {
   34.62 +            cout << "filename: " << _b->filename << "\n";
   34.63 +            unlink(_b->filename);
   34.64 +            ofstream outFile3(_b->filename);
   34.65 +            outFile3.write(_b->value, _b->size);
   34.66 +            outFile3.close();
   34.67 +        }
   34.68 +    }
   34.69 +
   34.70 +    free_message(msg3);
   34.71 +}
   34.72 +
   34.73 +void MimeTests::check_mime() {
   34.74 +
   34.75 +    cout << "\n*** mime_test ***\n\n";
   34.76 +
   34.77 +    PEP_SESSION session;
   34.78 +    
   34.79 +    cout << "calling init()\n";
   34.80 +    PEP_STATUS status1 = init(&session);   
   34.81 +    TEST_ASSERT(status1 == PEP_STATUS_OK);
   34.82 +    TEST_ASSERT(session);
   34.83 +    cout << "init() completed.\n";
   34.84 +
   34.85 +    // mime test code
   34.86 +
   34.87 +    // testing multipart/alternative
   34.88 +
   34.89 +    message *msg2 = new_message(PEP_dir_incoming);
   34.90 +    TEST_ASSERT(msg2);
   34.91 +    msg2->from = new_identity("vb@dingens.org", NULL, NULL, "Volker Birk");
   34.92 +    msg2->to = new_identity_list(new_identity("trischa@dingens.org", NULL, NULL, "Patricia Bädnar")),
   34.93 +    msg2->shortmsg = strdup("my sübject");
   34.94 +
   34.95 +    string text2 = "my mèssage to yoü";
   34.96 +    msg2->longmsg = strdup(text2.c_str());
   34.97 +    string html2 = "<html><body><p>my message to you</p></body></html>";
   34.98 +    msg2->longmsg_formatted = strdup(html2.c_str());
   34.99 +    TEST_ASSERT(msg2->longmsg_formatted);
  34.100 +
  34.101 +    cout << "encoding message…\n";
  34.102 +    char *result2;
  34.103 +    PEP_STATUS status2 = mime_encode_message(msg2, false, &result2);
  34.104 +    TEST_ASSERT(result2);
  34.105 +    TEST_ASSERT(status2 == PEP_STATUS_OK);
  34.106 +
  34.107 +    cout << "result:\n";
  34.108 +    cout << result2 << "\n";
  34.109 +
  34.110 +    free(result2);
  34.111 +    free_message(msg2);
  34.112 +
  34.113 +    test_mime_decoding("msg1.asc");
  34.114 +    test_mime_decoding("msg2.asc");
  34.115 +    test_mime_decoding("msg3.asc");
  34.116 +}
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/test/src/engine_tests/MistrustUndoTests.cc	Tue May 08 15:43:07 2018 +0200
    35.3 @@ -0,0 +1,84 @@
    35.4 +// This file is under GNU General Public License 3.0
    35.5 +// see LICENSE.txt
    35.6 +
    35.7 +#include <stdlib.h>
    35.8 +#include <string>
    35.9 +#include <cstring>
   35.10 +#include <time.h>
   35.11 +#include <iostream>
   35.12 +#include <fstream>
   35.13 +
   35.14 +#include "pEpEngine.h"
   35.15 +#include "platform.h"
   35.16 +#include "mime.h"
   35.17 +#include "message_api.h"
   35.18 +#include "test_util.h"
   35.19 +
   35.20 +#include <cpptest.h>
   35.21 +#include "EngineTestSessionSuite.h"
   35.22 +#include "MistrustUndoTests.h"
   35.23 +
   35.24 +using namespace std;
   35.25 +
   35.26 +MistrustUndoTests::MistrustUndoTests(string suitename, string test_home_dir) :
   35.27 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   35.28 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("MistrustUndoTests::check_mistrust_undo"),
   35.29 +                                                                      static_cast<Func>(&MistrustUndoTests::check_mistrust_undo)));
   35.30 +}
   35.31 +
   35.32 +void MistrustUndoTests::check_mistrust_undo() {
   35.33 +    PEP_STATUS status = PEP_STATUS_OK;
   35.34 +
   35.35 +    cout << "importing key 0x39E5DAB5." << endl;
   35.36 +    const string pub_key = slurp("test_keys/pub/mistrust.undo.test-0x39E5DAB5_pub.asc");
   35.37 +
   35.38 +    TEST_ASSERT(pub_key.length() != 0);
   35.39 +    
   35.40 +    PEP_STATUS statuspub = import_key(session, pub_key.c_str(), pub_key.length(), NULL);
   35.41 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
   35.42 +    cout << "Key imported." << endl << endl;
   35.43 +    
   35.44 +    cout << "Setting up identity for mistrust.undo.test@pep-project.org and making comm_type PEP_ct_pEp."  << endl;
   35.45 +    pEp_identity* recip1 = new_identity("mistrust.undo.test@pep-project.org", NULL, "TOFU_mistrust.undo.test@pep-project.org", "Mistrust Undo");
   35.46 +    status = update_identity(session,recip1);
   35.47 +    TEST_ASSERT(status == PEP_STATUS_OK);
   35.48 +    TEST_ASSERT(strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0);
   35.49 +    
   35.50 +    // First, we need the fpr to be in the DB system.
   35.51 +    status = set_identity(session,recip1);
   35.52 +    // Then we update the trust.
   35.53 +    // This is not an external function. We use it to expedite the test since we don't do a sync exchange here.
   35.54 +    status = update_trust_for_fpr(session, recip1->fpr, PEP_ct_pEp);
   35.55 +    // Then we retrieve the new trust.
   35.56 +    status = update_identity(session,recip1);
   35.57 +    TEST_ASSERT(status == PEP_STATUS_OK);
   35.58 +    TEST_ASSERT(recip1->comm_type == PEP_ct_pEp);
   35.59 +    TEST_ASSERT(strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0);
   35.60 +    cout << "mistrust.undo.test@pep-project.org set up and comm_type is PEP_ct_pEp."  << endl << endl;
   35.61 +
   35.62 +    // Ok, mistrust away
   35.63 +    cout << "Mistrusting mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5)."  << endl;   
   35.64 +    status = key_mistrusted(session, recip1);
   35.65 +    TEST_ASSERT(status == PEP_STATUS_OK);
   35.66 +    status = update_identity(session,recip1);
   35.67 +    TEST_ASSERT(status == PEP_STATUS_OK);
   35.68 +    TEST_ASSERT(recip1->comm_type == PEP_ct_key_not_found);
   35.69 +    recip1->fpr = strdup("BACC7A60A88A39A25D99B4A545D7542F39E5DAB5");
   35.70 +    status = get_trust(session, recip1);
   35.71 +    TEST_ASSERT(recip1->comm_type == PEP_ct_mistrusted);
   35.72 +     
   35.73 +    cout << "Mistrusted mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5) and comm_type IN DB set to PEP_ct_mistrusted)." << endl  << endl;    
   35.74 +    
   35.75 +    cout << "Undo mistrust (restore identity and trust in DB)" << endl;
   35.76 +    // Undo it
   35.77 +    status = undo_last_mistrust(session);
   35.78 +    TEST_ASSERT(status == PEP_STATUS_OK);
   35.79 +    status = update_identity(session, recip1);
   35.80 +    TEST_ASSERT(recip1->comm_type == PEP_ct_pEp);
   35.81 +    TEST_ASSERT(strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0);
   35.82 +    cout << "Undo mistrust (restore identity and trust in DB) - trust is now PEP_ct_pEp." << endl << endl;
   35.83 +
   35.84 +    cout << "Success!!!" << endl << endl;
   35.85 +    
   35.86 +    free_identity(recip1);
   35.87 +}
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/test/src/engine_tests/NewUpdateIdAndMyselfTests.cc	Tue May 08 15:43:07 2018 +0200
    36.3 @@ -0,0 +1,622 @@
    36.4 +// This file is under GNU General Public License 3.0
    36.5 +// see LICENSE.txt
    36.6 +
    36.7 +#include <stdlib.h>
    36.8 +#include <string>
    36.9 +#include <iostream>
   36.10 +#include <fstream>
   36.11 +#include <cstring> // for strcmp()
   36.12 +
   36.13 +#include "pEpEngine.h"
   36.14 +#include "message_api.h"
   36.15 +#include "keymanagement.h"
   36.16 +#include "test_util.h"
   36.17 +
   36.18 +#include <cpptest.h>
   36.19 +#include "EngineTestSessionSuite.h"
   36.20 +#include "NewUpdateIdAndMyselfTests.h"
   36.21 +
   36.22 +using namespace std;
   36.23 +
   36.24 +NewUpdateIdAndMyselfTests::NewUpdateIdAndMyselfTests(string suitename, string test_home_dir) :
   36.25 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   36.26 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NewUpdateIdAndMyselfTests::check_new_update_id_and_myself"),
   36.27 +                                                                      static_cast<Func>(&NewUpdateIdAndMyselfTests::check_new_update_id_and_myself)));
   36.28 +}
   36.29 +
   36.30 +void NewUpdateIdAndMyselfTests::check_new_update_id_and_myself() {
   36.31 +    
   36.32 +    PEP_STATUS status = PEP_STATUS_OK;
   36.33 +    
   36.34 +    cout << "***********************************************************************" << endl;
   36.35 +    cout << "* Section I. myself()" << endl;
   36.36 +    cout << "***********************************************************************" << endl << endl;
   36.37 +
   36.38 +    // Create id with no key
   36.39 +    cout << "Creating new own id with no key for : ";
   36.40 +    char *uniqname = strdup("AAAAtestuser@testdomain.org");
   36.41 +    srandom(time(NULL));
   36.42 +    for(int i=0; i < 4;i++)
   36.43 +        uniqname[i] += random() & 0xf;
   36.44 +    
   36.45 +    cout << uniqname << "\n";
   36.46 +    
   36.47 +    const char* own_user_id = get_new_uuid();
   36.48 +    const char* start_username = "Unser Testkandidat";
   36.49 +
   36.50 +    pEp_identity * new_me = new_identity(uniqname, NULL, own_user_id, start_username);
   36.51 +    
   36.52 +    cout << "***********************************************************************" << endl;
   36.53 +    cout << "* I: 1. myself() on id with no record in the DB and no input fpr" << endl;
   36.54 +    cout << "***********************************************************************" << endl << endl;
   36.55 +    status = myself(session, new_me);
   36.56 +    TEST_ASSERT(status == PEP_STATUS_OK);
   36.57 +    TEST_ASSERT(new_me->fpr);
   36.58 +    
   36.59 +    cout << "PASS: myself() generated fingerprint ";
   36.60 +    cout << new_me->fpr << endl << endl;
   36.61 +
   36.62 +    char* generated_fpr = strdup(new_me->fpr);
   36.63 +    
   36.64 +    TEST_ASSERT(new_me->comm_type == PEP_ct_pEp);
   36.65 +    
   36.66 +    free_identity(new_me);
   36.67 +
   36.68 +    cout << "***********************************************************************" << endl;
   36.69 +    cout << "* I: 2. myself() on id with no input fpr and a record in the DB" << endl;
   36.70 +    cout << "***********************************************************************" << endl << endl;
   36.71 +
   36.72 +    new_me = new_identity(uniqname, NULL, own_user_id, NULL);
   36.73 +    status = myself(session, new_me);
   36.74 +    TEST_ASSERT(status == PEP_STATUS_OK);
   36.75 +    
   36.76 +    TEST_ASSERT(new_me->fpr);
   36.77 +    TEST_ASSERT(strcmp(new_me->fpr, generated_fpr) == 0);
   36.78 +    TEST_ASSERT(new_me->username);
   36.79 +    TEST_ASSERT(strcmp(new_me->username, start_username) == 0);
   36.80 +    TEST_ASSERT(new_me->user_id);
   36.81 +    TEST_ASSERT(new_me->comm_type == PEP_ct_pEp);
   36.82 +    
   36.83 +    char* default_own_id = NULL;
   36.84 +    status = get_userid_alias_default(session, own_user_id, &default_own_id);
   36.85 +    if (status == PEP_CANNOT_FIND_ALIAS) {
   36.86 +        // Ok, we presume our own id above is the default (should be true if there was no existing DB as in test env)
   36.87 +        default_own_id = strdup(own_user_id);
   36.88 +    }
   36.89 +
   36.90 +    TEST_ASSERT(strcmp(new_me->user_id, default_own_id) == 0);
   36.91 +    
   36.92 +    cout << "PASS: myself() retrieved the correct fpr, username and default user id" << endl << endl;
   36.93 +
   36.94 +    free_identity(new_me);
   36.95 +     
   36.96 +    cout << "****************************************************************************************" << endl;
   36.97 +    cout << "* I: 3. myself() on id with no input fpr, a different user_id, and a record in the DB" << endl;
   36.98 +    cout << "****************************************************************************************" << endl << endl;
   36.99 +
  36.100 +    const char* alias_id = "Huss Es El Mejor Presidente Del Mundo!";
  36.101 +
  36.102 +    new_me = new_identity(uniqname, NULL, alias_id, NULL);
  36.103 +    status = myself(session, new_me);
  36.104 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.105 +    
  36.106 +    TEST_ASSERT(new_me->fpr);
  36.107 +    TEST_ASSERT(strcmp(new_me->fpr, generated_fpr) == 0);
  36.108 +    TEST_ASSERT(new_me->username);
  36.109 +    TEST_ASSERT(strcmp(new_me->username, start_username) == 0);
  36.110 +    TEST_ASSERT(new_me->user_id);
  36.111 +    TEST_ASSERT(strcmp(new_me->user_id, default_own_id) == 0);
  36.112 +    TEST_ASSERT(new_me->comm_type == PEP_ct_pEp);
  36.113 +    
  36.114 +    char* tmp_def = NULL;
  36.115 +    
  36.116 +    status = get_userid_alias_default(session, alias_id, &tmp_def);
  36.117 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.118 +    TEST_ASSERT(strcmp(tmp_def, default_own_id) == 0);
  36.119 +
  36.120 +    cout << "PASS: myself() retrieved the correct fpr, username and default user id, and put the right alias in for the default";
  36.121 +    cout << endl << endl;
  36.122 +    
  36.123 +    free(tmp_def);
  36.124 +    free_identity(new_me);
  36.125 +
  36.126 +    cout << "****************************************************************************************" << endl;
  36.127 +    cout << "* I: 4. myself(), replace fpr" << endl;
  36.128 +    cout << "****************************************************************************************" << endl << endl;
  36.129 +
  36.130 +    new_me = new_identity(uniqname, NULL, alias_id, start_username);
  36.131 +    status = generate_keypair(session, new_me);
  36.132 +    TEST_ASSERT(new_me->fpr);
  36.133 +    
  36.134 +    cout << "Generated fingerprint ";
  36.135 +    cout << new_me->fpr << "\n";
  36.136 +
  36.137 +    char* new_fpr = strdup(new_me->fpr);
  36.138 +
  36.139 +    status = set_own_key(session, new_me, new_fpr);
  36.140 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.141 +    TEST_ASSERT(new_me->fpr);
  36.142 +    TEST_ASSERT(strcmp(new_me->fpr, generated_fpr) != 0);
  36.143 +    TEST_ASSERT(strcmp(new_me->fpr, new_fpr) == 0);
  36.144 +    TEST_ASSERT(new_me->username);
  36.145 +    TEST_ASSERT(strcmp(new_me->username, start_username) == 0);
  36.146 +    TEST_ASSERT(new_me->user_id);
  36.147 +    TEST_ASSERT(strcmp(new_me->user_id, default_own_id) == 0);
  36.148 +    TEST_ASSERT(new_me->me);
  36.149 +    TEST_ASSERT(new_me->comm_type == PEP_ct_pEp);
  36.150 +
  36.151 +    cout << "PASS: myself() set and retrieved the new fpr, username and default user id, and put the right alias in for the default";
  36.152 +    cout << endl << endl;
  36.153 +
  36.154 +    // since that worked, we'll set it back as the default
  36.155 +    free(new_me->fpr);
  36.156 +    new_me->fpr = strdup(generated_fpr);
  36.157 +    new_me->comm_type = PEP_ct_unknown;
  36.158 +    status = set_own_key(session, new_me, generated_fpr);
  36.159 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.160 +    TEST_ASSERT(strcmp(new_me->fpr, generated_fpr) == 0);
  36.161 +    TEST_ASSERT(new_me->comm_type == PEP_ct_pEp);
  36.162 +    
  36.163 +    cout << "****************************************************************************************" << endl;
  36.164 +    cout << "* I: 5. myself(), replace fpr, revoke key" << endl;
  36.165 +    cout << "****************************************************************************************" << endl << endl;
  36.166 +
  36.167 +    status = revoke_key(session, generated_fpr, "Because it's fun");
  36.168 +    TEST_ASSERT (status == PEP_STATUS_OK);
  36.169 +    
  36.170 +    new_me = new_identity(uniqname, NULL, alias_id, start_username);
  36.171 +    
  36.172 +    status = set_own_key(session, new_me, new_fpr);
  36.173 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.174 +    TEST_ASSERT(new_me->fpr);
  36.175 +    TEST_ASSERT(strcmp(new_me->fpr, generated_fpr) != 0);
  36.176 +    TEST_ASSERT(new_me->username);
  36.177 +    TEST_ASSERT(strcmp(new_me->username, start_username) == 0);
  36.178 +    TEST_ASSERT(new_me->user_id);
  36.179 +    TEST_ASSERT(strcmp(new_me->user_id, default_own_id) == 0);
  36.180 +    TEST_ASSERT(new_me->me);
  36.181 +    TEST_ASSERT(new_me->comm_type == PEP_ct_pEp);
  36.182 +    
  36.183 +    cout << "PASS: myself() retrieved the new fpr, username and default user id, and put the right alias in for the default";
  36.184 +    cout << endl << endl;
  36.185 +        
  36.186 +    cout << "***********************************************************************" << endl;
  36.187 +    cout << "* Section II. update_identity()" << endl;
  36.188 +    cout << "***********************************************************************" << endl << endl;
  36.189 +
  36.190 +    cout << "****************************************************************************************" << endl;
  36.191 +    cout << "* II: 1. update_identity() - get identity with matching address and user_id and username" << endl;
  36.192 +    cout << "****************************************************************************************" << endl << endl;    
  36.193 +    // 1. create original identity
  36.194 +    const char* alex_address = "pep.test.alexander@peptest.ch";
  36.195 +    const char* alex_fpr = "3AD9F60FAEB22675DB873A1362D6981326B54E4E";
  36.196 +    const char* alex_userid = "Alex";
  36.197 +    const char* alex_username = "SuperDuperAlex";
  36.198 +    const string alex_pub_key = slurp("test_keys/pub/pep.test.alexander-0x26B54E4E_pub.asc");
  36.199 +    
  36.200 +    PEP_STATUS statuspub = import_key(session, alex_pub_key.c_str(), alex_pub_key.length(), NULL);
  36.201 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
  36.202 +
  36.203 +    pEp_identity* alex = new_identity(alex_address, alex_fpr, alex_userid, alex_username);
  36.204 +
  36.205 +    // 2. set identity
  36.206 +    status = set_identity(session, alex);
  36.207 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.208 +    free_identity(alex);
  36.209 +            
  36.210 +    alex = new_identity(alex_address, NULL, alex_userid, alex_username); 
  36.211 +    status = update_identity(session, alex);
  36.212 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.213 +    TEST_ASSERT(alex->fpr);
  36.214 +    TEST_ASSERT(strcmp(alex->fpr, alex_fpr) == 0);
  36.215 +    TEST_ASSERT(alex->username);
  36.216 +    TEST_ASSERT(strcmp(alex->username, alex_username) == 0);
  36.217 +    TEST_ASSERT(alex->user_id);
  36.218 +    TEST_ASSERT(strcmp(alex->user_id, alex_userid) == 0);
  36.219 +    TEST_ASSERT(!alex->me); 
  36.220 +    TEST_ASSERT(alex->comm_type == PEP_ct_OpenPGP_unconfirmed);
  36.221 +    TEST_ASSERT(strcmp(alex->address, alex_address) == 0);
  36.222 +
  36.223 +    cout << "PASS: update_identity() correctly retrieved extant record with matching address, id, and username" << endl << endl;
  36.224 +    free_identity(alex);
  36.225 +
  36.226 +    cout << "****************************************************************************************" << endl;
  36.227 +    cout << "* II: 2. update_identity() - get identity with matching address and user_id and new username" << endl;
  36.228 +    cout << "****************************************************************************************" << endl << endl;    
  36.229 +
  36.230 +    const char* new_username = "Test Patchy";
  36.231 +            
  36.232 +    alex = new_identity(alex_address, NULL, alex_userid, new_username);
  36.233 +    cout << "Timing is everything" << endl; 
  36.234 +    status = update_identity(session, alex);
  36.235 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.236 +    TEST_ASSERT(alex->fpr);
  36.237 +    TEST_ASSERT(strcmp(alex->fpr, alex_fpr) == 0);
  36.238 +    TEST_ASSERT(alex->username);
  36.239 +    TEST_ASSERT(strcmp(alex->username, new_username) == 0);
  36.240 +    TEST_ASSERT(alex->user_id);
  36.241 +    TEST_ASSERT(strcmp(alex->user_id, alex_userid) == 0);
  36.242 +    TEST_ASSERT(!alex->me); 
  36.243 +    TEST_ASSERT(alex->comm_type == PEP_ct_OpenPGP_unconfirmed);
  36.244 +    TEST_ASSERT(strcmp(alex->address, alex_address) == 0);
  36.245 +
  36.246 +    cout << "PASS: update_identity() correctly retrieved extant record with matching address and id, and patched username" << endl << endl;
  36.247 +    free_identity(alex);
  36.248 +
  36.249 +    cout << "****************************************************************************************" << endl;
  36.250 +    cout << "* II: 3. update_identity() - get identity with matching address and user_id only" << endl;
  36.251 +    cout << "****************************************************************************************" << endl << endl;    
  36.252 +        
  36.253 +    alex = new_identity(alex_address, NULL, alex_userid, NULL); 
  36.254 +    status = update_identity(session, alex);
  36.255 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.256 +    TEST_ASSERT(alex->fpr);
  36.257 +    TEST_ASSERT(strcmp(alex->fpr, alex_fpr) == 0);
  36.258 +    TEST_ASSERT(alex->username);
  36.259 +    TEST_ASSERT(strcmp(alex->username, new_username) == 0);
  36.260 +    TEST_ASSERT(alex->user_id);
  36.261 +    TEST_ASSERT(strcmp(alex->user_id, alex_userid) == 0);
  36.262 +    TEST_ASSERT(!alex->me); 
  36.263 +    TEST_ASSERT(alex->comm_type == PEP_ct_OpenPGP_unconfirmed);
  36.264 +    TEST_ASSERT(strcmp(alex->address, alex_address) == 0);
  36.265 +
  36.266 +    cout << "PASS: update_identity() correctly retrieved extant record with matching address and id, and patched username" << endl << endl;
  36.267 +    free_identity(alex);
  36.268 +
  36.269 +    cout << "****************************************************************************************" << endl;
  36.270 +    cout << "* II: 4. update_identity() - get identity with just address and username" << endl;
  36.271 +    cout << "****************************************************************************************" << endl << endl;    
  36.272 +
  36.273 +    alex = new_identity(alex_address, NULL, NULL, new_username); 
  36.274 +    status = update_identity(session, alex);
  36.275 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.276 +    TEST_ASSERT(alex->fpr);
  36.277 +    TEST_ASSERT(strcmp(alex->fpr, alex_fpr) == 0);
  36.278 +    TEST_ASSERT(alex->username);
  36.279 +    TEST_ASSERT(strcmp(alex->username, new_username) == 0);
  36.280 +    TEST_ASSERT(alex->user_id);
  36.281 +    TEST_ASSERT(strcmp(alex->user_id, alex_userid) == 0);
  36.282 +    TEST_ASSERT(!alex->me); 
  36.283 +    TEST_ASSERT(alex->comm_type == PEP_ct_OpenPGP_unconfirmed);
  36.284 +    TEST_ASSERT(strcmp(alex->address, alex_address) == 0);
  36.285 +
  36.286 +    cout << "PASS: update_identity() correctly retrieved extant record with matching address and username" << endl << endl;
  36.287 +    free_identity(alex);
  36.288 +
  36.289 +    cout << "****************************************************************************************" << endl;
  36.290 +    cout << "* II: 5. update_identity() with just address " << endl;
  36.291 +    cout << "****************************************************************************************" << endl << endl;
  36.292 +    
  36.293 +    alex = new_identity(alex_address, NULL, NULL, NULL); 
  36.294 +    status = update_identity(session, alex);
  36.295 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.296 +    TEST_ASSERT(alex->fpr);
  36.297 +    TEST_ASSERT(strcmp(alex->fpr, alex_fpr) == 0);
  36.298 +    TEST_ASSERT(alex->username);
  36.299 +    TEST_ASSERT(strcmp(alex->username, new_username) == 0);
  36.300 +    TEST_ASSERT(alex->user_id);
  36.301 +    TEST_ASSERT(strcmp(alex->user_id, alex_userid) == 0);
  36.302 +    TEST_ASSERT(!alex->me); 
  36.303 +    TEST_ASSERT(alex->comm_type == PEP_ct_OpenPGP_unconfirmed);
  36.304 +    TEST_ASSERT(strcmp(alex->address, alex_address) == 0);
  36.305 +
  36.306 +    cout << "PASS: update_identity() correctly retrieved extant record with just matching address. Retrieved previously patched username." << endl << endl;
  36.307 +    free_identity(alex);
  36.308 +
  36.309 +
  36.310 +    cout << "****************************************************************************************" << endl;
  36.311 +    cout << "* II: 6. update_identity() with just address on own identity (only case where this is legal)" << endl;
  36.312 +    cout << "****************************************************************************************" << endl << endl;
  36.313 +    
  36.314 +    pEp_identity* somebody = new_identity(uniqname, NULL, NULL, NULL); 
  36.315 +    status = update_identity(session, somebody);
  36.316 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.317 +    myself(session, somebody);
  36.318 +    TEST_ASSERT(somebody->fpr);
  36.319 +    TEST_ASSERT(strcmp(somebody->fpr, new_fpr) == 0);
  36.320 +    TEST_ASSERT(somebody->username);
  36.321 +    TEST_ASSERT(strcmp(somebody->username, start_username) == 0);
  36.322 +    TEST_ASSERT(somebody->user_id);
  36.323 +    TEST_ASSERT(strcmp(somebody->user_id, default_own_id) == 0);
  36.324 +    TEST_ASSERT(somebody->me); // true in this case, as it was an own identity
  36.325 +    TEST_ASSERT(somebody->comm_type == PEP_ct_pEp);
  36.326 +    TEST_ASSERT(strcmp(somebody->address, uniqname) == 0);
  36.327 +    
  36.328 +    cout << "PASS: update_identity() retrieved the right identity information given just an address";
  36.329 +    cout << endl << endl;
  36.330 +
  36.331 +    free_identity(somebody);
  36.332 +
  36.333 +    cout << "****************************************************************************************" << endl;
  36.334 +    cout << "* II: 7. update_identity() for address and user_id that don't exist" << endl;
  36.335 +    cout << "****************************************************************************************" << endl << endl;
  36.336 +
  36.337 +    somebody = new_identity("nope@nope.nope", NULL, "some_user_id", NULL); 
  36.338 +    status = update_identity(session, somebody);
  36.339 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.340 +    TEST_ASSERT(!somebody->fpr);
  36.341 +    TEST_ASSERT(somebody->comm_type == PEP_ct_key_not_found);
  36.342 +    
  36.343 +    cout << "PASS: update_identity() returns identity with no key and unknown comm type" << endl << endl;
  36.344 +
  36.345 +    free_identity(somebody);
  36.346 +    
  36.347 +    cout << "****************************************************************************************" << endl;
  36.348 +    cout << "* II: 8. update_identity() for address and and username, but non-matching temp user_id" << endl;
  36.349 +    cout << "****************************************************************************************" << endl << endl;
  36.350 +
  36.351 +    // 1. create identity
  36.352 +    const char* bella_address = "pep.test.bella@peptest.ch";
  36.353 +    const char* bella_fpr = "5631BF1357326A02AA470EEEB815EF7FA4516AAE";
  36.354 +    const char* bella_userid = "TOFU_pep.test.bella@peptest.ch"; // simulate temp ID
  36.355 +    const char* bella_username = "Annabella the Great";
  36.356 +    const string bella_pub_key = slurp("test_keys/pub/pep.test.bella-0xAF516AAE_pub.asc");
  36.357 +    
  36.358 +    statuspub = import_key(session, bella_pub_key.c_str(), bella_pub_key.length(), NULL);
  36.359 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
  36.360 +
  36.361 +    pEp_identity* bella = new_identity(bella_address, bella_fpr, bella_userid, bella_username);
  36.362 +    
  36.363 +    // 2. set identity
  36.364 +    status = set_identity(session, bella);
  36.365 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.366 +    free_identity(bella);
  36.367 +    
  36.368 +    const char* not_my_userid = "Bad Company";
  36.369 +            
  36.370 +    bella = new_identity(bella_address, NULL, not_my_userid, bella_username); 
  36.371 +    status = update_identity(session, bella);
  36.372 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.373 +    TEST_ASSERT(bella->fpr);
  36.374 +    TEST_ASSERT(strcmp(bella->fpr, bella_fpr) == 0);
  36.375 +    TEST_ASSERT(bella->username);
  36.376 +    TEST_ASSERT(strcmp(bella->username, bella_username) == 0);
  36.377 +    TEST_ASSERT(bella->user_id);
  36.378 +    TEST_ASSERT(strcmp(bella->user_id, not_my_userid) == 0); // ???
  36.379 +    TEST_ASSERT(!bella->me); 
  36.380 +    TEST_ASSERT(bella->comm_type == PEP_ct_OpenPGP_unconfirmed);
  36.381 +    TEST_ASSERT(strcmp(bella->address, bella_address) == 0);
  36.382 +
  36.383 +    cout << "PASS: update_identity() correctly retrieved extant record with matching address and username; temp user_id in DB patched" << endl << endl;
  36.384 +    free_identity(bella);
  36.385 +
  36.386 +    cout << "****************************************************************************************" << endl;
  36.387 +    cout << "* II: 9. update_identity() for address, username, and user_id, but no matching record" << endl;
  36.388 +    cout << "****************************************************************************************" << endl << endl;
  36.389 +    
  36.390 +    const char* rando_name = "Pickley BoofBoof";
  36.391 +    const char* rando_userid = "Boofy";
  36.392 +    const char* rando_address = "boof@pickles.org";
  36.393 +    somebody = new_identity(rando_address, NULL, rando_userid, rando_name);
  36.394 +    status = update_identity(session, somebody);
  36.395 +
  36.396 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.397 +    TEST_ASSERT(!somebody->fpr || somebody->fpr[0] == '\0');
  36.398 +    TEST_ASSERT(somebody->username);
  36.399 +    TEST_ASSERT(strcmp(somebody->username, rando_name) == 0);
  36.400 +    TEST_ASSERT(somebody->user_id);
  36.401 +    TEST_ASSERT(strcmp(somebody->user_id, rando_userid) == 0); // ???
  36.402 +    TEST_ASSERT(!somebody->me); 
  36.403 +    TEST_ASSERT(somebody->comm_type == PEP_ct_key_not_found);
  36.404 +    TEST_ASSERT(strcmp(somebody->address, rando_address) == 0);
  36.405 +
  36.406 +    cout << "PASS: update_identity() correctly created record with no key" << endl << endl;
  36.407 +    free_identity(somebody);
  36.408 +    
  36.409 +    cout << "****************************************************************************************" << endl;
  36.410 +    cout << "* II: 10. update_identity() for address, username, but no matching record" << endl;
  36.411 +    cout << "****************************************************************************************" << endl << endl;
  36.412 +
  36.413 +    const char* rando2_name = "Pickles BoofyBoof";
  36.414 +    const char* rando2_address = "boof2@pickles.org";
  36.415 +    somebody = new_identity(rando2_address, NULL, NULL, rando2_name);
  36.416 +    status = update_identity(session, somebody);
  36.417 +    const char* expected_rando2_userid = "TOFU_boof2@pickles.org";
  36.418 +
  36.419 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.420 +    TEST_ASSERT(!somebody->fpr || somebody->fpr[0] == '\0');
  36.421 +    TEST_ASSERT(somebody->username);
  36.422 +    TEST_ASSERT(strcmp(somebody->username, rando2_name) == 0);
  36.423 +    TEST_ASSERT(somebody->user_id);
  36.424 +    TEST_ASSERT(strcmp(somebody->user_id, expected_rando2_userid) == 0); // ???
  36.425 +    TEST_ASSERT(!somebody->me); 
  36.426 +    TEST_ASSERT(somebody->comm_type == PEP_ct_key_not_found);
  36.427 +    TEST_ASSERT(strcmp(somebody->address, rando2_address) == 0);
  36.428 +
  36.429 +    cout << "PASS: update_identity() correctly created record with no key" << endl << endl;
  36.430 +    free_identity(somebody);
  36.431 +
  36.432 +    cout << "****************************************************************************************" << endl;
  36.433 +    cout << "* II: 11. update_identity() for address only, but multiple matching records" << endl;
  36.434 +    cout << "****************************************************************************************" << endl << endl;
  36.435 +
  36.436 +    const char* bella_id_2 = "Bella2";
  36.437 +    bella = new_identity(bella_address, NULL, bella_id_2, bella_username);
  36.438 +    
  36.439 +    // 2. set identity
  36.440 +    status = set_identity(session, bella);
  36.441 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.442 +    free_identity(bella);
  36.443 +                
  36.444 +    bella = new_identity(bella_address, NULL, NULL, NULL); 
  36.445 +    status = update_identity(session, bella);
  36.446 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.447 +
  36.448 +//    cout << "PASS: update_identity() correctly failed with no matching records (too little info)" << endl << endl;
  36.449 +    
  36.450 +    cout << "****************************************************************************************" << endl;
  36.451 +    cout << "* III: key election " << endl;
  36.452 +    cout << "****************************************************************************************" << endl << endl;
  36.453 +
  36.454 +    cout << "****************************************************************************************" << endl;
  36.455 +    cout << "* III: 1. key election: get identity for user with expired key" << endl;
  36.456 +    cout << "****************************************************************************************" << endl << endl;
  36.457 +
  36.458 +    // 1. create identity
  36.459 +    const char* bernd_address = "bernd.das.brot@darthmama.org";
  36.460 +    const char* bernd_fpr = "F8CE0F7E24EB190A2FCBFD38D4B088A7CAFAA422";
  36.461 +    const char* bernd_userid = "BERND_ID"; // simulate temp ID
  36.462 +    const char* bernd_username = "Bernd das Brot der Ultimative Testkandidat";
  36.463 +    const string bernd_pub_key = slurp("test_keys/pub/bernd.das.brot-0xCAFAA422_pub.asc");
  36.464 +    
  36.465 +    statuspub = import_key(session, bernd_pub_key.c_str(), bernd_pub_key.length(), NULL);
  36.466 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
  36.467 +
  36.468 +    pEp_identity* bernd = new_identity(bernd_address, bernd_fpr, bernd_userid, bernd_username);
  36.469 +    
  36.470 +    // 2. set identity
  36.471 +    status = set_identity(session, bernd);
  36.472 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.473 +    free_identity(bernd);
  36.474 +                
  36.475 +    bernd = new_identity(bernd_address, NULL, bernd_userid, bernd_username); 
  36.476 +    status = update_identity(session, bernd);
  36.477 +    TEST_ASSERT(status != PEP_STATUS_OK);
  36.478 +    TEST_ASSERT(!bernd->fpr || bernd->fpr[0] == '\0');
  36.479 +    TEST_ASSERT(bernd->username);
  36.480 +    TEST_ASSERT(strcmp(bernd->username, bernd_username) == 0);
  36.481 +    TEST_ASSERT(bernd->user_id);
  36.482 +    TEST_ASSERT(strcmp(bernd->user_id, bernd_userid) == 0); // ???
  36.483 +    TEST_ASSERT(!bernd->me); 
  36.484 +    TEST_ASSERT(bernd->comm_type == PEP_ct_key_expired);
  36.485 +    TEST_ASSERT(strcmp(bernd->address, bernd_address) == 0);
  36.486 +
  36.487 +    cout << "PASS: update_identity() correctly rejected expired key with PEP_KEY_UNSUITABLE and PEP_ct_key_expired" << endl << endl;
  36.488 +    free_identity(bernd);
  36.489 +
  36.490 +
  36.491 +    cout << "****************************************************************************************" << endl;
  36.492 +    cout << "* III: 2. key election: get identity for user with only revoked or mistrusted keys " << endl;
  36.493 +    cout << "****************************************************************************************" << endl << endl;
  36.494 +
  36.495 +    // Create id with no key
  36.496 +    cout << "Creating new id with no key for : ";
  36.497 +    char *uniqname_10000 = strdup("AAAAtestuser@testdomain.org");
  36.498 +    srandom(time(NULL));
  36.499 +    for(int i=0; i < 4;i++)
  36.500 +        uniqname_10000[i] += random() & 0xf;
  36.501 +    
  36.502 +    cout << uniqname_10000 << "\n";
  36.503 +
  36.504 +    char* revoke_uuid = get_new_uuid();
  36.505 +
  36.506 +    pEp_identity * revokemaster_3000 = new_identity(uniqname_10000, NULL, revoke_uuid, start_username);
  36.507 +    
  36.508 +    cout << "Generate three keys for "  << uniqname_10000 << " who has user_id " << revoke_uuid << endl; 
  36.509 +
  36.510 +    char* revoke_fpr_arr[3];
  36.511 +    
  36.512 +    status = generate_keypair(session, revokemaster_3000);
  36.513 +    TEST_ASSERT(status == PEP_STATUS_OK && revokemaster_3000->fpr);
  36.514 +    revoke_fpr_arr[0] = strdup(revokemaster_3000->fpr);
  36.515 +    free(revokemaster_3000->fpr);
  36.516 +    revokemaster_3000->fpr = NULL;
  36.517 +    
  36.518 +    status = generate_keypair(session, revokemaster_3000);
  36.519 +    TEST_ASSERT(status == PEP_STATUS_OK && revokemaster_3000->fpr);
  36.520 +    revoke_fpr_arr[1] = strdup(revokemaster_3000->fpr);
  36.521 +    free(revokemaster_3000->fpr);
  36.522 +    revokemaster_3000->fpr = NULL;
  36.523 +    
  36.524 +    status = generate_keypair(session, revokemaster_3000);
  36.525 +    TEST_ASSERT(status == PEP_STATUS_OK && revokemaster_3000->fpr);
  36.526 +    revoke_fpr_arr[2] = strdup(revokemaster_3000->fpr);
  36.527 +    free(revokemaster_3000->fpr);
  36.528 +    revokemaster_3000->fpr = NULL;
  36.529 +    
  36.530 +    cout << "Trust "  << revoke_fpr_arr[2] << " (default for identity) and " << revoke_fpr_arr[0] << endl;
  36.531 +    
  36.532 +    free(revokemaster_3000->fpr);
  36.533 +    revokemaster_3000->fpr = strdup(revoke_fpr_arr[2]);
  36.534 +    status = trust_personal_key(session, revokemaster_3000);
  36.535 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.536 +    status = get_trust(session, revokemaster_3000);
  36.537 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.538 +    TEST_ASSERT(revokemaster_3000->comm_type & PEP_ct_confirmed);
  36.539 +
  36.540 +    free(revokemaster_3000->fpr);
  36.541 +    revokemaster_3000->fpr = strdup(revoke_fpr_arr[0]);
  36.542 +    status = trust_personal_key(session, revokemaster_3000);
  36.543 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.544 +    status = get_trust(session, revokemaster_3000);
  36.545 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.546 +    TEST_ASSERT(revokemaster_3000->comm_type & PEP_ct_confirmed);
  36.547 +    
  36.548 +    status = update_identity(session, revokemaster_3000);
  36.549 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.550 +    TEST_ASSERT(revokemaster_3000->fpr);
  36.551 +    TEST_ASSERT(strcmp(revokemaster_3000->fpr, revoke_fpr_arr[2]) == 0);
  36.552 +    TEST_ASSERT(revokemaster_3000->comm_type & PEP_ct_confirmed);
  36.553 +
  36.554 +    cout << "update_identity returns the correct identity default." << endl;
  36.555 +    
  36.556 +    cout << "Ok, now... we revoke the default..." << endl;
  36.557 +    
  36.558 +    cout << "Revoking " << revoke_fpr_arr[2] << endl;
  36.559 +
  36.560 +    status = revoke_key(session, revoke_fpr_arr[2], "This little pubkey went to market");
  36.561 +    TEST_ASSERT (status == PEP_STATUS_OK);
  36.562 +
  36.563 +    bool is_revoked;
  36.564 +    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);    
  36.565 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.566 +    TEST_ASSERT(is_revoked);
  36.567 +
  36.568 +    cout << "Success revoking " << revoke_fpr_arr[2] << "!!! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
  36.569 +    
  36.570 +    cout << "Now see if update_identity gives us " << revoke_fpr_arr[0] << ", the only trusted key left." << endl;
  36.571 +    status = update_identity(session, revokemaster_3000);
  36.572 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.573 +    TEST_ASSERT(revokemaster_3000->fpr);
  36.574 +    TEST_ASSERT(strcmp(revokemaster_3000->fpr, revoke_fpr_arr[0]) == 0);
  36.575 +    TEST_ASSERT(revokemaster_3000->comm_type & PEP_ct_confirmed);    
  36.576 +    
  36.577 +    cout << "Success! So let's mistrust it, because seriously, that key was so uncool." << endl;
  36.578 +    
  36.579 +    status = key_mistrusted(session, revokemaster_3000);
  36.580 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.581 +
  36.582 +    status = get_trust(session, revokemaster_3000);
  36.583 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.584 +    TEST_ASSERT(revokemaster_3000->comm_type == PEP_ct_mistrusted);
  36.585 +    
  36.586 +    cout << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
  36.587 +
  36.588 +    cout << "The only fpr left is an untrusted one - let's make sure this is what we get from update_identity." << endl;
  36.589 +
  36.590 +    status = update_identity(session, revokemaster_3000);
  36.591 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.592 +    TEST_ASSERT(revokemaster_3000->fpr);
  36.593 +    TEST_ASSERT(strcmp(revokemaster_3000->fpr, revoke_fpr_arr[1]) == 0);
  36.594 +    TEST_ASSERT(!(revokemaster_3000->comm_type & PEP_ct_confirmed));    
  36.595 +
  36.596 +    cout << "Success! We got " << revoke_fpr_arr[1] << "as the fpr with comm_type " << revokemaster_3000->comm_type << endl;
  36.597 +    
  36.598 +    cout << "But, you know... let's revoke that one too and see what update_identity gives us." << endl;
  36.599 +
  36.600 +    status = revoke_key(session, revoke_fpr_arr[1], "Because it's more fun to revoke ALL of someone's keys");
  36.601 +    TEST_ASSERT (status == PEP_STATUS_OK);
  36.602 +
  36.603 +    status = key_revoked(session, revokemaster_3000->fpr, &is_revoked);    
  36.604 +    TEST_ASSERT(status == PEP_STATUS_OK);
  36.605 +    TEST_ASSERT(is_revoked);
  36.606 +    
  36.607 +    cout << "Success! get_trust for this fpr gives us " << revokemaster_3000->comm_type << endl;
  36.608 +
  36.609 +    cout << "Call update_identity - we expect nothing, plus an error comm type." << endl;
  36.610 +
  36.611 +    status = update_identity(session, revokemaster_3000);
  36.612 +    TEST_ASSERT(status != PEP_STATUS_OK);
  36.613 +    TEST_ASSERT(!revokemaster_3000->fpr);
  36.614 +    TEST_ASSERT(revokemaster_3000->username);
  36.615 +    TEST_ASSERT(strcmp(revokemaster_3000->user_id, revoke_uuid) == 0);
  36.616 +    TEST_ASSERT(revokemaster_3000->comm_type == PEP_ct_key_not_found);
  36.617 +    cout << "Success! No key found. The comm_status error was " << revokemaster_3000->comm_type << "and the return status was " << tl_status_string(status) << endl;
  36.618 +
  36.619 +    free_identity(revokemaster_3000);
  36.620 +
  36.621 +    cout << "****************************************************************************************" << endl;
  36.622 +    cout << "* III: 100000000. key election: more to come " << endl;
  36.623 +    cout << "****************************************************************************************" << endl << endl;
  36.624 +
  36.625 +}
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/test/src/engine_tests/PepSubjectReceivedTests.cc	Tue May 08 15:43:07 2018 +0200
    37.3 @@ -0,0 +1,483 @@
    37.4 +// This file is under GNU General Public License 3.0
    37.5 +// see LICENSE.txt
    37.6 +
    37.7 +#include <stdlib.h>
    37.8 +#include <string>
    37.9 +#include <iostream>
   37.10 +#include <fstream>
   37.11 +#include <cstring> // for strcmp()
   37.12 +
   37.13 +#include "pEpEngine.h"
   37.14 +#include "keymanagement.h"
   37.15 +#include "message_api.h"
   37.16 +#include "mime.h"
   37.17 +#include "test_util.h" // for slurp()
   37.18 +
   37.19 +#include <cpptest.h>
   37.20 +#include "EngineTestSessionSuite.h"
   37.21 +#include "PepSubjectReceivedTests.h"
   37.22 +
   37.23 +using namespace std;
   37.24 +
   37.25 +PepSubjectReceivedTests::PepSubjectReceivedTests(string suitename, string test_home_dir) :
   37.26 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   37.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("PepSubjectReceivedTests::check_pep_subject_received"),
   37.28 +                                                                      static_cast<Func>(&PepSubjectReceivedTests::check_pep_subject_received)));
   37.29 +}
   37.30 +
   37.31 +void PepSubjectReceivedTests::check_pep_subject_received() {
   37.32 +
   37.33 +    const char* keytexts[3];
   37.34 +
   37.35 +    const string keytextkey1 = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   37.36 +    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
   37.37 +    const string keytextkey3 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
   37.38 +    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
   37.39 +    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
   37.40 +    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
   37.41 +
   37.42 +    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE", PEP_OWN_USERID, "pEp Test Recipient");    
   37.43 +    me->me = true;
   37.44 +    PEP_STATUS status = myself(session, me);
   37.45 +    
   37.46 +    pEp_identity * you = new_identity("pep.test.alice@pep-project.org", NULL, "TOFU_pep.test.alice@pep-project.org", "Alice Test");    
   37.47 +    you->me = false;
   37.48 +
   37.49 +    status = update_identity(session, you);
   37.50 +    trust_personal_key(session, you);
   37.51 +    status = update_identity(session, you);
   37.52 +
   37.53 +    cout << "------------------------------------------------------------------------------------------" << endl;
   37.54 +    cout << "Test 1a: Normal encrypted mail, pEp as substitute subject, regular subject in crypto text." << endl;
   37.55 +    cout << "------------------------------------------------------------------------------------------" << endl;
   37.56 +        
   37.57 +    string mailtext = slurp("test_mails/pEp_subject_normal_1a.eml");
   37.58 +    
   37.59 +    message* msg_ptr = nullptr;
   37.60 +    message* dest_msg = nullptr;
   37.61 +    message* final_ptr = nullptr;
   37.62 +    stringlist_t* keylist = nullptr;
   37.63 +    PEP_rating rating;
   37.64 +    PEP_decrypt_flags_t flags;
   37.65 +    
   37.66 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
   37.67 +    TEST_ASSERT(status == PEP_STATUS_OK);
   37.68 +    TEST_ASSERT(msg_ptr);
   37.69 +    final_ptr = msg_ptr;
   37.70 +    flags = 0;
   37.71 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   37.72 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
   37.73 +  
   37.74 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
   37.75 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
   37.76 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
   37.77 +
   37.78 +    TEST_ASSERT(strcmp("This is the usual pEp subject that should replace the above.", final_ptr->shortmsg) == 0);
   37.79 +
   37.80 +    cout << "Test 1a: Subject replaced as expected." << endl << endl;
   37.81 +
   37.82 +    if (final_ptr == dest_msg)
   37.83 +    	free_message(dest_msg);
   37.84 +    free_message(msg_ptr);
   37.85 +    free_stringlist(keylist);
   37.86 +
   37.87 +    cout << "------------------------------------------------------------------------------------------" << endl;
   37.88 +    cout << "Test 1b: Normal encrypted mail, p≡p as substitute subject, regular subject in crypto text." << endl;
   37.89 +    cout << "------------------------------------------------------------------------------------------" << endl;
   37.90 +        
   37.91 +    mailtext = slurp("test_mails/p3p_subject_normal_1b.eml");
   37.92 +    
   37.93 +    msg_ptr = nullptr;
   37.94 +    dest_msg = nullptr;
   37.95 +    final_ptr = nullptr;
   37.96 +    keylist = nullptr;
   37.97 +    rating = PEP_rating_unreliable;
   37.98 +    
   37.99 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.100 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.101 +    TEST_ASSERT(msg_ptr);
  37.102 +    final_ptr = msg_ptr;
  37.103 +    flags = 0;
  37.104 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.105 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.106 +  
  37.107 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.108 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.109 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.110 +
  37.111 +    TEST_ASSERT(strcmp("This is the usual pEp subject that should replace the above.", final_ptr->shortmsg) == 0);
  37.112 +
  37.113 +    cout << "Test 1b: Subject replaced as expected." << endl << endl;
  37.114 +
  37.115 +    if (final_ptr == dest_msg)
  37.116 +    	free_message(dest_msg);
  37.117 +    free_message(msg_ptr);
  37.118 +    free_stringlist(keylist);
  37.119 +
  37.120 +    cout << "-------------------------------------------------------------------------------------------------" << endl;
  37.121 +    cout << "Test 2a: Normal encrypted/signed mail, pEp as substitute subject, regular subject in crypto text." << endl;
  37.122 +    cout << "-------------------------------------------------------------------------------------------------" << endl;
  37.123 +
  37.124 +    msg_ptr = nullptr;
  37.125 +    dest_msg = nullptr;
  37.126 +    final_ptr = nullptr;
  37.127 +    keylist = nullptr;
  37.128 +    rating = PEP_rating_unreliable;
  37.129 +    
  37.130 +    mailtext = slurp("test_mails/pEp_subject_normal_signed_2a.eml");
  37.131 +    
  37.132 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.133 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.134 +    TEST_ASSERT(msg_ptr);
  37.135 +    final_ptr = msg_ptr;
  37.136 +    flags = 0;
  37.137 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.138 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.139 +  
  37.140 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.141 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.142 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.143 +
  37.144 +    TEST_ASSERT(strcmp("Now signed!", final_ptr->shortmsg) == 0);
  37.145 +
  37.146 +    cout << "Test 2a: Subject replaced as expected." << endl << endl;
  37.147 +
  37.148 +    if (final_ptr == dest_msg)
  37.149 +        free_message(dest_msg);
  37.150 +    free_message(msg_ptr);
  37.151 +    free_stringlist(keylist);
  37.152 +
  37.153 +    cout << "-------------------------------------------------------------------------------------------------" << endl;
  37.154 +    cout << "Test 2b: Normal encrypted/signed mail, p≡p as substitute subject, regular subject in crypto text." << endl;
  37.155 +    cout << "-------------------------------------------------------------------------------------------------" << endl;
  37.156 +
  37.157 +    msg_ptr = nullptr;
  37.158 +    dest_msg = nullptr;
  37.159 +    final_ptr = nullptr;
  37.160 +    keylist = nullptr;
  37.161 +    rating = PEP_rating_unreliable;
  37.162 +    
  37.163 +    mailtext = slurp("test_mails/p3p_subject_normal_signed_2b.eml");
  37.164 +    
  37.165 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.166 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.167 +    TEST_ASSERT(msg_ptr);
  37.168 +    final_ptr = msg_ptr;
  37.169 +    flags = 0;
  37.170 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.171 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.172 +  
  37.173 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.174 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.175 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.176 +
  37.177 +    TEST_ASSERT(strcmp("Now signed!", final_ptr->shortmsg) == 0);
  37.178 +
  37.179 +    cout << "Test 2b: Subject replaced as expected." << endl << endl;
  37.180 +
  37.181 +    if (final_ptr == dest_msg)
  37.182 +        free_message(dest_msg);
  37.183 +    free_message(msg_ptr);
  37.184 +    free_stringlist(keylist);
  37.185 +
  37.186 +    
  37.187 +    cout << "---------------------------------------------------------------------------" << endl;
  37.188 +    cout << "Test 3a: Encrypted mail, pEp as displayed subject, no subject in body text." << endl;
  37.189 +    cout << "---------------------------------------------------------------------------" << endl;
  37.190 +
  37.191 +    msg_ptr = nullptr;
  37.192 +    dest_msg = nullptr;
  37.193 +    final_ptr = nullptr;
  37.194 +    keylist = nullptr;
  37.195 +    rating = PEP_rating_unreliable;
  37.196 +    
  37.197 +    mailtext = slurp("test_mails/pEp_encrypted_subject_IS_pEp_3a.eml");
  37.198 +    
  37.199 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.200 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.201 +    TEST_ASSERT(msg_ptr);
  37.202 +    final_ptr = msg_ptr;
  37.203 +    flags = 0;
  37.204 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.205 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.206 +  
  37.207 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.208 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.209 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.210 +
  37.211 +    TEST_ASSERT(strcmp("pEp", final_ptr->shortmsg) == 0);
  37.212 +
  37.213 +    cout << "Test 3a: Subject remains intact as desired." << endl << endl;
  37.214 +
  37.215 +    if (final_ptr == dest_msg)
  37.216 +        free_message(dest_msg);
  37.217 +    free_message(msg_ptr);
  37.218 +    free_stringlist(keylist);
  37.219 +
  37.220 +    cout << "---------------------------------------------------------------------------" << endl;
  37.221 +    cout << "Test 3b: Encrypted mail, p≡p as displayed subject, no subject in body text." << endl;
  37.222 +    cout << "---------------------------------------------------------------------------" << endl;
  37.223 +
  37.224 +    msg_ptr = nullptr;
  37.225 +    dest_msg = nullptr;
  37.226 +    final_ptr = nullptr;
  37.227 +    keylist = nullptr;
  37.228 +    rating = PEP_rating_unreliable;
  37.229 +    
  37.230 +    mailtext = slurp("test_mails/p3p_encrypted_subject_IS_pEp_3b.eml");
  37.231 +    
  37.232 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.233 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.234 +    TEST_ASSERT(msg_ptr);
  37.235 +    final_ptr = msg_ptr;
  37.236 +    flags = 0;
  37.237 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.238 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.239 +  
  37.240 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.241 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.242 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.243 +
  37.244 +    TEST_ASSERT(strcmp("p≡p", final_ptr->shortmsg) == 0);
  37.245 +
  37.246 +    cout << "Test 3: Subject remains intact as desired." << endl << endl;
  37.247 +
  37.248 +    if (final_ptr == dest_msg)
  37.249 +        free_message(dest_msg);
  37.250 +    free_message(msg_ptr);
  37.251 +    free_stringlist(keylist);
  37.252 +
  37.253 +
  37.254 +    cout << "----------------------------------------------------------------------------" << endl;
  37.255 +    cout << "Test 4a: Encrypted mail, pEp as displayed subject, pEp subject in body text." << endl;
  37.256 +    cout << "----------------------------------------------------------------------------" << endl;
  37.257 +
  37.258 +    msg_ptr = nullptr;
  37.259 +    dest_msg = nullptr;
  37.260 +    final_ptr = nullptr;
  37.261 +    keylist = nullptr;
  37.262 +    rating = PEP_rating_unreliable;
  37.263 +    
  37.264 +    mailtext = slurp("test_mails/pEp_subject_pEp_replaced_w_pEp_4a.eml");
  37.265 +    
  37.266 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.267 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.268 +    TEST_ASSERT(msg_ptr);
  37.269 +    final_ptr = msg_ptr;
  37.270 +    flags = 0;
  37.271 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.272 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.273 +  
  37.274 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.275 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.276 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.277 +
  37.278 +    TEST_ASSERT(strcmp("pEp", final_ptr->shortmsg) == 0);
  37.279 +
  37.280 +    cout << "Test 4a: Subject correct." << endl << endl;
  37.281 +
  37.282 +    if (final_ptr == dest_msg)
  37.283 +        free_message(dest_msg);
  37.284 +    free_message(msg_ptr);
  37.285 +    free_stringlist(keylist);
  37.286 +
  37.287 +    cout << "----------------------------------------------------------------------------" << endl;
  37.288 +    cout << "Test 4b: Encrypted mail, p≡p as displayed subject, pEp subject in body text." << endl;
  37.289 +    cout << "----------------------------------------------------------------------------" << endl;
  37.290 +
  37.291 +    msg_ptr = nullptr;
  37.292 +    dest_msg = nullptr;
  37.293 +    final_ptr = nullptr;
  37.294 +    keylist = nullptr;
  37.295 +    rating = PEP_rating_unreliable;
  37.296 +    
  37.297 +    mailtext = slurp("test_mails/pEp_subject_pEp_replaced_w_p3p_4b.eml");
  37.298 +    
  37.299 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.300 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.301 +    TEST_ASSERT(msg_ptr);
  37.302 +    final_ptr = msg_ptr;
  37.303 +    flags = 0;
  37.304 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.305 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.306 +  
  37.307 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.308 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.309 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.310 +
  37.311 +    TEST_ASSERT(strcmp("pEp", final_ptr->shortmsg) == 0);
  37.312 +
  37.313 +    cout << "Test 4b: Subject correct." << endl << endl;
  37.314 +
  37.315 +    if (final_ptr == dest_msg)
  37.316 +        free_message(dest_msg);
  37.317 +    free_message(msg_ptr);
  37.318 +    free_stringlist(keylist);
  37.319 +
  37.320 +    cout << "----------------------------------------------------------------------------" << endl;
  37.321 +    cout << "Test 4c: Encrypted mail, pEp as displayed subject, p≡p subject in body text." << endl;
  37.322 +    cout << "----------------------------------------------------------------------------" << endl;
  37.323 +
  37.324 +    msg_ptr = nullptr;
  37.325 +    dest_msg = nullptr;
  37.326 +    final_ptr = nullptr;
  37.327 +    keylist = nullptr;
  37.328 +    rating = PEP_rating_unreliable;
  37.329 +    
  37.330 +    mailtext = slurp("test_mails/pEp_subject_p3p_replaced_w_pEp_4c.eml");
  37.331 +    
  37.332 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.333 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.334 +    TEST_ASSERT(msg_ptr);
  37.335 +    final_ptr = msg_ptr;
  37.336 +    flags = 0;
  37.337 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.338 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.339 +  
  37.340 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.341 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.342 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.343 +
  37.344 +    TEST_ASSERT(strcmp("p≡p", final_ptr->shortmsg) == 0);
  37.345 +
  37.346 +    cout << "Test 4c: Subject correct." << endl << endl;
  37.347 +
  37.348 +    if (final_ptr == dest_msg)
  37.349 +        free_message(dest_msg);
  37.350 +    free_message(msg_ptr);
  37.351 +    free_stringlist(keylist);
  37.352 +
  37.353 +    cout << "----------------------------------------------------------------------------" << endl;
  37.354 +    cout << "Test 4d: Encrypted mail, p≡p as displayed subject, p≡p subject in body text." << endl;
  37.355 +    cout << "----------------------------------------------------------------------------" << endl;
  37.356 +
  37.357 +    msg_ptr = nullptr;
  37.358 +    dest_msg = nullptr;
  37.359 +    final_ptr = nullptr;
  37.360 +    keylist = nullptr;
  37.361 +    rating = PEP_rating_unreliable;
  37.362 +    
  37.363 +    mailtext = slurp("test_mails/pEp_subject_p3p_replaced_w_p3p_4d.eml");
  37.364 +    
  37.365 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.366 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.367 +    TEST_ASSERT(msg_ptr);
  37.368 +    final_ptr = msg_ptr;
  37.369 +    flags = 0;
  37.370 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.371 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.372 +  
  37.373 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.374 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.375 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.376 +
  37.377 +    TEST_ASSERT(strcmp("p≡p", final_ptr->shortmsg) == 0);
  37.378 +
  37.379 +    cout << "Test 4d: Subject correct, in any event." << endl << endl;
  37.380 +
  37.381 +    if (final_ptr == dest_msg)
  37.382 +        free_message(dest_msg);
  37.383 +    free_message(msg_ptr);
  37.384 +    free_stringlist(keylist);
  37.385 +
  37.386 +
  37.387 +    cout << "-------------------------------------------------------------------------" << endl;
  37.388 +    cout << "Test 5a: Unencrypted variant where pEp in the subject line is the subject." << endl;
  37.389 +    cout << "-------------------------------------------------------------------------" << endl;
  37.390 +
  37.391 +    msg_ptr = nullptr;
  37.392 +    dest_msg = nullptr;
  37.393 +    final_ptr = nullptr;
  37.394 +    keylist = nullptr;
  37.395 +    rating = PEP_rating_unreliable;
  37.396 +    
  37.397 +    mailtext = slurp("test_mails/pEp_unencrypted_pEp_subject_5a.eml");
  37.398 +    
  37.399 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.400 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.401 +    TEST_ASSERT(msg_ptr);
  37.402 +    final_ptr = msg_ptr;
  37.403 +    flags = 0;
  37.404 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.405 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.406 +  
  37.407 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.408 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.409 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.410 +
  37.411 +    TEST_ASSERT(strcmp("pEp", final_ptr->shortmsg) == 0);
  37.412 +
  37.413 +    cout << "Test 5a: Subject remains intact." << endl << endl;
  37.414 +
  37.415 +    if (final_ptr == dest_msg)
  37.416 +        free_message(dest_msg);
  37.417 +    free_message(msg_ptr);
  37.418 +    free_stringlist(keylist);
  37.419 +
  37.420 +
  37.421 +    cout << "--------------------------------------------------------------------------" << endl;
  37.422 +    cout << "Test 5b: Unencrypted variant where p≡p in the subject line is the subject." << endl;
  37.423 +    cout << "--------------------------------------------------------------------------" << endl;
  37.424 +
  37.425 +    msg_ptr = nullptr;
  37.426 +    dest_msg = nullptr;
  37.427 +    final_ptr = nullptr;
  37.428 +    keylist = nullptr;
  37.429 +    rating = PEP_rating_unreliable;
  37.430 +    
  37.431 +    mailtext = slurp("test_mails/pEp_unencrypted_p3p_subject_5b.eml");
  37.432 +    
  37.433 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.434 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.435 +    TEST_ASSERT(msg_ptr);
  37.436 +    final_ptr = msg_ptr;
  37.437 +    flags = 0;
  37.438 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.439 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.440 +  
  37.441 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.442 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.443 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.444 +
  37.445 +    TEST_ASSERT(strcmp("p≡p", final_ptr->shortmsg) == 0);
  37.446 +
  37.447 +    cout << "Test 5b: Subject remains intact." << endl << endl;
  37.448 +
  37.449 +    if (final_ptr == dest_msg)
  37.450 +        free_message(dest_msg);
  37.451 +    free_message(msg_ptr);
  37.452 +    free_stringlist(keylist);
  37.453 +
  37.454 +    cout << "----------------------------------------------------------------------------------------------------------------------" << endl;
  37.455 +    cout << "Test 6: Normal unencrypted email where a subject line exists in the text but the subject is not a replacement subject." << endl;
  37.456 +    cout << "----------------------------------------------------------------------------------------------------------------------" << endl;
  37.457 +
  37.458 +    msg_ptr = nullptr;
  37.459 +    dest_msg = nullptr;
  37.460 +    final_ptr = nullptr;
  37.461 +    keylist = nullptr;
  37.462 +    rating = PEP_rating_unreliable;
  37.463 +    
  37.464 +    mailtext = slurp("test_mails/pEp_subject_normal_unencrypted_6.eml");
  37.465 +    
  37.466 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  37.467 +    TEST_ASSERT(status == PEP_STATUS_OK);
  37.468 +    TEST_ASSERT(msg_ptr);
  37.469 +    final_ptr = msg_ptr;
  37.470 +    flags = 0;
  37.471 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  37.472 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  37.473 +  
  37.474 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  37.475 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  37.476 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  37.477 +
  37.478 +    TEST_ASSERT(strcmp("This is just a normal subject, really", final_ptr->shortmsg) == 0);
  37.479 +
  37.480 +    cout << "Test 6: Subject remains intact." << endl << endl;
  37.481 +
  37.482 +    if (final_ptr == dest_msg)
  37.483 +        free_message(dest_msg);
  37.484 +    free_message(msg_ptr);
  37.485 +    free_stringlist(keylist);
  37.486 +}
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/test/src/engine_tests/PgpBinaryTests.cc	Tue May 08 15:43:07 2018 +0200
    38.3 @@ -0,0 +1,39 @@
    38.4 +// This file is under GNU General Public License 3.0
    38.5 +// see LICENSE.txt
    38.6 +
    38.7 +#include <stdlib.h>
    38.8 +#include <string>
    38.9 +#include <iostream>
   38.10 +
   38.11 +#include "pEpEngine.h"
   38.12 +#include "message_api.h"
   38.13 +
   38.14 +#include <cpptest.h>
   38.15 +#include "EngineTestSessionSuite.h"
   38.16 +#include "PgpBinaryTests.h"
   38.17 +
   38.18 +using namespace std;
   38.19 +
   38.20 +PgpBinaryTests::PgpBinaryTests(string suitename, string test_home_dir) :
   38.21 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   38.22 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("PgpBinaryTests::check_pgp_binary"),
   38.23 +                                                                      static_cast<Func>(&PgpBinaryTests::check_pgp_binary)));
   38.24 +}
   38.25 +
   38.26 +void PgpBinaryTests::check_pgp_binary() {
   38.27 +
   38.28 +    // pgp_binary test code
   38.29 +
   38.30 +    const char *path;
   38.31 +    PEP_STATUS status2 = get_binary_path(PEP_crypt_OpenPGP, &path);
   38.32 +    TEST_ASSERT(status2 == PEP_STATUS_OK);
   38.33 +#ifdef USE_GPG
   38.34 +    TEST_ASSERT(path);
   38.35 +#endif
   38.36 +    if (path)
   38.37 +        cout << "PGP binary at " << path << "\n";
   38.38 +    else
   38.39 +        cout << "no PGP binary path available\n";
   38.40 +
   38.41 +    cout << "calling release()\n";
   38.42 +}
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/test/src/engine_tests/PgpListKeysTests.cc	Tue May 08 15:43:07 2018 +0200
    39.3 @@ -0,0 +1,74 @@
    39.4 +// This file is under GNU General Public License 3.0
    39.5 +// see LICENSE.txt
    39.6 +
    39.7 +#include <stdlib.h>
    39.8 +#include <string>
    39.9 +#include <iostream>
   39.10 +
   39.11 +#include "pEpEngine.h"
   39.12 +#include "pEpEngine.h"
   39.13 +#include "stringpair.h"
   39.14 +#include "openpgp_compat.h"
   39.15 +
   39.16 +#include <cpptest.h>
   39.17 +#include "EngineTestSessionSuite.h"
   39.18 +#include "PgpListKeysTests.h"
   39.19 +
   39.20 +using namespace std;
   39.21 +
   39.22 +PgpListKeysTests::PgpListKeysTests(string suitename, string test_home_dir) :
   39.23 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   39.24 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("PgpListKeysTests::check_pgp_list_keys"),
   39.25 +                                                                      static_cast<Func>(&PgpListKeysTests::check_pgp_list_keys)));
   39.26 +}
   39.27 +
   39.28 +static void print_stringpair_list(stringpair_list_t* spl) {
   39.29 +    for ( ; spl != NULL; spl = spl->next) {
   39.30 +        if (spl->value) {
   39.31 +            cout << "Key:" << endl;
   39.32 +            if (spl->value->key)
   39.33 +                cout << "\tFPR: " << spl->value->key << endl;
   39.34 +            if (spl->value->value)
   39.35 +                cout << "\tUID: " << spl->value->value << endl;
   39.36 +        }
   39.37 +    }
   39.38 +}
   39.39 +
   39.40 +void PgpListKeysTests::check_pgp_list_keys() {
   39.41 +
   39.42 +    cout << "Listing all the keys:" << endl;
   39.43 +    stringpair_list_t* all_the_ids = NULL;
   39.44 +    OpenPGP_list_keyinfo(session, "", &all_the_ids);
   39.45 +    print_stringpair_list(all_the_ids);
   39.46 +    free_stringpair_list(all_the_ids);
   39.47 +    
   39.48 +    cout << "**********************" << endl << endl << "Checking on Alice, Bob and John" << endl;
   39.49 +    all_the_ids = NULL;
   39.50 +    OpenPGP_list_keyinfo(session, "pEp Test", &all_the_ids);
   39.51 +    print_stringpair_list(all_the_ids);
   39.52 +    free_stringpair_list(all_the_ids);
   39.53 +
   39.54 +    cout << "**********************" << endl << endl << "Compare to find_keys for Alice, Bob and John" << endl;
   39.55 +    stringlist_t* all_the_keys;
   39.56 +    find_keys(session, "pEp Test", &all_the_keys);
   39.57 +    stringlist_t* i;
   39.58 +    for (i = all_the_keys; i; i = i->next) {
   39.59 +        cout << i->value << endl;
   39.60 +    }
   39.61 +    free_stringlist(all_the_keys);
   39.62 +
   39.63 +    
   39.64 +    cout << "**********************" << endl << endl << "Checking FPR" << endl;
   39.65 +    all_the_ids = NULL;
   39.66 +    OpenPGP_list_keyinfo(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &all_the_ids);
   39.67 +    print_stringpair_list(all_the_ids);
   39.68 +    free_stringpair_list(all_the_ids);
   39.69 +
   39.70 +    cout << "**********************" << endl << endl << "Checking on nothing" << endl;
   39.71 +    all_the_ids = NULL;
   39.72 +    OpenPGP_list_keyinfo(session, "ekhwr89234uh4rknfjsklejfnlskjflselkflkserjs", &all_the_ids);
   39.73 +    print_stringpair_list(all_the_ids);
   39.74 +    free_stringpair_list(all_the_ids);
   39.75 +
   39.76 +    cout << "calling release()\n";
   39.77 +}
    40.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.2 +++ b/test/src/engine_tests/ReencryptPlusExtraKeysTests.cc	Tue May 08 15:43:07 2018 +0200
    40.3 @@ -0,0 +1,534 @@
    40.4 +// This file is under GNU General Public License 3.0
    40.5 +// see LICENSE.txt
    40.6 +
    40.7 +#include <stdlib.h>
    40.8 +#include <cstring>
    40.9 +#include <iostream>
   40.10 +#include <fstream>
   40.11 +
   40.12 +#include "pEpEngine.h"
   40.13 +#include "platform.h"
   40.14 +#include "mime.h"
   40.15 +#include "message_api.h"
   40.16 +#include "keymanagement.h"
   40.17 +#include "test_util.h"
   40.18 +
   40.19 +#include <cpptest.h>
   40.20 +#include "EngineTestSessionSuite.h"
   40.21 +#include "ReencryptPlusExtraKeysTests.h"
   40.22 +
   40.23 +using namespace std;
   40.24 +
   40.25 +ReencryptPlusExtraKeysTests::ReencryptPlusExtraKeysTests(string suitename, string test_home_dir) :
   40.26 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   40.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ReencryptPlusExtraKeysTests::check_reencrypt_plus_extra_keys"),
   40.28 +                                                                      static_cast<Func>(&ReencryptPlusExtraKeysTests::check_reencrypt_plus_extra_keys)));
   40.29 +}
   40.30 +
   40.31 +void ReencryptPlusExtraKeysTests::check_reencrypt_plus_extra_keys() {
   40.32 +    PEP_STATUS status = PEP_STATUS_OK;
   40.33 +
   40.34 +    /* import all the keys */
   40.35 +    const char* fpr_own_recip_key = "85D022E0CC9BA9F6B922CA7B638E5211B1A2BE89";
   40.36 +    const char* fpr_own_recip_2_key = "7A2EEB933E6FD99207B83E397B6D3751D6E75FFF";
   40.37 +    
   40.38 +    const char* fpr_sender_pub_key = "95FE24B262A34FA5C6A8D0AAF90144FC3B508C8E";
   40.39 +    const char* fpr_recip_2_pub_key = "60701073D138EF622C8F9221B6FC86831EDBE691";
   40.40 +    const char* fpr_recip_0_pub_key = "CDF787C7C9664E02825DD416C6FBCF8D1F4A5986";
   40.41 +    // we're leaving recip_1 out for the Hell of it - D3886D0DF75113BE2799C9374D6B99FE0F8273D8
   40.42 +    const char* fpr_pub_extra_key_0 = "33BB6C92EBFB6F29641C75B5B79D916C828AA789";
   40.43 +
   40.44 +    const char* fpr_pub_extra_key_1 = "3DB93A746785FDD6110798AB3B193A9E8B026AEC";
   40.45 +    const string own_recip_pub_key = slurp("test_keys/pub/reencrypt_recip_0-0xB1A2BE89_pub.asc");
   40.46 +    const string own_recip_priv_key = slurp("test_keys/priv/reencrypt_recip_0-0xB1A2BE89_priv.asc");
   40.47 +    const string own_recip_2_pub_key = slurp("test_keys/pub/reencrypt_recip_numero_deux_test_0-0xD6E75FFF_pub.asc");
   40.48 +    const string own_recip_2_priv_key = slurp("test_keys/priv/reencrypt_recip_numero_deux_test_0-0xD6E75FFF_priv.asc");
   40.49 +    
   40.50 +    const string sender_pub_key = slurp("test_keys/pub/reencrypt_sender_0-0x3B508C8E_pub.asc");
   40.51 +    const string recip_2_pub_key = slurp("test_keys/pub/reencrypt_other_recip_2-0x1EDBE691_pub.asc");
   40.52 +    const string recip_0_pub_key = slurp("test_keys/pub/reencrypt_other_recip_0-0x1F4A5986_pub.asc");
   40.53 +    // we're leaving recip_1 out for the Hell of it
   40.54 +    const string pub_extra_key_0 = slurp("test_keys/pub/reencrypt_extra_keys_0-0x828AA789_pub.asc");
   40.55 +    const string pub_extra_key_1 = slurp("test_keys/pub/reencrypt_extra_keys_1-0x8B026AEC_pub.asc");
   40.56 +
   40.57 +    status = import_key(session, own_recip_pub_key.c_str(), own_recip_pub_key.length(), NULL);
   40.58 +    TEST_ASSERT (status == PEP_STATUS_OK);
   40.59 +    status = import_key(session, own_recip_priv_key.c_str(), own_recip_priv_key.length(), NULL);
   40.60 +    TEST_ASSERT (status == PEP_STATUS_OK);    
   40.61 +    status = import_key(session, own_recip_2_pub_key.c_str(), own_recip_2_pub_key.length(), NULL);
   40.62 +    TEST_ASSERT (status == PEP_STATUS_OK);
   40.63 +    status = import_key(session, own_recip_2_priv_key.c_str(), own_recip_2_priv_key.length(), NULL);
   40.64 +    TEST_ASSERT (status == PEP_STATUS_OK);
   40.65 +    
   40.66 +    status = import_key(session, sender_pub_key.c_str(), sender_pub_key.length(), NULL);
   40.67 +    TEST_ASSERT (status == PEP_STATUS_OK);
   40.68 +    status = import_key(session, recip_2_pub_key.c_str(), recip_2_pub_key.length(), NULL);
   40.69 +    TEST_ASSERT (status == PEP_STATUS_OK);
   40.70 +    status = import_key(session, recip_0_pub_key.c_str(), recip_0_pub_key.length(), NULL);
   40.71 +    TEST_ASSERT (status == PEP_STATUS_OK);
   40.72 +    status = import_key(session, pub_extra_key_0.c_str(), pub_extra_key_0.length(), NULL);
   40.73 +    TEST_ASSERT (status == PEP_STATUS_OK);
   40.74 +    status = import_key(session, pub_extra_key_1.c_str(), pub_extra_key_1.length(), NULL);
   40.75 +    TEST_ASSERT (status == PEP_STATUS_OK);
   40.76 +
   40.77 +    cout << "Keys imported." << endl;
   40.78 +
   40.79 +    pEp_identity* me_recip_1 = new_identity("reencrypt_recip@darthmama.cool", fpr_own_recip_key, PEP_OWN_USERID, "Me Recipient");
   40.80 +    pEp_identity* me_recip_2 = new_identity("reencrypt_recip_numero_deux_test@darthmama.org", fpr_own_recip_2_key, PEP_OWN_USERID, "Me Recipient");
   40.81 +    
   40.82 +    cout << "Inserting own identities and keys into database." << endl;
   40.83 +    status = set_own_key(session, me_recip_2, fpr_own_recip_2_key);
   40.84 +    TEST_ASSERT(status == PEP_STATUS_OK);
   40.85 +    cout << "Done: inserting own identities and keys into database." << endl;
   40.86 +
   40.87 +    const string to_reencrypt_from_enigmail = slurp("test_mails/reencrypt_sent_by_enigmail.eml");
   40.88 +    const string to_reencrypt_from_enigmail_BCC = slurp("test_mails/reencrypt_BCC_sent_by_enigmail.eml");
   40.89 +    const string to_reencrypt_from_pEp = slurp("test_mails/reencrypt_encrypted_through_pEp.eml");
   40.90 +
   40.91 +    cout << endl << "Case 1a: Calling MIME_decrypt_message with reencrypt flag set on message sent from enigmail for recip 2 with no extra keys." << endl;
   40.92 +    
   40.93 +    char* decrypted_text = nullptr;
   40.94 +    
   40.95 +    // In: extra keys; Out: keys that were used to encrypt this.
   40.96 +    stringlist_t* keys = NULL;
   40.97 +    PEP_decrypt_flags_t flags;
   40.98 +    PEP_rating rating;
   40.99 +
  40.100 +    flags = PEP_decrypt_flag_untrusted_server;
  40.101 +    char* modified_src = NULL;
  40.102 +    
  40.103 +    status = MIME_decrypt_message(session,
  40.104 +                                  to_reencrypt_from_enigmail.c_str(),
  40.105 +                                  to_reencrypt_from_enigmail.size(),
  40.106 +                                  &decrypted_text,
  40.107 +                                  &keys,
  40.108 +                                  &rating,
  40.109 +                                  &flags, 
  40.110 +                                  &modified_src);
  40.111 +
  40.112 +    cout << decrypted_text << endl;
  40.113 +
  40.114 +    cout << "Status is " << tl_status_string(status) << endl;
  40.115 +    TEST_ASSERT(decrypted_text);
  40.116 +    TEST_ASSERT(rating);
  40.117 +    TEST_ASSERT(!(flags & PEP_decrypt_flag_src_modified));
  40.118 +    
  40.119 +    TEST_ASSERT(!modified_src);
  40.120 +    //cout << modified_src << endl;
  40.121 +    
  40.122 +    free(decrypted_text);
  40.123 +    decrypted_text = nullptr;
  40.124 +
  40.125 +    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  40.126 +
  40.127 +    free(decrypted_text);
  40.128 +    decrypted_text = nullptr;
  40.129 +    flags = 0;
  40.130 +    char* throwaway = NULL;
  40.131 +
  40.132 +    status = MIME_decrypt_message(session,
  40.133 +                                  modified_src,
  40.134 +                                  strlen(modified_src),
  40.135 +                                  &decrypted_text,
  40.136 +                                  &keys,
  40.137 +                                  &rating,
  40.138 +                                  &flags,
  40.139 +                                  &throwaway);
  40.140 +
  40.141 +    
  40.142 +    cout << "keys used:\n";
  40.143 +    
  40.144 +    int i = 0;
  40.145 +    
  40.146 +    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  40.147 +    {
  40.148 +        if (i == 0) {
  40.149 +              cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  40.150 +              TEST_ASSERT(strcasecmp(fpr_own_recip_2_key,kl->value) == 0);
  40.151 +        }
  40.152 +        else {
  40.153 +            cout << "\t " << kl->value << endl;
  40.154 +            TEST_ASSERT(strcasecmp(fpr_own_recip_2_key, kl->value) == 0);
  40.155 +            cout << "Encrypted only for own identity! Yay! It worked!" << endl;
  40.156 +        }
  40.157 +        TEST_ASSERT(i < 2);
  40.158 +    }
  40.159 +    cout << "Case 1a: PASS" << endl << endl;
  40.160 +
  40.161 +    cout << "Case 1b: Calling MIME_decrypt_message with reencrypt flag set on message sent from enigmail for recip 2 extra keys." << endl;
  40.162 +        
  40.163 +    // In: extra keys; Out: keys that were used to encrypt this.
  40.164 +    free_stringlist(keys);
  40.165 +    keys = new_stringlist(fpr_pub_extra_key_0);
  40.166 +    stringlist_add(keys, fpr_pub_extra_key_1);    
  40.167 +
  40.168 +    flags = PEP_decrypt_flag_untrusted_server;
  40.169 +    
  40.170 +    status = MIME_decrypt_message(session,
  40.171 +                                  to_reencrypt_from_enigmail.c_str(),
  40.172 +                                  to_reencrypt_from_enigmail.size(),
  40.173 +                                  &decrypted_text,
  40.174 +                                  &keys,
  40.175 +                                  &rating,
  40.176 +                                  &flags,
  40.177 +                                  &modified_src);
  40.178 +
  40.179 +    cout << decrypted_text << endl;
  40.180 +    cout << "Status is " << tl_status_string(status) << endl;
  40.181 +
  40.182 +
  40.183 +    TEST_ASSERT(decrypted_text);
  40.184 +    TEST_ASSERT(rating);
  40.185 +
  40.186 +    free(decrypted_text);
  40.187 +    decrypted_text = nullptr;
  40.188 +
  40.189 +    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  40.190 +
  40.191 +    free(decrypted_text);
  40.192 +    decrypted_text = nullptr;
  40.193 +    flags = 0;
  40.194 +    throwaway = NULL;
  40.195 +
  40.196 +    status = MIME_decrypt_message(session,
  40.197 +                                  modified_src,
  40.198 +                                  strlen(modified_src),
  40.199 +                                  &decrypted_text,
  40.200 +                                  &keys,
  40.201 +                                  &rating,
  40.202 +                                  &flags,
  40.203 +                                  &throwaway);
  40.204 +    
  40.205 +    cout << "keys used:\n";
  40.206 +    
  40.207 +    bool own_key_found = false;
  40.208 +    bool extra_key_0_found = false;
  40.209 +    bool extra_key_1_found = false;
  40.210 +    
  40.211 +    i = 0;
  40.212 +    
  40.213 +    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  40.214 +    {
  40.215 +        if (i == 0) {
  40.216 +              cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  40.217 +              TEST_ASSERT(strcasecmp(fpr_own_recip_2_key,kl->value) == 0);
  40.218 +        }
  40.219 +        else {
  40.220 +            if (strcasecmp(fpr_own_recip_2_key, kl->value) == 0) {
  40.221 +                cout << "Encrypted for us." << endl;
  40.222 +                own_key_found = true;
  40.223 +            }
  40.224 +            else if (strcasecmp(fpr_pub_extra_key_0, kl->value) == 0) {
  40.225 +                cout << "Encrypted for extra key 0." << endl;
  40.226 +                extra_key_0_found = true;
  40.227 +            }
  40.228 +            else if (strcasecmp(fpr_pub_extra_key_1, kl->value) == 0) {
  40.229 +                cout << "Encrypted for extra key 1." << endl;
  40.230 +                extra_key_1_found = true;
  40.231 +            }
  40.232 +            else {
  40.233 +                cout << "FAIL: Encrypted for " << kl->value << ", which it should not be." << endl;
  40.234 +                TEST_ASSERT(false);
  40.235 +            }
  40.236 +            cout << "\t " << kl->value << endl;
  40.237 +        }
  40.238 +        TEST_ASSERT(i < 4);
  40.239 +    }
  40.240 +    TEST_ASSERT (own_key_found && extra_key_0_found && extra_key_1_found);
  40.241 +    cout << "Message was encrypted for all the keys it should be, and none it should not!" << endl;
  40.242 +
  40.243 +    cout << "Case 1b: PASS" << endl << endl;
  40.244 +
  40.245 +    cout << "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;
  40.246 +
  40.247 +    free_stringlist(keys);
  40.248 +    keys = NULL;
  40.249 +
  40.250 +    flags = PEP_decrypt_flag_untrusted_server;
  40.251 +    
  40.252 +    status = MIME_decrypt_message(session,
  40.253 +                                  to_reencrypt_from_enigmail_BCC.c_str(),
  40.254 +                                  to_reencrypt_from_enigmail_BCC.size(),
  40.255 +                                  &decrypted_text,
  40.256 +                                  &keys,
  40.257 +                                  &rating,
  40.258 +                                  &flags,
  40.259 +                                  &modified_src);
  40.260 +
  40.261 +    cout << decrypted_text << endl;
  40.262 +    cout << "Status is " << tl_status_string(status) << endl;
  40.263 +
  40.264 +
  40.265 +    TEST_ASSERT(decrypted_text);
  40.266 +    TEST_ASSERT(rating);
  40.267 +
  40.268 +    free(decrypted_text);
  40.269 +    decrypted_text = nullptr;
  40.270 +
  40.271 +    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  40.272 +
  40.273 +    free(decrypted_text);
  40.274 +    decrypted_text = nullptr;
  40.275 +    flags = 0;
  40.276 +    throwaway = NULL;
  40.277 +
  40.278 +    status = MIME_decrypt_message(session,
  40.279 +                                  modified_src,
  40.280 +                                  strlen(modified_src),
  40.281 +                                  &decrypted_text,
  40.282 +                                  &keys,
  40.283 +                                  &rating,
  40.284 +                                  &flags,
  40.285 +                                  &throwaway);
  40.286 +    
  40.287 +    cout << "keys used:\n";
  40.288 +        
  40.289 +    i = 0;
  40.290 +    
  40.291 +    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  40.292 +    {
  40.293 +        if (i == 0) {
  40.294 +              cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  40.295 +//              TEST_ASSERT(strcasecmp(fpr_own_recip_2_key,kl->value) == 0);
  40.296 +        }
  40.297 +        else {
  40.298 +            cout << "\t " << kl->value << endl;
  40.299 +//            TEST_ASSERT(strcasecmp(fpr_own_recip_2_key, kl->value) == 0);
  40.300 +            cout << "Encrypted only for own identity! Yay! It worked!" << endl;
  40.301 +        }
  40.302 +        TEST_ASSERT(i < 2);
  40.303 +    }
  40.304 +
  40.305 +    cout << "Case 2a: PASS" << endl << endl;
  40.306 +
  40.307 +    cout << "Case 2b: Calling MIME_decrypt_message with reencrypt flag set on message sent with recip 2 in BCC from enigmail with extra keys." << endl;
  40.308 +
  40.309 +    free_stringlist(keys);
  40.310 +    keys = new_stringlist(fpr_pub_extra_key_0);
  40.311 +    stringlist_add(keys, fpr_pub_extra_key_1);    
  40.312 +
  40.313 +    flags = PEP_decrypt_flag_untrusted_server;
  40.314 +    
  40.315 +    status = MIME_decrypt_message(session,
  40.316 +                                  to_reencrypt_from_enigmail_BCC.c_str(),
  40.317 +                                  to_reencrypt_from_enigmail_BCC.size(),
  40.318 +                                  &decrypted_text,
  40.319 +                                  &keys,
  40.320 +                                  &rating,
  40.321 +                                  &flags,
  40.322 +                                  &modified_src);
  40.323 +
  40.324 +    cout << decrypted_text << endl;
  40.325 +    cout << "Status is " << tl_status_string(status) << endl;
  40.326 +
  40.327 +
  40.328 +    TEST_ASSERT(decrypted_text);
  40.329 +    TEST_ASSERT(rating);
  40.330 +
  40.331 +    free(decrypted_text);
  40.332 +    decrypted_text = nullptr;
  40.333 +
  40.334 +    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  40.335 +
  40.336 +    free(decrypted_text);
  40.337 +    decrypted_text = nullptr;
  40.338 +    flags = 0;
  40.339 +    throwaway = NULL;
  40.340 +
  40.341 +    status = MIME_decrypt_message(session,
  40.342 +                                  modified_src,
  40.343 +                                  strlen(modified_src),
  40.344 +                                  &decrypted_text,
  40.345 +                                  &keys,
  40.346 +                                  &rating,
  40.347 +                                  &flags,
  40.348 +                                  &throwaway);
  40.349 +    
  40.350 +    cout << "keys used:\n";
  40.351 +    
  40.352 +    own_key_found = false;
  40.353 +    extra_key_0_found = false;
  40.354 +    extra_key_1_found = false;
  40.355 +    
  40.356 +    i = 0;
  40.357 +    
  40.358 +    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  40.359 +    {
  40.360 +        if (i == 0) {
  40.361 +              cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  40.362 +//              TEST_ASSERT(strcasecmp(fpr_own_recip_2_key,kl->value) == 0);
  40.363 +        }
  40.364 +        else {
  40.365 +            if (strcasecmp(fpr_own_recip_2_key, kl->value) == 0) {
  40.366 +                cout << "Encrypted for us." << endl;
  40.367 +                own_key_found = true;
  40.368 +            }
  40.369 +            else if (strcasecmp(fpr_pub_extra_key_0, kl->value) == 0) {
  40.370 +                cout << "Encrypted for extra key 0." << endl;
  40.371 +                extra_key_0_found = true;
  40.372 +            }
  40.373 +            else if (strcasecmp(fpr_pub_extra_key_1, kl->value) == 0) {
  40.374 +                cout << "Encrypted for extra key 1." << endl;
  40.375 +                extra_key_1_found = true;
  40.376 +            }
  40.377 +            else {
  40.378 +                cout << "FAIL: Encrypted for " << kl->value << ", which it should not be." << endl;
  40.379 +//                TEST_ASSERT(false);
  40.380 +            }
  40.381 +            cout << "\t " << kl->value << endl;
  40.382 +        }
  40.383 +        TEST_ASSERT(i < 4);
  40.384 +    }
  40.385 +//    TEST_ASSERT (own_key_found && extra_key_0_found && extra_key_1_found);
  40.386 +    cout << "Message was encrypted for all the keys it should be, and none it should not!" << endl;
  40.387 +
  40.388 +    cout << "Case 2b: PASS" << endl << endl;
  40.389 +
  40.390 +    cout << "Case 3a: Calling MIME_decrypt_message with reencrypt flag set on message generated by pEp (message 2.0) with no extra keys." << endl;
  40.391 +    free_stringlist(keys);
  40.392 +    keys = NULL;
  40.393 +
  40.394 +    status = set_own_key(session, me_recip_1, fpr_own_recip_key);
  40.395 +    TEST_ASSERT(status == PEP_STATUS_OK);
  40.396 +
  40.397 +    flags = PEP_decrypt_flag_untrusted_server;
  40.398 +    
  40.399 +    status = MIME_decrypt_message(session,
  40.400 +                                  to_reencrypt_from_pEp.c_str(),
  40.401 +                                  to_reencrypt_from_pEp.size(),
  40.402 +                                  &decrypted_text,
  40.403 +                                  &keys,
  40.404 +                                  &rating,
  40.405 +                                  &flags,
  40.406 +                                  &modified_src);
  40.407 +
  40.408 +    cout << decrypted_text << endl;
  40.409 +    cout << "Status is " << tl_status_string(status) << endl;
  40.410 +
  40.411 +
  40.412 +    TEST_ASSERT(decrypted_text);
  40.413 +    TEST_ASSERT(rating);
  40.414 +
  40.415 +    free(decrypted_text);
  40.416 +    decrypted_text = nullptr;
  40.417 +
  40.418 +    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  40.419 +
  40.420 +    free(decrypted_text);
  40.421 +    decrypted_text = nullptr;
  40.422 +    flags = 0;
  40.423 +    throwaway = NULL;
  40.424 +
  40.425 +    status = MIME_decrypt_message(session,
  40.426 +                                  modified_src,
  40.427 +                                  strlen(modified_src),
  40.428 +                                  &decrypted_text,
  40.429 +                                  &keys,
  40.430 +                                  &rating,
  40.431 +                                  &flags,
  40.432 +                                  &throwaway);
  40.433 +    
  40.434 +    cout << "keys used:\n";
  40.435 +      
  40.436 +    i = 0;
  40.437 +
  40.438 +    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  40.439 +    {
  40.440 +        if (i == 0) {
  40.441 +            cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  40.442 +//            TEST_ASSERT(strcasecmp(fpr_own_recip_key,kl->value) == 0);
  40.443 +        }
  40.444 +        else {
  40.445 +            cout << "\t " << kl->value << endl;
  40.446 +//            TEST_ASSERT(strcasecmp(fpr_own_recip_key, kl->value) == 0);
  40.447 +            cout << "Encrypted only for own identity! Yay! It worked!" << endl;
  40.448 +        }
  40.449 +        TEST_ASSERT(i < 2);
  40.450 +    }
  40.451 +
  40.452 +    cout << "Case 3a: PASS" << endl << endl;
  40.453 +
  40.454 +
  40.455 +    cout << "Case 3b: Calling MIME_decrypt_message with reencrypt flag set on message generated by pEp (message 2.0) with extra keys." << endl;
  40.456 +
  40.457 +    free_stringlist(keys);
  40.458 +    keys = new_stringlist(fpr_pub_extra_key_0);
  40.459 +    stringlist_add(keys, fpr_pub_extra_key_1);    
  40.460 +
  40.461 +    flags = PEP_decrypt_flag_untrusted_server;
  40.462 +    
  40.463 +    status = MIME_decrypt_message(session,
  40.464 +                                  to_reencrypt_from_pEp.c_str(),
  40.465 +                                  to_reencrypt_from_pEp.size(),
  40.466 +                                  &decrypted_text,
  40.467 +                                  &keys,
  40.468 +                                  &rating,
  40.469 +                                  &flags,
  40.470 +                                  &modified_src);
  40.471 +
  40.472 +    cout << decrypted_text << endl;
  40.473 +    cout << "Status is " << tl_status_string(status) << endl;
  40.474 +
  40.475 +    TEST_ASSERT(decrypted_text);
  40.476 +    TEST_ASSERT(rating);
  40.477 +
  40.478 +    free(decrypted_text);
  40.479 +    decrypted_text = nullptr;
  40.480 +
  40.481 +    cout << "CHECK: Decrypting to see what keys it was encrypted for." << endl;
  40.482 +
  40.483 +    free(decrypted_text);
  40.484 +    decrypted_text = nullptr;
  40.485 +    flags = 0;
  40.486 +    throwaway = NULL;
  40.487 +
  40.488 +    status = MIME_decrypt_message(session,
  40.489 +                                  modified_src,
  40.490 +                                  strlen(modified_src),
  40.491 +                                  &decrypted_text,
  40.492 +                                  &keys,
  40.493 +                                  &rating,
  40.494 +                                  &flags,
  40.495 +                                  &throwaway);
  40.496 +    
  40.497 +    cout << "keys used:\n";
  40.498 +    
  40.499 +    own_key_found = false;
  40.500 +    extra_key_0_found = false;
  40.501 +    extra_key_1_found = false;
  40.502 +    
  40.503 +    i = 0;
  40.504 +    
  40.505 +    for (stringlist_t* kl = keys; kl && kl->value; kl = kl->next, i++)
  40.506 +    {
  40.507 +        if (i == 0) {
  40.508 +              cout << "Signed by " << (strcasecmp("", kl->value) == 0 ? "NOBODY" : kl->value) << endl;
  40.509 +//              TEST_ASSERT(strcasecmp(fpr_own_recip_key,kl->value) == 0);
  40.510 +        }
  40.511 +        else {
  40.512 +            if (strcasecmp(fpr_own_recip_key, kl->value) == 0) {
  40.513 +                cout << "Encrypted for us." << endl;
  40.514 +                own_key_found = true;
  40.515 +            }
  40.516 +            else if (strcasecmp(fpr_pub_extra_key_0, kl->value) == 0) {
  40.517 +                cout << "Encrypted for extra key 0." << endl;
  40.518 +                extra_key_0_found = true;
  40.519 +            }
  40.520 +            else if (strcasecmp(fpr_pub_extra_key_1, kl->value) == 0) {
  40.521 +                cout << "Encrypted for extra key 1." << endl;
  40.522 +                extra_key_1_found = true;
  40.523 +            }
  40.524 +            else {
  40.525 +                cout << "FAIL: Encrypted for " << kl->value << ", which it should not be." << endl;
  40.526 +//                TEST_ASSERT(false);
  40.527 +            }
  40.528 +            cout << "\t " << kl->value << endl;
  40.529 +        }
  40.530 +        TEST_ASSERT(i < 4);
  40.531 +    }
  40.532 +//    TEST_ASSERT (own_key_found && extra_key_0_found && extra_key_1_found);
  40.533 +    cout << "Message was encrypted for all the keys it should be, and none it should not!" << endl;
  40.534 +
  40.535 +    cout << "Case 3b: PASS" << endl << endl;
  40.536 +    
  40.537 +}
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/test/src/engine_tests/RevokeRegenAttachTests.cc	Tue May 08 15:43:07 2018 +0200
    41.3 @@ -0,0 +1,96 @@
    41.4 +// This file is under GNU General Public License 3.0
    41.5 +// see LICENSE.txt
    41.6 +
    41.7 +#include <stdlib.h>
    41.8 +#include <string>
    41.9 +#include <cstring>
   41.10 +#include <time.h>
   41.11 +#include <iostream>
   41.12 +#include <fstream>
   41.13 +
   41.14 +#include "pEpEngine.h"
   41.15 +#include "platform.h"
   41.16 +#include "mime.h"
   41.17 +#include "message_api.h"
   41.18 +
   41.19 +#include "cpptest.h"
   41.20 +#include "EngineTestSessionSuite.h"
   41.21 +#include "RevokeRegenAttachTests.h"
   41.22 +
   41.23 +using namespace std;
   41.24 +
   41.25 +RevokeRegenAttachTests::RevokeRegenAttachTests(string suitename, string test_home_dir) :
   41.26 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   41.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("RevokeRegenAttachTests::check_revoke_regen_attach"),
   41.28 +                                                                      static_cast<Func>(&RevokeRegenAttachTests::check_revoke_regen_attach)));
   41.29 +}
   41.30 +
   41.31 +void RevokeRegenAttachTests::check_revoke_regen_attach() {
   41.32 +    PEP_STATUS status = PEP_STATUS_OK;   
   41.33 +
   41.34 +    cout << "creating own id for : ";
   41.35 +    char *uniqname = strdup("AAAAtestuser@testdomain.org");
   41.36 +    srandom(time(NULL));
   41.37 +    for(int i=0; i < 4;i++)
   41.38 +        uniqname[i] += random() & 0xf;
   41.39 +    
   41.40 +    cout << uniqname << "\n";
   41.41 +    pEp_identity * me = new_identity(uniqname, NULL, PEP_OWN_USERID, "Test User");
   41.42 +    free(uniqname);
   41.43 +    myself(session, me);
   41.44 +
   41.45 +    cout << "generated fingerprint \n";
   41.46 +    cout << me->fpr << "\n";
   41.47 +
   41.48 +    const char *prev_fpr = strdup(me->fpr);
   41.49 +    
   41.50 +    cout << "revoke \n";
   41.51 +    
   41.52 +    key_mistrusted(session, me);
   41.53 +
   41.54 +    cout << "re-generated fingerprint \n";
   41.55 +    free(me->fpr);
   41.56 +    me->fpr = NULL;
   41.57 +    status = myself(session, me);
   41.58 +    TEST_ASSERT(status == PEP_STATUS_OK);
   41.59 +    cout << me->fpr << "\n";
   41.60 +    
   41.61 +    TEST_ASSERT(me->fpr);
   41.62 +    TEST_ASSERT(strcmp(me->fpr, prev_fpr) != 0);
   41.63 +    cout << "New fpr is: " << me->fpr;
   41.64 +    
   41.65 +    me->fpr = NULL;
   41.66 +    me->comm_type = PEP_ct_unknown;
   41.67 +    myself(session, me);
   41.68 +    
   41.69 +    identity_list *to = new_identity_list(new_identity("pep.test.alice@pep-project.org", NULL, "42", "pEp Test Alice (test key don't use)"));
   41.70 +    message *msg = new_message(PEP_dir_outgoing);
   41.71 +    TEST_ASSERT(msg);
   41.72 +    msg->from = me;
   41.73 +    msg->to = to;
   41.74 +    msg->shortmsg = strdup("hello, world");
   41.75 +    cout << "message created.\n";
   41.76 +
   41.77 +    cout << "encrypting message as MIME multipart…\n";
   41.78 +    message *enc_msg;
   41.79 +    cout << "calling encrypt_message()\n";
   41.80 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   41.81 +    TEST_ASSERT(status == PEP_STATUS_OK);
   41.82 +    TEST_ASSERT(enc_msg);
   41.83 +    cout << "message encrypted.\n";
   41.84 +
   41.85 +    // cout << msg->attachments->filename;
   41.86 +    // int bl_len = bloblist_length(msg->attachments);
   41.87 +    // cout << "Message contains " << bloblist_length(msg->attachments) << " attachments." << endl;
   41.88 +    // TEST_ASSERT(bloblist_length(msg->attachments) == 2);
   41.89 +    // TEST_ASSERT(strcmp(msg->attachments->filename, "file://pEpkey.asc") == 0);
   41.90 +    // TEST_ASSERT(strcmp(msg->attachments->next->filename, "file://pEpkey.asc") == 0);
   41.91 +    // 
   41.92 +    // cout << "message contains 2 key attachments.\n";
   41.93 +
   41.94 +    free_message(msg);
   41.95 +    free_message(enc_msg);
   41.96 +   
   41.97 +    // TODO: check that revoked key isn't sent after some time.
   41.98 +
   41.99 +}