Skip to content

Commit 21d7c66

Browse files
committed
Add Contact Discovery SSL certificate and add test validating connection to all Signal URLs work
1 parent 6683cfe commit 21d7c66

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

libsignal-service-dotnet-tests/ConnectionTest.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using libsignalservice;
22
using libsignalservice.configuration;
33
using libsignalservice.push.exceptions;
4+
using libsignalservice.util;
45
using Microsoft.VisualStudio.TestTools.UnitTesting;
56
using System;
67
using System.Collections.Generic;
8+
using System.Net.Http;
79
using System.Text;
810
using System.Threading;
911
using System.Threading.Tasks;
@@ -14,7 +16,8 @@ namespace libsignal_service_dotnet_tests
1416
public class ConnectionTest
1517
{
1618
public static SignalServiceUrl[] ServiceUrls = new SignalServiceUrl[] { new SignalServiceUrl("https://textsecure-service.whispersystems.org") };
17-
public static SignalServiceConfiguration ServiceConfiguration = new SignalServiceConfiguration(ServiceUrls, null, null);
19+
public static SignalContactDiscoveryUrl[] ContactDiscoveryUrls = new SignalContactDiscoveryUrl[] { new SignalContactDiscoveryUrl("https://api.directory.signal.org") };
20+
public static SignalServiceConfiguration ServiceConfiguration = new SignalServiceConfiguration(ServiceUrls, null, ContactDiscoveryUrls);
1821
public static string UserAgent = "libsignal-service-dotnet-tests";
1922

2023
[TestMethod]
@@ -28,5 +31,13 @@ public async Task TestConnection()
2831
}
2932
catch (AuthorizationFailedException) { }
3033
}
34+
35+
[TestMethod]
36+
public async Task TestSignalConnections()
37+
{
38+
using HttpClient httpClient = Util.CreateHttpClient();
39+
await httpClient.GetAsync(ServiceUrls[0].Url);
40+
await httpClient.GetAsync(ContactDiscoveryUrls[0].Url);
41+
}
3142
}
3243
}

libsignal-service-dotnet-tests/libsignal-service-dotnet-tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<RootNamespace>libsignal_service_dotnet_tests</RootNamespace>
6-
6+
<LangVersion>8.0</LangVersion>
77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
99

libsignal-service-dotnet/util/Util.cs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace libsignalservice.util
1010
{
11-
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
1211
public class Util
1312
{
1413
public static byte[] Join(params byte[][] input)
@@ -191,10 +190,12 @@ public static HttpClient CreateHttpClient()
191190

192191
private static bool IsCorrectCertificate(HttpRequestMessage a, X509Certificate2 b, X509Chain c, SslPolicyErrors d)
193192
{
194-
return d == SslPolicyErrors.None || b.RawData.SequenceEqual(Certificate);
193+
return d == SslPolicyErrors.None ||
194+
b.RawData.SequenceEqual(SignalServiceCertificate) ||
195+
b.RawData.SequenceEqual(SignalContactDiscoveryServiceCertificate);
195196
}
196197

197-
public static readonly byte[] Certificate = new byte[] {
198+
public static readonly byte[] SignalServiceCertificate = new byte[] {
198199
48, 130, 3, 227, 48, 130, 2, 203, 160, 3, 2, 1, 2, 2, 2, 16, 24, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1,
199200
11, 5, 0, 48, 129, 141, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 19, 48, 17, 6, 3, 85, 4, 8, 12, 10, 67,
200201
97, 108, 105, 102, 111, 114, 110, 105, 97, 49, 22, 48, 20, 6, 3, 85, 4, 7, 12, 13, 83, 97, 110, 32, 70, 114, 97,
@@ -233,6 +234,51 @@ private static bool IsCorrectCertificate(HttpRequestMessage a, X509Certificate2
233234
243, 201, 67, 3, 145, 192, 45, 100, 116, 227, 145, 64, 46, 72, 184, 175, 159, 141, 248, 156, 183, 24, 93, 169, 76, 80,
234235
133, 188, 177, 3, 75, 146, 194, 147, 169, 81, 246, 232, 194, 146, 218, 221, 135, 69, 91, 56, 115, 0, 223, 154, 209, 179,
235236
153, 100, 139, 110, 4, 65, 151, 255, 14, 170, 234, 185, 92, 178, 205, 17, 66, 12, 223, 83, 85, 112, 21, 5, 164, 168, 73 };
237+
238+
public static readonly byte[] SignalContactDiscoveryServiceCertificate = new byte[] {
239+
48, 130, 4, 48, 48, 130, 3, 24, 160, 3, 2, 1, 2, 2, 2, 16, 58, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1,
240+
1, 11, 5, 0, 48, 129, 141, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 19, 48, 17, 6, 3, 85, 4, 8, 12,
241+
10, 67, 97, 108, 105, 102, 111, 114, 110, 105, 97, 49, 22, 48, 20, 6, 3, 85, 4, 7, 12, 13, 83, 97, 110, 32,
242+
70, 114, 97, 110, 99, 105, 115, 99, 111, 49, 29, 48, 27, 6, 3, 85, 4, 10, 12, 20, 79, 112, 101, 110, 32, 87,
243+
104, 105, 115, 112, 101, 114, 32, 83, 121, 115, 116, 101, 109, 115, 49, 29, 48, 27, 6, 3, 85, 4, 11, 12, 20,
244+
79, 112, 101, 110, 32, 87, 104, 105, 115, 112, 101, 114, 32, 83, 121, 115, 116, 101, 109, 115, 49, 19, 48,
245+
17, 6, 3, 85, 4, 3, 12, 10, 84, 101, 120, 116, 83, 101, 99, 117, 114, 101, 48, 30, 23, 13, 49, 57, 48, 54,
246+
48, 49, 48, 48, 48, 48, 48, 48, 90, 23, 13, 51, 49, 48, 49, 48, 57, 48, 51, 51, 55, 49, 48, 90, 48, 129,
247+
131, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 19, 48, 17, 6, 3, 85, 4, 8, 12, 10, 67, 97, 108, 105,
248+
102, 111, 114, 110, 105, 97, 49, 29, 48, 27, 6, 3, 85, 4, 10, 12, 20, 79, 112, 101, 110, 32, 87, 104, 105,
249+
115, 112, 101, 114, 32, 83, 121, 115, 116, 101, 109, 115, 49, 29, 48, 27, 6, 3, 85, 4, 11, 12, 20, 79, 112,
250+
101, 110, 32, 87, 104, 105, 115, 112, 101, 114, 32, 83, 121, 115, 116, 101, 109, 115, 49, 33, 48, 31, 6, 3,
251+
85, 4, 3, 12, 24, 97, 112, 105, 46, 100, 105, 114, 101, 99, 116, 111, 114, 121, 46, 115, 105, 103, 110, 97,
252+
108, 46, 111, 114, 103, 48, 130, 1, 34, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 130, 1,
253+
15, 0, 48, 130, 1, 10, 2, 130, 1, 1, 0, 207, 148, 23, 178, 30, 144, 63, 40, 29, 131, 2, 24, 243, 160, 155,
254+
162, 144, 64, 158, 14, 115, 28, 121, 39, 188, 61, 233, 95, 123, 206, 6, 75, 123, 25, 222, 136, 149, 159,
255+
137, 149, 239, 208, 21, 185, 90, 169, 49, 79, 78, 229, 63, 85, 125, 104, 79, 131, 136, 115, 150, 83, 53,
256+
190, 96, 252, 187, 202, 49, 48, 81, 204, 75, 30, 183, 208, 158, 78, 60, 121, 73, 52, 92, 153, 100, 101, 61,
257+
235, 183, 0, 147, 217, 100, 67, 175, 8, 125, 192, 55, 158, 70, 56, 232, 133, 240, 84, 41, 170, 129, 85, 34,
258+
20, 148, 21, 45, 123, 138, 228, 107, 222, 33, 139, 3, 66, 161, 159, 66, 39, 147, 74, 137, 162, 228, 46, 6,
259+
167, 235, 199, 192, 11, 250, 190, 93, 125, 55, 196, 170, 206, 44, 198, 148, 183, 226, 188, 114, 228, 207,
260+
51, 236, 122, 220, 115, 22, 221, 112, 17, 228, 53, 249, 255, 65, 18, 213, 138, 73, 179, 164, 82, 1, 134, 83,
261+
28, 119, 208, 188, 162, 186, 27, 199, 239, 89, 191, 87, 19, 179, 41, 123, 155, 222, 76, 107, 172, 230, 253,
262+
160, 21, 79, 89, 207, 124, 168, 189, 183, 174, 186, 145, 139, 238, 77, 236, 228, 122, 22, 206, 10, 195, 234,
263+
78, 225, 153, 138, 148, 60, 235, 109, 47, 90, 206, 40, 210, 238, 151, 250, 223, 73, 37, 246, 26, 76, 113,
264+
197, 148, 5, 62, 26, 230, 51, 9, 2, 3, 1, 0, 1, 163, 129, 161, 48, 129, 158, 48, 9, 6, 3, 85, 29, 19, 4, 2,
265+
48, 0, 48, 44, 6, 9, 96, 134, 72, 1, 134, 248, 66, 1, 13, 4, 31, 22, 29, 79, 112, 101, 110, 83, 83, 76, 32,
266+
71, 101, 110, 101, 114, 97, 116, 101, 100, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 48, 29,
267+
6, 3, 85, 29, 14, 4, 22, 4, 20, 175, 37, 18, 132, 74, 95, 181, 187, 172, 34, 86, 206, 227, 187, 79, 21, 81,
268+
214, 133, 47, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, 128, 20, 1, 139, 24, 241, 63, 251, 57, 25, 68, 110,
269+
133, 134, 190, 148, 101, 50, 167, 50, 60, 144, 48, 35, 6, 3, 85, 29, 17, 4, 28, 48, 26, 130, 24, 97, 112,
270+
105, 46, 100, 105, 114, 101, 99, 116, 111, 114, 121, 46, 115, 105, 103, 110, 97, 108, 46, 111, 114, 103, 48,
271+
13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 11, 5, 0, 3, 130, 1, 1, 0, 88, 26, 158, 239, 214, 185, 20, 229,
272+
114, 125, 141, 97, 3, 193, 26, 53, 75, 180, 85, 38, 191, 22, 124, 99, 69, 61, 187, 117, 96, 249, 248, 252,
273+
133, 121, 41, 11, 114, 13, 208, 201, 86, 178, 89, 138, 16, 129, 73, 77, 133, 9, 42, 149, 42, 190, 96, 143,
274+
186, 24, 239, 177, 165, 10, 10, 193, 117, 16, 38, 178, 119, 57, 122, 78, 222, 167, 65, 153, 156, 239, 135,
275+
169, 47, 16, 194, 166, 182, 194, 148, 207, 34, 44, 54, 82, 251, 74, 35, 81, 151, 69, 253, 241, 163, 79, 94,
276+
141, 158, 133, 50, 213, 164, 246, 6, 26, 69, 176, 132, 14, 100, 42, 140, 227, 72, 223, 214, 193, 214, 69,
277+
43, 47, 158, 136, 207, 187, 207, 205, 204, 117, 129, 185, 24, 237, 28, 163, 9, 252, 143, 100, 157, 169, 14,
278+
203, 10, 221, 222, 27, 67, 65, 220, 146, 105, 213, 62, 238, 236, 10, 70, 117, 255, 105, 212, 105, 190, 189,
279+
236, 98, 47, 248, 113, 30, 108, 30, 231, 250, 108, 9, 139, 233, 224, 129, 137, 158, 50, 78, 70, 19, 67, 75,
280+
15, 140, 1, 24, 10, 176, 182, 30, 196, 15, 125, 131, 29, 0, 243, 204, 90, 227, 37, 198, 4, 67, 38, 70, 19,
281+
247, 45, 124, 141, 191, 69, 92, 94, 177, 85, 254, 199, 132, 245, 144, 101, 73, 158, 202, 109, 44, 62, 199,
282+
77, 19, 107, 138, 4, 75, 168, 217, 134, 87, 198, 177 };
236283
}
237-
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
238284
}

0 commit comments

Comments
 (0)