Skip to content

Instantly share code, notes, and snippets.

@deepumi
Last active April 9, 2018 11:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepumi/49a4cc98d0908674049a64513e54156d to your computer and use it in GitHub Desktop.
Save deepumi/49a4cc98d0908674049a64513e54156d to your computer and use it in GitHub Desktop.
Stripe TLS 1.2 integration. Sample code to ensure TLS 1.2 support in OS, library and framework level using C# HttpClient
//No third party library required for this code.
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
internal static class Stripe
{
internal static async Task<string> DoesTLS12Support()
{
const string apiEndPoint = "https:api-tls12.stripe.com/v1/charges";
string result = "TLS 1.2 supported, no action required.";
try
{
var handler = new HttpClientHandler
{
Credentials = new NetworkCredential { UserName = "REPLACE_WITH_YOUR_SECRET_KEY" },
PreAuthenticate = true
};
using (var client = new HttpClient(handler))
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, apiEndPoint)).ConfigureAwait(false);
await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
}
catch (System.Exception)
{
result = "TLS 1.2 is not supported. You will need to upgrade your integration.";
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment