I do the following:
File tmpDir = com.google.common.io.Files.createTempDir();
tmpDir.deleteOnExit();
// determine command based upon OS
String prefix = "pk12util";
String command = String.format(
"-i %s -d sql:%s -W '' -K ''",
cert.getAbsolutePath(), tmpDir.getAbsolutePath());
// run the command
CommandRunner.run(prefix, command);
CommandRunner is a wrapper around the java ProcessBuilder. It handles creating the process, returning command output and exit status.
Here is the command being run from the java process and the corresponding output.
pk12util -i a-typical-tls-cert.p12 -d sql:/tmpdirpath -W '' -K ''
pk12util: function failed: security library: bad database.
When I copy and paste the command I am running from the java process it completes successfully. I verified permissions on the certdir. I even tried running the -N on the tmpDir which yields no resolution. Anyone have any suggestions? I tried to dig through the source code for the pk12util for the error but couldn't find anything pertinent.