-
-
Save hyperius/f9363eb2f63e692c0d04dfaee8953890 to your computer and use it in GitHub Desktop.
Import RDS certificates to truststore
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/sh -e | |
set -x | |
# create a temp dir in which to work | |
OLDDIR="$PWD" | |
mkdir /tmp/rds-ca && cd /tmp/rds-ca | |
# download the bundle | |
wget https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem | |
# split the bundle into individual certs (prefixed with xx) | |
csplit -sz global-bundle.pem '/-BEGIN CERTIFICATE-/' '{*}' | |
# import each cert individually | |
for CERT in xx*; do | |
# extract a human-readable alias from the cert | |
ALIAS=$(openssl x509 -noout -text -in $CERT | | |
perl -ne 'next unless /Subject:/; s/.*CN=//; print') | |
echo "importing $ALIAS" | |
# import the cert into the default java keystore | |
sudo keytool -import \ | |
-cacerts \ | |
-storepass changeit -noprompt \ | |
-alias "$ALIAS" -file $CERT | |
done | |
# back out of the temp dir and delete it | |
cd "$OLDDIR" | |
rm -r /tmp/rds-ca | |
# list the imported rds certs as a sanity check | |
keytool -list \ | |
-cacerts \ | |
-storepass changeit -noprompt | | |
grep -i rds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment