i am looking to get the data from any given domain names SSL certificate. For example I want to put in any website address e.g. "http://stackoverflow.com" and my code would firstly check if an SSL certificate exists. If it does then I want it to pull out the expiry date of the certificate. [ i am reading Domainnames from DB ] Example :http://www.digicert.com/help/
i need to create a web service to check expiry date. how can i implement it?? - I have looked up loads of different things such as RequestCertificateValidationCallback and ClientCertificates etc.
I could be completely wrong (hence why I need help) but would I create a HTTPWebRequest and then somehow request the client certificate and specific elements that way?
i tried the example provided @SSL certificate pre-fetch .NET , but i am getting forbitten 403 error.
For this to work your project will need a reference to
System.Security
:.Net Core 2.1
You can use HttpClientHandler and ServerCertificateCustomValidationCallback Property. (This class is available in .net 4.7.1 and above also).
@cdev's solution didn't work for me on .NET Core 2.1. It seems
HttpWebRequest
is not completely supported on .NET Core.Here is the function I'm using on .NET Core to get any server's X509 certificate:
One thing to note is that you might need to set
request.AllowAutoRedirect = False
. Otherwise, if the server redirects HTTPS to HTTP, you won't be able to get the certificate from theHttpWebRequest
object.