89 lines
3.1 KiB
Bash
Executable file
89 lines
3.1 KiB
Bash
Executable file
#!/bin/bash
|
|
################################################################################
|
|
# Intended use: Simple shell script to create certs (RSA or EC)
|
|
#
|
|
# Notes: This script support Linux Bash shell script only
|
|
# Install Bash from https://www.gnu.org/software/bash/
|
|
#
|
|
# Copyright (C) 2015 - 2025, VGISC Dev Team <dev@vgisc.com>
|
|
################################################################################
|
|
|
|
OPENSSL_BIN="$basedir/bin/openssl"
|
|
MKC4B_B64_BIN="$basedir/bin/util_mkc4b_encrypt_encode_file"
|
|
|
|
filepath=`readlink -f $0`
|
|
basedir=`dirname $filepath`
|
|
|
|
XML_DIR="$basedir/xml"
|
|
PKI_PARAM_XML="$basedir/xml/pki_param.xml"
|
|
|
|
ROOT_CA_CERT="$basedir/root-ca/root-ca.crt"
|
|
SUB_CA_CERT="$basedir/sub-ca/sub-ca.crt"
|
|
CLIENT_DIR="$basedir/client"
|
|
|
|
i=1
|
|
NUM=99
|
|
|
|
echo "==========================================================="
|
|
echo "Generating pki_param file ${PKI_PARAM_XML}..."
|
|
echo "==========================================================="
|
|
echo ""
|
|
|
|
echo -e "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > ${PKI_PARAM_XML}
|
|
echo -e "<inms>" >> ${PKI_PARAM_XML}
|
|
echo -e "\t<system>" >> ${PKI_PARAM_XML}
|
|
echo -e "\t\t<inms_version>1.0</inms_version>" >> ${PKI_PARAM_XML}
|
|
echo -e "\t\t<config_file_version>1554450545070</config_file_version>" >> ${PKI_PARAM_XML}
|
|
echo -e "\t\t<device_id>1</device_id>" >> ${PKI_PARAM_XML}
|
|
echo -e "\t</system>" >> ${PKI_PARAM_XML}
|
|
echo -e "\t<crypto>" >> ${PKI_PARAM_XML}
|
|
echo -e "\t\t<vcrypt>" >> ${PKI_PARAM_XML}
|
|
echo -e "\t\t\t<pki>" >> ${PKI_PARAM_XML}
|
|
|
|
echo -e "\t\t\t\t<cacerts>" >> ${PKI_PARAM_XML}
|
|
|
|
echo -e "\t\t\t\t\t<item name=\"root-ca.vgisc.com.crt\" type=\"RSA\" key_size=\"\" content_type=\"PEM\" use_for=\"\">" >> ${PKI_PARAM_XML}
|
|
${OPENSSL_BIN} x509 -in ${ROOT_CA_CERT} >> ${PKI_PARAM_XML}
|
|
echo -e "</item>" >> ${PKI_PARAM_XML}
|
|
|
|
echo -e "\t\t\t\t\t<item name=\"sub-ca.vgisc.com.crt\" type=\"RSA\" key_size=\"\" content_type=\"PEM\" use_for=\"\">" >> ${PKI_PARAM_XML}
|
|
${OPENSSL_BIN} x509 -in ${SUB_CA_CERT} >> ${PKI_PARAM_XML}
|
|
echo -e "\t\t\t\t\t</item>" >> ${PKI_PARAM_XML}
|
|
|
|
echo -e "\t\t\t\t</cacerts>" >> ${PKI_PARAM_XML}
|
|
|
|
echo -e "\t\t\t\t<certs>" >> ${PKI_PARAM_XML}
|
|
|
|
i=1
|
|
while [ $i -le $NUM ]
|
|
do
|
|
echo -e "\t\t\t\t\t<item name=\"vpn$i.vgisc.com.crt\" type=\"RSA\" key_size=\"\" content_type=\"PEM\" use_for=\"\">" >> ${PKI_PARAM_XML}
|
|
${OPENSSL_BIN} x509 -in ${CLIENT_DIR}/vpn$i.vgisc.com.crt >> ${PKI_PARAM_XML}
|
|
echo -e "</item>" >> ${PKI_PARAM_XML}
|
|
i=`expr $i + 1`
|
|
done
|
|
|
|
echo -e "\t\t\t\t</certs>" >> ${PKI_PARAM_XML}
|
|
|
|
echo -e "\t\t\t\t<private>" >> ${PKI_PARAM_XML}
|
|
|
|
i=1
|
|
while [ $i -le $NUM ]
|
|
do
|
|
echo -e "\t\t\t\t\t<item name=\"vpn$i.vgisc.com.key\" type=\"RSA\" key_size=\"4096\" content_type=\"B64\" use_for=\"\" passphare=\"\">" >> ${PKI_PARAM_XML}
|
|
cat ${CLIENT_DIR}/vpn$i.vgisc.com.mkc4b.b64 >> ${PKI_PARAM_XML}
|
|
echo -e "</item>" >> ${PKI_PARAM_XML}
|
|
i=`expr $i + 1`
|
|
done
|
|
|
|
echo -e "\t\t\t\t</private>" >> ${PKI_PARAM_XML}
|
|
|
|
echo -e "\t\t\t</pki>" >> ${PKI_PARAM_XML}
|
|
echo -e "\t\t</vcrypt>" >> ${PKI_PARAM_XML}
|
|
echo -e "\t</crypto>" >> ${PKI_PARAM_XML}
|
|
echo -e "</inms>" >> ${PKI_PARAM_XML}
|
|
|
|
echo "XML PKI key is saved to file $PKI_PARAM_XML"
|
|
echo ""
|
|
|
|
echo "All Done"
|