ENGINE-209: externally revoked and added keys should now be handled correctly in the database. ENGINE-209
authorKrista Bennett <krista@pep-project.org>
Thu, 01 Jun 2017 19:52:13 +0200
branchENGINE-209
changeset 1812925ad845e3ec
parent 1811 04d2a7abcfa2
child 1813 0dbbba72dfbb
child 1814 9a17b12aa457
ENGINE-209: externally revoked and added keys should now be handled correctly in the database.
test/Makefile
test/external_revoke_test.cc
test/test_util.cc
test/test_util.h
     1.1 --- a/test/Makefile	Wed May 31 17:47:42 2017 +0200
     1.2 +++ b/test/Makefile	Thu Jun 01 19:52:13 2017 +0200
     1.3 @@ -4,8 +4,7 @@
     1.4  
     1.5  include ../Makefile.conf
     1.6  
     1.7 -export GNUPGHOME=/home/krista/.gnupg/.
     1.8 -#export GNUPGHOME=.
     1.9 +export GNUPGHOME=.
    1.10  
    1.11  CC?=g++ -std=gnu++11 -pthread
    1.12  CXX?=g++ -std=gnu++11 -pthread
     2.1 --- a/test/external_revoke_test.cc	Wed May 31 17:47:42 2017 +0200
     2.2 +++ b/test/external_revoke_test.cc	Thu Jun 01 19:52:13 2017 +0200
     2.3 @@ -10,6 +10,7 @@
     2.4  #include <assert.h>
     2.5  #include "mime.h"
     2.6  #include "message_api.h"
     2.7 +#include "test_util.h"
     2.8  
     2.9  using namespace std;
    2.10  
    2.11 @@ -25,7 +26,8 @@
    2.12      cout << "init() completed.\n";
    2.13  
    2.14  #ifndef NETPGP
    2.15 -
    2.16 +    char* fprs[2];
    2.17 +    
    2.18      // Create sender ID
    2.19      
    2.20      pEp_identity * me = new_identity("pep.test.apple@pep-project.org", NULL, PEP_OWN_USERID, "Alice Cooper");
    2.21 @@ -35,7 +37,7 @@
    2.22      
    2.23      // Create key
    2.24  
    2.25 -    cout << "creating new id for : ";
    2.26 +    cout << "Creating new id for : ";
    2.27      char *uniqname = strdup("AAAAtestuser@testdomain.org");
    2.28      srandom(time(NULL));
    2.29      for(int i=0; i < 4;i++)
    2.30 @@ -46,178 +48,267 @@
    2.31  
    2.32      status = generate_keypair(session, recip1);
    2.33      
    2.34 -    cout << "generated fingerprint \n";
    2.35 +    cout << "Generated fingerprint ";
    2.36      cout << recip1->fpr << "\n";
    2.37  
    2.38 +    fprs[0] = strdup(recip1->fpr);
    2.39 +    
    2.40 +    cout << endl << "*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*" << endl;
    2.41 +    cout << "Trust and revoke single key, ensure trust changes, then generate new key and ensure rating is correct." << endl;
    2.42 +    cout << "*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*" << endl << endl;
    2.43 +    
    2.44 +    cout << endl << "---------------------------------------------------------" << endl;
    2.45 +    cout << "1a. Encrypt message for trusted partner." << endl;
    2.46 +    cout << "---------------------------------------------------------" << endl << endl;
    2.47 +
    2.48 +    cout << "Trusting personal key for " << uniqname << endl;
    2.49      // Trust it
    2.50      recip1->me = false;
    2.51      status = update_identity(session, recip1);
    2.52      status = trust_personal_key(session, recip1);
    2.53      status = update_identity(session, recip1);
    2.54 +    
    2.55 +    // TODO: Check trust?
    2.56 +    cout << "Done! Trusted personal key with fpr " << recip1->fpr << " for " << uniqname << endl;
    2.57  
    2.58      const char* r1_userid = (recip1->user_id ? strdup(recip1->user_id) : NULL);
    2.59  
    2.60 +    
    2.61      // encrypt something to the key
    2.62 -    cout << "creating message…\n";
    2.63 +    cout << "Creating message…\n";
    2.64      identity_list* to_list = new_identity_list(identity_dup(recip1)); // to bob
    2.65 -    message* outgoing_message = new_message(PEP_dir_outgoing);
    2.66 -    assert(outgoing_message);
    2.67 -    outgoing_message->from = identity_dup(me);
    2.68 -    outgoing_message->to = to_list;
    2.69 -    outgoing_message->shortmsg = strdup("Greetings, humans!");
    2.70 -    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
    2.71 -    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
    2.72 -    cout << "message created.\n";
    2.73 +    message* outgoing_msg = new_message(PEP_dir_outgoing);
    2.74 +    assert(outgoing_msg);
    2.75 +    outgoing_msg->from = identity_dup(me);
    2.76 +    outgoing_msg->to = to_list;
    2.77 +    outgoing_msg->shortmsg = strdup("Greetings, humans!");
    2.78 +    outgoing_msg->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
    2.79 +    outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
    2.80 +    cout << "Message created.\n";
    2.81  
    2.82      message* encrypted_outgoing_msg = NULL;
    2.83 -    
    2.84 -    status = encrypt_message(session, outgoing_message, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
    2.85 -    
    2.86 +
    2.87 +    cout << "Encrypting message to " << uniqname << "…\n";    
    2.88 +    status = encrypt_message(session, outgoing_msg, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
    2.89 +    cout << "Encrypted message with status " << tl_status_string(status) << endl;
    2.90      // check status
    2.91      assert(status == PEP_STATUS_OK);
    2.92      assert(encrypted_outgoing_msg);
    2.93  
    2.94 +    cout << "Checking message recipient comm_type from message." << endl;
    2.95      // check comm_type
    2.96 -    cout << "comm_type: " << encrypted_outgoing_msg->to->ident->comm_type << endl;
    2.97 +    cout << "comm_type: " << tl_ct_string(encrypted_outgoing_msg->to->ident->comm_type) << endl;
    2.98      assert(encrypted_outgoing_msg->to->ident->comm_type == PEP_ct_OpenPGP);
    2.99      
   2.100      status = get_trust(session, recip1);
   2.101      
   2.102 -    cout << "Recip's trust DB comm_type = " << hex << recip1->comm_type << endl;
   2.103 +    cout << "Recip's trust DB comm_type = " << hex << tl_ct_string(recip1->comm_type) << endl;
   2.104      assert(recip1->comm_type == PEP_ct_OpenPGP); // FIXME: PEP_ct_pEp???
   2.105  
   2.106      // decrypt message
   2.107 -    free_message(outgoing_message);
   2.108 -    outgoing_message = NULL;
   2.109 +    free_message(outgoing_msg);
   2.110 +    outgoing_msg = NULL;
   2.111  
   2.112      stringlist_t* keylist = nullptr;
   2.113      PEP_rating rating;
   2.114      PEP_decrypt_flags_t flags;
   2.115  
   2.116 -    status = decrypt_message(session, encrypted_outgoing_msg, &outgoing_message, &keylist, &rating, &flags);
   2.117 +    cout << endl << "---------------------------------------------------------" << endl;
   2.118 +    cout << "1b. Decrypt message that was encrypted for trusted partner." << endl;
   2.119 +    cout << "---------------------------------------------------------" << endl << endl;
   2.120 +
   2.121 +    cout << "Decrypting message." << endl;
   2.122 +    status = decrypt_message(session, encrypted_outgoing_msg, &outgoing_msg, &keylist, &rating, &flags);
   2.123 +    cout << "Decrypted message with status " << tl_status_string(status) << endl;
   2.124      assert(status == PEP_STATUS_OK);
   2.125      assert(rating == PEP_rating_trusted);
   2.126  
   2.127      // check rating
   2.128 -    cout << "Rating of decrypted message to trusted recip: " << rating << endl;
   2.129 +    cout << "Rating of decrypted message to trusted recip: " << tl_rating_string(rating) << endl;
   2.130      assert(rating == PEP_rating_trusted); // FIXME: trusted and anonymised?
   2.131      
   2.132      // check comm_type
   2.133      status = get_trust(session, recip1);
   2.134  
   2.135 -    cout << "Recip's trust DB comm_type = " << recip1->comm_type << endl;
   2.136 +    cout << "Recip's trust DB comm_type = " << tl_ct_string(recip1->comm_type) << endl;
   2.137      assert(recip1->comm_type == PEP_ct_OpenPGP); // FIXME: PEP_ct_pEp???
   2.138  
   2.139 +    cout << endl << "---------------------------------------------------------" << endl;
   2.140 +    cout << "2a. Revoke key for (currently) trusted partner." << endl;
   2.141 +    cout << "---------------------------------------------------------" << endl << endl;
   2.142      // externally revoke key
   2.143      // (note - as of 23.5.17, revoke_key() doesn't touch the trust db, just the keyring, so we can do this)
   2.144  
   2.145 -    status = get_identity(session, uniqname, r1_userid, &recip1);
   2.146 -    
   2.147 +    cout << "Revoking key." << endl;
   2.148 +    status = get_identity(session, uniqname, r1_userid, &recip1);    
   2.149      status = revoke_key(session, recip1->fpr, "encrypt_for_identity_test");
   2.150 -    
   2.151 +    cout << "Status of revocation call for " << recip1->fpr << " is "<< tl_status_string(status) << endl;
   2.152 +
   2.153      // free messages
   2.154 -    free_message(outgoing_message);
   2.155 +    free_message(outgoing_msg);
   2.156      free_message(encrypted_outgoing_msg);
   2.157 -    outgoing_message = NULL;
   2.158 +    outgoing_msg = NULL;
   2.159      encrypted_outgoing_msg = NULL;
   2.160      
   2.161      // encrypt something to the key
   2.162      cout << "creating message…\n";
   2.163      to_list = new_identity_list(identity_dup(recip1)); // to bob
   2.164 -    outgoing_message = new_message(PEP_dir_outgoing);
   2.165 -    assert(outgoing_message);
   2.166 -    outgoing_message->from = identity_dup(me);
   2.167 -    outgoing_message->to = to_list;
   2.168 -    outgoing_message->shortmsg = strdup("Greetings, humans!");
   2.169 -    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   2.170 -    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   2.171 +    outgoing_msg = new_message(PEP_dir_outgoing);
   2.172 +    assert(outgoing_msg);
   2.173 +    outgoing_msg->from = identity_dup(me);
   2.174 +    outgoing_msg->to = to_list;
   2.175 +    outgoing_msg->shortmsg = strdup("Greetings, humans!");
   2.176 +    outgoing_msg->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   2.177 +    outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   2.178      cout << "message created.\n";
   2.179  
   2.180      encrypted_outgoing_msg = NULL;
   2.181      message* decrypted_msg = NULL;
   2.182  
   2.183 -    status = encrypt_message(session, outgoing_message, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
   2.184 +    cout << endl << "---------------------------------------------------------" << endl;
   2.185 +    cout << "2b. Encrypt message for recip whose key has been externally revoked in the keyring, not the app." << endl;
   2.186 +    cout << "---------------------------------------------------------" << endl << endl;
   2.187  
   2.188 -    PEP_comm_type ct = (encrypted_outgoing_msg ? encrypted_outgoing_msg->to->ident->comm_type : outgoing_message->to->ident->comm_type);
   2.189 +    status = encrypt_message(session, outgoing_msg, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
   2.190 +    cout << "Encryption returns with status " << tl_status_string(status) << endl;
   2.191 +
   2.192 +    PEP_comm_type ct = (encrypted_outgoing_msg ? encrypted_outgoing_msg->to->ident->comm_type : outgoing_msg->to->ident->comm_type);
   2.193 +
   2.194 +    cout << endl << "---------------------------------------------------------" << endl;
   2.195 +    cout << "2c. Check trust of recip, whose only key has been revoked, once an encryption attempt has been made." << endl;
   2.196 +    cout << "---------------------------------------------------------" << endl << endl;
   2.197  
   2.198      // check comm_type
   2.199 -    cout << "comm_type: " << ct << endl;
   2.200 +    cout << "comm_type: " << tl_ct_string(ct) << endl;
   2.201      assert(ct == PEP_ct_key_revoked);
   2.202      
   2.203      status = get_trust(session, recip1);
   2.204  
   2.205 -    cout << "Recip's trust DB comm_type = " << hex << recip1->comm_type << endl;
   2.206 +    cout << "Recip's trust DB comm_type = " << hex << tl_ct_string(recip1->comm_type) << endl;
   2.207      assert(recip1->comm_type == PEP_ct_key_revoked);
   2.208  
   2.209 +    cout << endl << "---------------------------------------------------------" << endl;
   2.210 +    cout << "2d. Try to decrypt message that was encrypted for revoked key guy." << endl;
   2.211 +    cout << "---------------------------------------------------------" << endl << endl;
   2.212      // decrypt message
   2.213 -//    free_message(outgoing_message);
   2.214 -//    outgoing_message = NULL;
   2.215 -
   2.216 -    status = decrypt_message(session, outgoing_message, &decrypted_msg, &keylist, &rating, &flags);
   2.217 +//    free_message(outgoing_msg);
   2.218 +//    outgoing_msg = NULL;
   2.219 +    // FIXME: Make this make more sense
   2.220 +    status = decrypt_message(session, outgoing_msg, &decrypted_msg, &keylist, &rating, &flags);
   2.221 +    cout << "Decryption returns with status " << tl_status_string(status) << endl;
   2.222      assert(status == PEP_UNENCRYPTED);
   2.223 -
   2.224 +    
   2.225      // check rating
   2.226 -    cout << "Rating of decrypted message to trusted recip: " << rating << endl;
   2.227 +    cout << "Rating of decrypted message to trusted recip: " << tl_rating_string(rating) << endl;
   2.228      assert(rating == PEP_rating_unencrypted);
   2.229  
   2.230 -    ct = (decrypted_msg ? decrypted_msg->to->ident->comm_type : outgoing_message->to->ident->comm_type);
   2.231 +    ct = (decrypted_msg ? decrypted_msg->to->ident->comm_type : outgoing_msg->to->ident->comm_type);
   2.232  
   2.233 -    cout << "comm_type: " << ct << endl;
   2.234 +    cout << "comm_type: " << tl_ct_string(ct) << endl;
   2.235      assert(ct == PEP_ct_key_revoked);
   2.236      
   2.237      status = get_trust(session, recip1);
   2.238      
   2.239 -    cout << "Recip's trust DB comm_type = " << hex << recip1->comm_type << endl;
   2.240 +    cout << "Recip's trust DB comm_type = " << hex << tl_ct_string(recip1->comm_type) << endl;
   2.241      assert(recip1->comm_type == PEP_ct_key_revoked);
   2.242  
   2.243 -    // generate new key
   2.244 +    free_message(encrypted_outgoing_msg);
   2.245 +    free_message(decrypted_msg);
   2.246 +    free_message(outgoing_msg);
   2.247 +    outgoing_msg = NULL;
   2.248 +    decrypted_msg = NULL;
   2.249 +    encrypted_outgoing_msg = NULL;
   2.250 +
   2.251 +    cout << endl << "---------------------------------------------------------" << endl;
   2.252 +    cout << "3a. Generate new key, but don't explicitly trust it." << endl;
   2.253 +    cout << "---------------------------------------------------------" << endl << endl;
   2.254 +
   2.255 +    // now: generate new key
   2.256 +    free(recip1->fpr);
   2.257 +    recip1->fpr = NULL;
   2.258      status = generate_keypair(session, recip1);
   2.259      
   2.260 -    cout << "generated fingerprint \n";
   2.261 +    cout << "Generated fingerprint \n";
   2.262      cout << recip1->fpr << "\n";
   2.263 +    fprs[1] = strdup(recip1->fpr);
   2.264  
   2.265 -    // PART DEUX
   2.266 +    // try again
   2.267 +    cout << endl << "---------------------------------------------------------" << endl;
   2.268 +    cout << "3b. Try to send something to the email address of our revoked friend, make sure a new key is used to encrypt." << endl;
   2.269 +    cout << "---------------------------------------------------------" << endl << endl;
   2.270      
   2.271 -    // Create key
   2.272 +    // encrypt something to the key
   2.273 +    cout << "Creating message…\n";
   2.274 +    to_list = new_identity_list(identity_dup(recip1)); // to bob
   2.275 +    outgoing_msg = new_message(PEP_dir_outgoing);
   2.276 +    assert(outgoing_msg);
   2.277 +    outgoing_msg->from = identity_dup(me);
   2.278 +    outgoing_msg->to = to_list;
   2.279 +    outgoing_msg->shortmsg = strdup("Greetings, humans!");
   2.280 +    outgoing_msg->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   2.281 +    outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   2.282 +    cout << "Message created.\n";
   2.283  
   2.284 -    // DO NOT trust it
   2.285 +    status = encrypt_message(session, outgoing_msg, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
   2.286  
   2.287 -    // encrypt something to the key
   2.288 +    ct = (encrypted_outgoing_msg ? encrypted_outgoing_msg->to->ident->comm_type : outgoing_msg->to->ident->comm_type);
   2.289 +
   2.290 +    // CHECK STATUS???
   2.291 +    cout << "Encryption returns with status " << tl_status_string(status) << endl;
   2.292 +
   2.293 +    // check comm_type
   2.294 +    cout << "comm_type: " << tl_ct_string(ct) << endl;
   2.295 +    assert(ct == PEP_ct_OpenPGP_unconfirmed);
   2.296 +    
   2.297 +    status = get_trust(session, recip1);
   2.298 +
   2.299 +    cout << "Recip's trust DB comm_type = " << hex << tl_ct_string(recip1->comm_type) << endl;
   2.300 +    assert(recip1->comm_type == PEP_ct_OpenPGP_unconfirmed);
   2.301 +
   2.302 +    // decrypt message
   2.303 +//    free_message(outgoing_msg);
   2.304 +//    outgoing_msg = NULL;
   2.305 +
   2.306 +    cout << endl << "---------------------------------------------------------" << endl;
   2.307 +    cout << "3c. Decrypt... that... message!" << endl;
   2.308 +    cout << "---------------------------------------------------------" << endl << endl;
   2.309 +
   2.310 +
   2.311 +    status = decrypt_message(session, encrypted_outgoing_msg, &decrypted_msg, &keylist, &rating, &flags);
   2.312 +    cout << "Decryption returns with status " << tl_status_string(status) << endl;
   2.313 +    assert(status == PEP_STATUS_OK);
   2.314  
   2.315      // check rating
   2.316 +    cout << "Rating of decrypted message to trusted recip: " << tl_rating_string(rating) << endl;
   2.317 +    assert(rating == PEP_rating_reliable);
   2.318  
   2.319 -    // check comm_type
   2.320 +    ct = (decrypted_msg ? decrypted_msg->to->ident->comm_type : outgoing_msg->to->ident->comm_type);
   2.321  
   2.322 -    // externally revoke key
   2.323 +    cout << "comm_type: " << tl_ct_string(ct) << endl;
   2.324 +    assert(ct == PEP_ct_OpenPGP_unconfirmed);
   2.325      
   2.326 -    // encrypt something to the key
   2.327 +    status = get_trust(session, recip1);
   2.328 +    
   2.329 +    cout << "Recip's trust DB comm_type = " << hex << tl_ct_string(recip1->comm_type) << endl;
   2.330 +    assert(recip1->comm_type == PEP_ct_OpenPGP_unconfirmed);
   2.331  
   2.332 -    // check rating
   2.333 +    free_message(encrypted_outgoing_msg);
   2.334 +    free_message(decrypted_msg);
   2.335 +    free_message(outgoing_msg);
   2.336 +    outgoing_msg = NULL;
   2.337 +    decrypted_msg = NULL;
   2.338 +    encrypted_outgoing_msg = NULL;
   2.339  
   2.340 -    // check comm_type
   2.341 -
   2.342 -
   2.343 -    // PART TROIS
   2.344 +    free_identity(me);
   2.345 +    free_identity(recip1);
   2.346 +    free(uniqname);
   2.347      
   2.348 -    // Create key
   2.349 -
   2.350 -    // DO NOT trust it
   2.351 -
   2.352 -    // encrypt something to the key
   2.353 -
   2.354 -    // check rating
   2.355 -
   2.356 -    // check comm_type
   2.357 -
   2.358 -    // externally revoke key
   2.359 +    delete_keypair(session, fprs[0]);    
   2.360 +    delete_keypair(session, fprs[1]);
   2.361      
   2.362 -    // encrypt something to the key
   2.363 -
   2.364 -    // check rating
   2.365 -
   2.366 -    // check comm_type
   2.367 +    free(fprs[0]);
   2.368 +    free(fprs[1]);
   2.369      
   2.370 -    free(uniqname);
   2.371  #else
   2.372      cout << "Sorry, test is not defined for NETPGP at this time." << endl;
   2.373      
     3.1 --- a/test/test_util.cc	Wed May 31 17:47:42 2017 +0200
     3.2 +++ b/test/test_util.cc	Thu Jun 01 19:52:13 2017 +0200
     3.3 @@ -1,4 +1,6 @@
     3.4  #include "pEpEngine_test.h"
     3.5 +#include "pEpEngine.h"
     3.6 +#include "message_api.h"
     3.7  #include <fstream>
     3.8  #include <sstream>
     3.9  #include <stdexcept>
    3.10 @@ -15,3 +17,237 @@
    3.11  	sstr << input.rdbuf();
    3.12  	return sstr.str();
    3.13  }
    3.14 +
    3.15 +const char* tl_status_string(PEP_STATUS status) {
    3.16 +    switch (status) {
    3.17 +        case PEP_STATUS_OK:
    3.18 +            return "PEP_STATUS_OK";
    3.19 +        case PEP_INIT_CANNOT_LOAD_GPGME:
    3.20 +            return "PEP_INIT_CANNOT_LOAD_GPGME";
    3.21 +        case PEP_INIT_GPGME_INIT_FAILED:
    3.22 +            return "PEP_INIT_GPGME_INIT_FAILED";
    3.23 +        case PEP_INIT_NO_GPG_HOME:
    3.24 +            return "PEP_INIT_NO_GPG_HOME";
    3.25 +        case PEP_INIT_NETPGP_INIT_FAILED:
    3.26 +            return "PEP_INIT_NETPGP_INIT_FAILED";
    3.27 +        case PEP_INIT_SQLITE3_WITHOUT_MUTEX:
    3.28 +            return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
    3.29 +        case PEP_INIT_CANNOT_OPEN_DB:
    3.30 +            return "PEP_INIT_CANNOT_OPEN_DB";
    3.31 +        case PEP_INIT_CANNOT_OPEN_SYSTEM_DB:
    3.32 +            return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
    3.33 +        case PEP_KEY_NOT_FOUND:
    3.34 +            return "PEP_KEY_NOT_FOUND";
    3.35 +        case PEP_KEY_HAS_AMBIG_NAME:
    3.36 +            return "PEP_KEY_HAS_AMBIG_NAME";
    3.37 +        case PEP_GET_KEY_FAILED:
    3.38 +            return "PEP_GET_KEY_FAILED";
    3.39 +        case PEP_CANNOT_EXPORT_KEY:
    3.40 +            return "PEP_CANNOT_EXPORT_KEY";
    3.41 +        case PEP_CANNOT_EDIT_KEY:
    3.42 +            return "PEP_CANNOT_EDIT_KEY";
    3.43 +        case PEP_CANNOT_FIND_IDENTITY:
    3.44 +            return "PEP_CANNOT_FIND_IDENTITY";
    3.45 +        case PEP_CANNOT_SET_PERSON:
    3.46 +            return "PEP_CANNOT_SET_PERSON";
    3.47 +        case PEP_CANNOT_SET_PGP_KEYPAIR:
    3.48 +            return "PEP_CANNOT_SET_PGP_KEYPAIR";
    3.49 +        case PEP_CANNOT_SET_IDENTITY:
    3.50 +            return "PEP_CANNOT_SET_IDENTITY";
    3.51 +        case PEP_CANNOT_SET_TRUST:
    3.52 +            return "PEP_CANNOT_SET_TRUST";
    3.53 +        case PEP_KEY_BLACKLISTED:
    3.54 +            return "PEP_KEY_BLACKLISTED";
    3.55 +        case PEP_UNENCRYPTED:
    3.56 +            return "PEP_UNENCRYPTED";
    3.57 +        case PEP_VERIFIED:
    3.58 +            return "PEP_VERIFIED";
    3.59 +        case PEP_DECRYPTED:
    3.60 +            return "PEP_DECRYPTED";
    3.61 +        case PEP_DECRYPTED_AND_VERIFIED:
    3.62 +            return "PEP_DECRYPTED_AND_VERIFIED";
    3.63 +        case PEP_DECRYPT_WRONG_FORMAT:
    3.64 +            return "PEP_DECRYPT_WRONG_FORMAT";
    3.65 +        case PEP_DECRYPT_NO_KEY:
    3.66 +            return "PEP_DECRYPT_NO_KEY";
    3.67 +        case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH:
    3.68 +            return "PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH";
    3.69 +        case PEP_VERIFY_NO_KEY:
    3.70 +            return "PEP_VERIFY_NO_KEY";
    3.71 +        case PEP_VERIFIED_AND_TRUSTED:
    3.72 +            return "PEP_VERIFIED_AND_TRUSTED";
    3.73 +        case PEP_CANNOT_DECRYPT_UNKNOWN:
    3.74 +            return "PEP_CANNOT_DECRYPT_UNKNOWN";
    3.75 +        case PEP_TRUSTWORD_NOT_FOUND:
    3.76 +            return "PEP_TRUSTWORD_NOT_FOUND";
    3.77 +        case PEP_TRUSTWORDS_FPR_WRONG_LENGTH:
    3.78 +            return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
    3.79 +        case PEP_CANNOT_CREATE_KEY:
    3.80 +            return "PEP_CANNOT_CREATE_KEY";
    3.81 +        case PEP_CANNOT_SEND_KEY:
    3.82 +            return "PEP_CANNOT_SEND_KEY";
    3.83 +        case PEP_PHRASE_NOT_FOUND:
    3.84 +            return "PEP_PHRASE_NOT_FOUND";
    3.85 +        case PEP_SEND_FUNCTION_NOT_REGISTERED:
    3.86 +            return "PEP_SEND_FUNCTION_NOT_REGISTERED";
    3.87 +        case PEP_CONTRAINTS_VIOLATED:
    3.88 +            return "PEP_CONTRAINTS_VIOLATED";
    3.89 +        case PEP_CANNOT_ENCODE:
    3.90 +            return "PEP_CANNOT_ENCODE";
    3.91 +        case PEP_SYNC_NO_NOTIFY_CALLBACK:
    3.92 +            return "PEP_SYNC_NO_NOTIFY_CALLBACK";
    3.93 +        case PEP_SYNC_ILLEGAL_MESSAGE:
    3.94 +            return "PEP_SYNC_ILLEGAL_MESSAGE";
    3.95 +        case PEP_SYNC_NO_INJECT_CALLBACK:
    3.96 +            return "PEP_SYNC_NO_INJECT_CALLBACK";
    3.97 +        case PEP_SEQUENCE_VIOLATED:
    3.98 +            return "PEP_SEQUENCE_VIOLATED";
    3.99 +        case PEP_CANNOT_INCREASE_SEQUENCE:
   3.100 +            return "PEP_CANNOT_INCREASE_SEQUENCE";
   3.101 +        case PEP_CANNOT_SET_SEQUENCE_VALUE:
   3.102 +            return "PEP_CANNOT_SET_SEQUENCE_VALUE";
   3.103 +        case PEP_OWN_SEQUENCE:
   3.104 +            return "PEP_OWN_SEQUENCE";
   3.105 +        case PEP_SYNC_STATEMACHINE_ERROR:
   3.106 +            return "PEP_SYNC_STATEMACHINE_ERROR";
   3.107 +        case PEP_SYNC_NO_TRUST:
   3.108 +            return "PEP_SYNC_NO_TRUST";
   3.109 +        case PEP_STATEMACHINE_INVALID_STATE:
   3.110 +            return "PEP_STATEMACHINE_INVALID_STATE";
   3.111 +        case PEP_STATEMACHINE_INVALID_EVENT:
   3.112 +            return "PEP_STATEMACHINE_INVALID_EVENT";
   3.113 +        case PEP_STATEMACHINE_INVALID_CONDITION:
   3.114 +            return "PEP_STATEMACHINE_INVALID_CONDITION";
   3.115 +        case PEP_STATEMACHINE_INVALID_ACTION:
   3.116 +            return "PEP_STATEMACHINE_INVALID_ACTION";
   3.117 +        case PEP_STATEMACHINE_INHIBITED_EVENT:
   3.118 +            return "PEP_STATEMACHINE_INHIBITED_EVENT";
   3.119 +        case PEP_COMMIT_FAILED:
   3.120 +            return "PEP_COMMIT_FAILED";
   3.121 +        case PEP_MESSAGE_CONSUME:
   3.122 +            return "PEP_MESSAGE_CONSUME";
   3.123 +        case PEP_MESSAGE_IGNORE:
   3.124 +            return "PEP_MESSAGE_IGNORE";
   3.125 +        case PEP_RECORD_NOT_FOUND:
   3.126 +            return "PEP_RECORD_NOT_FOUND";
   3.127 +        case PEP_CANNOT_CREATE_TEMP_FILE:
   3.128 +            return "PEP_CANNOT_CREATE_TEMP_FILE";
   3.129 +        case PEP_ILLEGAL_VALUE:
   3.130 +            return "PEP_ILLEGAL_VALUE";
   3.131 +        case PEP_BUFFER_TOO_SMALL:
   3.132 +            return "PEP_BUFFER_TOO_SMALL";
   3.133 +        case PEP_OUT_OF_MEMORY:
   3.134 +            return "PEP_OUT_OF_MEMORY";
   3.135 +        case PEP_UNKNOWN_ERROR:
   3.136 +            return "PEP_UNKNOWN_ERROR";
   3.137 +        default:
   3.138 +            return "PEP_STATUS_OMGWTFBBQ - This means you're using a status the test lib doesn't know about!";
   3.139 +    }
   3.140 +}
   3.141 +const char* tl_rating_string(PEP_rating rating) {
   3.142 +    switch (rating) {
   3.143 +        case PEP_rating_undefined:
   3.144 +            return "PEP_rating_undefined";
   3.145 +        case PEP_rating_cannot_decrypt:
   3.146 +            return "PEP_rating_cannot_decrypt";
   3.147 +        case PEP_rating_have_no_key:
   3.148 +            return "PEP_rating_have_no_key";
   3.149 +        case PEP_rating_unencrypted:
   3.150 +            return "PEP_rating_unencrypted";
   3.151 +        case PEP_rating_unencrypted_for_some:
   3.152 +            return "PEP_rating_unencrypted_for_some";
   3.153 +        case PEP_rating_unreliable:
   3.154 +            return "PEP_rating_unreliable";
   3.155 +        case PEP_rating_reliable:
   3.156 +            return "PEP_rating_reliable";
   3.157 +        case PEP_rating_trusted:
   3.158 +            return "PEP_rating_trusted";
   3.159 +        case PEP_rating_trusted_and_anonymized:
   3.160 +            return "PEP_rating_trusted_and_anonymized";
   3.161 +        case PEP_rating_fully_anonymous:
   3.162 +            return "PEP_rating_fully_anonymous";
   3.163 +        case PEP_rating_mistrust:
   3.164 +            return "PEP_rating_mistrust";
   3.165 +        case PEP_rating_b0rken:
   3.166 +            return "PEP_rating_b0rken";
   3.167 +        case PEP_rating_under_attack:
   3.168 +            return "PEP_rating_under_attack";
   3.169 +        default:
   3.170 +            return "PEP_rating_OMGWTFBBQ - in other words, INVALID RATING VALUE!!!\n\nSomething bad is going on here, or a new rating value has been added to the enum and not the test function.";
   3.171 +    }
   3.172 +}
   3.173 +
   3.174 +const char* tl_ct_string(PEP_comm_type ct) {
   3.175 +    switch (ct) {
   3.176 +        case PEP_ct_unknown:
   3.177 +            return "PEP_ct_unknown";
   3.178 +        case PEP_ct_no_encryption:
   3.179 +            return "PEP_ct_no_encryption";
   3.180 +        case PEP_ct_no_encrypted_channel:
   3.181 +            return "PEP_ct_no_encrypted_channel";
   3.182 +        case PEP_ct_key_not_found:
   3.183 +            return "PEP_ct_key_not_found";
   3.184 +        case PEP_ct_key_expired:
   3.185 +            return "PEP_ct_key_expired";
   3.186 +        case PEP_ct_key_revoked:
   3.187 +            return "PEP_ct_key_revoked";
   3.188 +        case PEP_ct_key_b0rken:
   3.189 +            return "PEP_ct_key_b0rken";
   3.190 +        case PEP_ct_my_key_not_included:
   3.191 +            return "PEP_ct_my_key_not_included";
   3.192 +        case PEP_ct_security_by_obscurity:
   3.193 +            return "PEP_ct_security_by_obscurity";
   3.194 +        case PEP_ct_b0rken_crypto:
   3.195 +            return "PEP_ct_b0rken_crypto";
   3.196 +        case PEP_ct_key_too_short:
   3.197 +            return "PEP_ct_key_too_short";
   3.198 +        case PEP_ct_compromized:
   3.199 +            return "PEP_ct_compromized";
   3.200 +        case PEP_ct_mistrusted:
   3.201 +            return "PEP_ct_mistrusted";
   3.202 +        case PEP_ct_unconfirmed_encryption:
   3.203 +            return "PEP_ct_unconfirmed_encryption";
   3.204 +        case PEP_ct_OpenPGP_weak_unconfirmed:
   3.205 +            return "PEP_ct_OpenPGP_weak_unconfirmed";
   3.206 +        case PEP_ct_to_be_checked:
   3.207 +            return "PEP_ct_to_be_checked";
   3.208 +        case PEP_ct_SMIME_unconfirmed:
   3.209 +            return "PEP_ct_SMIME_unconfirmed";
   3.210 +        case PEP_ct_CMS_unconfirmed:
   3.211 +            return "PEP_ct_CMS_unconfirmed";
   3.212 +        case PEP_ct_strong_but_unconfirmed:
   3.213 +            return "PEP_ct_strong_but_unconfirmed";
   3.214 +        case PEP_ct_OpenPGP_unconfirmed:
   3.215 +            return "PEP_ct_OpenPGP_unconfirmed";
   3.216 +        case PEP_ct_OTR_unconfirmed:
   3.217 +            return "PEP_ct_OTR_unconfirmed";
   3.218 +        case PEP_ct_unconfirmed_enc_anon:
   3.219 +            return "PEP_ct_unconfirmed_enc_anon";
   3.220 +        case PEP_ct_pEp_unconfirmed:
   3.221 +            return "PEP_ct_pEp_unconfirmed";
   3.222 +        case PEP_ct_confirmed:
   3.223 +            return "PEP_ct_pEp_confirmed";
   3.224 +        case PEP_ct_confirmed_encryption:
   3.225 +            return "PEP_ct_confirmed_encryption";
   3.226 +        case PEP_ct_OpenPGP_weak:
   3.227 +            return "PEP_ct_OpenPGP_weak";
   3.228 +        case PEP_ct_to_be_checked_confirmed:
   3.229 +            return "PEP_ct_to_be_checked_confirmed";
   3.230 +        case PEP_ct_SMIME:
   3.231 +            return "PEP_ct_SMIME";
   3.232 +        case PEP_ct_CMS:
   3.233 +            return "PEP_ct_CMS";
   3.234 +        case PEP_ct_strong_encryption:
   3.235 +            return "PEP_ct_strong_encryption";
   3.236 +        case PEP_ct_OpenPGP:
   3.237 +            return "PEP_ct_OpenPGP";
   3.238 +        case PEP_ct_OTR:
   3.239 +            return "PEP_ct_OTR";
   3.240 +        case PEP_ct_confirmed_enc_anon:
   3.241 +            return "PEP_ct_confirmed_enc_anon";
   3.242 +        case PEP_ct_pEp:
   3.243 +            return "PEP_ct_pEp";
   3.244 +        default:
   3.245 +            return "PEP_ct_OMGWTFBBQ\n\nIn other words, comm type is invalid. Either something's corrupt or a new ct value has been added to the enum but not to the test function.";
   3.246 +    }
   3.247 +}
     4.1 --- a/test/test_util.h	Wed May 31 17:47:42 2017 +0200
     4.2 +++ b/test/test_util.h	Thu Jun 01 19:52:13 2017 +0200
     4.3 @@ -1,5 +1,16 @@
     4.4  #include <string>
     4.5 +#include "pEpEngine.h"
     4.6 +#include "message_api.h"
     4.7  
     4.8  // reads a whole file and returns it as std::string
     4.9  // throws std::runtime_error() if the file cannot be read. Empty file is not an error.
    4.10  std::string slurp(const std::string& filename);
    4.11 +
    4.12 +// Returns the string value of the input rating enum value. 
    4.13 +const char* tl_rating_string(PEP_rating rating);
    4.14 +
    4.15 +// Returns the string value of the input comm_type enum value. 
    4.16 +const char* tl_ct_string(PEP_comm_type ct);
    4.17 +
    4.18 +// Returns the string value of the input status enum value. 
    4.19 +const char* tl_status_string(PEP_STATUS status);