Browse Source

ENGINE-693: integrated with key reset at least. Needs explicit testing, but breaks nothing right now.

add_key_notification
parent
commit
c3158beff8
4 changed files with 88 additions and 5 deletions
  1. +43
    -4
      src/key_reset.c
  2. +41
    -1
      src/pEpEngine.c
  3. +3
    -0
      src/pEpEngine.h
  4. +1
    -0
      src/pEp_internal.h

+ 43
- 4
src/key_reset.c View File

@ -572,6 +572,11 @@ PEP_STATUS receive_key_reset(PEP_SESSION session,
// Make new key the default
curr_ident->fpr = new_fpr;
// Whether new_key is NULL or not, if this key is equal to the current user default, we
// replace it.
status = replace_main_user_fpr_if_equal(session, curr_ident->user_id,
new_fpr, old_fpr);
// This only sets as the default, does NOT TRUST IN ANY WAY
PEP_comm_type new_key_rating = PEP_ct_unknown;
@ -601,6 +606,7 @@ PEP_STATUS receive_key_reset(PEP_SESSION session,
// then so be it - but we need to double-check to
// ensure that in this case, we end up with a private one,
// so talk to vb about this.
// Make new key the default
// This is REQUIRED for set_own_key (see doc)
@ -610,15 +616,27 @@ PEP_STATUS receive_key_reset(PEP_SESSION session,
if (status != PEP_STATUS_OK)
return status;
// Whether new_key is NULL or not, if this key is equal to the current user default, we
// replace it.
status = replace_main_user_fpr_if_equal(session, curr_ident->user_id,
new_fpr, old_fpr);
if (status != PEP_STATUS_OK)
return status;
status = myself(session, curr_ident);
if (status != PEP_STATUS_OK)
return status;
char* old_copy = NULL;
char* new_copy = NULL;
old_copy = strdup(old_fpr);
new_copy = strdup(new_fpr);
if (!old_copy || !new_copy)
return PEP_OUT_OF_MEMORY;
stringpair_t* revp = new_stringpair(old_copy, new_copy);
if (!rev_pairs) {
@ -636,11 +654,12 @@ PEP_STATUS receive_key_reset(PEP_SESSION session,
new_fpr = NULL;
}
// actually revoke
// actually revoke - list only exists with own keys
stringpair_list_t* curr_rev_pair = rev_pairs;
while (curr_rev_pair && curr_rev_pair->value) {
char* rev_key = curr_rev_pair->value->key;
char* new_key = curr_rev_pair->value->value;
if (EMPTYSTR(rev_key) || EMPTYSTR(new_key))
return PEP_UNKNOWN_ERROR;
bool revoked = false;
@ -659,7 +678,8 @@ PEP_STATUS receive_key_reset(PEP_SESSION session,
status = set_revoked(session, rev_key, new_key, time(NULL));
if (status != PEP_STATUS_OK)
goto pEp_free;
goto pEp_free;
curr_rev_pair = curr_rev_pair->next;
}
@ -981,6 +1001,7 @@ static PEP_STATUS _key_reset_device_group_for_shared_key(PEP_SESSION session,
return status;
}
free(ident->fpr);
// release ownership to the struct again
ident->fpr = new_key;
@ -989,6 +1010,16 @@ static PEP_STATUS _key_reset_device_group_for_shared_key(PEP_SESSION session,
if (status == PEP_STATUS_OK)
status = set_revoked(session, old_key, new_key, time(NULL));
if (status != PEP_STATUS_OK)
goto pEp_free;
// Whether new_key is NULL or not, if this key is equal to the current user default, we
// replace it.
status = replace_main_user_fpr_if_equal(session,
ident->user_id,
new_key,
old_key);
if (status != PEP_STATUS_OK)
goto pEp_free;
@ -1202,6 +1233,10 @@ PEP_STATUS key_reset(
status = get_identities_by_main_key_id(session, fpr_copy, &key_idents);
if (status != PEP_CANNOT_FIND_IDENTITY) {
// N.B. Possible user default key replacement will happen inside
// _key_reset_device_group_for_shared_key in the first case.
// We handle the reassignment for the second case in the block here.
if (is_grouped)
status = _key_reset_device_group_for_shared_key(session, key_idents, fpr_copy, false);
else if (status == PEP_STATUS_OK) {
@ -1267,7 +1302,11 @@ PEP_STATUS key_reset(
if (status == PEP_STATUS_OK)
status = send_key_reset_to_recents(session, this_ident, fpr_copy, new_key);
tmp_ident->fpr = NULL;
}
}
// Whether new_key is NULL or not, if this key is equal to the current user default, we
// replace it.
status = replace_main_user_fpr_if_equal(session, this_ident->user_id, new_key, fpr_copy);
} // Ident list gets freed below, do not free here!
}
// Ok, we've either now reset for each own identity with this key, or


+ 41
- 1
src/pEpEngine.c View File

@ -210,6 +210,11 @@ static const char *sql_get_main_user_fpr =
"select main_key_id from person"
" where id = ?1 ;";
static const char *sql_replace_main_user_fpr_if_equal =
"update person "
" set main_key_id = ?1 "
" where id = ?2 and main_key_id = ?3;";
static const char *sql_refresh_userid_default_key =
"update person "
" set main_key_id = "
@ -886,7 +891,7 @@ static PEP_STATUS upgrade_revoc_contact_to_13(PEP_SESSION session) {
}
}
sqlite3_finalize(update_revoked_w_addr_stmt);
int_result = sqlite3_exec(
session->db,
"delete from revocation_contact_list where own_address is NULL;\n"
@ -1772,6 +1777,10 @@ DYNAMIC_API PEP_STATUS init(
(int)strlen(sql_replace_main_user_fpr), &_session->replace_main_user_fpr, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_replace_main_user_fpr_if_equal,
(int)strlen(sql_replace_main_user_fpr_if_equal), &_session->replace_main_user_fpr_if_equal, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_get_main_user_fpr,
(int)strlen(sql_get_main_user_fpr), &_session->get_main_user_fpr, NULL);
assert(int_result == SQLITE_OK);
@ -2207,6 +2216,8 @@ DYNAMIC_API void release(PEP_SESSION session)
sqlite3_finalize(session->delete_key);
if (session->replace_main_user_fpr)
sqlite3_finalize(session->replace_main_user_fpr);
if (session->replace_main_user_fpr_if_equal)
sqlite3_finalize(session->replace_main_user_fpr_if_equal);
if (session->get_main_user_fpr)
sqlite3_finalize(session->get_main_user_fpr);
if (session->refresh_userid_default_key)
@ -4343,6 +4354,35 @@ PEP_STATUS replace_main_user_fpr(PEP_SESSION session, const char* user_id,
return PEP_STATUS_OK;
}
PEP_STATUS replace_main_user_fpr_if_equal(PEP_SESSION session, const char* user_id,
const char* new_fpr, const char* compare_fpr) {
assert(session);
assert(user_id);
assert(new_fpr);
if (!session || !user_id || !compare_fpr)
return PEP_ILLEGAL_VALUE;
// N.B. new_fpr can be NULL - if there's no key to replace it, this is fine.
// See sqlite3 documentation on sqlite3_bind_text() and sqlite3_bind_null()
int result;
sqlite3_reset(session->replace_main_user_fpr_if_equal);
sqlite3_bind_text(session->replace_main_user_fpr, 1, new_fpr, -1,
SQLITE_STATIC);
sqlite3_bind_text(session->replace_main_user_fpr_if_equal, 2, user_id, -1,
SQLITE_STATIC);
sqlite3_bind_text(session->replace_main_user_fpr_if_equal, 3, compare_fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->replace_main_user_fpr_if_equal);
sqlite3_reset(session->replace_main_user_fpr_if_equal);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_PERSON;
return PEP_STATUS_OK;
}
PEP_STATUS get_main_user_fpr(PEP_SESSION session,
const char* user_id,
char** main_fpr)


+ 3
- 0
src/pEpEngine.h View File

@ -1366,6 +1366,9 @@ PEP_STATUS get_main_user_fpr(PEP_SESSION session,
PEP_STATUS replace_main_user_fpr(PEP_SESSION session, const char* user_id,
const char* new_fpr);
PEP_STATUS replace_main_user_fpr_if_equal(PEP_SESSION session, const char* user_id,
const char* new_fpr, const char* compare_fpr);
DYNAMIC_API PEP_STATUS get_replacement_fpr(
PEP_SESSION session,


+ 1
- 0
src/pEp_internal.h View File

@ -175,6 +175,7 @@ struct _pEpSession {
sqlite3_stmt *get_identities_by_main_key_id;
sqlite3_stmt *replace_identities_fpr;
sqlite3_stmt *replace_main_user_fpr;
sqlite3_stmt *replace_main_user_fpr_if_equal;
sqlite3_stmt *get_main_user_fpr;
sqlite3_stmt *refresh_userid_default_key;
sqlite3_stmt *delete_key;


Loading…
Cancel
Save