Skip to content

Instantly share code, notes, and snippets.

@threez
Created March 3, 2014 10:20
Show Gist options
  • Save threez/9322140 to your computer and use it in GitHub Desktop.
Save threez/9322140 to your computer and use it in GitHub Desktop.
Extract and update a ldap certificate in a java keystore (jenkins)
#!/bin/bash
LDAP_SERVER=example.com:636
ALIAS=LDAP_SERVER
KEYSTORE=/usr/lib/jvm/java-1.6.0-openjdk-amd64/jre/lib/security/cacerts
PASSWD=changeit
# grep the certificate
echo -n | openssl s_client -connect $LDAP_SERVER | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ldaps.crt
# remove the old cert
keytool -delete -alias $ALIAS -keystore $KEYSTORE -storepass $PASSWD
# install the new cert
keytool -import -trustcacerts -alias $ALIAS -file ldaps.crt -keystore $KEYSTORE -storepass $PASSWD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment