ENGINE-289: passing tests again. Still need to revisit the myself() in MIME_encrypt (it's been pushed into encrypt's myself with a user_id check), ensure priority of own idents over other idents in update_identity in certain circumstances (when we don't know a priori that it's an own identity), and general post-apocalyptic cleanup, plus some specific tests (most cases are exercised in the test suite, but surely not all). ENGINE-289
authorKrista Bennett <krista@pep-project.org>
Tue, 16 Jan 2018 14:14:01 +0100
branchENGINE-289
changeset 239488b9027db1bf
parent 2389 df065c08127d
child 2395 2b7294a57041
ENGINE-289: passing tests again. Still need to revisit the myself() in MIME_encrypt (it's been pushed into encrypt's myself with a user_id check), ensure priority of own idents over other idents in update_identity in certain circumstances (when we don't know a priori that it's an own identity), and general post-apocalyptic cleanup, plus some specific tests (most cases are exercised in the test suite, but surely not all).
src/keymanagement.c
src/message_api.c
test/encrypt_missing_private_key_test.cc
test/message_api_test.cc
     1.1 --- a/src/keymanagement.c	Tue Jan 16 01:48:05 2018 +0100
     1.2 +++ b/src/keymanagement.c	Tue Jan 16 14:14:01 2018 +0100
     1.3 @@ -834,7 +834,8 @@
     1.4              stored_identity->comm_type >= PEP_ct_strong_but_unconfirmed) {
     1.5            
     1.6              free(identity->fpr);
     1.7 -            identity->fpr = strdup(stored_identity->fpr);            
     1.8 +            identity->fpr = strdup(stored_identity->fpr);
     1.9 +            valid_key_found = true;            
    1.10          }
    1.11          else {
    1.12              bool revoked = false;
     2.1 --- a/src/message_api.c	Tue Jan 16 01:48:05 2018 +0100
     2.2 +++ b/src/message_api.c	Tue Jan 16 14:14:01 2018 +0100
     2.3 @@ -1457,6 +1457,15 @@
     2.4  
     2.5      *dst = NULL;
     2.6  
     2.7 +    if (src->from && (!src->from->user_id || src->from->user_id[0] == '\0')) {
     2.8 +        char* own_id = NULL;
     2.9 +        status = get_default_own_userid(session, &own_id);
    2.10 +        if (own_id) {
    2.11 +            free(src->from->user_id);
    2.12 +            src->from->user_id = own_id; // ownership transfer
    2.13 +        }
    2.14 +    }
    2.15 +    
    2.16      status = myself(session, src->from);
    2.17      if (status != PEP_STATUS_OK)
    2.18          GOTO(pep_error);
    2.19 @@ -1683,18 +1692,26 @@
    2.20      if (src->enc_format != PEP_enc_none)
    2.21          return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
    2.22  
    2.23 +    if (target_id && (!target_id->user_id || target_id->user_id[0] == '\0')) {
    2.24 +        char* own_id = NULL;
    2.25 +        status = get_default_own_userid(session, &own_id);
    2.26 +        if (own_id) {
    2.27 +            free(target_id->user_id);
    2.28 +            target_id->user_id = own_id; // ownership transfer
    2.29 +        }
    2.30 +    }
    2.31 +
    2.32      status = myself(session, target_id);
    2.33      if (status != PEP_STATUS_OK)
    2.34          GOTO(pep_error);
    2.35  
    2.36      *dst = NULL;
    2.37  
    2.38 -
    2.39 -    PEP_STATUS _status = update_identity(session, target_id);
    2.40 -    if (_status != PEP_STATUS_OK) {
    2.41 -        status = _status;
    2.42 -        goto pep_error;
    2.43 -    }
    2.44 +    // PEP_STATUS _status = update_identity(session, target_id);
    2.45 +    // if (_status != PEP_STATUS_OK) {
    2.46 +    //     status = _status;
    2.47 +    //     goto pep_error;
    2.48 +    // }
    2.49  
    2.50      char* target_fpr = target_id->fpr;
    2.51      if (!target_fpr)
     3.1 --- a/test/encrypt_missing_private_key_test.cc	Tue Jan 16 01:48:05 2018 +0100
     3.2 +++ b/test/encrypt_missing_private_key_test.cc	Tue Jan 16 14:14:01 2018 +0100
     3.3 @@ -25,47 +25,33 @@
     3.4      assert(status1 == PEP_STATUS_OK);
     3.5      assert(session);
     3.6      cout << "init() completed.\n";
     3.7 -
     3.8 -    // blacklist test code
     3.9 -
    3.10 -    cout << "blacklist only key for identity / add key / check which key is used" << endl;
    3.11      
    3.12 -    // B252066DE0513BECA2954F30E8E18177B28D9B9D - this is the blacklisted key in blacklisted_self.asc
    3.13 -
    3.14 -    const string keytext = slurp("test_keys/priv/blacklist_self.asc");
    3.15 -    
    3.16 -    /* import it into pep */
    3.17 -    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    3.18 -    
    3.19 -    const char* bl_fpr_1 = "B252066DE0513BECA2954F30E8E18177B28D9B9D";
    3.20 -    bool is_blacklisted = false;
    3.21 -    
    3.22 -    pEp_identity* blacklisted_identity = new_identity("blacklistself@kgrothoff.org",
    3.23 -                                                      bl_fpr_1,
    3.24 +    pEp_identity* no_key_identity = new_identity("blacklistself@kgrothoff.org",
    3.25 +                                                      NULL,
    3.26                                                        PEP_OWN_USERID,
    3.27                                                        "Blacklist Self");
    3.28 -    blacklisted_identity->me = true;
    3.29 -    PEP_STATUS status8 = myself(session, blacklisted_identity);
    3.30 +    no_key_identity->me = true;
    3.31 +    PEP_STATUS status8 = myself(session, no_key_identity);
    3.32      assert (status8 == PEP_STATUS_OK);
    3.33 -    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
    3.34 -    assert (status9 == PEP_STATUS_OK);
    3.35 -    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
    3.36 -    assert (status10 == PEP_STATUS_OK);
    3.37 -    PEP_STATUS status11 = myself(session, blacklisted_identity);
    3.38 -    assert (status11 == PEP_STATUS_OK);
    3.39  
    3.40 -    /* identity is blacklisted. Now let's try to encrypt a message. */
    3.41 -    
    3.42 -    const char* new_key = NULL;
    3.43 -    
    3.44 -    const string mailtext = slurp("test_mails/blacklist_no_key.eml");
    3.45 -    
    3.46 +    /* Now let's try to encrypt a message. */
    3.47 +        
    3.48      message* tmp_msg = NULL;
    3.49      message* enc_msg = NULL;
    3.50      
    3.51 +    const string mailtext = slurp("test_mails/blacklist_no_key.eml");
    3.52 +
    3.53      PEP_STATUS status = mime_decode_message(mailtext.c_str(), mailtext.length(), &tmp_msg);
    3.54      assert(status == PEP_STATUS_OK);
    3.55      
    3.56 +    status = update_identity(session, tmp_msg->from);
    3.57 +    identity_list* to_list = tmp_msg->to;
    3.58 +
    3.59 +    while (to_list) {
    3.60 +        if (to_list->ident)
    3.61 +            update_identity(session, to_list->ident);
    3.62 +        to_list = to_list->next;
    3.63 +    }
    3.64      
    3.65      // This isn't incoming, though... so we need to reverse the direction
    3.66      tmp_msg->dir = PEP_dir_outgoing;
    3.67 @@ -77,30 +63,12 @@
    3.68                               0);
    3.69      assert(status == PEP_STATUS_OK);
    3.70      
    3.71 -//    PEP_STATUS status69 = MIME_encrypt_message(session, mailtext.c_str(), mailtext.length(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    3.72 -//    pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");    
    3.73  
    3.74 -    new_key = enc_msg->from->fpr;
    3.75 +    char* new_key = enc_msg->from->fpr;
    3.76      cout << "Encrypted with key " << new_key << endl;
    3.77 -    assert (strcasecmp(new_key, bl_fpr_1) != 0);
    3.78 -//     PEP_STATUS status = update_identity(session, me1);
    3.79 -//     message* msg_ptr = nullptr;
    3.80 -//     message* dest_msg = nullptr;
    3.81 -//     stringlist_t* keylist = nullptr;
    3.82 -//     PEP_rating rating;
    3.83 -//     PEP_decrypt_flags_t flags;
    3.84 -//     
    3.85 -//     status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    3.86 -//     assert(status == PEP_STATUS_OK);
    3.87 -//     status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    3.88 -// 
    3.89 -//     PEP_STATUS status12 = update_identity(session, blacklisted_identity);
    3.90 -// 
    3.91 -//     assert(strcasecmp(blacklisted_identity->fpr, new_key) == 0);
    3.92      
    3.93      status = delete_keypair(session, new_key);
    3.94 -    PEP_STATUS status13 = blacklist_delete(session, bl_fpr_1);
    3.95 -    PEP_STATUS status14 = update_identity(session, blacklisted_identity);
    3.96 +    PEP_STATUS status14 = myself(session, no_key_identity);
    3.97  
    3.98      free_message(tmp_msg);    
    3.99      free_message(enc_msg);
     4.1 --- a/test/message_api_test.cc	Tue Jan 16 01:48:05 2018 +0100
     4.2 +++ b/test/message_api_test.cc	Tue Jan 16 14:14:01 2018 +0100
     4.3 @@ -147,7 +147,8 @@
     4.4  	
     4.5  	std::cout << "MIME_decrypt_message returned " << std::dec << status2 << std::hex << " (0x" << status2 << ")" << std::dec << endl;
     4.6  	
     4.7 -	assert(status2 == PEP_STATUS_OK);
     4.8 +    // We have no public key, so we cannot, in fact, VERIFY the message. SO cannot be PEP_STATUS_OK.
     4.9 +	assert(status2 == PEP_DECRYPTED);
    4.10  	assert(plaintext);
    4.11  	
    4.12  	pEp_free(plaintext);
    4.13 @@ -162,7 +163,6 @@
    4.14  	free_identity_list(pk);
    4.15  }
    4.16  
    4.17 -
    4.18  int main() {
    4.19      cout << "\n*** message_api_test ***\n\n";
    4.20      test_MIME_decrypt_message();