Add Self Signed Certificate without promting Yes/No from User

JavaSslImportKeystoreKeytool

Java Problem Overview


Using some batch file, I want to add the untrusted self signed certificate within Java Keystore.

Command is

%JAVA_HOME%/bin/keytool -import -v -trustcacerts -alias server-alias
-file server.cer -keystore cacerts.jks -keypass changeit -storepass changeit

After running above command, the screen promts for Trust of certificate using Y/N.

Trust this certificate? [no]:

But I don't want to provide Y/N here.

Is there a way to complete the import using a single command or some additional import switch if any?

Java Solutions


Solution 1 - Java

The option -noprompt doesn't prompt the input Y/N from a user and assumes yes.

More details can found by running command keytool -importcert -help on terminal.

Solution 2 - Java

As such, keytool is most likely looking for "yes" in your locale ("si" in this case).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionArun KumarView Question on Stackoverflow
Solution 1 - JavaArun KumarView Answer on Stackoverflow
Solution 2 - JavaCarlosView Answer on Stackoverflow