michael@0: #! /bin/bash michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: ######################################################################## michael@0: # mozilla/security/nss/tests/fips/fips.sh michael@0: # michael@0: # Script to test basic functionallity of NSS in FIPS-compliant mode michael@0: # michael@0: # needs to work on all Unix and Windows platforms michael@0: # michael@0: # tests implemented: michael@0: # michael@0: # special strings michael@0: # --------------- michael@0: # michael@0: ######################################################################## michael@0: michael@0: ############################## fips_init ############################## michael@0: # local shell function to initialize this script michael@0: ######################################################################## michael@0: fips_init() michael@0: { michael@0: SCRIPTNAME=fips.sh # sourced - $0 would point to all.sh michael@0: michael@0: if [ -z "${CLEANUP}" ] ; then # if nobody else is responsible for michael@0: CLEANUP="${SCRIPTNAME}" # cleaning this script will do it michael@0: fi michael@0: michael@0: if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then michael@0: cd ../common michael@0: . ./init.sh michael@0: fi michael@0: if [ ! -r $CERT_LOG_FILE ]; then # we need certificates here michael@0: cd ../cert michael@0: . ./cert.sh michael@0: fi michael@0: SCRIPTNAME=fips.sh michael@0: html_head "FIPS 140 Compliance Tests" michael@0: michael@0: grep "SUCCESS: FIPS passed" $CERT_LOG_FILE >/dev/null || { michael@0: Exit 15 "Fatal - FIPS of cert.sh needs to pass first" michael@0: } michael@0: michael@0: COPYDIR=${FIPSDIR}/copydir michael@0: michael@0: R_FIPSDIR=../fips michael@0: P_R_FIPSDIR=../fips michael@0: R_COPYDIR=../fips/copydir michael@0: michael@0: if [ -n "${MULTIACCESS_DBM}" ]; then michael@0: P_R_FIPSDIR="multiaccess:${D_FIPS}" michael@0: fi michael@0: michael@0: mkdir -p ${FIPSDIR} michael@0: mkdir -p ${COPYDIR} michael@0: michael@0: cd ${FIPSDIR} michael@0: } michael@0: michael@0: ############################## fips_140 ############################## michael@0: # local shell function to test basic functionality of NSS while in michael@0: # FIPS 140 compliant mode michael@0: ######################################################################## michael@0: fips_140() michael@0: { michael@0: echo "$SCRIPTNAME: Verify this module is in FIPS mode -----------------" michael@0: echo "modutil -dbdir ${P_R_FIPSDIR} -list" michael@0: ${BINDIR}/modutil -dbdir ${P_R_FIPSDIR} -list 2>&1 michael@0: ${BINDIR}/modutil -dbdir ${P_R_FIPSDIR} -chkfips true 2>&1 michael@0: html_msg $? 0 "Verify this module is in FIPS mode (modutil -chkfips true)" "." michael@0: michael@0: echo "$SCRIPTNAME: List the FIPS module certificates -----------------" michael@0: echo "certutil -d ${P_R_FIPSDIR} -L" michael@0: ${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1 michael@0: html_msg $? 0 "List the FIPS module certificates (certutil -L)" "." michael@0: michael@0: echo "$SCRIPTNAME: List the FIPS module keys -------------------------" michael@0: echo "certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE}" michael@0: ${BINDIR}/certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE} 2>&1 michael@0: html_msg $? 0 "List the FIPS module keys (certutil -K)" "." michael@0: michael@0: echo "$SCRIPTNAME: Attempt to list FIPS module keys with incorrect password" michael@0: echo "certutil -d ${P_R_FIPSDIR} -K -f ${FIPSBADPWFILE}" michael@0: ${BINDIR}/certutil -d ${P_R_FIPSDIR} -K -f ${FIPSBADPWFILE} 2>&1 michael@0: RET=$? michael@0: html_msg $RET 255 "Attempt to list FIPS module keys with incorrect password (certutil -K)" "." michael@0: echo "certutil -K returned $RET" michael@0: michael@0: echo "$SCRIPTNAME: Validate the certificate --------------------------" michael@0: echo "certutil -d ${P_R_FIPSDIR} -V -n ${FIPSCERTNICK} -u SR -e -f ${R_FIPSPWFILE}" michael@0: ${BINDIR}/certutil -d ${P_R_FIPSDIR} -V -n ${FIPSCERTNICK} -u SR -e -f ${R_FIPSPWFILE} michael@0: html_msg $? 0 "Validate the certificate (certutil -V -e)" "." michael@0: michael@0: echo "$SCRIPTNAME: Export the certificate and key as a PKCS#12 file --" michael@0: echo "pk12util -d ${P_R_FIPSDIR} -o fips140.p12 -n ${FIPSCERTNICK} -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE}" michael@0: ${BINDIR}/pk12util -d ${P_R_FIPSDIR} -o fips140.p12 -n ${FIPSCERTNICK} -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE} 2>&1 michael@0: html_msg $? 0 "Export the certificate and key as a PKCS#12 file (pk12util -o)" "." michael@0: michael@0: echo "$SCRIPTNAME: Export the certificate as a DER-encoded file ------" michael@0: echo "certutil -d ${P_R_FIPSDIR} -L -n ${FIPSCERTNICK} -r -o fips140.crt" michael@0: ${BINDIR}/certutil -d ${P_R_FIPSDIR} -L -n ${FIPSCERTNICK} -r -o fips140.crt 2>&1 michael@0: html_msg $? 0 "Export the certificate as a DER (certutil -L -r)" "." michael@0: michael@0: echo "$SCRIPTNAME: List the FIPS module certificates -----------------" michael@0: echo "certutil -d ${P_R_FIPSDIR} -L" michael@0: certs=`${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1` michael@0: ret=$? michael@0: echo "${certs}" michael@0: if [ ${ret} -eq 0 ]; then michael@0: echo "${certs}" | grep FIPS_PUB_140_Test_Certificate > /dev/null michael@0: ret=$? michael@0: fi michael@0: html_msg $ret 0 "List the FIPS module certificates (certutil -L)" "." michael@0: michael@0: michael@0: echo "$SCRIPTNAME: Delete the certificate and key from the FIPS module" michael@0: echo "certutil -d ${P_R_FIPSDIR} -F -n ${FIPSCERTNICK} -f ${R_FIPSPWFILE}" michael@0: ${BINDIR}/certutil -d ${P_R_FIPSDIR} -F -n ${FIPSCERTNICK} -f ${R_FIPSPWFILE} 2>&1 michael@0: html_msg $? 0 "Delete the certificate and key from the FIPS module (certutil -F)" "." michael@0: michael@0: echo "$SCRIPTNAME: List the FIPS module certificates -----------------" michael@0: echo "certutil -d ${P_R_FIPSDIR} -L" michael@0: certs=`${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1` michael@0: ret=$? michael@0: echo "${certs}" michael@0: if [ ${ret} -eq 0 ]; then michael@0: echo "${certs}" | grep FIPS_PUB_140_Test_Certificate > /dev/null michael@0: if [ $? -eq 0 ]; then michael@0: ret=255 michael@0: fi michael@0: fi michael@0: html_msg $ret 0 "List the FIPS module certificates (certutil -L)" "." michael@0: michael@0: echo "$SCRIPTNAME: List the FIPS module keys." michael@0: echo "certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE}" michael@0: ${BINDIR}/certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE} 2>&1 michael@0: # certutil -K now returns a failure if no keys are found. This verifies that michael@0: # our delete succeded. michael@0: html_msg $? 255 "List the FIPS module keys (certutil -K)" "." michael@0: michael@0: michael@0: echo "$SCRIPTNAME: Import the certificate and key from the PKCS#12 file" michael@0: echo "pk12util -d ${P_R_FIPSDIR} -i fips140.p12 -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE}" michael@0: ${BINDIR}/pk12util -d ${P_R_FIPSDIR} -i fips140.p12 -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE} 2>&1 michael@0: html_msg $? 0 "Import the certificate and key from the PKCS#12 file (pk12util -i)" "." michael@0: michael@0: echo "$SCRIPTNAME: List the FIPS module certificates -----------------" michael@0: echo "certutil -d ${P_R_FIPSDIR} -L" michael@0: certs=`${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1` michael@0: ret=$? michael@0: echo "${certs}" michael@0: if [ ${ret} -eq 0 ]; then michael@0: echo "${certs}" | grep FIPS_PUB_140_Test_Certificate > /dev/null michael@0: ret=$? michael@0: fi michael@0: html_msg $ret 0 "List the FIPS module certificates (certutil -L)" "." michael@0: michael@0: echo "$SCRIPTNAME: List the FIPS module keys --------------------------" michael@0: echo "certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE}" michael@0: ${BINDIR}/certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE} 2>&1 michael@0: html_msg $? 0 "List the FIPS module keys (certutil -K)" "." michael@0: michael@0: michael@0: echo "$SCRIPTNAME: Delete the certificate from the FIPS module" michael@0: echo "certutil -d ${P_R_FIPSDIR} -D -n ${FIPSCERTNICK}" michael@0: ${BINDIR}/certutil -d ${P_R_FIPSDIR} -D -n ${FIPSCERTNICK} 2>&1 michael@0: html_msg $? 0 "Delete the certificate from the FIPS module (certutil -D)" "." michael@0: michael@0: echo "$SCRIPTNAME: List the FIPS module certificates -----------------" michael@0: echo "certutil -d ${P_R_FIPSDIR} -L" michael@0: certs=`${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1` michael@0: ret=$? michael@0: echo "${certs}" michael@0: if [ ${ret} -eq 0 ]; then michael@0: echo "${certs}" | grep FIPS_PUB_140_Test_Certificate > /dev/null michael@0: if [ $? -eq 0 ]; then michael@0: ret=255 michael@0: fi michael@0: fi michael@0: html_msg $ret 0 "List the FIPS module certificates (certutil -L)" "." michael@0: michael@0: michael@0: echo "$SCRIPTNAME: Import the certificate and key from the PKCS#12 file" michael@0: echo "pk12util -d ${P_R_FIPSDIR} -i fips140.p12 -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE}" michael@0: ${BINDIR}/pk12util -d ${P_R_FIPSDIR} -i fips140.p12 -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE} 2>&1 michael@0: html_msg $? 0 "Import the certificate and key from the PKCS#12 file (pk12util -i)" "." michael@0: michael@0: echo "$SCRIPTNAME: List the FIPS module certificates -----------------" michael@0: echo "certutil -d ${P_R_FIPSDIR} -L" michael@0: certs=`${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1` michael@0: ret=$? michael@0: echo "${certs}" michael@0: if [ ${ret} -eq 0 ]; then michael@0: echo "${certs}" | grep FIPS_PUB_140_Test_Certificate > /dev/null michael@0: ret=$? michael@0: fi michael@0: html_msg $ret 0 "List the FIPS module certificates (certutil -L)" "." michael@0: michael@0: echo "$SCRIPTNAME: List the FIPS module keys --------------------------" michael@0: echo "certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE}" michael@0: ${BINDIR}/certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE} 2>&1 michael@0: html_msg $? 0 "List the FIPS module keys (certutil -K)" "." michael@0: michael@0: michael@0: echo "$SCRIPTNAME: Run PK11MODE in FIPSMODE -----------------" michael@0: echo "pk11mode -d ${P_R_FIPSDIR} -p fips- -f ${R_FIPSPWFILE}" michael@0: ${BINDIR}/pk11mode -d ${P_R_FIPSDIR} -p fips- -f ${R_FIPSPWFILE} 2>&1 michael@0: html_msg $? 0 "Run PK11MODE in FIPS mode (pk11mode)" "." michael@0: michael@0: echo "$SCRIPTNAME: Run PK11MODE in Non FIPSMODE -----------------" michael@0: echo "pk11mode -d ${P_R_FIPSDIR} -p nonfips- -f ${R_FIPSPWFILE} -n" michael@0: ${BINDIR}/pk11mode -d ${P_R_FIPSDIR} -p nonfips- -f ${R_FIPSPWFILE} -n 2>&1 michael@0: html_msg $? 0 "Run PK11MODE in Non FIPS mode (pk11mode -n)" "." michael@0: michael@0: LIBDIR="${DIST}/${OBJDIR}/lib" michael@0: MANGLEDIR="${FIPSDIR}/mangle" michael@0: michael@0: # There are different versions of cp command on different systems, some of them michael@0: # copies only symlinks, others doesn't have option to disable links, so there michael@0: # is needed to copy files one by one. michael@0: echo "mkdir ${MANGLEDIR}" michael@0: mkdir ${MANGLEDIR} michael@0: for lib in `ls ${LIBDIR}`; do michael@0: echo "cp ${LIBDIR}/${lib} ${MANGLEDIR}" michael@0: cp ${LIBDIR}/${lib} ${MANGLEDIR} michael@0: done michael@0: michael@0: echo "$SCRIPTNAME: Detect mangled softoken--------------------------" michael@0: SOFTOKEN=${MANGLEDIR}/${DLL_PREFIX}softokn3.${DLL_SUFFIX} michael@0: michael@0: echo "mangling ${SOFTOKEN}" michael@0: echo "mangle -i ${SOFTOKEN} -o -8 -b 5" michael@0: # If nss was built without softoken use the system installed one. michael@0: # It's location must be specified by the package maintainer. michael@0: if [ ! -e ${MANGLEDIR}/${DLL_PREFIX}softokn3.${DLL_SUFFIX} ]; then michael@0: echo "cp ${SOFTOKEN_LIB_DIR}/${DLL_PREFIX}softokn3.${DLL_SUFFIX} ${MANGLEDIR}" michael@0: cp ${SOFTOKEN_LIB_DIR}/${DLL_PREFIX}softokn3.${DLL_SUFFIX} ${MANGLEDIR} michael@0: fi michael@0: ${BINDIR}/mangle -i ${SOFTOKEN} -o -8 -b 5 2>&1 michael@0: if [ $? -eq 0 ]; then michael@0: if [ "${OS_ARCH}" = "WINNT" ]; then michael@0: DBTEST=`which dbtest` michael@0: if [ "${OS_ARCH}" = "WINNT" -a "$OS_NAME" = "CYGWIN_NT" ]; then michael@0: DBTEST=`cygpath -m ${DBTEST}` michael@0: MANGLEDIR=`cygpath -u ${MANGLEDIR}` michael@0: fi michael@0: echo "PATH=${MANGLEDIR} ${DBTEST} -r -d ${P_R_FIPSDIR}" michael@0: PATH="${MANGLEDIR}" ${DBTEST} -r -d ${P_R_FIPSDIR} > ${TMP}/dbtestoutput.txt 2>&1 michael@0: RESULT=$? michael@0: elif [ "${OS_ARCH}" = "HP-UX" ]; then michael@0: echo "SHLIB_PATH=${MANGLEDIR} dbtest -r -d ${P_R_FIPSDIR}" michael@0: LD_LIBRARY_PATH="" SHLIB_PATH="${MANGLEDIR}" ${BINDIR}/dbtest -r -d ${P_R_FIPSDIR} > ${TMP}/dbtestoutput.txt 2>&1 michael@0: RESULT=$? michael@0: elif [ "${OS_ARCH}" = "AIX" ]; then michael@0: echo "LIBPATH=${MANGLEDIR} dbtest -r -d ${P_R_FIPSDIR}" michael@0: LIBPATH="${MANGLEDIR}" ${BINDIR}/dbtest -r -d ${P_R_FIPSDIR} > ${TMP}/dbtestoutput.txt 2>&1 michael@0: RESULT=$? michael@0: elif [ "${OS_ARCH}" = "Darwin" ]; then michael@0: echo "DYLD_LIBRARY_PATH=${MANGLEDIR} dbtest -r -d ${P_R_FIPSDIR}" michael@0: DYLD_LIBRARY_PATH="${MANGLEDIR}" ${BINDIR}/dbtest -r -d ${P_R_FIPSDIR} > ${TMP}/dbtestoutput.txt 2>&1 michael@0: RESULT=$? michael@0: else michael@0: echo "LD_LIBRARY_PATH=${MANGLEDIR} dbtest -r -d ${P_R_FIPSDIR}" michael@0: LD_LIBRARY_PATH="${MANGLEDIR}" ${BINDIR}/dbtest -r -d ${P_R_FIPSDIR} > ${TMP}/dbtestoutput.txt 2>&1 michael@0: RESULT=$? michael@0: fi michael@0: michael@0: html_msg ${RESULT} 46 "Init NSS with a corrupted library (dbtest -r)" "." michael@0: else michael@0: html_failed "Mangle ${DLL_PREFIX}softokn3.${DLL_SUFFIX}" michael@0: fi michael@0: } michael@0: michael@0: ############################## fips_cleanup ############################ michael@0: # local shell function to finish this script (no exit since it might be michael@0: # sourced) michael@0: ######################################################################## michael@0: fips_cleanup() michael@0: { michael@0: html "
" michael@0: cd ${QADIR} michael@0: . common/cleanup.sh michael@0: } michael@0: michael@0: ################## main ################################################# michael@0: michael@0: fips_init michael@0: fips_140 michael@0: fips_cleanup michael@0: echo "fips.sh done"