Skip to content

Commit 4bf541a

Browse files
committed
[System] Makes TLS providers linker friendly
1 parent b250b4a commit 4bf541a

4 files changed

Lines changed: 114 additions & 35 deletions

File tree

‎mcs/build/profiles/build.make‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ NO_TEST = yes
2222
NO_INSTALL = yes
2323

2424
FRAMEWORK_VERSION = 4.5
25+
MONO_FEATURE_APPLETLS=1
26+

‎mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.cs‎

Lines changed: 82 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -226,45 +226,79 @@ static void InitializeProviderRegistration ()
226226
providerRegistration = new Dictionary<string,Tuple<Guid,string>> ();
227227
providerCache = new Dictionary<Guid,MSI.MonoTlsProvider> ();
228228

229-
var appleTlsEntry = new Tuple<Guid,String> (AppleTlsId, "Mono.AppleTls.AppleTlsProvider");
229+
PopulateProviders ();
230+
}
231+
}
230232

231233
#if ONLY_APPLETLS || MONOTOUCH || XAMMAC
232-
providerRegistration.Add ("default", appleTlsEntry);
233-
providerRegistration.Add ("apple", appleTlsEntry);
234+
// TODO: Should be redundant
235+
static void PopulateProviders ()
236+
{
237+
var appleTlsEntry = new Tuple<Guid,String> (AppleTlsId, typeof (Mono.AppleTls.AppleTlsProvider).FullName);
238+
239+
providerRegistration.Add ("default", appleTlsEntry);
240+
providerRegistration.Add ("apple", appleTlsEntry);
241+
}
242+
#elif MONODROID
243+
// TODO: Should be redundant
244+
static void PopulateProviders ()
245+
{
246+
var legacyEntry = new Tuple<Guid,String> (LegacyId, typeof (Mono.Net.Security.LegacyTlsProvider).FullName);
247+
248+
providerRegistration.Add ("legacy", legacyEntry);
249+
250+
#if MONO_FEATURE_BTLS
251+
var btlsEntry = new Tuple<Guid,String> (BtlsId, typeof (Mono.Btls.MonoBtlsProvider).FullName);
252+
if (btlsEntry != null)
253+
providerRegistration.Add ("default", btlsEntry);
254+
else
255+
#endif
256+
providerRegistration.Add ("default", legacyEntry);
257+
}
234258
#else
235-
var legacyEntry = new Tuple<Guid,String> (LegacyId, "Mono.Net.Security.LegacyTlsProvider");
236-
providerRegistration.Add ("legacy", legacyEntry);
259+
static void PopulateProviders ()
260+
{
261+
#if MONO_FEATURE_APPLETLS
262+
var appleTlsEntry = new Tuple<Guid,String> (AppleTlsId, typeof (Mono.AppleTls.AppleTlsProvider).FullName);
263+
#endif
264+
var legacyEntry = new Tuple<Guid,String> (LegacyId, typeof (Mono.Net.Security.LegacyTlsProvider).FullName);
265+
providerRegistration.Add ("legacy", legacyEntry);
237266

238-
Tuple<Guid,String> btlsEntry = null;
267+
Tuple<Guid,String> btlsEntry = null;
239268
#if MONO_FEATURE_BTLS
240-
if (IsBtlsSupported ()) {
241-
btlsEntry = new Tuple<Guid,String> (BtlsId, "Mono.Btls.MonoBtlsProvider");
242-
providerRegistration.Add ("btls", btlsEntry);
243-
}
269+
if (IsBtlsSupported ()) {
270+
btlsEntry = new Tuple<Guid,String> (BtlsId, typeof (Mono.Btls.MonoBtlsProvider).FullName);
271+
providerRegistration.Add ("btls", btlsEntry);
272+
}
244273
#endif
245274

246-
if (Platform.IsMacOS)
247-
providerRegistration.Add ("default", appleTlsEntry);
248-
else if (btlsEntry != null)
249-
providerRegistration.Add ("default", btlsEntry);
250-
else
251-
providerRegistration.Add ("default", legacyEntry);
275+
#if MONO_FEATURE_APPLETLS
276+
if (Platform.IsMacOS)
277+
providerRegistration.Add ("default", appleTlsEntry);
278+
else
279+
#endif
280+
#if MONO_FEATURE_BTLS
281+
if (btlsEntry != null)
282+
providerRegistration.Add ("default", btlsEntry);
283+
else
284+
#endif
285+
providerRegistration.Add ("default", legacyEntry);
252286

253-
providerRegistration.Add ("apple", appleTlsEntry);
287+
#if MONO_FEATURE_APPLETLS
288+
providerRegistration.Add ("apple", appleTlsEntry);
254289
#endif
255-
}
256290
}
291+
#endif
257292

258-
#region Platform-Specific code
259293

260294
#if MONO_FEATURE_BTLS
261295
[MethodImpl (MethodImplOptions.InternalCall)]
262296
internal extern static bool IsBtlsSupported ();
263297
#endif
264298

265-
#if MONODROID
266299
static MSI.MonoTlsProvider CreateDefaultProviderImpl ()
267300
{
301+
#if MONODROID
268302
MSI.MonoTlsProvider provider = null;
269303
var type = Environment.GetEnvironmentVariable ("XA_TLS_PROVIDER");
270304
switch (type) {
@@ -281,24 +315,40 @@ static MSI.MonoTlsProvider CreateDefaultProviderImpl ()
281315
default:
282316
throw new NotSupportedException (string.Format ("Invalid TLS Provider: `{0}'.", provider));
283317
}
284-
}
318+
285319
#elif ONLY_APPLETLS || MONOTOUCH || XAMMAC
286-
static MSI.MonoTlsProvider CreateDefaultProviderImpl ()
287-
{
288320
return new AppleTlsProvider ();
289-
}
290321
#else
291-
static MSI.MonoTlsProvider CreateDefaultProviderImpl ()
292-
{
293-
var variable = Environment.GetEnvironmentVariable ("MONO_TLS_PROVIDER");
294-
if (string.IsNullOrEmpty (variable))
295-
variable = "default";
322+
var type = Environment.GetEnvironmentVariable ("MONO_TLS_PROVIDER");
323+
if (string.IsNullOrEmpty (type))
324+
type = "default";
296325

297-
return LookupProvider (variable, true);
298-
}
326+
switch (type) {
327+
case "default":
328+
#if MONO_FEATURE_APPLETLS
329+
if (Platform.IsMacOS)
330+
goto case "apple";
299331
#endif
332+
#if MONO_FEATURE_BTLS
333+
if (IsBtlsSupported ())
334+
goto case "btls";
335+
#endif
336+
goto case "legacy";
337+
#if MONO_FEATURE_APPLETLS
338+
case "apple":
339+
return new AppleTlsProvider ();
340+
#endif
341+
#if MONO_FEATURE_BTLS
342+
case "btls":
343+
return new MonoBtlsProvider ();
344+
#endif
345+
case "legacy":
346+
return new Mono.Net.Security.LegacyTlsProvider ();
347+
}
300348

301-
#endregion
349+
return LookupProvider (type, true);
350+
#endif
351+
}
302352

303353
#region Mono.Security visible API
304354

‎mcs/tools/linker/Makefile‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ PROGRAM = monolinker.exe
66

77
LIB_REFS = System System.Core System.Xml Mono.Cecil
88

9-
TEST_CASES = \
9+
TEST_CASES := \
1010
mscorlib/test-array.cs \
11-
mscorlib/test-remoting.cs
11+
mscorlib/test-remoting.cs \
12+
System/test-security.cs
1213

1314
ifndef AOT_FRIENDLY_PROFILE
1415
TEST_CASES += \
@@ -25,6 +26,9 @@ compile-tests: $(TEST_CASES)
2526
mscorlib/test-%.cs:
2627
$(TESTS_COMPILER) Tests/$@ /out:Tests/$(@:.cs=.exe)
2728

29+
System/test-%.cs:
30+
$(TESTS_COMPILER) -r:$(topdir)/class/lib/$(PROFILE_DIRECTORY)/System.dll Tests/$@ /out:Tests/$(@:.cs=.exe)
31+
2832
run-tests: $(TEST_CASES:.cs=.exe)
2933

3034
LINKER_OUTPUT := illink-output-$(PROFILE_DIRECTORY)
@@ -34,7 +38,7 @@ TEST_EXEC = MONO_PATH=$(LINKER_OUTPUT) $(RUNTIME) $(RUNTIME_FLAGS) --debug -O=-a
3438

3539
.NOTPARALLEL:
3640

37-
mscorlib/test-%.exe:
41+
System/test-%.exe mscorlib/test-%.exe:
3842
@rm -rf $(LINKER_OUTPUT)
3943
@mkdir $(LINKER_OUTPUT)
4044
@echo Testing $@
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Security;
2+
using System.Security.Cryptography.X509Certificates;
3+
4+
public class C
5+
{
6+
public static int Main ()
7+
{
8+
X509Certificate2 x509 = new X509Certificate2 ();
9+
10+
byte[] data = {
11+
0x30,0x82,0x01,0xFF,0x30,0x82,0x01,0x6C,0x02,0x05,0x02,0x72,0x00,0x06,0xE8,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,0x05,0x00,0x30,0x5F,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x20,0x30,0x1E,0x06,0x03,0x55,0x04,0x0A,0x13,0x17,0x52,0x53,0x41,0x20,0x44,0x61,0x74,0x61,0x20,0x53,0x65,0x63,0x75,0x72,0x69,0x74,0x79,0x2C,0x20,0x49,0x6E,0x63,0x2E,0x31,0x2E,0x30,0x2C,0x06,0x03,0x55,0x04,0x0B,0x13,0x25,0x53,0x65,0x63,0x75,0x72,0x65,0x20,0x53,0x65,0x72,0x76,
12+
0x65,0x72,0x20,0x43,0x65,0x72,0x74,0x69,0x66,0x69,0x63,0x61,0x74,0x69,0x6F,0x6E,0x20,0x41,0x75,0x74,0x68,0x6F,0x72,0x69,0x74,0x79,0x30,0x1E,0x17,0x0D,0x39,0x36,0x30,0x33,0x31,0x32,0x31,0x38,0x33,0x38,0x34,0x37,0x5A,0x17,0x0D,0x39,0x37,0x30,0x33,0x31,0x32,0x31,0x38,0x33,0x38,0x34,0x36,0x5A,0x30,0x61,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x08,0x13,0x0A,0x43,0x61,0x6C,0x69,0x66,0x6F,0x72,0x6E,0x69,0x61,0x31,0x14,0x30,0x12,0x06,0x03,
13+
0x55,0x04,0x0A,0x13,0x0B,0x43,0x6F,0x6D,0x6D,0x65,0x72,0x63,0x65,0x4E,0x65,0x74,0x31,0x27,0x30,0x25,0x06,0x03,0x55,0x04,0x0B,0x13,0x1E,0x53,0x65,0x72,0x76,0x65,0x72,0x20,0x43,0x65,0x72,0x74,0x69,0x66,0x69,0x63,0x61,0x74,0x69,0x6F,0x6E,0x20,0x41,0x75,0x74,0x68,0x6F,0x72,0x69,0x74,0x79,0x30,0x70,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,0x05,0x00,0x03,0x5F,0x00,0x30,0x5C,0x02,0x55,0x2D,0x58,0xE9,0xBF,0xF0,0x31,0xCD,0x79,0x06,0x50,0x5A,0xD5,0x9E,0x0E,0x2C,0xE6,0xC2,0xF7,0xF9,
14+
0xD2,0xCE,0x55,0x64,0x85,0xB1,0x90,0x9A,0x92,0xB3,0x36,0xC1,0xBC,0xEA,0xC8,0x23,0xB7,0xAB,0x3A,0xA7,0x64,0x63,0x77,0x5F,0x84,0x22,0x8E,0xE5,0xB6,0x45,0xDD,0x46,0xAE,0x0A,0xDD,0x00,0xC2,0x1F,0xBA,0xD9,0xAD,0xC0,0x75,0x62,0xF8,0x95,0x82,0xA2,0x80,0xB1,0x82,0x69,0xFA,0xE1,0xAF,0x7F,0xBC,0x7D,0xE2,0x7C,0x76,0xD5,0xBC,0x2A,0x80,0xFB,0x02,0x03,0x01,0x00,0x01,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,0x05,0x00,0x03,0x7E,0x00,0x54,0x20,0x67,0x12,0xBB,0x66,0x14,0xC3,0x26,0x6B,0x7F,
15+
0xDA,0x4A,0x25,0x4D,0x8B,0xE0,0xFD,0x1E,0x53,0x6D,0xAC,0xA2,0xD0,0x89,0xB8,0x2E,0x90,0xA0,0x27,0x43,0xA4,0xEE,0x4A,0x26,0x86,0x40,0xFF,0xB8,0x72,0x8D,0x1E,0xE7,0xB7,0x77,0xDC,0x7D,0xD8,0x3F,0x3A,0x6E,0x55,0x10,0xA6,0x1D,0xB5,0x58,0xF2,0xF9,0x0F,0x2E,0xB4,0x10,0x55,0x48,0xDC,0x13,0x5F,0x0D,0x08,0x26,0x88,0xC9,0xAF,0x66,0xF2,0x2C,0x9C,0x6F,0x3D,0xC3,0x2B,0x69,0x28,0x89,0x40,0x6F,0x8F,0x35,0x3B,0x9E,0xF6,0x8E,0xF1,0x11,0x17,0xFB,0x0C,0x98,0x95,0xA1,0xC2,0xBA,0x89,0x48,0xEB,0xB4,0x06,0x6A,0x22,0x54,
16+
0xD7,0xBA,0x18,0x3A,0x48,0xA6,0xCB,0xC2,0xFD,0x20,0x57,0xBC,0x63,0x1C };
17+
18+
19+
x509.Import (data);
20+
21+
return 0;
22+
}
23+
}

0 commit comments

Comments
 (0)