.net - Determine SSL Certificate Expiration Date IIS -
I have to schedule the expiry date of the SSL certificates on my IIS box, ideally I want to do it in C # , But if the VB script is the only way which is also acceptable
environment => IIS version 6 & amp; 7, .NET 2.0, Windows 2003 & amp; 2008
thanks
I'm not familiar with one way to do this investigation I am VBS and / or WMI, which is probably a security because it might possibly expose the private key, however, there is a way to take advantage of a common HTTPS connection to obtain public information about the certificate. If you connect to any secure web site using IE, you can go to the File menu and view the properties and then click on the certificate button. This shows a public certificate information dialog for the site. You can use this information program to use C #.
Basically, what you have to do is open a TCP connection to the server on port 443 and then get SSL data. This data stream contains public information about the certificate and you can validate it and remove all your required information from that time, including the expiration date. Here is some sample code:
Fixed zero main (string [] ARG) {foreach (string in ARG in string) {Console.WriteLine ("\ n \ nFetching SSL cert {0} \ N ", server name); TcpClient Client = new TcpClient (server name, 443); SSLstream SSL stream = new SSL stream (client gatestream (false, callback, empty); Try {SslStream.AuthenticateAsClient (servername); } Hold (authentication exceptions) {Console.WriteLine ("exception: {0}", prior.); If (ex.InnerException! = Null) {Console.WriteLine ("Inner exception: {0}", ex.InnerException.Message); } Console.WriteLine ("Authentication failed - connection closed."); } Client.Close (); }} and code for callback that handles the information of the certificate:
Fixed remote certificate certificate verification callback = delegate (object sender, X509 certificate Certificate, X509 chain chain, SSL policies, SslError) {X509 certificate 2 x509 = new X50 9 certificate certification 2 (certification); // To consolidate the information contained in the certificate, print the console. Light line ("subject: {0}", x509.Subject); Console.light line ("Issuer: {0}", x509.Issuer); Console.lightline ("version: {0}", x509.wersian); Console.light line ("valid date: {0}", x509. not before); Console.light line ("end date: {0}", x509.Now); Console.light line ("thumbprint: {0}", x509. thumbprint); Console.light line ("serial number: {0}", x509.SerialNumber); Console.lightline ("friendly name: {0}", x509.PublicKey.Oid.FriendlyName); Console.light line ("public key format: {0}", x509. public K. encoded by format (true)); Console.lightline ("raw data length: {0}", x509.RawData.Length); If (sslError! = SslPolicyErrors.None) {Console.WriteLine ("Certificate Error:" + sslError); } return false; }; And the good part is that this approach should technically work with any webserver ... I have tested only on IIS 6 and 7.
Comments
Post a Comment