Compare commits

...

10 Commits

@ -26,7 +26,9 @@ Identity ::= SEQUENCE {
user-id PString,
username PString,
comm-type INTEGER (0..255),
lang ISO639-1
lang ISO639-1,
...,
sticky BOOLEAN
}
IdentityList ::= SEQUENCE OF Identity

@ -72,6 +72,60 @@ enomem:
return NULL;
}
PEP_STATUS add_sticky_bit_to_Identity(PEP_SESSION session, Identity_t *ident)
{
assert(session && ident);
if (!(session && ident))
return PEP_ILLEGAL_VALUE;
PEP_STATUS status = PEP_STATUS_OK;
char *fpr = NULL;
char *user_id = NULL;
BOOLEAN_t *sticky = NULL;
fpr = strndup((char *) ident->fpr.buf, ident->fpr.size);
assert(fpr);
if (!fpr)
goto enomem;
user_id = strndup((char *) ident->user_id.buf, ident->user_id.size);
assert(user_id);
if (!user_id)
goto enomem;
sticky = (BOOLEAN_t *) calloc(1, sizeof(BOOLEAN_t));
assert(sticky);
if (!sticky)
goto enomem;
bool _sticky = false;
status = get_key_sticky_bit_for_user(session, user_id, fpr, &_sticky);
if (status) {
if (status == PEP_KEY_NOT_FOUND)
_sticky = false;
else
goto error;
}
*sticky = _sticky;
ident->sticky = sticky;
free(fpr);
free(user_id);
return PEP_STATUS_OK;
enomem:
status = PEP_OUT_OF_MEMORY;
error:
free(fpr);
free(user_id);
free(sticky);
return status;
}
pEp_identity *Identity_to_Struct(Identity_t *ident, pEp_identity *result)
{
bool allocated = !result;
@ -124,6 +178,99 @@ enomem:
return NULL;
}
PEP_STATUS set_new_own_key_if_not_sticky(PEP_SESSION session, Identity_t *ident)
{
assert(session && ident);
if (!(session && ident))
return PEP_ILLEGAL_VALUE;
PEP_STATUS status = PEP_STATUS_OK;
pEp_identity *_new = NULL;
pEp_identity *_old = NULL;
char *own_user_id = NULL;
_new = Identity_to_Struct(ident, NULL);
if (!_new)
goto enomem;
bool new_is_sticky = ident->sticky && *ident->sticky;
if (EMPTYSTR(_new->address) || EMPTYSTR(_new->fpr)) {
status = PEP_ILLEGAL_VALUE;
goto error;
}
status = get_default_own_userid(session, &own_user_id);
if (status) {
if (status == PEP_CANNOT_FIND_IDENTITY) {
own_user_id = strdup(PEP_OWN_USERID);
assert(own_user_id);
if (!own_user_id)
goto enomem;
}
else {
goto error;
}
}
status = get_identity(session, _new->address, own_user_id, &_old);
switch (status) {
case PEP_STATUS_OK: {
assert(_old);
if (!EMPTYSTR(_old->fpr)) {
if (!new_is_sticky && strcasecmp(_new->fpr, _old->fpr) == 0)
break;
}
bool old_is_sticky = false;
if (!EMPTYSTR(_old->fpr)) {
status = get_key_sticky_bit_for_user(session, own_user_id, _old->fpr, &old_is_sticky);
if (status) {
if (status == PEP_KEY_NOT_FOUND) {
old_is_sticky = false;
status = PEP_STATUS_OK;
}
else {
goto error;
}
}
if (old_is_sticky)
break;
}
status = set_own_imported_key(session, _old, _new->fpr, new_is_sticky);
if (status)
goto error;
break;
}
case PEP_CANNOT_FIND_IDENTITY:
status = set_own_imported_key(session, _new, _new->fpr, new_is_sticky);
if (status)
goto error;
default:
goto error;
}
free_identity(_new);
free_identity(_old);
free(own_user_id);
return PEP_STATUS_OK;
enomem:
status = PEP_OUT_OF_MEMORY;
error:
free_identity(_new);
free_identity(_old);
free(own_user_id);
return status;
}
IdentityList_t *IdentityList_from_identity_list(
const identity_list *list,
IdentityList_t *result

@ -38,6 +38,23 @@ Identity_t *Identity_from_Struct(
);
/**
* <!-- add_sticky_bit_to_Identity() -->
*
* @brief retrieve the sticky bit of a key for sending with Identity
*
* params:
* session (in) pEp session to use
* ident (inout) Identity_t to convert; ident->user_id and ident->fpr
* must be set
*
* @retval error status
*
*/
PEP_STATUS add_sticky_bit_to_Identity(PEP_SESSION session, Identity_t *ident);
/**
* <!-- Identity_to_Struct() -->
*
@ -56,6 +73,25 @@ Identity_t *Identity_from_Struct(
pEp_identity *Identity_to_Struct(Identity_t *ident, pEp_identity *result);
/**
* <!-- set_new_own_key_if_not_sticky() -->
*
* @brief set a new own key if the old one is not sticky
*
* params:
* session (in) pEp session to use
* ident (in) Identity_t to set own key; ident->address and
* ident->fpr must be set
*
* @retval pointer to updated or allocated result
*
* @warning if a new struct is allocated, the ownership goes to the caller
*
*/
PEP_STATUS set_new_own_key_if_not_sticky(PEP_SESSION session, Identity_t *ident);
/**
* <!-- IdentityList_from_identity_list() -->
*

@ -386,6 +386,13 @@ action prepareOwnKeys
IdentityList_from_identity_list(il, &session->sync_state.keysync.ownIdentities);
free_identity_list(il);
for (int i=0; i<session->sync_state.keysync.ownIdentities.list.count; ++i) {
status = add_sticky_bit_to_Identity(session,
session->sync_state.keysync.ownIdentities.list.array[i]);
if (status)
break;
}
||
action saveGroupKeys

Loading…
Cancel
Save