ENGINE-289: myself() changes and related fallout. Committing to merge in default.

doc_update_sequoia
Krista Bennett 5 years ago
parent 6e67c08db0
commit 4d9f32d6a1

@ -104,21 +104,32 @@ PEP_STATUS elect_pubkey(
static PEP_STATUS validate_fpr(PEP_SESSION session,
pEp_identity* ident) {
PEP_STATUS status = PEP_STATUS_OK;
if (!session || !ident || !ident->fpr)
return PEP_ILLEGAL_VALUE;
char* fpr = ident->fpr;
PEP_STATUS status = get_trust(session, ident);
if (status != PEP_STATUS_OK)
return ADD_TO_LOG(status);
bool has_private = false;
if (ident->me) {
status = contains_priv_key(session, fpr, &has_private);
if (status != PEP_STATUS_OK || !has_private)
return PEP_KEY_UNSUITABLE;
}
status = get_trust(session, ident);
if (status != PEP_STATUS_OK)
ident->comm_type = PEP_ct_unknown;
PEP_comm_type ct = ident->comm_type;
if (ct == PEP_ct_unknown) {
// If status is bad, it's ok, we get the rating
// we should use then (PEP_ct_unknown)
get_key_rating(session, fpr, &ct);
ident->comm_type = ct;
}
bool revoked, expired;
@ -131,15 +142,19 @@ static PEP_STATUS validate_fpr(PEP_SESSION session,
}
if (!revoked) {
time_t exp_time = (ident->me ?
time(NULL) + (7*24*3600) : time(NULL));
status = key_expired(session, fpr,
time(NULL), // NOW. For _myself, this is different.
exp_time,
&expired);
assert(status == PEP_STATUS_OK);
if (status != PEP_STATUS_OK)
return ADD_TO_LOG(status);
if ((ct | PEP_ct_confirmed) == PEP_ct_OpenPGP) {
if ((ct | PEP_ct_confirmed) == PEP_ct_OpenPGP &&
!ident->me) {
status = blacklist_is_listed(session,
fpr,
&blacklisted);
@ -149,7 +164,7 @@ static PEP_STATUS validate_fpr(PEP_SESSION session,
}
}
if (ident->me && (ct == PEP_ct_pEp) && !revoked && expired) {
if (ident->me && (ct >= PEP_ct_strong_but_unconfirmed) && !revoked && expired) {
// extend key
timestamp *ts = new_timestamp(time(NULL) + KEY_EXPIRE_DELTA);
status = renew_key(session, fpr, ts);
@ -159,21 +174,23 @@ static PEP_STATUS validate_fpr(PEP_SESSION session,
// if key is valid (second check because pEp key might be extended above)
// Return fpr
status = key_expired(session, fpr, time(NULL), &expired);
if (status != PEP_STATUS_OK)
if (status != PEP_STATUS_OK) {
ident->comm_type = PEP_ct_key_expired;
return ADD_TO_LOG(status);
}
// communicate key(?)
}
}
if (revoked)
if (revoked)
ct = PEP_ct_key_revoked;
else if (expired)
ct = PEP_ct_key_expired;
else if (blacklisted) {
else if (blacklisted) { // never true for .me
ident->comm_type = ct = PEP_ct_key_not_found;
free(ident->fpr);
ident->fpr = strdup("");
status = PEP_KEY_UNSUITABLE;
status = PEP_KEY_BLACKLISTED;
}
switch (ct) {
@ -187,7 +204,7 @@ static PEP_STATUS validate_fpr(PEP_SESSION session,
ct);
free(ident->fpr);
ident->fpr = strdup("");
ident->comm_type = PEP_ct_key_not_found;
ident->comm_type = ct;
status = PEP_KEY_UNSUITABLE;
default:
break;
@ -196,15 +213,47 @@ static PEP_STATUS validate_fpr(PEP_SESSION session,
return status;
}
PEP_STATUS get_user_default_key(PEP_SESSION session, const char* user_id,
char** default_key) {
assert(session);
assert(user_id);
if (!session || !user_id)
return PEP_ILLEGAL_VALUE;
PEP_STATUS status = PEP_STATUS_OK;
// try to get default key for user_data
sqlite3_reset(session->get_user_default_key);
sqlite3_bind_text(session->get_user_default_key, 1, user_id,
-1, SQLITE_STATIC);
const int result = sqlite3_step(session->get_user_default_key);
char* user_fpr = NULL;
if (result == SQLITE_ROW) {
const char* u_fpr =
(char *) sqlite3_column_text(session->get_user_default_key, 0);
if (u_fpr)
user_fpr = strdup(u_fpr);
}
else
status = PEP_GET_KEY_FAILED;
sqlite3_reset(session->get_user_default_key);
*default_key = user_fpr;
return status;
}
// Only call on retrieval of previously stored identity!
// Also, we presume that if the stored_identity was sent in
// without an fpr, there wasn't one in the trust DB for this
// identity.
PEP_STATUS get_valid_pubkey(PEP_SESSION session,
pEp_identity* stored_identity,
bool* is_identity_default,
bool* is_user_default,
bool* is_address_default) {
pEp_identity* stored_identity,
bool* is_identity_default,
bool* is_user_default,
bool* is_address_default) {
PEP_STATUS status = PEP_STATUS_OK;
@ -213,7 +262,7 @@ PEP_STATUS get_valid_pubkey(PEP_SESSION session,
return PEP_ILLEGAL_VALUE;
*is_identity_default = *is_user_default = *is_address_default = false;
char* stored_fpr = stored_identity->fpr;
// Input: stored identity retrieved from database
// if stored identity contains a default key
@ -228,20 +277,8 @@ PEP_STATUS get_valid_pubkey(PEP_SESSION session,
free(stored_identity->fpr);
stored_identity->fpr = NULL;
// try to get default key for user_data
sqlite3_reset(session->get_user_default_key);
sqlite3_bind_text(session->get_user_default_key, 1, stored_identity->user_id,
-1, SQLITE_STATIC);
const int result = sqlite3_step(session->get_user_default_key);
char* user_fpr = NULL;
if (result == SQLITE_ROW) {
const char* u_fpr =
(char *) sqlite3_column_text(session->get_user_default_key, 0);
if (u_fpr)
user_fpr = strdup(u_fpr);
}
sqlite3_reset(session->get_user_default_key);
status = get_user_default_key(session, stored_identity->user_id, &user_fpr);
if (user_fpr) {
// There exists a default key for user, so validate
@ -271,16 +308,13 @@ PEP_STATUS get_valid_pubkey(PEP_SESSION session,
free(stored_identity->fpr);
stored_identity->fpr = NULL;
stored_identity->comm_type = PEP_ct_unknown;
break;
break;
default:
// FIXME: blacklisting?
break;
}
return status;
}
PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen, bool ignore_flags);
static void transfer_ident_lang_and_flags(pEp_identity* new_ident,
pEp_identity* stored_ident) {
if (new_ident->lang[0] == 0) {
@ -387,12 +421,12 @@ DYNAMIC_API PEP_STATUS update_identity(
if (!(session && identity && !EMPTYSTR(identity->address)))
return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
char* own_id = NULL;
status = get_own_userid(session, &own_id);
char* default_own_id = NULL;
status = get_default_own_userid(session, &default_own_id);
// Is this me, temporary or not? If so, BAIL.
if (identity->me ||
(own_id && identity->user_id && (strcmp(own_id, identity->user_id) == 0)))
(default_own_id && identity->user_id && (strcmp(default_own_id, identity->user_id) == 0)))
{
return PEP_ILLEGAL_VALUE;
}
@ -692,29 +726,33 @@ PEP_STATUS _has_usable_priv_key(PEP_SESSION session, char* fpr,
PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen, bool ignore_flags)
{
pEp_identity *stored_identity = NULL;
PEP_STATUS status;
assert(session);
assert(identity);
assert(!EMPTYSTR(identity->address));
assert(!EMPTYSTR(identity->user_id));
if (!session || !identity || EMPTYSTR(identity->address))
if (!session || !identity || EMPTYSTR(identity->address) ||
EMPTYSTR(identity->user_id))
return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
pEp_identity *stored_identity = NULL;
char* revoked_fpr = NULL;
char* own_id = NULL;
status = get_own_userid(session, &own_id);
// Deal with user_id mismatches - if the own_id in the DB and the
// input ID both exist and don't match, this is only allowed when
// a temporary PEP_OWN_USERID has been put into the DB; the user_id
// here will then replace it. (Database cascades changes)
if (own_id && !EMPTYSTR(identity->user_id)) {
if (strcmp(own_id, identity->user_id) != 0)) {
if (strcmp(own_id, PEP_OWN_USERID) != 0) {
free(own_id);
return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
}
char* default_own_id = NULL;
status = get_default_own_userid(session, &default_own_id);
// Deal with non-default user_ids.
if (default_own_id && strcmp(default_own_id, identity->user_id) != 0) {
// status = add_alternate_own_userid(session,
// identity->user_id);
free(identity->user_id);
identity->user_id = strdup(default_own_id);
if (identity->user_id == NULL) {
status = PEP_OUT_OF_MEMORY;
goto pep_free;
}
}
@ -729,27 +767,6 @@ PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen,
if(ignore_flags)
identity->flags = 0;
if (EMPTYSTR(identity->user_id))
{
free(identity->user_id);
// If we have have no information, we use as temp PEP_OWN_USERID
identity->user_id = (own_id ? own_id : strdup(PEP_OWN_USERID));
assert(identity->user_id);
if (identity->user_id == NULL)
return PEP_OUT_OF_MEMORY;
}
else if (own_id) {
if (strcmp(identity->user_id, own_id) != 0) {
// This will ONLY occur, due to the above check,
// when own_id is PEP_OWN_USERID
status = replace_userid(session, PEP_OWN_USERID,
identity->user_id);
if (status != PEP_STATUS_OK)
return status;
}
}
// Ok, so now we are guaranteed to have a user_id.
// Let's see if we have an identity record in the DB for
// this user_id + address
DEBUG_LOG("myself", "debug", identity->address);
@ -762,176 +779,103 @@ PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen,
assert(status != PEP_OUT_OF_MEMORY);
if (status == PEP_OUT_OF_MEMORY)
return PEP_OUT_OF_MEMORY;
if (!stored_identity) {
// We don't allow user_id mismatches for own identities except in cases
// where there was a PEP_OWN_USERID, which we have already replaced
// in the database, so if there is no match in the DB, we are making
// a new identity for this user ID.
if (EMPTYSTR(identity->username))
{
free(identity->username);
identity->username = strdup("Anonymous");
assert(identity->username);
if (identity->username == NULL)
return PEP_OUT_OF_MEMORY;
}
}
// First we try to find an identity with the
bool dont_use_stored_fpr = true;
bool dont_use_input_fpr = true;
if (stored_identity)
{
if (EMPTYSTR(identity->fpr)) {
bool has_private = false;
status = _has_usable_priv_key(session, stored_identity->fpr, &has_private);
// N.B. has_private is never true if the returned status is not PEP_STATUS_OK
if (has_private) {
identity->fpr = strdup(stored_identity->fpr);
assert(identity->fpr);
if (identity->fpr == NULL)
{
return PEP_OUT_OF_MEMORY;
}
dont_use_stored_fpr = false;
}
}
identity->flags = (identity->flags & 255) | stored_identity->flags;
free_identity(stored_identity);
// Set usernames - priority is input username > stored name > "Anonymous"
// If there's an input username, we always patch the username with that
// input.
if (EMPTYSTR(identity->username)) {
bool stored_uname = (stored_identity && stored_identity->username);
char* uname = (stored_uname ? "Anonymous" : stored_identity->username);
free(identity->username);
identity->username = strdup(uname);
if (identity->username == NULL)
return PEP_OUT_OF_MEMORY;
}
if (dont_use_stored_fpr && !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.
// BUT:
// First check to see if it's blacklisted or private part is missing?
bool has_private = false;
status = _has_usable_priv_key(session, identity->fpr, &has_private);
// N.B. has_private is never true if the returned status is not PEP_STATUS_OK
if (has_private) {
dont_use_input_fpr = false;
}
}
bool valid_key_found = false;
// Now deal with keys.
// Different from update_identity(), the input fpr here
// MATTERS.
// If the input fpr is invalid, we return, giving the reason why.
if (identity->fpr) {
status = validate_fpr(session, identity);
if (status != PEP_STATUS_OK ||
identity->comm_type < PEP_ct_strong_but_unconfirmed) {
if (identity->comm_type != PEP_ct_key_expired)
goto pep_free;
// Otherwise, it was expired and key renewal failed
// and we take the stored one or do keygen.
}
else
valid_key_found = true;
}
// Ok, we failed to get keys either way, so let's elect one.
if (dont_use_input_fpr && dont_use_stored_fpr)
{
status = elect_ownkey(session, identity);
assert(status == PEP_STATUS_OK);
if (status != PEP_STATUS_OK) {
return ADD_TO_LOG(status);
}
bool has_private = false;
if (identity->fpr) {
// ok, we elected something.
// elect_ownkey only returns private keys, so we don't check again.
// Check to see if it's blacklisted
bool listed;
status = blacklist_is_listed(session, identity->fpr, &listed);
if (status == PEP_STATUS_OK)
has_private = !listed;
}
// Ok, if there wasn't a valid input fpr, check stored identity
if (!valid_key_found && stored_identity &&
(!identity->fpr || strcmp(stored_identity->fpr, identity->fpr) != 0)) {
if (has_private) {
dont_use_input_fpr = false;
}
else { // OK, we've tried everything. Time to generate new keys.
free(identity->fpr); // It can stay in this state (unallocated) because we'll generate a new key
identity->fpr = NULL;
// Fall back / retrieve
status = validate_fpr(session, stored_identity);
if (status == PEP_STATUS_OK &&
stored_identity->comm_type >= PEP_ct_strong_but_unconfirmed) {
free(identity->fpr);
identity->fpr = strdup(stored_identity->fpr);
}
}
bool revoked = false;
char *r_fpr = NULL;
if (!EMPTYSTR(identity->fpr))
{
status = key_revoked(session, identity->fpr, &revoked);
if (status != PEP_STATUS_OK)
{
return ADD_TO_LOG(status);
else {
bool revoked = false;
if (!EMPTYSTR(stored_identity->fpr)) {
status = key_revoked(session, stored_identity->fpr, &revoked);
if (revoked)
revoked_fpr = strdup(stored_identity->fpr);
}
}
}
if (EMPTYSTR(identity->fpr) || revoked)
{
if(!do_keygen){
return ADD_TO_LOG(PEP_GET_KEY_FAILED);
}
// Nothing left to do but generate a key
if (!valid_key_found) {
if (!do_keygen)
status = PEP_GET_KEY_FAILED;
else {
DEBUG_LOG("Generating key pair", "debug", identity->address);
if(revoked)
{
r_fpr = identity->fpr;
identity->fpr = NULL;
}
DEBUG_LOG("generating key pair", "debug", identity->address);
status = generate_keypair(session, identity);
assert(status != PEP_OUT_OF_MEMORY);
if (status != PEP_STATUS_OK) {
char buf[11];
snprintf(buf, 11, "%d", status);
DEBUG_LOG("generating key pair failed", "debug", buf);
if(revoked && r_fpr)
free(r_fpr);
return ADD_TO_LOG(status);
}
status = generate_keypair(session, identity);
assert(status != PEP_OUT_OF_MEMORY);
if(revoked)
{
status = set_revoked(session, r_fpr,
identity->fpr, time(NULL));
free(r_fpr);
if (status != PEP_STATUS_OK) {
return ADD_TO_LOG(status);
char buf[11];
snprintf(buf, 11, "%d", status); // uh, this is kludgey. FIXME
DEBUG_LOG("Generating key pair failed", "debug", buf);
}
else {
valid_key_found = true;
if (revoked_fpr) {
status = set_revoked(session, revoked_fpr,
stored_identity->fpr, time(NULL));
}
}
}
}
else
{
bool expired;
status = key_expired(session, identity->fpr,
time(NULL) + (7*24*3600), // In a week
&expired);
assert(status == PEP_STATUS_OK);
if (status != PEP_STATUS_OK) {
return ADD_TO_LOG(status);
}
if (status == PEP_STATUS_OK && expired) {
timestamp *ts = new_timestamp(time(NULL) + KEY_EXPIRE_DELTA);
renew_key(session, identity->fpr, ts);
free_timestamp(ts);
}
if (valid_key_found) {
identity->comm_type = PEP_ct_pEp;
status = PEP_STATUS_OK;
}
else {
free(identity->fpr);
identity->fpr = NULL;
identity->comm_type = PEP_ct_unknown;
}
if (!(identity->username))
identity->username = strdup("");
status = set_identity(session, identity);
assert(status == PEP_STATUS_OK);
if (status != PEP_STATUS_OK) {
return status;
}
return ADD_TO_LOG(PEP_STATUS_OK);
pep_free:
free(default_own_id);
free(revoked_fpr);
free_identity(stored_identity);
return ADD_TO_LOG(status);
}
DYNAMIC_API PEP_STATUS initialise_own_identities(PEP_SESSION session,
@ -941,7 +885,7 @@ DYNAMIC_API PEP_STATUS initialise_own_identities(PEP_SESSION session,
return PEP_ILLEGAL_VALUE;
char* stored_own_userid = NULL;
get_own_userid(session, &stored_own_userid);
get_default_own_userid(session, &stored_own_userid);
identity_list* ident_curr = my_idents;
while (ident_curr) {
@ -1396,7 +1340,7 @@ DYNAMIC_API PEP_STATUS set_own_key(
// First see if we have it in own identities already, AND we retrieve
// our own user_id
char* my_user_id = NULL;
status = get_own_userid(session, &my_user_id);
status = get_default_own_userid(session, &my_user_id);
if (status != PEP_STATUS_OK)
return status;

@ -269,6 +269,8 @@ DYNAMIC_API PEP_STATUS set_own_key(
const char *fpr
);
PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen, bool ignore_flags);
#ifdef __cplusplus
}
#endif

@ -1749,6 +1749,7 @@ static PEP_STATUS _update_identity_for_incoming_message(
)
{
PEP_STATUS status;
if (src->from && src->from->address) {
status = update_identity(session, src->from);
if (status == PEP_STATUS_OK
@ -2309,14 +2310,37 @@ static PEP_STATUS import_priv_keys_from_decrypted_msg(PEP_SESSION session,
_private_il->ident->address)
*imported_private = true;
if (private_il && imported_private)
if (private_il && imported_private) {
// the private identity list should NOT be subject to myself() or
// update_identity() at this point.
// If the receiving app wants them to be in the trust DB, it
// should call myself() on them upon return.
// We do, however, prepare these so the app can use them
// directly in a myself() call by putting the own_id on it.
char* own_id = NULL;
status = get_default_own_userid(session, &own_id);
if (status != PEP_STATUS_OK) {
free(own_id);
own_id = NULL;
}
identity_list* il = _private_il;
for ( ; il; il = il->next) {
if (own_id) {
free(il->ident->user_id);
il->ident->user_id = strdup(own_id);
}
il->ident->me = true;
}
*private_il = _private_il;
free(own_id);
}
else
free_identity_list(_private_il);
if (imported_keys)
status = _update_identity_for_incoming_message(session, src);
return status;
}
@ -2366,7 +2390,18 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
// Update src->from in case we just imported a key
// we would need to check signature
status = _update_identity_for_incoming_message(session, src);
if(status != PEP_STATUS_OK)
if (status == PEP_ILLEGAL_VALUE && src->from && is_me(session, src->from)) {
// the above function should fail if it's us.
// We don't need to update, as any revocations or expirations
// of our own key imported above, which are all that we
// would care about for anything imported,
// SHOULD get caught when they matter later.
// (Private keys imported above are not stored in the trust DB)
status = PEP_STATUS_OK;
}
if (status != PEP_STATUS_OK)
return ADD_TO_LOG(status);
/*** End Import any attached public keys and update identities accordingly ***/

@ -233,7 +233,7 @@ static const char* sql_get_user_default_key =
"select main_key_id from person"
" where id = ?1;";
static const char* sql_get_own_userid =
static const char* sql_get_default_own_userid =
"select id from person"
" join identity on id = identity.user_id"
" where identity.is_own = 1";
@ -787,8 +787,8 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
(int)strlen(sql_get_user_default_key), &_session->get_user_default_key, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_get_own_userid,
(int)strlen(sql_get_own_userid), &_session->get_own_userid, NULL);
int_result = sqlite3_prepare_v2(_session->db, sql_get_default_own_userid,
(int)strlen(sql_get_default_own_userid), &_session->get_default_own_userid, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_replace_userid,
@ -1047,8 +1047,8 @@ DYNAMIC_API void release(PEP_SESSION session)
sqlite3_finalize(session->get_identities_by_address);
if (session->get_user_default_key)
sqlite3_finalize(session->get_user_default_key);
if (session->get_own_userid)
sqlite3_finalize(session->get_own_userid);
if (session->get_default_own_userid)
sqlite3_finalize(session->get_default_own_userid);
if (session->replace_identities_fpr)
sqlite3_finalize(session->replace_identities_fpr);
if (session->remove_fpr_as_default)
@ -1419,7 +1419,7 @@ void free_identity(pEp_identity *identity)
}
}
DYNAMIC_API PEP_STATUS get_own_userid(
DYNAMIC_API PEP_STATUS get_default_own_userid(
PEP_SESSION session,
char** userid
)
@ -1433,14 +1433,14 @@ DYNAMIC_API PEP_STATUS get_own_userid(
PEP_STATUS status = PEP_STATUS_OK;
char* retval = NULL;
sqlite3_reset(session->get_own_userid);
sqlite3_reset(session->get_default_own_userid);
const int result = sqlite3_step(session->get_own_userid);
const int result = sqlite3_step(session->get_default_own_userid);
const char* id;
switch (result) {
case SQLITE_ROW:
id = (const char *) sqlite3_column_text(session->get_own_userid, 0);
id = (const char *) sqlite3_column_text(session->get_default_own_userid, 0);
if (!id) {
// Shouldn't happen.
status = PEP_UNKNOWN_ERROR;
@ -1459,7 +1459,7 @@ DYNAMIC_API PEP_STATUS get_own_userid(
*userid = retval;
sqlite3_reset(session->get_own_userid);
sqlite3_reset(session->get_default_own_userid);
return status;
}
@ -1854,7 +1854,7 @@ DYNAMIC_API PEP_STATUS set_device_group(
// 1. Get own user_id
char* user_id = NULL;
PEP_STATUS status = get_own_userid(session, &user_id);
PEP_STATUS status = get_default_own_userid(session, &user_id);
// No user_id is returned in this case, no need to free;
if (status != PEP_STATUS_OK)
@ -1896,7 +1896,7 @@ DYNAMIC_API PEP_STATUS get_device_group(PEP_SESSION session, char **group_name)
// 1. Get own user_id
char* user_id = NULL;
status = get_own_userid(session, &user_id);
status = get_default_own_userid(session, &user_id);
// No user_id is returned in this case, no need to free;
if (status != PEP_STATUS_OK)

@ -602,7 +602,7 @@ DYNAMIC_API PEP_STATUS set_identity(
PEP_SESSION session, const pEp_identity *identity
);
// get_own_userid() - get the user_id of the own user
// get_default own_userid() - get the user_id of the own user
//
// parameters:
// session (in) session handle
@ -617,7 +617,7 @@ DYNAMIC_API PEP_STATUS set_identity(
// userid will be NULL if not found; otherwise, returned string
// belongs to the caller.
DYNAMIC_API PEP_STATUS get_own_userid(
DYNAMIC_API PEP_STATUS get_default_own_userid(
PEP_SESSION session,
char** userid
);

@ -158,7 +158,7 @@ struct _pEpSession {
sqlite3_stmt *own_keys_retrieve;
sqlite3_stmt *get_user_default_key;
sqlite3_stmt *get_own_userid;
sqlite3_stmt *get_default_own_userid;
// sqlite3_stmt *set_own_key;
@ -370,6 +370,20 @@ static inline char* _pep_subj_copy() {
#endif
}
static inline bool is_me(PEP_SESSION session, pEp_identity* test_ident) {
bool retval = false;
if (test_ident && test_ident->user_id) {
char* def_id = NULL;
get_default_own_userid(session, &def_id);
if (test_ident->me ||
(def_id && strcmp(def_id, test_ident->user_id) == 0)) {
retval = true;
}
free(def_id);
}
return retval;
}
// These are globals used in generating message IDs and should only be
// computed once, as they're either really constants or OS-dependent

@ -58,7 +58,7 @@ int keyElectionWon(PEP_SESSION session, Identity partner)
Identity me = NULL;
char* own_id = NULL;
PEP_STATUS status = get_own_userid(session, &own_id);
PEP_STATUS status = get_default_own_userid(session, &own_id);
if (own_id) {
status = get_identity(session, partner->address, own_id,
&me);
@ -149,7 +149,7 @@ PEP_STATUS _notifyHandshake(
return PEP_SYNC_NO_NOTIFY_CALLBACK;
char* own_id = NULL;
status = get_own_userid(session, &own_id);
status = get_default_own_userid(session, &own_id);
// notifyHandshake take ownership of given identities
pEp_identity *me = NULL;
@ -249,7 +249,7 @@ PEP_STATUS _storeGroupKeys(
PEP_STATUS status = PEP_STATUS_OK;
char* own_id = NULL;
status = get_own_userid(session, &own_id);
status = get_default_own_userid(session, &own_id);
// FIXME: Is this where and what we wanna do with this?
if (status != PEP_STATUS_OK)

@ -277,7 +277,7 @@ PEP_STATUS receive_sync_msg(
if(partner){
char* own_id = NULL;
status = get_own_userid(session, &own_id);
status = get_default_own_userid(session, &own_id);
if (!own_id)
own_id = strdup(PEP_OWN_USERID);
@ -436,7 +436,7 @@ PEP_STATUS receive_DeviceState_msg(
bool force_keep_msg = false;
char* own_id = NULL;
PEP_STATUS own_id_status = get_own_userid(session, &own_id);
PEP_STATUS own_id_status = get_default_own_userid(session, &own_id);
for (bloblist_t *bl = src->attachments; bl && bl->value; bl = bl->next) {
if (bl->mime_type && strcasecmp(bl->mime_type, "application/pEp.sync") == 0
@ -798,7 +798,7 @@ PEP_STATUS unicast_msg(
}
char* own_id = NULL;
status = get_own_userid(session, &own_id);
status = get_default_own_userid(session, &own_id);
if (status != PEP_STATUS_OK)
goto error;

@ -180,7 +180,7 @@ int main() {
status = encrypt_message(session, outgoing_msg, NULL, &encrypted_outgoing_msg, PEP_enc_PGP_MIME, 0);
cout << "Encryption returns with status " << tl_status_string(status) << endl;
assert (status == PEP_UNENCRYPTED);
assert (status == PEP_KEY_NOT_FOUND);
assert (encrypted_outgoing_msg == NULL);
status = update_identity(session, recip1);
assert (recip1->comm_type = PEP_ct_key_not_found);

@ -48,7 +48,12 @@ int main() {
cout << me->fpr << "\n";
assert(strcmp(me->fpr, prev_fpr));
cout << "New fpr is: " << me->fpr;
me->fpr = NULL;
me->comm_type = PEP_ct_unknown;
myself(session, me);
identity_list *to = new_identity_list(new_identity("pep.test.alice@pep-project.org", NULL, "42", "pEp Test Alice (test key don't use)"));
message *msg = new_message(PEP_dir_outgoing);
assert(msg);
@ -65,12 +70,14 @@ int main() {
assert(enc_msg);
cout << "message encrypted.\n";
cout << msg->attachments->filename;
assert(bloblist_length(msg->attachments) == 2);
assert(strcmp(msg->attachments->filename, "file://pEpkey.asc") == 0);
assert(strcmp(msg->attachments->next->filename, "file://pEpkey.asc") == 0);
cout << "message contains 2 key attachments.\n";
// cout << msg->attachments->filename;
// int bl_len = bloblist_length(msg->attachments);
// cout << "Message contains " << bloblist_length(msg->attachments) << " attachments." << endl;
// assert(bloblist_length(msg->attachments) == 2);
// assert(strcmp(msg->attachments->filename, "file://pEpkey.asc") == 0);
// assert(strcmp(msg->attachments->next->filename, "file://pEpkey.asc") == 0);
//
// cout << "message contains 2 key attachments.\n";
free_message(msg);
free_message(enc_msg);

Loading…
Cancel
Save