test/src/engine_tests/CheckRenewedExpiredKeyTrustStatusTests.cc
author Krista Bennett <krista@pep-project.org>
Fri, 19 Oct 2018 13:25:50 +0200
branchENGINE-473
changeset 3092 389d6b6c204c
parent 3072 a02a5b80c92a
child 3137 93877eafa715
child 3277 fe1e94372261
permissions -rw-r--r--
ENGINE-473: all's well that ends well. We now keep track of trust bits when expiring and restore them when the key is renewed.
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include <stdlib.h>
     5 #include <string>
     6 #include <cstring>
     7 
     8 #include "pEpEngine.h"
     9 
    10 #include <cpptest.h>
    11 #include "test_util.h"
    12 #include "EngineTestIndividualSuite.h"
    13 #include "CheckRenewedExpiredKeyTrustStatusTests.h"
    14 
    15 using namespace std;
    16 
    17 CheckRenewedExpiredKeyTrustStatusTests::CheckRenewedExpiredKeyTrustStatusTests(string suitename, string test_home_dir) :
    18     EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
    19     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status"),
    20                                                                       static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status)));
    21     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_user"),
    22                                                                       static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_user)));
    23     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_pEp_user"),
    24                                                                       static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_pEp_user)));
    25     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_pEp_user"),
    26                                                                       static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_pEp_user)));                                                                  
    27 }
    28 
    29 void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status() {
    30     bool ok = false;
    31     ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    32     TEST_ASSERT(ok);    
    33     ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
    34     TEST_ASSERT(ok);
    35     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
    36     TEST_ASSERT(ok);
    37 
    38     const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
    39     pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
    40 
    41     PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
    42     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    43 
    44     // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
    45     // the expired key:
    46     const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
    47     
    48     char* decrypted_msg = NULL;
    49     stringlist_t* keylist_used = nullptr;
    50     char* modified_src = NULL;
    51     
    52     PEP_rating rating;
    53     PEP_decrypt_flags_t flags = 0;
    54      
    55     status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
    56     TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
    57 
    58     free(decrypted_msg);
    59     decrypted_msg = NULL;
    60     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
    61     TEST_ASSERT(ok);    
    62 
    63     pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
    64     message* msg2 = new_message(PEP_dir_outgoing);    
    65 
    66     msg2->from = alice_from;
    67     msg2->to = new_identity_list(expired_inquisitor);
    68     msg2->shortmsg = strdup("Blah!");
    69     msg2->longmsg = strdup("Blahblahblah!");
    70     msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
    71 
    72     status = outgoing_message_rating(session, msg2, &rating);
    73     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    74     TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));    
    75 
    76     status = get_trust(session, expired_inquisitor);
    77     TEST_ASSERT_MSG(expired_inquisitor->comm_type == PEP_ct_OpenPGP_unconfirmed, tl_ct_string(expired_inquisitor->comm_type));
    78     free_message(msg2);
    79 }
    80 
    81 void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_user() {
    82     bool ok = false;
    83     ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    84     TEST_ASSERT(ok);    
    85     ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
    86     TEST_ASSERT(ok);
    87     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
    88     TEST_ASSERT(ok);
    89 
    90     const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
    91     pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
    92 
    93     PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
    94     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    95 
    96     const char* inquisitor_fpr = "8E8D2381AE066ABE1FEE509821BA977CA4728718";
    97     pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", "8E8D2381AE066ABE1FEE509821BA977CA4728718", "TOFU_inquisitor@darthmama.org", "Lady Claire Trevelyan");
    98     status = set_identity(session, expired_inquisitor);
    99     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   100     expired_inquisitor->comm_type = PEP_ct_OpenPGP; // confirmed 
   101     status = set_trust(session, expired_inquisitor);
   102     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   103     status = get_trust(session, expired_inquisitor);
   104     TEST_ASSERT_MSG(expired_inquisitor->comm_type == PEP_ct_OpenPGP, tl_ct_string(expired_inquisitor->comm_type));
   105     
   106     // Ok, now update_identity - we'll discover it's expired
   107     status = update_identity(session, expired_inquisitor);
   108     TEST_ASSERT_MSG((status == PEP_KEY_UNSUITABLE), tl_status_string(status));
   109     PEP_comm_type ct = expired_inquisitor->comm_type;    
   110     TEST_ASSERT_MSG(ct == PEP_ct_key_expired_but_confirmed, tl_ct_string(ct));
   111     
   112     // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
   113     // the expired key:
   114     const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
   115     
   116     char* decrypted_msg = NULL;
   117     stringlist_t* keylist_used = nullptr;
   118     char* modified_src = NULL;
   119     
   120     PEP_rating rating;
   121     PEP_decrypt_flags_t flags = 0;
   122      
   123     status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
   124     TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
   125 
   126     free(decrypted_msg);
   127     decrypted_msg = NULL;
   128     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
   129     TEST_ASSERT(ok);    
   130 
   131     pEp_identity* expired_inquisitor1 = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
   132     
   133     status = update_identity(session, expired_inquisitor1);
   134     TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   135     status = get_trust(session, expired_inquisitor1);
   136     TEST_ASSERT_MSG(expired_inquisitor1->comm_type == PEP_ct_OpenPGP, tl_ct_string(expired_inquisitor1->comm_type));
   137 
   138     message* msg2 = new_message(PEP_dir_outgoing);    
   139 
   140     msg2->from = alice_from;
   141     msg2->to = new_identity_list(expired_inquisitor1);
   142     msg2->shortmsg = strdup("Blah!");
   143     msg2->longmsg = strdup("Blahblahblah!");
   144     msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   145 
   146     status = outgoing_message_rating(session, msg2, &rating);
   147     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   148     TEST_ASSERT_MSG((rating >= PEP_rating_trusted), tl_rating_string(rating));    
   149 
   150     free_message(msg2);
   151 }
   152 
   153 void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_pEp_user() {
   154     bool ok = false;
   155     ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   156     TEST_ASSERT(ok);    
   157     ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
   158     TEST_ASSERT(ok);
   159     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
   160     TEST_ASSERT(ok);
   161 
   162     const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
   163     pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
   164 
   165     PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
   166     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   167 
   168     const char* inquisitor_fpr = "8E8D2381AE066ABE1FEE509821BA977CA4728718";
   169     pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", "8E8D2381AE066ABE1FEE509821BA977CA4728718", "TOFU_inquisitor@darthmama.org", "Lady Claire Trevelyan");
   170     status = set_identity(session, expired_inquisitor);
   171     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   172     expired_inquisitor->comm_type = PEP_ct_pEp_unconfirmed;  
   173     status = set_trust(session, expired_inquisitor);
   174     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   175     
   176     bool pEp_user = false;
   177     status = is_pep_user(session, expired_inquisitor, &pEp_user);
   178     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   179     TEST_ASSERT(pEp_user);
   180 
   181     // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
   182     // the expired key:
   183     const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
   184 
   185     char* decrypted_msg = NULL;
   186     stringlist_t* keylist_used = nullptr;
   187     char* modified_src = NULL;
   188 
   189     PEP_rating rating;
   190     PEP_decrypt_flags_t flags = 0;
   191 
   192     status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
   193     TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
   194 
   195     free(decrypted_msg);
   196     decrypted_msg = NULL;
   197     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
   198     TEST_ASSERT(ok);    
   199 
   200     pEp_identity* expired_inquisitor1 = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
   201     message* msg2 = new_message(PEP_dir_outgoing);    
   202 
   203     msg2->from = alice_from;
   204     msg2->to = new_identity_list(expired_inquisitor1);
   205     msg2->shortmsg = strdup("Blah!");
   206     msg2->longmsg = strdup("Blahblahblah!");
   207     msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   208 
   209     status = outgoing_message_rating(session, msg2, &rating);
   210     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   211     TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));    
   212 
   213     status = get_trust(session, expired_inquisitor);
   214     TEST_ASSERT_MSG(expired_inquisitor1->comm_type == PEP_ct_pEp_unconfirmed, tl_ct_string(expired_inquisitor1->comm_type));
   215     free_message(msg2);
   216 }
   217 
   218 void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_pEp_user() {
   219     bool ok = false;
   220     ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   221     TEST_ASSERT(ok);    
   222     ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
   223     TEST_ASSERT(ok);
   224     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
   225     TEST_ASSERT(ok);
   226 
   227     const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
   228     pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
   229 
   230     PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
   231     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   232 
   233     const char* inquisitor_fpr = "8E8D2381AE066ABE1FEE509821BA977CA4728718";
   234     pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", "8E8D2381AE066ABE1FEE509821BA977CA4728718", "TOFU_inquisitor@darthmama.org", "Lady Claire Trevelyan");
   235     status = set_identity(session, expired_inquisitor);
   236     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   237     expired_inquisitor->comm_type = PEP_ct_pEp; // confirmed 
   238     status = set_trust(session, expired_inquisitor);
   239     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   240     status = get_trust(session, expired_inquisitor);
   241     TEST_ASSERT_MSG(expired_inquisitor->comm_type == PEP_ct_pEp, tl_ct_string(expired_inquisitor->comm_type));
   242 
   243     bool pEp_user = false;
   244     status = is_pep_user(session, expired_inquisitor, &pEp_user);
   245     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   246     TEST_ASSERT(pEp_user);
   247     
   248     // Ok, now update_identity - we'll discover it's expired
   249     status = update_identity(session, expired_inquisitor);
   250     TEST_ASSERT_MSG((status == PEP_KEY_UNSUITABLE), tl_status_string(status));
   251     PEP_comm_type ct = expired_inquisitor->comm_type;    
   252     TEST_ASSERT_MSG(ct == PEP_ct_key_expired_but_confirmed, tl_ct_string(ct));
   253     
   254     // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
   255     // the expired key:
   256     const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
   257     
   258     char* decrypted_msg = NULL;
   259     stringlist_t* keylist_used = nullptr;
   260     char* modified_src = NULL;
   261     
   262     PEP_rating rating;
   263     PEP_decrypt_flags_t flags = 0;
   264      
   265     status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
   266     TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
   267 
   268     free(decrypted_msg);
   269     decrypted_msg = NULL;
   270     ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
   271     TEST_ASSERT(ok);    
   272 
   273     pEp_identity* expired_inquisitor1 = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
   274     
   275     status = update_identity(session, expired_inquisitor1);
   276     TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   277     status = get_trust(session, expired_inquisitor1);
   278     TEST_ASSERT_MSG(expired_inquisitor1->comm_type == PEP_ct_pEp, tl_ct_string(expired_inquisitor1->comm_type));
   279 
   280     message* msg2 = new_message(PEP_dir_outgoing);    
   281 
   282     msg2->from = alice_from;
   283     msg2->to = new_identity_list(expired_inquisitor1);
   284     msg2->shortmsg = strdup("Blah!");
   285     msg2->longmsg = strdup("Blahblahblah!");
   286     msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   287 
   288     status = outgoing_message_rating(session, msg2, &rating);
   289     TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   290     TEST_ASSERT_MSG((rating >= PEP_rating_trusted), tl_rating_string(rating));    
   291 
   292     free_message(msg2);
   293 }