2023-05-12 19:07:28 +00:00
|
|
|
#!/bin/bash
|
|
|
|
############################################################################################
|
|
|
|
# Creates 2 Certificate Chains for the ACA:
|
|
|
|
# 1 RSA 3K SHA 384
|
|
|
|
# 2 ECC 512 SHA 384
|
|
|
|
#
|
|
|
|
############################################################################################
|
|
|
|
|
2023-07-07 20:54:02 +00:00
|
|
|
PROP_FILE=/etc/hirs/aca/application.properties
|
2023-07-18 17:09:11 +00:00
|
|
|
LOG_FILE=$1
|
2023-08-11 13:47:30 +00:00
|
|
|
PKI_PASS=$2
|
|
|
|
LOG_FILE_NAME="hirs_aca_install_"$(date +%Y-%m-%d).log
|
|
|
|
LOG_DIR="/var/log/hirs/"
|
|
|
|
HIRS_CONF_DIR=/etc/hirs/aca
|
2023-05-12 19:07:28 +00:00
|
|
|
# Capture location of the script to allow from invocation from any location
|
2023-05-19 20:35:46 +00:00
|
|
|
SCRIPT_DIR=$( dirname -- "$( readlink -f -- "$0"; )"; )
|
2023-08-11 13:47:30 +00:00
|
|
|
|
|
|
|
mkdir -p $HIRS_CONF_DIR $LOG_DIR
|
2023-07-18 17:09:11 +00:00
|
|
|
echo "SCRIPT_DIR is $SCRIPT_DIR" | tee -a "$LOG_FILE"
|
2023-07-13 20:40:15 +00:00
|
|
|
|
2023-08-11 13:47:30 +00:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
LOG_FILE="$LOG_DIR$LOG_FILE_NAME"
|
|
|
|
echo "using log file $LOG_FILE" | tee -a "$LOG_FILE"
|
|
|
|
fi
|
|
|
|
if [ -z "$2" ]; then
|
|
|
|
PKI_PASS=$(head -c 64 /dev/urandom | md5sum | tr -dc 'a-zA-Z0-9')
|
|
|
|
echo "Using randomly generated password for the PKI key password" | tee -a "$LOG_FILE"
|
|
|
|
echo "Using pki password=$PKI_PASS"
|
|
|
|
fi
|
|
|
|
|
2023-07-13 20:40:15 +00:00
|
|
|
# Check for sudo or root user
|
|
|
|
if [ "$EUID" -ne 0 ]
|
2023-07-18 17:09:11 +00:00
|
|
|
then echo "The first time this script is run, this script requires root. Please run as root" | tee -a "$LOG_FILE"
|
2023-07-13 20:40:15 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-05-12 19:07:28 +00:00
|
|
|
# Create Cert Chains
|
2023-06-02 19:23:55 +00:00
|
|
|
if [ ! -d "/etc/hirs/certificates" ]; then
|
|
|
|
|
2023-07-10 15:57:10 +00:00
|
|
|
if [ -d "/opt/hirs/scripts/pki" ]; then
|
2023-06-02 19:23:55 +00:00
|
|
|
PKI_SETUP_DIR="/opt/hirs/scripts/pki"
|
|
|
|
else
|
2023-07-10 15:57:10 +00:00
|
|
|
PKI_SETUP_DIR="$SCRIPT_DIR"
|
2023-06-02 19:23:55 +00:00
|
|
|
fi
|
2023-07-18 17:09:11 +00:00
|
|
|
echo "PKI_SETUP_DIR is $PKI_SETUP_DIR" | tee -a "$LOG_FILE"
|
|
|
|
|
|
|
|
mkdir -p /etc/hirs/certificates/ | tee -a "$LOG_FILE"
|
2023-05-12 19:07:28 +00:00
|
|
|
|
2023-06-02 19:23:55 +00:00
|
|
|
pushd /etc/hirs/certificates/ &> /dev/null
|
|
|
|
cp $PKI_SETUP_DIR/ca.conf .
|
2023-07-18 17:09:11 +00:00
|
|
|
sh $PKI_SETUP_DIR/pki_chain_gen.sh "HIRS" "rsa" "3072" "sha384" "$PKI_PASS" "$LOG_FILE"
|
|
|
|
sh $PKI_SETUP_DIR/pki_chain_gen.sh "HIRS" "ecc" "512" "sha384" "$PKI_PASS" "$LOG_FILE"
|
2023-06-02 19:23:55 +00:00
|
|
|
popd &> /dev/null
|
2023-07-07 20:54:02 +00:00
|
|
|
|
2023-07-18 17:09:11 +00:00
|
|
|
# Add tomcat TLS support to the application.properties file
|
|
|
|
echo "# Tomcat TLS support">> $PROP_FILE
|
|
|
|
echo "server.port=8443">> $PROP_FILE
|
|
|
|
echo "server.ssl.enabled=true">> $PROP_FILE
|
|
|
|
echo "server.ssl.trust-store-type=JKS">> $PROP_FILE
|
|
|
|
echo "server.ssl.trust-store=/etc/hirs/certificates/HIRS/TrustStore.jks">> $PROP_FILE
|
|
|
|
echo "server.ssl.trust-alias=hirs_aca_tls_rsa_3k_sha384">> $PROP_FILE
|
|
|
|
echo "server.ssl.key-store-type=JKS">> $PROP_FILE
|
|
|
|
echo "server.ssl.key-store=/etc/hirs/certificates/HIRS/KeyStore.jks">> $PROP_FILE
|
|
|
|
echo "server.ssl.key-alias=hirs_aca_tls_rsa_3k_sha384">> $PROP_FILE
|
2023-07-07 20:54:02 +00:00
|
|
|
echo "server.ssl.key-store-password="$PKI_PASS >> $PROP_FILE
|
|
|
|
echo "server.ssl.trust-store-password="$PKI_PASS >> $PROP_FILE
|
2023-06-02 19:23:55 +00:00
|
|
|
else
|
2023-07-18 17:09:11 +00:00
|
|
|
echo "/etc/hirs/certificates exists, skipping" | tee -a "$LOG_FILE"
|
2023-06-02 19:23:55 +00:00
|
|
|
fi
|