Browse Source

sync : attach_sync_session

Edouard Tisserant 6 years ago
parent
commit
93cb3b6ea2
6 changed files with 75 additions and 26 deletions
  1. +1
    -3
      src/pEpEngine.c
  2. +3
    -4
      src/pEp_internal.h
  3. +36
    -13
      src/sync.c
  4. +25
    -2
      src/sync.h
  5. +5
    -4
      src/sync_impl.c
  6. +5
    -0
      sync/devicegroup.fsm

+ 1
- 3
src/pEpEngine.c View File

@ -6,7 +6,6 @@
#include "sync_fsm.h"
static int init_count = -1;
char sync_uuid[37];
static int user_version(void *_version, int count, char **text, char **name)
{
@ -135,7 +134,6 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
#define _DDL_USER_VERSION "3"
if (in_first) {
memset(sync_uuid, 0, 37);
int_result = sqlite3_exec(
_session->db,
@ -1897,7 +1895,7 @@ DYNAMIC_API PEP_STATUS sequence_value(
own = 1;
}
else {
if (name == sync_uuid || strcmp(name, sync_uuid) == 0)
if (name == session->sync_uuid || strcmp(name, session->sync_uuid) == 0)
own = 1;
}


+ 3
- 4
src/pEp_internal.h View File

@ -77,8 +77,6 @@
#define NOT_IMPLEMENTED assert(0); return PEP_UNKNOWN_ERROR;
extern char sync_uuid[37];
typedef struct _pEpSession {
const char *version;
#ifdef USE_GPG
@ -126,7 +124,7 @@ typedef struct _pEpSession {
sqlite3_stmt *sequence_value2;
sqlite3_stmt *sequence_value3;
// sequence value
// revoked keys
sqlite3_stmt *set_revoked;
sqlite3_stmt *get_revoked;
@ -139,8 +137,9 @@ typedef struct _pEpSession {
inject_sync_msg_t inject_sync_msg;
retrieve_next_sync_msg_t retrieve_next_sync_msg;
// state machines
// key sync
DeviceState_state sync_state;
char sync_uuid[37];
// runtime config


+ 36
- 13
src/sync.c View File

@ -6,9 +6,6 @@
#include "asn1_helper.h"
#include "../asn.1/DeviceGroup-Protocol.h"
static void *static_sync_obj = NULL;
static inject_sync_msg_t static_inject_sync_msg = NULL;
// receive_sync_msg is defined in the sync_actions
PEP_STATUS receive_sync_msg(
@ -25,9 +22,13 @@ DYNAMIC_API PEP_STATUS register_sync_callbacks(
retrieve_next_sync_msg_t retrieve_next_sync_msg
)
{
assert(session && obj && messageToSend && showHandshake && inject_sync_msg && retrieve_next_sync_msg);
if (!(session && obj && messageToSend && showHandshake && inject_sync_msg && retrieve_next_sync_msg))
return PEP_ILLEGAL_VALUE;
unsigned char uuid[16];
uuid_generate_random(uuid);
uuid_unparse_upper(uuid, sync_uuid);
uuid_unparse_upper(uuid, session->sync_uuid);
session->sync_obj = obj;
session->messageToSend = messageToSend;
@ -35,9 +36,6 @@ DYNAMIC_API PEP_STATUS register_sync_callbacks(
session->inject_sync_msg = inject_sync_msg;
session->retrieve_next_sync_msg = retrieve_next_sync_msg;
static_sync_obj = obj;
static_inject_sync_msg = inject_sync_msg;
// start state machine
session->sync_state = InitState;
PEP_STATUS status = fsm_DeviceState_inject(session, Init, NULL, NULL);
@ -47,24 +45,49 @@ DYNAMIC_API PEP_STATUS register_sync_callbacks(
return status;
}
DYNAMIC_API PEP_STATUS attach_sync_session(
PEP_SESSION session,
PEP_SESSION sync_session
)
{
assert(session && sync_session && sync_session->sync_obj && sync_session->inject_sync_msg );
if (!(session && sync_session && sync_session->sync_obj && sync_session->inject_sync_msg ))
return PEP_ILLEGAL_VALUE;
memcpy(session->sync_uuid, sync_session->sync_uuid, 37);
session->sync_obj = sync_session->sync_obj;
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_obj && session->inject_sync_msg );
if (!(session && session->sync_obj && session->inject_sync_msg ))
return PEP_ILLEGAL_VALUE;
memset(session->sync_uuid, 0, 37);
session->sync_obj = 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_obj)
return session->inject_sync_msg(msg, session->sync_obj);
else if(static_inject_sync_msg && static_sync_obj)
return static_inject_sync_msg(msg, static_sync_obj);
else
return PEP_SYNC_NO_INJECT_CALLBACK;
}
DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
// stop state machine
session->sync_state = DeviceState_state_NONE;
static_sync_obj = NULL;
static_inject_sync_msg = NULL;
// unregister
session->sync_obj = NULL;
session->messageToSend = NULL;


+ 25
- 2
src/sync.h View File

@ -115,15 +115,38 @@ DYNAMIC_API PEP_STATUS register_sync_callbacks(
retrieve_next_sync_msg_t retrieve_next_sync_msg
);
// attach_sync_session() - attach session to a session running keysync state machine
//
// parameters:
// session (in) session to attach
// sync_session (in) session running keysync
//
// return value:
// PEP_STATUS_OK or any other value on errror
//
// caveat:
// register_sync_callbacks must have been called on sync_session
// call that BEFORE you're using that session in any other part of the engine
DYNAMIC_API PEP_STATUS attach_sync_session(
PEP_SESSION session,
PEP_SESSION sync_session
);
// detach_sync_session() - detach previously attached sync session
//
// parameters:
// session (in) session to detach
DYNAMIC_API PEP_STATUS detach_sync_session(PEP_SESSION session);
// unregister_sync_callbacks() - unregister adapter's callbacks
//
// parameters:
// session (in) session where to store obj handle
// session (in) session to unregister
DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session);
// do_sync_protocol() - function to be run on an extra thread
//
// parameters:


+ 5
- 4
src/sync_impl.c View File

@ -196,7 +196,7 @@ PEP_STATUS receive_DeviceState_msg(
// HandshakeRequest needs encryption
case DeviceGroup_Protocol__payload_PR_handshakeRequest:
if (rating < PEP_rating_reliable ||
strncmp(sync_uuid,
strncmp(session->sync_uuid,
(const char *)msg->payload.choice.handshakeRequest.partner.user_id->buf,
msg->payload.choice.handshakeRequest.partner.user_id->size) != 0){
ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
@ -207,7 +207,7 @@ PEP_STATUS receive_DeviceState_msg(
// accepting GroupKeys needs encryption and trust
case DeviceGroup_Protocol__payload_PR_groupKeys:
if (!keylist || rating < PEP_rating_reliable ||
strncmp(sync_uuid,
strncmp(session->sync_uuid,
(const char *)msg->payload.choice.groupKeys.partner.user_id->buf,
msg->payload.choice.groupKeys.partner.user_id->size) != 0){
ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
@ -350,7 +350,7 @@ PEP_STATUS unicast_msg(
int32_t seq = 0;
status = sequence_value(session, sync_uuid, &seq);
status = sequence_value(session, session->sync_uuid, &seq);
if (status != PEP_OWN_SEQUENCE && status != PEP_STATUS_OK)
goto error;
@ -361,7 +361,7 @@ PEP_STATUS unicast_msg(
goto enomem;
free(_me->user_id);
_me->user_id = strndup(sync_uuid, 36);
_me->user_id = strndup(session->sync_uuid, 36);
assert(_me->user_id);
if (!_me->user_id)
goto enomem;
@ -478,6 +478,7 @@ PEP_STATUS multicast_self_msg(
if (status != PEP_STATUS_OK)
return status;
// FIXME: exclude previously rejected identities
for (identity_list *_i = own_identities; _i && _i->ident; _i = _i->next) {
pEp_identity *me = _i->ident;


+ 5
- 0
sync/devicegroup.fsm View File

@ -78,6 +78,11 @@ protocol DeviceGroup {
do sendHandshakeRequest(partner);
go HandshakingGrouped(partner);
}
on GroupKeys(Identity partner, Stringlist keys) {
do storeGroupKeys(partner, keys);
// TODO : add a callback to signal finished waiting for group keys
go Grouped;
}
}
state HandshakingGrouped(Identity partner) {


Loading…
Cancel
Save