Browse Source

ENGINE-866: Test and use the sticky bit

Krista Bennett 2 months ago
parent
commit
23fec59a9a
6 changed files with 144 additions and 11 deletions
  1. +7
    -0
      src/key_reset.c
  2. +3
    -3
      src/keymanagement.c
  3. +1
    -1
      src/keymanagement.h
  4. +1
    -0
      sync/cond_act_sync.yml2
  5. +131
    -6
      test/src/KeyResetMessageTest.cc
  6. +1
    -1
      test/src/StickyBitTest.cc

+ 7
- 0
src/key_reset.c View File

@ -1327,6 +1327,13 @@ DYNAMIC_API PEP_STATUS key_reset_own_grouped_keys(PEP_SESSION session) {
for (curr_key = keys; curr_key && curr_key->value; curr_key = curr_key->next) {
identity_list* key_idents = NULL;
const char* own_key = curr_key->value;
// If the sticky bit is set, ignore this beast
bool is_sticky = false;
status = get_key_sticky_bit_for_user(session, user_id, own_key, &is_sticky);
if (is_sticky)
continue;
status = get_identities_by_main_key_id(session, own_key, &key_idents);
if (status == PEP_CANNOT_FIND_IDENTITY) {


+ 3
- 3
src/keymanagement.c View File

@ -2116,16 +2116,16 @@ PEP_STATUS update_key_sticky_bit_for_user(PEP_SESSION session,
}
PEP_STATUS get_key_sticky_bit_for_user(PEP_SESSION session,
pEp_identity* ident,
const char* user_id,
const char* fpr,
bool* is_sticky) {
PEP_STATUS status = PEP_STATUS_OK;
if (!session || !ident || !is_sticky || EMPTYSTR(ident->user_id) || EMPTYSTR(fpr))
if (!session || !is_sticky || EMPTYSTR(user_id) || EMPTYSTR(fpr))
return PEP_ILLEGAL_VALUE;
sqlite3_reset(session->is_key_sticky_for_user);
sqlite3_bind_text(session->is_key_sticky_for_user, 1, ident->user_id, -1,
sqlite3_bind_text(session->is_key_sticky_for_user, 1, user_id, -1,
SQLITE_STATIC);
sqlite3_bind_text(session->is_key_sticky_for_user, 2, fpr, -1,
SQLITE_STATIC);


+ 1
- 1
src/keymanagement.h View File

@ -584,7 +584,7 @@ PEP_STATUS get_valid_pubkey(PEP_SESSION session,
PEP_STATUS get_key_sticky_bit_for_user(PEP_SESSION session,
pEp_identity* ident,
const char* user_id,
const char* fpr,
bool* is_sticky);


+ 1
- 0
sync/cond_act_sync.yml2 View File

@ -603,6 +603,7 @@ action disable
action resetOwnGroupedKeys
||
// Will NOT reset keys with the sticky bit set
return key_reset_own_grouped_keys(session);
||


+ 131
- 6
test/src/KeyResetMessageTest.cc View File

@ -1101,6 +1101,129 @@ TEST_F(KeyResetMessageTest, check_reset_grouped_own_multiple_keys_multiple_ident
free_identity(alex_id3);
}
TEST_F(KeyResetMessageTest, check_reset_all_own_grouped_with_sticky) {
char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
NULL,
"AlexID",
"Alexander Braithwaite");
pEp_identity* alex_id2 = new_identity("pep.test.alexander6@darthmama.org",
NULL,
"AlexID",
"Alexander Braithwaite");
pEp_identity* alex_id3 = new_identity("pep.test.alexander6a@darthmama.org",
NULL,
"AlexID",
"Alexander Braithwaite");
PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x0019697D_priv.asc");
status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x503B14D8_priv.asc");
status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xA216E95A_priv.asc");
// sticky - false
alex_id->me = true;
status = set_own_key(session, alex_id, pubkey1);
ASSERT_EQ(status, PEP_STATUS_OK);
status = set_identity_flags(session, alex_id, alex_id->flags | PEP_idf_devicegroup);
ASSERT_EQ(status , PEP_STATUS_OK);
// sticky - true
alex_id2->me = true;
status = set_own_imported_key(session, alex_id2, pubkey2);
ASSERT_EQ(status, PEP_STATUS_OK);
status = set_identity_flags(session, alex_id2, alex_id2->flags | PEP_idf_not_for_sync);
ASSERT_EQ(status , PEP_STATUS_OK);
// sticky - true
alex_id3->me = true;
status = set_own_imported_key(session, alex_id3, pubkey3);
ASSERT_EQ(status, PEP_STATUS_OK);
status = set_identity_flags(session, alex_id3, alex_id3->flags | PEP_idf_devicegroup);
ASSERT_EQ(status , PEP_STATUS_OK);
status = myself(session, alex_id);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_STREQ(pubkey1, alex_id->fpr);
status = myself(session, alex_id2);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_STREQ(pubkey2, alex_id2->fpr);
status = myself(session, alex_id3);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_STREQ(pubkey3, alex_id3->fpr);
status = key_reset_own_grouped_keys(session);
free(alex_id->fpr);
alex_id->fpr = strdup(pubkey1);
status = get_trust(session, alex_id);
ASSERT_EQ(alex_id->comm_type , PEP_ct_mistrusted);
free(alex_id2->fpr);
alex_id2->fpr = strdup(pubkey2);
status = get_trust(session, alex_id2);
ASSERT_EQ(alex_id2->comm_type , PEP_ct_pEp);
free(alex_id3->fpr);
alex_id3->fpr = strdup(pubkey3);
status = get_trust(session, alex_id3);
ASSERT_EQ(alex_id3->comm_type , PEP_ct_pEp);
bool revoked = false;
status = key_revoked(session, pubkey1, &revoked);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_TRUE(revoked);
revoked = false;
status = key_revoked(session, pubkey2, &revoked);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_FALSE(revoked);
revoked = false;
status = key_revoked(session, pubkey3, &revoked);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_FALSE(revoked);
status = myself(session, alex_id);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_STRNE(pubkey1, alex_id->fpr);
status = myself(session, alex_id2);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_STREQ(pubkey2, alex_id2->fpr);
status = myself(session, alex_id3);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_STREQ(pubkey3, alex_id3->fpr);
ASSERT_EQ(m_queue.size(),1);
if (true) {
ofstream outfile;
string fname = "test_mails/check_reset_all_own_grouped_sticky.eml";
outfile.open(fname);
char* msg_txt = NULL;
mime_encode_message(m_queue[0], false, &msg_txt, false);
outfile << msg_txt;
outfile.close();
cout << " // For " << alex_id->address << endl;
cout << " const char* replkey1 = \"" << alex_id->fpr << "\";" << endl;
}
free_identity(alex_id);
free_identity(alex_id2);
free_identity(alex_id3);
}
TEST_F(KeyResetMessageTest, check_reset_all_own_grouped) {
char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
@ -1208,25 +1331,27 @@ TEST_F(KeyResetMessageTest, check_reset_all_own_grouped) {
ofstream outfile;
int i = 0;
for (vector<message*>::iterator it = m_queue.begin(); it != m_queue.end(); it++, i++) {
message* curr_sent_msg = *it;
message* curr_sent_msg = *it;
string fname = string("test_mails/check_reset_all_own_grouped") + to_string(i) + ".eml";
outfile.open(fname);
char* msg_txt = NULL;
mime_encode_message(curr_sent_msg, false, &msg_txt, false);
outfile << msg_txt;
outfile.close();
outfile.close();
}
cout << " // For " << alex_id->address << endl;
cout << " const char* replkey1 = \"" << alex_id->fpr << "\";" << endl;
cout << " // For " << alex_id3->address << endl;
cout << " const char* replkey3 = \"" << alex_id3->fpr << "\";" << endl;
}
cout << " const char* replkey1 = \"" << alex_id->fpr << "\";" << endl;
cout << " // For " << alex_id3->address << endl;
cout << " const char* replkey3 = \"" << alex_id3->fpr << "\";" << endl;
}
free_identity(alex_id);
free_identity(alex_id2);
free_identity(alex_id3);
}
TEST_F(KeyResetMessageTest, check_reset_all_own_grouped_recv) {
PEP_STATUS status = PEP_STATUS_OK;
char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");


+ 1
- 1
test/src/StickyBitTest.cc View File

@ -92,7 +92,7 @@ TEST_F(StickyBitTest, check_set_sticky_bit_normal) {
status = myself(session, me);
ASSERT_EQ(status , PEP_STATUS_OK);
bool sticky = false;
status = get_key_sticky_bit_for_user(session, me, bob_fpr, &sticky);
status = get_key_sticky_bit_for_user(session, me->user_id, bob_fpr, &sticky);
ASSERT_TRUE(sticky);
free_identity(me);
}

Loading…
Cancel
Save