ENGINE-398: removed key_reset functionality from key_mistrust; need to adjust a test or two. ENGINE-398
authorKrista Bennett <krista@pep-project.org>
Mon, 10 Sep 2018 15:09:45 +0200
branchENGINE-398
changeset 2936d5e80c521be1
parent 2935 73845aff051b
child 2938 0156ba1c5837
ENGINE-398: removed key_reset functionality from key_mistrust; need to adjust a test or two.
src/keymanagement.c
src/message_api.c
src/pEp_internal.h
test/include/KeyResetMessageTests.h
test/include/MistrustUndoTests.h
test/src/SuiteMaker.cc
test/src/engine_tests/KeyResetMessageTests.cc
test/src/engine_tests/MistrustUndoTests.cc
     1.1 --- a/src/keymanagement.c	Sat Sep 08 11:39:04 2018 +0200
     1.2 +++ b/src/keymanagement.c	Mon Sep 10 15:09:45 2018 +0200
     1.3 @@ -1192,76 +1192,21 @@
     1.4  
     1.5      if (!(session && ident && ident->fpr))
     1.6          return PEP_ILLEGAL_VALUE;
     1.7 +            
     1.8 +    // double-check to be sure key is even in the DB
     1.9 +    if (ident->fpr)
    1.10 +        status = set_pgp_keypair(session, ident->fpr);
    1.11  
    1.12 -    // ident is INPUT ONLY, so we need to preserve the input fpr
    1.13 -    char* preserve_fpr = ident->fpr;
    1.14 -    ident->fpr = strdup(preserve_fpr);
    1.15 +    // We set this temporarily but will grab it back from the cache afterwards
    1.16 +    ident->comm_type = PEP_ct_mistrusted;
    1.17 +    status = set_trust(session, ident);
    1.18      
    1.19 -    if (ident->me)
    1.20 -    {
    1.21 -        revoke_key(session, ident->fpr, NULL);
    1.22 -        myself(session, ident);
    1.23 -    }
    1.24 -    else
    1.25 -    {
    1.26 -        // for undo
    1.27 -        if (session->cached_mistrusted)
    1.28 -            free(session->cached_mistrusted);
    1.29 -        session->cached_mistrusted = identity_dup(ident);
    1.30 -        
    1.31 -        // set mistrust for this user_id/keypair (even if there's not an
    1.32 -        // identity set yet, this is important, as we need to record the mistrust
    1.33 -        // action)
    1.34 -        
    1.35 -        // double-check to be sure key is even in the DB
    1.36 -        if (ident->fpr)
    1.37 -            status = set_pgp_keypair(session, ident->fpr);
    1.38 -
    1.39 -        // We set this temporarily but will grab it back from the cache afterwards
    1.40 -        ident->comm_type = PEP_ct_mistrusted;
    1.41 -        status = set_trust(session, ident);
    1.42 -        ident->comm_type = session->cached_mistrusted->comm_type;
    1.43 -        
    1.44 -        if (status == PEP_STATUS_OK)
    1.45 -            // cascade that mistrust for anyone using this key
    1.46 -            status = mark_as_compromised(session, ident->fpr);
    1.47 -        if (status == PEP_STATUS_OK)
    1.48 -            status = remove_fpr_as_default(session, ident->fpr);
    1.49 -        if (status == PEP_STATUS_OK)
    1.50 -            status = add_mistrusted_key(session, ident->fpr);
    1.51 -    }
    1.52 -    free(ident->fpr);
    1.53 -    ident->fpr = preserve_fpr;
    1.54 -    return status;
    1.55 -}
    1.56 -
    1.57 -DYNAMIC_API PEP_STATUS undo_last_mistrust(PEP_SESSION session) {
    1.58 -    assert(session);
    1.59 -    
    1.60 -    if (!session)
    1.61 -        return PEP_ILLEGAL_VALUE;
    1.62 -    
    1.63 -    PEP_STATUS status = PEP_STATUS_OK;
    1.64 -        
    1.65 -    pEp_identity* cached_ident = session->cached_mistrusted;
    1.66 -    
    1.67 -    if (!cached_ident)
    1.68 -        status = PEP_CANNOT_FIND_IDENTITY;
    1.69 -    else {
    1.70 -        status = delete_mistrusted_key(session, cached_ident->fpr);
    1.71 -        if (status == PEP_STATUS_OK) {
    1.72 -            status = set_identity(session, cached_ident);
    1.73 -            // THIS SHOULDN'T BE NECESSARY - PREVIOUS VALUE WAS IN THE DB
    1.74 -            // if (status == PEP_STATUS_OK) {
    1.75 -            //     if ((cached_ident->comm_type | PEP_ct_confirmed) == PEP_ct_pEp)
    1.76 -            //         status = set_as_pep_user(session, cached_ident);
    1.77 -            // }            
    1.78 -            free_identity(session->cached_mistrusted);
    1.79 -        }
    1.80 -    }
    1.81 -    
    1.82 -    session->cached_mistrusted = NULL;
    1.83 -    
    1.84 +    if (status == PEP_STATUS_OK)
    1.85 +        // cascade that mistrust for anyone using this key
    1.86 +        status = mark_as_compromised(session, ident->fpr);
    1.87 +    if (status == PEP_STATUS_OK)
    1.88 +        status = add_mistrusted_key(session, ident->fpr);
    1.89 +            
    1.90      return status;
    1.91  }
    1.92  
     2.1 --- a/src/message_api.c	Sat Sep 08 11:39:04 2018 +0200
     2.2 +++ b/src/message_api.c	Mon Sep 10 15:09:45 2018 +0200
     2.3 @@ -4115,9 +4115,9 @@
     2.4              // remove fpr from all users
     2.5              if (status == PEP_STATUS_OK)
     2.6                  status = remove_fpr_as_default(session, fpr_copy);
     2.7 -            // delete key from key ring
     2.8 -            if (status == PEP_STATUS_OK)
     2.9 -                status = delete_keypair(session, fpr_copy);
    2.10 +            // delete key from DB
    2.11 +            if (status == PEP_STATUS_OK) {};
    2.12 +//                status = delete_keypair(session, fpr_copy);
    2.13              // N.B. If this key is being replaced by something else, it
    2.14              // is done outside of this function.    
    2.15          }
     3.1 --- a/src/pEp_internal.h	Sat Sep 08 11:39:04 2018 +0200
     3.2 +++ b/src/pEp_internal.h	Mon Sep 10 15:09:45 2018 +0200
     3.3 @@ -232,9 +232,6 @@
     3.4      bool unencrypted_subject;
     3.5      bool keep_sync_msg;
     3.6      bool service_log;
     3.7 -
     3.8 -    // mistrust undo cache
     3.9 -    pEp_identity* cached_mistrusted;
    3.10      
    3.11  #ifdef DEBUG_ERRORSTACK
    3.12      stringlist_t* errorstack;
     4.1 --- a/test/include/KeyResetMessageTests.h	Sat Sep 08 11:39:04 2018 +0200
     4.2 +++ b/test/include/KeyResetMessageTests.h	Mon Sep 10 15:09:45 2018 +0200
     4.3 @@ -22,7 +22,7 @@
     4.4          static constexpr const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
     4.5          static constexpr const char* bob_fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
     4.6          
     4.7 -        static constexpr const char* alice_receive_reset_fpr = "3EB562B0BE859A313636885910B2C4691EF99182";
     4.8 +        static constexpr const char* alice_receive_reset_fpr = "E7281DAE65DDD847F186B6988819915AA104FB62";
     4.9  
    4.10          static const string alice_user_id;
    4.11          static const string bob_user_id;    
     5.1 --- a/test/include/MistrustUndoTests.h	Sat Sep 08 11:39:04 2018 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,19 +0,0 @@
     5.4 -// This file is under GNU General Public License 3.0
     5.5 -// see LICENSE.txt
     5.6 -
     5.7 -#ifndef MISTRUST_UNDO_H
     5.8 -#define MISTRUST_UNDO_H
     5.9 -
    5.10 -#include <string>
    5.11 -#include "EngineTestSessionSuite.h"
    5.12 -
    5.13 -using namespace std;
    5.14 -
    5.15 -class MistrustUndoTests : public EngineTestSessionSuite {
    5.16 -    public:
    5.17 -        MistrustUndoTests(string test_suite, string test_home_dir);
    5.18 -    private:
    5.19 -        void check_mistrust_undo();
    5.20 -};
    5.21 -
    5.22 -#endif
     6.1 --- a/test/src/SuiteMaker.cc	Sat Sep 08 11:39:04 2018 +0200
     6.2 +++ b/test/src/SuiteMaker.cc	Mon Sep 10 15:09:45 2018 +0200
     6.3 @@ -30,7 +30,6 @@
     6.4  #include "BlacklistTests.h"
     6.5  #include "LeastCommonDenomColorTests.h"
     6.6  #include "PepSubjectReceivedTests.h"
     6.7 -#include "MistrustUndoTests.h"
     6.8  #include "StringpairListTests.h"
     6.9  #include "PgpListKeysTests.h"
    6.10  #include "ReencryptPlusExtraKeysTests.h"
    6.11 @@ -71,7 +70,6 @@
    6.12      "BlacklistTests",
    6.13      "LeastCommonDenomColorTests",
    6.14      "PepSubjectReceivedTests",
    6.15 -    "MistrustUndoTests",
    6.16      "StringpairListTests",
    6.17      "PgpListKeysTests",
    6.18      "ReencryptPlusExtraKeysTests",
    6.19 @@ -94,7 +92,7 @@
    6.20  };
    6.21  
    6.22  // This file is generated, so magic constants are ok.
    6.23 -int SuiteMaker::num_suites = 38;
    6.24 +int SuiteMaker::num_suites = 37;
    6.25  
    6.26  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
    6.27      if (strcmp(test_class_name, "MapAsn1Tests") == 0)
    6.28 @@ -133,8 +131,6 @@
    6.29          *test_suite = new LeastCommonDenomColorTests(test_class_name, test_home);
    6.30      else if (strcmp(test_class_name, "PepSubjectReceivedTests") == 0)
    6.31          *test_suite = new PepSubjectReceivedTests(test_class_name, test_home);
    6.32 -    else if (strcmp(test_class_name, "MistrustUndoTests") == 0)
    6.33 -        *test_suite = new MistrustUndoTests(test_class_name, test_home);
    6.34      else if (strcmp(test_class_name, "StringpairListTests") == 0)
    6.35          *test_suite = new StringpairListTests(test_class_name, test_home);
    6.36      else if (strcmp(test_class_name, "PgpListKeysTests") == 0)
     7.1 --- a/test/src/engine_tests/KeyResetMessageTests.cc	Sat Sep 08 11:39:04 2018 +0200
     7.2 +++ b/test/src/engine_tests/KeyResetMessageTests.cc	Mon Sep 10 15:09:45 2018 +0200
     7.3 @@ -188,6 +188,9 @@
     7.4      status = key_reset(session, alice_fpr, from_ident);
     7.5      TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
     7.6      TEST_ASSERT(m_queue.size() > 0);
     7.7 +    status = myself(session, from_ident);
     7.8 +    string new_fpr = from_ident->fpr;
     7.9 +    TEST_ASSERT_MSG((strcmp(alice_fpr, new_fpr.c_str()) != 0), new_fpr.c_str());
    7.10      
    7.11      unordered_map<string, bool> hashmap;
    7.12      hashmap[alice_user_id] = false;
    7.13 @@ -214,7 +217,16 @@
    7.14          
    7.15          TEST_ASSERT(jt != hashmap.end());
    7.16          hashmap[jt->first] = true;   
    7.17 -        
    7.18 +
    7.19 +        // Uncomment to regenerate received message - remember to update
    7.20 +        // alice_receive_reset_fpr
    7.21 +        //
    7.22 +        // if (it == m_queue.begin()) {
    7.23 +        //     char* bob_msg = NULL;
    7.24 +        //     mime_encode_message(curr_sent_msg, false, &bob_msg);
    7.25 +        //     cout << bob_msg;
    7.26 +        // }
    7.27 +            
    7.28          message* decrypted_msg = NULL;
    7.29          stringlist_t* keylist = NULL;
    7.30          PEP_rating rating;
    7.31 @@ -224,7 +236,14 @@
    7.32                                   &decrypted_msg, &keylist, 
    7.33                                   &rating, &flags);
    7.34                                   
    7.35 -        TEST_ASSERT_MSG((status == PEP_DECRYPTED_AND_VERIFIED), tl_status_string(status));
    7.36 +        TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    7.37 +        TEST_ASSERT(keylist);
    7.38 +        if (keylist) {
    7.39 +            TEST_ASSERT(keylist->value);
    7.40 +            if (keylist->value)
    7.41 +                TEST_ASSERT_MSG(strcmp(keylist->value, new_fpr.c_str()) == 0,
    7.42 +                                keylist->value);
    7.43 +        }
    7.44          free_message(curr_sent_msg); // DO NOT USE AFTER THIS
    7.45      }
    7.46      
    7.47 @@ -258,7 +277,7 @@
    7.48      status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
    7.49                                    &decrypted_msg, &keylist, &rating, &flags, &modified_src);
    7.50                                    
    7.51 -    TEST_ASSERT_MSG(status == PEP_DECRYPTED, tl_status_string(status));
    7.52 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    7.53      TEST_ASSERT(keylist);
    7.54      if (keylist) // there's a test option to continue when asserts fail, so...
    7.55          TEST_ASSERT_MSG(strcmp(keylist->value, alice_receive_reset_fpr) == 0,
    7.56 @@ -272,7 +291,8 @@
    7.57      keylist = NULL;
    7.58      status = find_keys(session, alice_fpr, &keylist);
    7.59  
    7.60 -    TEST_ASSERT(status == PEP_KEY_NOT_FOUND);
    7.61 +    // Do we really want to delete it, or do we need its revoked status hanging about?
    7.62 +    TEST_ASSERT_MSG(status == PEP_KEY_NOT_FOUND, tl_status_string(status));
    7.63      free(keylist);
    7.64      
    7.65  }
     8.1 --- a/test/src/engine_tests/MistrustUndoTests.cc	Sat Sep 08 11:39:04 2018 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,84 +0,0 @@
     8.4 -// This file is under GNU General Public License 3.0
     8.5 -// see LICENSE.txt
     8.6 -
     8.7 -#include <stdlib.h>
     8.8 -#include <string>
     8.9 -#include <cstring>
    8.10 -#include <time.h>
    8.11 -#include <iostream>
    8.12 -#include <fstream>
    8.13 -
    8.14 -#include "pEpEngine.h"
    8.15 -#include "platform.h"
    8.16 -#include "mime.h"
    8.17 -#include "message_api.h"
    8.18 -#include "test_util.h"
    8.19 -
    8.20 -#include <cpptest.h>
    8.21 -#include "EngineTestSessionSuite.h"
    8.22 -#include "MistrustUndoTests.h"
    8.23 -
    8.24 -using namespace std;
    8.25 -
    8.26 -MistrustUndoTests::MistrustUndoTests(string suitename, string test_home_dir) :
    8.27 -    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
    8.28 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("MistrustUndoTests::check_mistrust_undo"),
    8.29 -                                                                      static_cast<Func>(&MistrustUndoTests::check_mistrust_undo)));
    8.30 -}
    8.31 -
    8.32 -void MistrustUndoTests::check_mistrust_undo() {
    8.33 -    PEP_STATUS status = PEP_STATUS_OK;
    8.34 -
    8.35 -    cout << "importing key 0x39E5DAB5." << endl;
    8.36 -    const string pub_key = slurp("test_keys/pub/mistrust.undo.test-0x39E5DAB5_pub.asc");
    8.37 -
    8.38 -    TEST_ASSERT_MSG((pub_key.length() != 0), "pub_key.length() != 0");
    8.39 -    
    8.40 -    PEP_STATUS statuspub = import_key(session, pub_key.c_str(), pub_key.length(), NULL);
    8.41 -    TEST_ASSERT_MSG((statuspub == PEP_STATUS_OK), "statuspub == PEP_STATUS_OK");
    8.42 -    cout << "Key imported." << endl << endl;
    8.43 -    
    8.44 -    cout << "Setting up identity for mistrust.undo.test@pep-project.org and making comm_type PEP_ct_pEp."  << endl;
    8.45 -    pEp_identity* recip1 = new_identity("mistrust.undo.test@pep-project.org", NULL, "TOFU_mistrust.undo.test@pep-project.org", "Mistrust Undo");
    8.46 -    status = update_identity(session,recip1);
    8.47 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    8.48 -    TEST_ASSERT_MSG((strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0), "strcmp(recip1->fpr, \"BACC7A60A88A39A25D99B4A545D7542F39E5DAB5\") == 0");
    8.49 -    
    8.50 -    // First, we need the fpr to be in the DB system.
    8.51 -    status = set_identity(session,recip1);
    8.52 -    // Then we update the trust.
    8.53 -    // This is not an external function. We use it to expedite the test since we don't do a sync exchange here.
    8.54 -    status = update_trust_for_fpr(session, recip1->fpr, PEP_ct_pEp);
    8.55 -    // Then we retrieve the new trust.
    8.56 -    status = update_identity(session,recip1);
    8.57 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    8.58 -    TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_pEp), "recip1->comm_type == PEP_ct_pEp");
    8.59 -    TEST_ASSERT_MSG((strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0), "strcmp(recip1->fpr, \"BACC7A60A88A39A25D99B4A545D7542F39E5DAB5\") == 0");
    8.60 -    cout << "mistrust.undo.test@pep-project.org set up and comm_type is PEP_ct_pEp."  << endl << endl;
    8.61 -
    8.62 -    // Ok, mistrust away
    8.63 -    cout << "Mistrusting mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5)."  << endl;   
    8.64 -    status = key_mistrusted(session, recip1);
    8.65 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    8.66 -    status = update_identity(session,recip1);
    8.67 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    8.68 -    TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_key_not_found), "recip1->comm_type == PEP_ct_key_not_found");
    8.69 -    recip1->fpr = strdup("BACC7A60A88A39A25D99B4A545D7542F39E5DAB5");
    8.70 -    status = get_trust(session, recip1);
    8.71 -    TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_mistrusted), "recip1->comm_type == PEP_ct_mistrusted");
    8.72 -     
    8.73 -    cout << "Mistrusted mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5) and comm_type IN DB set to PEP_ct_mistrusted)." << endl  << endl;    
    8.74 -    
    8.75 -    cout << "Undo mistrust (restore identity and trust in DB)" << endl;
    8.76 -    // Undo it
    8.77 -    status = undo_last_mistrust(session);
    8.78 -    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
    8.79 -    status = update_identity(session, recip1);
    8.80 -    TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_pEp), "recip1->comm_type == PEP_ct_pEp");
    8.81 -    TEST_ASSERT_MSG((strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0), "strcmp(recip1->fpr, \"BACC7A60A88A39A25D99B4A545D7542F39E5DAB5\") == 0");
    8.82 -    cout << "Undo mistrust (restore identity and trust in DB) - trust is now PEP_ct_pEp." << endl << endl;
    8.83 -
    8.84 -    cout << "Success!!!" << endl << endl;
    8.85 -    
    8.86 -    free_identity(recip1);
    8.87 -}