Created
May 24, 2022 20:06
-
-
Save huwcbjones/8c26fe208cf2e76729228adc200cdbd8 to your computer and use it in GitHub Desktop.
Easily import a unifi cert into the keystore
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 | |
set -e | |
if [ $# -lt 2 ]; then | |
echo "$0 KEY_FILE CERT_FILE" | |
exit 1 | |
fi | |
key="${1}" | |
cert="${2}" | |
echo "***********************************" | |
echo " About to import key/cert to unifi " | |
echo " keystore: " | |
echo " " | |
echo " Key: ${key}" | |
echo " Cert: ${cert}" | |
echo "***********************************" | |
read -n 1 -s -r -p "Press any key to continue" | |
echo "" | |
BUNDLE="bundle.p12" | |
BUNDLE_PATH="/var/lib/unifi/${BUNDLE}" | |
trap 'rm -f "${BUNDLE_PATH}"' EXIT | |
echo "[*] Converting key/cert to PKCS12" | |
openssl pkcs12 -export -name unifi -in "${cert}" -inkey "${key}" -CAfile "ca_bundle.pem" -out "${BUNDLE_PATH}" -password pass:CHANGEME | |
echo "[*] Importing ${BUNDLE} to keystore" | |
docker exec -i unifi-controller keytool -importkeystore \ | |
-destkeystore /config/data/keystore \ | |
-deststorepass aircontrolenterprise -destkeypass aircontrolenterprise \ | |
-srckeystore "/config/${BUNDLE}" \ | |
-srcstorepass CHANGEME \ | |
-srcstoretype pkcs12 \ | |
-alias unifi \ | |
-noprompt | |
echo "[*] Imported new cert to keystore!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment