1 13 14 package org.ejbca.ui.cli; 15 16 import java.security.cert.X509Certificate ; 17 import java.security.interfaces.RSAPublicKey ; 18 import java.util.ArrayList ; 19 20 import org.ejbca.core.model.ca.caadmin.CAInfo; 21 import org.ejbca.util.CertTools; 22 23 24 25 30 public class CaInfoCommand extends BaseCaAdminCommand { 31 36 public CaInfoCommand(String [] args) { 37 super(args); 38 } 39 40 46 public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException { 47 if (args.length < 2) { 48 String msg = "Usage: CA info <caname>"; 49 throw new IllegalAdminCommandException(msg); 50 } 51 try { 52 String caname = args[1]; 53 ArrayList chain = new ArrayList (getCertChain(caname)); 54 CAInfo cainfo = getCAInfo(caname); 55 56 getOutputStream().println("CA name: " + caname); 57 getOutputStream().println("CA ID: " + cainfo.getCAId()); 58 getOutputStream().println("CA CRL Expiration Period: " + cainfo.getCRLPeriod()); 59 getOutputStream().println("CA CRL Issue Interval: " + cainfo.getCRLIssueInterval()); 60 getOutputStream().println("CA Description: " + cainfo.getDescription()); 61 getOutputStream().println("\n"); 62 63 if (chain.size() < 2) 64 getOutputStream().println("This is a Root CA."); 65 else 66 getOutputStream().println("This is a subordinate CA."); 67 68 getOutputStream().println("Size of chain: " + chain.size()); 69 if (chain.size() > 0) { 70 X509Certificate rootcert = (X509Certificate )chain.get(chain.size()-1); 71 getOutputStream().println("Root CA DN: "+CertTools.getSubjectDN(rootcert)); 72 getOutputStream().println("Root CA id: "+CertTools.getSubjectDN(rootcert).hashCode()); 73 getOutputStream().println("Certificate valid from: "+rootcert.getNotBefore().toString()); 74 getOutputStream().println("Certificate valid to: "+rootcert.getNotAfter().toString()); 75 getOutputStream().println("Root CA keysize: "+((RSAPublicKey )rootcert.getPublicKey()).getModulus().bitLength()); 76 for(int i = chain.size()-2; i>=0; i--){ 77 X509Certificate cacert = (X509Certificate )chain.get(i); 78 getOutputStream().println("CA DN: "+CertTools.getSubjectDN(cacert)); 79 getOutputStream().println("Certificate valid from: "+cacert.getNotBefore().toString()); 80 getOutputStream().println("Certificate valid to: "+cacert.getNotAfter().toString()); 81 getOutputStream().println("CA keysize: "+((RSAPublicKey )cacert.getPublicKey()).getModulus().bitLength()); 82 83 } 84 } 85 } catch (Exception e) { 86 throw new ErrorAdminCommandException(e); 87 } 88 } } | Popular Tags |