Skip to content

Instantly share code, notes, and snippets.

@bertrandmartel
Created January 16, 2024 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bertrandmartel/3f7424298acae9aee27e0bd25c171d64 to your computer and use it in GitHub Desktop.
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)
#!/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