PageRenderTime 372ms CodeModel.GetById 48ms RepoModel.GetById 4ms app.codeStats 1ms

/security/nss/tests/cert/cert.sh

http://github.com/zpao/v8monkey
Shell | 1509 lines | 1133 code | 155 blank | 221 comment | 125 complexity | 340be479f3f40930c01bddd082a68a62 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, LGPL-2.1, BSD-3-Clause, GPL-2.0, JSON, Apache-2.0, 0BSD
  1. #! /bin/bash
  2. #
  3. # ***** BEGIN LICENSE BLOCK *****
  4. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. #
  6. # The contents of this file are subject to the Mozilla Public License Version
  7. # 1.1 (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. # http://www.mozilla.org/MPL/
  10. #
  11. # Software distributed under the License is distributed on an "AS IS" basis,
  12. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. # for the specific language governing rights and limitations under the
  14. # License.
  15. #
  16. # The Original Code is the Netscape security libraries.
  17. #
  18. # The Initial Developer of the Original Code is
  19. # Netscape Communications Corporation.
  20. # Portions created by the Initial Developer are Copyright (C) 1994-2009
  21. # the Initial Developer. All Rights Reserved.
  22. #
  23. # Contributor(s):
  24. # Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
  25. # Slavomir Katuscak <slavomir.katuscak@sun.com>, Sun Microsystems
  26. #
  27. # Alternatively, the contents of this file may be used under the terms of
  28. # either the GNU General Public License Version 2 or later (the "GPL"), or
  29. # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30. # in which case the provisions of the GPL or the LGPL are applicable instead
  31. # of those above. If you wish to allow use of your version of this file only
  32. # under the terms of either the GPL or the LGPL, and not to allow others to
  33. # use your version of this file under the terms of the MPL, indicate your
  34. # decision by deleting the provisions above and replace them with the notice
  35. # and other provisions required by the GPL or the LGPL. If you do not delete
  36. # the provisions above, a recipient may use your version of this file under
  37. # the terms of any one of the MPL, the GPL or the LGPL.
  38. #
  39. # ***** END LICENSE BLOCK *****
  40. ########################################################################
  41. #
  42. # mozilla/security/nss/tests/cert/rcert.sh
  43. #
  44. # Certificate generating and handeling for NSS QA, can be included
  45. # multiple times from all.sh and the individual scripts
  46. #
  47. # needs to work on all Unix and Windows platforms
  48. #
  49. # included from (don't expect this to be up to date)
  50. # --------------------------------------------------
  51. # all.sh
  52. # ssl.sh
  53. # smime.sh
  54. # tools.sh
  55. #
  56. # special strings
  57. # ---------------
  58. # FIXME ... known problems, search for this string
  59. # NOTE .... unexpected behavior
  60. #
  61. # FIXME - Netscape - NSS
  62. ########################################################################
  63. ############################## cert_init ###############################
  64. # local shell function to initialize this script
  65. ########################################################################
  66. cert_init()
  67. {
  68. SCRIPTNAME="cert.sh"
  69. if [ -z "${CLEANUP}" ] ; then # if nobody else is responsible for
  70. CLEANUP="${SCRIPTNAME}" # cleaning this script will do it
  71. fi
  72. if [ -z "${INIT_SOURCED}" ] ; then
  73. cd ../common
  74. . ./init.sh
  75. fi
  76. if [ -z "${IOPR_CERT_SOURCED}" ]; then
  77. . ../iopr/cert_iopr.sh
  78. fi
  79. SCRIPTNAME="cert.sh"
  80. CRL_GRP_DATE=`date -u "+%Y%m%d%H%M%SZ"`
  81. if [ -n "$NSS_ENABLE_ECC" ] ; then
  82. html_head "Certutil and Crlutil Tests with ECC"
  83. else
  84. html_head "Certutil and Crlutil Tests"
  85. fi
  86. LIBDIR="${DIST}/${OBJDIR}/lib"
  87. ROOTCERTSFILE=`ls -1 ${LIBDIR}/*nssckbi* | head -1`
  88. if [ ! "${ROOTCERTSFILE}" ] ; then
  89. html_failed "Looking for root certs module."
  90. cert_log "ERROR: Root certs module not found."
  91. Exit 5 "Fatal - Root certs module not found."
  92. else
  93. html_passed "Looking for root certs module."
  94. fi
  95. if [ "${OS_ARCH}" = "WINNT" -a "$OS_NAME" = "CYGWIN_NT" ]; then
  96. ROOTCERTSFILE=`cygpath -m ${ROOTCERTSFILE}`
  97. fi
  98. }
  99. cert_log() ###################### write the cert_status file
  100. {
  101. echo "$SCRIPTNAME $*"
  102. echo $* >>${CERT_LOG_FILE}
  103. }
  104. ################################ certu #################################
  105. # local shell function to call certutil, also: writes action and options to
  106. # stdout, sets variable RET and writes results to the html file results
  107. ########################################################################
  108. certu()
  109. {
  110. echo "$SCRIPTNAME: ${CU_ACTION} --------------------------"
  111. EXPECTED=${RETEXPECTED-0}
  112. if [ -n "${CU_SUBJECT}" ]; then
  113. #the subject of the cert contains blanks, and the shell
  114. #will strip the quotes off the string, if called otherwise...
  115. echo "certutil -s \"${CU_SUBJECT}\" $*"
  116. ${PROFTOOL} ${BINDIR}/certutil -s "${CU_SUBJECT}" $*
  117. RET=$?
  118. CU_SUBJECT=""
  119. else
  120. echo "certutil $*"
  121. ${PROFTOOL} ${BINDIR}/certutil $*
  122. RET=$?
  123. fi
  124. if [ "$RET" -ne "$EXPECTED" ]; then
  125. CERTFAILED=$RET
  126. html_failed "${CU_ACTION} ($RET=$EXPECTED) "
  127. cert_log "ERROR: ${CU_ACTION} failed $RET"
  128. else
  129. html_passed "${CU_ACTION}"
  130. fi
  131. return $RET
  132. }
  133. ################################ crlu #################################
  134. # local shell function to call crlutil, also: writes action and options to
  135. # stdout, sets variable RET and writes results to the html file results
  136. ########################################################################
  137. crlu()
  138. {
  139. echo "$SCRIPTNAME: ${CU_ACTION} --------------------------"
  140. CRLUTIL="crlutil -q"
  141. echo "$CRLUTIL $*"
  142. ${PROFTOOL} ${BINDIR}/$CRLUTIL $*
  143. RET=$?
  144. if [ "$RET" -ne 0 ]; then
  145. CRLFAILED=$RET
  146. html_failed "${CU_ACTION} ($RET) "
  147. cert_log "ERROR: ${CU_ACTION} failed $RET"
  148. else
  149. html_passed "${CU_ACTION}"
  150. fi
  151. return $RET
  152. }
  153. modu()
  154. {
  155. echo "$SCRIPTNAME: ${CU_ACTION} --------------------------"
  156. MODUTIL="modutil"
  157. echo "$MODUTIL $*"
  158. # echo is used to press Enter expected by modutil
  159. echo | ${BINDIR}/$MODUTIL $*
  160. RET=$?
  161. if [ "$RET" -ne 0 ]; then
  162. MODFAILED=$RET
  163. html_failed "${CU_ACTION} ($RET) "
  164. cert_log "ERROR: ${CU_ACTION} failed $RET"
  165. else
  166. html_passed "${CU_ACTION}"
  167. fi
  168. return $RET
  169. }
  170. ############################# cert_init_cert ##########################
  171. # local shell function to initialize creation of client and server certs
  172. ########################################################################
  173. cert_init_cert()
  174. {
  175. CERTDIR="$1"
  176. CERTNAME="$2"
  177. CERTSERIAL="$3"
  178. DOMAIN="$4"
  179. if [ ! -d "${CERTDIR}" ]; then
  180. mkdir -p "${CERTDIR}"
  181. else
  182. echo "$SCRIPTNAME: WARNING - ${CERTDIR} exists"
  183. fi
  184. cd "${CERTDIR}"
  185. CERTDIR="."
  186. PROFILEDIR=`cd ${CERTDIR}; pwd`
  187. if [ "${OS_ARCH}" = "WINNT" -a "$OS_NAME" = "CYGWIN_NT" ]; then
  188. PROFILEDIR=`cygpath -m ${PROFILEDIR}`
  189. fi
  190. if [ -n "${MULTIACCESS_DBM}" ]; then
  191. PROFILEDIR="multiaccess:${DOMAIN}"
  192. fi
  193. noise
  194. }
  195. ############################# hw_acc #################################
  196. # local shell function to add hw accelerator modules to the db
  197. ########################################################################
  198. hw_acc()
  199. {
  200. HW_ACC_RET=0
  201. HW_ACC_ERR=""
  202. if [ -n "$O_HWACC" -a "$O_HWACC" = ON -a -z "$USE_64" ] ; then
  203. echo "creating $CERTNAME s cert with hwaccelerator..."
  204. #case $ACCELERATOR in
  205. #rainbow)
  206. echo "modutil -add rainbow -libfile /usr/lib/libcryptoki22.so "
  207. echo " -dbdir ${PROFILEDIR} 2>&1 "
  208. echo | ${BINDIR}/modutil -add rainbow -libfile /usr/lib/libcryptoki22.so \
  209. -dbdir ${PROFILEDIR} 2>&1
  210. if [ "$?" -ne 0 ]; then
  211. echo "modutil -add rainbow failed in `pwd`"
  212. HW_ACC_RET=1
  213. HW_ACC_ERR="modutil -add rainbow"
  214. fi
  215. echo "modutil -add ncipher "
  216. echo " -libfile /opt/nfast/toolkits/pkcs11/libcknfast.so "
  217. echo " -dbdir ${PROFILEDIR} 2>&1 "
  218. echo | ${BINDIR}/modutil -add ncipher \
  219. -libfile /opt/nfast/toolkits/pkcs11/libcknfast.so \
  220. -dbdir ${PROFILEDIR} 2>&1
  221. if [ "$?" -ne 0 ]; then
  222. echo "modutil -add ncipher failed in `pwd`"
  223. HW_ACC_RET=`expr $HW_ACC_RET + 2`
  224. HW_ACC_ERR="$HW_ACC_ERR,modutil -add ncipher"
  225. fi
  226. if [ "$HW_ACC_RET" -ne 0 ]; then
  227. html_failed "Adding HW accelerators to certDB for ${CERTNAME} ($HW_ACC_RET) "
  228. else
  229. html_passed "Adding HW accelerators to certDB for ${CERTNAME}"
  230. fi
  231. fi
  232. return $HW_ACC_RET
  233. }
  234. ############################# cert_create_cert #########################
  235. # local shell function to create client certs
  236. # initialize DB, import
  237. # root cert
  238. # add cert to DB
  239. ########################################################################
  240. cert_create_cert()
  241. {
  242. cert_init_cert "$1" "$2" "$3" "$4"
  243. CU_ACTION="Initializing ${CERTNAME}'s Cert DB"
  244. certu -N -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  245. if [ "$RET" -ne 0 ]; then
  246. return $RET
  247. fi
  248. CU_ACTION="Loading root cert module to ${CERTNAME}'s Cert DB"
  249. modu -add "RootCerts" -libfile "${ROOTCERTSFILE}" -dbdir "${PROFILEDIR}" 2>&1
  250. if [ "$RET" -ne 0 ]; then
  251. return $RET
  252. fi
  253. hw_acc
  254. CU_ACTION="Import Root CA for $CERTNAME"
  255. certu -A -n "TestCA" -t "TC,TC,TC" -f "${R_PWFILE}" -d "${PROFILEDIR}" \
  256. -i "${R_CADIR}/TestCA.ca.cert" 2>&1
  257. if [ "$RET" -ne 0 ]; then
  258. return $RET
  259. fi
  260. if [ -n "$NSS_ENABLE_ECC" ] ; then
  261. CU_ACTION="Import EC Root CA for $CERTNAME"
  262. certu -A -n "TestCA-ec" -t "TC,TC,TC" -f "${R_PWFILE}" \
  263. -d "${PROFILEDIR}" -i "${R_CADIR}/TestCA-ec.ca.cert" 2>&1
  264. if [ "$RET" -ne 0 ]; then
  265. return $RET
  266. fi
  267. fi
  268. cert_add_cert "$5"
  269. return $?
  270. }
  271. ############################# cert_add_cert ############################
  272. # local shell function to add client certs to an existing CERT DB
  273. # generate request
  274. # sign request
  275. # import Cert
  276. #
  277. ########################################################################
  278. cert_add_cert()
  279. {
  280. CU_ACTION="Generate Cert Request for $CERTNAME"
  281. CU_SUBJECT="CN=$CERTNAME, E=${CERTNAME}@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  282. certu -R -d "${PROFILEDIR}" -f "${R_PWFILE}" -z "${R_NOISE_FILE}" -o req 2>&1
  283. if [ "$RET" -ne 0 ]; then
  284. return $RET
  285. fi
  286. CU_ACTION="Sign ${CERTNAME}'s Request"
  287. certu -C -c "TestCA" -m "$CERTSERIAL" -v 60 -d "${P_R_CADIR}" \
  288. -i req -o "${CERTNAME}.cert" -f "${R_PWFILE}" "$1" 2>&1
  289. if [ "$RET" -ne 0 ]; then
  290. return $RET
  291. fi
  292. CU_ACTION="Import $CERTNAME's Cert"
  293. certu -A -n "$CERTNAME" -t "u,u,u" -d "${PROFILEDIR}" -f "${R_PWFILE}" \
  294. -i "${CERTNAME}.cert" 2>&1
  295. if [ "$RET" -ne 0 ]; then
  296. return $RET
  297. fi
  298. cert_log "SUCCESS: $CERTNAME's Cert Created"
  299. #
  300. # Generate and add EC cert
  301. #
  302. if [ -n "$NSS_ENABLE_ECC" ] ; then
  303. CURVE="secp384r1"
  304. CU_ACTION="Generate EC Cert Request for $CERTNAME"
  305. CU_SUBJECT="CN=$CERTNAME, E=${CERTNAME}-ec@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  306. certu -R -k ec -q "${CURVE}" -d "${PROFILEDIR}" -f "${R_PWFILE}" \
  307. -z "${R_NOISE_FILE}" -o req 2>&1
  308. if [ "$RET" -ne 0 ]; then
  309. return $RET
  310. fi
  311. CU_ACTION="Sign ${CERTNAME}'s EC Request"
  312. certu -C -c "TestCA-ec" -m "$CERTSERIAL" -v 60 -d "${P_R_CADIR}" \
  313. -i req -o "${CERTNAME}-ec.cert" -f "${R_PWFILE}" "$1" 2>&1
  314. if [ "$RET" -ne 0 ]; then
  315. return $RET
  316. fi
  317. CU_ACTION="Import $CERTNAME's EC Cert"
  318. certu -A -n "${CERTNAME}-ec" -t "u,u,u" -d "${PROFILEDIR}" \
  319. -f "${R_PWFILE}" -i "${CERTNAME}-ec.cert" 2>&1
  320. if [ "$RET" -ne 0 ]; then
  321. return $RET
  322. fi
  323. cert_log "SUCCESS: $CERTNAME's EC Cert Created"
  324. # Generate EC certificate signed with RSA
  325. CU_ACTION="Generate mixed EC Cert Request for $CERTNAME"
  326. CU_SUBJECT="CN=$CERTNAME, E=${CERTNAME}-ecmixed@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  327. certu -R -k ec -q "${CURVE}" -d "${PROFILEDIR}" -f "${R_PWFILE}" \
  328. -z "${R_NOISE_FILE}" -o req 2>&1
  329. if [ "$RET" -ne 0 ]; then
  330. return $RET
  331. fi
  332. CU_ACTION="Sign ${CERTNAME}'s EC Request with RSA"
  333. # Avoid conflicting serial numbers with TestCA issuer by keeping
  334. # this set far away. A smaller number risks colliding with the
  335. # extended ssl user certificates.
  336. NEWSERIAL=`expr ${CERTSERIAL} + 10000`
  337. certu -C -c "TestCA" -m "$NEWSERIAL" -v 60 -d "${P_R_CADIR}" \
  338. -i req -o "${CERTNAME}-ecmixed.cert" -f "${R_PWFILE}" "$1" 2>&1
  339. if [ "$RET" -ne 0 ]; then
  340. return $RET
  341. fi
  342. CU_ACTION="Import $CERTNAME's mixed EC Cert"
  343. certu -A -n "${CERTNAME}-ecmixed" -t "u,u,u" -d "${PROFILEDIR}" \
  344. -f "${R_PWFILE}" -i "${CERTNAME}-ecmixed.cert" 2>&1
  345. if [ "$RET" -ne 0 ]; then
  346. return $RET
  347. fi
  348. cert_log "SUCCESS: $CERTNAME's mixed EC Cert Created"
  349. fi
  350. return 0
  351. }
  352. ################################# cert_all_CA ################################
  353. # local shell function to build the additional Temp. Certificate Authority (CA)
  354. # used for the "real life" ssl test with 2 different CA's in the
  355. # client and in the server's dir
  356. ##########################################################################
  357. cert_all_CA()
  358. {
  359. echo nss > ${PWFILE}
  360. ALL_CU_SUBJECT="CN=NSS Test CA, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  361. cert_CA $CADIR TestCA -x "CTu,CTu,CTu" ${D_CA} "1"
  362. ALL_CU_SUBJECT="CN=NSS Server Test CA, O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  363. cert_CA $SERVER_CADIR serverCA -x "Cu,Cu,Cu" ${D_SERVER_CA} "2"
  364. ALL_CU_SUBJECT="CN=NSS Chain1 Server Test CA, O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  365. cert_CA $SERVER_CADIR chain-1-serverCA "-c serverCA" "u,u,u" ${D_SERVER_CA} "3"
  366. ALL_CU_SUBJECT="CN=NSS Chain2 Server Test CA, O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  367. cert_CA $SERVER_CADIR chain-2-serverCA "-c chain-1-serverCA" "u,u,u" ${D_SERVER_CA} "4"
  368. ALL_CU_SUBJECT="CN=NSS Client Test CA, O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  369. cert_CA $CLIENT_CADIR clientCA -x "Tu,Cu,Cu" ${D_CLIENT_CA} "5"
  370. ALL_CU_SUBJECT="CN=NSS Chain1 Client Test CA, O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  371. cert_CA $CLIENT_CADIR chain-1-clientCA "-c clientCA" "u,u,u" ${D_CLIENT_CA} "6"
  372. ALL_CU_SUBJECT="CN=NSS Chain2 Client Test CA, O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  373. cert_CA $CLIENT_CADIR chain-2-clientCA "-c chain-1-clientCA" "u,u,u" ${D_CLIENT_CA} "7"
  374. rm $CLIENT_CADIR/root.cert $SERVER_CADIR/root.cert
  375. # root.cert in $CLIENT_CADIR and in $SERVER_CADIR is one of the last
  376. # in the chain
  377. if [ -n "$NSS_ENABLE_ECC" ] ; then
  378. #
  379. # Create EC version of TestCA
  380. CA_CURVE="secp521r1"
  381. ALL_CU_SUBJECT="CN=NSS Test CA (ECC), O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  382. cert_ec_CA $CADIR TestCA-ec -x "CTu,CTu,CTu" ${D_CA} "1" ${CA_CURVE}
  383. #
  384. # Create EC versions of the intermediate CA certs
  385. ALL_CU_SUBJECT="CN=NSS Server Test CA (ECC), O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  386. cert_ec_CA $SERVER_CADIR serverCA-ec -x "Cu,Cu,Cu" ${D_SERVER_CA} "2" ${CA_CURVE}
  387. ALL_CU_SUBJECT="CN=NSS Chain1 Server Test CA (ECC), O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  388. cert_ec_CA $SERVER_CADIR chain-1-serverCA-ec "-c serverCA-ec" "u,u,u" ${D_SERVER_CA} "3" ${CA_CURVE}
  389. ALL_CU_SUBJECT="CN=NSS Chain2 Server Test CA (ECC), O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  390. cert_ec_CA $SERVER_CADIR chain-2-serverCA-ec "-c chain-1-serverCA-ec" "u,u,u" ${D_SERVER_CA} "4" ${CA_CURVE}
  391. ALL_CU_SUBJECT="CN=NSS Client Test CA (ECC), O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  392. cert_ec_CA $CLIENT_CADIR clientCA-ec -x "Tu,Cu,Cu" ${D_CLIENT_CA} "5" ${CA_CURVE}
  393. ALL_CU_SUBJECT="CN=NSS Chain1 Client Test CA (ECC), O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  394. cert_ec_CA $CLIENT_CADIR chain-1-clientCA-ec "-c clientCA-ec" "u,u,u" ${D_CLIENT_CA} "6" ${CA_CURVE}
  395. ALL_CU_SUBJECT="CN=NSS Chain2 Client Test CA (ECC), O=BOGUS NSS, L=Santa Clara, ST=California, C=US"
  396. cert_ec_CA $CLIENT_CADIR chain-2-clientCA-ec "-c chain-1-clientCA-ec" "u,u,u" ${D_CLIENT_CA} "7" ${CA_CURVE}
  397. rm $CLIENT_CADIR/ecroot.cert $SERVER_CADIR/ecroot.cert
  398. # ecroot.cert in $CLIENT_CADIR and in $SERVER_CADIR is one of the last
  399. # in the chain
  400. fi
  401. }
  402. ################################# cert_CA ################################
  403. # local shell function to build the Temp. Certificate Authority (CA)
  404. # used for testing purposes, creating a CA Certificate and a root cert
  405. ##########################################################################
  406. cert_CA()
  407. {
  408. CUR_CADIR=$1
  409. NICKNAME=$2
  410. SIGNER=$3
  411. TRUSTARG=$4
  412. DOMAIN=$5
  413. CERTSERIAL=$6
  414. echo "$SCRIPTNAME: Creating a CA Certificate $NICKNAME =========================="
  415. if [ ! -d "${CUR_CADIR}" ]; then
  416. mkdir -p "${CUR_CADIR}"
  417. fi
  418. cd ${CUR_CADIR}
  419. pwd
  420. LPROFILE=`pwd`
  421. if [ "${OS_ARCH}" = "WINNT" -a "$OS_NAME" = "CYGWIN_NT" ]; then
  422. LPROFILE=`cygpath -m ${LPROFILE}`
  423. fi
  424. if [ -n "${MULTIACCESS_DBM}" ]; then
  425. LPROFILE="multiaccess:${DOMAIN}"
  426. fi
  427. if [ "$SIGNER" = "-x" ] ; then # self signed -> create DB
  428. CU_ACTION="Creating CA Cert DB"
  429. certu -N -d "${LPROFILE}" -f ${R_PWFILE} 2>&1
  430. if [ "$RET" -ne 0 ]; then
  431. Exit 5 "Fatal - failed to create CA $NICKNAME "
  432. fi
  433. CU_ACTION="Loading root cert module to CA Cert DB"
  434. modu -add "RootCerts" -libfile "${ROOTCERTSFILE}" -dbdir "${LPROFILE}" 2>&1
  435. if [ "$RET" -ne 0 ]; then
  436. return $RET
  437. fi
  438. echo "$SCRIPTNAME: Certificate initialized ----------"
  439. fi
  440. ################# Creating CA Cert ######################################
  441. #
  442. CU_ACTION="Creating CA Cert $NICKNAME "
  443. CU_SUBJECT=$ALL_CU_SUBJECT
  444. certu -S -n $NICKNAME -t $TRUSTARG -v 600 $SIGNER -d ${LPROFILE} -1 -2 -5 \
  445. -f ${R_PWFILE} -z ${R_NOISE_FILE} -m $CERTSERIAL 2>&1 <<CERTSCRIPT
  446. 5
  447. 6
  448. 9
  449. n
  450. y
  451. -1
  452. n
  453. 5
  454. 6
  455. 7
  456. 9
  457. n
  458. CERTSCRIPT
  459. if [ "$RET" -ne 0 ]; then
  460. echo "return value is $RET"
  461. Exit 6 "Fatal - failed to create CA cert"
  462. fi
  463. ################# Exporting Root Cert ###################################
  464. #
  465. CU_ACTION="Exporting Root Cert"
  466. certu -L -n $NICKNAME -r -d ${LPROFILE} -o root.cert
  467. if [ "$RET" -ne 0 ]; then
  468. Exit 7 "Fatal - failed to export root cert"
  469. fi
  470. cp root.cert ${NICKNAME}.ca.cert
  471. }
  472. ################################ cert_ec_CA ##############################
  473. # local shell function to build the Temp. Certificate Authority (CA)
  474. # used for testing purposes, creating a CA Certificate and a root cert
  475. # This is the ECC version of cert_CA.
  476. ##########################################################################
  477. cert_ec_CA()
  478. {
  479. CUR_CADIR=$1
  480. NICKNAME=$2
  481. SIGNER=$3
  482. TRUSTARG=$4
  483. DOMAIN=$5
  484. CERTSERIAL=$6
  485. CURVE=$7
  486. echo "$SCRIPTNAME: Creating an EC CA Certificate $NICKNAME =========================="
  487. if [ ! -d "${CUR_CADIR}" ]; then
  488. mkdir -p "${CUR_CADIR}"
  489. fi
  490. cd ${CUR_CADIR}
  491. pwd
  492. LPROFILE=.
  493. if [ -n "${MULTIACCESS_DBM}" ]; then
  494. LPROFILE="multiaccess:${DOMAIN}"
  495. fi
  496. ################# Creating an EC CA Cert ################################
  497. #
  498. CU_ACTION="Creating EC CA Cert $NICKNAME "
  499. CU_SUBJECT=$ALL_CU_SUBJECT
  500. certu -S -n $NICKNAME -k ec -q $CURVE -t $TRUSTARG -v 600 $SIGNER \
  501. -d ${LPROFILE} -1 -2 -5 -f ${R_PWFILE} -z ${R_NOISE_FILE} \
  502. -m $CERTSERIAL 2>&1 <<CERTSCRIPT
  503. 5
  504. 6
  505. 9
  506. n
  507. y
  508. -1
  509. n
  510. 5
  511. 6
  512. 7
  513. 9
  514. n
  515. CERTSCRIPT
  516. if [ "$RET" -ne 0 ]; then
  517. echo "return value is $RET"
  518. Exit 6 "Fatal - failed to create EC CA cert"
  519. fi
  520. ################# Exporting EC Root Cert ################################
  521. #
  522. CU_ACTION="Exporting EC Root Cert"
  523. certu -L -n $NICKNAME -r -d ${LPROFILE} -o ecroot.cert
  524. if [ "$RET" -ne 0 ]; then
  525. Exit 7 "Fatal - failed to export ec root cert"
  526. fi
  527. cp ecroot.cert ${NICKNAME}.ca.cert
  528. }
  529. ############################## cert_smime_client #############################
  530. # local shell function to create client Certificates for S/MIME tests
  531. ##############################################################################
  532. cert_smime_client()
  533. {
  534. CERTFAILED=0
  535. echo "$SCRIPTNAME: Creating Client CA Issued Certificates =============="
  536. cert_create_cert ${ALICEDIR} "Alice" 30 ${D_ALICE}
  537. cert_create_cert ${BOBDIR} "Bob" 40 ${D_BOB}
  538. echo "$SCRIPTNAME: Creating Dave's Certificate -------------------------"
  539. cert_create_cert "${DAVEDIR}" Dave 50 ${D_DAVE}
  540. ## XXX With this new script merging ECC and non-ECC tests, the
  541. ## call to cert_create_cert ends up creating two separate certs
  542. ## one for Eve and another for Eve-ec but they both end up with
  543. ## the same Subject Alt Name Extension, i.e., both the cert for
  544. ## Eve@bogus.com and the cert for Eve-ec@bogus.com end up
  545. ## listing eve@bogus.net in the Certificate Subject Alt Name extension.
  546. ## This can cause a problem later when cmsutil attempts to create
  547. ## enveloped data and accidently picks up the ECC cert (NSS currently
  548. ## does not support ECC for enveloped data creation). This script
  549. ## avoids the problem by ensuring that these conflicting certs are
  550. ## never added to the same cert database (see comment marked XXXX).
  551. echo "$SCRIPTNAME: Creating multiEmail's Certificate --------------------"
  552. cert_create_cert "${EVEDIR}" "Eve" 60 ${D_EVE} "-7 eve@bogus.net,eve@bogus.cc,beve@bogus.com"
  553. #echo "************* Copying CA files to ${SERVERDIR}"
  554. #cp ${CADIR}/*.db .
  555. #hw_acc
  556. #########################################################################
  557. #
  558. #cd ${CERTDIR}
  559. #CU_ACTION="Creating ${CERTNAME}'s Server Cert"
  560. #CU_SUBJECT="CN=${CERTNAME}, E=${CERTNAME}@bogus.com, O=BOGUS Netscape, L=Mountain View, ST=California, C=US"
  561. #certu -S -n "${CERTNAME}" -c "TestCA" -t "u,u,u" -m "$CERTSERIAL" \
  562. # -d ${PROFILEDIR} -f "${R_PWFILE}" -z "${R_NOISE_FILE}" -v 60 2>&1
  563. #CU_ACTION="Export Dave's Cert"
  564. #cd ${DAVEDIR}
  565. #certu -L -n "Dave" -r -d ${P_R_DAVE} -o Dave.cert
  566. ################# Importing Certificates for S/MIME tests ###############
  567. #
  568. echo "$SCRIPTNAME: Importing Certificates =============================="
  569. CU_ACTION="Import Bob's cert into Alice's db"
  570. certu -E -t ",," -d ${P_R_ALICEDIR} -f ${R_PWFILE} \
  571. -i ${R_BOBDIR}/Bob.cert 2>&1
  572. CU_ACTION="Import Dave's cert into Alice's DB"
  573. certu -E -t ",," -d ${P_R_ALICEDIR} -f ${R_PWFILE} \
  574. -i ${R_DAVEDIR}/Dave.cert 2>&1
  575. CU_ACTION="Import Dave's cert into Bob's DB"
  576. certu -E -t ",," -d ${P_R_BOBDIR} -f ${R_PWFILE} \
  577. -i ${R_DAVEDIR}/Dave.cert 2>&1
  578. CU_ACTION="Import Eve's cert into Alice's DB"
  579. certu -E -t ",," -d ${P_R_ALICEDIR} -f ${R_PWFILE} \
  580. -i ${R_EVEDIR}/Eve.cert 2>&1
  581. CU_ACTION="Import Eve's cert into Bob's DB"
  582. certu -E -t ",," -d ${P_R_BOBDIR} -f ${R_PWFILE} \
  583. -i ${R_EVEDIR}/Eve.cert 2>&1
  584. if [ -n "$NSS_ENABLE_ECC" ] ; then
  585. echo "$SCRIPTNAME: Importing EC Certificates =============================="
  586. CU_ACTION="Import Bob's EC cert into Alice's db"
  587. certu -E -t ",," -d ${P_R_ALICEDIR} -f ${R_PWFILE} \
  588. -i ${R_BOBDIR}/Bob-ec.cert 2>&1
  589. CU_ACTION="Import Dave's EC cert into Alice's DB"
  590. certu -E -t ",," -d ${P_R_ALICEDIR} -f ${R_PWFILE} \
  591. -i ${R_DAVEDIR}/Dave-ec.cert 2>&1
  592. CU_ACTION="Import Dave's EC cert into Bob's DB"
  593. certu -E -t ",," -d ${P_R_BOBDIR} -f ${R_PWFILE} \
  594. -i ${R_DAVEDIR}/Dave-ec.cert 2>&1
  595. ## XXXX Do not import Eve's EC cert until we can make sure that
  596. ## the email addresses listed in the Subject Alt Name Extension
  597. ## inside Eve's ECC and non-ECC certs are different.
  598. # CU_ACTION="Import Eve's EC cert into Alice's DB"
  599. # certu -E -t ",," -d ${P_R_ALICEDIR} -f ${R_PWFILE} \
  600. # -i ${R_EVEDIR}/Eve-ec.cert 2>&1
  601. # CU_ACTION="Import Eve's EC cert into Bob's DB"
  602. # certu -E -t ",," -d ${P_R_BOBDIR} -f ${R_PWFILE} \
  603. # -i ${R_EVEDIR}/Eve-ec.cert 2>&1
  604. fi
  605. if [ "$CERTFAILED" != 0 ] ; then
  606. cert_log "ERROR: SMIME failed $RET"
  607. else
  608. cert_log "SUCCESS: SMIME passed"
  609. fi
  610. }
  611. ############################## cert_extended_ssl #######################
  612. # local shell function to create client + server certs for extended SSL test
  613. ########################################################################
  614. cert_extended_ssl()
  615. {
  616. ################# Creating Certs for extended SSL test ####################
  617. #
  618. CERTFAILED=0
  619. echo "$SCRIPTNAME: Creating Certificates, issued by the last ==============="
  620. echo " of a chain of CA's which are not in the same database============"
  621. echo "Server Cert"
  622. cert_init_cert ${EXT_SERVERDIR} "${HOSTADDR}" 1 ${D_EXT_SERVER}
  623. CU_ACTION="Initializing ${CERTNAME}'s Cert DB (ext.)"
  624. certu -N -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  625. CU_ACTION="Loading root cert module to ${CERTNAME}'s Cert DB (ext.)"
  626. modu -add "RootCerts" -libfile "${ROOTCERTSFILE}" -dbdir "${PROFILEDIR}" 2>&1
  627. CU_ACTION="Generate Cert Request for $CERTNAME (ext)"
  628. CU_SUBJECT="CN=$CERTNAME, E=${CERTNAME}@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  629. certu -R -d "${PROFILEDIR}" -f "${R_PWFILE}" -z "${R_NOISE_FILE}" -o req 2>&1
  630. CU_ACTION="Sign ${CERTNAME}'s Request (ext)"
  631. cp ${CERTDIR}/req ${SERVER_CADIR}
  632. certu -C -c "chain-2-serverCA" -m 200 -v 60 -d "${P_SERVER_CADIR}" \
  633. -i req -o "${CERTNAME}.cert" -f "${R_PWFILE}" 2>&1
  634. CU_ACTION="Import $CERTNAME's Cert -t u,u,u (ext)"
  635. certu -A -n "$CERTNAME" -t "u,u,u" -d "${PROFILEDIR}" -f "${R_PWFILE}" \
  636. -i "${CERTNAME}.cert" 2>&1
  637. CU_ACTION="Import Client Root CA -t T,, for $CERTNAME (ext.)"
  638. certu -A -n "clientCA" -t "T,," -f "${R_PWFILE}" -d "${PROFILEDIR}" \
  639. -i "${CLIENT_CADIR}/clientCA.ca.cert" 2>&1
  640. if [ -n "$NSS_ENABLE_ECC" ] ; then
  641. #
  642. # Repeat the above for EC certs
  643. #
  644. EC_CURVE="secp256r1"
  645. CU_ACTION="Generate EC Cert Request for $CERTNAME (ext)"
  646. CU_SUBJECT="CN=$CERTNAME, E=${CERTNAME}-ec@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  647. certu -R -d "${PROFILEDIR}" -k ec -q "${EC_CURVE}" -f "${R_PWFILE}" \
  648. -z "${R_NOISE_FILE}" -o req 2>&1
  649. CU_ACTION="Sign ${CERTNAME}'s EC Request (ext)"
  650. cp ${CERTDIR}/req ${SERVER_CADIR}
  651. certu -C -c "chain-2-serverCA-ec" -m 200 -v 60 -d "${P_SERVER_CADIR}" \
  652. -i req -o "${CERTNAME}-ec.cert" -f "${R_PWFILE}" 2>&1
  653. CU_ACTION="Import $CERTNAME's EC Cert -t u,u,u (ext)"
  654. certu -A -n "${CERTNAME}-ec" -t "u,u,u" -d "${PROFILEDIR}" \
  655. -f "${R_PWFILE}" -i "${CERTNAME}-ec.cert" 2>&1
  656. CU_ACTION="Import Client EC Root CA -t T,, for $CERTNAME (ext.)"
  657. certu -A -n "clientCA-ec" -t "T,," -f "${R_PWFILE}" -d "${PROFILEDIR}" \
  658. -i "${CLIENT_CADIR}/clientCA-ec.ca.cert" 2>&1
  659. #
  660. # done with EC certs
  661. #
  662. # Repeat again for mixed EC certs
  663. #
  664. EC_CURVE="secp256r1"
  665. CU_ACTION="Generate mixed EC Cert Request for $CERTNAME (ext)"
  666. CU_SUBJECT="CN=$CERTNAME, E=${CERTNAME}-ecmixed@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  667. certu -R -d "${PROFILEDIR}" -k ec -q "${EC_CURVE}" -f "${R_PWFILE}" \
  668. -z "${R_NOISE_FILE}" -o req 2>&1
  669. CU_ACTION="Sign ${CERTNAME}'s mixed EC Request (ext)"
  670. cp ${CERTDIR}/req ${SERVER_CADIR}
  671. certu -C -c "chain-2-serverCA" -m 201 -v 60 -d "${P_SERVER_CADIR}" \
  672. -i req -o "${CERTNAME}-ecmixed.cert" -f "${R_PWFILE}" 2>&1
  673. CU_ACTION="Import $CERTNAME's mixed EC Cert -t u,u,u (ext)"
  674. certu -A -n "${CERTNAME}-ecmixed" -t "u,u,u" -d "${PROFILEDIR}" \
  675. -f "${R_PWFILE}" -i "${CERTNAME}-ecmixed.cert" 2>&1
  676. # CU_ACTION="Import Client mixed EC Root CA -t T,, for $CERTNAME (ext.)"
  677. # certu -A -n "clientCA-ecmixed" -t "T,," -f "${R_PWFILE}" \
  678. # -d "${PROFILEDIR}" -i "${CLIENT_CADIR}/clientCA-ecmixed.ca.cert" \
  679. # 2>&1
  680. fi
  681. echo "Importing all the server's own CA chain into the servers DB"
  682. for CA in `find ${SERVER_CADIR} -name "?*.ca.cert"` ;
  683. do
  684. N=`basename $CA | sed -e "s/.ca.cert//"`
  685. if [ $N = "serverCA" -o $N = "serverCA-ec" ] ; then
  686. T="-t C,C,C"
  687. else
  688. T="-t u,u,u"
  689. fi
  690. CU_ACTION="Import $N CA $T for $CERTNAME (ext.) "
  691. certu -A -n $N $T -f "${R_PWFILE}" -d "${PROFILEDIR}" \
  692. -i "${CA}" 2>&1
  693. done
  694. #============
  695. echo "Client Cert"
  696. cert_init_cert ${EXT_CLIENTDIR} ExtendedSSLUser 1 ${D_EXT_CLIENT}
  697. CU_ACTION="Initializing ${CERTNAME}'s Cert DB (ext.)"
  698. certu -N -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  699. CU_ACTION="Loading root cert module to ${CERTNAME}'s Cert DB (ext.)"
  700. modu -add "RootCerts" -libfile "${ROOTCERTSFILE}" -dbdir "${PROFILEDIR}" 2>&1
  701. CU_ACTION="Generate Cert Request for $CERTNAME (ext)"
  702. CU_SUBJECT="CN=$CERTNAME, E=${CERTNAME}@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  703. certu -R -d "${PROFILEDIR}" -f "${R_PWFILE}" -z "${R_NOISE_FILE}" \
  704. -o req 2>&1
  705. CU_ACTION="Sign ${CERTNAME}'s Request (ext)"
  706. cp ${CERTDIR}/req ${CLIENT_CADIR}
  707. certu -C -c "chain-2-clientCA" -m 300 -v 60 -d "${P_CLIENT_CADIR}" \
  708. -i req -o "${CERTNAME}.cert" -f "${R_PWFILE}" 2>&1
  709. CU_ACTION="Import $CERTNAME's Cert -t u,u,u (ext)"
  710. certu -A -n "$CERTNAME" -t "u,u,u" -d "${PROFILEDIR}" -f "${R_PWFILE}" \
  711. -i "${CERTNAME}.cert" 2>&1
  712. CU_ACTION="Import Server Root CA -t C,C,C for $CERTNAME (ext.)"
  713. certu -A -n "serverCA" -t "C,C,C" -f "${R_PWFILE}" -d "${PROFILEDIR}" \
  714. -i "${SERVER_CADIR}/serverCA.ca.cert" 2>&1
  715. if [ -n "$NSS_ENABLE_ECC" ] ; then
  716. #
  717. # Repeat the above for EC certs
  718. #
  719. CU_ACTION="Generate EC Cert Request for $CERTNAME (ext)"
  720. CU_SUBJECT="CN=$CERTNAME, E=${CERTNAME}-ec@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  721. certu -R -d "${PROFILEDIR}" -k ec -q "${EC_CURVE}" -f "${R_PWFILE}" \
  722. -z "${R_NOISE_FILE}" -o req 2>&1
  723. CU_ACTION="Sign ${CERTNAME}'s EC Request (ext)"
  724. cp ${CERTDIR}/req ${CLIENT_CADIR}
  725. certu -C -c "chain-2-clientCA-ec" -m 300 -v 60 -d "${P_CLIENT_CADIR}" \
  726. -i req -o "${CERTNAME}-ec.cert" -f "${R_PWFILE}" 2>&1
  727. CU_ACTION="Import $CERTNAME's EC Cert -t u,u,u (ext)"
  728. certu -A -n "${CERTNAME}-ec" -t "u,u,u" -d "${PROFILEDIR}" \
  729. -f "${R_PWFILE}" -i "${CERTNAME}-ec.cert" 2>&1
  730. CU_ACTION="Import Server EC Root CA -t C,C,C for $CERTNAME (ext.)"
  731. certu -A -n "serverCA-ec" -t "C,C,C" -f "${R_PWFILE}" \
  732. -d "${PROFILEDIR}" -i "${SERVER_CADIR}/serverCA-ec.ca.cert" 2>&1
  733. #
  734. # done with EC certs
  735. #
  736. #
  737. # Repeat the above for mixed EC certs
  738. #
  739. CU_ACTION="Generate mixed EC Cert Request for $CERTNAME (ext)"
  740. CU_SUBJECT="CN=$CERTNAME, E=${CERTNAME}-ecmixed@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  741. certu -R -d "${PROFILEDIR}" -k ec -q "${EC_CURVE}" -f "${R_PWFILE}" \
  742. -z "${R_NOISE_FILE}" -o req 2>&1
  743. CU_ACTION="Sign ${CERTNAME}'s mixed EC Request (ext)"
  744. cp ${CERTDIR}/req ${CLIENT_CADIR}
  745. certu -C -c "chain-2-clientCA" -m 301 -v 60 -d "${P_CLIENT_CADIR}" \
  746. -i req -o "${CERTNAME}-ecmixed.cert" -f "${R_PWFILE}" 2>&1
  747. CU_ACTION="Import $CERTNAME's mixed EC Cert -t u,u,u (ext)"
  748. certu -A -n "${CERTNAME}-ecmixed" -t "u,u,u" -d "${PROFILEDIR}" \
  749. -f "${R_PWFILE}" -i "${CERTNAME}-ecmixed.cert" 2>&1
  750. # CU_ACTION="Import Server EC Root CA -t C,C,C for $CERTNAME (ext.)"
  751. # certu -A -n "serverCA-ec" -t "C,C,C" -f "${R_PWFILE}" \
  752. # -d "${PROFILEDIR}" -i "${SERVER_CADIR}/serverCA-ec.ca.cert" 2>&1
  753. #
  754. # done with mixed EC certs
  755. #
  756. fi
  757. echo "Importing all the client's own CA chain into the servers DB"
  758. for CA in `find ${CLIENT_CADIR} -name "?*.ca.cert"` ;
  759. do
  760. N=`basename $CA | sed -e "s/.ca.cert//"`
  761. if [ $N = "clientCA" -o $N = "clientCA-ec" ] ; then
  762. T="-t T,C,C"
  763. else
  764. T="-t u,u,u"
  765. fi
  766. CU_ACTION="Import $N CA $T for $CERTNAME (ext.)"
  767. certu -A -n $N $T -f "${R_PWFILE}" -d "${PROFILEDIR}" \
  768. -i "${CA}" 2>&1
  769. done
  770. if [ "$CERTFAILED" != 0 ] ; then
  771. cert_log "ERROR: EXT failed $RET"
  772. else
  773. cert_log "SUCCESS: EXT passed"
  774. fi
  775. }
  776. ############################## cert_ssl ################################
  777. # local shell function to create client + server certs for SSL test
  778. ########################################################################
  779. cert_ssl()
  780. {
  781. ################# Creating Certs for SSL test ###########################
  782. #
  783. CERTFAILED=0
  784. echo "$SCRIPTNAME: Creating Client CA Issued Certificates ==============="
  785. cert_create_cert ${CLIENTDIR} "TestUser" 70 ${D_CLIENT}
  786. echo "$SCRIPTNAME: Creating Server CA Issued Certificate for \\"
  787. echo " ${HOSTADDR} ------------------------------------"
  788. cert_create_cert ${SERVERDIR} "${HOSTADDR}" 100 ${D_SERVER}
  789. echo "$SCRIPTNAME: Creating Server CA Issued Certificate for \\"
  790. echo " ${HOSTADDR}-sni --------------------------------"
  791. CERTSERIAL=101
  792. CERTNAME="${HOST}-sni${sniCertCount}.${DOMSUF}"
  793. cert_add_cert
  794. CU_ACTION="Modify trust attributes of Root CA -t TC,TC,TC"
  795. certu -M -n "TestCA" -t "TC,TC,TC" -d ${PROFILEDIR} -f "${R_PWFILE}"
  796. if [ -n "$NSS_ENABLE_ECC" ] ; then
  797. CU_ACTION="Modify trust attributes of EC Root CA -t TC,TC,TC"
  798. certu -M -n "TestCA-ec" -t "TC,TC,TC" -d ${PROFILEDIR} -f "${R_PWFILE}"
  799. fi
  800. # cert_init_cert ${SERVERDIR} "${HOSTADDR}" 1 ${D_SERVER}
  801. # echo "************* Copying CA files to ${SERVERDIR}"
  802. # cp ${CADIR}/*.db .
  803. # hw_acc
  804. # CU_ACTION="Creating ${CERTNAME}'s Server Cert"
  805. # CU_SUBJECT="CN=${CERTNAME}, O=BOGUS Netscape, L=Mountain View, ST=California, C=US"
  806. # certu -S -n "${CERTNAME}" -c "TestCA" -t "Pu,Pu,Pu" -d ${PROFILEDIR} \
  807. # -f "${R_PWFILE}" -z "${R_NOISE_FILE}" -v 60 2>&1
  808. if [ "$CERTFAILED" != 0 ] ; then
  809. cert_log "ERROR: SSL failed $RET"
  810. else
  811. cert_log "SUCCESS: SSL passed"
  812. fi
  813. }
  814. ############################## cert_stresscerts ################################
  815. # local shell function to create client certs for SSL stresstest
  816. ########################################################################
  817. cert_stresscerts()
  818. {
  819. ############### Creating Certs for SSL stress test #######################
  820. #
  821. CERTDIR="$CLIENTDIR"
  822. cd "${CERTDIR}"
  823. PROFILEDIR=`cd ${CERTDIR}; pwd`
  824. if [ "${OS_ARCH}" = "WINNT" -a "$OS_NAME" = "CYGWIN_NT" ]; then
  825. PROFILEDIR=`cygpath -m ${PROFILEDIR}`
  826. fi
  827. if [ -n "${MULTIACCESS_DBM}" ]; then
  828. PROFILEDIR="multiaccess:${D_CLIENT}"
  829. fi
  830. CERTFAILED=0
  831. echo "$SCRIPTNAME: Creating Client CA Issued Certificates ==============="
  832. CONTINUE=$GLOB_MAX_CERT
  833. CERTSERIAL=10
  834. while [ $CONTINUE -ge $GLOB_MIN_CERT ]
  835. do
  836. CERTNAME="TestUser$CONTINUE"
  837. # cert_add_cert ${CLIENTDIR} "TestUser$CONTINUE" $CERTSERIAL
  838. cert_add_cert
  839. CERTSERIAL=`expr $CERTSERIAL + 1 `
  840. CONTINUE=`expr $CONTINUE - 1 `
  841. done
  842. if [ "$CERTFAILED" != 0 ] ; then
  843. cert_log "ERROR: StressCert failed $RET"
  844. else
  845. cert_log "SUCCESS: StressCert passed"
  846. fi
  847. }
  848. ############################## cert_fips #####################################
  849. # local shell function to create certificates for FIPS tests
  850. ##############################################################################
  851. cert_fips()
  852. {
  853. CERTFAILED=0
  854. echo "$SCRIPTNAME: Creating FIPS 140 DSA Certificates =============="
  855. cert_init_cert "${FIPSDIR}" "FIPS PUB 140 Test Certificate" 1000 "${D_FIPS}"
  856. CU_ACTION="Initializing ${CERTNAME}'s Cert DB"
  857. certu -N -d "${PROFILEDIR}" -f "${R_FIPSPWFILE}" 2>&1
  858. CU_ACTION="Loading root cert module to ${CERTNAME}'s Cert DB (ext.)"
  859. modu -add "RootCerts" -libfile "${ROOTCERTSFILE}" -dbdir "${PROFILEDIR}" 2>&1
  860. echo "$SCRIPTNAME: Enable FIPS mode on database -----------------------"
  861. CU_ACTION="Enable FIPS mode on database for ${CERTNAME}"
  862. echo "modutil -dbdir ${PROFILEDIR} -fips true "
  863. ${BINDIR}/modutil -dbdir ${PROFILEDIR} -fips true 2>&1 <<MODSCRIPT
  864. y
  865. MODSCRIPT
  866. RET=$?
  867. if [ "$RET" -ne 0 ]; then
  868. html_failed "${CU_ACTION} ($RET) "
  869. cert_log "ERROR: ${CU_ACTION} failed $RET"
  870. else
  871. html_passed "${CU_ACTION}"
  872. fi
  873. CU_ACTION="Generate Certificate for ${CERTNAME}"
  874. CU_SUBJECT="CN=${CERTNAME}, E=fips@bogus.com, O=BOGUS NSS, OU=FIPS PUB 140, L=Mountain View, ST=California, C=US"
  875. certu -S -n ${FIPSCERTNICK} -x -t "Cu,Cu,Cu" -d "${PROFILEDIR}" -f "${R_FIPSPWFILE}" -k dsa -v 600 -m 500 -z "${R_NOISE_FILE}" 2>&1
  876. if [ "$RET" -eq 0 ]; then
  877. cert_log "SUCCESS: FIPS passed"
  878. fi
  879. }
  880. ############################## cert_eccurves ###########################
  881. # local shell function to create server certs for all EC curves
  882. ########################################################################
  883. cert_eccurves()
  884. {
  885. ################# Creating Certs for EC curves test ########################
  886. #
  887. if [ -n "$NSS_ENABLE_ECC" ] ; then
  888. echo "$SCRIPTNAME: Creating Server CA Issued Certificate for "
  889. echo " EC Curves Test Certificates ------------------------------------"
  890. cert_init_cert "${ECCURVES_DIR}" "EC Curves Test Certificates" 1 ${D_ECCURVES}
  891. CU_ACTION="Initializing EC Curve's Cert DB"
  892. certu -N -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  893. CU_ACTION="Loading root cert module to EC Curve's Cert DB"
  894. modu -add "RootCerts" -libfile "${ROOTCERTSFILE}" -dbdir "${PROFILEDIR}" 2>&1
  895. CU_ACTION="Import EC Root CA for $CERTNAME"
  896. certu -A -n "TestCA-ec" -t "TC,TC,TC" -f "${R_PWFILE}" \
  897. -d "${PROFILEDIR}" -i "${R_CADIR}/TestCA-ec.ca.cert" 2>&1
  898. if [ -n "${NSS_ECC_MORE_THAN_SUITE_B}" ] ; then
  899. CURVE_LIST="c2pnb163v1 c2pnb163v2 c2pnb163v3 c2pnb176v1 \
  900. c2pnb208w1 c2pnb272w1 c2pnb304w1 c2pnb368w1 \
  901. c2tnb191v1 c2tnb191v2 c2tnb191v3 c2tnb239v1 \
  902. c2tnb239v2 c2tnb239v3 c2tnb359v1 c2tnb431r1 \
  903. nistb163 nistb233 nistb283 nistb409 nistb571 \
  904. nistk163 nistk233 nistk283 nistk409 nistk571 \
  905. nistp192 nistp224 nistp256 nistp384 nistp521 \
  906. prime192v1 prime192v2 prime192v3 \
  907. prime239v1 prime239v2 prime239v3 \
  908. secp112r1 secp112r2 secp128r1 secp128r2 secp160k1 \
  909. secp160r1 secp160r2 secp192k1 secp192r1 secp224k1 \
  910. secp224r1 secp256k1 secp256r1 secp384r1 secp521r1 \
  911. sect113r1 sect113r2 sect131r1 sect131r2 sect163k1 sect163r1 \
  912. sect163r2 sect193r1 sect193r2 sect233k1 sect233r1 sect239k1 \
  913. sect283k1 sect283r1 sect409k1 sect409r1 sect571k1 sect571r1"
  914. else
  915. CURVE_LIST="nistp256 nistp384 nistp521"
  916. fi
  917. CERTSERIAL=2000
  918. for CURVE in ${CURVE_LIST}
  919. do
  920. CERTFAILED=0
  921. CERTNAME="Curve-${CURVE}"
  922. CERTSERIAL=`expr $CERTSERIAL + 1 `
  923. CU_ACTION="Generate EC Cert Request for $CERTNAME"
  924. CU_SUBJECT="CN=$CERTNAME, E=${CERTNAME}-ec@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  925. certu -R -k ec -q "${CURVE}" -d "${PROFILEDIR}" -f "${R_PWFILE}" \
  926. -z "${R_NOISE_FILE}" -o req 2>&1
  927. if [ $RET -eq 0 ] ; then
  928. CU_ACTION="Sign ${CERTNAME}'s EC Request"
  929. certu -C -c "TestCA-ec" -m "$CERTSERIAL" -v 60 -d "${P_R_CADIR}" \
  930. -i req -o "${CERTNAME}-ec.cert" -f "${R_PWFILE}" "$1" 2>&1
  931. fi
  932. if [ $RET -eq 0 ] ; then
  933. CU_ACTION="Import $CERTNAME's EC Cert"
  934. certu -A -n "${CERTNAME}-ec" -t "u,u,u" -d "${PROFILEDIR}" \
  935. -f "${R_PWFILE}" -i "${CERTNAME}-ec.cert" 2>&1
  936. fi
  937. done
  938. fi # if NSS_ENABLE_ECC=1
  939. }
  940. ########################### cert_extensions_test #############################
  941. # local shell function to test cert extensions generation
  942. ##############################################################################
  943. cert_extensions_test()
  944. {
  945. COUNT=`expr ${COUNT} + 1`
  946. CERTNAME=TestExt${COUNT}
  947. CU_SUBJECT="CN=${CERTNAME}, E=${CERTNAME}@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  948. echo
  949. echo certutil -d ${CERT_EXTENSIONS_DIR} -S -n ${CERTNAME} \
  950. -t "u,u,u" -o /tmp/cert -s "${CU_SUBJECT}" -x -f ${R_PWFILE} \
  951. -z "${R_NOISE_FILE}" -${OPT} \< ${TARG_FILE}
  952. echo "certutil options:"
  953. cat ${TARG_FILE}
  954. ${BINDIR}/certutil -d ${CERT_EXTENSIONS_DIR} -S -n ${CERTNAME} \
  955. -t "u,u,u" -o /tmp/cert -s "${CU_SUBJECT}" -x -f ${R_PWFILE} \
  956. -z "${R_NOISE_FILE}" -${OPT} < ${TARG_FILE}
  957. RET=$?
  958. if [ "${RET}" -ne 0 ]; then
  959. CERTFAILED=1
  960. html_failed "${TESTNAME} (${COUNT}) - Create and Add Certificate"
  961. cert_log "ERROR: ${TESTNAME} - Create and Add Certificate failed"
  962. return 1
  963. fi
  964. echo certutil -d ${CERT_EXTENSIONS_DIR} -L -n ${CERTNAME}
  965. EXTLIST=`${BINDIR}/certutil -d ${CERT_EXTENSIONS_DIR} -L -n ${CERTNAME}`
  966. RET=$?
  967. echo "${EXTLIST}"
  968. if [ "${RET}" -ne 0 ]; then
  969. CERTFAILED=1
  970. html_failed "${TESTNAME} (${COUNT}) - List Certificate"
  971. cert_log "ERROR: ${TESTNAME} - List Certificate failed"
  972. return 1
  973. fi
  974. for FL in `echo ${FILTERLIST} | tr \| ' '`; do
  975. FL="`echo ${FL} | tr _ ' '`"
  976. EXPSTAT=0
  977. if [ X`echo "${FL}" | cut -c 1` = 'X!' ]; then
  978. EXPSTAT=1
  979. FL=`echo ${FL} | tr -d '!'`
  980. fi
  981. echo "${EXTLIST}" | grep "${FL}" >/dev/null 2>&1
  982. RET=$?
  983. if [ "${RET}" -ne "${EXPSTAT}" ]; then
  984. CERTFAILED=1
  985. html_failed "${TESTNAME} (${COUNT}) - Looking for ${FL}" "returned ${RET}, expected is ${EXPSTAT}"
  986. cert_log "ERROR: ${TESTNAME} - Looking for ${FL} failed"
  987. return 1
  988. fi
  989. done
  990. html_passed "${TESTNAME} (${COUNT})"
  991. return 0
  992. }
  993. ############################## cert_extensions ###############################
  994. # local shell function to run cert extensions tests
  995. ##############################################################################
  996. cert_extensions()
  997. {
  998. CERTNAME=TestExt
  999. cert_create_cert ${CERT_EXTENSIONS_DIR} ${CERTNAME} 90 ${D_CERT_EXTENSTIONS}
  1000. TARG_FILE=${CERT_EXTENSIONS_DIR}/test.args
  1001. COUNT=0
  1002. while read ARG OPT FILTERLIST; do
  1003. if [ X"`echo ${ARG} | cut -c 1`" = "X#" ]; then
  1004. continue
  1005. fi
  1006. if [ X"`echo ${ARG} | cut -c 1`" = "X!" ]; then
  1007. TESTNAME="${FILTERLIST}"
  1008. continue
  1009. fi
  1010. if [ X"${ARG}" = "X=" ]; then
  1011. cert_extensions_test
  1012. rm -f ${TARG_FILE}
  1013. else
  1014. echo ${ARG} >> ${TARG_FILE}
  1015. fi
  1016. done < ${QADIR}/cert/certext.txt
  1017. }
  1018. ############################## cert_crl_ssl ############################
  1019. # local shell function to generate certs and crls for SSL tests
  1020. ########################################################################
  1021. cert_crl_ssl()
  1022. {
  1023. ################# Creating Certs ###################################
  1024. #
  1025. CERTFAILED=0
  1026. CERTSERIAL=${CRL_GRP_1_BEGIN}
  1027. cd $CADIR
  1028. PROFILEDIR=`cd ${CLIENTDIR}; pwd`
  1029. if [ "${OS_ARCH}" = "WINNT" -a "$OS_NAME" = "CYGWIN_NT" ]; then
  1030. PROFILEDIR=`cygpath -m ${PROFILEDIR}`
  1031. fi
  1032. CRL_GRPS_END=`expr ${CRL_GRP_1_BEGIN} + ${TOTAL_CRL_RANGE} - 1`
  1033. echo "$SCRIPTNAME: Creating Client CA Issued Certificates Range $CRL_GRP_1_BEGIN - $CRL_GRPS_END ==="
  1034. CU_ACTION="Creating client test certs"
  1035. while [ $CERTSERIAL -le $CRL_GRPS_END ]
  1036. do
  1037. CERTNAME="TestUser$CERTSERIAL"
  1038. cert_add_cert
  1039. CERTSERIAL=`expr $CERTSERIAL + 1 `
  1040. done
  1041. #################### CRL Creation ##############################
  1042. CRL_GEN_RES=0
  1043. echo "$SCRIPTNAME: Creating CA CRL ====================================="
  1044. CRL_GRP_END=`expr ${CRL_GRP_1_BEGIN} + ${CRL_GRP_1_RANGE} - 1`
  1045. CRL_FILE_GRP_1=${R_SERVERDIR}/root.crl_${CRL_GRP_1_BEGIN}-${CRL_GRP_END}
  1046. CRL_FILE=${CRL_FILE_GRP_1}
  1047. CRLUPDATE=`date -u "+%Y%m%d%H%M%SZ"`
  1048. CU_ACTION="Generating CRL for range ${CRL_GRP_1_BEGIN}-${CRL_GRP_END} TestCA authority"
  1049. CRL_GRP_END_=`expr ${CRL_GRP_END} - 1`
  1050. crlu -d $CADIR -G -n "TestCA" -f ${R_PWFILE} \
  1051. -o ${CRL_FILE_GRP_1}_or <<EOF_CRLINI
  1052. update=$CRLUPDATE
  1053. addcert ${CRL_GRP_1_BEGIN}-${CRL_GRP_END_} $CRL_GRP_DATE
  1054. addext reasonCode 0 4
  1055. addext issuerAltNames 0 "rfc822Name:caemail@ca.com|dnsName:ca.com|directoryName:CN=NSS Test CA,O=BOGUS NSS,L=Mountain View,ST=California,C=US|URI:http://ca.com|ipAddress:192.168.0.1|registerID=reg CA"
  1056. EOF_CRLINI
  1057. # This extension should be added to the list, but currently nss has bug
  1058. #addext authKeyId 0 "CN=NSS Test CA,O=BOGUS NSS,L=Mountain View,ST=California,C=US" 1
  1059. CRL_GEN_RES=`expr $? + $CRL_GEN_RES`
  1060. chmod 600 ${CRL_FILE_GRP_1}_or
  1061. if [ -n "$NSS_ENABLE_ECC" ] ; then
  1062. CU_ACTION="Generating CRL (ECC) for range ${CRL_GRP_1_BEGIN}-${CRL_GRP_END} TestCA-ec authority"
  1063. # Until Bug 292285 is resolved, do not encode x400 Addresses. After
  1064. # the bug is resolved, reintroduce "x400Address:x400Address" within
  1065. # addext issuerAltNames ...
  1066. crlu -q -d $CADIR -G -n "TestCA-ec" -f ${R_PWFILE} \
  1067. -o ${CRL_FILE_GRP_1}_or-ec <<EOF_CRLINI
  1068. update=$CRLUPDATE
  1069. addcert ${CRL_GRP_1_BEGIN}-${CRL_GRP_END_} $CRL_GRP_DATE
  1070. addext reasonCode 0 4
  1071. addext issuerAltNames 0 "rfc822Name:ca-ecemail@ca.com|dnsName:ca-ec.com|directoryName:CN=NSS Test CA (ECC),O=BOGUS NSS,L=Mountain View,ST=California,C=US|URI:http://ca-ec.com|ipAddress:192.168.0.1|registerID=reg CA (ECC)"
  1072. EOF_CRLINI
  1073. CRL_GEN_RES=`expr $? + $CRL_GEN_RES`
  1074. chmod 600 ${CRL_FILE_GRP_1}_or-ec
  1075. fi
  1076. echo test > file
  1077. ############################# Modification ##################################
  1078. echo "$SCRIPTNAME: Modifying CA CRL by adding one more cert ============"
  1079. sleep 2
  1080. CRLUPDATE=`date -u "+%Y%m%d%H%M%SZ"`
  1081. CRL_GRP_DATE=`date -u "+%Y%m%d%H%M%SZ"`
  1082. CU_ACTION="Modify CRL by adding one more cert"
  1083. crlu -d $CADIR -M -n "TestCA" -f ${R_PWFILE} -o ${CRL_FILE_GRP_1}_or1 \
  1084. -i ${CRL_FILE_GRP_1}_or <<EOF_CRLINI
  1085. update=$CRLUPDATE
  1086. addcert ${CRL_GRP_END} $CRL_GRP_DATE
  1087. EOF_CRLINI
  1088. CRL_GEN_RES=`expr $? + $CRL_GEN_RES`
  1089. chmod 600 ${CRL_FILE_GRP_1}_or1
  1090. TEMPFILES="$TEMPFILES ${CRL_FILE_GRP_1}_or"
  1091. if [ -n "$NSS_ENABLE_ECC" ] ; then
  1092. CU_ACTION="Modify CRL (ECC) by adding one more cert"
  1093. crlu -d $CADIR -M -n "TestCA-ec" -f ${R_PWFILE} \
  1094. -o ${CRL_FILE_GRP_1}_or1-ec -i ${CRL_FILE_GRP_1}_or-ec <<EOF_CRLINI
  1095. update=$CRLUPDATE
  1096. addcert ${CRL_GRP_END} $CRL_GRP_DATE
  1097. EOF_CRLINI
  1098. CRL_GEN_RES=`expr $? + $CRL_GEN_RES`
  1099. chmod 600 ${CRL_FILE_GRP_1}_or1-ec
  1100. TEMPFILES="$TEMPFILES ${CRL_FILE_GRP_1}_or-ec"
  1101. fi
  1102. ########### Removing one cert ${UNREVOKED_CERT_GRP_1} #######################
  1103. echo "$SCRIPTNAME: Modifying CA CRL by removing one cert ==============="
  1104. CU_ACTION="Modify CRL by removing one cert"
  1105. sleep 2
  1106. CRLUPDATE=`date -u "+%Y%m%d%H%M%SZ"`
  1107. crlu -d $CADIR -M -n "TestCA" -f ${R_PWFILE} -o ${CRL_FILE_GRP_1} \
  1108. -i ${CRL_FILE_GRP_1}_or1 <<EOF_CRLINI
  1109. update=$CRLUPDATE
  1110. rmcert ${UNREVOKED_CERT_GRP_1}
  1111. EOF_CRLINI
  1112. chmod 600 ${CRL_FILE_GRP_1}
  1113. TEMPFILES="$TEMPFILES ${CRL_FILE_GRP_1}_or1"
  1114. if [ -n "$NSS_ENABLE_ECC" ] ; then
  1115. CU_ACTION="Modify CRL (ECC) by removing one cert"
  1116. crlu -d $CADIR -M -n "TestCA-ec" -f ${R_PWFILE} -o ${CRL_FILE_GRP_1}-ec \
  1117. -i ${CRL_FILE_GRP_1}_or1-ec <<EOF_CRLINI
  1118. update=$CRLUPDATE
  1119. rmcert ${UNREVOKED_CERT_GRP_1}
  1120. EOF_CRLINI
  1121. chmod 600 ${CRL_FILE_GRP_1}-ec
  1122. TEMPFILES="$TEMPFILES ${CRL_FILE_GRP_1}_or1-ec"
  1123. fi
  1124. ########### Creating second CRL which includes groups 1 and 2 ##############
  1125. CRL_GRP_END=`expr ${CRL_GRP_2_BEGIN} + ${CRL_GRP_2_RANGE} - 1`
  1126. CRL_FILE_GRP_2=${R_SERVERDIR}/root.crl_${CRL_GRP_2_BEGIN}-${CRL_GRP_END}
  1127. echo "$SCRIPTNAME: Creating CA CRL for groups 1 and 2 ==============="
  1128. sleep 2
  1129. CRLUPDATE=`date -u "+%Y%m%d%H%M%SZ"`
  1130. CRL_GRP_DATE=`date -u "+%Y%m%d%H%M%SZ"`
  1131. CU_ACTION="Creating CRL for groups 1 and 2"
  1132. crlu -d $CADIR -M -n "TestCA" -f ${R_PWFILE} -o ${CRL_FILE_GRP_2} \
  1133. -i ${CRL_FILE_GRP_1} <<EOF_CRLINI
  1134. update=$CRLUPDATE
  1135. addcert ${CRL_GRP_2_BEGIN}-${CRL_GRP_END} $CRL_GRP_DATE
  1136. addext invalidityDate 0 $CRLUPDATE
  1137. rmcert ${UNREVOKED_CERT_GRP_2}
  1138. EOF_CRLINI
  1139. CRL_GEN_RES=`expr $? + $CRL_GEN_RES`
  1140. chmod 600 ${CRL_FILE_GRP_2}
  1141. if [ -n "$NSS_ENABLE_ECC" ] ; then
  1142. CU_ACTION="Creating CRL (ECC) for groups 1 and 2"
  1143. crlu -d $CADIR -M -n "TestCA-ec" -f ${R_PWFILE} -o ${CRL_FILE_GRP_2}-ec \
  1144. -i ${CRL_FILE_GRP_1}-ec <<EOF_CRLINI
  1145. update=$CRLUPDATE
  1146. addcert ${CRL_GRP_2_BEGIN}-${CRL_GRP_END} $CRL_GRP_DATE
  1147. addext invalidityDate 0 $CRLUPDATE
  1148. rmcert ${UNREVOKED_CERT_GRP_2}
  1149. EOF_CRLINI
  1150. CRL_GEN_RES=`expr $? + $CRL_GEN_RES`
  1151. chmod 600 ${CRL_FILE_GRP_2}-ec
  1152. fi
  1153. ########### Creating second CRL which includes groups 1, 2 and 3 ##############
  1154. CRL_GRP_END=`expr ${CRL_GRP_3_BEGIN} + ${CRL_GRP_3_RANGE} - 1`
  1155. CRL_FILE_GRP_3=${R_SERVERDIR}/root.crl_${CRL_GRP_3_BEGIN}-${CRL_GRP_END}
  1156. echo "$SCRIPTNAME: Creating CA CRL for groups 1, 2 and 3 ==============="
  1157. sleep 2
  1158. CRLUPDATE=`date -u "+%Y%m%d%H%M%SZ"`
  1159. CRL_GRP_DATE=`date -u "+%Y%m%d%H%M%SZ"`
  1160. CU_ACTION="Creating CRL for groups 1, 2 and 3"
  1161. crlu -d $CADIR -M -n "TestCA" -f ${R_PWFILE} -o ${CRL_FILE_GRP_3} \
  1162. -i ${CRL_FILE_GRP_2} <<EOF_CRLINI
  1163. update=$CRLUPDATE
  1164. addcert ${CRL_GRP_3_BEGIN}-${CRL_GRP_END} $CRL_GRP_DATE
  1165. rmcert ${UNREVOKED_CERT_GRP_3}
  1166. addext crlNumber 0 2
  1167. EOF_CRLINI
  1168. CRL_GEN_RES=`expr $? + $CRL_GEN_RES`
  1169. chmod 600 ${CRL_FILE_GRP_3}
  1170. if [ -n "$NSS_ENABLE_ECC" ] ; then
  1171. CU_ACTION="Creating CRL (ECC) for groups 1, 2 and 3"
  1172. crlu -d $CADIR -M -n "TestCA-ec" -f ${R_PWFILE} -o ${CRL_FILE_GRP_3}-ec \
  1173. -i ${CRL_FILE_GRP_2}-ec <<EOF_CRLINI
  1174. update=$CRLUPDATE
  1175. addcert ${CRL_GRP_3_BEGIN}-${CRL_GRP_END} $CRL_GRP_DATE
  1176. rmcert ${UNREVOKED_CERT_GRP_3}
  1177. addext crlNumber 0 2
  1178. EOF_CRLINI
  1179. CRL_GEN_RES=`expr $? + $CRL_GEN_RES`
  1180. chmod 600 ${CRL_FILE_GRP_3}-ec
  1181. fi
  1182. ############ Importing Server CA Issued CRL for certs of first group #######
  1183. echo "$SCRIPTNAME: Importing Server CA Issued CRL for certs ${CRL_GRP_BEGIN} trough ${CRL_GRP_END}"
  1184. CU_ACTION="Importing CRL for groups 1"
  1185. crlu -D -n TestCA -f "${R_PWFILE}" -d "${R_SERVERDIR}"
  1186. crlu -I -i ${CRL_FILE} -n "TestCA" -f "${R_PWFILE}" -d "${R_SERVERDIR}"
  1187. CRL_GEN_RES=`expr $? + $CRL_GEN_RES`
  1188. if [ -n "$NSS_ENABLE_ECC" ] ; then
  1189. CU_ACTION="Importing CRL (ECC) for groups 1"
  1190. crlu -D -n TestCA-ec -f "${R_PWFILE}" -d "${R_SERVERDIR}"
  1191. crlu -I -i ${CRL_FILE}-ec -n "TestCA-ec" -f "${R_PWFILE}" \
  1192. -d "${R_SERVERDIR}"
  1193. CRL_GEN_RES=`expr $? + $CRL_GEN_RES`
  1194. fi
  1195. if [ "$CERTFAILED" != 0 -o "$CRL_GEN_RES" != 0 ] ; then
  1196. cert_log "ERROR: SSL CRL prep failed $CERTFAILED : $CRL_GEN_RES"
  1197. else
  1198. cert_log "SUCCESS: SSL CRL prep passed"
  1199. fi
  1200. }
  1201. #################
  1202. # Verify the we can successfully change the password on the database
  1203. #
  1204. cert_test_password()
  1205. {
  1206. CERTFAILED=0
  1207. echo "$SCRIPTNAME: Create A Password Test Cert =============="
  1208. cert_init_cert "${DBPASSDIR}" "Password Test Cert" 1000 "${D_DBPASSDIR}"
  1209. echo "$SCRIPTNAME: Create A Password Test Ca --------"
  1210. ALL_CU_SUBJECT="CN=NSS Password Test CA, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  1211. cert_CA ${DBPASSDIR} PasswordCA -x "CTu,CTu,CTu" ${D_DBPASS} "1"
  1212. # now change the password
  1213. CU_ACTION="Changing password on ${CERTNAME}'s Cert DB"
  1214. certu -W -d "${PROFILEDIR}" -f "${R_PWFILE}" -@ "${R_FIPSPWFILE}" 2>&1
  1215. # finally make sure we can use the old key with the new password
  1216. CU_ACTION="Generate Certificate for ${CERTNAME} with new password"
  1217. CU_SUBJECT="CN=${CERTNAME}, E=password@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  1218. certu -S -n PasswordCert -c PasswordCA -t "u,u,u" -d "${PROFILEDIR}" -f "${R_FIPSPWFILE}" -z "${R_NOISE_FILE}" 2>&1
  1219. if [ "$RET" -eq 0 ]; then
  1220. cert_log "SUCCESS: PASSWORD passed"
  1221. fi
  1222. CU_ACTION="Verify Certificate for ${CERTNAME} with new password"
  1223. certu -V -n PasswordCert -u S -d "${PROFILEDIR}" -f "${R_FIPSPWFILE}" 2>&1
  1224. }
  1225. ###############################
  1226. # test if we can distrust a certificate.
  1227. #
  1228. # we create 3 new certs:
  1229. # 1 leaf signed by the trusted root.
  1230. # 1 intermediate signed by the trusted root.
  1231. # 1 leaf signed by the intermediate.
  1232. #
  1233. # we mark the first leaf and the intermediate as explicitly untrusted.
  1234. # we then try to verify the two leaf certs for our possible usages.
  1235. # All verification should fail.
  1236. #
  1237. cert_test_distrust()
  1238. {
  1239. echo "$SCRIPTNAME: Creating Distrusted Certificate"
  1240. cert_create_cert ${DISTRUSTDIR} "Distrusted" 2000 ${D_DISTRUST}
  1241. CU_ACTION="Mark CERT as unstrusted"
  1242. certu -M -n "Distrusted" -t p,p,p -d ${PROFILEDIR} -f "${R_PWFILE}" 2>&1
  1243. echo "$SCRIPTNAME: Creating Distrusted Intermediate"
  1244. CERTNAME="DistrustedCA"
  1245. ALL_CU_SUBJECT="CN=${CERTNAME}, E=${CERTNAME}@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  1246. cert_CA ${CADIR} "${CERTNAME}" "-c TestCA" ",," ${D_CA} 2010 2>&1
  1247. CU_ACTION="Import Distrusted Intermediate"
  1248. certu -A -n "${CERTNAME}" -t "p,p,p" -f "${R_PWFILE}" -d "${PROFILEDIR}" \
  1249. -i "${R_CADIR}/DistrustedCA.ca.cert" 2>&1
  1250. # now create the last leaf signed by our distrusted CA
  1251. # since it's not signed by TestCA it requires more steps.
  1252. CU_ACTION="Generate Cert Request for Leaf Chained to Distrusted CA"
  1253. CERTNAME="LeafChainedToDistrustedCA"
  1254. CU_SUBJECT="CN=${CERTNAME}, E=${CERTNAME}@bogus.com, O=BOGUS NSS, L=Mountain View, ST=California, C=US"
  1255. certu -R -d "${PROFILEDIR}" -f "${R_PWFILE}" -z "${R_NOISE_FILE}" -o req 2>&1
  1256. CU_ACTION="Sign ${CERTNAME}'s Request"
  1257. cp ${CERTDIR}/req ${CADIR}
  1258. certu -C -c "DistrustedCA" -m 100 -v 60 -d "${P_R_CADIR}" \
  1259. -i req -o "${CERTNAME}.cert" -f "${R_PWFILE}" 2>&1
  1260. CU_ACTION="Import $CERTNAME's Cert -t u,u,u"
  1261. certu -A -n "$CERTNAME" -t "u,u,u" -d "${PROFILEDIR}" -f "${R_PWFILE}" \
  1262. -i "${CERTNAME}.cert" 2>&1
  1263. RETEXPECTED=255
  1264. CU_ACTION="Verify ${CERTNAME} Cert for SSL Server"
  1265. certu -V -n ${CERTNAME} -u V -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1266. CU_ACTION="Verify ${CERTNAME} Cert for SSL Client"
  1267. certu -V -n ${CERTNAME} -u C -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1268. CU_ACTION="Verify ${CERTNAME} Cert for Email signer"
  1269. certu -V -n ${CERTNAME} -u S -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1270. CU_ACTION="Verify ${CERTNAME} Cert for Email recipient"
  1271. certu -V -n ${CERTNAME} -u R -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1272. CU_ACTION="Verify ${CERTNAME} Cert for OCSP responder"
  1273. certu -V -n ${CERTNAME} -u O -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1274. CU_ACTION="Verify ${CERTNAME} Cert for Object Signer"
  1275. certu -V -n ${CERTNAME} -u J -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1276. CERTNAME="Distrusted"
  1277. CU_ACTION="Verify ${CERTNAME} Cert for SSL Server"
  1278. certu -V -n ${CERTNAME} -u V -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1279. CU_ACTION="Verify ${CERTNAME} Cert for SSL Client"
  1280. certu -V -n ${CERTNAME} -u C -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1281. CU_ACTION="Verify ${CERTNAME} Cert for Email signer"
  1282. certu -V -n ${CERTNAME} -u S -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1283. CU_ACTION="Verify ${CERTNAME} Cert for Email recipient"
  1284. certu -V -n ${CERTNAME} -u R -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1285. CU_ACTION="Verify ${CERTNAME} Cert for OCSP responder"
  1286. certu -V -n ${CERTNAME} -u O -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1287. CU_ACTION="Verify ${CERTNAME} Cert for Object Signer"
  1288. certu -V -n ${CERTNAME} -u J -d "${PROFILEDIR}" -f "${R_PWFILE}" 2>&1
  1289. RETEXPECTED=0
  1290. }
  1291. ############################## cert_cleanup ############################
  1292. # local shell function to finish this script (no exit since it might be
  1293. # sourced)
  1294. ########################################################################
  1295. cert_cleanup()
  1296. {
  1297. cert_log "$SCRIPTNAME: finished $SCRIPTNAME"
  1298. html "</TABLE><BR>"
  1299. cd ${QADIR}
  1300. . common/cleanup.sh
  1301. }
  1302. ################## main #################################################
  1303. cert_init
  1304. cert_all_CA
  1305. cert_extended_ssl
  1306. cert_ssl
  1307. cert_smime_client
  1308. cert_fips
  1309. cert_eccurves
  1310. cert_extensions
  1311. cert_test_password
  1312. cert_test_distrust
  1313. if [ -z "$NSS_TEST_DISABLE_CRL" ] ; then
  1314. cert_crl_ssl
  1315. else
  1316. echo "$SCRIPTNAME: Skipping CRL Tests"
  1317. fi
  1318. if [ -n "$DO_DIST_ST" -a "$DO_DIST_ST" = "TRUE" ] ; then
  1319. cert_stresscerts
  1320. fi
  1321. cert_iopr_setup
  1322. cert_cleanup