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

+1-1
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;
+43
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+
}
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+
}
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+
}
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+
}
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+
}
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

+18-3
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

+1-1
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

+1-1
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);

Signal-Windows.Lib/Util/LibUtils.cs

+22-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1+
using System;
2+
using System.IO;
3+
using System.Net.Http;
4+
using System.Threading;
15
using libsignal.ecc;
26
using libsignalmetadatadotnet.certificate;
37
using libsignalservice;
48
using libsignalservice.configuration;
5-
using libsignalservice.push;
69
using libsignalservice.util;
710
using Microsoft.Extensions.Logging;
8-
using Microsoft.Toolkit.Uwp.Notifications;
9-
using System;
10-
using System.Collections.Generic;
11-
using System.IO;
12-
using System.Linq;
13-
using System.Text;
14-
using System.Threading;
15-
using System.Threading.Tasks;
11+
using Signal_Windows.Lib.Settings;
1612
using Windows.ApplicationModel;
17-
using Windows.Foundation.Metadata;
18-
using Windows.Networking.BackgroundTransfer;
1913
using Windows.Storage;
20-
using Windows.UI.Core;
21-
using Windows.UI.Notifications;
2214

2315
namespace Signal_Windows.Lib
2416
{
@@ -28,14 +20,28 @@ public class LibUtils
2820
public const string GlobalMutexName = "SignalWindowsPrivateMessenger_Mutex";
2921
public const string GlobalEventWaitHandleName = "SignalWindowsPrivateMessenger_EventWaitHandle";
3022
public static string UNIDENTIFIED_SENDER_TRUST_ROOT = "BXu6QIKVz5MA8gstzfOgRQGqyLqOwNKHL6INkv3IHWMF";
31-
public static string URL = "https://textsecure-service.whispersystems.org";
32-
public static SignalServiceUrl[] ServiceUrls = new SignalServiceUrl[] { new SignalServiceUrl("https://textsecure-service.whispersystems.org") };
33-
public static SignalServiceConfiguration ServiceConfiguration = new SignalServiceConfiguration(ServiceUrls, null);
23+
public static SignalServiceUrl[] ServiceUrls;
24+
public static SignalContactDiscoveryUrl[] ContactDiscoveryUrls;
25+
public static SignalServiceConfiguration ServiceConfiguration;
3426
public static bool MainPageActive = false;
3527
public static string USER_AGENT = "Signal-Windows";
3628
public static uint PREKEY_BATCH_SIZE = 100;
3729
public static bool WindowActive = false;
3830
public static Mutex GlobalLock;
31+
public static HttpClient HttpClient;
32+
public static AppConfig AppConfig;
33+
public static SignalSettings SignalSettings;
34+
35+
static LibUtils()
36+
{
37+
HttpClient = new HttpClient();
38+
AppConfig = new AppConfig();
39+
SignalSettings = AppConfig.GetSignalSettings();
40+
ServiceUrls = new SignalServiceUrl[] { new SignalServiceUrl(SignalSettings.ServiceUrl) };
41+
ContactDiscoveryUrls = new SignalContactDiscoveryUrl[] { new SignalContactDiscoveryUrl(SignalSettings.ContactDiscoveryServiceUrl) };
42+
ServiceConfiguration = new SignalServiceConfiguration(ServiceUrls, null, ContactDiscoveryUrls);
43+
}
44+
3945
private static SynchronizationContext GlobalLockContext;
4046

4147
internal static void Lock()

Signal-Windows.RC/Signal-Windows.RC.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@
112112
</ItemGroup>
113113
<ItemGroup>
114114
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
115-
<Version>6.1.5</Version>
115+
<Version>6.2.12</Version>
116116
</PackageReference>
117117
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
118-
<Version>3.0.0</Version>
118+
<Version>6.1.1</Version>
119119
</PackageReference>
120120
</ItemGroup>
121121
<ItemGroup>

Signal-Windows.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio Version 16
3-
VisualStudioVersion = 16.0.29503.13
3+
VisualStudioVersion = 16.0.30907.101
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Signal-Windows", "Signal-Windows\Signal-Windows.csproj", "{41736A64-5B66-44AF-879A-501192A46920}"
66
ProjectSection(ProjectDependencies) = postProject

Signal-Windows/App.xaml.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ sealed partial class App : Application
3535
{
3636
private static App Instance;
3737
private static ILogger Logger = LibsignalLogging.CreateLogger<App>();
38-
public static SignalServiceUrl[] ServiceUrls = new SignalServiceUrl[] { new SignalServiceUrl("https://textsecure-service.whispersystems.org") };
39-
public static SignalServiceConfiguration ServiceConfiguration = new SignalServiceConfiguration(ServiceUrls, null);
4038
public static StorageFolder LocalCacheFolder = ApplicationData.Current.LocalCacheFolder;
4139
public static bool MainPageActive = false;
42-
public static string USER_AGENT = "Signal-Windows";
4340
public static uint PREKEY_BATCH_SIZE = 100;
4441
public static ISignalLibHandle Handle = SignalHelper.CreateSignalLibHandle(false);
4542
private Dictionary<int, SignalWindowsFrontend> _Views = new Dictionary<int, SignalWindowsFrontend>();
@@ -102,7 +99,7 @@ private async void App_Suspending(object sender, SuspendingEventArgs e)
10299
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs ex)
103100
{
104101
Exception e = ex.Exception;
105-
Logger.LogError("UnhandledException {0} occured ({1}):\n{2}", e.GetType(), e.Message, e.StackTrace);
102+
Logger.LogError("UnhandledException {0} occurred ({1}):\n{2}", e.GetType(), e.Message, e.StackTrace);
106103
}
107104

108105
protected override async void OnActivated(IActivatedEventArgs args)

Signal-Windows/Package.appxmanifest

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
<Certificates>
5050
<Certificate StoreName="TrustedPeople" Content="textsecure-servicewhispersystemsorg.crt" />
5151
<Certificate StoreName="TrustedPeople" Content="api-directory-signal-org.crt"/>
52+
<Certificate StoreName="TrustedPeople" Content="textsecure-service-staging-whispersystems-org.crt"/>
53+
<Certificate StoreName="TrustedPeople" Content="api-staging-directory-signal-org.crt"/>
5254
</Certificates>
5355
</Extension>
5456
</Extensions>

Signal-Windows/Signal-Windows.csproj

+7-4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<UseVSHostingProcess>false</UseVSHostingProcess>
6666
<ErrorReport>prompt</ErrorReport>
6767
<Prefer32Bit>true</Prefer32Bit>
68+
<UseDotNetNativeToolchain>false</UseDotNetNativeToolchain>
6869
</PropertyGroup>
6970
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
7071
<OutputPath>bin\ARM\Release\</OutputPath>
@@ -144,10 +145,12 @@
144145
<Content Include="Assets\Wide310x150Logo.scale-150.png" />
145146
<Content Include="Assets\Wide310x150Logo.scale-400.png" />
146147
<Content Include="api-directory-signal-org.crt" />
148+
<Content Include="api-staging-directory-signal-org.crt" />
147149
<None Include="Package.StoreAssociation.xml" />
148150
<None Include="Package.xml" />
149151
<Content Include="textsecure-servicewhispersystemsorg.crt" />
150152
<None Include="Signal-Windows_StoreKey.pfx" />
153+
<Content Include="textsecure-service-staging-whispersystems-org.crt" />
151154
</ItemGroup>
152155
<ItemGroup>
153156
<Compile Include="App.xaml.cs">
@@ -386,16 +389,16 @@
386389
</ItemGroup>
387390
<ItemGroup>
388391
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
389-
<Version>6.1.5</Version>
392+
<Version>6.2.12</Version>
390393
</PackageReference>
391394
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
392-
<Version>3.0.0</Version>
395+
<Version>6.1.1</Version>
393396
</PackageReference>
394397
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
395-
<Version>3.0.0</Version>
398+
<Version>4.0.0</Version>
396399
</PackageReference>
397400
<PackageReference Include="MvvmLight">
398-
<Version>5.4.1</Version>
401+
<Version>5.4.1.1</Version>
399402
</PackageReference>
400403
<PackageReference Include="QueryString.NET">
401404
<Version>1.0.0</Version>

Signal-Windows/Utils.cs

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Globalization;
1010
using System.Threading.Tasks;
1111
using Windows.ApplicationModel;
12+
using Windows.ApplicationModel.Core;
1213
using Windows.Foundation;
1314
using Windows.Foundation.Metadata;
1415
using Windows.UI;
@@ -132,6 +133,16 @@ public static string GetColorFromBrush(SolidColorBrush brush)
132133
else { return GREY; }
133134
}
134135

136+
public static async Task CallOnMainViewUIThreadAsync(DispatchedHandler handler)
137+
{
138+
await CallOnUIThreadAsync(CoreApplication.MainView.CoreWindow.Dispatcher, handler);
139+
}
140+
141+
public static async Task CallOnUIThreadAsync(CoreDispatcher dispatcher, DispatchedHandler handler)
142+
{
143+
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, handler);
144+
}
145+
135146
public static IMessageView CreateMessageView(SignalMessage message)
136147
{
137148
if (message.Type == SignalMessageType.IdentityKeyChange)

0 commit comments

Comments
 (0)