001: /*************************************************************************
002: * *
003: * EJBCA: The OpenSource Certificate Authority *
004: * *
005: * This software is free software; you can redistribute it and/or *
006: * modify it under the terms of the GNU Lesser General Public *
007: * License as published by the Free Software Foundation; either *
008: * version 2.1 of the License, or any later version. *
009: * *
010: * See terms of license at gnu.org. *
011: * *
012: *************************************************************************/package org.ejbca.ui.cli;
013:
014: import java.security.cert.X509Certificate;
015: import java.security.interfaces.RSAPublicKey;
016: import java.util.ArrayList;
017:
018: import org.ejbca.core.model.ca.caadmin.CAInfo;
019: import org.ejbca.util.CertTools;
020:
021: /**
022: * Gets and prints info about the CA.
023: *
024: * @version $Id: CaInfoCommand.java,v 1.3 2006/12/15 15:07:10 anatom Exp $
025: */
026: public class CaInfoCommand extends BaseCaAdminCommand {
027: /**
028: * Creates a new instance of CaInfoCommand
029: *
030: * @param args command line arguments
031: */
032: public CaInfoCommand(String[] args) {
033: super (args);
034: }
035:
036: /**
037: * Runs the command
038: *
039: * @throws IllegalAdminCommandException Error in command args
040: * @throws ErrorAdminCommandException Error running command
041: */
042: public void execute() throws IllegalAdminCommandException,
043: ErrorAdminCommandException {
044: if (args.length < 2) {
045: String msg = "Usage: CA info <caname>";
046: throw new IllegalAdminCommandException(msg);
047: }
048: try {
049: String caname = args[1];
050: ArrayList chain = new ArrayList(getCertChain(caname));
051: CAInfo cainfo = getCAInfo(caname);
052:
053: getOutputStream().println("CA name: " + caname);
054: getOutputStream().println("CA ID: " + cainfo.getCAId());
055: getOutputStream().println(
056: "CA CRL Expiration Period: "
057: + cainfo.getCRLPeriod());
058: getOutputStream().println(
059: "CA CRL Issue Interval: "
060: + cainfo.getCRLIssueInterval());
061: getOutputStream().println(
062: "CA Description: " + cainfo.getDescription());
063: getOutputStream().println("\n");
064:
065: if (chain.size() < 2)
066: getOutputStream().println("This is a Root CA.");
067: else
068: getOutputStream().println("This is a subordinate CA.");
069:
070: getOutputStream().println("Size of chain: " + chain.size());
071: if (chain.size() > 0) {
072: X509Certificate rootcert = (X509Certificate) chain
073: .get(chain.size() - 1);
074: getOutputStream().println(
075: "Root CA DN: "
076: + CertTools.getSubjectDN(rootcert));
077: getOutputStream().println(
078: "Root CA id: "
079: + CertTools.getSubjectDN(rootcert)
080: .hashCode());
081: getOutputStream().println(
082: "Certificate valid from: "
083: + rootcert.getNotBefore().toString());
084: getOutputStream().println(
085: "Certificate valid to: "
086: + rootcert.getNotAfter().toString());
087: getOutputStream().println(
088: "Root CA keysize: "
089: + ((RSAPublicKey) rootcert
090: .getPublicKey()).getModulus()
091: .bitLength());
092: for (int i = chain.size() - 2; i >= 0; i--) {
093: X509Certificate cacert = (X509Certificate) chain
094: .get(i);
095: getOutputStream().println(
096: "CA DN: " + CertTools.getSubjectDN(cacert));
097: getOutputStream().println(
098: "Certificate valid from: "
099: + cacert.getNotBefore().toString());
100: getOutputStream().println(
101: "Certificate valid to: "
102: + cacert.getNotAfter().toString());
103: getOutputStream().println(
104: "CA keysize: "
105: + ((RSAPublicKey) cacert
106: .getPublicKey())
107: .getModulus().bitLength());
108:
109: }
110: }
111: } catch (Exception e) {
112: throw new ErrorAdminCommandException(e);
113: }
114: } // execute
115: }
|