/security/nss/tests/fips/fips.sh

https://github.com/rillian/firefox · Shell · 293 lines · 212 code · 44 blank · 37 comment · 18 complexity · 4a87f56daaadee7033e45addeb60ad27 MD5 · raw file

  1. #! /bin/bash
  2. #
  3. # This Source Code Form is subject to the terms of the Mozilla Public
  4. # License, v. 2.0. If a copy of the MPL was not distributed with this
  5. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. ########################################################################
  7. # mozilla/security/nss/tests/fips/fips.sh
  8. #
  9. # Script to test basic functionallity of NSS in FIPS-compliant mode
  10. #
  11. # needs to work on all Unix and Windows platforms
  12. #
  13. # tests implemented:
  14. #
  15. # special strings
  16. # ---------------
  17. #
  18. ########################################################################
  19. ############################## fips_init ##############################
  20. # local shell function to initialize this script
  21. ########################################################################
  22. fips_init()
  23. {
  24. SCRIPTNAME=fips.sh # sourced - $0 would point to all.sh
  25. if [ -z "${CLEANUP}" ] ; then # if nobody else is responsible for
  26. CLEANUP="${SCRIPTNAME}" # cleaning this script will do it
  27. fi
  28. if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then
  29. cd ../common
  30. . ./init.sh
  31. fi
  32. if [ ! -r $CERT_LOG_FILE ]; then # we need certificates here
  33. cd ../cert
  34. . ./cert.sh
  35. fi
  36. SCRIPTNAME=fips.sh
  37. html_head "FIPS 140 Compliance Tests"
  38. grep "SUCCESS: FIPS passed" $CERT_LOG_FILE >/dev/null || {
  39. Exit 15 "Fatal - FIPS of cert.sh needs to pass first"
  40. }
  41. COPYDIR=${FIPSDIR}/copydir
  42. R_FIPSDIR=../fips
  43. P_R_FIPSDIR=../fips
  44. R_COPYDIR=../fips/copydir
  45. if [ -n "${MULTIACCESS_DBM}" ]; then
  46. P_R_FIPSDIR="multiaccess:${D_FIPS}"
  47. fi
  48. mkdir -p ${FIPSDIR}
  49. mkdir -p ${COPYDIR}
  50. cd ${FIPSDIR}
  51. }
  52. ############################## fips_140 ##############################
  53. # local shell function to test basic functionality of NSS while in
  54. # FIPS 140 compliant mode
  55. ########################################################################
  56. fips_140()
  57. {
  58. echo "$SCRIPTNAME: Verify this module is in FIPS mode -----------------"
  59. echo "modutil -dbdir ${P_R_FIPSDIR} -list"
  60. ${BINDIR}/modutil -dbdir ${P_R_FIPSDIR} -list 2>&1
  61. ${BINDIR}/modutil -dbdir ${P_R_FIPSDIR} -chkfips true 2>&1
  62. html_msg $? 0 "Verify this module is in FIPS mode (modutil -chkfips true)" "."
  63. echo "$SCRIPTNAME: List the FIPS module certificates -----------------"
  64. echo "certutil -d ${P_R_FIPSDIR} -L"
  65. ${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1
  66. html_msg $? 0 "List the FIPS module certificates (certutil -L)" "."
  67. echo "$SCRIPTNAME: List the FIPS module keys -------------------------"
  68. echo "certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE}"
  69. ${BINDIR}/certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE} 2>&1
  70. html_msg $? 0 "List the FIPS module keys (certutil -K)" "."
  71. echo "$SCRIPTNAME: Attempt to list FIPS module keys with incorrect password"
  72. echo "certutil -d ${P_R_FIPSDIR} -K -f ${FIPSBADPWFILE}"
  73. ${BINDIR}/certutil -d ${P_R_FIPSDIR} -K -f ${FIPSBADPWFILE} 2>&1
  74. RET=$?
  75. html_msg $RET 255 "Attempt to list FIPS module keys with incorrect password (certutil -K)" "."
  76. echo "certutil -K returned $RET"
  77. echo "$SCRIPTNAME: Validate the certificate --------------------------"
  78. echo "certutil -d ${P_R_FIPSDIR} -V -n ${FIPSCERTNICK} -u SR -e -f ${R_FIPSPWFILE}"
  79. ${BINDIR}/certutil -d ${P_R_FIPSDIR} -V -n ${FIPSCERTNICK} -u SR -e -f ${R_FIPSPWFILE}
  80. html_msg $? 0 "Validate the certificate (certutil -V -e)" "."
  81. echo "$SCRIPTNAME: Export the certificate and key as a PKCS#12 file --"
  82. echo "pk12util -d ${P_R_FIPSDIR} -o fips140.p12 -n ${FIPSCERTNICK} -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE}"
  83. ${BINDIR}/pk12util -d ${P_R_FIPSDIR} -o fips140.p12 -n ${FIPSCERTNICK} -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE} 2>&1
  84. html_msg $? 0 "Export the certificate and key as a PKCS#12 file (pk12util -o)" "."
  85. echo "$SCRIPTNAME: Export the certificate as a DER-encoded file ------"
  86. echo "certutil -d ${P_R_FIPSDIR} -L -n ${FIPSCERTNICK} -r -o fips140.crt"
  87. ${BINDIR}/certutil -d ${P_R_FIPSDIR} -L -n ${FIPSCERTNICK} -r -o fips140.crt 2>&1
  88. html_msg $? 0 "Export the certificate as a DER (certutil -L -r)" "."
  89. echo "$SCRIPTNAME: List the FIPS module certificates -----------------"
  90. echo "certutil -d ${P_R_FIPSDIR} -L"
  91. certs=`${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1`
  92. ret=$?
  93. echo "${certs}"
  94. if [ ${ret} -eq 0 ]; then
  95. echo "${certs}" | grep FIPS_PUB_140_Test_Certificate > /dev/null
  96. ret=$?
  97. fi
  98. html_msg $ret 0 "List the FIPS module certificates (certutil -L)" "."
  99. echo "$SCRIPTNAME: Delete the certificate and key from the FIPS module"
  100. echo "certutil -d ${P_R_FIPSDIR} -F -n ${FIPSCERTNICK} -f ${R_FIPSPWFILE}"
  101. ${BINDIR}/certutil -d ${P_R_FIPSDIR} -F -n ${FIPSCERTNICK} -f ${R_FIPSPWFILE} 2>&1
  102. html_msg $? 0 "Delete the certificate and key from the FIPS module (certutil -F)" "."
  103. echo "$SCRIPTNAME: List the FIPS module certificates -----------------"
  104. echo "certutil -d ${P_R_FIPSDIR} -L"
  105. certs=`${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1`
  106. ret=$?
  107. echo "${certs}"
  108. if [ ${ret} -eq 0 ]; then
  109. echo "${certs}" | grep FIPS_PUB_140_Test_Certificate > /dev/null
  110. if [ $? -eq 0 ]; then
  111. ret=255
  112. fi
  113. fi
  114. html_msg $ret 0 "List the FIPS module certificates (certutil -L)" "."
  115. echo "$SCRIPTNAME: List the FIPS module keys."
  116. echo "certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE}"
  117. ${BINDIR}/certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE} 2>&1
  118. # certutil -K now returns a failure if no keys are found. This verifies that
  119. # our delete succeded.
  120. html_msg $? 255 "List the FIPS module keys (certutil -K)" "."
  121. echo "$SCRIPTNAME: Import the certificate and key from the PKCS#12 file"
  122. echo "pk12util -d ${P_R_FIPSDIR} -i fips140.p12 -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE}"
  123. ${BINDIR}/pk12util -d ${P_R_FIPSDIR} -i fips140.p12 -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE} 2>&1
  124. html_msg $? 0 "Import the certificate and key from the PKCS#12 file (pk12util -i)" "."
  125. echo "$SCRIPTNAME: List the FIPS module certificates -----------------"
  126. echo "certutil -d ${P_R_FIPSDIR} -L"
  127. certs=`${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1`
  128. ret=$?
  129. echo "${certs}"
  130. if [ ${ret} -eq 0 ]; then
  131. echo "${certs}" | grep FIPS_PUB_140_Test_Certificate > /dev/null
  132. ret=$?
  133. fi
  134. html_msg $ret 0 "List the FIPS module certificates (certutil -L)" "."
  135. echo "$SCRIPTNAME: List the FIPS module keys --------------------------"
  136. echo "certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE}"
  137. ${BINDIR}/certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE} 2>&1
  138. html_msg $? 0 "List the FIPS module keys (certutil -K)" "."
  139. echo "$SCRIPTNAME: Delete the certificate from the FIPS module"
  140. echo "certutil -d ${P_R_FIPSDIR} -D -n ${FIPSCERTNICK}"
  141. ${BINDIR}/certutil -d ${P_R_FIPSDIR} -D -n ${FIPSCERTNICK} 2>&1
  142. html_msg $? 0 "Delete the certificate from the FIPS module (certutil -D)" "."
  143. echo "$SCRIPTNAME: List the FIPS module certificates -----------------"
  144. echo "certutil -d ${P_R_FIPSDIR} -L"
  145. certs=`${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1`
  146. ret=$?
  147. echo "${certs}"
  148. if [ ${ret} -eq 0 ]; then
  149. echo "${certs}" | grep FIPS_PUB_140_Test_Certificate > /dev/null
  150. if [ $? -eq 0 ]; then
  151. ret=255
  152. fi
  153. fi
  154. html_msg $ret 0 "List the FIPS module certificates (certutil -L)" "."
  155. echo "$SCRIPTNAME: Import the certificate and key from the PKCS#12 file"
  156. echo "pk12util -d ${P_R_FIPSDIR} -i fips140.p12 -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE}"
  157. ${BINDIR}/pk12util -d ${P_R_FIPSDIR} -i fips140.p12 -w ${R_FIPSP12PWFILE} -k ${R_FIPSPWFILE} 2>&1
  158. html_msg $? 0 "Import the certificate and key from the PKCS#12 file (pk12util -i)" "."
  159. echo "$SCRIPTNAME: List the FIPS module certificates -----------------"
  160. echo "certutil -d ${P_R_FIPSDIR} -L"
  161. certs=`${BINDIR}/certutil -d ${P_R_FIPSDIR} -L 2>&1`
  162. ret=$?
  163. echo "${certs}"
  164. if [ ${ret} -eq 0 ]; then
  165. echo "${certs}" | grep FIPS_PUB_140_Test_Certificate > /dev/null
  166. ret=$?
  167. fi
  168. html_msg $ret 0 "List the FIPS module certificates (certutil -L)" "."
  169. echo "$SCRIPTNAME: List the FIPS module keys --------------------------"
  170. echo "certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE}"
  171. ${BINDIR}/certutil -d ${P_R_FIPSDIR} -K -f ${R_FIPSPWFILE} 2>&1
  172. html_msg $? 0 "List the FIPS module keys (certutil -K)" "."
  173. echo "$SCRIPTNAME: Run PK11MODE in FIPSMODE -----------------"
  174. echo "pk11mode -d ${P_R_FIPSDIR} -p fips- -f ${R_FIPSPWFILE}"
  175. ${BINDIR}/pk11mode -d ${P_R_FIPSDIR} -p fips- -f ${R_FIPSPWFILE} 2>&1
  176. html_msg $? 0 "Run PK11MODE in FIPS mode (pk11mode)" "."
  177. echo "$SCRIPTNAME: Run PK11MODE in Non FIPSMODE -----------------"
  178. echo "pk11mode -d ${P_R_FIPSDIR} -p nonfips- -f ${R_FIPSPWFILE} -n"
  179. ${BINDIR}/pk11mode -d ${P_R_FIPSDIR} -p nonfips- -f ${R_FIPSPWFILE} -n 2>&1
  180. html_msg $? 0 "Run PK11MODE in Non FIPS mode (pk11mode -n)" "."
  181. LIBDIR="${DIST}/${OBJDIR}/lib"
  182. MANGLEDIR="${FIPSDIR}/mangle"
  183. # There are different versions of cp command on different systems, some of them
  184. # copies only symlinks, others doesn't have option to disable links, so there
  185. # is needed to copy files one by one.
  186. echo "mkdir ${MANGLEDIR}"
  187. mkdir ${MANGLEDIR}
  188. for lib in `ls ${LIBDIR}`; do
  189. echo "cp ${LIBDIR}/${lib} ${MANGLEDIR}"
  190. cp ${LIBDIR}/${lib} ${MANGLEDIR}
  191. done
  192. echo "$SCRIPTNAME: Detect mangled softoken--------------------------"
  193. SOFTOKEN=${MANGLEDIR}/${DLL_PREFIX}softokn3.${DLL_SUFFIX}
  194. echo "mangling ${SOFTOKEN}"
  195. echo "mangle -i ${SOFTOKEN} -o -8 -b 5"
  196. # If nss was built without softoken use the system installed one.
  197. # It's location must be specified by the package maintainer.
  198. if [ ! -e ${MANGLEDIR}/${DLL_PREFIX}softokn3.${DLL_SUFFIX} ]; then
  199. echo "cp ${SOFTOKEN_LIB_DIR}/${DLL_PREFIX}softokn3.${DLL_SUFFIX} ${MANGLEDIR}"
  200. cp ${SOFTOKEN_LIB_DIR}/${DLL_PREFIX}softokn3.${DLL_SUFFIX} ${MANGLEDIR}
  201. fi
  202. ${BINDIR}/mangle -i ${SOFTOKEN} -o -8 -b 5 2>&1
  203. if [ $? -eq 0 ]; then
  204. if [ "${OS_ARCH}" = "WINNT" ]; then
  205. DBTEST=`which dbtest`
  206. if [ "${OS_ARCH}" = "WINNT" -a "$OS_NAME" = "CYGWIN_NT" ]; then
  207. DBTEST=`cygpath -m ${DBTEST}`
  208. MANGLEDIR=`cygpath -u ${MANGLEDIR}`
  209. fi
  210. echo "PATH=${MANGLEDIR} ${DBTEST} -r -d ${P_R_FIPSDIR}"
  211. PATH="${MANGLEDIR}" ${DBTEST} -r -d ${P_R_FIPSDIR} > ${TMP}/dbtestoutput.txt 2>&1
  212. RESULT=$?
  213. elif [ "${OS_ARCH}" = "HP-UX" ]; then
  214. echo "SHLIB_PATH=${MANGLEDIR} dbtest -r -d ${P_R_FIPSDIR}"
  215. LD_LIBRARY_PATH="" SHLIB_PATH="${MANGLEDIR}" ${BINDIR}/dbtest -r -d ${P_R_FIPSDIR} > ${TMP}/dbtestoutput.txt 2>&1
  216. RESULT=$?
  217. elif [ "${OS_ARCH}" = "AIX" ]; then
  218. echo "LIBPATH=${MANGLEDIR} dbtest -r -d ${P_R_FIPSDIR}"
  219. LIBPATH="${MANGLEDIR}" ${BINDIR}/dbtest -r -d ${P_R_FIPSDIR} > ${TMP}/dbtestoutput.txt 2>&1
  220. RESULT=$?
  221. elif [ "${OS_ARCH}" = "Darwin" ]; then
  222. echo "DYLD_LIBRARY_PATH=${MANGLEDIR} dbtest -r -d ${P_R_FIPSDIR}"
  223. DYLD_LIBRARY_PATH="${MANGLEDIR}" ${BINDIR}/dbtest -r -d ${P_R_FIPSDIR} > ${TMP}/dbtestoutput.txt 2>&1
  224. RESULT=$?
  225. else
  226. echo "LD_LIBRARY_PATH=${MANGLEDIR} dbtest -r -d ${P_R_FIPSDIR}"
  227. LD_LIBRARY_PATH="${MANGLEDIR}" ${BINDIR}/dbtest -r -d ${P_R_FIPSDIR} > ${TMP}/dbtestoutput.txt 2>&1
  228. RESULT=$?
  229. fi
  230. html_msg ${RESULT} 46 "Init NSS with a corrupted library (dbtest -r)" "."
  231. else
  232. html_failed "Mangle ${DLL_PREFIX}softokn3.${DLL_SUFFIX}"
  233. fi
  234. }
  235. ############################## fips_cleanup ############################
  236. # local shell function to finish this script (no exit since it might be
  237. # sourced)
  238. ########################################################################
  239. fips_cleanup()
  240. {
  241. html "</TABLE><BR>"
  242. cd ${QADIR}
  243. . common/cleanup.sh
  244. }
  245. ################## main #################################################
  246. fips_init
  247. fips_140
  248. fips_cleanup
  249. echo "fips.sh done"