merge sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Mon, 25 Mar 2019 15:18:13 +0100
branchsync
changeset 3397837e7a550111
parent 3396 d5d64124bb10
parent 3395 c8c82db9865a
child 3398 45fa5be301e8
merge
     1.1 --- a/src/baseprotocol.c	Mon Mar 25 15:16:50 2019 +0100
     1.2 +++ b/src/baseprotocol.c	Mon Mar 25 15:18:13 2019 +0100
     1.3 @@ -9,7 +9,8 @@
     1.4          message *msg,
     1.5          char *payload,
     1.6          size_t size,
     1.7 -        char *fpr
     1.8 +        const char *fpr,
     1.9 +        stringlist_t **keys
    1.10      )
    1.11  {
    1.12      PEP_STATUS status = PEP_STATUS_OK;
    1.13 @@ -44,7 +45,31 @@
    1.14              goto enomem;
    1.15      }
    1.16  
    1.17 -    return PEP_STATUS_OK;
    1.18 +    if (keys) {
    1.19 +        size_t size = 1;
    1.20 +        for (stringlist_t *sl = *keys; sl && sl->value; sl = sl->next) {
    1.21 +            size += strlen(sl->value);
    1.22 +        }
    1.23 +
    1.24 +        char *_keys = calloc(1, size);
    1.25 +        if (!_keys)
    1.26 +            goto enomem;
    1.27 +
    1.28 +        char *_k = _keys;
    1.29 +        for (stringlist_t *sl = *keys; sl && sl->value; sl = sl->next) {
    1.30 +            strcpy(_k, sl->value);
    1.31 +            _k += strlen(sl->value);
    1.32 +        }
    1.33 +
    1.34 +        bl = bloblist_add(bl, _keys, size, "application/pgp-keys", "keys.asc");
    1.35 +        if (!bl)
    1.36 +            status = PEP_OUT_OF_MEMORY;
    1.37 +
    1.38 +        free_stringlist(*keys);
    1.39 +        *keys = NULL;
    1.40 +    }
    1.41 +
    1.42 +    return status;
    1.43  
    1.44  enomem:
    1.45      status = PEP_OUT_OF_MEMORY;
    1.46 @@ -59,7 +84,8 @@
    1.47          const pEp_identity *partner,
    1.48          char *payload,
    1.49          size_t size,
    1.50 -        char *fpr,
    1.51 +        const char *fpr,
    1.52 +        stringlist_t **keys,
    1.53          message **result
    1.54      )
    1.55  {
    1.56 @@ -101,7 +127,7 @@
    1.57      if (!msg->longmsg)
    1.58          goto enomem;
    1.59  
    1.60 -    status = base_decorate_message(session, msg, payload, size, fpr);
    1.61 +    status = base_decorate_message(session, msg, payload, size, fpr, keys);
    1.62      if (status == PEP_STATUS_OK)
    1.63          *result = msg;
    1.64      return status;
     2.1 --- a/src/baseprotocol.h	Mon Mar 25 15:16:50 2019 +0100
     2.2 +++ b/src/baseprotocol.h	Mon Mar 25 15:18:13 2019 +0100
     2.3 @@ -31,7 +31,8 @@
     2.4          message *msg,
     2.5          char *payload,
     2.6          size_t size,
     2.7 -        char *fpr
     2.8 +        const char *fpr,
     2.9 +        stringlist_t **keys
    2.10      );
    2.11  
    2.12  
    2.13 @@ -59,7 +60,8 @@
    2.14          const pEp_identity *partner,
    2.15          char *payload,
    2.16          size_t size,
    2.17 -        char *fpr,
    2.18 +        const char *fpr,
    2.19 +        stringlist_t **keys,
    2.20          message **result
    2.21      );
    2.22  
     3.1 --- a/src/pEpEngine.c	Mon Mar 25 15:16:50 2019 +0100
     3.2 +++ b/src/pEpEngine.c	Mon Mar 25 15:18:13 2019 +0100
     3.3 @@ -1585,6 +1585,7 @@
     3.4          out_last = true;
     3.5  
     3.6      if (session) {
     3.7 +        free_Sync_state(session);
     3.8  
     3.9          if (session->db) {
    3.10              if (session->log)
    3.11 @@ -1758,12 +1759,6 @@
    3.12      session->unencrypted_subject = enable;
    3.13  }
    3.14  
    3.15 -DYNAMIC_API void config_keep_sync_msg(PEP_SESSION session, bool enable)
    3.16 -{
    3.17 -    assert(session);
    3.18 -    session->keep_sync_msg = enable;
    3.19 -}
    3.20 -
    3.21  DYNAMIC_API void config_service_log(PEP_SESSION session, bool enable)
    3.22  {
    3.23      assert(session);
     4.1 --- a/src/pEpEngine.h	Mon Mar 25 15:16:50 2019 +0100
     4.2 +++ b/src/pEpEngine.h	Mon Mar 25 15:18:13 2019 +0100
     4.3 @@ -367,14 +367,6 @@
     4.4  DYNAMIC_API void config_use_only_own_private_keys(PEP_SESSION session, bool enable);
     4.5  
     4.6  
     4.7 -// config_keep_sync_msg() - do not remove sync messages (for debugging purposes)
     4.8 -//
     4.9 -//      session (in)    session handle
    4.10 -//      enable (in)     flag if enabled or disabled
    4.11 -
    4.12 -DYNAMIC_API void config_keep_sync_msg(PEP_SESSION session, bool enable);
    4.13 -
    4.14 -
    4.15  // config_service_log() - log more for service purposes
    4.16  //
    4.17  //      session (in)    session handle
     5.1 --- a/src/pEp_internal.h	Mon Mar 25 15:16:50 2019 +0100
     5.2 +++ b/src/pEp_internal.h	Mon Mar 25 15:18:13 2019 +0100
     5.3 @@ -260,7 +260,6 @@
     5.4  
     5.5      bool passive_mode;
     5.6      bool unencrypted_subject;
     5.7 -    bool keep_sync_msg;
     5.8      bool service_log;
     5.9      
    5.10  #ifdef DEBUG_ERRORSTACK
     6.1 --- a/src/sync_api.c	Mon Mar 25 15:16:50 2019 +0100
     6.2 +++ b/src/sync_api.c	Mon Mar 25 15:18:13 2019 +0100
     6.3 @@ -39,7 +39,6 @@
     6.4  
     6.5  DYNAMIC_API PEP_STATUS deliverHandshakeResult(
     6.6          PEP_SESSION session,
     6.7 -        pEp_identity *partner,
     6.8          sync_handshake_result result
     6.9      )
    6.10  {
    6.11 @@ -50,7 +49,6 @@
    6.12      PEP_STATUS status = PEP_STATUS_OK;
    6.13  
    6.14      int event;
    6.15 -    bool need_partner = false;
    6.16  
    6.17      switch (result) {
    6.18          case SYNC_HANDSHAKE_CANCEL:
    6.19 @@ -70,14 +68,7 @@
    6.20              return PEP_ILLEGAL_VALUE;
    6.21      }
    6.22  
    6.23 -    pEp_identity *_partner = NULL;
    6.24 -    if(need_partner){
    6.25 -        _partner = identity_dup(partner);
    6.26 -        if (_partner == NULL)
    6.27 -            return PEP_OUT_OF_MEMORY;
    6.28 -    }
    6.29 -    status = send_Sync_message(session, Sync_PR_keysync, event);
    6.30 -
    6.31 +    status = signal_Sync_event(session, Sync_PR_keysync, event);
    6.32      return status;
    6.33  }
    6.34  
     7.1 --- a/src/sync_api.h	Mon Mar 25 15:16:50 2019 +0100
     7.2 +++ b/src/sync_api.h	Mon Mar 25 15:18:13 2019 +0100
     7.3 @@ -60,7 +60,7 @@
     7.4      SYNC_HANDSHAKE_REJECTED = 1
     7.5  } sync_handshake_result;
     7.6  
     7.7 -// deliverHandshakeResult() - give the result of the handshake dialog
     7.8 +// deliverHandshakeResult() - provide the result of the handshake dialog
     7.9  //
    7.10  //  parameters:
    7.11  //      session (in)        session handle
    7.12 @@ -68,7 +68,6 @@
    7.13  
    7.14  DYNAMIC_API PEP_STATUS deliverHandshakeResult(
    7.15          PEP_SESSION session,
    7.16 -        pEp_identity *partner,
    7.17          sync_handshake_result result
    7.18      );
    7.19  
     8.1 --- a/sync/cond_act_sync.yml2	Mon Mar 25 15:16:50 2019 +0100
     8.2 +++ b/sync/cond_act_sync.yml2	Mon Mar 25 15:18:13 2019 +0100
     8.3 @@ -40,11 +40,12 @@
     8.4  condition keyElectionWon
     8.5  ||
     8.6      pEp_identity *from = session->sync_state.common.from;
     8.7 +    char *signature_fpr = session->sync_state.common.signature_fpr;
     8.8  
     8.9 -    assert(from && from->fpr && from->fpr[0] && from->address &&
    8.10 -            from->address[0] && from->user_id && from->user_id[0]);
    8.11 -    if (!(from && from->fpr && from->fpr[0] && from->address &&
    8.12 -            from->address[0] && from->user_id && from->user_id[0]))
    8.13 +    assert(from && from->address && from->address[0] && from->user_id &&
    8.14 +            from->user_id[0]);
    8.15 +    if (!(from && from->address && from->address[0] && from->user_id &&
    8.16 +            from->user_id[0]))
    8.17          return PEP_ILLEGAL_VALUE;
    8.18  
    8.19      pEp_identity *me = NULL;
    8.20 @@ -59,8 +60,8 @@
    8.21          return PEP_ILLEGAL_VALUE;
    8.22      }
    8.23  
    8.24 -    size_t len = MIN(strlen(from->fpr), strlen(me->fpr));
    8.25 -    *result = strncasecmp(from->fpr, me->fpr, len) > 0;
    8.26 +    size_t len = MIN(strlen(signature_fpr), strlen(me->fpr));
    8.27 +    *result = strncasecmp(signature_fpr, me->fpr, len) > 0;
    8.28      free_identity(me);
    8.29  ||
    8.30  
    8.31 @@ -136,12 +137,15 @@
    8.32              return PEP_OUT_OF_MEMORY;
    8.33          }
    8.34  
    8.35 -        free(partner->fpr);
    8.36 -        partner->fpr = strdup(session->sync_state.common.signature_fpr);
    8.37 -        if (!partner->fpr) {
    8.38 -            free_identity(me);
    8.39 -            free_identity(partner);
    8.40 -            return PEP_OUT_OF_MEMORY;
    8.41 +        assert(session->sync_state.common.signature_fpr);
    8.42 +        if (session->sync_state.common.signature_fpr) {
    8.43 +            free(partner->fpr);
    8.44 +            partner->fpr = strdup(session->sync_state.common.signature_fpr);
    8.45 +            if (!partner->fpr) {
    8.46 +                free_identity(me);
    8.47 +                free_identity(partner);
    8.48 +                return PEP_OUT_OF_MEMORY;
    8.49 +            }
    8.50          }
    8.51  
    8.52          status = session->notifyHandshake(me, partner, «$type»);
    8.53 @@ -162,9 +166,28 @@
    8.54  timeout KeySync
    8.55      call "show_handshake" with "type" > SYNC_NOTIFY_TIMEOUT
    8.56  
    8.57 +action prepareOwnKeys
    8.58 +||
    8.59 +    stringlist_t *own_keys;
    8.60 +    PEP_STATUS status = _own_keys_retrieve(session, &own_keys, PEP_idf_not_for_sync);
    8.61 +    if (status)
    8.62 +        return status;
    8.63 +
    8.64 +    if (session->sync_state.common.own_keys)
    8.65 +        free_stringlist(session->sync_state.common.own_keys);
    8.66 +    session->sync_state.common.own_keys = own_keys;
    8.67 +
    8.68 +    identity_list *il;
    8.69 +    status = _own_identities_retrieve(session, &il, PEP_idf_not_for_sync);
    8.70 +    if (status)
    8.71 +        return status;
    8.72 +
    8.73 +    IdentityList_from_identity_list(il, &session->sync_state.keysync.ownIdentities);
    8.74 +||
    8.75 +
    8.76  action saveGroupKeys
    8.77  ||
    8.78 -    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.identities, NULL);
    8.79 +    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
    8.80      if (!il)
    8.81          return PEP_OUT_OF_MEMORY;
    8.82      
    8.83 @@ -250,7 +273,7 @@
    8.84              }
    8.85          } while (result != SQLITE_DONE);
    8.86  
    8.87 -        IdentityList_t *r = IdentityList_from_identity_list(il, &session->sync_state.keysync.identities);
    8.88 +        IdentityList_t *r = IdentityList_from_identity_list(il, &session->sync_state.keysync.ownIdentities);
    8.89          free_identity_list(il);
    8.90          if (!r)
    8.91              return PEP_OUT_OF_MEMORY;
     9.1 --- a/sync/gen_message_func.ysl2	Mon Mar 25 15:16:50 2019 +0100
     9.2 +++ b/sync/gen_message_func.ysl2	Mon Mar 25 15:18:13 2019 +0100
     9.3 @@ -42,6 +42,7 @@
     9.4      struct common_state_s {
     9.5          pEp_identity *from;
     9.6          char *signature_fpr;
     9.7 +        stringlist_t *own_keys;
     9.8      } common;
     9.9  
    9.10      `` apply "fsm", mode=state
    9.11 @@ -97,6 +98,8 @@
    9.12          return;
    9.13  
    9.14      free_identity(session->«yml:lcase(@name)»_state.common.from);
    9.15 +    free(session->«yml:lcase(@name)»_state.common.signature_fpr);
    9.16 +    free_stringlist(session->«yml:lcase(@name)»_state.common.own_keys);
    9.17  
    9.18  ||
    9.19  for "fsm"
    10.1 --- a/sync/gen_statemachine.ysl2	Mon Mar 25 15:16:50 2019 +0100
    10.2 +++ b/sync/gen_statemachine.ysl2	Mon Mar 25 15:18:13 2019 +0100
    10.3 @@ -3,7 +3,7 @@
    10.4  
    10.5  // generate state machine code
    10.6  
    10.7 -// Copyleft (c) 2016 - 2018, p≡p foundation
    10.8 +// Copyleft (c) 2016 - 2019, p≡p foundation
    10.9  
   10.10  // Written by Volker Birk
   10.11  
   10.12 @@ -487,6 +487,7 @@
   10.13                                      _data,
   10.14                                      size,
   10.15                                      li->ident->fpr,
   10.16 +                                    NULL,
   10.17                                      &_m
   10.18                                  );
   10.19                              if (status) {
   10.20 @@ -497,6 +498,29 @@
   10.21                              m = _m;
   10.22                              break;
   10.23  
   10.24 +                    `` for "fsm/message[@security='attach_own_keys']" |>>> case «../@name»__payload_PR_«yml:mixedCase(@name)»:
   10.25 +                            status = base_prepare_message(
   10.26 +                                    session,
   10.27 +                                    li->ident,
   10.28 +                                    li->ident,
   10.29 +                                    _data,
   10.30 +                                    size,
   10.31 +                                    NULL,
   10.32 +                                    &session->«yml:lcase(@name)»_state.common.own_keys,
   10.33 +                                    &_m
   10.34 +                                );
   10.35 +                            if (status) {
   10.36 +                                free(_data);
   10.37 +                                goto the_end;
   10.38 +                            }
   10.39 +                            status = encrypt_message(session, _m, NULL, &m, PEP_enc_PEP, 0);
   10.40 +                            if (status) {
   10.41 +                                status = PEP_«yml:ucase(@name)»_CANNOT_ENCRYPT;
   10.42 +                                goto the_end;
   10.43 +                            }
   10.44 +                            free_message(_m);
   10.45 +                            break;
   10.46 +
   10.47                          default:
   10.48                              status = base_prepare_message(
   10.49                                      session,
   10.50 @@ -505,6 +529,7 @@
   10.51                                      _data,
   10.52                                      size,
   10.53                                      NULL,
   10.54 +                                    NULL,
   10.55                                      &_m
   10.56                                  );
   10.57                              if (status) {
   10.58 @@ -764,15 +789,16 @@
   10.59              «@name»_event_None = None,
   10.60              «@name»_event_Init = Init,
   10.61          ||
   10.62 -        for "func:distinctName(state/event[not(not(../../message/@name=@name))])" {
   10.63 +        for "message" {
   10.64              const "name", "@name";
   10.65              |> «$name» = «/protocol/fsm/message[@name=$name]/@id»,
   10.66          }
   10.67 -        for "func:distinctName(state/event[not(not(../../external/@name=@name))])" {
   10.68 -            const "name", "@name";
   10.69 -            |> «$name» = «/protocol/fsm/external[@name=$name]/@id»,
   10.70 +        |> «@name»_event_Extra = Extra,
   10.71 +        for "external" {
   10.72 +            if "@id < 128"
   10.73 +                error > external «@name» must have ID >= 128 but it's «@id»
   10.74 +            |> «@name» = «@id»,
   10.75          }
   10.76 -        |> «@name»_event_Extra = Extra,
   10.77          for "func:distinctName(state/event[not(../../message/@name=@name or ../../external/@name=@name)])" {
   10.78              if "@name!='Init'"
   10.79                  |> «@name»`if "position()!=last()" > , `
   10.80 @@ -922,7 +948,7 @@
   10.81          if "not(event[@name='Init'])"
   10.82          ||
   10.83                  case Init:
   10.84 -                    // nothing to do
   10.85 +                    «../@name»_SERVICE_LOG("received Init but nothing to do", "Init");
   10.86                      break;
   10.87  
   10.88          ||
    11.1 --- a/sync/sync.fsm	Mon Mar 25 15:16:50 2019 +0100
    11.2 +++ b/sync/sync.fsm	Mon Mar 25 15:18:13 2019 +0100
    11.3 @@ -1,7 +1,7 @@
    11.4  // This file is under BSD License 2.0
    11.5  
    11.6  // Sync protocol for p≡p
    11.7 -// Copyright (c) 2016 - 2018, p≡p foundation
    11.8 +// Copyright (c) 2016 - 2019, p≡p foundation
    11.9  
   11.10  // Written by Volker Birk
   11.11  
   11.12 @@ -128,8 +128,10 @@
   11.13          }
   11.14  
   11.15          state NewGroup {
   11.16 -            on Init
   11.17 +            on Init {
   11.18 +                do prepareOwnKeys;
   11.19                  send GroupKeysAndClose; // we're not grouped yet, this is our own keys
   11.20 +            }
   11.21  
   11.22              on GroupKeysAndClose {
   11.23                  do saveGroupKeys;
   11.24 @@ -299,9 +301,9 @@
   11.25                  do saveGroupKeys;
   11.26          }
   11.27   
   11.28 -        external Accept 30;
   11.29 -        external Reject 31;
   11.30 -        external Cancel 32;
   11.31 +        external Accept 129;
   11.32 +        external Reject 130;
   11.33 +        external Cancel 131;
   11.34  
   11.35          // beacons are always broadcasted
   11.36  
   11.37 @@ -317,7 +319,8 @@
   11.38              field bool is_group;
   11.39          }
   11.40  
   11.41 -        message HandshakeAnswer 4 {
   11.42 +        message HandshakeAnswer 4, security=untrusted {
   11.43 +            auto Version version;
   11.44              field TID transaction;
   11.45          }
   11.46  
   11.47 @@ -333,13 +336,13 @@
   11.48              field TID transaction;
   11.49          }
   11.50  
   11.51 -        message GroupKeysAndClose 8 {
   11.52 +        message GroupKeysAndClose 8, security=attach_own_keys {
   11.53              field TID transaction;
   11.54 -            field IdentityList identities;
   11.55 +            field IdentityList ownIdentities;
   11.56          }
   11.57  
   11.58 -        message GroupKeys 9 {
   11.59 -            field IdentityList identities;
   11.60 +        message GroupKeys 9, security=attach_own_keys {
   11.61 +            field IdentityList ownIdentities;
   11.62          }
   11.63      }
   11.64  }