I'm having a problem using the keytool distributed with the JDK from a servlet running on Tomcat.  Using the keytool from the command line requires a command like the following:
 
/usr/local/jdk1.2.2/bin/keytool -genkey -dname "cn=eForms Demo " -alias demoAlias -keypass demoPassword -keystore /us/local/tomcat/webapps/eform/WEB-INF/keystore/file.keystore -storepass irgkeystore -validity 365".
 
When I enter the command at the comman line, it works perfectly. When I try to run it from the Servlet, it doesn't work.
 
To run it from the servlet, I used the Runtime.exec(String [] cmd) where cmd is a array holding each of the commands. It looks like the following:
 
cmd[0] = KEY_TOOL_PATH;
cmd[1] = COMMAND_GENERATE_KEY;
cmd[2] = COMMAND_DISTINGUISHED_NAME + "\"cn=" + userName + "\"";
cmd[3] = COMMAND_ALIAS + keyAlias;
cmd[4] = COMMAND_KEY_PASSWORD + keyPassword;  
cmd[5] = COMMAND_KEY_STORE_PATH + keyStorePath;
cmd[6] = COMMAND_KEY_STORE_PASSWORD + keyStorePassword;
cmd[7] = COMMAND_DAYS_VALID + numberOfDaysKeyIsValid;
 
I even tried sending the command as one String using the Runtime.exec(command.toString()) method where command is a StringBufger  like th following:
 
StringBuffer command = new StringBuffer();  
command.append(KEY_TOOL_PATH);
command.append(COMMAND_GENERATE_KEY);    
command.append(COMMAND_DISTINGUISHED_NAME);
command.append("\"cn=");
command.append(userName);
command.append("\"");
command.append(COMMAND_ALIAS);
command.append(keyAlias);
command.append(COMMAND_KEY_PASSWORD);
command.append(keyPassword);
command.append(COMMAND_KEY_STORE_PATH);
command.append(keyStorePath);
command.append(COMMAND_KEY_STORE_PASSWORD);
command.append(keyStorePassword);
command.append(COMMAND_DAYS_VALID);
command.append(numberOfDaysKeyIsValid); 
 
I even tried using the example from Jason Hunter's Servlet book that says use a shell and that didn't work either. The array is constructed like the following where command is the StringBuffer above:
 
String [] cmd = new String[3];    
cmd[0] = "/bin/csh";
cmd[1] = "-c";
cmd[2] = command.toString();
 
In all my attemps, an exception is not thrown, the keystore is not created, and the exit value of the process is not 0. An exit value of 0 would indicate that the command was executed properly. Is this a tomcat bug?
 

Reply via email to