1 13 14 package org.ejbca.core.protocol.ws.client; 15 16 import java.math.BigInteger ; 17 18 19 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; 23 import org.ejbca.ui.cli.IAdminCommand; 24 import org.ejbca.ui.cli.IllegalAdminCommandException; 25 import org.ejbca.util.CertTools; 26 27 32 public class RevokeCertCommand extends EJBCAWSRABaseCommand implements IAdminCommand{ 33 34 35 private static final int ARG_ISSUERDN = 1; 36 private static final int ARG_CERTSN = 2; 37 private static final int ARG_REASON = 3; 38 39 40 45 public RevokeCertCommand(String [] args) { 46 super(args); 47 } 48 49 55 public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException { 56 57 try { 58 59 if(args.length != 4){ 60 usage(); 61 System.exit(-1); 62 } 63 64 String issuerdn = CertTools.stringToBCDNString(args[ARG_ISSUERDN]); 65 String certsn = getCertSN(args[ARG_CERTSN]); 66 int reason = getRevokeReason(args[ARG_REASON]); 67 68 if(reason == RevokedCertInfo.NOT_REVOKED){ 69 getPrintStream().println("Error : Unsupported reason " + reason); 70 usage(); 71 System.exit(-1); 72 } 73 74 try{ 75 76 RevokeStatus status = getEjbcaRAWS().checkRevokationStatus(issuerdn,certsn); 77 if(status.getReason() != RevokedCertInfo.NOT_REVOKED){ 78 getPrintStream().println("Error : Certificate is already revoked"); 79 System.exit(-1); 80 } 81 82 getEjbcaRAWS().revokeCert(issuerdn,certsn,reason); 83 getPrintStream().println("Certificate revoked sucessfully"); 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 to revoke a certificate"); 106 getPrintStream().println("Usage : revokecert <issuerdn> <certificatesn (HEX)> <reason> \n\n"); 107 getPrintStream().println("Reason should be one of : "); 108 for(int i=1; i< REASON_TEXTS.length-1;i++){ 109 getPrintStream().print(REASON_TEXTS[i] + ", "); 110 } 111 getPrintStream().print(REASON_TEXTS[REASON_TEXTS.length-1]); 112 } 113 114 115 } 116 | Popular Tags |