changing message_api: adding flags to encrypt_message() keysync
authorVolker Birk <vb@pep-project.org>
Fri, 29 Jul 2016 10:45:13 +0200
branchkeysync
changeset 939ed7dfdae3031
parent 934 6ec71cdedec1
child 940 5f0a9d0f0ecd
changing message_api: adding flags to encrypt_message()
src/message_api.c
src/message_api.h
src/pEpEngine.c
src/sync_actions.c
src/sync_fsm.c
src/sync_fsm.h
src/sync_send_actions.c
sync/devicegroup.fsm
sync/gen_actions_skeleton.ysl2
sync/gen_statemachine.ysl2
     1.1 --- a/src/message_api.c	Wed Jul 27 16:20:31 2016 +0200
     1.2 +++ b/src/message_api.c	Fri Jul 29 10:45:13 2016 +0200
     1.3 @@ -1022,7 +1022,8 @@
     1.4          message *src,
     1.5          stringlist_t * extra,
     1.6          message **dst,
     1.7 -        PEP_enc_format enc_format
     1.8 +        PEP_enc_format enc_format,
     1.9 +        PEP_encrypt_flags_t flags
    1.10      )
    1.11  {
    1.12      PEP_STATUS status = PEP_STATUS_OK;
     2.1 --- a/src/message_api.h	Wed Jul 27 16:20:31 2016 +0200
     2.2 +++ b/src/message_api.h	Fri Jul 29 10:45:13 2016 +0200
     2.3 @@ -18,6 +18,12 @@
     2.4  void attach_own_key(PEP_SESSION session, message *msg);
     2.5  PEP_cryptotech determine_encryption_format(message *msg);
     2.6  
     2.7 +typedef enum _PEP_encrypt_flags {
     2.8 +    PEP_encrypt_flag_force_encryption = 0x1
     2.9 +} PEP_encrypt_flags; 
    2.10 +
    2.11 +typedef unsigned int PEP_encrypt_flags_t;
    2.12 +
    2.13  // encrypt_message() - encrypt message in memory
    2.14  //
    2.15  //  parameters:
    2.16 @@ -26,6 +32,7 @@
    2.17  //      extra (in)          extra keys for encryption
    2.18  //      dst (out)           pointer to new encrypted message or NULL on failure
    2.19  //      enc_format (in)     encrypted format
    2.20 +//      flags (in)          flags to set special encryption features
    2.21  //
    2.22  //  return value:
    2.23  //      PEP_STATUS_OK                   on success
    2.24 @@ -44,7 +51,8 @@
    2.25          message *src,
    2.26          stringlist_t *extra,
    2.27          message **dst,
    2.28 -        PEP_enc_format enc_format
    2.29 +        PEP_enc_format enc_format,
    2.30 +        PEP_encrypt_flags_t flags
    2.31      );
    2.32  
    2.33  
    2.34 @@ -72,7 +80,7 @@
    2.35      PEP_decrypt_flag_own_private_key = 0x1
    2.36  } PEP_decrypt_flags; 
    2.37  
    2.38 -typedef uint32_t PEP_decrypt_flags_t;
    2.39 +typedef unsigned int PEP_decrypt_flags_t;
    2.40  
    2.41  // decrypt_message() - decrypt message in memory
    2.42  //
    2.43 @@ -82,7 +90,7 @@
    2.44  //      dst (out)           pointer to new decrypted message or NULL on failure
    2.45  //      keylist (out)       stringlist with keyids
    2.46  //      color (out)         color for the message
    2.47 -//      flags (out)         flags to signal special message features
    2.48 +//      flags (out)         flags to signal special decryption features
    2.49  //
    2.50  //  return value:
    2.51  //      error status or PEP_STATUS_OK on success
    2.52 @@ -100,7 +108,7 @@
    2.53          message **dst,
    2.54          stringlist_t **keylist,
    2.55          PEP_color *color,
    2.56 -        PEP_decrypt_flags_t *flags 
    2.57 +        PEP_decrypt_flags_t *flags
    2.58  );
    2.59  
    2.60  // own_message_private_key_details() - details on own key in own message
     3.1 --- a/src/pEpEngine.c	Wed Jul 27 16:20:31 2016 +0200
     3.2 +++ b/src/pEpEngine.c	Fri Jul 29 10:45:13 2016 +0200
     3.3 @@ -685,7 +685,6 @@
     3.4      char *buffer;
     3.5      char *dest;
     3.6      size_t fsize;
     3.7 -    PEP_STATUS _status;
     3.8  
     3.9      assert(session);
    3.10      assert(fingerprint);
    3.11 @@ -718,6 +717,7 @@
    3.12  
    3.13      int n_words = 0;
    3.14      while (source < fingerprint + fsize) {
    3.15 +        PEP_STATUS _status;
    3.16          uint16_t value;
    3.17          char *word;
    3.18          size_t _wsize;
    3.19 @@ -1140,10 +1140,11 @@
    3.20      assert(psize);
    3.21      assert(keylist);
    3.22  
    3.23 -    if (!(session && ctext && csize && ptext && psize && keylist && keylist))
    3.24 +    if (!(session && ctext && csize && ptext && psize && keylist))
    3.25          return PEP_ILLEGAL_VALUE;
    3.26  
    3.27 -    return session->cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify(session, ctext, csize, ptext, psize, keylist);
    3.28 +    return session->cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify(
    3.29 +            session, ctext, csize, ptext, psize, keylist);
    3.30  }
    3.31  
    3.32  DYNAMIC_API PEP_STATUS encrypt_and_sign(
     4.1 --- a/src/sync_actions.c	Wed Jul 27 16:20:31 2016 +0200
     4.2 +++ b/src/sync_actions.c	Fri Jul 29 10:45:13 2016 +0200
     4.3 @@ -19,14 +19,19 @@
     4.4  PEP_STATUS showHandshake(
     4.5          PEP_SESSION session,
     4.6          DeviceState_state state,
     4.7 -        const Identity partner
     4.8 +        Identity partner,
     4.9 +        void *extra
    4.10      )
    4.11  {
    4.12      PEP_STATUS status = PEP_STATUS_OK;
    4.13 +
    4.14      assert(session);
    4.15      assert(partner);
    4.16 +    assert(extra == NULL);
    4.17 +
    4.18      if (!(session && partner))
    4.19          return PEP_ILLEGAL_VALUE;
    4.20 +
    4.21      assert(session->showHandshake);
    4.22      if (!session->showHandshake)
    4.23          return PEP_SYNC_NO_TRUSTWORDS_CALLBACK;
    4.24 @@ -64,18 +69,20 @@
    4.25  PEP_STATUS reject(
    4.26          PEP_SESSION session,
    4.27          DeviceState_state state,
    4.28 -        const Identity partner
    4.29 +        Identity partner,
    4.30 +        void *extra
    4.31      )
    4.32  {
    4.33      PEP_STATUS status = PEP_STATUS_OK;
    4.34  
    4.35      assert(session);
    4.36      assert(partner);
    4.37 +    assert(extra == NULL);
    4.38      if (!(session && partner))
    4.39          return PEP_ILLEGAL_VALUE;
    4.40  
    4.41 -    // working code
    4.42 -
    4.43 +    status = set_identity_flags(session, partner,
    4.44 +            partner->flags | PEP_idf_not_for_sync);
    4.45  
    4.46      return status;
    4.47  
    4.48 @@ -93,6 +100,7 @@
    4.49  //      session (in)        session handle
    4.50  //      state (in)          state the state machine is in
    4.51  //      partner (in)        partner to communicate with
    4.52 +//      _group_keys (in)    group keys received from partner
    4.53  //
    4.54  //  returns:
    4.55  //      PEP_STATUS_OK or any other value on error
    4.56 @@ -100,17 +108,19 @@
    4.57  PEP_STATUS storeGroupKeys(
    4.58          PEP_SESSION session,
    4.59          DeviceState_state state,
    4.60 -        const Identity partner
    4.61 +        Identity partner,
    4.62 +        void *_group_keys
    4.63      )
    4.64  {
    4.65      PEP_STATUS status = PEP_STATUS_OK;
    4.66  
    4.67      assert(session);
    4.68      assert(partner);
    4.69 -    if (!(session && partner))
    4.70 +    assert(_group_keys);
    4.71 +    if (!(session && partner && _group_keys))
    4.72          return PEP_ILLEGAL_VALUE;
    4.73  
    4.74 -    // working code
    4.75 +    Stringlist group_keys = (Stringlist) _group_keys;
    4.76  
    4.77  
    4.78      return status;
     5.1 --- a/src/sync_fsm.c	Wed Jul 27 16:20:31 2016 +0200
     5.2 +++ b/src/sync_fsm.c	Fri Jul 29 10:45:13 2016 +0200
     5.3 @@ -6,7 +6,7 @@
     5.4          PEP_SESSION session,
     5.5          DeviceState_state state,
     5.6          DeviceState_event event,
     5.7 -        const Identity partner,
     5.8 +        Identity partner,
     5.9          DeviceState_state state_partner
    5.10      )
    5.11  {
    5.12 @@ -23,16 +23,16 @@
    5.13      case Sole:
    5.14          switch (event) {
    5.15              case KeyGen:
    5.16 -                sendBeacon(session, state, NULL);
    5.17 +                sendBeacon(session, state, NULL, NULL);
    5.18                  break;
    5.19              case CannotDecrypt:
    5.20 -                sendBeacon(session, state, NULL);
    5.21 +                sendBeacon(session, state, NULL, NULL);
    5.22                  break;
    5.23              case Beacon:
    5.24 -                sendHandshakeRequest(session, state, partner);
    5.25 +                sendHandshakeRequest(session, state, partner, NULL);
    5.26                  break;
    5.27              case HandshakeRequest:
    5.28 -                sendHandshakeRequest(session, state, partner);
    5.29 +                sendHandshakeRequest(session, state, partner, NULL);
    5.30                  return HandshakingSole;
    5.31          default:
    5.32              return (DeviceState_state) invalid_event;
    5.33 @@ -42,10 +42,10 @@
    5.34      case HandshakingSole:
    5.35          switch (event) {
    5.36              case Init:
    5.37 -                showHandshake(session, state, partner);
    5.38 +                showHandshake(session, state, partner, NULL);
    5.39                  break;
    5.40              case HandshakeRejected:
    5.41 -                reject(session, state, partner);
    5.42 +                reject(session, state, partner, NULL);
    5.43                  return Sole;
    5.44              case HandshakeAccepted:
    5.45                  return WaitForGroupKeys;
    5.46 @@ -57,12 +57,12 @@
    5.47      case WaitForGroupKeys:
    5.48          switch (event) {
    5.49              case GroupKeys:
    5.50 -                storeGroupKeys(session, state, partner);
    5.51 +                storeGroupKeys(session, state, partner, NULL);
    5.52                  return Grouped;
    5.53              case Cancel:
    5.54                  return Sole;
    5.55              case Reject:
    5.56 -                reject(session, state, partner);
    5.57 +                reject(session, state, partner, NULL);
    5.58                  return Sole;
    5.59          default:
    5.60              return (DeviceState_state) invalid_event;
    5.61 @@ -72,20 +72,19 @@
    5.62      case Grouped:
    5.63          switch (event) {
    5.64              case KeyGen:
    5.65 -                sendGroupKeys(session, state, NULL);
    5.66 +                sendGroupKeys(session, state, NULL, NULL);
    5.67                  break;
    5.68              case HandshakeRequest:
    5.69 -                sendHandshakeRequest(session, state, partner);
    5.70 -                showHandshake(session, state, partner);
    5.71 +                sendHandshakeRequest(session, state, partner, NULL);
    5.72 +                showHandshake(session, state, partner, NULL);
    5.73                  break;
    5.74              case HandshakeRejected:
    5.75 -                reject(session, state, partner);
    5.76 +                reject(session, state, partner, NULL);
    5.77                  break;
    5.78 -            case HandshakeAccepted:
    5.79 -                sendGroupKeys(session, state, partner);
    5.80 +            case Hand:
    5.81                  break;
    5.82              case Reject:
    5.83 -                reject(session, state, NULL);
    5.84 +                reject(session, state, NULL, NULL);
    5.85                  break;
    5.86          default:
    5.87              return (DeviceState_state) invalid_event;
     6.1 --- a/src/sync_fsm.h	Wed Jul 27 16:20:31 2016 +0200
     6.2 +++ b/src/sync_fsm.h	Fri Jul 29 10:45:13 2016 +0200
     6.3 @@ -11,7 +11,8 @@
     6.4  // types
     6.5  
     6.6  typedef pEp_identity * Identity;
     6.7 -typedef union _param { const Identity partner; const stringlist_t *keylist; } param_t;
     6.8 +typedef stringlist_t * Stringlist;
     6.9 +typedef union _param { Identity partner; stringlist_t *keylist; } param_t;
    6.10  
    6.11  // error values
    6.12  
    6.13 @@ -44,17 +45,18 @@
    6.14      HandshakeRejected, 
    6.15      HandshakeAccepted, 
    6.16      Cancel, 
    6.17 -    Reject
    6.18 +    Reject, 
    6.19 +    Hand
    6.20  } DeviceState_event;
    6.21  
    6.22  // actions
    6.23  
    6.24 -PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, const Identity partner);
    6.25 -PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, const Identity partner);
    6.26 -PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, const Identity partner);
    6.27 -PEP_STATUS reject(PEP_SESSION session, DeviceState_state state, const Identity partner);
    6.28 -PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, const Identity partner);
    6.29 -PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, const Identity partner);
    6.30 +PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.31 +PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.32 +PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.33 +PEP_STATUS reject(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.34 +PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.35 +PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.36  
    6.37  // state machine
    6.38  
    6.39 @@ -62,7 +64,7 @@
    6.40          PEP_SESSION session,
    6.41          DeviceState_state state,
    6.42          DeviceState_event event,
    6.43 -        const Identity partner,
    6.44 +        Identity partner,
    6.45          DeviceState_state state_partner
    6.46      );
    6.47  
     7.1 --- a/src/sync_send_actions.c	Wed Jul 27 16:20:31 2016 +0200
     7.2 +++ b/src/sync_send_actions.c	Fri Jul 29 10:45:13 2016 +0200
     7.3 @@ -25,7 +25,8 @@
     7.4  PEP_STATUS sendBeacon(
     7.5          PEP_SESSION session,
     7.6          DeviceState_state state,
     7.7 -        const Identity partner
     7.8 +        Identity partner,
     7.9 +        void *extra
    7.10      )
    7.11  {
    7.12      PEP_STATUS status = PEP_STATUS_OK;
    7.13 @@ -116,7 +117,8 @@
    7.14  PEP_STATUS sendHandshakeRequest(
    7.15          PEP_SESSION session,
    7.16          DeviceState_state state,
    7.17 -        const Identity partner
    7.18 +        Identity partner,
    7.19 +        void *extra
    7.20      )
    7.21  {
    7.22      PEP_STATUS status = PEP_STATUS_OK;
    7.23 @@ -210,7 +212,8 @@
    7.24  PEP_STATUS sendGroupKeys(
    7.25          PEP_SESSION session,
    7.26          DeviceState_state state,
    7.27 -        const Identity partner
    7.28 +        Identity partner,
    7.29 +        void *extra
    7.30      )
    7.31  {
    7.32      PEP_STATUS status = PEP_STATUS_OK;
     8.1 --- a/sync/devicegroup.fsm	Wed Jul 27 16:20:31 2016 +0200
     8.2 +++ b/sync/devicegroup.fsm	Fri Jul 29 10:45:13 2016 +0200
     8.3 @@ -71,7 +71,8 @@
     8.4              }
     8.5              on HandshakeRejected(Identity partner)
     8.6                  do reject(partner);
     8.7 -            on HandshakeAccepted(Identity partner)
     8.8 +            on Hand
     8.9 +                hakeAccepted(Identity partner)
    8.10                  do sendGroupKeys(partner);
    8.11              on Reject(Identity partner)
    8.12                  do reject partner;
     9.1 --- a/sync/gen_actions_skeleton.ysl2	Wed Jul 27 16:20:31 2016 +0200
     9.2 +++ b/sync/gen_actions_skeleton.ysl2	Fri Jul 29 10:45:13 2016 +0200
     9.3 @@ -101,7 +101,8 @@
     9.4          PEP_STATUS «$action/@name»(
     9.5                  PEP_SESSION session,
     9.6                  «$fsm»_state state,
     9.7 -                const Identity partner
     9.8 +                Identity partner,
     9.9 +                void *extra
    9.10              )
    9.11          {
    9.12              PEP_STATUS status = PEP_STATUS_OK;
    9.13 @@ -145,7 +146,8 @@
    9.14          PEP_STATUS «$action/@name»(
    9.15                  PEP_SESSION session,
    9.16                  «$fsm»_state state,
    9.17 -                const Identity partner
    9.18 +                Identity partner,
    9.19 +                void *extra
    9.20              )
    9.21          {
    9.22              PEP_STATUS status = PEP_STATUS_OK;
    10.1 --- a/sync/gen_statemachine.ysl2	Wed Jul 27 16:20:31 2016 +0200
    10.2 +++ b/sync/gen_statemachine.ysl2	Fri Jul 29 10:45:13 2016 +0200
    10.3 @@ -37,7 +37,8 @@
    10.4          // types
    10.5  
    10.6          typedef pEp_identity * Identity;
    10.7 -        typedef union _param { const Identity partner; const stringlist_t *keylist; } param_t;
    10.8 +        typedef stringlist_t * Stringlist;
    10.9 +        typedef union _param { Identity partner; stringlist_t *keylist; } param_t;
   10.10  
   10.11          // error values
   10.12  
   10.13 @@ -70,7 +71,7 @@
   10.14          // actions
   10.15  
   10.16          `` const "name", "@name"
   10.17 -        `` for "func:distinctName(//action)" | PEP_STATUS «@name»(PEP_SESSION session, «$name»_state state, const Identity partner);
   10.18 +        `` for "func:distinctName(//action)" | PEP_STATUS «@name»(PEP_SESSION session, «$name»_state state, Identity partner, void *extra);
   10.19  
   10.20          // state machine
   10.21  
   10.22 @@ -78,7 +79,7 @@
   10.23                  PEP_SESSION session,
   10.24                  «@name»_state state,
   10.25                  «@name»_event event,
   10.26 -                const Identity partner,
   10.27 +                Identity partner,
   10.28                  «@name»_state state_partner
   10.29              );
   10.30  
   10.31 @@ -131,7 +132,7 @@
   10.32                  PEP_SESSION session,
   10.33                  «@name»_state state,
   10.34                  «@name»_event event,
   10.35 -                const Identity partner,
   10.36 +                Identity partner,
   10.37                  «@name»_state state_partner
   10.38              )
   10.39          {
   10.40 @@ -173,7 +174,7 @@
   10.41              when "parm" > «name(parm/*)»
   10.42              otherwise > NULL
   10.43          }
   10.44 -        > );\n
   10.45 +        > , NULL);\n
   10.46      }
   10.47  
   10.48      template "transition" | return «@target»;