... keysync
authorVolker Birk <vb@pep.foundation>
Wed, 24 Aug 2016 00:30:50 +0200
branchkeysync
changeset 1077d22b9d70370d
parent 1076 7a80153bfc5a
child 1078 5861b53e0536
...
asn.1/devicegroup.asn1
asn.1/pEp.asn1
src/map_asn1.c
src/sync_impl.c
     1.1 --- a/asn.1/devicegroup.asn1	Tue Aug 23 19:20:08 2016 +0200
     1.2 +++ b/asn.1/devicegroup.asn1	Wed Aug 24 00:30:50 2016 +0200
     1.3 @@ -8,13 +8,9 @@
     1.4  EXPORTS DeviceGroup-Protocol;
     1.5  IMPORTS Version, Identity, IdentityList FROM PEP;
     1.6  
     1.7 -Beacon ::= SEQUENCE {
     1.8 +Beacon ::= NULL
     1.9  
    1.10 -}
    1.11 -
    1.12 -HandshakeRequest ::= SEQUENCE {
    1.13 -
    1.14 -}
    1.15 +HandshakeRequest ::= NULL
    1.16  
    1.17  GroupKeys ::= SEQUENCE {
    1.18      ownIdentities IdentityList
    1.19 @@ -28,7 +24,7 @@
    1.20          sequence    INTEGER,  /* always increases */
    1.21          me          Identity, /* identity of the sender */
    1.22          state       INTEGER,  /* state the sender is in */
    1.23 -        devicegroup BOOLEAN DEFAULT FALSE
    1.24 +        devicegroup BOOLEAN
    1.25              /* signals if this message is coming from a device group member */
    1.26      },
    1.27  
     2.1 --- a/asn.1/pEp.asn1	Tue Aug 23 19:20:08 2016 +0200
     2.2 +++ b/asn.1/pEp.asn1	Wed Aug 24 00:30:50 2016 +0200
     2.3 @@ -7,9 +7,6 @@
     2.4  
     2.5  EXPORTS Version, Identity, IdentityList;
     2.6  
     2.7 -major-version INTEGER ::= 1
     2.8 -minor-version INTEGER ::= 0
     2.9 -
    2.10  ISO639-1 ::= PrintableString(FROM ("a".."z")) (SIZE(2))
    2.11  Hex ::= PrintableString(FROM ("A".."F") | FROM ("0".."9"))
    2.12  Hash ::= Hex(SIZE(1..128)) -- SHA1 to SHA512 in hex
    2.13 @@ -20,14 +17,14 @@
    2.14      user-id     UTF8String  (SIZE(1..1024)) OPTIONAL,
    2.15      username    UTF8String  (SIZE(1..1024)) OPTIONAL,
    2.16      comm-type   INTEGER     (0..255) OPTIONAL,
    2.17 -    lang        ISO639-1    DEFAULT "en"
    2.18 +    lang        ISO639-1
    2.19  }
    2.20  
    2.21  IdentityList ::= SEQUENCE OF Identity
    2.22  
    2.23  Version ::= SEQUENCE {
    2.24 -    major       INTEGER (0..255) DEFAULT major-version,
    2.25 -    minor       INTEGER (0..255) DEFAULT minor-version
    2.26 +    major       INTEGER (0..255),
    2.27 +    minor       INTEGER (0..255)
    2.28  }
    2.29  
    2.30  END
     3.1 --- a/src/map_asn1.c	Tue Aug 23 19:20:08 2016 +0200
     3.2 +++ b/src/map_asn1.c	Wed Aug 24 00:30:50 2016 +0200
     3.3 @@ -51,10 +51,12 @@
     3.4      }
     3.5  
     3.6      if (ident->lang[0]) {
     3.7 -        result->lang = OCTET_STRING_new_fromBuf(&asn_DEF_ISO639_1,
     3.8 -                ident->lang, 2);
     3.9 -        if (!result->lang)
    3.10 -            goto enomem;
    3.11 +        int r = OCTET_STRING_fromBuf(&result->lang, ident->lang, 2);
    3.12 +        assert(r == 0);
    3.13 +    }
    3.14 +    else {
    3.15 +        int r = OCTET_STRING_fromBuf(&result->lang, "en", 2);
    3.16 +        assert(r == 0);
    3.17      }
    3.18  
    3.19      return result;
    3.20 @@ -107,9 +109,10 @@
    3.21      if (ident->comm_type)
    3.22          result->comm_type = (PEP_comm_type) *ident->comm_type;
    3.23  
    3.24 -    if (ident->lang) {
    3.25 -        result->lang[0] = ident->lang->buf[0];
    3.26 -        result->lang[1] = ident->lang->buf[1];
    3.27 +    if (ident->lang.size == 2) {
    3.28 +        result->lang[0] = ident->lang.buf[0];
    3.29 +        result->lang[1] = ident->lang.buf[1];
    3.30 +        result->lang[2] = 0;
    3.31      }
    3.32  
    3.33      return result;
     4.1 --- a/src/sync_impl.c	Tue Aug 23 19:20:08 2016 +0200
     4.2 +++ b/src/sync_impl.c	Wed Aug 24 00:30:50 2016 +0200
     4.3 @@ -6,6 +6,9 @@
     4.4  #include "map_asn1.h"
     4.5  #include "baseprotocol.h"
     4.6  
     4.7 +#define SYNC_VERSION_MAJOR 1
     4.8 +#define SYNC_VERSION_MINOR 0
     4.9 +
    4.10  PEP_STATUS receive_sync_msg(
    4.11          PEP_SESSION session,
    4.12          DeviceGroup_Protocol_t *msg
    4.13 @@ -28,16 +31,14 @@
    4.14              break;
    4.15  
    4.16          case DeviceGroup_Protocol__payload_PR_handshakeRequest:
    4.17 -            partner = Identity_to_Struct(
    4.18 -                    &msg->header.me, NULL);
    4.19 +            partner = Identity_to_Struct(&msg->header.me, NULL);
    4.20              if (!partner)
    4.21                  return PEP_OUT_OF_MEMORY;
    4.22              event = HandshakeRequest;
    4.23              break;
    4.24  
    4.25          case DeviceGroup_Protocol__payload_PR_groupKeys:
    4.26 -            partner = Identity_to_Struct(&msg->header.me,
    4.27 -                    NULL);
    4.28 +            partner = Identity_to_Struct(&msg->header.me, NULL);
    4.29              if (!partner)
    4.30                  return PEP_OUT_OF_MEMORY;
    4.31              identity_list *group_keys = IdentityList_to_identity_list(
    4.32 @@ -68,7 +69,7 @@
    4.33      for (bloblist_t *bl = src->attachments; bl && bl->value; bl = bl->next) {
    4.34          if (bl->mime_type && strcasecmp(bl->mime_type, "application/pEp") == 0
    4.35                  && bl->size) {
    4.36 -            DeviceGroup_Protocol_t *msg;
    4.37 +            DeviceGroup_Protocol_t *msg = NULL;
    4.38              uper_decode_complete(NULL, &asn_DEF_DeviceGroup_Protocol,
    4.39                      (void **) &msg, bl->value, bl->size);
    4.40              if (msg) {
    4.41 @@ -134,31 +135,29 @@
    4.42          goto error;
    4.43      }
    4.44  
    4.45 +    msg->header.version.major = SYNC_VERSION_MAJOR;
    4.46 +    msg->header.version.minor = SYNC_VERSION_MINOR;
    4.47 +
    4.48      int32_t seq;
    4.49      status = sequence_value(session, "DeviceGroup", &seq);
    4.50      if (status != PEP_STATUS_OK)
    4.51          goto error;
    4.52      msg->header.sequence = (long) seq;
    4.53  
    4.54 -    bool devicegroup = storedGroupKeys(session);
    4.55 -    if (devicegroup) { // default is FALSE
    4.56 -        BOOLEAN_t *dg = malloc(sizeof(BOOLEAN_t));
    4.57 -        assert(dg);
    4.58 -        if (!dg)
    4.59 -            goto enomem;
    4.60 -
    4.61 -        *dg = 1;
    4.62 -        msg->header.devicegroup = dg;
    4.63 -    }
    4.64 -
    4.65 -    msg->header.state = (long) state;
    4.66 -
    4.67      status = get_identity(session, partner->address, PEP_OWN_USERID, &me);
    4.68      if (status != PEP_STATUS_OK)
    4.69          goto error;
    4.70      if (Identity_from_Struct(me, &msg->header.me) == NULL)
    4.71          goto enomem;
    4.72  
    4.73 +    msg->header.state = (long) state;
    4.74 +
    4.75 +    bool devicegroup = storedGroupKeys(session);
    4.76 +    if (devicegroup)
    4.77 +        msg->header.devicegroup = 1;
    4.78 +    else
    4.79 +        msg->header.devicegroup = 0;
    4.80 +
    4.81      if (asn_check_constraints(&asn_DEF_DeviceGroup_Protocol, msg, NULL, NULL)) {
    4.82          status = PEP_CONTRAINTS_VIOLATED;
    4.83          goto error;