diff options
Diffstat (limited to 'pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java')
-rw-r--r-- | pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java b/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java index 84cc54cbe..671a175f7 100644 --- a/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java +++ b/pki/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmstools; - import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.FileInputStream; @@ -36,41 +35,41 @@ import netscape.security.x509.X500Name; import netscape.security.x509.X509CertImpl; import netscape.security.x509.X509CertInfo; - /** * The PrettyPrintCert class is a utility program designed to "pretty print" - * a certificate. It assumes that the name of a data file is passed to the + * a certificate. It assumes that the name of a data file is passed to the * program via the command line, and that the contents contain a certificate - * encoded in an ASCII BASE 64 format. Note that the data file may contain + * encoded in an ASCII BASE 64 format. Note that the data file may contain * an optional "-----BEGIN" header and/or an optional "-----END" trailer. - * + * * <P> * The program may be invoked as follows: + * * <PRE> - * + * * PrettyPrintCert <input filename> [output filename] - * + * * NOTE: <input filename> must contain an ASCII * BASE 64 encoded certificate - * + * * <output filename> contains a certificate displayed * in a "pretty print" ASCII format * </PRE> - * + * * @version $Revision$, $Date$ */ public class PrettyPrintCert { // Define constants - public static final int ARGC = 2; + public static final int ARGC = 2; public static final String HEADER = "-----BEGIN"; public static final String TRAILER = "-----END"; public static void usageAndExit() { System.out.println("Usage: PrettyPrintCert " + - "[options] " + - "<input filename> " + - "[output filename]"); + "[options] " + + "<input filename> " + + "[output filename]"); System.out.println("\n options: "); System.out.println(" -simpleinfo : prints limited cert info in easy to parse format"); System.exit(0); @@ -87,7 +86,7 @@ public class PrettyPrintCert { CertPrettyPrint certDetails = null; String pp = new String(); FileOutputStream outputCert = null; - boolean mSimpleInfo = false; + boolean mSimpleInfo = false; String inputfile = null; String outputfile = null; @@ -130,18 +129,18 @@ public class PrettyPrintCert { if (inputfile == null) { usageAndExit(); } - + // (2) Create a DataInputStream() object to the BASE 64 // encoded certificate contained within the file // specified on the command line try { inputCert = new BufferedReader(new InputStreamReader( new BufferedInputStream( - new FileInputStream( - inputfile)))); + new FileInputStream( + inputfile)))); } catch (FileNotFoundException e) { System.out.println("PrettyPrintCert: can't find file " + - inputfile + ":\n" + e); + inputfile + ":\n" + e); return; } @@ -152,14 +151,14 @@ public class PrettyPrintCert { try { while ((encodedBASE64CertChunk = inputCert.readLine()) != null) { if (!(encodedBASE64CertChunk.startsWith(HEADER)) && - !(encodedBASE64CertChunk.startsWith(TRAILER))) { + !(encodedBASE64CertChunk.startsWith(TRAILER))) { encodedBASE64Cert += encodedBASE64CertChunk.trim(); } } } catch (IOException e) { System.out.println("PrettyPrintCert: Unexpected BASE64 " + - "encoded error encountered in readLine():\n" + - e); + "encoded error encountered in readLine():\n" + + e); } // (4) Close the DataInputStream() object @@ -167,9 +166,9 @@ public class PrettyPrintCert { inputCert.close(); } catch (IOException e) { System.out.println("PrettyPrintCert: Unexpected BASE64 " + - "encoded error encountered in close():\n" + e); + "encoded error encountered in close():\n" + e); } - + // (5) Decode the ASCII BASE 64 certificate enclosed in the // String() object into a BINARY BASE 64 byte[] object @@ -181,19 +180,19 @@ public class PrettyPrintCert { cert = new X509CertImpl(decodedBASE64Cert); } catch (CertificateException e) { System.out.println("PrettyPrintCert: Error encountered " + - "on parsing certificate :\n" + e); + "on parsing certificate :\n" + e); } if (mSimpleInfo) { try { X509CertInfo certinfo = (X509CertInfo) cert.get("x509.INFO"); - + CertificateSubjectName csn = (CertificateSubjectName) - certinfo.get(X509CertInfo.SUBJECT); + certinfo.get(X509CertInfo.SUBJECT); Enumeration en = csn.getElements(); - X500Name dname = (X500Name) csn.get(CertificateSubjectName.DN_NAME); + X500Name dname = (X500Name) csn.get(CertificateSubjectName.DN_NAME); pp = ""; RDN[] rdns = dname.getNames(); @@ -201,14 +200,14 @@ public class PrettyPrintCert { for (int i = rdns.length - 1; i >= 0; i--) { pp = pp + rdns[i] + "\n"; } - - } catch (Exception e) { + + } catch (Exception e) { System.out.println("ERROR"); e.printStackTrace(); - } + } } else { // (7) For this utility, always specify the default Locale - aLocale = Locale.getDefault(); + aLocale = Locale.getDefault(); // (8) Create a CertPrettyPrint() object certDetails = new CertPrettyPrint(cert); @@ -226,7 +225,7 @@ public class PrettyPrintCert { outputCert = new FileOutputStream(outputfile); } catch (Exception e) { System.out.println("PrettyPrintCert: unable to open file " + - argv[1] + " for writing:\n" + e); + argv[1] + " for writing:\n" + e); return; } @@ -234,18 +233,17 @@ public class PrettyPrintCert { outputCert.write(pp.getBytes()); } catch (IOException e) { System.out.println("PrettyPrintCert: Unexpected error " + - "encountered while attempting to write() " + - outputfile + ":\n" + e); + "encountered while attempting to write() " + + outputfile + ":\n" + e); } try { outputCert.close(); } catch (IOException e) { System.out.println("PrettyPrintCert: Unexpected error " + - "encountered while attempting to close() " + - outputfile + ":\n" + e); + "encountered while attempting to close() " + + outputfile + ":\n" + e); } } } } - |