This repository has been archived on 2022-01-23. You can view files and clone it, but cannot push or open issues or pull requests.
ssladmin/new.intermediate.sh
2016-02-22 01:42:47 -05:00

155 lines
7.9 KiB
Bash

#!/bin/bash
set -e
if [[ -z "${NEWCA}" ]];
then
rootdir='/root/ssl/ca'
bindir="$(dirname ${0})"
export rootdir
export bindir
echo "If you continue, I will completely DELETE (if found):"
echo " ${rootdir}/intermediate/key"
echo " ${rootdir}/intermediate/crt"
echo " ${rootdir}/intermediate/crl"
echo " ${rootdir}/intermediate/csr"
echo " ${rootdir}/intermediate/index.txt"
echo " ${rootdir}/intermediate/serial"
echo
echo "To continue, type YESIAMCRAZY and hit the enter key."
read RUCRAZY2
else
RUCRAZY2='YESIAMCRAZY'
fi
if [[ "${RUCRAZY2}" != 'YESIAMCRAZY' ]];
then
echo '"IAMCRAZY" *NOT* entered. Quitting.'
exit 1
fi
echo "Deleting intermediary hierarchy and creating clean..."
rm -rf ${rootdir}/intermediate/{key,crt,crl,csr,index.txt,serial}
mkdir -p ${rootdir}/intermediate/{key,crt,crl,csr}
echo '1000' > ${rootdir}/intermediate/serial
touch ${rootdir}/intermediate/index.txt
chmod 700 ${rootdir}/intermediate
chmod 700 ${rootdir}/intermediate/key
echo 1000 > ${rootdir}/intermediate/crlnumber
base64 -d >> ${rootdir}/intermediate/openssl.cnf << EOF
IyBPcGVuU1NMIGludGVybWVkaWF0ZSBDQSBjb25maWd1cmF0aW9uIGZpbGUuCiMgQ29weSB0byBg
L3Jvb3QvY2EvaW50ZXJtZWRpYXRlL29wZW5zc2wuY25mYC4KClsgY2EgXQojIGBtYW4gY2FgCmRl
ZmF1bHRfY2EgPSBDQV9kZWZhdWx0CgpbIENBX2RlZmF1bHQgXQojIERpcmVjdG9yeSBhbmQgZmls
ZSBsb2NhdGlvbnMuCmRpciAgICAgICAgICAgICAgID0gJSVURU1QTEFURV9ST09URElSJSUvaW50
ZXJtZWRpYXRlCmNlcnRzICAgICAgICAgICAgID0gJGRpci9jcnQKY3JsX2R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
ZmllciA9IGtleWlkLGlzc3VlcgprZXlVc2FnZSA9IGNyaXRpY2FsLCBkaWdpdGFsU2lnbmF0dXJl
CmV4dGVuZGVkS2V5VXNhZ2UgPSBjcml0aWNhbCwgT0NTUFNpZ25pbmcKCg==
EOF
if [[ -z ${NEWCA} ]];
then
echo "Customizing openssl.cnf..."
echo
echo -n "What is your ORGANIZATION'S name? "
read ORGNAME
export ORGNAME
echo -n "And what is your organization's MAIN DOMAIN? "
read ORGSITE
export ORGSITE
echo -n "What Country (two-letter abbreviation) is your organization locatied in? "
read ORGCNTRY
export ORGCNTRY
echo -n "What State (full name) is your organization located in? "
read ORGSTATE
export ORGSTATE
echo -n "What City is your organization located in? "
read ORGCITY
export ORGCITY
echo -n "Lastly, what email address should be used for the SSL administrator? "
read SSLADMIN
export SSLADMIN
fi
sed -i -e "s/%%TEMPLATE_ORG%%/${ORGNAME}/g ; s/%%TEMPLATE_DOMAIN%%/${ORGSITE}/g ; s/%%TEMPLATE_ROOTDIR%%/${rootdir}/g ; s/%%TEMPLATE_COUNTRY%%/${ORGCNTRY}/g ; s/%%TEMPLATE_STATE%%/${ORGSTATE}/g ; s/%%TEMPLATE_CITY%%/${ORGCITY}/g ; s/%%TEMPLATE_SSLADMIN%%/${SSLADMIN}/g" ${rootdir}/intermediate/openssl.cnf
sh ${bindir}/gen.intermediate.key.sh
sh ${bindir}/gen.intermediate.csr.sh
sh ${bindir}/gen.intermediate.cert.sh
sh ${bindir}/gen.intermediate.chain.sh