Skip to content

Instantly share code, notes, and snippets.

@serac
Last active Dec 14, 2018
Embed
What would you like to do?
Generate a PKCS#12 trust store
#!/bin/bash
# Generates a PKCS#12 trust store from a directory of PEM-encoded certificates
# using the Java keytool utility.
if [ $# -lt 2 ]; then
echo "USAGE $(basename $0) path/to/certs/dir path/to/output.p12"
exit
fi
IN="${1%/}"
OUT="$2"
PWD="password"
for CRT in "$IN"/*; do
echo "Processing $CRT"
NAME=$(basename $CRT)
ALIAS="${NAME%.*}"
keytool -importcert -trustcacerts -noprompt -alias $ALIAS \
-file $CRT -keystore $OUT -storetype PKCS12 -storepass $PWD
done
echo "Truststore created with trusted certificates:"
keytool -list -keystore $OUT -storetype PKCS12 -storepass $PWD
@serac
Copy link
Author

serac commented Dec 14, 2018

Requirements: functional JDK on host system where keytool utility is on the PATH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment