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