1 package org.ejbca.core.protocol.ws.client; 2 3 import java.io.BufferedReader ; 4 import java.io.FileInputStream ; 5 import java.io.FileNotFoundException ; 6 import java.io.IOException ; 7 import java.io.InputStreamReader ; 8 import java.io.PrintStream ; 9 import java.net.URL ; 10 import java.util.Properties ; 11 12 import javax.xml.namespace.QName ; 13 14 import org.ejbca.core.model.ca.crl.RevokedCertInfo; 15 import org.ejbca.core.protocol.ws.client.gen.EjbcaWSService; 16 17 18 import org.ejbca.util.CertTools; 19 20 27 28 public abstract class EJBCAWSRABaseCommand { 29 30 protected String [] args = null; 31 private org.ejbca.core.protocol.ws.client.gen.EjbcaWS ejbcaraws = null; 32 private Properties props = null; 33 private String password = null; 34 35 36 protected static final String [] REASON_TEXTS ={"NOT REVOKED","UNSPECIFIED","KEYCOMPROMISE","CACOMPROMISE", 37 "AFFILIATIONCHANGED","SUPERSEDED","CESSATIONOFOPERATION", 38 "CERTIFICATEHOLD","REMOVEFROMCRL","PRIVILEGESWITHDRAWN", 39 "AACOMPROMISE"}; 40 41 public static final int NOT_REVOKED = RevokedCertInfo.NOT_REVOKED; 42 public static final int REVOKATION_REASON_UNSPECIFIED = RevokedCertInfo.REVOKATION_REASON_UNSPECIFIED; 43 public static final int REVOKATION_REASON_KEYCOMPROMISE = RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE; 44 public static final int REVOKATION_REASON_CACOMPROMISE = RevokedCertInfo.REVOKATION_REASON_CACOMPROMISE; 45 public static final int REVOKATION_REASON_AFFILIATIONCHANGED = RevokedCertInfo.REVOKATION_REASON_AFFILIATIONCHANGED; 46 public static final int REVOKATION_REASON_SUPERSEDED = RevokedCertInfo.REVOKATION_REASON_SUPERSEDED; 47 public static final int REVOKATION_REASON_CESSATIONOFOPERATION = RevokedCertInfo.REVOKATION_REASON_CESSATIONOFOPERATION; 48 public static final int REVOKATION_REASON_CERTIFICATEHOLD = RevokedCertInfo.REVOKATION_REASON_CERTIFICATEHOLD; 49 public static final int REVOKATION_REASON_REMOVEFROMCRL = RevokedCertInfo.REVOKATION_REASON_REMOVEFROMCRL; 50 public static final int REVOKATION_REASON_PRIVILEGESWITHDRAWN = RevokedCertInfo.REVOKATION_REASON_PRIVILEGESWITHDRAWN; 51 public static final int REVOKATION_REASON_AACOMPROMISE = RevokedCertInfo.REVOKATION_REASON_AACOMPROMISE; 52 53 protected static final int[] REASON_VALUES = {NOT_REVOKED,REVOKATION_REASON_UNSPECIFIED, 54 REVOKATION_REASON_KEYCOMPROMISE, REVOKATION_REASON_CACOMPROMISE, 55 REVOKATION_REASON_AFFILIATIONCHANGED, REVOKATION_REASON_SUPERSEDED, 56 REVOKATION_REASON_CESSATIONOFOPERATION, REVOKATION_REASON_CERTIFICATEHOLD, 57 REVOKATION_REASON_REMOVEFROMCRL, REVOKATION_REASON_PRIVILEGESWITHDRAWN, 58 REVOKATION_REASON_AACOMPROMISE}; 59 60 EJBCAWSRABaseCommand(String [] args){ 61 this.args = args; 62 } 63 64 71 protected org.ejbca.core.protocol.ws.client.gen.EjbcaWS getEjbcaRAWS() throws FileNotFoundException , IOException { 72 if(ejbcaraws == null){ 73 CertTools.installBCProvider(); 74 75 System.setProperty("javax.net.ssl.trustStore",getKeyStorePath()); 76 System.setProperty("javax.net.ssl.trustStorePassword",getKeyStorePassword()); 77 78 System.setProperty("javax.net.ssl.keyStore",getKeyStorePath()); 79 System.setProperty("javax.net.ssl.keyStorePassword",getKeyStorePassword()); 80 81 82 QName qname = new QName ("http://ws.protocol.core.ejbca.org/", "EjbcaWSService"); 83 EjbcaWSService service = new EjbcaWSService(new URL (getWebServiceURL()),qname); 84 ejbcaraws = service.getEjbcaWSPort(); 85 86 87 } 88 89 return ejbcaraws; 90 91 } 92 93 private String getKeyStorePassword() throws FileNotFoundException , IOException { 94 if(password == null){ 95 if(getProperties().getProperty("ejbcawsracli.keystore.password") == null){ 96 BufferedReader reader = new BufferedReader (new InputStreamReader (System.in)); 97 System.out.print("Enter keystore password :"); 98 password = reader.readLine(); 99 }else{ 100 password = getProperties().getProperty("ejbcawsracli.keystore.password"); 101 } 102 } 103 return password; 104 } 105 106 private String getKeyStorePath() throws FileNotFoundException , IOException { 107 return getProperties().getProperty("ejbcawsracli.keystore.path", "keystore.jks"); 108 } 109 110 private String getWebServiceURL() throws FileNotFoundException , IOException { 111 return getProperties().getProperty("ejbcawsracli.url", "https://localhost:8443/ejbca/ejbcaws/ejbcaws") + "?wsdl"; 112 } 113 114 private Properties getProperties() throws FileNotFoundException , IOException { 115 if(props == null){ 116 props = new Properties (); 117 try { 118 props.load(new FileInputStream ("ejbcawsracli.properties")); 119 } catch (FileNotFoundException e) { 120 props.load(new FileInputStream ("../ejbcawsracli.properties")); 122 } 123 } 124 return props; 125 } 126 127 protected PrintStream getPrintStream(){ 128 return System.out; 129 } 130 131 protected int getRevokeReason(String reason) throws Exception { 132 for(int i=0;i<REASON_TEXTS.length;i++){ 133 if(REASON_TEXTS[i].equalsIgnoreCase(reason)){ 134 return REASON_VALUES[i]; 135 } 136 } 137 getPrintStream().println("Error : Unsupported reason " + reason); 138 usage(); 139 System.exit(-1); 140 return 0; 141 } 142 143 protected String getRevokeReason(int reason) { 144 for(int i=0;i<REASON_VALUES.length;i++){ 145 if(REASON_VALUES[i]==reason){ 146 return REASON_TEXTS[i]; 147 } 148 } 149 getPrintStream().println("Error : Unsupported reason " + reason); 150 usage(); 151 System.exit(-1); 152 return null; 153 } 154 155 protected abstract void usage(); 156 157 } 158 | Popular Tags |