Created
January 16, 2024 12:34
-
-
Save bertrandmartel/3f7424298acae9aee27e0bd25c171d64 to your computer and use it in GitHub Desktop.
Extract certificates from a truststore and import them into an existing keystore (jre security cacerts)
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 | |
keystore=$JAVA_HOME/lib/security/cacerts | |
certs=$(keytool \ | |
-list \ | |
-keystore generic-truststore.jks \ | |
-storepass "" | grep trustedCertEntry | grep -Eo "^[^,]*") | |
while read -r cert | |
do | |
printf '%s\n' "$cert" | |
output_cert=$(echo "$cert" | base64).crt | |
keytool -exportcert -keystore bytel-generic-truststore.jks -alias "$cert" -file $output_cert <<< "" | |
keytool -import -trustcacerts -alias "$cert" -file $output_cert -keystore $keystore -storepass "" -noprompt | |
done < <(echo "$certs") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment