Skip to content

Commit d4c5a32

Browse files
committed
Add support for contact discovery service
This addresses #212 Also - Add support for Signal staging services - Consolidate SignalServiceConfiguration initialization to one location - Update libsignal-service-dotnet to 2.10.0.1 - Update other dependencies
1 parent ea298db commit d4c5a32

23 files changed

+246
-46
lines changed

Signal-Windows.Lib/OutgoingMessages.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public async Task HandleOutgoingMessages()
189189
Logger.LogDebug("HandleOutgoingMessages()");
190190
try
191191
{
192-
var messageSender = new SignalServiceMessageSender(Token, LibUtils.ServiceConfiguration, Store.Username, Store.Password, (int)Store.DeviceId, new Store(), LibUtils.USER_AGENT, Store.DeviceId != 1, Pipe, null, null);
192+
var messageSender = new SignalServiceMessageSender(Token, LibUtils.ServiceConfiguration, Store.Username, Store.Password, (int)Store.DeviceId, new Store(), LibUtils.USER_AGENT, LibUtils.HttpClient, Store.DeviceId != 1, Pipe, null, null);
193193
while (!Token.IsCancellationRequested)
194194
{
195195
ISendable sendable = null;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Microsoft.Extensions.Configuration;
2+
using Windows.ApplicationModel;
3+
4+
namespace Signal_Windows.Lib.Settings
5+
{
6+
public class AppConfig
7+
{
8+
private readonly IConfigurationRoot configurationRoot;
9+
10+
public AppConfig()
11+
{
12+
string jsonSettingsFilePath =
13+
$@"{Package.Current.InstalledLocation.Path}\Signal-Windows.Lib\Settings\";
14+
15+
bool useStaging = false;
16+
if (useStaging)
17+
{
18+
jsonSettingsFilePath += "appsettings.json";
19+
}
20+
else
21+
{
22+
jsonSettingsFilePath += "appsettings.production.json";
23+
}
24+
25+
IConfigurationBuilder builder = new ConfigurationBuilder()
26+
.Add(new LocalConfigurationSource(jsonSettingsFilePath));
27+
28+
configurationRoot = builder.Build();
29+
}
30+
31+
public SignalSettings GetSignalSettings()
32+
{
33+
return new SignalSettings(GetSection<string>(nameof(SignalSettings.ServiceUrl)),
34+
GetSection<string>(nameof(SignalSettings.ContactDiscoveryServiceUrl)),
35+
GetSection<string>(nameof(SignalSettings.ContactDiscoveryServiceEnclaveId)));
36+
}
37+
38+
private T GetSection<T>(string key)
39+
{
40+
return configurationRoot.GetSection(key).Get<T>();
41+
}
42+
}
43+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Microsoft.Extensions.Configuration;
4+
using Newtonsoft.Json.Linq;
5+
using Windows.Storage;
6+
7+
namespace Signal_Windows.Lib.Settings
8+
{
9+
internal class LocalConfigurationProvider : ConfigurationProvider
10+
{
11+
public LocalConfigurationProvider(LocalConfigurationSource localConfigurationSource)
12+
{
13+
var appSettingsFile = WaitAndGet(StorageFile.GetFileFromPathAsync($@"{localConfigurationSource.JsonSettingsFilePath}").AsTask());
14+
JObject o = JObject.Parse(WaitAndGet(FileIO.ReadTextAsync(appSettingsFile).AsTask()));
15+
foreach (JProperty token in o["signalSettings"])
16+
{
17+
Data.Add(token.Name, (string)token.Value);
18+
}
19+
}
20+
21+
private T WaitAndGet<T>(Task<T> t)
22+
{
23+
t.Wait();
24+
return t.Result;
25+
}
26+
}
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.Extensions.Configuration;
2+
3+
namespace Signal_Windows.Lib.Settings
4+
{
5+
internal class LocalConfigurationSource : IConfigurationSource
6+
{
7+
public string JsonSettingsFilePath { get; }
8+
9+
public LocalConfigurationSource(string jsonSettingsFilePath)
10+
{
11+
JsonSettingsFilePath = jsonSettingsFilePath;
12+
}
13+
14+
public IConfigurationProvider Build(IConfigurationBuilder builder)
15+
{
16+
return new LocalConfigurationProvider(this);
17+
}
18+
}
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Signal_Windows.Lib.Settings
2+
{
3+
public sealed class SignalSettings
4+
{
5+
public string ServiceUrl { get; private set; }
6+
public string ContactDiscoveryServiceUrl { get; private set; }
7+
public string ContactDiscoveryServiceEnclaveId { get; private set; }
8+
9+
public SignalSettings(string serviceUrl, string contactDiscoveryServiceUrl, string contactDiscoveryServiceEnclaveId)
10+
{
11+
ServiceUrl = serviceUrl;
12+
ContactDiscoveryServiceUrl = contactDiscoveryServiceUrl;
13+
ContactDiscoveryServiceEnclaveId = contactDiscoveryServiceEnclaveId;
14+
}
15+
}
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"signalSettings": {
3+
"ServiceUrl": "https://textsecure-service-staging.whispersystems.org",
4+
"ContactDiscoveryServiceUrl": "https://api-staging.directory.signal.org",
5+
"ContactDiscoveryServiceEnclaveId": "c98e00a4e3ff977a56afefe7362a27e4961e4f19e211febfbb19b897e6b80b15"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"signalSettings": {
3+
"ServiceUrl": "https://textsecure-service.whispersystems.org",
4+
"ContactDiscoveryServiceUrl": "https://api.directory.signal.org",
5+
"ContactDiscoveryServiceEnclaveId": "c98e00a4e3ff977a56afefe7362a27e4961e4f19e211febfbb19b897e6b80b15"
6+
}
7+
}

Signal-Windows.Lib/Signal-Windows.Lib.csproj

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
107107
</PropertyGroup>
108108
<ItemGroup>
109+
<Compile Include="Settings\AppConfig.cs" />
109110
<Compile Include="DisappearingMessagesManager.cs" />
110111
<Compile Include="Events\SignalMessageEventArgs.cs" />
111112
<Compile Include="GlobalSettingsManager.cs" />
@@ -114,6 +115,9 @@
114115
<Compile Include="Migrations\SignalDB\20180521001340_m6.designer.cs">
115116
<DependentUpon>20180521001340_m6.cs</DependentUpon>
116117
</Compile>
118+
<Compile Include="Settings\LocalConfigurationProvider.cs" />
119+
<Compile Include="Settings\LocalConfigurationSource.cs" />
120+
<Compile Include="Settings\SignalSettings.cs" />
117121
<Compile Include="SignalWebSocket.cs" />
118122
<Compile Include="Util\LibUtils.cs" />
119123
<Compile Include="Migrations\LibsignalDB\20170806145530_ls1.cs" />
@@ -167,7 +171,7 @@
167171
</ItemGroup>
168172
<ItemGroup>
169173
<PackageReference Include="libsignal-service-dotnet">
170-
<Version>2.10.0</Version>
174+
<Version>2.10.0.1</Version>
171175
</PackageReference>
172176
<PackageReference Include="Microsoft.EntityFrameworkCore">
173177
<Version>1.1.5</Version>
@@ -181,18 +185,29 @@
181185
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
182186
<Version>1.1.5</Version>
183187
</PackageReference>
188+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions">
189+
<Version>1.1.2</Version>
190+
</PackageReference>
184191
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
185-
<Version>6.1.5</Version>
192+
<Version>6.2.12</Version>
186193
</PackageReference>
187194
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
188-
<Version>3.0.0</Version>
195+
<Version>6.1.1</Version>
189196
</PackageReference>
190197
</ItemGroup>
191198
<ItemGroup>
192199
<SDKReference Include="WindowsMobile, Version=10.0.16299.0">
193200
<Name>Windows Mobile Extensions for the UWP</Name>
194201
</SDKReference>
195202
</ItemGroup>
203+
<ItemGroup>
204+
<Content Include="Settings\appsettings.json">
205+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
206+
</Content>
207+
<Content Include="Settings\appsettings.production.json">
208+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
209+
</Content>
210+
</ItemGroup>
196211
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
197212
<VisualStudioVersion>14.0</VisualStudioVersion>
198213
</PropertyGroup>

Signal-Windows.Lib/SignalLibHandle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ private void InitNetwork()
975975
try
976976
{
977977
Logger.LogTrace("InitNetwork() sync context = {0}", SynchronizationContext.Current);
978-
MessageReceiver = new SignalServiceMessageReceiver(LibUtils.ServiceConfiguration, new StaticCredentialsProvider(Store.Username, Store.Password, Store.SignalingKey, (int)Store.DeviceId), LibUtils.USER_AGENT);
978+
MessageReceiver = new SignalServiceMessageReceiver(LibUtils.ServiceConfiguration, new StaticCredentialsProvider(Store.Username, Store.Password, Store.SignalingKey, (int)Store.DeviceId), LibUtils.USER_AGENT, LibUtils.HttpClient);
979979
Task.Run(async () =>
980980
{
981981
try

Signal-Windows.Lib/SignalWebSocket.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public async Task ConnectAsync()
9696
if (e.Message.Contains("(403)"))
9797
{
9898
SemaphoreSlim.Release();
99-
throw new AuthorizationFailedException("OWS server rejected authorization.");
99+
throw new AuthorizationFailedException(403, "OWS server rejected authorization.");
100100
}
101101
Logger.LogError("ConnectAsync() failed: {0}\n{1}", e.Message, e.StackTrace); //System.Runtime.InteropServices.COMException (0x80072EE7)
102102
await Task.Delay(10 * 1000);

0 commit comments

Comments
 (0)