Skip to content

Instantly share code, notes, and snippets.

@dandpg
Forked from paxswill/pfsense_cert_to_keystore.sh
Last active November 20, 2018 22:47
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 dandpg/0ea4ed55c1775ece4e4e8b529e442657 to your computer and use it in GitHub Desktop.
Save dandpg/0ea4ed55c1775ece4e4e8b529e442657 to your computer and use it in GitHub Desktop.
I modfied the Script for generate only .pem file for use Let's Encrypt certificate with Encrypted browser-Squid connection.
#!/bin/sh
set -eu
XMLLINT=/usr/local/bin/xmllint
BASE64_DECODE='/usr/local/bin/python2 -m base64 -d'
OPENSSL="/usr/bin/openssl"
KEYTOOL="/usr/local/bin/keytool"
PFSENSE_CONF=/cf/conf/config.xml
extract_private_key() {
local RAW XPATH
XPATH="/pfsense/cert[descr[normalize-space(.) = '$1']]/prv/text()"
RAW="`"$XMLLINT" --xpath "$XPATH" "$PFSENSE_CONF"`"
printf "%s\n" "`echo "$RAW" | $BASE64_DECODE`"
}
extract_certificate() {
local RAW XPATH
XPATH="/pfsense/cert[descr[normalize-space(.) = '$1']]/crt/text()"
RAW="`"$XMLLINT" --xpath "$XPATH" "$PFSENSE_CONF"`"
printf "%s\n" "`echo "$RAW" | $BASE64_DECODE`"
}
combine_pem() {
local PRIVATE_KEY CERTIFICATE
PRIVATE_KEY="`extract_private_key "$1"`"
CERTIFICATE="`extract_certificate "$1"`"
printf '%s\n%s\n' "$PRIVATE_KEY" "$CERTIFICATE"
}
main() {
local KEYSTORE PFSENSE_CERT_NAME
if [ "$#" -ne 1 ]; then
printf "Not enough arguments.\nUsage:\n\t%s\n" \
"$0 certificate_name"
exit 1
fi
PFSENSE_CERT_NAME="$1"
echo "Extracting cert+key form pfSense"
combine_pem "$PFSENSE_CERT_NAME"
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment