add own keys sync
authorVolker Birk <vb@pep-project.org>
Mon, 25 Mar 2019 12:30:25 +0100
branchsync
changeset 3393ecdb1635904a
parent 3392 6737d7f72b0c
child 3394 7e42949926d4
add own keys
src/baseprotocol.c
src/baseprotocol.h
sync/gen_statemachine.ysl2
sync/sync.fsm
     1.1 --- a/src/baseprotocol.c	Mon Mar 25 11:57:38 2019 +0100
     1.2 +++ b/src/baseprotocol.c	Mon Mar 25 12:30:25 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,32 @@
    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(_keys);
    1.39 +        free_stringlist(*keys);
    1.40 +        *keys = NULL;
    1.41 +    }
    1.42 +
    1.43 +    return status;
    1.44  
    1.45  enomem:
    1.46      status = PEP_OUT_OF_MEMORY;
    1.47 @@ -59,7 +85,8 @@
    1.48          const pEp_identity *partner,
    1.49          char *payload,
    1.50          size_t size,
    1.51 -        char *fpr,
    1.52 +        const char *fpr,
    1.53 +        stringlist_t **keys,
    1.54          message **result
    1.55      )
    1.56  {
    1.57 @@ -101,7 +128,7 @@
    1.58      if (!msg->longmsg)
    1.59          goto enomem;
    1.60  
    1.61 -    status = base_decorate_message(session, msg, payload, size, fpr);
    1.62 +    status = base_decorate_message(session, msg, payload, size, fpr, keys);
    1.63      if (status == PEP_STATUS_OK)
    1.64          *result = msg;
    1.65      return status;
     2.1 --- a/src/baseprotocol.h	Mon Mar 25 11:57:38 2019 +0100
     2.2 +++ b/src/baseprotocol.h	Mon Mar 25 12:30:25 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/sync/gen_statemachine.ysl2	Mon Mar 25 11:57:38 2019 +0100
     3.2 +++ b/sync/gen_statemachine.ysl2	Mon Mar 25 12:30:25 2019 +0100
     3.3 @@ -487,6 +487,7 @@
     3.4                                      _data,
     3.5                                      size,
     3.6                                      li->ident->fpr,
     3.7 +                                    NULL,
     3.8                                      &_m
     3.9                                  );
    3.10                              if (status) {
    3.11 @@ -497,6 +498,29 @@
    3.12                              m = _m;
    3.13                              break;
    3.14  
    3.15 +                    `` for "fsm/message[@security='attach_own_keys']" |>>> case «../@name»__payload_PR_«yml:mixedCase(@name)»:
    3.16 +                            status = base_prepare_message(
    3.17 +                                    session,
    3.18 +                                    li->ident,
    3.19 +                                    li->ident,
    3.20 +                                    _data,
    3.21 +                                    size,
    3.22 +                                    NULL,
    3.23 +                                    &session->«yml:lcase(@name)»_state.common.own_keys,
    3.24 +                                    &_m
    3.25 +                                );
    3.26 +                            if (status) {
    3.27 +                                free(_data);
    3.28 +                                goto the_end;
    3.29 +                            }
    3.30 +                            status = encrypt_message(session, _m, NULL, &m, PEP_enc_PEP, 0);
    3.31 +                            if (status) {
    3.32 +                                status = PEP_«yml:ucase(@name)»_CANNOT_ENCRYPT;
    3.33 +                                goto the_end;
    3.34 +                            }
    3.35 +                            free_message(_m);
    3.36 +                            break;
    3.37 +
    3.38                          default:
    3.39                              status = base_prepare_message(
    3.40                                      session,
    3.41 @@ -505,6 +529,7 @@
    3.42                                      _data,
    3.43                                      size,
    3.44                                      NULL,
    3.45 +                                    NULL,
    3.46                                      &_m
    3.47                                  );
    3.48                              if (status) {
     4.1 --- a/sync/sync.fsm	Mon Mar 25 11:57:38 2019 +0100
     4.2 +++ b/sync/sync.fsm	Mon Mar 25 12:30:25 2019 +0100
     4.3 @@ -336,12 +336,12 @@
     4.4              field TID transaction;
     4.5          }
     4.6  
     4.7 -        message GroupKeysAndClose 8 {
     4.8 +        message GroupKeysAndClose 8, security=attach_own_keys {
     4.9              field TID transaction;
    4.10              field IdentityList ownIdentities;
    4.11          }
    4.12  
    4.13 -        message GroupKeys 9 {
    4.14 +        message GroupKeys 9, security=attach_own_keys {
    4.15              field IdentityList ownIdentities;
    4.16          }
    4.17      }