Last active
June 17, 2019 22:17
-
-
Save klpatil/3609fe2ea400a0b38b6203718106f309 to your computer and use it in GitHub Desktop.
To check TLS version at .NET APP level
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" AutoEventWireup="true" %> | |
<%@ Import Namespace="Sitecore.Configuration" %> | |
<%@ Import Namespace="System.Web" %> | |
<%@ Import Namespace="System.Net" %> | |
<% | |
/* https://stackoverflow.com/questions/28286086/default-securityprotocol-in-net-4-5 */ | |
// print initial status | |
Response.Write("Runtime: " + System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(int).Assembly.Location).ProductVersion); | |
Response.Write("<br/>"); | |
Response.Write("Enabled protocols: " + ServicePointManager.SecurityProtocol); | |
Response.Write("<br/>"); | |
Console.WriteLine("Available protocols: "); | |
Boolean platformSupportsTls12 = false; | |
foreach (SecurityProtocolType protocol in Enum.GetValues(typeof(SecurityProtocolType))) { | |
Response.Write(protocol.GetHashCode()); | |
if (protocol.GetHashCode() == 3072){ | |
platformSupportsTls12 = true; | |
} | |
} | |
Response.Write("Is Tls12 enabled: " + ServicePointManager.SecurityProtocol.HasFlag((SecurityProtocolType)3072)); | |
Response.Write("<br/>"); | |
/* | |
// enable Tls12, if possible | |
if (!ServicePointManager.SecurityProtocol.HasFlag((SecurityProtocolType)3072)){ | |
if (platformSupportsTls12){ | |
Console.WriteLine("Platform supports Tls12, but it is not enabled. Enabling it now."); | |
ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072; | |
} else { | |
Console.WriteLine("Platform does not supports Tls12."); | |
} | |
} | |
// disable ssl3 | |
if (ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Ssl3)) { | |
Console.WriteLine("Ssl3SSL3 is enabled. Disabling it now."); | |
// disable SSL3. Has no negative impact if SSL3 is already disabled. The enclosing "if" if just for illustration. | |
System.Net.ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3; | |
} | |
*/ | |
Response.Write("Enabled protocols: " + ServicePointManager.SecurityProtocol); | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment