Skip to content

Instantly share code, notes, and snippets.

@lhriley
Created February 3, 2018 02:10
Show Gist options
  • Select an option

  • Save lhriley/d19ed92d1f09f7ae8edebab9eaf29ec3 to your computer and use it in GitHub Desktop.

Select an option

Save lhriley/d19ed92d1f09f7ae8edebab9eaf29ec3 to your computer and use it in GitHub Desktop.
AWS CA import script for JDK keystore
#!/bin/bash -e
# create a temp dir in which to work
OLDDIR="$PWD"
TMPDIR="/tmp/_aws-ca"
mkdir "${TMPDIR}" && cd "${TMPDIR}"
AWS_CERTS=(
AmazonRootCA1.pem
AmazonRootCA2.pem
AmazonRootCA3.pem
AmazonRootCA4.pem
)
# download the bundle(s)
for cert in ${AWS_CERTS[*]}; do
wget "https://www.amazontrust.com/repository/${cert}" -O "${TMPDIR}/${cert}"
# extract a human-readable alias from the cert
ALIAS=$(openssl x509 -noout -text -in "${TMPDIR}/${cert}" |
perl -ne 'next unless /Subject:/; s/.*CN=//; print')
echo "importing $ALIAS"
# import the cert into the default java keystore
keytool -import \
-keystore /etc/ssl/certs/java/cacerts \
-storepass changeit -noprompt \
-alias "$ALIAS" -file "${TMPDIR}/${cert}"
done
# back out of the temp dir and delete the temp folder
cd "$OLDDIR"
rm -r "${TMPDIR}"
# list the imported certs as a sanity check
keytool -list \
-keystore /etc/ssl/certs/java/cacerts -storepass changeit -noprompt |
grep -i Amazon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment