Skip to content

Instantly share code, notes, and snippets.

@ridomin
Created January 10, 2018 03:20
Show Gist options
  • Select an option

  • Save ridomin/9c27e758ee5b2f665efa96f6ea66efd8 to your computer and use it in GitHub Desktop.

Select an option

Save ridomin/9c27e758ee5b2f665efa96f6ea66efd8 to your computer and use it in GitHub Desktop.
SSLInspector
namespace SSLInspector
{
using System;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Url to query (https://nuget.org is default)");
var url = Console.ReadLine();
if (url == string.Empty) url = "https://www.nuget.org";
new Program().Run(url).Wait();
Console.ReadLine();
}
async Task Run(string url)
{
HttpClientHandler httpClientHandler = new HttpClientHandler();
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
{
chain.Build(cert);
foreach (var item in chain.ChainElements)
{
Console.WriteLine(item.Certificate.PrintCert());
Console.WriteLine();
}
Console.WriteLine("Errors: " + errors);
return true;
};
HttpClient http = new HttpClient(httpClientHandler);
var x = await http.GetAsync(url);
Console.WriteLine(x.StatusCode);
}
}
public static class CertExtensions
{
public static string PrintCert(this X509Certificate2 cert)
{
return $"{cert.SubjectName.Name} ({cert.GetSerialNumberString()}) by {cert.IssuerName.Name}";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment