Skip to content

Instantly share code, notes, and snippets.

@LannyRipple
Created May 18, 2021 17:54
Show Gist options
  • Save LannyRipple/e7a7e4e7f1c94c093a63072cfc6642a8 to your computer and use it in GitHub Desktop.
Save LannyRipple/e7a7e4e7f1c94c093a63072cfc6642a8 to your computer and use it in GitHub Desktop.
Bash script adding nexus cacert to current java
#!/bin/bash
nexus=nexus.example.net:443
java_home=$( java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' | sed 's/.*= //' )
echo -n | openssl s_client -connect $nexus |\
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/nexus.crt
trap "rm -f /tmp/nexus.crt" 0 2 13 14
keytool -delete -trustcacerts -keystore $java_home/lib/security/cacerts -storepass changeit -noprompt -alias nexuscert
keytool -import -trustcacerts -keystore $java_home/lib/security/cacerts -storepass changeit \
-noprompt -alias nexuscert -file /tmp/nexus.crt
## __END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment