ENGINE 84: #comment tested, appears to work. ENGINE-84
authorKrista Grothoff <krista@pep-project.org>
Fri, 11 Nov 2016 14:08:20 +0100
branchENGINE-84
changeset 137720be7d9a7536
parent 1371 e2423e1df7e7
child 1378 b2b2c6d361c9
ENGINE 84: #comment tested, appears to work.
src/pEpEngine.h
test/encrypt_missing_private_key_test.cc
test/test_keys/priv/blacklist_self.asc
test/test_keys/pub/blacklist_self_pub.asc
test/test_mails/blacklist_no_key.eml
     1.1 --- a/src/pEpEngine.h	Tue Nov 08 17:57:06 2016 +0100
     1.2 +++ b/src/pEpEngine.h	Fri Nov 11 14:08:20 2016 +0100
     1.3 @@ -999,7 +999,7 @@
     1.4      );
     1.5  
     1.6  
     1.7 -// find_keys() - find keys in keyring
     1.8 +// find_private_keys() - find keys in keyring
     1.9  //
    1.10  //  parameters:
    1.11  //      session (in)            session handle
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/encrypt_missing_private_key_test.cc	Fri Nov 11 14:08:20 2016 +0100
     2.3 @@ -0,0 +1,121 @@
     2.4 +#include <iostream>
     2.5 +#include <iostream>
     2.6 +#include <fstream>
     2.7 +#include <string>
     2.8 +#include <cstring> // for strcmp()
     2.9 +#include <assert.h>
    2.10 +#include "blacklist.h"
    2.11 +#include "keymanagement.h"
    2.12 +#include "message_api.h"
    2.13 +#include "mime.h"
    2.14 +
    2.15 +using namespace std;
    2.16 +
    2.17 +int main() {
    2.18 +    cout << "\n*** encrypt_missing_private_key_test ***\n\n";
    2.19 +
    2.20 +    PEP_SESSION session;
    2.21 +    
    2.22 +    cout << "calling init()\n";
    2.23 +    PEP_STATUS status1 = init(&session);   
    2.24 +    assert(status1 == PEP_STATUS_OK);
    2.25 +    assert(session);
    2.26 +    cout << "init() completed.\n";
    2.27 +
    2.28 +    // blacklist test code
    2.29 +
    2.30 +    cout << "blacklist only key for identity / add key / check which key is used" << endl;
    2.31 +    
    2.32 +    // B252066DE0513BECA2954F30E8E18177B28D9B9D - this is the blacklisted key in blacklisted_self.asc
    2.33 +
    2.34 +    /* read the key into memory */
    2.35 +    ifstream infile("test_keys/priv/blacklist_self.asc");
    2.36 +    string keytext;
    2.37 +    while (!infile.eof()) {
    2.38 +        static string line;
    2.39 +        getline(infile, line);
    2.40 +        keytext += line + "\n";
    2.41 +    }
    2.42 +    infile.close(); 
    2.43 +    
    2.44 +    /* import it into pep */
    2.45 +    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    2.46 +    
    2.47 +    const char* bl_fpr_1 = "B252066DE0513BECA2954F30E8E18177B28D9B9D";
    2.48 +    bool is_blacklisted = false;
    2.49 +    
    2.50 +    pEp_identity* blacklisted_identity = new_identity("blacklistself@kgrothoff.org",
    2.51 +                                                      bl_fpr_1,
    2.52 +                                                      PEP_OWN_USERID,
    2.53 +                                                      "Blacklist Self");
    2.54 +    blacklisted_identity->me = true;
    2.55 +    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
    2.56 +    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
    2.57 +    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
    2.58 +    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
    2.59 +
    2.60 +    /* identity is blacklisted. Now let's try to encrypt a message. */
    2.61 +    
    2.62 +    const char* new_key = NULL;    
    2.63 +    
    2.64 +    ifstream infile2("test_mails/blacklist_no_key.eml");
    2.65 +    string mailtext;
    2.66 +    while (!infile2.eof()) {
    2.67 +        static string line;
    2.68 +        getline(infile2, line);
    2.69 +        mailtext += line + "\n";
    2.70 +    }     infile2.close(); 
    2.71 +
    2.72 +    
    2.73 +    message* tmp_msg = NULL;
    2.74 +    message* enc_msg = NULL;
    2.75 +    
    2.76 +    PEP_STATUS status = mime_decode_message(mailtext.c_str(), mailtext.length(), &tmp_msg);
    2.77 +    assert(status == PEP_STATUS_OK);
    2.78 +    
    2.79 +    
    2.80 +    
    2.81 +    // This isn't incoming, though... so we need to reverse the direction
    2.82 +    tmp_msg->dir = PEP_dir_outgoing;
    2.83 +    status = encrypt_message(session,
    2.84 +                             tmp_msg,
    2.85 +                             NULL,
    2.86 +                             &enc_msg,
    2.87 +                             PEP_enc_PGP_MIME,
    2.88 +                             0);
    2.89 +    assert(status == PEP_STATUS_OK);
    2.90 +    
    2.91 +    
    2.92 +//    PEP_STATUS status69 = MIME_encrypt_message(session, mailtext.c_str(), mailtext.length(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    2.93 +//    pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");    
    2.94 +
    2.95 +    new_key = enc_msg->from->fpr;
    2.96 +    cout << "Encrypted with key " << new_key << endl;
    2.97 +    assert (strcasecmp(new_key, bl_fpr_1) != 0);
    2.98 +//     PEP_STATUS status = update_identity(session, me1);
    2.99 +//     message* msg_ptr = nullptr;
   2.100 +//     message* dest_msg = nullptr;
   2.101 +//     stringlist_t* keylist = nullptr;
   2.102 +//     PEP_rating rating;
   2.103 +//     PEP_decrypt_flags_t flags;
   2.104 +//     
   2.105 +//     status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
   2.106 +//     assert(status == PEP_STATUS_OK);
   2.107 +//     status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   2.108 +// 
   2.109 +//     PEP_STATUS status12 = update_identity(session, blacklisted_identity);
   2.110 +// 
   2.111 +//     assert(strcasecmp(blacklisted_identity->fpr, new_key) == 0);
   2.112 +    
   2.113 +    status = delete_keypair(session, new_key);
   2.114 +    PEP_STATUS status13 = blacklist_delete(session, bl_fpr_1);
   2.115 +    PEP_STATUS status14 = update_identity(session, blacklisted_identity);
   2.116 +
   2.117 +    free_message(tmp_msg);    
   2.118 +    free_message(enc_msg);
   2.119 +    
   2.120 +    cout << "calling release()\n";
   2.121 +    release(session);
   2.122 +    return 0;
   2.123 +}
   2.124 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/test_keys/priv/blacklist_self.asc	Fri Nov 11 14:08:20 2016 +0100
     3.3 @@ -0,0 +1,57 @@
     3.4 +-----BEGIN PGP PRIVATE KEY BLOCK-----
     3.5 +
     3.6 +lQOYBFgltZIBCADIlORdZvfrWGP/QL1rVYGfy1TeqrlvBPgb5h9ZMB0RCHAq6hMV
     3.7 +nyq2zBTNgrOVC41VKq6qd+3GffPqgc+Ja/2q2YQJ480j2E5vRue8rUSFWg6msMvQ
     3.8 +1Df23LNfRR7g1D7d0wGMsXaMm6PduXuAmj4z5/8BTHriDPAh8DqrdtKj1v5WBSaZ
     3.9 +5O1fJK2f6/1Opa2Kg1hmAupP6IK8AZtuPJ8JPqmYt0LNOfmQNFZpRIc1VpbcC62H
    3.10 +IYcCYW3SwJQr2O/v06fJGao4A914JbcwLeJpSXwbtMJClN3go9MUSf8JYuhIiUJ0
    3.11 +jgdP6WvopRnn1STWDv0Hq1jd8Lb+M5GBX24/ABEBAAEAB/oCciewveMzDae2gp8X
    3.12 +XSUQrPA9gN50V0lWlGv4cJ5CHr9jaT75/1q20kPvV53XU5s8bndPy9jsl+JED04t
    3.13 +ElHhu0z2uT4/UXwaCPF60FrADN+V3R0MewdYWCD100geR2hMLdkHKAOBO8VNRwhA
    3.14 +WAvUd9/uWko7UcYR2+CTRlvTifOSCHFqMLz22WIw0DyIU0dU+yjtCYI3Q0HKyZtB
    3.15 +VmNTFZxTkMtYKI1yvma0VsYNsOc6Dvs4gbU0kD0FiDPcCJz1NyA4Xj4VjsW//k0/
    3.16 +exVXkYvXWuzVzyOBAS5rURhNL7Tm8W/tZVRuEaZ8mzykvPszMckg706FUgqfcnSV
    3.17 +2nfVBADQlJujiB1rz9/g39YKB4kzOm9aELgpyGo+oEQgttVkHJLMdsnAliM7lDsy
    3.18 +ck60QsSnELku931qOPYW6NICs5GD23kexsv5HqK9FlTeXJjnvx+HRubaHyKIndJG
    3.19 +iWieQCXuH94t5TNy0FafVhsdKWuDPNAGfewNKILYc3aPQI399QQA9i6/l3mEuGpf
    3.20 +UkQxfrW9gHniXx4b2VJTlzh+8nxc0iF+Z6x8nq/H5+gN0Y/firk+hB74LXeV5X7o
    3.21 +B2JpjscyVhW3BodBACAZU5qNO48Vpl5H1GcBNLrdtGhYU7y9utEHxgDWlJY2RyuR
    3.22 +IE+SLrlM+y6vq528REzfqMhuTZfFhuMEAJRRY/RBLbmND094tT3IKKU/I1Uu5Tuv
    3.23 +6IC3pqoxeuJLxsRxqREPqoTtkwFpnAAbdOYFhNpC3m1bhTzbyavK68006+9DLRXT
    3.24 +kV/7DRm2PLcR9fJZqgWhQImktsQvWkcqYqLzwGT1bkG+QqpBq1ou1Hb2ufg44pCK
    3.25 +CxT3Yij2XsdFN0+0VUJsYWNrbGlzdCBTZWxmIChUZXN0IERvIE5vdCBVc2UgRm9y
    3.26 +IE90aGVyIFRlc3RzIFBsZWFzZSkgPGJsYWNrbGlzdHNlbGZAa2dyb3Rob2ZmLm9y
    3.27 +Zz6JATgEEwEIACIFAlgltZICGwMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJ
    3.28 +EOjhgXeyjZud5JEH/3p7258h32EmOvMdJZfl7S3W5g1OTGij6rs656eJu5lv/E6w
    3.29 +yre+MbqcBGHHJfjobrIx8qzyaq1lYBksnZcT+sAf++i5xG/LXF+MhmpaM8ZIiopv
    3.30 +KzRXSzEyCp/58oggIbz/DkT1DfI1CjTwQzOCyPdOXM1e0DcKTT8HAiRgm1tQaxw7
    3.31 +sOjdfatt37aOclJQatIE0eCBqk7Zn5Qt9KURmUCq6IkGf4XJ4bTEvbbtdizsy4ie
    3.32 +6uUt3m/csZqLmV9vXPJAPvgYAB7hd4jBOOdQGtWRzZ05Q59QWHjvlAoZaXmfH3ER
    3.33 +BEAixn6cP4Kl7wKtHMA8npCGMcdDd4o4q1KlhnidA5gEWCW1kgEIAMRJTlhJsyv3
    3.34 +8T3P/lgzLKplWF6/XkrLZ8B6aR6WphafUoSeknD2fvLa+0MyfGpThMdPDICTsjN5
    3.35 +yCnO5HqX/dtM2tGmnKNtJFpMup8a5aSe8/bcfWg7qZLzebexsw0DaNZjlrbjtI/6
    3.36 +nF/JfpPKTgXb1bHhu3Fn6/USeG2Y0F54V4Y9K5Sljz5pVFQGNGU+Wb5jBE7FSa9+
    3.37 +beo2ik3iL4W2AYadONSZTD2FnjNTrZ0oHGaD65kHnJ+yDLCMMkeZ16gCN89weQas
    3.38 +I+9on2E1afXCpi1fPUvnktijkxZ9xgGNRYDljxPqgXuXM3H0oWND4+v3ZB55h/jH
    3.39 +0OEdMW6IoJMAEQEAAQAH/AtobUkF44e6BKwb8Of/0NXRkHzC8K3tKS3hs/3m6IuL
    3.40 +VIZahvsILjPtS4C3qBZ5CyuXIMMaSUUHnkZSoXQbbgiuEQcWboLYw0Av/9z1Qk3x
    3.41 +YsYKHLChp6JyApBWVqhVv5u7WUwlaxUH++2mG/Rm0YtXMm1cR94dGZlDhjGRB5hb
    3.42 +mjbYgXhq5jXR1hzDGAR5imtSyCRiTYPIKkRUg8vdG4RfNt4eds15F15m4RjuGZol
    3.43 +c9K0fS0dIemQNfyv40Hu8Ow0EuKXqZwnsfc/opnoUUkvhmuid4zo213NhQGpxtTm
    3.44 +2xz7OuWzJvHbt5UD73YVohbCjDYZSIdJMKpFLM4ynYkEANSiPetbNMwPLNlM0dqe
    3.45 +/0EGgq/UMblvCXNI1Ie1OeLAkAgMEY8ztu8ye0bI7jR8xzBywF7ho3HruWXkm4bG
    3.46 +fqeP4Zx8GiHYEa61wyhVnZjXJbKlY1PcDeyTd4HnjX+CM4DqhP2a+HHYby7Dv1vg
    3.47 +jjwOKL0JNiy6rRvpMVdMVT05BADsUY363Q3TJY4H2zh3IFpGoxDgo9U9YCOwf16r
    3.48 +f+qAKdy0KsS13DWdQifRcIJFS6EzdB6oHLWl70kvgAPbgmr4u1za4Y+jZ/1+euG6
    3.49 +tYB45CSfeoBhhEsQJRKHxNA4m0OWYuZTR1TOvrEwd4f6/LlSSmfJ9w6hffuZ8WEH
    3.50 +TEoYKwQAwWDk0BNzQNk6AUxURw0p7HlWGCcCRgBOfr2xg/+mkZ6DkKcs3ExGOvm8
    3.51 +6cdzcwMJjqBNC45q5ZTAUCC+nxK5/AfvLlAopRYOoj8DfAbMR+S1CmCgC5RC/zn/
    3.52 +yHUnP+HrcvSfLzCi8wF7fqYsB6uU2PN+/TP6Ncui3fEPd+BvEdc+s4kBHwQYAQgA
    3.53 +CQUCWCW1kgIbDAAKCRDo4YF3so2bnbAkB/4z30XQR4LUUU/0NvkV7qpce2PTkjqB
    3.54 +8j3xtSUgxKx+XLXLdweF1ysxP6NJs6zZ4NK8mqCqqZ4ejaRtLUuQZ+t+aZUzjoRS
    3.55 +j5jGMtxY8zItkqm+A7UD8sXN9nyTwGFgGIaNyMK6I5PMQUR7Us3y3STlVeUJW1/m
    3.56 +JpfzWiFuXPX89QowqRUXtOzrh4RP+6uuu4mjj4w0HV50VUa/jaEDmYRxYRWAcqm+
    3.57 +OYoC38TJ9UelavDJq54H9etZ5mr7vhpTdrMFxAc91tqFS32Bg8c1qjO7dlXOI0Bl
    3.58 +31llkCRRc8Ft20Bfa4lMoM2lMU43OlaaOotutSWW+ZiHIHUHO71Chjt9
    3.59 +=/xdd
    3.60 +-----END PGP PRIVATE KEY BLOCK-----
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/test_keys/pub/blacklist_self_pub.asc	Fri Nov 11 14:08:20 2016 +0100
     4.3 @@ -0,0 +1,30 @@
     4.4 +-----BEGIN PGP PUBLIC KEY BLOCK-----
     4.5 +
     4.6 +mQENBFgltZIBCADIlORdZvfrWGP/QL1rVYGfy1TeqrlvBPgb5h9ZMB0RCHAq6hMV
     4.7 +nyq2zBTNgrOVC41VKq6qd+3GffPqgc+Ja/2q2YQJ480j2E5vRue8rUSFWg6msMvQ
     4.8 +1Df23LNfRR7g1D7d0wGMsXaMm6PduXuAmj4z5/8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3iL4W2AYadONSZTD2FnjNTrZ0oHGaD
    4.24 +65kHnJ+yDLCMMkeZ16gCN89weQasI+9on2E1afXCpi1fPUvnktijkxZ9xgGNRYDl
    4.25 +jxPqgXuXM3H0oWND4+v3ZB55h/jH0OEdMW6IoJMAEQEAAYkBHwQYAQgACQUCWCW1
    4.26 +kgIbDAAKCRDo4YF3so2bnbAkB/4z30XQR4LUUU/0NvkV7qpce2PTkjqB8j3xtSUg
    4.27 +xKx+XLXLdweF1ysxP6NJs6zZ4NK8mqCqqZ4ejaRtLUuQZ+t+aZUzjoRSj5jGMtxY
    4.28 +8zItkqm+A7UD8sXN9nyTwGFgGIaNyMK6I5PMQUR7Us3y3STlVeUJW1/mJpfzWiFu
    4.29 +XPX89QowqRUXtOzrh4RP+6uuu4mjj4w0HV50VUa/jaEDmYRxYRWAcqm+OYoC38TJ
    4.30 +9UelavDJq54H9etZ5mr7vhpTdrMFxAc91tqFS32Bg8c1qjO7dlXOI0Bl31llkCRR
    4.31 +c8Ft20Bfa4lMoM2lMU43OlaaOotutSWW+ZiHIHUHO71Chjt9
    4.32 +=TA0e
    4.33 +-----END PGP PUBLIC KEY BLOCK-----
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/test_mails/blacklist_no_key.eml	Fri Nov 11 14:08:20 2016 +0100
     5.3 @@ -0,0 +1,12 @@
     5.4 +From: Blacklist Self <blacklistself@kgrothoff.org> 
     5.5 +To: Bob <pep.test.bob@pep-project.org>
     5.6 +Subject: This is a test of the emergency broadcast system.
     5.7 +Message-ID: <c1329dd1-b404-3e95-2612-cfe430352c3d@pep-project.org>
     5.8 +Date: Mon, 24 Oct 2016 12:57:28 +0200
     5.9 +User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
    5.10 + Thunderbird/45.3.0
    5.11 +MIME-Version: 1.0
    5.12 +Content-Type: text/plain; charset=utf-8
    5.13 +Content-Transfer-Encoding: 7bit
    5.14 +
    5.15 +So this is a very exciting MIME mail. Yay!