1 13 14 package org.ejbca.core.protocol.ws.client; 15 16 import java.math.BigInteger ; 17 18 import org.ejbca.core.model.ca.crl.RevokedCertInfo; 20 import org.ejbca.core.protocol.ws.client.gen.AuthorizationDeniedException_Exception; 21 import org.ejbca.core.protocol.ws.client.gen.RevokeStatus; 22 import org.ejbca.ui.cli.ErrorAdminCommandException; 24 import org.ejbca.ui.cli.IAdminCommand; 25 import org.ejbca.ui.cli.IllegalAdminCommandException; 26 import org.ejbca.util.CertTools; 27 28 33 public class CheckRevokeStatusCommand extends EJBCAWSRABaseCommand implements IAdminCommand{ 34 35 36 private static final int ARG_ISSUERDN = 1; 37 private static final int ARG_CERTSN = 2; 38 39 40 41 46 public CheckRevokeStatusCommand(String [] args) { 47 super(args); 48 } 49 50 56 public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException { 57 try { 58 59 if(args.length != 3){ 60 usage(); 61 System.exit(-1); 62 } 63 64 String issuerdn = CertTools.stringToBCDNString(args[ARG_ISSUERDN]); 65 String certsn = getCertSN(args[ARG_CERTSN]); 66 67 try{ 68 69 RevokeStatus status = getEjbcaRAWS().checkRevokationStatus(issuerdn,certsn); 70 if(status == null){ 71 getPrintStream().println("Error, No certificate found in database."); 72 }else{ 73 getPrintStream().println("Revokation status :"); 74 getPrintStream().println(" IssuerDN : " + status.getIssuerDN()); 75 getPrintStream().println(" CertificateSN : " + status.getCertificateSN()); 76 if(status.getReason() == RevokedCertInfo.NOT_REVOKED){ 77 getPrintStream().println(" Status : NOT REVOKED"); 78 }else{ 79 getPrintStream().println(" Status : REVOKED"); 80 getPrintStream().println(" Reason : " + getRevokeReason(status.getReason())); 81 getPrintStream().println(" Date : " + status.getRevocationDate().toString()); 82 } 83 } 84 }catch(AuthorizationDeniedException_Exception e){ 85 getPrintStream().println("Error : " + e.getMessage()); 86 } 87 } catch (Exception e) { 88 throw new ErrorAdminCommandException(e); 89 } 90 } 91 92 93 private String getCertSN(String certsn) { 94 try{ 95 new BigInteger (certsn,16); 96 }catch(NumberFormatException e){ 97 getPrintStream().println("Error in Certificate SN"); 98 usage(); 99 System.exit(-1); 100 } 101 return certsn; 102 } 103 104 protected void usage() { 105 getPrintStream().println("Command used check the status of certificate"); 106 getPrintStream().println("Usage : checkrevokationstatus <issuerdn> <certificatesn (HEX)> \n\n"); 107 108 } 109 110 111 } 112 | Popular Tags |