ENGINE-209: fixed test - works with only key revoked. Now to add a key and make sure trust is correct, as well as testing with multiple keys. ENGINE-209
authorKrista Bennett <krista@pep-project.org>
Mon, 29 May 2017 11:08:13 +0200
branchENGINE-209
changeset 1808121361c60644
parent 1807 795d1b201b6f
child 1810 0beaab16a32c
ENGINE-209: fixed test - works with only key revoked. Now to add a key and make sure trust is correct, as well as testing with multiple keys.
test/apple_mail_test.cc
test/external_revoke_test.cc
     1.1 --- a/test/apple_mail_test.cc	Wed May 24 13:16:49 2017 +0200
     1.2 +++ b/test/apple_mail_test.cc	Mon May 29 11:08:13 2017 +0200
     1.3 @@ -26,13 +26,9 @@
     1.4  
     1.5      const string keytextkey1 = slurp("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
     1.6      const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
     1.7 -    const string keytextkey3 = slurp("test_keys/priv/pep-test-apple-0x1CCBC7D7_priv.asc");
     1.8 -    const string keytextkey4 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
     1.9  
    1.10      PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
    1.11      PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
    1.12 -    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
    1.13 -    PEP_STATUS statuskey4 = import_key(session, keytextkey4.c_str(), keytextkey4.length(), NULL);
    1.14          
    1.15      const string mailtext = slurp(mailfile);
    1.16      pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", NULL, PEP_OWN_USERID, "pEp Test Recipient");    
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/external_revoke_test.cc	Mon May 29 11:08:13 2017 +0200
     2.3 @@ -0,0 +1,225 @@
     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 <time.h>
    2.10 +#include "platform.h"
    2.11 +#include <iostream>
    2.12 +#include <fstream>
    2.13 +#include <assert.h>
    2.14 +#include "mime.h"
    2.15 +#include "message_api.h"
    2.16 +
    2.17 +using namespace std;
    2.18 +
    2.19 +int main() {
    2.20 +    cout << "\n*** external_revoke_test.cc ***\n\n";
    2.21 +
    2.22 +    PEP_SESSION session;
    2.23 +    
    2.24 +    cout << "calling init()\n";
    2.25 +    PEP_STATUS status = init(&session);   
    2.26 +    assert(status == PEP_STATUS_OK);
    2.27 +    assert(session);
    2.28 +    cout << "init() completed.\n";
    2.29 +
    2.30 +#ifndef NETPGP
    2.31 +
    2.32 +    // Create sender ID
    2.33 +    
    2.34 +    pEp_identity * me = new_identity("pep.test.apple@pep-project.org", NULL, PEP_OWN_USERID, "Alice Cooper");
    2.35 +    status = update_identity(session, me);
    2.36 +    status = trust_personal_key(session, me);
    2.37 +    status = update_identity(session, me);
    2.38 +    
    2.39 +    // Create key
    2.40 +
    2.41 +    cout << "creating new id for : ";
    2.42 +    char *uniqname = strdup("AAAAtestuser@testdomain.org");
    2.43 +    srandom(time(NULL));
    2.44 +    for(int i=0; i < 4;i++)
    2.45 +        uniqname[i] += random() & 0xf;
    2.46 +    
    2.47 +    cout << uniqname << "\n";
    2.48 +    pEp_identity * recip1 = new_identity(uniqname, NULL, NULL, "Test User");
    2.49 +
    2.50 +    status = generate_keypair(session, recip1);
    2.51 +    
    2.52 +    cout << "generated fingerprint \n";
    2.53 +    cout << recip1->fpr << "\n";
    2.54 +
    2.55 +    // Trust it
    2.56 +    recip1->me = false;
    2.57 +    status = update_identity(session, recip1);
    2.58 +    status = trust_personal_key(session, recip1);
    2.59 +    status = update_identity(session, recip1);
    2.60 +
    2.61 +    const char* r1_userid = (recip1->user_id ? strdup(recip1->user_id) : NULL);
    2.62 +
    2.63 +    // encrypt something to the key
    2.64 +    cout << "creating message…\n";
    2.65 +    identity_list* to_list = new_identity_list(identity_dup(recip1)); // to bob
    2.66 +    message* outgoing_message = new_message(PEP_dir_outgoing);
    2.67 +    assert(outgoing_message);
    2.68 +    outgoing_message->from = identity_dup(me);
    2.69 +    outgoing_message->to = to_list;
    2.70 +    outgoing_message->shortmsg = strdup("Greetings, humans!");
    2.71 +    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
    2.72 +    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
    2.73 +    cout << "message created.\n";
    2.74 +
    2.75 +    message* encrypted_outgoing_msg = NULL;
    2.76 +    
    2.77 +    status = encrypt_message(session, outgoing_message, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
    2.78 +    
    2.79 +    // check status
    2.80 +    assert(status == PEP_STATUS_OK);
    2.81 +    assert(encrypted_outgoing_msg);
    2.82 +
    2.83 +    // check comm_type
    2.84 +    cout << "comm_type: " << encrypted_outgoing_msg->to->ident->comm_type << endl;
    2.85 +
    2.86 +    assert(encrypted_outgoing_msg->to->ident->comm_type == PEP_ct_OpenPGP);
    2.87 +    status = get_trust(session, recip1);
    2.88 +    
    2.89 +    cout << "Recip's trust DB comm_type = " << hex << recip1->comm_type << endl;
    2.90 +    assert(recip1->comm_type == PEP_ct_OpenPGP);
    2.91 +
    2.92 +    // decrypt message
    2.93 +    free_message(outgoing_message);
    2.94 +    outgoing_message = NULL;
    2.95 +
    2.96 +    stringlist_t* keylist = nullptr;
    2.97 +    PEP_rating rating;
    2.98 +    PEP_decrypt_flags_t flags;
    2.99 +
   2.100 +    status = decrypt_message(session, encrypted_outgoing_msg, &outgoing_message, &keylist, &rating, &flags);
   2.101 +    assert(status == PEP_STATUS_OK);
   2.102 +    assert(rating >= PEP_rating_trusted);
   2.103 +
   2.104 +    // check rating
   2.105 +    cout << "Rating of decrypted message to trusted recip: " << rating << endl;
   2.106 +
   2.107 +    // check comm_type
   2.108 +    status = get_trust(session, recip1);
   2.109 +    
   2.110 +    cout << "Recip's trust DB comm_type = " << recip1->comm_type << endl;
   2.111 +
   2.112 +    // externally revoke key
   2.113 +    // (note - as of 23.5.17, revoke_key() doesn't touch the trust db, just the keyring, so we can do this)
   2.114 +
   2.115 +    status = get_identity(session, uniqname, r1_userid, &recip1);
   2.116 +    
   2.117 +    status = revoke_key(session, recip1->fpr, "encrypt_for_identity_test");
   2.118 +
   2.119 +    
   2.120 +    // free messages
   2.121 +    free_message(outgoing_message);
   2.122 +    free_message(encrypted_outgoing_msg);
   2.123 +    outgoing_message = NULL;
   2.124 +    encrypted_outgoing_msg = NULL;
   2.125 +    
   2.126 +    // encrypt something to the key
   2.127 +    cout << "creating message…\n";
   2.128 +    to_list = new_identity_list(identity_dup(recip1)); // to bob
   2.129 +    outgoing_message = new_message(PEP_dir_outgoing);
   2.130 +    assert(outgoing_message);
   2.131 +    outgoing_message->from = identity_dup(me);
   2.132 +    outgoing_message->to = to_list;
   2.133 +    outgoing_message->shortmsg = strdup("Greetings, humans!");
   2.134 +    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   2.135 +    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   2.136 +    cout << "message created.\n";
   2.137 +
   2.138 +    encrypted_outgoing_msg = NULL;
   2.139 +    message* decrypted_msg = NULL;
   2.140 +
   2.141 +    status = encrypt_message(session, outgoing_message, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
   2.142 +
   2.143 +    // check comm_type
   2.144 +    if (encrypted_outgoing_msg)
   2.145 +        cout << "comm_type: " << encrypted_outgoing_msg->to->ident->comm_type << endl;
   2.146 +    else
   2.147 +        cout << "comm_type: " << outgoing_message->to->ident->comm_type << endl;
   2.148 +        
   2.149 +    status = get_trust(session, recip1);
   2.150 +
   2.151 +    cout << "Recip's trust DB comm_type = " << hex << recip1->comm_type << endl;
   2.152 +
   2.153 +    // decrypt message
   2.154 +//    free_message(outgoing_message);
   2.155 +//    outgoing_message = NULL;
   2.156 +
   2.157 +    status = decrypt_message(session, outgoing_message, &decrypted_msg, &keylist, &rating, &flags);
   2.158 +
   2.159 +    // check rating
   2.160 +    cout << "Rating of decrypted message to trusted recip: " << rating << endl;
   2.161 +
   2.162 +    // check comm_type
   2.163 +    if (decrypted_msg)
   2.164 +        cout << "comm_type: " << decrypted_msg->to->ident->comm_type << endl;
   2.165 +    else
   2.166 +        cout << "comm_type: " << outgoing_message->to->ident->comm_type << endl;
   2.167 +    
   2.168 +    status = get_trust(session, recip1);
   2.169 +    
   2.170 +    cout << "Recip's trust DB comm_type = " << hex << recip1->comm_type << endl;
   2.171 +
   2.172 +    // generate new key
   2.173 +    status = generate_keypair(session, recip1);
   2.174 +    
   2.175 +    cout << "generated fingerprint \n";
   2.176 +    cout << recip1->fpr << "\n";
   2.177 +
   2.178 +    // PART DEUX
   2.179 +    
   2.180 +    // Create key
   2.181 +
   2.182 +    // DO NOT trust it
   2.183 +
   2.184 +    // encrypt something to the key
   2.185 +
   2.186 +    // check rating
   2.187 +
   2.188 +    // check comm_type
   2.189 +
   2.190 +    // externally revoke key
   2.191 +    
   2.192 +    // encrypt something to the key
   2.193 +
   2.194 +    // check rating
   2.195 +
   2.196 +    // check comm_type
   2.197 +
   2.198 +
   2.199 +    // PART TROIS
   2.200 +    
   2.201 +    // Create key
   2.202 +
   2.203 +    // DO NOT trust it
   2.204 +
   2.205 +    // encrypt something to the key
   2.206 +
   2.207 +    // check rating
   2.208 +
   2.209 +    // check comm_type
   2.210 +
   2.211 +    // externally revoke key
   2.212 +    
   2.213 +    // encrypt something to the key
   2.214 +
   2.215 +    // check rating
   2.216 +
   2.217 +    // check comm_type
   2.218 +    
   2.219 +    free(uniqname);
   2.220 +#else
   2.221 +    cout << "Sorry, test is not defined for NETPGP at this time." << endl;
   2.222 +    
   2.223 +#endif
   2.224 +    
   2.225 +    release(session);
   2.226 +
   2.227 +    return 0;
   2.228 +}