Skip to content

Commit

Permalink
Merge pull request #255 from MediaPortal/MP1-5195-Set_higher_TLS_secu…
Browse files Browse the repository at this point in the history
…rity_for_NET_Framework_4

MP1-5195: Set higher TLS security for NET Framework 4
  • Loading branch information
andrewjswan authored Jan 19, 2024
2 parents 89117ae + ffbdbeb commit 8d28d2e
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 9 deletions.
15 changes: 14 additions & 1 deletion Tools/MediaPortal.DeployTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ internal static class Program
private static void Main()
{
// .NET 4.0: Use TLS v1.2. Many download sources no longer support the older and now insecure TLS v1.0/1.1 and SSL v3.
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
try
{
//TLS 1.2 and 1.3
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00 | (SecurityProtocolType)0x3000;
}
catch (NotSupportedException)
{
//TLS 1.2 only
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
}

//Set TLS Schannel to higher security
Utils.SetHigherNetFramework4TlsSecurity();

if (Utils.CheckStartupPath())
{
Application.EnableVisualStyles();
Expand Down
24 changes: 24 additions & 0 deletions Tools/MediaPortal.DeployTool/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,30 @@ public static void FixMediaPortal64RegistryPath(string strName)
}
}

/// <summary>
/// Set higher TLS security for NET 4.0 applications by using 'SchUseStrongCrypto' registry key
/// </summary>
public static void SetHigherNetFramework4TlsSecurity()
{
//https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls
//Setting registry keys affects all applications on the system.
//A value of 1 causes your app to use strong cryptography.
//The strong cryptography uses more secure network protocols (TLS 1.2 and TLS 1.1) and blocks protocols that aren't secure.
//This registry setting affects only client (outgoing) connections in your application.

const string PATH = @"SOFTWARE\Microsoft\.NETFramework\v4.0.30319";
const string KEY_VALUE_NAME = "SchUseStrongCrypto";

RegistryKey key = Registry.LocalMachine.OpenSubKey(PATH, true);
if (key == null)
key = Registry.LocalMachine.CreateSubKey(PATH);

if ((int)key.GetValue(KEY_VALUE_NAME, 0) == 0)
key.SetValue(KEY_VALUE_NAME, 1);

key.Close();
}

#endregion
}
}
11 changes: 10 additions & 1 deletion TvEngine3/TVLibrary/SetupTv/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ public static void Application_ThreadException(object sender, ThreadExceptionEve
public static void Main(string[] arguments)
{
// .NET 4.0: Use TLS v1.2. Many download sources no longer support the older and now insecure TLS v1.0/1.1 and SSL v3.
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
try
{
//TLS 1.2 and 1.3
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00 | (SecurityProtocolType)0x3000;
}
catch (NotSupportedException)
{
//TLS 1.2 only
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
}
// Init Common logger -> this will enable TVPlugin to write in the Mediaportal.log file
var loggerName = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]);
var dataPath = Log.GetPathName();
Expand Down
11 changes: 10 additions & 1 deletion TvEngine3/TVLibrary/TvService/Service1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,16 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
private static void Main(string[] args)
{
// .NET 4.0: Use TLS v1.2. Many download sources no longer support the older and now insecure TLS v1.0/1.1 and SSL v3.
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
try
{
//TLS 1.2 and 1.3
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00 | (SecurityProtocolType)0x3000;
}
catch (NotSupportedException)
{
//TLS 1.2 only
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
}
// Init Common logger -> this will enable TVPlugin to write in the Mediaportal.log file
var loggerName = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]);
var dataPath = Log.GetPathName();
Expand Down
11 changes: 10 additions & 1 deletion mediaportal/Configuration/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,16 @@ public static void Main(string[] arguments)
try
{
// .NET 4.0: Use TLS v1.2. Many download sources no longer support the older and now insecure TLS v1.0/1.1 and SSL v3.
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
try
{
//TLS 1.2 and 1.3
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00 | (SecurityProtocolType)0x3000;
}
catch (NotSupportedException)
{
//TLS 1.2 only
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
}
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
Application.EnableVisualStyles();
Application.DoEvents();
Expand Down
11 changes: 10 additions & 1 deletion mediaportal/Core/Util/HtmlToText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,16 @@ public class HtmlToText
public static void Main(string[] args)
{
// .NET 4.0: Use TLS v1.2. Many download sources no longer support the older and now insecure TLS v1.0/1.1 and SSL v3.
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
try
{
//TLS 1.2 and 1.3
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00 | (SecurityProtocolType)0x3000;
}
catch (NotSupportedException)
{
//TLS 1.2 only
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
}
Thread.CurrentThread.Name = "HtmlToText";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]);
try
Expand Down
11 changes: 10 additions & 1 deletion mediaportal/MPE/MpeInstaller/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ internal static class Program
private static void Main(string[] args)
{
// .NET 4.0: Use TLS v1.2. Many download sources no longer support the older and now insecure TLS v1.0/1.1 and SSL v3.
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
try
{
//TLS 1.2 and 1.3
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00 | (SecurityProtocolType)0x3000;
}
catch (NotSupportedException)
{
//TLS 1.2 only
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length > 0)
Expand Down
11 changes: 10 additions & 1 deletion mediaportal/MPE/MpeMaker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ internal static class Program
private static void Main(string[] args)
{
// .NET 4.0: Use TLS v1.2. Many download sources no longer support the older and now insecure TLS v1.0/1.1 and SSL v3.
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
try
{
//TLS 1.2 and 1.3
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00 | (SecurityProtocolType)0x3000;
}
catch (NotSupportedException)
{
//TLS 1.2 only
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length > 0)
Expand Down
11 changes: 10 additions & 1 deletion mediaportal/MediaPortal.Application/MediaPortal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,16 @@ public static void Main(string[] args)
//Application.ApplicationExit += new EventHandler(Application_ApplicationExit);

// .NET 4.0: Use TLS v1.2. Many download sources no longer support the older and now insecure TLS v1.0/1.1 and SSL v3.
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
try
{
//TLS 1.2 and 1.3
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00 | (SecurityProtocolType)0x3000;
}
catch (NotSupportedException)
{
//TLS 1.2 only
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
}

using (Settings xmlreader = new MPSettings())
{
Expand Down
11 changes: 10 additions & 1 deletion mediaportal/PostSetup/MPRecommendations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,16 @@ private void InitializeComponent()
private static void Main(string[] args)
{
// .NET 4.0: Use TLS v1.2. Many download sources no longer support the older and now insecure TLS v1.0/1.1 and SSL v3.
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
try
{
//TLS 1.2 and 1.3
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00 | (SecurityProtocolType)0x3000;
}
catch (NotSupportedException)
{
//TLS 1.2 only
ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xc00;
}
Application.Run(new MPRecommendations(args));
}

Expand Down

0 comments on commit 8d28d2e

Please sign in to comment.