Skip to content

Commit

Permalink
Update unifi_ssl_import.sh
Browse files Browse the repository at this point in the history
Amending last PR Merge.

The changes added previous streamlined the Let's Encrypt Process but in the process broke the script for user using their own certs. Resulting in errors:
- "No Certificate matches private key"
- "Alias <unifi> does not exist"
etc

Now the script should check if the signed cert exists, if it does add that to the export. (alternative would be to create a combined file, but I personally prefer to keep CA and Cert seperate)

Also added the "deststoretype" option as controller was complaining about security.
  • Loading branch information
roadrunnerspeed committed Dec 6, 2018
1 parent d5aba2c commit cefcdf3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions unifi_ssl_import.sh
Expand Up @@ -124,11 +124,21 @@ fi
# Export your existing SSL key, cert, and CA data to a PKCS12 file
printf "\nExporting SSL certificate and key data into temporary PKCS12 file...\n"

openssl pkcs12 -export \
-in ${CHAIN_FILE} \
-inkey ${PRIV_KEY} \
-out ${P12_TEMP} -passout pass:${PASSWORD} \
-name ${ALIAS}
#If there is a signed crt we should include this in the export
if [ -f ${SIGNED_CRT} ]; then
openssl pkcs12 -export \
-in ${CHAIN_FILE} \
-in ${SIGNED_CRT} \
-inkey ${PRIV_KEY} \
-out ${P12_TEMP} -passout pass:${PASSWORD} \
-name ${ALIAS}
else
openssl pkcs12 -export \
-in ${CHAIN_FILE} \
-inkey ${PRIV_KEY} \
-out ${P12_TEMP} -passout pass:${PASSWORD} \
-name ${ALIAS}
fi

# Delete the previous certificate data from keystore to avoid "already exists" message
printf "\nRemoving previous certificate data from UniFi keystore...\n"
Expand All @@ -142,6 +152,7 @@ keytool -importkeystore \
-destkeystore ${KEYSTORE} \
-deststorepass ${PASSWORD} \
-destkeypass ${PASSWORD} \
-deststoretype pkcs12 \
-alias ${ALIAS} -trustcacerts

# Clean up temp files
Expand All @@ -155,4 +166,4 @@ service ${UNIFI_SERVICE} start
# That's all, folks!
printf "\nDone!\n"

exit 0
exit 0

0 comments on commit cefcdf3

Please sign in to comment.