Last active
July 29, 2024 09:01
-
-
Save serac/e9b1e058a6b83a782997174726b7b3d2 to your computer and use it in GitHub Desktop.
Generate a PKCS#12 trust store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements: functional JDK on host system where keytool utility is on the PATH