Browse Source

KeySync: ensure that UUID is the same for every session attached to a a sync session

doc_update_sequoia
Edouard Tisserant 5 years ago
parent
commit
5f7e8e3068
5 changed files with 34 additions and 21 deletions
  1. +3
    -2
      src/message_api.c
  2. +6
    -1
      src/pEpEngine.c
  3. +5
    -2
      src/pEp_internal.h
  4. +14
    -10
      src/sync.c
  5. +6
    -6
      src/sync_impl.c

+ 3
- 2
src/message_api.c View File

@ -1582,7 +1582,7 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
*rating = PEP_rating_unencrypted;
if (imported_keys)
remove_attached_keys(src);
if(session->inject_sync_msg){
if(session->sync_session->inject_sync_msg){
status = receive_DeviceState_msg(session, src, *rating, *keylist);
if (status == PEP_MESSAGE_CONSUME ||
status == PEP_MESSAGE_IGNORE) {
@ -1963,7 +1963,8 @@ DYNAMIC_API PEP_STATUS _decrypt_message(
decorate_message(msg, *rating, _keylist);
if (imported_keys)
remove_attached_keys(msg);
if (*rating >= PEP_rating_reliable && session->inject_sync_msg) {
if (*rating >= PEP_rating_reliable &&
session->sync_session->inject_sync_msg) {
status = receive_DeviceState_msg(session, msg, *rating, _keylist);
if (status == PEP_MESSAGE_CONSUME ||
status == PEP_MESSAGE_IGNORE) {


+ 6
- 1
src/pEpEngine.c View File

@ -621,6 +621,10 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
_session->use_only_own_private_keys = false;
#endif
// sync_session set to own session by default
// sync_session is then never null on a valid session
_session->sync_session = _session;
*session = _session;
return PEP_STATUS_OK;
@ -2032,7 +2036,8 @@ DYNAMIC_API PEP_STATUS sequence_value(
own = 1;
}
else {
if (name == session->sync_uuid || strcmp(name, session->sync_uuid) == 0)
if (name == session->sync_session->sync_uuid ||
strcmp(name, session->sync_session->sync_uuid) == 0)
own = 1;
}


+ 5
- 2
src/pEp_internal.h View File

@ -81,7 +81,9 @@
#define NOT_IMPLEMENTED assert(0); return PEP_UNKNOWN_ERROR;
typedef struct _pEpSession {
struct _pEpSession;
typedef struct _pEpSession pEpSession;
struct _pEpSession {
const char *version;
#ifdef USE_GPG
gpgme_ctx_t ctx;
@ -146,6 +148,7 @@ typedef struct _pEpSession {
retrieve_next_sync_msg_t retrieve_next_sync_msg;
// key sync
pEpSession* sync_session;
DeviceState_state sync_state;
void* sync_state_payload;
char sync_uuid[37];
@ -159,7 +162,7 @@ typedef struct _pEpSession {
bool use_only_own_private_keys;
bool keep_sync_msg;
} pEpSession;
};
PEP_STATUS init_transport_system(PEP_SESSION session, bool in_first);
void release_transport_system(PEP_SESSION session, bool out_last);


+ 14
- 10
src/sync.c View File

@ -59,32 +59,36 @@ DYNAMIC_API PEP_STATUS attach_sync_session(
if (!(session && sync_session && sync_session->sync_management && sync_session->inject_sync_msg ))
return PEP_ILLEGAL_VALUE;
memcpy(session->sync_uuid, sync_session->sync_uuid, 37);
session->sync_session = sync_session;
// memcpy(session->sync_uuid, sync_session->sync_uuid, 37);
session->sync_management = sync_session->sync_management;
session->inject_sync_msg = sync_session->inject_sync_msg;
// session->sync_management = sync_session->sync_management;
// session->inject_sync_msg = sync_session->inject_sync_msg;
return PEP_STATUS_OK;
}
DYNAMIC_API PEP_STATUS detach_sync_session(PEP_SESSION session)
{
assert(session && session->sync_management && session->inject_sync_msg );
if (!(session && session->sync_management && session->inject_sync_msg ))
assert(session);
if (!(session))
return PEP_ILLEGAL_VALUE;
memset(session->sync_uuid, 0, 37);
session->sync_session = session;
// memset(session->sync_uuid, 0, 37);
session->sync_management = NULL;
session->inject_sync_msg = NULL;
// session->sync_management = NULL;
// session->inject_sync_msg = NULL;
return PEP_STATUS_OK;
}
int call_inject_sync_msg(PEP_SESSION session, void *msg)
{
if(session->inject_sync_msg && session->sync_management)
return session->inject_sync_msg(msg, session->sync_management);
if(session->sync_session->inject_sync_msg &&
session->sync_session->sync_management)
return session->sync_session->inject_sync_msg(msg,
session->sync_session->sync_management);
else
return PEP_SYNC_NO_INJECT_CALLBACK;
}


+ 6
- 6
src/sync_impl.c View File

@ -63,7 +63,7 @@ PEP_STATUS receive_sync_msg(
case DeviceGroup_Protocol__payload_PR_handshakeRequest:
// re-check uuid in case sync_uuid changed while in the queue
if (strncmp(session->sync_uuid,
if (strncmp(session->sync_session->sync_uuid,
(const char *)msg->payload.choice.handshakeRequest.partner_id->buf,
msg->payload.choice.handshakeRequest.partner_id->size) != 0){
status = PEP_SYNC_ILLEGAL_MESSAGE;
@ -96,7 +96,7 @@ PEP_STATUS receive_sync_msg(
case DeviceGroup_Protocol__payload_PR_groupKeys:
{
// re-check uuid in case sync_uuid changed while in the queue
if (strncmp(session->sync_uuid,
if (strncmp(session->sync_session->sync_uuid,
(const char *)msg->payload.choice.groupKeys.partner_id->buf,
msg->payload.choice.groupKeys.partner_id->size) != 0){
status = PEP_SYNC_ILLEGAL_MESSAGE;
@ -437,7 +437,7 @@ PEP_STATUS receive_DeviceState_msg(
// HandshakeRequest needs encryption
case DeviceGroup_Protocol__payload_PR_handshakeRequest:
if (rating < PEP_rating_reliable ||
strncmp(session->sync_uuid,
strncmp(session->sync_session->sync_uuid,
(const char *)msg->payload.choice.handshakeRequest.partner_id->buf,
msg->payload.choice.handshakeRequest.partner_id->size) != 0){
discard = true;
@ -450,7 +450,7 @@ PEP_STATUS receive_DeviceState_msg(
{
if (!keylist || rating < PEP_rating_reliable ||
// message is only consumed by instance it is addressed to
(strncmp(session->sync_uuid,
(strncmp(session->sync_session->sync_uuid,
(const char *)msg->payload.choice.groupKeys.partner_id->buf,
msg->payload.choice.groupKeys.partner_id->size) != 0)){
discard = true;
@ -658,7 +658,7 @@ PEP_STATUS unicast_msg(
int32_t seq = 0;
status = sequence_value(session, session->sync_uuid, &seq);
status = sequence_value(session, session->sync_session->sync_uuid, &seq);
if (status != PEP_OWN_SEQUENCE && status != PEP_STATUS_OK)
goto error;
@ -669,7 +669,7 @@ PEP_STATUS unicast_msg(
goto enomem;
free(_me->user_id);
_me->user_id = strndup(session->sync_uuid, 36);
_me->user_id = strndup(session->sync_session->sync_uuid, 36);
assert(_me->user_id);
if (!_me->user_id)
goto enomem;


Loading…
Cancel
Save