From 4823e610155da295c4c42dc368a0acc6823b2ab3 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Tue, 7 Mar 2017 11:50:50 +0100 Subject: [PATCH] Check for BTLS support before using it --- src/Jackett/JackettModule.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Jackett/JackettModule.cs b/src/Jackett/JackettModule.cs index 1bfc45ed6..484e726b5 100644 --- a/src/Jackett/JackettModule.cs +++ b/src/Jackett/JackettModule.cs @@ -55,7 +55,27 @@ namespace Jackett var monoVersionO = new Version(monoVersion.Split(' ')[0]); if (monoVersionO.Major >= 4 && monoVersionO.Minor >= 8) { - usehttpclient = true; + // check if btls is supported + var monoSecurity = Assembly.Load("Mono.Security"); + Type monoTlsProviderFactory = monoSecurity.GetType("Mono.Security.Interface.MonoTlsProviderFactory"); + if (monoTlsProviderFactory != null) + { + MethodInfo isProviderSupported = monoTlsProviderFactory.GetMethod("IsProviderSupported"); + if(isProviderSupported != null) + { + var btlsSupported = (bool)isProviderSupported.Invoke(null, new string[] { "btls" }); + if (btlsSupported) + { + // initialize btls + MethodInfo initialize = monoTlsProviderFactory.GetMethod("Initialize", new[] { typeof(string) }); + if (initialize != null) + { + initialize.Invoke(null, new string[] { "btls" }); + usehttpclient = true; + } + } + } + } } } }