Browse Source

Remove own_keys table, added PEP_OWN_USERID, unique person userId for any own identities and keys.

doc_update_sequoia
Edouard Tisserant 6 years ago
parent
commit
12a7477ed6
5 changed files with 35 additions and 76 deletions
  1. +16
    -49
      src/keymanagement.c
  2. +0
    -9
      src/keymanagement.h
  3. +17
    -17
      src/pEpEngine.c
  4. +2
    -0
      src/pEpEngine.h
  5. +0
    -1
      src/pEp_internal.h

+ 16
- 49
src/keymanagement.c View File

@ -249,17 +249,29 @@ DYNAMIC_API PEP_STATUS myself(PEP_SESSION session, pEp_identity * identity)
assert(identity);
assert(identity->address);
assert(identity->username);
assert(identity->user_id);
assert(EMPTYSTR(identity->user_id) ||
strcmp(identity->user_id, PEP_OWN_USERID) == 0);
if (!(session && identity && identity->address && identity->username &&
identity->user_id))
(EMPTYSTR(identity->user_id) ||
strcmp(identity->user_id, PEP_OWN_USERID) == 0)))
return PEP_ILLEGAL_VALUE;
identity->comm_type = PEP_ct_pEp;
identity->me = true;
if(EMPTYSTR(identity->user_id))
{
free(identity->user_id);
identity->user_id = strdup(PEP_OWN_USERID);
assert(identity->user_id);
if (identity->user_id == NULL)
{
return PEP_OUT_OF_MEMORY;
}
}
DEBUG_LOG("myself", "debug", identity->address);
status = get_identity(session,
identity->address,
@ -280,22 +292,13 @@ DYNAMIC_API PEP_STATUS myself(PEP_SESSION session, pEp_identity * identity)
return PEP_OUT_OF_MEMORY;
}
}
// Backward compatibility, not check that stored key is indeed own key
}
else if (!EMPTYSTR(identity->fpr))
{
// App must have a good reason to give fpr, such as explicit
// import of private key, or similar.
// Take given fpr as-is, and consider it as own-key.
status = own_key_add(session, identity->fpr);
assert(status == PEP_STATUS_OK);
if (status != PEP_STATUS_OK) {
return status;
}
// Take given fpr as-is.
}
else
{
@ -392,14 +395,6 @@ DYNAMIC_API PEP_STATUS myself(PEP_SESSION session, pEp_identity * identity)
free_stringlist(keylist);
return PEP_UNKNOWN_ERROR;
}
// Consider generated keys as own keys.
status = own_key_add(session, identity->fpr);
assert(status == PEP_STATUS_OK);
if (status != PEP_STATUS_OK) {
free_stringlist(keylist);
return status;
}
}
else
{
@ -582,34 +577,6 @@ DYNAMIC_API PEP_STATUS trust_personal_key(
return status;
}
DYNAMIC_API PEP_STATUS own_key_add(PEP_SESSION session, const char *fpr)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(session && fpr && fpr[0]);
if (!(session && fpr && fpr[0]))
return PEP_ILLEGAL_VALUE;
sqlite3_reset(session->own_key_add);
sqlite3_bind_text(session->own_key_add, 1, fpr, -1, SQLITE_STATIC);
int result;
result = sqlite3_step(session->own_key_add);
switch (result) {
case SQLITE_DONE:
status = PEP_STATUS_OK;
break;
default:
status = PEP_UNKNOWN_ERROR;
}
sqlite3_reset(session->own_key_add);
return status;
}
DYNAMIC_API PEP_STATUS own_key_is_listed(
PEP_SESSION session,
const char *fpr,


+ 0
- 9
src/keymanagement.h View File

@ -152,15 +152,6 @@ DYNAMIC_API PEP_STATUS key_reset_trust(
pEp_identity *ident
);
// own_key_add() - add to own keys
//
// parameters:
// session (in) session to use
// fpr (in) fingerprint of owned key
DYNAMIC_API PEP_STATUS own_key_add(PEP_SESSION session, const char *fpr);
// own_key_is_listed() - returns true id key is listed as own key
//


+ 17
- 17
src/pEpEngine.c View File

@ -31,7 +31,6 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
static const char *sql_blacklist_retrieve;
// Own keys
static const char *sql_own_key_add;
static const char *sql_own_key_is_listed;
static const char *sql_own_key_retrieve;
@ -176,12 +175,6 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
"create table if not exists blacklist_keys (\n"
" fpr text primary key\n"
");\n"
// Own keys
"create table if not exists own_keys (\n"
" fpr text primary key\n"
" references pgp_keypair (fpr)\n"
" on delete cascade\n"
");\n"
// sequences
"create table if not exists sequences(\n"
" name text primary key,\n"
@ -262,13 +255,24 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
// Own keys
sql_own_key_add = "insert or replace into own_keys (fpr) "
" values (upper(replace(?1,' ',''))) ;";
sql_own_key_is_listed =
"select count(*) from ("
" select main_key_id from person "
" where main_key_id = upper(replace(?1,' ',''))"
" and id = '" PEP_OWN_USERID "' "
" union "
" select main_key_id from identity "
" where main_key_id = upper(replace(?1,' ',''))"
" and user_id = '" PEP_OWN_USERID "' );";
sql_own_key_retrieve = "select main_key_id from person "
" where main_key_id is not null"
" and id = '" PEP_OWN_USERID "' "
"union "
" select main_key_id from identity "
" where main_key_id is not null"
" and user_id = '" PEP_OWN_USERID "' ;";
sql_own_key_is_listed = "select count(*) from own_keys where fpr = upper(replace(?1,' ','')) ;";
sql_own_key_retrieve = "select * from own_keys ;";
sql_sequence_value1 = "insert or replace into sequences (name, value) "
"values (?1, "
"(select coalesce((select value + 1 from sequences "
@ -348,10 +352,6 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
// Own keys
int_result = sqlite3_prepare_v2(_session->db, sql_own_key_add,
(int)strlen(sql_own_key_add), &_session->own_key_add, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_own_key_is_listed,
(int)strlen(sql_own_key_is_listed), &_session->own_key_is_listed, NULL);
assert(int_result == SQLITE_OK);


+ 2
- 0
src/pEpEngine.h View File

@ -14,6 +14,8 @@ extern "C" {
#define PEP_VERSION "1.0"
#define PEP_OWN_USERID "pEp_own_userId"
// pEp Engine API
// caveat:


+ 0
- 1
src/pEp_internal.h View File

@ -108,7 +108,6 @@ typedef struct _pEpSession {
sqlite3_stmt *blacklist_retrieve;
// Own keys
sqlite3_stmt *own_key_add;
sqlite3_stmt *own_key_is_listed;
sqlite3_stmt *own_key_retrieve;


Loading…
Cancel
Save