.Net console application to get the site certificate to validate and show cert info.
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Security;
namespace CertValidate
{
class Program
{
static void Main(string[] args)
{
while (true) {
Console.WriteLine("Enter Full URL");
CheckSite(Console.ReadLine());
}
}
public static void CheckSite(string URL) {
HttpWebRequest request = WebRequest.CreateHttp(URL);
request.ServerCertificateValidationCallback += ServerCertificateValidationCallback;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { }
Console.WriteLine("End.");
}
private static bool ServerCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
{
Console.WriteLine("Certificate OK");
Console.WriteLine(certificate.ToString());
return true;
}
else
{
Console.WriteLine("Certificate ERROR");
return false;
}
}
}
}
No comments:
Post a Comment