How to read SSL certificates?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • somebody

    How to read SSL certificates?

    I have several web servers with SSL certificates installed.
    My plan is to write a java program which will grab the certs
    via ftp, then read (parse) the certificate information.
    Ultimately what I want is the expiration date. I found an
    example of printing a cert (listed below), but get unresolved
    symbol errors when compiling. I thought I needed the Java
    Cryptography Extension (JCE), so I downloaded and installed
    that, but still get the error. What do I need to do in order
    to parse a Verisign certificate, in either .cer or .crt format?

    -Thanks


    import java.security.c ert.*;
    import java.io.*;

    public class PrintCert {
    public static void main(String args[]) {
    try {
    FileInputStream fr = new FileInputStream ("sdo.cer");
    X509Certificate c = X509Certificate .getInstance(fr );
    System.out.prin tln("Read in the following certificate:");
    System.out.prin tln("\tCertific ate for: " + c.getSubjectDN( ));
    System.out.prin tln("\tCertific ate issued by: " + c.getIssuerDN() );
    System.out.prin tln("\tThe certificate is valid from " +
    c.getNotBefore( ) + " to " + c.getNotAfter() );
    System.out.prin tln("\tCertific ate SN# " + c.getSerialNumb er());
    System.out.prin tln("\tGenerate d with " + c.getSigAlgName ());
    } catch (Exception e) {
    e.printStackTra ce();
    }
    }
    }


Working...