1 13 14 package org.ejbca.ui.cli; 15 16 import java.io.FileInputStream ; 17 import java.security.cert.X509Certificate ; 18 import java.util.Collection ; 19 import java.util.Iterator ; 20 21 import org.bouncycastle.asn1.ASN1InputStream; 22 import org.bouncycastle.asn1.DERObject; 23 import org.bouncycastle.asn1.util.ASN1Dump; 24 import org.ejbca.util.CertTools; 25 26 27 32 public class Asn1Dump extends BaseCommand { 33 34 public Asn1Dump(String [] args) { 35 this.args = args; 36 } 37 38 43 public static void main(String [] args) { 44 try { 45 if (args.length == 1) { 46 Asn1Dump d = new Asn1Dump(args); 47 d.execute(); 48 } else { 49 System.out.println( 50 "Usage: asn1dump filename-of-pem-encoded-certs||filename-of-der-encoded-asn1"); 51 } 52 } catch (Exception e) { 53 System.out.println(e.getMessage()); 54 System.exit(-1); 56 } 57 } 58 59 public void execute() throws ErrorAdminCommandException { 60 try { 61 String filename = args[0]; 62 boolean iscert = true; 63 Collection coll = null; 64 CertTools.installBCProvider(); 65 try { 66 coll = CertTools.getCertsFromPEM(filename); 67 if (coll.isEmpty()) { 68 iscert = false; 69 } 70 } catch (Exception e) { 71 iscert = false; 72 } 73 if (!iscert) { 74 ASN1InputStream ais = new ASN1InputStream(new FileInputStream (filename)); 75 DERObject obj = ais.readObject(); 76 String dump = ASN1Dump.dumpAsString(obj); 77 getOutputStream().println(dump); 78 } else { 79 Iterator iter = coll.iterator(); 80 while (iter.hasNext()) { 81 X509Certificate cert = (X509Certificate )iter.next(); 82 String dump = ASN1Dump.dumpAsString(cert); 83 getOutputStream().println(dump); 84 } 85 } 86 } catch (Exception e) { 87 throw new ErrorAdminCommandException(e); 88 } 89 90 } 91 } 92 93 94 | Popular Tags |