Browse Source

ENGINE-398: removed key_reset functionality from key_mistrust; need to adjust a test or two.

generate_api
Krista Bennett 4 years ago
parent
commit
158f6efbd6
8 changed files with 42 additions and 187 deletions
  1. +13
    -68
      src/keymanagement.c
  2. +3
    -3
      src/message_api.c
  3. +0
    -3
      src/pEp_internal.h
  4. +1
    -1
      test/include/KeyResetMessageTests.h
  5. +0
    -19
      test/include/MistrustUndoTests.h
  6. +1
    -5
      test/src/SuiteMaker.cc
  7. +24
    -4
      test/src/engine_tests/KeyResetMessageTests.cc
  8. +0
    -84
      test/src/engine_tests/MistrustUndoTests.cc

+ 13
- 68
src/keymanagement.c View File

@ -1192,76 +1192,21 @@ DYNAMIC_API PEP_STATUS key_mistrusted(
if (!(session && ident && ident->fpr))
return PEP_ILLEGAL_VALUE;
// double-check to be sure key is even in the DB
if (ident->fpr)
status = set_pgp_keypair(session, ident->fpr);
// ident is INPUT ONLY, so we need to preserve the input fpr
char* preserve_fpr = ident->fpr;
ident->fpr = strdup(preserve_fpr);
if (ident->me)
{
revoke_key(session, ident->fpr, NULL);
myself(session, ident);
}
else
{
// for undo
if (session->cached_mistrusted)
free(session->cached_mistrusted);
session->cached_mistrusted = identity_dup(ident);
// set mistrust for this user_id/keypair (even if there's not an
// identity set yet, this is important, as we need to record the mistrust
// action)
// double-check to be sure key is even in the DB
if (ident->fpr)
status = set_pgp_keypair(session, ident->fpr);
// We set this temporarily but will grab it back from the cache afterwards
ident->comm_type = PEP_ct_mistrusted;
status = set_trust(session, ident);
ident->comm_type = session->cached_mistrusted->comm_type;
if (status == PEP_STATUS_OK)
// cascade that mistrust for anyone using this key
status = mark_as_compromised(session, ident->fpr);
if (status == PEP_STATUS_OK)
status = remove_fpr_as_default(session, ident->fpr);
if (status == PEP_STATUS_OK)
status = add_mistrusted_key(session, ident->fpr);
}
free(ident->fpr);
ident->fpr = preserve_fpr;
return status;
}
DYNAMIC_API PEP_STATUS undo_last_mistrust(PEP_SESSION session) {
assert(session);
if (!session)
return PEP_ILLEGAL_VALUE;
PEP_STATUS status = PEP_STATUS_OK;
pEp_identity* cached_ident = session->cached_mistrusted;
if (!cached_ident)
status = PEP_CANNOT_FIND_IDENTITY;
else {
status = delete_mistrusted_key(session, cached_ident->fpr);
if (status == PEP_STATUS_OK) {
status = set_identity(session, cached_ident);
// THIS SHOULDN'T BE NECESSARY - PREVIOUS VALUE WAS IN THE DB
// if (status == PEP_STATUS_OK) {
// if ((cached_ident->comm_type | PEP_ct_confirmed) == PEP_ct_pEp)
// status = set_as_pep_user(session, cached_ident);
// }
free_identity(session->cached_mistrusted);
}
}
session->cached_mistrusted = NULL;
// We set this temporarily but will grab it back from the cache afterwards
ident->comm_type = PEP_ct_mistrusted;
status = set_trust(session, ident);
if (status == PEP_STATUS_OK)
// cascade that mistrust for anyone using this key
status = mark_as_compromised(session, ident->fpr);
if (status == PEP_STATUS_OK)
status = add_mistrusted_key(session, ident->fpr);
return status;
}


+ 3
- 3
src/message_api.c View File

@ -4115,9 +4115,9 @@ DYNAMIC_API PEP_STATUS key_reset(
// remove fpr from all users
if (status == PEP_STATUS_OK)
status = remove_fpr_as_default(session, fpr_copy);
// delete key from key ring
if (status == PEP_STATUS_OK)
status = delete_keypair(session, fpr_copy);
// delete key from DB
if (status == PEP_STATUS_OK) {};
// status = delete_keypair(session, fpr_copy);
// N.B. If this key is being replaced by something else, it
// is done outside of this function.
}


+ 0
- 3
src/pEp_internal.h View File

@ -232,9 +232,6 @@ struct _pEpSession {
bool unencrypted_subject;
bool keep_sync_msg;
bool service_log;
// mistrust undo cache
pEp_identity* cached_mistrusted;
#ifdef DEBUG_ERRORSTACK
stringlist_t* errorstack;


+ 1
- 1
test/include/KeyResetMessageTests.h View File

@ -22,7 +22,7 @@ class KeyResetMessageTests : public EngineTestIndividualSuite {
static constexpr const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
static constexpr const char* bob_fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
static constexpr const char* alice_receive_reset_fpr = "3EB562B0BE859A313636885910B2C4691EF99182";
static constexpr const char* alice_receive_reset_fpr = "E7281DAE65DDD847F186B6988819915AA104FB62";
static const string alice_user_id;
static const string bob_user_id;


+ 0
- 19
test/include/MistrustUndoTests.h View File

@ -1,19 +0,0 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef MISTRUST_UNDO_H
#define MISTRUST_UNDO_H
#include <string>
#include "EngineTestSessionSuite.h"
using namespace std;
class MistrustUndoTests : public EngineTestSessionSuite {
public:
MistrustUndoTests(string test_suite, string test_home_dir);
private:
void check_mistrust_undo();
};
#endif

+ 1
- 5
test/src/SuiteMaker.cc View File

@ -30,7 +30,6 @@
#include "BlacklistTests.h"
#include "LeastCommonDenomColorTests.h"
#include "PepSubjectReceivedTests.h"
#include "MistrustUndoTests.h"
#include "StringpairListTests.h"
#include "PgpListKeysTests.h"
#include "ReencryptPlusExtraKeysTests.h"
@ -71,7 +70,6 @@ const char* SuiteMaker::all_suites[] = {
"BlacklistTests",
"LeastCommonDenomColorTests",
"PepSubjectReceivedTests",
"MistrustUndoTests",
"StringpairListTests",
"PgpListKeysTests",
"ReencryptPlusExtraKeysTests",
@ -94,7 +92,7 @@ const char* SuiteMaker::all_suites[] = {
};
// This file is generated, so magic constants are ok.
int SuiteMaker::num_suites = 38;
int SuiteMaker::num_suites = 37;
void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
if (strcmp(test_class_name, "MapAsn1Tests") == 0)
@ -133,8 +131,6 @@ void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_
*test_suite = new LeastCommonDenomColorTests(test_class_name, test_home);
else if (strcmp(test_class_name, "PepSubjectReceivedTests") == 0)
*test_suite = new PepSubjectReceivedTests(test_class_name, test_home);
else if (strcmp(test_class_name, "MistrustUndoTests") == 0)
*test_suite = new MistrustUndoTests(test_class_name, test_home);
else if (strcmp(test_class_name, "StringpairListTests") == 0)
*test_suite = new StringpairListTests(test_class_name, test_home);
else if (strcmp(test_class_name, "PgpListKeysTests") == 0)


+ 24
- 4
test/src/engine_tests/KeyResetMessageTests.cc View File

@ -188,6 +188,9 @@ void KeyResetMessageTests::check_reset_key_and_notify() {
status = key_reset(session, alice_fpr, from_ident);
TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
TEST_ASSERT(m_queue.size() > 0);
status = myself(session, from_ident);
string new_fpr = from_ident->fpr;
TEST_ASSERT_MSG((strcmp(alice_fpr, new_fpr.c_str()) != 0), new_fpr.c_str());
unordered_map<string, bool> hashmap;
hashmap[alice_user_id] = false;
@ -214,7 +217,16 @@ void KeyResetMessageTests::check_reset_key_and_notify() {
TEST_ASSERT(jt != hashmap.end());
hashmap[jt->first] = true;
// Uncomment to regenerate received message - remember to update
// alice_receive_reset_fpr
//
// if (it == m_queue.begin()) {
// char* bob_msg = NULL;
// mime_encode_message(curr_sent_msg, false, &bob_msg);
// cout << bob_msg;
// }
message* decrypted_msg = NULL;
stringlist_t* keylist = NULL;
PEP_rating rating;
@ -224,7 +236,14 @@ void KeyResetMessageTests::check_reset_key_and_notify() {
&decrypted_msg, &keylist,
&rating, &flags);
TEST_ASSERT_MSG((status == PEP_DECRYPTED_AND_VERIFIED), tl_status_string(status));
TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
TEST_ASSERT(keylist);
if (keylist) {
TEST_ASSERT(keylist->value);
if (keylist->value)
TEST_ASSERT_MSG(strcmp(keylist->value, new_fpr.c_str()) == 0,
keylist->value);
}
free_message(curr_sent_msg); // DO NOT USE AFTER THIS
}
@ -258,7 +277,7 @@ void KeyResetMessageTests::check_receive_revoked() {
status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
&decrypted_msg, &keylist, &rating, &flags, &modified_src);
TEST_ASSERT_MSG(status == PEP_DECRYPTED, tl_status_string(status));
TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
TEST_ASSERT(keylist);
if (keylist) // there's a test option to continue when asserts fail, so...
TEST_ASSERT_MSG(strcmp(keylist->value, alice_receive_reset_fpr) == 0,
@ -272,7 +291,8 @@ void KeyResetMessageTests::check_receive_revoked() {
keylist = NULL;
status = find_keys(session, alice_fpr, &keylist);
TEST_ASSERT(status == PEP_KEY_NOT_FOUND);
// Do we really want to delete it, or do we need its revoked status hanging about?
TEST_ASSERT_MSG(status == PEP_KEY_NOT_FOUND, tl_status_string(status));
free(keylist);
}


+ 0
- 84
test/src/engine_tests/MistrustUndoTests.cc View File

@ -1,84 +0,0 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include <stdlib.h>
#include <string>
#include <cstring>
#include <time.h>
#include <iostream>
#include <fstream>
#include "pEpEngine.h"
#include "platform.h"
#include "mime.h"
#include "message_api.h"
#include "test_util.h"
#include <cpptest.h>
#include "EngineTestSessionSuite.h"
#include "MistrustUndoTests.h"
using namespace std;
MistrustUndoTests::MistrustUndoTests(string suitename, string test_home_dir) :
EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("MistrustUndoTests::check_mistrust_undo"),
static_cast<Func>(&MistrustUndoTests::check_mistrust_undo)));
}
void MistrustUndoTests::check_mistrust_undo() {
PEP_STATUS status = PEP_STATUS_OK;
cout << "importing key 0x39E5DAB5." << endl;
const string pub_key = slurp("test_keys/pub/mistrust.undo.test-0x39E5DAB5_pub.asc");
TEST_ASSERT_MSG((pub_key.length() != 0), "pub_key.length() != 0");
PEP_STATUS statuspub = import_key(session, pub_key.c_str(), pub_key.length(), NULL);
TEST_ASSERT_MSG((statuspub == PEP_STATUS_OK), "statuspub == PEP_STATUS_OK");
cout << "Key imported." << endl << endl;
cout << "Setting up identity for mistrust.undo.test@pep-project.org and making comm_type PEP_ct_pEp." << endl;
pEp_identity* recip1 = new_identity("mistrust.undo.test@pep-project.org", NULL, "TOFU_mistrust.undo.test@pep-project.org", "Mistrust Undo");
status = update_identity(session,recip1);
TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
TEST_ASSERT_MSG((strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0), "strcmp(recip1->fpr, \"BACC7A60A88A39A25D99B4A545D7542F39E5DAB5\") == 0");
// First, we need the fpr to be in the DB system.
status = set_identity(session,recip1);
// Then we update the trust.
// This is not an external function. We use it to expedite the test since we don't do a sync exchange here.
status = update_trust_for_fpr(session, recip1->fpr, PEP_ct_pEp);
// Then we retrieve the new trust.
status = update_identity(session,recip1);
TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_pEp), "recip1->comm_type == PEP_ct_pEp");
TEST_ASSERT_MSG((strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0), "strcmp(recip1->fpr, \"BACC7A60A88A39A25D99B4A545D7542F39E5DAB5\") == 0");
cout << "mistrust.undo.test@pep-project.org set up and comm_type is PEP_ct_pEp." << endl << endl;
// Ok, mistrust away
cout << "Mistrusting mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5)." << endl;
status = key_mistrusted(session, recip1);
TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
status = update_identity(session,recip1);
TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_key_not_found), "recip1->comm_type == PEP_ct_key_not_found");
recip1->fpr = strdup("BACC7A60A88A39A25D99B4A545D7542F39E5DAB5");
status = get_trust(session, recip1);
TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_mistrusted), "recip1->comm_type == PEP_ct_mistrusted");
cout << "Mistrusted mistrust.undo.test@pep-project.org (BACC7A60A88A39A25D99B4A545D7542F39E5DAB5) and comm_type IN DB set to PEP_ct_mistrusted)." << endl << endl;
cout << "Undo mistrust (restore identity and trust in DB)" << endl;
// Undo it
status = undo_last_mistrust(session);
TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
status = update_identity(session, recip1);
TEST_ASSERT_MSG((recip1->comm_type == PEP_ct_pEp), "recip1->comm_type == PEP_ct_pEp");
TEST_ASSERT_MSG((strcmp(recip1->fpr, "BACC7A60A88A39A25D99B4A545D7542F39E5DAB5") == 0), "strcmp(recip1->fpr, \"BACC7A60A88A39A25D99B4A545D7542F39E5DAB5\") == 0");
cout << "Undo mistrust (restore identity and trust in DB) - trust is now PEP_ct_pEp." << endl << endl;
cout << "Success!!!" << endl << endl;
free_identity(recip1);
}

Loading…
Cancel
Save