Skip to main content

Code to check SSL Client Certificate ...

Code to check SSL Client Certificate Expiration remotely

Language: C# (C Sharp) using MS Visual Studio Express 2010

Reference: System.Net.ServicePointManager, another sample code from stackOverflow

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Diagnostics;

namespace CertCheck
{
    class Program
    {
        static void Main(string[] args)
        {
            //Get URL from command line to check
            if (args.Length==0)
            {
                Console.WriteLine("Usage: CertCheck <https://url> [-v]");
                Console.WriteLine("Enter an url with https prefix");
                Console.WriteLine("Add -v for verbose output.  By default, this will print just the number of days on the console");
                return;
            }
            string https_url = args[0];
            bool bVerbose=false;
            if (args.Length > 1)
                if (args[1] == "-v")
                    bVerbose = true;
            HttpWebRequest http_req = null;

            //Define the Certificate Verification Callback method
            ServicePointManager.ServerCertificateValidationCallback = (state,cert,certChain,sslerr)=>
                {
                    DateTime certExpirationDate= DateTime.Parse(cert.GetExpirationDateString());
                    if (bVerbose)
                    {
                        Console.WriteLine("Certificate Expires in {0} days on {1}", certExpirationDate.Subtract(DateTime.Now).Days,certExpirationDate.ToShortDateString());
                        Console.WriteLine("Certificate Serial Number: {0}",cert.GetSerialNumberString());
                        Console.WriteLine("Certificate Issued to: {0}",cert.Subject);
                    }
                    else
                        Console.WriteLine(certExpirationDate.Subtract(DateTime.Now).Days);
                    return true;
                };
            //Connect to the URL to validate the certificate
            try
            {
                http_req=(HttpWebRequest)HttpWebRequest.Create(https_url);
                HttpWebResponse http_resp = (HttpWebResponse)http_req.GetResponse();
                http_resp.Close();
            }
            catch (Exception http_excep)
            {
                Debug.WriteLine("Error Checking site {0} : {1}",https_url,http_excep.ToString());
            }
        }
    }
}



Please feel free to modify the code to fit your needs.

Popular posts from this blog

Commands to restart RMC connection (t...

Commands to restart RMC connection (to HMC from LPAR) It has become very common with the IBM HMC to LPAR (logical/micro partition) communication to drop for unknown reasons.  Most of the time this is not a problem unless there is a need to do a dynamic logical partition operation (or DLAPR operation to add/remove resources on the fly).  This will become evident during the DLPAR operation when HMC complains about having no RMC connection to LPAR in operation.  When this happens run the following commands on the LPAR in question before reattemping the operation.  The DLPAR operation will still work with out this connection, but the LPAR needs a restart to see the change in the resources.  Restart the RMC connection on the LPAR: # /usr/sbin/rsct/install/bin/recfgct # /usr/sbin/rsct/bin/rmcctrl -p Verify the connection by running: lsrsrc IBM.ManagementServer This will show the HMC IP/hostname and the LPAR information.

HP-UX tape configuration

Here are few commands to configure tape drives in HP-UX 1.  Scan for new devices: # ioscan –fnC tape 2.  List tape drives currently recognized by the OS (without performing an actual hardware scan) # ioscan –fnkC tape 3.  remove all the special files used by the tape drives # rmsf  /dev/rmt/* 4.  Recreate the specil files for the tape drives # insf –C tape –e 5.  Remove a tape drive (that has a NO_HW state) # rmsf –H 0/7/1/0.1.24.255.5.5.0 Find the WWN for the HBAs: # ioscan –fnkC fc # fcmsutil /dev/fcd0 Find the WWN for the tape drives connected to the HBA: # fcmsutil /dev/fcd0 get remote all   **These are just a handful of commands to deal with the tape drives.  Not to be used as a procedure

Converting SEA on VIO from access to trunk mode

Shared Ethernet Adapters on VIO server can be configured in two different modes while accessing the external network. 1.  Simple mode 2. Trunk mode or 802.1Q mode In a Simple mode, the SEA is not aware of any VLAN information and bridges all the network packets to the external switch.  the external switch then determines the target and routes/discards it accordingly.  This is very useful when there is only one VLAN that needs to be serviced through the SEA to the LPARs using these VIO servers.  The configuration on the switch as well as the VIO (SEA) is simple and straight forward.  In a Trunk mode (802.1Q complaint), the SEA is aware of the VLANs and bridges only the packets that is part of the ‘Additional VLANs’ list.  The external switch then determines the target and routes/discards it accordingly.  This is very useful when there is a need to service multiple VLANs through the same SEA adapter.  This will provide the ability to create LPAR...