Skip to content

Instantly share code, notes, and snippets.

@napramirez
Created December 18, 2017 04:43
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save napramirez/1c942929f5c101be89a80247f3a8617a to your computer and use it in GitHub Desktop.
Save napramirez/1c942929f5c101be89a80247f3a8617a to your computer and use it in GitHub Desktop.
Convert LetsEncrypt Certificates to PFX
#!/bin/sh
#
# Copy of https://gist.githubusercontent.com/arichika/b1a1413b554734ae964f/raw/e657ad2dc4ddab60750d26e87add61f9b988d887/ConvertLetsPemToPfx.sh
#
pemsdir='/etc/letsencrypt/archive' # default search PEMs
pfxspath='/share/letsencrypt/archive' # dest of the PFXs
passfile='/share/letsencrypt/pass.txt' # password to be applied to the PFX file
for cnvifull in `find "${pemsdir}" -name 'cert*.pem' -o -name '*chain*.pem'`
do
cnvifile=${cnvifull##*/}
cnvinum=`echo ${cnvifile%.*} | sed -e "s#[cert|chain|fullchain]##g"`
cnvipkey="${cnvifull%/*}/privkey${cnvinum}.pem"
cnvopem=`echo ${cnvifull} | sed -e "s#${pemsdir}#${pfxspath}#g"`
cnvofull="${cnvopem%.*}.pfx"
echo "- :-) ->"
echo "-in ${cnvifull}"
echo "-inkey ${cnvipkey}"
echo "-out ${cnvofull}"
mkdir -p ${cnvofull%/*}
openssl pkcs12 \
-export \
-in ${cnvifull} \
-inkey ${cnvipkey} \
-out ${cnvofull} \
-passout file:${passfile}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment