Skip to content

Commit 4481174

Browse files
author
Jon Elverkilde
authored
Merge pull request #112 from pusher/feature/E2E-encryption
Feature: end-to-end encryption for private encrypted channels
2 parents 7810cda + 948fdb6 commit 4481174

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1336
-1187
lines changed

.github/workflows/build.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ jobs:
2626
PUSHER_APP_KEY: ${{ secrets.CI_APP_KEY }}
2727
PUSHER_APP_SECRET: ${{ secrets.CI_APP_SECRET }}
2828
PUSHER_APP_CLUSTER: ${{ secrets.CI_APP_CLUSTER }}
29-
run: vstest.console.exe /Parallel /Platform:x64 "./PusherClient.Tests/bin/Release/PusherClient.Tests.dll" /TestAdapterPath:"./PusherClient.Tests/bin/Release/"
30-
- name: Test pack
31-
run: msbuild /t:Pack /p:configuration=release PusherClient/PusherClient.csproj
29+
run: vstest.console.exe /Parallel /Platform:x64 "./PusherClient.Tests/bin/Release/net45/PusherClient.Tests.dll" /TestAdapterPath:"./PusherClient.Tests/bin/Release/net45"
30+
- name: Write code signing key
31+
env:
32+
CI_CODE_SIGN_KEY: ${{ secrets.CI_CODE_SIGN_KEY }}
33+
run: |
34+
./StrongName/WritePusherKey.ps1
35+
- name: Test strong name signing
36+
run: msbuild /p:SignAssembly=true /p:deterministic=true /p:msbuildArchitecture=x64 /p:configuration=Release pusher-dotnet-client.sln
37+
- name: Test pack with strong named assembly
38+
run: msbuild /t:Pack /p:SignAssembly=true /p:configuration=release PusherClient/PusherClient.csproj

.github/workflows/publish.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ jobs:
1515
uses: microsoft/[email protected]
1616
- name: Restore dependencies
1717
run: nuget restore pusher-dotnet-client.sln
18+
- name: Write code signing key
19+
env:
20+
CI_CODE_SIGN_KEY: ${{ secrets.CI_CODE_SIGN_KEY }}
21+
run: |
22+
./StrongName/WritePusherKey.ps1
1823
- name: Build
19-
run: msbuild /p:deterministic=true /p:msbuildArchitecture=x64 /p:configuration=Release pusher-dotnet-client.sln
24+
run: msbuild /p:SignAssembly=true /p:deterministic=true /p:msbuildArchitecture=x64 /p:configuration=Release pusher-dotnet-client.sln
2025
- name: Pack
21-
run: msbuild /t:Pack /p:configuration=release PusherClient/PusherClient.csproj
26+
run: msbuild /t:Pack /p:SignAssembly=true /p:configuration=release PusherClient/PusherClient.csproj
2227
- name: Publish
2328
run: nuget push PusherClient\bin\release\PusherClient.*.nupkg -NonInteractive -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NUGET_API_KEY }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ TestResults/
3535
# Secrets file
3636
AppConfig.test.json
3737

38+
# Signing key
39+
PusherClient.snk
40+
3841
# Custom
3942
_ReSharper.*/
4043
packages/

AuthHost/App.config

-11
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,4 @@
33
<appSettings>
44
<add key="Port" value="8888" />
55
</appSettings>
6-
<startup>
7-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
8-
</startup>
9-
<runtime>
10-
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
11-
<dependentAssembly>
12-
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
13-
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
14-
</dependentAssembly>
15-
</assemblyBinding>
16-
</runtime>
176
</configuration>

AuthHost/AuthHost.csproj

+19-125
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,28 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
42
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{218EE921-5E27-4E15-9382-42DD2F40857C}</ProjectGuid>
3+
<TargetFrameworks>net45</TargetFrameworks>
4+
<IsPackable>false</IsPackable>
85
<OutputType>Exe</OutputType>
9-
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>AuthHost</RootNamespace>
11-
<AssemblyName>AuthHost</AssemblyName>
12-
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
13-
<FileAlignment>512</FileAlignment>
14-
<TargetFrameworkProfile />
15-
<NuGetPackageImportStamp>
16-
</NuGetPackageImportStamp>
6+
<Authors>Pusher</Authors>
7+
<Company>Pusher.com</Company>
8+
<Product>PusherClient</Product>
9+
<Copyright>Copyright © Pusher 2021</Copyright>
10+
<Description>An example authentication host for use with the Pusher example app</Description>
1711
</PropertyGroup>
18-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19-
<PlatformTarget>AnyCPU</PlatformTarget>
20-
<DebugSymbols>true</DebugSymbols>
21-
<DebugType>full</DebugType>
22-
<Optimize>false</Optimize>
23-
<OutputPath>bin\Debug\</OutputPath>
24-
<DefineConstants>DEBUG;TRACE</DefineConstants>
25-
<ErrorReport>prompt</ErrorReport>
26-
<WarningLevel>4</WarningLevel>
27-
<Prefer32Bit>false</Prefer32Bit>
28-
</PropertyGroup>
29-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30-
<PlatformTarget>AnyCPU</PlatformTarget>
31-
<DebugType>pdbonly</DebugType>
32-
<Optimize>true</Optimize>
33-
<OutputPath>bin\Release\</OutputPath>
34-
<DefineConstants>TRACE</DefineConstants>
35-
<ErrorReport>prompt</ErrorReport>
36-
<WarningLevel>4</WarningLevel>
37-
<Prefer32Bit>false</Prefer32Bit>
38-
</PropertyGroup>
39-
<ItemGroup>
40-
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
42-
</Reference>
43-
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
44-
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
45-
</Reference>
46-
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
47-
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
48-
</Reference>
49-
<Reference Include="Nancy, Version=1.4.4.0, Culture=neutral, processorArchitecture=MSIL">
50-
<HintPath>..\packages\Nancy.1.4.4\lib\net40\Nancy.dll</HintPath>
51-
</Reference>
52-
<Reference Include="Nancy.Hosting.Self, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
53-
<HintPath>..\packages\Nancy.Hosting.Self.1.4.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
54-
</Reference>
55-
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
56-
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
57-
</Reference>
58-
<Reference Include="PusherServer, Version=4.4.0.0, Culture=neutral, processorArchitecture=MSIL">
59-
<HintPath>..\packages\PusherServer.4.4.0\lib\net45\PusherServer.dll</HintPath>
60-
</Reference>
61-
<Reference Include="SuperSocket.ClientEngine, Version=0.10.0.0, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
62-
<HintPath>..\packages\SuperSocket.ClientEngine.Core.0.10.0\lib\net45\SuperSocket.ClientEngine.dll</HintPath>
63-
</Reference>
64-
<Reference Include="System" />
65-
<Reference Include="System.ComponentModel.Composition" />
66-
<Reference Include="System.Configuration" />
67-
<Reference Include="System.Core" />
68-
<Reference Include="System.Linq, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
69-
<HintPath>..\packages\System.Linq.4.3.0\lib\net463\System.Linq.dll</HintPath>
70-
<Private>True</Private>
71-
<Private>True</Private>
72-
</Reference>
73-
<Reference Include="System.Net" />
74-
<Reference Include="System.Net.Http" />
75-
<Reference Include="System.Runtime, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
76-
<HintPath>..\packages\System.Runtime.4.3.1\lib\net462\System.Runtime.dll</HintPath>
77-
<Private>True</Private>
78-
<Private>True</Private>
79-
</Reference>
80-
<Reference Include="System.Runtime.Extensions, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
81-
<HintPath>..\packages\System.Runtime.Extensions.4.3.1\lib\net462\System.Runtime.Extensions.dll</HintPath>
82-
<Private>True</Private>
83-
<Private>True</Private>
84-
</Reference>
85-
<Reference Include="System.Runtime.InteropServices, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
86-
<HintPath>..\packages\System.Runtime.InteropServices.4.3.0\lib\net463\System.Runtime.InteropServices.dll</HintPath>
87-
<Private>True</Private>
88-
<Private>True</Private>
89-
</Reference>
90-
<Reference Include="System.Text.RegularExpressions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
91-
<HintPath>..\packages\System.Text.RegularExpressions.4.3.1\lib\net463\System.Text.RegularExpressions.dll</HintPath>
92-
<Private>True</Private>
93-
<Private>True</Private>
94-
</Reference>
95-
<Reference Include="System.Xml.Linq" />
96-
<Reference Include="System.Data.DataSetExtensions" />
97-
<Reference Include="Microsoft.CSharp" />
98-
<Reference Include="System.Data" />
99-
<Reference Include="System.Xml" />
100-
<Reference Include="WebSocket4Net, Version=0.15.2.11, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
101-
<HintPath>..\packages\WebSocket4Net.0.15.2\lib\net45\WebSocket4Net.dll</HintPath>
102-
</Reference>
103-
</ItemGroup>
12+
10413
<ItemGroup>
105-
<Compile Include="AuthModule.cs" />
106-
<Compile Include="Program.cs" />
107-
<Compile Include="Properties\AssemblyInfo.cs" />
14+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
15+
<PackageReference Include="Nancy" Version="1.4.4" />
16+
<PackageReference Include="Nancy.Hosting.Self" Version="1.4.1" />
17+
<PackageReference Include="PusherServer" Version="4.6.0" />
10818
</ItemGroup>
19+
10920
<ItemGroup>
110-
<None Include="App.config" />
111-
<None Include="packages.config" />
21+
<Reference Include="System.Configuration" />
11222
</ItemGroup>
23+
11324
<ItemGroup>
114-
<ProjectReference Include="..\PusherClient.Tests.Utilities\PusherClient.Tests.Utilities.csproj">
115-
<Project>{00f1f3be-1210-4d06-89ca-f1e17898384c}</Project>
116-
<Name>PusherClient.Tests.Utilities</Name>
117-
</ProjectReference>
25+
<ProjectReference Include="..\PusherClient.Tests.Utilities\PusherClient.Tests.Utilities.csproj" />
11826
</ItemGroup>
119-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
120-
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
121-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
122-
<PropertyGroup>
123-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
124-
</PropertyGroup>
125-
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
126-
</Target>
127-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
128-
Other similar extension points exist, see Microsoft.Common.targets.
129-
<Target Name="BeforeBuild">
130-
</Target>
131-
<Target Name="AfterBuild">
132-
</Target>
133-
-->
134-
</Project>
27+
28+
</Project>

AuthHost/AuthModule.cs

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Threading.Tasks;
23
using Nancy;
4+
using PusherClient;
35
using PusherClient.Tests.Utilities;
46
using PusherServer;
57

@@ -14,9 +16,16 @@ public class AuthModule : NancyModule
1416

1517
public string PusherApplicationSecret => Config.AppSecret;
1618

19+
public const string EncryptionMasterKeyText = "Rk4twMwEogcmx5dpV+6puT+nNidXoRd3smLvWR57FbQ=";
20+
1721
public AuthModule()
1822
{
19-
var provider = new Pusher(PusherApplicationId, PusherApplicationKey, PusherApplicationSecret);
23+
PusherServer.PusherOptions options = new PusherServer.PusherOptions
24+
{
25+
EncryptionMasterKey = Convert.FromBase64String(EncryptionMasterKeyText),
26+
Cluster = Config.Cluster,
27+
};
28+
var provider = new PusherServer.Pusher(PusherApplicationId, PusherApplicationKey, PusherApplicationSecret, options);
2029

2130
Post["/auth/{username}", ctx => ctx.Request.Form.channel_name && ctx.Request.Form.socket_id] = _ =>
2231
{
@@ -27,7 +36,7 @@ public AuthModule()
2736

2837
string authData = null;
2938

30-
if (channelName.StartsWith("presence-"))
39+
if (Channel.GetChannelType(channelName) == ChannelTypes.Presence)
3140
{
3241
var channelData = new PresenceChannelData
3342
{
@@ -42,8 +51,35 @@ public AuthModule()
4251
authData = provider.Authenticate(channelName, socketId).ToJson();
4352
}
4453

54+
if (Channel.GetChannelType(channelName) == ChannelTypes.PrivateEncrypted)
55+
{
56+
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
57+
SendSecretMessageAsync();
58+
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
59+
}
60+
4561
return authData;
4662
};
4763
}
64+
65+
private async Task SendSecretMessageAsync()
66+
{
67+
await Task.Delay(5000).ConfigureAwait(false);
68+
PusherServer.PusherOptions options = new PusherServer.PusherOptions
69+
{
70+
EncryptionMasterKey = Convert.FromBase64String(EncryptionMasterKeyText),
71+
Cluster = Config.Cluster,
72+
};
73+
string channelName = "private-encrypted-channel";
74+
string eventName = "secret-event";
75+
var provider = new PusherServer.Pusher(PusherApplicationId, PusherApplicationKey, PusherApplicationSecret, options);
76+
string secretMessage = $"sent secret at {DateTime.Now} on '{channelName}' using event '{eventName}'.";
77+
await provider.TriggerAsync(channelName, eventName, new
78+
{
79+
Name = nameof(AuthModule),
80+
Message = secretMessage,
81+
}).ConfigureAwait(false);
82+
Console.WriteLine(secretMessage);
83+
}
4884
}
4985
}

AuthHost/Properties/AssemblyInfo.cs

-36
This file was deleted.

AuthHost/packages.config

-18
This file was deleted.

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 2.1.0
4+
* [ADDED] Strong name to the PusherClient assembly.
5+
* [ADDED] Support for the authentication header on the HttpAuthorizer.
6+
* [ADDED] End-to-end encryption for private encrypted channels.
7+
* [ADDED] Method Channel.UnsubscribeAsync.
8+
* [ADDED] Host to PusherOptions.
9+
* [FIXED] The intermittent WebsocketAutoReconnect issue The socket is connecting, cannot connect again!
10+
311
## 2.0.1
412
* [FIXED] Filter on event name in event emitter.
513

ExampleApplication/App.config

-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
5-
</startup>
63
<system.diagnostics>
74
<sources>
85
<source name="Pusher" switchValue="Information, Warning, Error">
@@ -13,16 +10,4 @@
1310
</sources>
1411
<trace autoflush="true" />
1512
</system.diagnostics>
16-
<runtime>
17-
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
18-
<dependentAssembly>
19-
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
20-
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
21-
</dependentAssembly>
22-
<dependentAssembly>
23-
<assemblyIdentity name="System.Runtime.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
24-
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
25-
</dependentAssembly>
26-
</assemblyBinding>
27-
</runtime>
2813
</configuration>

0 commit comments

Comments
 (0)