final File keyStoreFile = serverEnv.getJKS();
final File trustStoreFile = new File(serverEnv.getConfigDirPath(), "cacerts.jks");
final String pw = masterPassword();
final char[] pwChar = pw.toCharArray();
ProcessManager pm = new ProcessManager(new String[]{
"keytool",
"-genkey",
"-keyalg", "RSA",
"-keystore", keyStoreFile.getAbsolutePath(),
"-alias", SecureAdmin.Duck.DEFAULT_INSTANCE_ALIAS,
"-dname", getCertificateDN(),
"-validity", "3650",
"-keypass", pw,
"-storepass", pw,});
pm.execute();
if (pm.getExitValue() != 0) {
final String err = pm.getStdout();
throw new RuntimeException(err);
}
final File tempCertFile = new File(serverEnv.getConfigDirPath(),"temp.cer");
tempCertFile.deleteOnExit();
pm = new ProcessManager(new String[] {
"keytool",
"-exportcert",
"-keystore", keyStoreFile.getAbsolutePath(),
"-alias", SecureAdmin.Duck.DEFAULT_INSTANCE_ALIAS,
"-keypass", pw,
"-storepass", pw,
"-file", tempCertFile.getAbsolutePath()
});
pm.execute();
if (pm.getExitValue() != 0) {
throw new RuntimeException(pm.getStderr());
}
pm = new ProcessManager(new String[] {
"keytool",
"-importcert",
"-noprompt",
"-trustcacerts",
"-storepass", pw,
"-keypass", pw,
"-keystore", trustStoreFile.getAbsolutePath(),
"-file", tempCertFile.getAbsolutePath(),
"-alias", SecureAdmin.Duck.DEFAULT_INSTANCE_ALIAS
});
pm.execute();
tempCertFile.delete();
if (pm.getExitValue() != 0) {
throw new RuntimeException(pm.getStderr());
}
/*
* Reload the keystore and truststore from disk.
*/