Browse Source

first version compiles for key_reset_and_deliver_revocations

add_key_notification
parent
commit
c90df49169
4 changed files with 124 additions and 16 deletions
  1. +110
    -9
      src/key_reset.c
  2. +8
    -1
      src/key_reset.h
  3. +1
    -1
      src/pEp_internal.h
  4. +5
    -5
      test/src/KeyResetMessageTest.cc

+ 110
- 9
src/key_reset.c View File

@ -156,7 +156,7 @@ PEP_STATUS receive_key_reset(PEP_SESSION session,
new_fpr = strdup(p + 5);
// Reset the original key
status = key_reset(session, old_fpr, temp_ident);
status = key_reset(session, old_fpr, temp_ident, NULL, NULL);
if (status != PEP_STATUS_OK)
goto pEp_free;
@ -334,7 +334,7 @@ DYNAMIC_API PEP_STATUS key_reset_identity(
if (!session || !ident || (ident && (EMPTYSTR(ident->user_id) || EMPTYSTR(ident->address))))
return PEP_ILLEGAL_VALUE;
return key_reset(session, fpr, ident);
return key_reset(session, fpr, ident, NULL, NULL);
}
DYNAMIC_API PEP_STATUS key_reset_user(
@ -353,13 +353,13 @@ DYNAMIC_API PEP_STATUS key_reset_user(
if (is_me(session, input_ident) && EMPTYSTR(fpr))
return PEP_ILLEGAL_VALUE;
PEP_STATUS status = key_reset(session, fpr, input_ident);
PEP_STATUS status = key_reset(session, fpr, input_ident, NULL, NULL);
free_identity(input_ident);
return status;
}
DYNAMIC_API PEP_STATUS key_reset_all_own_keys(PEP_SESSION session) {
return key_reset(session, NULL, NULL);
return key_reset(session, NULL, NULL, NULL, NULL);
}
// Notes to integrate into header:
@ -367,7 +367,9 @@ DYNAMIC_API PEP_STATUS key_reset_all_own_keys(PEP_SESSION session) {
PEP_STATUS key_reset(
PEP_SESSION session,
const char* key_id,
pEp_identity* ident
pEp_identity* ident,
identity_list** own_identities,
stringlist_t** own_revoked_fprs
)
{
if (!session || (ident && EMPTYSTR(ident->user_id)))
@ -417,7 +419,7 @@ PEP_STATUS key_reset(
for (curr_key = keys; curr_key && curr_key->value; curr_key = curr_key->next) {
// FIXME: Is the ident really necessary?
status = key_reset(session, curr_key->value, tmp_ident);
status = key_reset(session, curr_key->value, tmp_ident, own_identities, own_revoked_fprs);
if (status != PEP_STATUS_OK)
break;
}
@ -497,7 +499,7 @@ PEP_STATUS key_reset(
pEp_identity* this_identity = curr_ident->ident;
// Do the full reset on this identity
status = key_reset(session, fpr_copy, this_identity);
status = key_reset(session, fpr_copy, this_identity, own_identities, own_revoked_fprs);
// Ident list gets freed below, do not free here!
@ -512,7 +514,8 @@ PEP_STATUS key_reset(
}
}
// Create revocation
// Base case for is_own_private starts here
status = revoke_key(session, fpr_copy, NULL);
// If we have a full identity, we have some cleanup and generation tasks here
@ -526,9 +529,23 @@ PEP_STATUS key_reset(
new_key = strdup(tmp_ident->fpr);
// status = set_own_key(session, tmp_ident, new_key);
}
if (own_revoked_fprs) {
// We can dedup this later
if (!(*own_revoked_fprs))
*own_revoked_fprs = new_stringlist(NULL);
char* revkey = strdup(fpr_copy);
if (!revkey) {
status = PEP_OUT_OF_MEMORY;
goto pEp_free;
}
stringlist_add(*own_revoked_fprs, revkey);
}
// mistrust fpr from trust
tmp_ident->fpr = fpr_copy;
tmp_ident->comm_type = PEP_ct_mistrusted;
status = set_trust(session, tmp_ident);
tmp_ident->fpr = NULL;
@ -538,6 +555,18 @@ PEP_STATUS key_reset(
// Update fpr for outgoing
status = myself(session, tmp_ident);
}
if (own_identities) {
if (!(*own_identities))
*own_identities = new_identity_list(NULL);
pEp_identity* new_ident = identity_dup(tmp_ident);
if (!new_ident) {
status = PEP_OUT_OF_MEMORY;
goto pEp_free;
}
identity_list_add(*own_identities, new_ident);
}
}
if (status == PEP_STATUS_OK)
@ -577,6 +606,7 @@ PEP_STATUS key_reset(
// we want it gone anyway)
//
// Delete this key from the keyring.
// FIXME: when key election disappears, so should this!
status = delete_keypair(session, fpr_copy);
}
@ -604,3 +634,74 @@ pEp_free:
free(new_key);
return status;
}
static stringlist_t* collect_key_material(PEP_SESSION session, stringlist_t* fprs) {
stringlist_t* keydata = NULL;
stringlist_t* curr_fpr = fprs;
while (curr_fpr) {
if (curr_fpr->value) {
char* key_material = NULL;
size_t datasize = 0;
PEP_STATUS status = export_key(session, curr_fpr->value, &key_material, &datasize);
if (status) {
free_stringlist(keydata);
return NULL;
}
if (datasize > 0 && key_material) {
if (!(keydata))
keydata = new_stringlist(NULL);
stringlist_add(keydata, key_material);
}
}
curr_fpr = curr_fpr->next;
}
return keydata;
}
PEP_STATUS key_reset_own_and_deliver_revocations(PEP_SESSION session,
identity_list** own_identities,
stringlist_t** revocations,
stringlist_t** keys) {
if (!(session && own_identities && revocations && keys))
return PEP_ILLEGAL_VALUE;
stringlist_t* revoked_fprs = NULL;
identity_list* affected_idents = NULL;
PEP_STATUS status = key_reset(session, NULL, NULL, &affected_idents, &revoked_fprs);
// FIXME: free things
if (status != PEP_STATUS_OK)
return status;
dedup_stringlist(revoked_fprs);
*revocations = collect_key_material(session, revoked_fprs);
stringlist_t* keydata = NULL;
if (affected_idents) {
keydata = new_stringlist(NULL);
identity_list* curr_ident = affected_idents;
while (curr_ident) {
if (curr_ident->ident && curr_ident->ident->fpr) {
char* key_material = NULL;
size_t datasize = 0;
status = export_key(session, curr_ident->ident->fpr, &key_material, &datasize);
if (status) {
free_stringlist(keydata);
return status;
}
if (datasize > 0 && key_material)
stringlist_add(keydata, key_material);
}
}
}
*own_identities = affected_idents;
*keys = keydata;
free(revoked_fprs);
return PEP_STATUS_OK;
}

+ 8
- 1
src/key_reset.h View File

@ -122,10 +122,17 @@ DYNAMIC_API PEP_STATUS key_reset_all_own_keys(PEP_SESSION session);
PEP_STATUS key_reset(
PEP_SESSION session,
const char* fpr,
pEp_identity* ident
pEp_identity* ident,
identity_list** own_identities,
stringlist_t** own_revoked_fprs
);
PEP_STATUS key_reset_own_and_deliver_revocations(PEP_SESSION session,
identity_list** own_identities,
stringlist_t** revocations,
stringlist_t** keys);
PEP_STATUS has_key_reset_been_sent(
PEP_SESSION session,


+ 1
- 1
src/pEp_internal.h View File

@ -228,6 +228,7 @@ struct _pEpSession {
sqlite3_stmt *is_own_address;
sqlite3_stmt *own_identities_retrieve;
sqlite3_stmt *own_keys_retrieve;
sqlite3_stmt *key_identities_retrieve;
sqlite3_stmt *get_user_default_key;
sqlite3_stmt *get_all_keys_for_user;
@ -570,4 +571,3 @@ static inline int Sqlite3_step(sqlite3_stmt* stmt)
} while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
return rc;
}

+ 5
- 5
test/src/KeyResetMessageTest.cc View File

@ -307,7 +307,7 @@ TEST_F(KeyResetMessageTest, check_reset_key_and_notify) {
);
ASSERT_EQ(int_result , SQLITE_OK);
status = key_reset(session, alice_fpr, from_ident);
status = key_reset(session, alice_fpr, from_ident, NULL, NULL);
ASSERT_EQ(status , PEP_STATUS_OK);
ASSERT_GT(m_queue.size(), 0);
status = myself(session, from_ident);
@ -460,7 +460,7 @@ TEST_F(KeyResetMessageTest, check_receive_message_to_revoked_key_from_unknown) {
ASSERT_STRCASEEQ(from_ident->fpr, alice_fpr);
ASSERT_TRUE(from_ident->me);
status = key_reset(session, alice_fpr, from_ident);
status = key_reset(session, alice_fpr, from_ident, NULL, NULL);
ASSERT_EQ(status , PEP_STATUS_OK);
m_queue.clear();
@ -524,7 +524,7 @@ TEST_F(KeyResetMessageTest, check_receive_message_to_revoked_key_from_contact) {
// FIXME: longer term we need to fix the test, but the key attached to the message below has expired, so for now, we give her a new key
slurp_and_import_key(session, "test_keys/pub/pep-test-gabrielle-0xE203586C_pub.asc");
status = key_reset(session, alice_fpr, from_ident);
status = key_reset(session, alice_fpr, from_ident, NULL, NULL);
ASSERT_EQ(status , PEP_STATUS_OK);
ASSERT_EQ(m_queue.size() , 0);
m_queue.clear();
@ -570,10 +570,10 @@ TEST_F(KeyResetMessageTest, check_multiple_resets_single_key) {
ASSERT_STRCASEEQ(from_ident->fpr, alice_fpr);
ASSERT_TRUE(from_ident->me);
status = key_reset(session, NULL, NULL);
status = key_reset(session, NULL, NULL, NULL, NULL);
ASSERT_EQ(status , PEP_STATUS_OK);
status = key_reset(session, NULL, NULL);
status = key_reset(session, NULL, NULL, NULL, NULL);
ASSERT_EQ(status , PEP_STATUS_OK);
status = myself(session, from_ident);


Loading…
Cancel
Save