ENGINE-107: Merged with default ENGINE-107
authorKrista Grothoff <krista@pep-project.org>
Thu, 06 Oct 2016 10:56:30 +0200
branchENGINE-107
changeset 12498d96a89bedb0
parent 1243 f1ca06851a48
parent 1248 c332c47fe26e
child 1251 070a7a80a6c9
child 1252 32a6231347f8
ENGINE-107: Merged with default
     1.1 --- a/.hgignore	Wed Oct 05 14:56:54 2016 +0200
     1.2 +++ b/.hgignore	Thu Oct 06 10:56:30 2016 +0200
     1.3 @@ -39,3 +39,4 @@
     1.4  Makefile.protocols
     1.5  test/msg_encrypt_for_self.asc
     1.6  tags
     1.7 +asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj.user
     2.1 --- a/asn.1/devicegroup.asn1	Wed Oct 05 14:56:54 2016 +0200
     2.2 +++ b/asn.1/devicegroup.asn1	Thu Oct 06 10:56:30 2016 +0200
     2.3 @@ -27,8 +27,9 @@
     2.4          sequence    INTEGER,  /* always increases */
     2.5          me          Identity, /* identity of the sender */
     2.6          state       INTEGER,  /* state the sender is in */
     2.7 -        devicegroup BOOLEAN
     2.8 +        devicegroup BOOLEAN,
     2.9              /* signals if this message is coming from a device group member */
    2.10 +        expiry      GeneralizedTime
    2.11      },
    2.12  
    2.13      payload CHOICE {
     3.1 --- a/asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj	Wed Oct 05 14:56:54 2016 +0200
     3.2 +++ b/asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj	Thu Oct 06 10:56:30 2016 +0200
     3.3 @@ -54,7 +54,7 @@
     3.4        <WarningLevel>Level3</WarningLevel>
     3.5        <Optimization>Disabled</Optimization>
     3.6        <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     3.7 -	  <CompileAs>Default</CompileAs>
     3.8 +      <CompileAs>Default</CompileAs>
     3.9      </ClCompile>
    3.10      <Link>
    3.11        <SubSystem>Windows</SubSystem>
    3.12 @@ -100,6 +100,8 @@
    3.13      </Link>
    3.14      <PreBuildEvent>
    3.15        <Command>cd ..
    3.16 +del *.c
    3.17 +del *.h
    3.18  asn1c -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message pEp.asn1 devicegroup.asn1
    3.19  del converter-sample.c
    3.20  </Command>
    3.21 @@ -130,6 +132,7 @@
    3.22      <ClCompile Include="..\ber_tlv_length.c" />
    3.23      <ClCompile Include="..\ber_tlv_tag.c" />
    3.24      <ClCompile Include="..\BIT_STRING.c" />
    3.25 +    <ClCompile Include="..\BOOLEAN.c" />
    3.26      <ClCompile Include="..\constraints.c" />
    3.27      <ClCompile Include="..\constr_CHOICE.c" />
    3.28      <ClCompile Include="..\constr_SEQUENCE.c" />
    3.29 @@ -141,20 +144,21 @@
    3.30      <ClCompile Include="..\GroupKeys.c" />
    3.31      <ClCompile Include="..\HandshakeRequest.c" />
    3.32      <ClCompile Include="..\Hash.c" />
    3.33 -    <ClCompile Include="..\Header.c" />
    3.34      <ClCompile Include="..\Hex.c" />
    3.35      <ClCompile Include="..\Identity.c" />
    3.36 +    <ClCompile Include="..\IdentityList.c" />
    3.37      <ClCompile Include="..\INTEGER.c" />
    3.38      <ClCompile Include="..\ISO639-1.c" />
    3.39 -    <ClCompile Include="..\KeyList.c" />
    3.40      <ClCompile Include="..\NativeEnumerated.c" />
    3.41      <ClCompile Include="..\NativeInteger.c" />
    3.42 +    <ClCompile Include="..\NULL.c" />
    3.43      <ClCompile Include="..\OCTET_STRING.c" />
    3.44      <ClCompile Include="..\per_decoder.c" />
    3.45      <ClCompile Include="..\per_encoder.c" />
    3.46      <ClCompile Include="..\per_opentype.c" />
    3.47      <ClCompile Include="..\per_support.c" />
    3.48      <ClCompile Include="..\PrintableString.c" />
    3.49 +    <ClCompile Include="..\Sync-Protocols.c" />
    3.50      <ClCompile Include="..\UTF8String.c" />
    3.51      <ClCompile Include="..\Version.c" />
    3.52      <ClCompile Include="..\xer_decoder.c" />
    3.53 @@ -174,6 +178,7 @@
    3.54      <ClInclude Include="..\ber_tlv_length.h" />
    3.55      <ClInclude Include="..\ber_tlv_tag.h" />
    3.56      <ClInclude Include="..\BIT_STRING.h" />
    3.57 +    <ClInclude Include="..\BOOLEAN.h" />
    3.58      <ClInclude Include="..\constraints.h" />
    3.59      <ClInclude Include="..\constr_CHOICE.h" />
    3.60      <ClInclude Include="..\constr_SEQUENCE.h" />
    3.61 @@ -185,21 +190,21 @@
    3.62      <ClInclude Include="..\GroupKeys.h" />
    3.63      <ClInclude Include="..\HandshakeRequest.h" />
    3.64      <ClInclude Include="..\Hash.h" />
    3.65 -    <ClInclude Include="..\Header.h" />
    3.66      <ClInclude Include="..\Hex.h" />
    3.67      <ClInclude Include="..\Identity.h" />
    3.68 +    <ClInclude Include="..\IdentityList.h" />
    3.69      <ClInclude Include="..\INTEGER.h" />
    3.70      <ClInclude Include="..\ISO639-1.h" />
    3.71 -    <ClInclude Include="..\KeyList.h" />
    3.72      <ClInclude Include="..\NativeEnumerated.h" />
    3.73      <ClInclude Include="..\NativeInteger.h" />
    3.74 +    <ClInclude Include="..\NULL.h" />
    3.75      <ClInclude Include="..\OCTET_STRING.h" />
    3.76 -    <ClInclude Include="..\OwnKeys.h" />
    3.77      <ClInclude Include="..\per_decoder.h" />
    3.78      <ClInclude Include="..\per_encoder.h" />
    3.79      <ClInclude Include="..\per_opentype.h" />
    3.80      <ClInclude Include="..\per_support.h" />
    3.81      <ClInclude Include="..\PrintableString.h" />
    3.82 +    <ClInclude Include="..\Sync-Protocols.h" />
    3.83      <ClInclude Include="..\UTF8String.h" />
    3.84      <ClInclude Include="..\Version.h" />
    3.85      <ClInclude Include="..\xer_decoder.h" />
     4.1 --- a/asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj.filters	Wed Oct 05 14:56:54 2016 +0200
     4.2 +++ b/asn.1/pEpEngineASN1/pEpEngineASN1.vcxproj.filters	Thu Oct 06 10:56:30 2016 +0200
     4.3 @@ -72,9 +72,6 @@
     4.4      <ClCompile Include="..\Hash.c">
     4.5        <Filter>Source Files</Filter>
     4.6      </ClCompile>
     4.7 -    <ClCompile Include="..\Header.c">
     4.8 -      <Filter>Source Files</Filter>
     4.9 -    </ClCompile>
    4.10      <ClCompile Include="..\Hex.c">
    4.11        <Filter>Source Files</Filter>
    4.12      </ClCompile>
    4.13 @@ -87,9 +84,6 @@
    4.14      <ClCompile Include="..\ISO639-1.c">
    4.15        <Filter>Source Files</Filter>
    4.16      </ClCompile>
    4.17 -    <ClCompile Include="..\KeyList.c">
    4.18 -      <Filter>Source Files</Filter>
    4.19 -    </ClCompile>
    4.20      <ClCompile Include="..\NativeEnumerated.c">
    4.21        <Filter>Source Files</Filter>
    4.22      </ClCompile>
    4.23 @@ -132,6 +126,18 @@
    4.24      <ClCompile Include="..\GroupKeys.c">
    4.25        <Filter>Source Files</Filter>
    4.26      </ClCompile>
    4.27 +    <ClCompile Include="..\BOOLEAN.c">
    4.28 +      <Filter>Source Files</Filter>
    4.29 +    </ClCompile>
    4.30 +    <ClCompile Include="..\IdentityList.c">
    4.31 +      <Filter>Source Files</Filter>
    4.32 +    </ClCompile>
    4.33 +    <ClCompile Include="..\NULL.c">
    4.34 +      <Filter>Source Files</Filter>
    4.35 +    </ClCompile>
    4.36 +    <ClCompile Include="..\Sync-Protocols.c">
    4.37 +      <Filter>Source Files</Filter>
    4.38 +    </ClCompile>
    4.39    </ItemGroup>
    4.40    <ItemGroup>
    4.41      <ClInclude Include="..\DeviceGroup-Protocol.h">
    4.42 @@ -200,9 +206,6 @@
    4.43      <ClInclude Include="..\Hash.h">
    4.44        <Filter>Header Files</Filter>
    4.45      </ClInclude>
    4.46 -    <ClInclude Include="..\Header.h">
    4.47 -      <Filter>Header Files</Filter>
    4.48 -    </ClInclude>
    4.49      <ClInclude Include="..\Hex.h">
    4.50        <Filter>Header Files</Filter>
    4.51      </ClInclude>
    4.52 @@ -215,9 +218,6 @@
    4.53      <ClInclude Include="..\ISO639-1.h">
    4.54        <Filter>Header Files</Filter>
    4.55      </ClInclude>
    4.56 -    <ClInclude Include="..\KeyList.h">
    4.57 -      <Filter>Header Files</Filter>
    4.58 -    </ClInclude>
    4.59      <ClInclude Include="..\NativeEnumerated.h">
    4.60        <Filter>Header Files</Filter>
    4.61      </ClInclude>
    4.62 @@ -227,9 +227,6 @@
    4.63      <ClInclude Include="..\OCTET_STRING.h">
    4.64        <Filter>Header Files</Filter>
    4.65      </ClInclude>
    4.66 -    <ClInclude Include="..\OwnKeys.h">
    4.67 -      <Filter>Header Files</Filter>
    4.68 -    </ClInclude>
    4.69      <ClInclude Include="..\per_decoder.h">
    4.70        <Filter>Header Files</Filter>
    4.71      </ClInclude>
    4.72 @@ -263,5 +260,17 @@
    4.73      <ClInclude Include="..\GroupKeys.h">
    4.74        <Filter>Header Files</Filter>
    4.75      </ClInclude>
    4.76 +    <ClInclude Include="..\BOOLEAN.h">
    4.77 +      <Filter>Header Files</Filter>
    4.78 +    </ClInclude>
    4.79 +    <ClInclude Include="..\IdentityList.h">
    4.80 +      <Filter>Header Files</Filter>
    4.81 +    </ClInclude>
    4.82 +    <ClInclude Include="..\NULL.h">
    4.83 +      <Filter>Header Files</Filter>
    4.84 +    </ClInclude>
    4.85 +    <ClInclude Include="..\Sync-Protocols.h">
    4.86 +      <Filter>Header Files</Filter>
    4.87 +    </ClInclude>
    4.88    </ItemGroup>
    4.89  </Project>
    4.90 \ No newline at end of file
     5.1 --- a/pEpEngine.vcxproj	Wed Oct 05 14:56:54 2016 +0200
     5.2 +++ b/pEpEngine.vcxproj	Thu Oct 06 10:56:30 2016 +0200
     5.3 @@ -65,7 +65,7 @@
     5.4      <Link>
     5.5        <SubSystem>Windows</SubSystem>
     5.6        <GenerateDebugInformation>true</GenerateDebugInformation>
     5.7 -      <AdditionalDependencies>$(TargetDir)\pEpEngineASN1.lib;%(AdditionalDependencies)</AdditionalDependencies>
     5.8 +      <AdditionalDependencies>$(TargetDir)\pEpEngineASN1.lib;Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
     5.9      </Link>
    5.10      <PreBuildEvent>
    5.11        <Command>
    5.12 @@ -84,13 +84,15 @@
    5.13        <TreatWarningAsError>false</TreatWarningAsError>
    5.14        <AdditionalIncludeDirectories>C:\Users\vb\share\asn1c;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    5.15        <CompileAs>Default</CompileAs>
    5.16 +      <MultiProcessorCompilation>true</MultiProcessorCompilation>
    5.17 +      <ControlFlowGuard>Guard</ControlFlowGuard>
    5.18      </ClCompile>
    5.19      <Link>
    5.20        <SubSystem>Windows</SubSystem>
    5.21        <GenerateDebugInformation>true</GenerateDebugInformation>
    5.22        <EnableCOMDATFolding>true</EnableCOMDATFolding>
    5.23        <OptimizeReferences>true</OptimizeReferences>
    5.24 -      <AdditionalDependencies>$(TargetDir)\pEpEngineASN1.lib;%(AdditionalDependencies)</AdditionalDependencies>
    5.25 +      <AdditionalDependencies>$(TargetDir)\pEpEngineASN1.lib;Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
    5.26      </Link>
    5.27      <PreBuildEvent>
    5.28        <Command>
    5.29 @@ -98,6 +100,7 @@
    5.30      </PreBuildEvent>
    5.31    </ItemDefinitionGroup>
    5.32    <ItemGroup>
    5.33 +    <ClCompile Include="src\asn1_helper.c" />
    5.34      <ClCompile Include="src\baseprotocol.c" />
    5.35      <ClCompile Include="src\blacklist.c" />
    5.36      <ClCompile Include="src\bloblist.c" />
    5.37 @@ -121,12 +124,14 @@
    5.38      <ClCompile Include="src\sync_actions.c" />
    5.39      <ClCompile Include="src\sync_driver.c" />
    5.40      <ClCompile Include="src\sync_fsm.c" />
    5.41 +    <ClCompile Include="src\sync_impl.c" />
    5.42      <ClCompile Include="src\sync_send_actions.c" />
    5.43      <ClCompile Include="src\timestamp.c" />
    5.44      <ClCompile Include="src\transport.c" />
    5.45      <ClCompile Include="src\trans_auto.c" />
    5.46    </ItemGroup>
    5.47    <ItemGroup>
    5.48 +    <ClInclude Include="src\asn1_helper.h" />
    5.49      <ClInclude Include="src\baseprotocol.h" />
    5.50      <ClInclude Include="src\blacklist.h" />
    5.51      <ClInclude Include="src\bloblist.h" />
    5.52 @@ -153,6 +158,7 @@
    5.53      <ClInclude Include="src\stringpair.h" />
    5.54      <ClInclude Include="src\sync.h" />
    5.55      <ClInclude Include="src\sync_fsm.h" />
    5.56 +    <ClInclude Include="src\sync_impl.h" />
    5.57      <ClInclude Include="src\timestamp.h" />
    5.58      <ClInclude Include="src\transport.h" />
    5.59      <ClInclude Include="src\trans_auto.h" />
     6.1 --- a/pEpEngine.vcxproj.filters	Wed Oct 05 14:56:54 2016 +0200
     6.2 +++ b/pEpEngine.vcxproj.filters	Thu Oct 06 10:56:30 2016 +0200
     6.3 @@ -96,6 +96,12 @@
     6.4      <ClCompile Include="src\openpgp_compat.c">
     6.5        <Filter>Quelldateien</Filter>
     6.6      </ClCompile>
     6.7 +    <ClCompile Include="src\asn1_helper.c">
     6.8 +      <Filter>Quelldateien</Filter>
     6.9 +    </ClCompile>
    6.10 +    <ClCompile Include="src\sync_impl.c">
    6.11 +      <Filter>Quelldateien</Filter>
    6.12 +    </ClCompile>
    6.13    </ItemGroup>
    6.14    <ItemGroup>
    6.15      <ClInclude Include="src\keymanagement.h">
    6.16 @@ -188,6 +194,12 @@
    6.17      <ClInclude Include="src\openpgp_compat.h">
    6.18        <Filter>Headerdateien</Filter>
    6.19      </ClInclude>
    6.20 +    <ClInclude Include="src\asn1_helper.h">
    6.21 +      <Filter>Headerdateien</Filter>
    6.22 +    </ClInclude>
    6.23 +    <ClInclude Include="src\sync_impl.h">
    6.24 +      <Filter>Headerdateien</Filter>
    6.25 +    </ClInclude>
    6.26    </ItemGroup>
    6.27    <ItemGroup>
    6.28      <Text Include="LICENSE.txt" />
     7.1 --- a/src/map_asn1.c	Wed Oct 05 14:56:54 2016 +0200
     7.2 +++ b/src/map_asn1.c	Thu Oct 06 10:56:30 2016 +0200
     7.3 @@ -178,3 +178,35 @@
     7.4      return NULL;
     7.5  }
     7.6  
     7.7 +timestamp *GeneralizedTime_to_timestamp(GeneralizedTime_t * asntime, timestamp *result)
     7.8 +{
     7.9 +    assert(asntime);
    7.10 +    if (!asntime)
    7.11 +        return NULL;
    7.12 +
    7.13 +    time_t smpltime = asn_GT2time(asntime, NULL, 0);
    7.14 +
    7.15 +    if (!result){
    7.16 +        result = new_timestamp(smpltime);
    7.17 +    }
    7.18 +    else
    7.19 +        gmtime_r(&smpltime, result);
    7.20 +
    7.21 +
    7.22 +    return result;
    7.23 +}
    7.24 +
    7.25 +time_t GeneralizedTime_to_time_t(GeneralizedTime_t * asntime)
    7.26 +{
    7.27 +    return asn_GT2time(asntime, NULL, 0);
    7.28 +}
    7.29 +
    7.30 +GeneralizedTime_t *timestamp_to_GeneralizedTime(timestamp * ts, GeneralizedTime_t *result)
    7.31 +{
    7.32 +    assert(ts);
    7.33 +    if (!ts)
    7.34 +        return NULL;
    7.35 +
    7.36 +    GeneralizedTime_t *asntime = asn_time2GT(result, ts, 0);
    7.37 +    return asntime;
    7.38 +}
     8.1 --- a/src/map_asn1.h	Wed Oct 05 14:56:54 2016 +0200
     8.2 +++ b/src/map_asn1.h	Thu Oct 06 10:56:30 2016 +0200
     8.3 @@ -4,6 +4,7 @@
     8.4  #include "identity_list.h"
     8.5  #include "../asn.1/Identity.h"
     8.6  #include "../asn.1/IdentityList.h"
     8.7 +#include "../asn.1/GeneralizedTime.h"
     8.8  
     8.9  #ifdef __cplusplus
    8.10  extern "C" {
    8.11 @@ -74,6 +75,44 @@
    8.12  
    8.13  identity_list *IdentityList_to_identity_list(IdentityList_t *list, identity_list *result);
    8.14  
    8.15 +// GeneralizedTime_to_timestamp() - convert ASN.1 GeneralizedTime to timestamp
    8.16 +//
    8.17 +//  params:
    8.18 +//      asntime (in)        ASN.1 GeneralizedTime to convert
    8.19 +//      result (inout)      timestamp to update or NULL to alloc a new one
    8.20 +//
    8.21 +//  return value:
    8.22 +//      pointer to allocated timestamp
    8.23 +//
    8.24 +//  caveat:
    8.25 +//      if a new timestamp is allocated, the ownership goes to the caller
    8.26 +
    8.27 +timestamp *GeneralizedTime_to_timestamp(GeneralizedTime_t * asntime, timestamp *result);
    8.28 +
    8.29 +// GeneralizedTime_to_time_t() - convert ASN.1 GeneralizedTime to time_t
    8.30 +//
    8.31 +//  params:
    8.32 +//      asntime (in)        ASN.1 GeneralizedTime to convert
    8.33 +//
    8.34 +//  return value:
    8.35 +//      resulting time_t
    8.36 +//
    8.37 +
    8.38 +time_t GeneralizedTime_to_time_t(GeneralizedTime_t * asntime);
    8.39 +
    8.40 +// timestamp_GeneralizedTime_to() - convert ASN.1 timestamp to GeneralizedTime
    8.41 +//
    8.42 +//  params:
    8.43 +//      ts (in)             timestam to convert
    8.44 +//      result (inout)      GeneralizedTime_t to update or NULL to alloc a new one
    8.45 +//
    8.46 +//  return value:
    8.47 +//      pointer to allocated ASN.1 GeneralizedTime
    8.48 +//
    8.49 +//  caveat:
    8.50 +//      if a new GeneralizedTime is allocated, the ownership goes to the caller
    8.51 +
    8.52 +GeneralizedTime_t *timestamp_to_GeneralizedTime(timestamp * ts, GeneralizedTime_t *result);
    8.53  
    8.54  #ifdef __cplusplus
    8.55  }
     9.1 --- a/src/platform_unix.c	Wed Oct 05 14:56:54 2016 +0200
     9.2 +++ b/src/platform_unix.c	Thu Oct 06 10:56:30 2016 +0200
     9.3 @@ -98,7 +98,8 @@
     9.4      return buffer;
     9.5  }
     9.6  
     9.7 -void uuid_generate_random(uuid__t out)
     9.8 +// TODO: Check and possibly fix this function if necessary
     9.9 +void uuid_generate_random(pEpUUID out)
    9.10  {
    9.11      uuid_t *uuid;
    9.12      uuid_rc_t rc_create;
    9.13 @@ -107,7 +108,7 @@
    9.14          uuid_make(uuid, UUID_MAKE_V1) != UUID_RC_OK ||
    9.15          uuid_export(uuid, UUID_FMT_BIN, out, NULL) != UUID_RC_OK)
    9.16      {
    9.17 -        memset(out, 0, sizeof(uuid__t));
    9.18 +        memset(out, 0, sizeof(pEpUUID));
    9.19      }
    9.20  
    9.21      if (rc_create == UUID_RC_OK)
    9.22 @@ -116,7 +117,8 @@
    9.23      }
    9.24  }
    9.25  
    9.26 -void uuid_unparse_upper(uuid__t uu, uuid_string_t out)
    9.27 +// TODO: Check and possibly fix this function if necessary
    9.28 +void uuid_unparse_upper(pEpUUID uu, uuid_string_t out)
    9.29  {
    9.30      uuid_t *uuid;
    9.31      uuid_rc_t rc_create;
    10.1 --- a/src/platform_unix.h	Wed Oct 05 14:56:54 2016 +0200
    10.2 +++ b/src/platform_unix.h	Thu Oct 06 10:56:30 2016 +0200
    10.3 @@ -71,9 +71,11 @@
    10.4  #define UUID uuid_t
    10.5  
    10.6  #ifdef ANDROID
    10.7 -typedef char uuid__t[16];
    10.8 -void uuid_generate_random(uuid__t out);
    10.9 -void uuid_unparse_upper(uuid__t uu, uuid_string_t out);
   10.10 +typedef char pEpUUID[16];
   10.11 +void uuid_generate_random(pEpUUID out);
   10.12 +void uuid_unparse_upper(pEpUUID uu, uuid_string_t out);
   10.13 +#else
   10.14 +typedef uuid_t pEpUUID;
   10.15  #endif
   10.16  
   10.17  #ifdef __cplusplus
    11.1 --- a/src/platform_windows.cpp	Wed Oct 05 14:56:54 2016 +0200
    11.2 +++ b/src/platform_windows.cpp	Thu Oct 06 10:56:30 2016 +0200
    11.3 @@ -267,32 +267,32 @@
    11.4      return _open(pathname, _O_RDWR | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
    11.5  }
    11.6  
    11.7 -void uuid_generate_random(uuid_t out)
    11.8 +void uuid_generate_random(pEpUUID out)
    11.9  {
   11.10      RPC_STATUS rpc_status = UuidCreate(out);
   11.11      assert(rpc_status == RPC_S_OK);
   11.12  }
   11.13  
   11.14 -int uuid_parse(char *in, uuid_t uu)
   11.15 +int uuid_parse(char *in, pEpUUID uu)
   11.16  {
   11.17      unsigned char *_in = (unsigned char *) in;
   11.18 -    RPC_STATUS rpc_status = UuidFromString(_in, &uu);
   11.19 +    RPC_STATUS rpc_status = UuidFromStringA(_in, uu);
   11.20      assert(rpc_status == RPC_S_OK);
   11.21      if (rpc_status == RPC_S_INVALID_STRING_UUID)
   11.22          return -1;
   11.23      return 0;
   11.24  }
   11.25  
   11.26 -void uuid_unparse_upper(uuid_t uu, uuid_string_t out)
   11.27 +void uuid_unparse_upper(pEpUUID uu, uuid_string_t out)
   11.28  {
   11.29 -    unsigned char *_out = out;
   11.30 +    unsigned char *_out = (unsigned char*)out;
   11.31      RPC_CSTR str;
   11.32 -    RPC_STATUS rpc_status = UuidToString(uu, &str);
   11.33 +    RPC_STATUS rpc_status = UuidToStringA(uu, &str);
   11.34      assert(rpc_status == RPC_S_OK);
   11.35      if (rpc_status == RPC_S_OK) {
   11.36          memcpy(out, str, 36);
   11.37          out[36] = 0;
   11.38 -        RpcStringFree(str);
   11.39 +        RpcStringFreeA(&str);
   11.40      }
   11.41      else { // if (rpc_status == RPC_S_OUT_OF_MEMORY)
   11.42          memset(out, 0, 37);
    12.1 --- a/src/platform_windows.h	Wed Oct 05 14:56:54 2016 +0200
    12.2 +++ b/src/platform_windows.h	Thu Oct 06 10:56:30 2016 +0200
    12.3 @@ -4,6 +4,14 @@
    12.4  
    12.5  #pragma warning(disable : 4996)
    12.6  
    12.7 +// We need to make sure winsock2 is included before windows.h, or we will get redefinitions of symbols
    12.8 +// as windows.h includes winsock1.h, so we will have duplicate symbols if windows.h is included first.
    12.9 +// It seems some of our code includes sync.h before including winsock.h, leading to the failure.
   12.10 +// Including winsock2.h here fixes the problem for now...
   12.11 +#ifdef WIN32 
   12.12 +#include <winsock2.h>
   12.13 +#endif // WIN32 
   12.14 +
   12.15  #include <Rpc.h>
   12.16  #include <string.h>
   12.17  #include <io.h>
   12.18 @@ -62,13 +70,13 @@
   12.19  long random(void);
   12.20  
   12.21  // on Windoze, uuid_t needs pointer semantics
   12.22 -typedef UUID *uuid_t;
   12.23 +typedef UUID pEpUUID[1];
   12.24  #define _UUID_STRING_T
   12.25  typedef char uuid_string_t[37];
   12.26  
   12.27 -void uuid_generate_random(uuid_t out);
   12.28 -int uuid_parse(char *in, uuid_t uu);
   12.29 -void uuid_unparse_upper(uuid_t uu, uuid_string_t out);
   12.30 +void uuid_generate_random(pEpUUID out);
   12.31 +int uuid_parse(char *in, pEpUUID uu);
   12.32 +void uuid_unparse_upper(pEpUUID uu, uuid_string_t out);
   12.33  
   12.34  #ifndef inline
   12.35  #define inline __inline
    13.1 --- a/src/sync_impl.c	Wed Oct 05 14:56:54 2016 +0200
    13.2 +++ b/src/sync_impl.c	Thu Oct 06 10:56:30 2016 +0200
    13.3 @@ -104,7 +104,9 @@
    13.4      return status;
    13.5  }
    13.6  
    13.7 -DYNAMIC_API void free_sync_msg(sync_msg_t *sync_msg)
    13.8 +// TODO: DYNAMIC_API was here, but broke the windows build. 
    13.9 +// We need to check whether it belongs here or it's a bug.
   13.10 +/* DYNAMIC_API */ void free_sync_msg(sync_msg_t *sync_msg)
   13.11  {
   13.12      assert(sync_msg);
   13.13      if (!(sync_msg))
   13.14 @@ -173,6 +175,9 @@
   13.15          return PEP_ILLEGAL_VALUE;
   13.16  
   13.17      bool found = false;
   13.18 +    bool expired = false;
   13.19 +    bool discarded = false;
   13.20 +    bool force_keep_msg = false;
   13.21      
   13.22      bloblist_t *last = NULL;
   13.23      for (bloblist_t *bl = src->attachments; bl && bl->value; bl = bl->next) {
   13.24 @@ -181,9 +186,9 @@
   13.25              DeviceGroup_Protocol_t *msg = NULL;
   13.26              uper_decode_complete(NULL, &asn_DEF_DeviceGroup_Protocol, (void **)
   13.27                      &msg, bl->value, bl->size);
   13.28 +
   13.29              if (msg) {
   13.30  
   13.31 -                int32_t value = (int32_t) msg->header.sequence;
   13.32                  char *user_id = strndup((char *) msg->header.me.user_id->buf,
   13.33                          msg->header.me.user_id->size);
   13.34                  assert(user_id);
   13.35 @@ -192,79 +197,105 @@
   13.36                      return PEP_OUT_OF_MEMORY;
   13.37                  }
   13.38  
   13.39 -                switch (msg->payload.present) {
   13.40 -                    // HandshakeRequest needs encryption
   13.41 -                    case DeviceGroup_Protocol__payload_PR_handshakeRequest:
   13.42 -                        if (rating < PEP_rating_reliable ||
   13.43 -                            strncmp(session->sync_uuid,
   13.44 -                                    (const char *)msg->payload.choice.handshakeRequest.partner.user_id->buf,
   13.45 -                                    msg->payload.choice.handshakeRequest.partner.user_id->size) != 0){
   13.46 -                            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
   13.47 -                            free(user_id);
   13.48 -                            return PEP_MESSAGE_DISCARDED;
   13.49 -                        }
   13.50 -                        break;
   13.51 -                    // accepting GroupKeys needs encryption and trust
   13.52 -                    case DeviceGroup_Protocol__payload_PR_groupKeys:
   13.53 -                        if (!keylist || rating < PEP_rating_reliable ||
   13.54 -                            strncmp(session->sync_uuid,
   13.55 -                                    (const char *)msg->payload.choice.groupKeys.partner.user_id->buf,
   13.56 -                                    msg->payload.choice.groupKeys.partner.user_id->size) != 0){
   13.57 -                            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
   13.58 -                            free(user_id);
   13.59 -                            return PEP_MESSAGE_DISCARDED;
   13.60 -                        }
   13.61 -
   13.62 -                        // check trust of identity with the right user_id
   13.63 -                        pEp_identity *_from = new_identity(src->from->address, 
   13.64 -                                                           keylist->value,
   13.65 -                                                           user_id,
   13.66 -                                                           src->from->username);
   13.67 -                        if (_from == NULL){
   13.68 -                            free(user_id);
   13.69 -                            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
   13.70 -                            return PEP_OUT_OF_MEMORY;
   13.71 -                        }
   13.72 -                        PEP_rating this_user_id_rating = PEP_rating_undefined;
   13.73 -                        identity_rating(session, _from, &this_user_id_rating);
   13.74 -                        free_identity(_from);
   13.75 -
   13.76 -                        if (this_user_id_rating < PEP_rating_trusted ) {
   13.77 -                            ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
   13.78 -                            free(user_id);
   13.79 -                            return PEP_MESSAGE_DISCARDED;
   13.80 -                        }
   13.81 -                        break;
   13.82 -                    default:
   13.83 -                        break;
   13.84 +                // check message expiry 
   13.85 +                time_t expiry = GeneralizedTime_to_time_t(&msg->header.expiry);
   13.86 +                time_t now = time(NULL);
   13.87 +                if(expiry != 0 && now != 0 && expiry < now){
   13.88 +                    expired = true;
   13.89 +                    goto flush;
   13.90                  }
   13.91  
   13.92 -
   13.93 +                int32_t value = (int32_t) msg->header.sequence;
   13.94                  PEP_STATUS status = sequence_value(session, (char *) user_id,
   13.95                          &value);
   13.96  
   13.97                  if (status == PEP_STATUS_OK) {
   13.98 +                    switch (msg->payload.present) {
   13.99 +                        // HandshakeRequest needs encryption
  13.100 +                        case DeviceGroup_Protocol__payload_PR_handshakeRequest:
  13.101 +                            if (rating < PEP_rating_reliable ||
  13.102 +                                strncmp(session->sync_uuid,
  13.103 +                                        (const char *)msg->payload.choice.handshakeRequest.partner.user_id->buf,
  13.104 +                                        msg->payload.choice.handshakeRequest.partner.user_id->size) != 0){
  13.105 +                                discarded = true;
  13.106 +                                goto flush;
  13.107 +                            }
  13.108 +                            break;
  13.109 +                        // accepting GroupKeys needs encryption and trust
  13.110 +                        case DeviceGroup_Protocol__payload_PR_groupKeys:
  13.111 +                            if (!keylist || rating < PEP_rating_reliable ||
  13.112 +                                // if header.state is HandshakingSole, then
  13.113 +                                // group is just forming in between 2 devices
  13.114 +                                // message must be addressed to that instance
  13.115 +                                // to be consumed
  13.116 +                                (msg->header.state == HandshakingSole && 
  13.117 +                                 strncmp(session->sync_uuid,
  13.118 +                                        (const char *)msg->payload.choice.groupKeys.partner.user_id->buf,
  13.119 +                                        msg->payload.choice.groupKeys.partner.user_id->size) != 0)){
  13.120 +                                discarded = true;
  13.121 +                                goto flush;
  13.122 +                            }
  13.123 +
  13.124 +                            // otherwise, when group keys are sent from a 
  13.125 +                            // pre-existing group, inject message but flag is 
  13.126 +                            // as discarded to prevent app to delete it, so 
  13.127 +                            // that other group members can also be updated
  13.128 +                            if(msg->header.state != HandshakingSole){
  13.129 +                                force_keep_msg = true;
  13.130 +                            }
  13.131 +
  13.132 +                            // check trust of identity with the right user_id
  13.133 +                            pEp_identity *_from = new_identity(src->from->address, 
  13.134 +                                                               keylist->value,
  13.135 +                                                               user_id,
  13.136 +                                                               src->from->username);
  13.137 +                            if (_from == NULL){
  13.138 +                                status = PEP_OUT_OF_MEMORY;
  13.139 +                                goto flush;
  13.140 +                            }
  13.141 +                            PEP_rating this_user_id_rating = PEP_rating_undefined;
  13.142 +                            identity_rating(session, _from, &this_user_id_rating);
  13.143 +                            free_identity(_from);
  13.144 +
  13.145 +                            if (this_user_id_rating < PEP_rating_trusted ) {
  13.146 +                                discarded = true;
  13.147 +                                goto flush;
  13.148 +                            }
  13.149 +                            break;
  13.150 +                        default:
  13.151 +                            break;
  13.152 +                    }
  13.153 +
  13.154 +
  13.155                      found = true;
  13.156                      sync_msg_t *sync_msg = malloc(sizeof(sync_msg_t));
  13.157                      if(sync_msg == NULL){
  13.158 -                        ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
  13.159 -                        return PEP_OUT_OF_MEMORY;
  13.160 +                        status = PEP_OUT_OF_MEMORY;
  13.161 +                        goto flush;
  13.162                      }
  13.163                      sync_msg->is_a_message = true;
  13.164                      sync_msg->u.message = msg;
  13.165                      status = call_inject_sync_msg(session, sync_msg);
  13.166                      if (status != PEP_STATUS_OK){
  13.167 -                        ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
  13.168                          if (status == PEP_SYNC_NO_INJECT_CALLBACK){
  13.169                              free(sync_msg);
  13.170                          }
  13.171 -                        return status;
  13.172 +                        goto flush;
  13.173                      }
  13.174                  }
  13.175                  else if (status == PEP_OWN_SEQUENCE) {
  13.176 -                    ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
  13.177 -                    return PEP_MESSAGE_DISCARDED;
  13.178 +                    status = PEP_STATUS_OK;
  13.179 +                    discarded = true;
  13.180 +                    goto flush;
  13.181                  }
  13.182 +
  13.183 +            flush:
  13.184 +                ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
  13.185 +                free(user_id);
  13.186 +
  13.187 +                if (status != PEP_STATUS_OK)
  13.188 +                    return status;
  13.189 +
  13.190              }
  13.191  
  13.192              if (!session->keep_sync_msg) {
  13.193 @@ -286,7 +317,11 @@
  13.194          }
  13.195      }
  13.196  
  13.197 -    if (found && !session->keep_sync_msg) {
  13.198 +    if (force_keep_msg) {
  13.199 +        return PEP_MESSAGE_DISCARDED;
  13.200 +    }
  13.201 +
  13.202 +    if ((expired || found) && !session->keep_sync_msg) {
  13.203          for (stringpair_list_t *spl = src->opt_fields ; spl && spl->value ;
  13.204                  spl = spl->next) {
  13.205              if (spl->value->key &&
  13.206 @@ -296,8 +331,12 @@
  13.207                      return PEP_MESSAGE_CONSUMED;
  13.208              }
  13.209          }
  13.210 +        return PEP_MESSAGE_DISCARDED;
  13.211      }
  13.212  
  13.213 +    if(discarded)
  13.214 +        return PEP_MESSAGE_DISCARDED;
  13.215 +
  13.216      return PEP_STATUS_OK;
  13.217  }
  13.218  
  13.219 @@ -317,6 +356,9 @@
  13.220      ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
  13.221  }
  13.222  
  13.223 +// Ten minutes
  13.224 +#define SYNC_MSG_EXPIRE_DELTA (60 * 10)
  13.225 +
  13.226  PEP_STATUS unicast_msg(
  13.227          PEP_SESSION session,
  13.228          const Identity partner,
  13.229 @@ -380,6 +422,13 @@
  13.230      else
  13.231          msg->header.devicegroup = 0;
  13.232  
  13.233 +    timestamp *expiry = new_timestamp(time(NULL) + SYNC_MSG_EXPIRE_DELTA);
  13.234 +    if(timestamp_to_GeneralizedTime(expiry, &msg->header.expiry) == NULL){
  13.235 +        free_timestamp(expiry);
  13.236 +        goto enomem;
  13.237 +    }
  13.238 +    free_timestamp(expiry);
  13.239 +
  13.240      if (asn_check_constraints(&asn_DEF_DeviceGroup_Protocol, msg, NULL, NULL)) {
  13.241          status = PEP_CONTRAINTS_VIOLATED;
  13.242          goto error;