#!/bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
########################################################################
#
# mozilla/security/nss/tests/cert/chains.sh
#
# Script to test certificate chains validity.
#
# needs to work on all Unix and Windows platforms
#
# special strings
# ---------------
# FIXME ... known problems, search for this string
# NOTE .... unexpected behavior
########################################################################
########################### is_httpserv_alive ##########################
# local shell function to exit with a fatal error if selfserver is not
# running
########################################################################
is_httpserv_alive()
{
if [ ! -f
"${HTTPPID}" ];
then
echo "$SCRIPTNAME: Error - httpserv PID file ${HTTPPID} doesn't exist"
sleep 5
if [ ! -f
"${HTTPPID}" ];
then
Exit 9
"Fatal - httpserv pid file ${HTTPPID} does not exist"
fi
fi
if [
"${OS_ARCH}" =
"WINNT" ] && \
[
"$OS_NAME" =
"CYGWIN_NT" -o
"$OS_NAME" =
"MINGW32_NT" ];
then
PID=${SHELL_HTTPPID}
else
PID=`
cat ${HTTPPID}`
fi
echo "kill -0 ${PID} >/dev/null 2>/dev/null"
kill -0 ${PID} >/dev/null 2>/dev/null || Exit 10
"Fatal - httpserv process not detectable"
echo "httpserv with PID ${PID} found at `date`"
}
########################### wait_for_httpserv ##########################
# local shell function to wait until httpserver is running and initialized
########################################################################
wait_for_httpserv()
{
echo "trying to connect to httpserv at `date`"
echo "tstclnt -4 -p ${NSS_AIA_PORT} -h ${HOSTADDR} -q -v"
${BINDIR}/tstclnt -4 -p ${NSS_AIA_PORT} -h ${HOSTADDR} -q -v
if [ $? -ne 0 ];
then
sleep 5
echo "retrying to connect to httpserv at `date`"
echo "tstclnt -4 -p ${NSS_AIA_PORT} -h ${HOSTADDR} -q -v"
${BINDIR}/tstclnt -4 -p ${NSS_AIA_PORT} -h ${HOSTADDR} -q -v
if [ $? -ne 0 ];
then
html_failed
"Waiting for Server"
fi
fi
is_httpserv_alive
}
########################### kill_httpserv ##############################
# local shell function to kill the httpserver after the tests are done
########################################################################
kill_httpserv()
{
if [
"${OS_ARCH}" =
"WINNT" ] && \
[
"$OS_NAME" =
"CYGWIN_NT" -o
"$OS_NAME" =
"MINGW32_NT" ];
then
PID=${SHELL_HTTPPID}
else
PID=`
cat ${HTTPPID}`
fi
echo "trying to kill httpserv with PID ${PID} at `date`"
if [
"${OS_ARCH}" =
"WINNT" ];
then
echo "${KILL} ${PID}"
${KILL} ${PID}
else
echo "${KILL} -USR1 ${PID}"
${KILL} -USR1 ${PID}
fi
wait ${PID}
# On Linux httpserv needs up to 30 seconds to fully die and free
# the port. Wait until the port is free. (Bug 129701)
if [
"${OS_ARCH}" =
"Linux" ];
then
echo "httpserv -b -p ${NSS_AIA_PORT} 2>/dev/null;"
until ${BINDIR}/httpserv -b -p ${NSS_AIA_PORT} 2>/dev/null;
do
echo "RETRY: httpserv -b -p ${NSS_AIA_PORT} 2>/dev/null;"
sleep 1
done
fi
echo "httpserv with PID ${PID} killed at `date`"
rm ${HTTPPID}
html_detect_core
"kill_httpserv core detection step"
}
########################### start_httpserv #############################
# local shell function to start the httpserver with the parameters required
# for this test and log information (parameters, start time)
# also: wait until the server is up and running
########################################################################
start_httpserv()
{
HTTP_METHOD=$1
if [ -n
"$testname" ] ;
then
echo "$SCRIPTNAME: $testname ----"
fi
echo "httpserv starting at `date`"
ODDIR=
"${HOSTDIR}/chains/OCSPD"
echo "httpserv -D -p ${NSS_AIA_PORT} ${SERVER_OPTIONS} \\"
echo " -A OCSPRoot -C ${ODDIR}/OCSPRoot.crl -A OCSPCA1 -C ${ODDIR}/OCSPCA1.crl \\"
echo " -A OCSPCA2 -C ${ODDIR}/OCSPCA2.crl -A OCSPCA3 -C ${ODDIR}/OCSPCA3.crl \\"
echo " -O ${HTTP_METHOD} -d ${ODDIR}/ServerDB/ -f ${ODDIR}/ServerDB/dbpasswd \\"
echo " -i ${HTTPPID} $verbose &"
${PROFTOOL} ${BINDIR}/httpserv -D -p ${NSS_AIA_PORT} ${SERVER_OPTIONS} \
-A OCSPRoot -C ${ODDIR}/OCSPRoot.crl -A OCSPCA1 -C ${ODDIR}/OCSPCA1.crl \
-A OCSPCA2 -C ${ODDIR}/OCSPCA2.crl -A OCSPCA3 -C ${ODDIR}/OCSPCA3.crl \
-O ${HTTP_METHOD} -d ${ODDIR}/ServerDB/ -f ${ODDIR}/ServerDB/dbpasswd \
-i ${HTTPPID} $verbose &
RET=$?
# The PID $! returned by the MKS or Cygwin shell is not the PID of
# the real background process, but rather the PID of a helper
# process (sh.exe). MKS's kill command has a bug: invoking kill
# on the helper process does not terminate the real background
# process. Our workaround has been to have httpserv save its PID
# in the ${HTTPPID} file and "kill" that PID instead. But this
# doesn't work under Cygwin; its kill command doesn't recognize
# the PID of the real background process, but it does work on the
# PID of the helper process. So we save the value of $! in the
# SHELL_HTTPPID variable, and use it instead of the ${HTTPPID}
# file under Cygwin. (In fact, this should work in any shell
# other than the MKS shell.)
SHELL_HTTPPID=$!
wait_for_httpserv
if [
"${OS_ARCH}" =
"WINNT" ] && \
[
"$OS_NAME" =
"CYGWIN_NT" -o
"$OS_NAME" =
"MINGW32_NT" ];
then
PID=${SHELL_HTTPPID}
else
PID=`
cat ${HTTPPID}`
fi
echo "httpserv with PID ${PID} started at `date`"
}
############################# chains_init ##############################
# local shell function to initialize this script
########################################################################
chains_init()
{
if [ -z
"${CLEANUP}" ] ;
then # if nobody else is responsible for
CLEANUP=
"${SCRIPTNAME}" # cleaning this script will do it
fi
if [ -z
"${INIT_SOURCED}" ] ;
then
cd ../common
. ./init.sh
fi
SCRIPTNAME=
"chains.sh"
CHAINS_DIR=
"${HOSTDIR}/chains"
mkdir -p ${CHAINS_DIR}
cd ${CHAINS_DIR}
CHAINS_SCENARIOS=
"${QADIR}/chains/scenarios/scenarios"
CERT_SN_CNT=$(date
'+%m%d%H%M%S' | sed
"s/^0*//")
CERT_SN_FIX=$(expr ${CERT_SN_CNT} - 1000)
PK7_NONCE=${CERT_SN_CNT}
SCEN_CNT=${CERT_SN_CNT}
AIA_FILES=
"${HOSTDIR}/aiafiles"
CU_DATA=${HOSTDIR}/cu_data
CRL_DATA=${HOSTDIR}/crl_data
DEFAULT_AIA_BASE_PORT=$(expr ${PORT:-8631} + 10)
NSS_AIA_PORT=${NSS_AIA_PORT:-$DEFAULT_AIA_BASE_PORT}
DEFAULT_UNUSED_PORT=$(expr ${PORT:-8631} + 11)
NSS_UNUSED_PORT=${NSS_UNUSED_PORT:-$DEFAULT_UNUSED_PORT}
NSS_AIA_HTTP=${NSS_AIA_HTTP:-
"http://${HOSTADDR}:${NSS_AIA_PORT}"}
NSS_AIA_PATH=${NSS_AIA_PATH:-$HOSTDIR/aiahttp}
NSS_AIA_OCSP=${NSS_AIA_OCSP:-$NSS_AIA_HTTP/ocsp}
NSS_OCSP_UNUSED=${NSS_AIA_OCSP_UNUSED:-
"http://${HOSTADDR}:${NSS_UNUSED_PORT}"}
html_head
"Certificate Chains Tests"
}
chains_run_httpserv()
{
HTTP_METHOD=$1
if [ -n
"${NSS_AIA_PATH}" ];
then
HTTPPID=${NSS_AIA_PATH}/http_pid.$$
mkdir -p
"${NSS_AIA_PATH}"
SAVEPWD=`pwd`
cd
"${NSS_AIA_PATH}"
# Start_httpserv sets environment variables, which are required for
# correct cleanup. (Running it in a subshell doesn't work, the
# value of $SHELL_HTTPPID wouldn't arrive in this scope.)
start_httpserv ${HTTP_METHOD}
cd
"${SAVEPWD}"
fi
}
chains_stop_httpserv()
{
if [ -n
"${NSS_AIA_PATH}" ];
then
kill_httpserv
fi
}
############################ chains_cleanup ############################
# local shell function to finish this script (no exit since it might be
# sourced)
########################################################################
chains_cleanup()
{
html
"