Skip to content

Instantly share code, notes, and snippets.

@serac
Last active December 14, 2018 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serac/e9b1e058a6b83a782997174726b7b3d2 to your computer and use it in GitHub Desktop.
Save serac/e9b1e058a6b83a782997174726b7b3d2 to your computer and use it in GitHub Desktop.
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