DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b66b287a2650)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
#!/bin/bash
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Netscape security libraries.
#
# The Initial Developer of the Original Code is
# Sun Microsystems, Inc..
# Portions created by the Initial Developer are Copyright (C) 2004-2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

# This script runs NSS against test data provided by the United Kingdom
# National Infrastructure Security Co-ordination Centre (NISCC).
# The test data is not public and is not provided with this script.
########################################################################
# Base location to work from
NISCC_HOME=${NISCC_HOME:-/niscc}
export NISCC_HOME
# Set to where special NSS version exists. 
NSS_HACK=${NSS_HACK:-${NISCC_HOME}/nss_hack}; export NSS_HACK
# NSS version to test
LOCALDIST=${LOCALDIST:-/share/builds/sbstools/nsstools}
export LOCALDIST
# If true, do not rebuild client and server directories
NO_SETUP=${NO_SETUP:-"false"}; export NO_SETUP
# location of NISCC SSL testcases
TEST=${TEST:-"${NISCC_HOME}/NISCC_SSL_testcases"}; export TEST
# build the fully qualified domain name
# NOTE: domainname(1) may return the wrong domain in NIS environments
DOMSUF=${DOMSUF:-`domainname`}
if [ -z "$HOST" ]; then
	HOST=`uname -n`
fi
HOSTNAME=$HOST.$DOMSUF; export HOSTNAME
# Who and how to mail the output to
QA_LIST=${QA_LIST:-"nobody@localhost"}; export QA_LIST
MAIL_COMMAND=${MAIL_COMMAND:-/bin/mail}; export MAIL_COMMAND
# Whether or not to archive the logs
LOG_STORE=${LOG_STORE:-"false"}; export LOG_STORE


##############################################################
# set build dir, bin and lib directories
##############################################################
init()
{
  #enable useful core files to be generated in case of crash
  ulimit -c unlimited

# gmake is needed in the path for this suite to run
  PATH=/usr/bin:/usr/sbin:/usr/local/bin:/tools/ns/bin; export PATH
  echo "PATH $PATH" >> $NISCC_HOME/nisccLog00

  DISTTYPE=`cd ${NSS_HACK}/mozilla/security/nss/tests/common; gmake objdir_name`
  echo "DISTTYPE ${DISTTYPE}" >> $NISCC_HOME/nisccLog00
  HACKBIN=${NSS_HACK}/mozilla/dist/${DISTTYPE}/bin; export HACKBIN
  HACKLIB=${NSS_HACK}/mozilla/dist/${DISTTYPE}/lib; export HACKLIB

  TESTBIN=${LOCALDIST}/mozilla/dist/${DISTTYPE}/bin; export TESTBIN
  TESTLIB=${LOCALDIST}/mozilla/dist/${DISTTYPE}/lib; export TESTLIB

# Verify NISCC_TEST was set in the proper library
	if strings ${HACKLIB}/libssl3.so | grep NISCC_TEST > /dev/null 2>&1; then
		echo "${HACKLIB}/libssl3.so contains NISCC_TEST" >> \
$NISCC_HOME/nisccLog00
	else
		echo "${HACKLIB}/libssl3.so does NOT contain NISCC_TEST" >> \
$NISCC_HOME/nisccLog00
	fi

	if strings ${TESTLIB}/libssl3.so | grep NISCC_TEST > /dev/null 2>&1; then
		echo "${TESTLIB}/libssl3.so contains NISCC_TEST" >> \
$NISCC_HOME/nisccLog00
	else
		echo "${TESTLIB}/libssl3.so does NOT contain NISCC_TEST" >> \
$NISCC_HOME/nisccLog00
	fi
}
#end of init section


##############################################################
# Setup simple client and server directory
##############################################################
ssl_setup_dirs_simple()
{
  [ "$NO_SETUP" = "true" ] && return

  CLIENT=${NISCC_HOME}/niscc_ssl/simple_client
  SERVER=${NISCC_HOME}/niscc_ssl/simple_server

#
# Setup simple client directory
#
  rm -rf $CLIENT
  mkdir -p $CLIENT
  echo test > $CLIENT/password-is-test.txt
  LD_LIBRARY_PATH=${TESTLIB}; export LD_LIBRARY_PATH
  ${TESTBIN}/certutil -N -d $CLIENT -f $CLIENT/password-is-test.txt >> \
$NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/certutil -A -d $CLIENT -n rootca -i $TEST/rootca.crt -t \
"C,C," >> $NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/pk12util -i $TEST/client_crt.p12 -d $CLIENT -k \
$CLIENT/password-is-test.txt -W testtest1 >> $NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/certutil -L -d $CLIENT >> $NISCC_HOME/nisccLog00 2>&1

  echo "GET /stop HTTP/1.0" > $CLIENT/stop.txt
  echo ""                  >> $CLIENT/stop.txt

#
# Setup simple server directory
#
  rm -rf $SERVER
  mkdir -p $SERVER
  echo test > $SERVER/password-is-test.txt
  ${TESTBIN}/certutil -N -d $SERVER -f $SERVER/password-is-test.txt \
>> $NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/certutil -A -d $SERVER -n rootca -i $TEST/rootca.crt -t \
"TC,C," >> $NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/pk12util -i $TEST/server_crt.p12 -d $SERVER -k \
$SERVER/password-is-test.txt -W testtest1 >> $NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/certutil -L -d $SERVER >> $NISCC_HOME/nisccLog00 2>&1

  unset LD_LIBRARY_PATH
}


##############################################################
# Setup resigned client and server directory
###############################################################
ssl_setup_dirs_resigned()
{
  [ "$NO_SETUP" = "true" ] && return

  CLIENT=${NISCC_HOME}/niscc_ssl/resigned_client
  SERVER=${NISCC_HOME}/niscc_ssl/resigned_server

#
# Setup resigned client directory
#
  rm -rf $CLIENT
  mkdir -p $CLIENT
  echo test > $CLIENT/password-is-test.txt
  LD_LIBRARY_PATH=${TESTLIB}; export LD_LIBRARY_PATH
  ${TESTBIN}/certutil -N -d $CLIENT -f $CLIENT/password-is-test.txt \
>> $NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/certutil -A -d $CLIENT -n rootca -i $TEST/rootca.crt -t \
"C,C," >> $NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/pk12util -i $TEST/client_crt.p12 -d $CLIENT -k \
$CLIENT/password-is-test.txt -W testtest1 >> $NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/certutil -L -d $CLIENT  >> $NISCC_HOME/nisccLog00 2>&1

  echo "GET /stop HTTP/1.0" > $CLIENT/stop.txt
  echo ""                  >> $CLIENT/stop.txt

#
# Setup resigned server directory
#
  rm -rf $SERVER
  mkdir -p $SERVER
  echo test > $SERVER/password-is-test.txt
  ${TESTBIN}/certutil -N -d $SERVER -f $SERVER/password-is-test.txt \
>> $NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/certutil -A -d $SERVER -n rootca -i $TEST/rootca.crt -t \
"TC,C," >> $NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/pk12util -i $TEST/server_crt.p12 -d $SERVER -k \
$SERVER/password-is-test.txt -W testtest1 >> $NISCC_HOME/nisccLog00 2>&1
  ${TESTBIN}/certutil -L -d $SERVER >> $NISCC_HOME/nisccLog00 2>&1

  unset LD_LIBRARY_PATH
}


##############################################################
# NISCC SMIME tests
##############################################################
niscc_smime()
{
  cd ${NISCC_HOME}/NISCC_SMIME_testcases

  if [ ! -d ${NISCC_HOME}/niscc_smime ]; then
	mkdir -p ${NISCC_HOME}/niscc_smime
  fi

  SMIME_CERT_DB_DIR=envDB; export SMIME_CERT_DB_DIR
  NSS_STRICT_SHUTDOWN=1; export NSS_STRICT_SHUTDOWN
  NSS_DISABLE_ARENA_FREE_LIST=1; export NSS_DISABLE_ARENA_FREE_LIST
  LD_LIBRARY_PATH=${TESTLIB}; export LD_LIBRARY_PATH

# Generate envDB if needed
  if [ ! -d $SMIME_CERT_DB_DIR ]; then
	mkdir -p $SMIME_CERT_DB_DIR
 	echo testtest1 > password-is-testtest1.txt
	${TESTBIN}/certutil -N -d ./${SMIME_CERT_DB_DIR} -f \
password-is-testtest1.txt > /dev/null 2>&1
	${TESTBIN}/certutil -A -d $SMIME_CERT_DB_DIR -i CA.crt -n CA -t "TC,C,"
	${TESTBIN}/certutil -A -d $SMIME_CERT_DB_DIR -i Client.crt -n Client \
-t "TC,C,"
	${TESTBIN}/pk12util -i ./CA.p12 -d $SMIME_CERT_DB_DIR -k \
./password-is-test.txt -W testtest1 
	${TESTBIN}/pk12util -i ./Client.p12 -d $SMIME_CERT_DB_DIR -k \
./password-is-test.txt -W testtest1 
  fi

# if p7m-ed-m-files.txt does not exist, then generate it.
  if [ ! -f p7m-ed-m-files.txt ]; then
	find ./p7m-ed-m-0* -type f -print >> p7m-ed-m-files.txt
  fi

  ${TESTBIN}/cmsutil -D -d $SMIME_CERT_DB_DIR -p testtest1 -b -i \
p7m-ed-m-files.txt > $NISCC_HOME/niscc_smime/p7m-ed-m-results.txt 2>&1 
 
  SMIME_CERT_DB_DIR=sigDB; export SMIME_CERT_DB_DIR
# Generate sigDB if needed
  if [ ! -d $SMIME_CERT_DB_DIR ]; then
	mkdir -p $SMIME_CERT_DB_DIR
	${TESTBIN}/certutil -N -d $SMIME_CERT_DB_DIR -f password-is-testtest1.txt
	${TESTBIN}/certutil -A -d $SMIME_CERT_DB_DIR -i CA.crt -n CA -t "TC,C,"
	${TESTBIN}/certutil -A -d $SMIME_CERT_DB_DIR -i Client.crt -n Client \
-t "TC,C,"
  fi

# if p7m-sd-dt-files.txt does not exist, then generate it.
  if [ ! -f p7m-sd-dt-files.txt ]; then
	find ./p7m-sd-dt-[cm]-* -type f -print >> p7m-sd-dt-files.txt
  fi

  if [ ! -f detached.txt ]; then
	touch detached.txt
  fi

  ${TESTBIN}/cmsutil -D -d $SMIME_CERT_DB_DIR -c detached.txt -b -i \
p7m-sd-dt-files.txt > $NISCC_HOME/niscc_smime/p7m-sd-dt-results.txt 2>&1 

# if p7m-sd-op-files.txt does not exist, then generate it.
  if [ ! -f p7m-sd-op-files.txt ]; then
	find ./p7m-sd-op-[cm]-* -type f -print >> p7m-sd-op-files.txt
  fi

  ${TESTBIN}/cmsutil -D -d $SMIME_CERT_DB_DIR -b -i p7m-sd-op-files.txt > \
$NISCC_HOME/niscc_smime/p7m-sd-op-results.txt 2>&1 

  unset LD_LIBRARY_PATH

  find_core
}
#end of smime section

##############################################################
# set env variables for NISCC SSL tests
##############################################################
niscc_ssl_init()
{
  NSS_STRICT_SHUTDOWN=1; export NSS_STRICT_SHUTDOWN
  NSS_DISABLE_ARENA_FREE_LIST=1; export NSS_DISABLE_ARENA_FREE_LIST
  cd $NISCC_HOME
}


##############################################################
# do simple client auth tests
# Use an altered client against the server
##############################################################
ssl_simple_client_auth()
{
  CLIENT=${NISCC_HOME}/niscc_ssl/simple_client; export CLIENT
  SERVER=${NISCC_HOME}/niscc_ssl/simple_server; export SERVER
  PORT=8443; export PORT
  START_AT=1; export START_AT
  STOP_AT=106160; export STOP_AT
  unset NISCC_TEST; export NISCC_TEST
  LD_LIBRARY_PATH=${TESTLIB}; export LD_LIBRARY_PATH
  ${TESTBIN}/selfserv -p $PORT -d $SERVER -n server_crt -rr -t 5 -w test > \
$NISCC_HOME/nisccLog01 2>&1 &
  sleep 10

  NISCC_TEST=$TEST/simple_client; export NISCC_TEST
  LD_LIBRARY_PATH=${HACKLIB}; export LD_LIBRARY_PATH
  ${HACKBIN}/strsclnt -d $CLIENT -n client_crt -p $PORT -t 4 -c 106160 -o -N \
-w test $HOSTNAME > $NISCC_HOME/nisccLog02 2>&1

  unset NISCC_TEST; export NISCC_TEST
  echo "starting tstclnt to shutdown simple client selfserv process"
  ${HACKBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f -w \
test < $CLIENT/stop.txt >> nisccLog02 2>&1
  ${HACKBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f -w \
test < $CLIENT/stop.txt >> nisccLog02 2>&1
  ${HACKBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f -w \
test < $CLIENT/stop.txt >> nisccLog02 2>&1
  ${HACKBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f -w \
test < $CLIENT/stop.txt >> nisccLog02 2>&1
  ${HACKBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f -w \
test < $CLIENT/stop.txt >> nisccLog02 2>&1

  unset LD_LIBRARY_PATH

  sleep 10

  find_core
}

##############################################################
# do simple server auth tests
# Use an altered server against the client
##############################################################
ssl_simple_server_auth()
{
  CLIENT=${NISCC_HOME}/niscc_ssl/simple_client; export CLIENT
  SERVER=${NISCC_HOME}/niscc_ssl/simple_server; export SERVER
  PORT=8444; export PORT
  START_AT=1; export START_AT
  STOP_AT=106167; export STOP_AT
  LD_LIBRARY_PATH=${HACKLIB}; export LD_LIBRARY_PATH
  NISCC_TEST=$TEST/simple_server; export NISCC_TEST
  ${HACKBIN}/selfserv -p $PORT -d $SERVER -n server_crt -t 5 -w test > \
$NISCC_HOME/nisccLog03 2>&1 &

  unset NISCC_TEST; export NISCC_TEST
  LD_LIBRARY_PATH=${TESTLIB}; export LD_LIBRARY_PATH
  ${TESTBIN}/strsclnt -d $CLIENT -p $PORT -t 4 -c 106167 -o -N $HOSTNAME > \
$NISCC_HOME/nisccLog04 2>&1 

  echo "starting tstclnt to shutdown simple server selfserv process"
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog04 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog04 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog04 2>&1 
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog04 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog04 2>&1

  unset LD_LIBRARY_PATH

  sleep 10

  find_core
}

##############################################################
# do simple rootCA tests
# Use an altered server against the client
##############################################################
ssl_simple_rootca()
{
  CLIENT=${NISCC_HOME}/niscc_ssl/simple_client; export CLIENT
  SERVER=${NISCC_HOME}/niscc_ssl/simple_server; export SERVER
  PORT=8445; export PORT
  START_AT=1; export START_AT
  STOP_AT=106190; export STOP_AT
  LD_LIBRARY_PATH=${HACKLIB}; export LD_LIBRARY_PATH
  NISCC_TEST=$TEST/simple_rootca; export NISCC_TEST
  ${HACKBIN}/selfserv -p $PORT -d $SERVER -n server_crt -t 5 -w test > \
$NISCC_HOME/nisccLog05 2>&1 &

  unset NISCC_TEST; export NISCC_TEST
  LD_LIBRARY_PATH=${TESTLIB}; export LD_LIBRARY_PATH
  ${TESTBIN}/strsclnt -d $CLIENT -p $PORT -t 4 -c 106190 -o -N $HOSTNAME > \
$NISCC_HOME/nisccLog06 2>&1

  echo "starting tstclnt to shutdown simple rootca selfserv process"
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog06 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog06 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog06 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog06 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog06 2>&1

  unset LD_LIBRARY_PATH
  sleep 10

  find_core
}

##############################################################
# do resigned client auth tests
# Use an altered client against the server
##############################################################
ssl_resigned_client_auth()
{
  CLIENT=${NISCC_HOME}/niscc_ssl/resigned_client; export CLIENT
  SERVER=${NISCC_HOME}/niscc_ssl/resigned_server; export SERVER
  PORT=8446; export PORT
  START_AT=0; export START_AT
  STOP_AT=99981; export STOP_AT
  unset NISCC_TEST; export NISCC_TEST
  LD_LIBRARY_PATH=${TESTLIB}; export LD_LIBRARY_PATH
  ${TESTBIN}/selfserv -p $PORT -d $SERVER -n server_crt -rr -t 5 -w test > \
$NISCC_HOME/nisccLog07 2>&1 &

  NISCC_TEST=$TEST/resigned_client; export NISCC_TEST
  LD_LIBRARY_PATH=${HACKLIB}; export LD_LIBRARY_PATH
  ${HACKBIN}/strsclnt -d $CLIENT -n client_crt -p $PORT -t 4 -c 99982 -o -N \
-w test $HOSTNAME > $NISCC_HOME/nisccLog08 2>&1 

  unset NISCC_TEST; export NISCC_TEST
  echo "starting tstclnt to shutdown resigned client selfserv process"
  ${HACKBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog08 2>&1
  ${HACKBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog08 2>&1
  ${HACKBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog08 2>&1
  ${HACKBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog08 2>&1
  ${HACKBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog08 2>&1

  unset LD_LIBRARY_PATH

  sleep 10

  find_core
}

##############################################################
# do resigned server auth tests
# Use an altered server against the client
##############################################################
ssl_resigned_server_auth()
{
  CLIENT=${NISCC_HOME}/niscc_ssl/resigned_client; export CLIENT
  SERVER=${NISCC_HOME}/niscc_ssl/resigned_server; export SERVER
  PORT=8447; export PORT
  START_AT=0; export START_AT
  STOP_AT=100068; export STOP_AT
  LD_LIBRARY_PATH=${HACKLIB}; export LD_LIBRARY_PATH
  NISCC_TEST=$TEST/resigned_server; export NISCC_TEST
  ${HACKBIN}/selfserv -p $PORT -d $SERVER -n server_crt -t 5 -w test > \
$NISCC_HOME/nisccLog09 2>&1 &

  unset NISCC_TEST; export NISCC_TEST
  LD_LIBRARY_PATH=${TESTLIB}; export LD_LIBRARY_PATH
  ${TESTBIN}/strsclnt -d $CLIENT -p $PORT -t 4 -c 100069 -o -N $HOSTNAME > \
$NISCC_HOME/nisccLog10 2>&1 

  echo "starting tstclnt to shutdown resigned server selfserv process"
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog10 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog10 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog10 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog10 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog10 2>&1

  unset LD_LIBRARY_PATH

  sleep 10

  find_core
}

##############################################################
# do resigned rootCA tests
# Use an altered server against the client
##############################################################
ssl_resigned_rootca()
{
  CLIENT=${NISCC_HOME}/niscc_ssl/resigned_client; export CLIENT
  SERVER=${NISCC_HOME}/niscc_ssl/resigned_server; export SERVER
  PORT=8448; export PORT
  START_AT=0; export START_AT
  STOP_AT=99959; export STOP_AT
  LD_LIBRARY_PATH=${HACKLIB}; export LD_LIBRARY_PATH
  NISCC_TEST=$TEST/resigned_rootca; export NISCC_TEST
  ${HACKBIN}/selfserv -p $PORT -d $SERVER -n server_crt -t 5 -w test > \
$NISCC_HOME/nisccLog11 2>&1 &

  unset NISCC_TEST; export NISCC_TEST
  LD_LIBRARY_PATH=${TESTLIB}; export LD_LIBRARY_PATH
  ${TESTBIN}/strsclnt -d $CLIENT -p $PORT -t 4 -c 99960 -o -N $HOSTNAME > \
$NISCC_HOME/nisccLog12 2>&1 

  echo "starting tstclnt to shutdown resigned rootca selfserv process"
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog12 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog12 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog12 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog12 2>&1
  ${TESTBIN}/tstclnt -h $HOSTNAME -p $PORT -d $CLIENT -n client_crt -o -f \
-w test < $CLIENT/stop.txt >> nisccLog12 2>&1

  unset LD_LIBRARY_PATH

  sleep 10

  find_core
}

###############################################################
# find core file and email if found, move core file to save it
###############################################################
find_core()
{
  for w in `find $NISCC_HOME -name "core" -print`
  do
      mv $w $w.`date +%H%M%S`
  done
}


###############################################################
# NISCC tests result in a failure only if a core file is produced
# Mail out the status - the log summary is not mailed due to its 
# size of about one hundred megabytes.
###############################################################
mail_testLog()
{
  # remove mozilla nss build false positives and core stored in previous runs
  find $NISCC_HOME -name "core*" -print | grep -v coreconf | grep -v \
core_watch | grep -v archive >> $NISCC_HOME/crashLog
  SIZE=`cat $NISCC_HOME/crashLog | wc -l`
  if [ "$SIZE" -gt 0 ]; then
      cat $NISCC_HOME/crashLog >> $NISCC_HOME/nisccLogSummary
      $MAIL_COMMAND -s "WEEKLY NISCC TESTS FAILED: check end of logfile" \
        $QA_LIST < /dev/null
  else
      $MAIL_COMMAND -s "PASSED: weekly NISCC tests completed" \
        $QA_LIST < /dev/null
  fi
}


###############################################################
# summarise all logs
###############################################################
log_summary()
{

  for a in $NISCC_HOME/nisccLog[0-9]*
      do echo ================================== $a
      grep -v using $a | sort | uniq -c | sort -b -n +0 -1
      done | tee $NISCC_HOME/nisccLogSummary

  for a in $NISCC_HOME/niscc_smime/p7m-*-results.txt
      do echo ================================== $a
      grep -v using $a | sort | uniq -c | sort -b -n +0 -1
      done | tee -a $NISCC_HOME/nisccLogSummary
}


###############################################################
# move the old mozilla and log files to save them, delete extra
# log files
###############################################################
move_files()
{

  cd $NISCC_HOME

  if [ "$LOG_STORE" = "true" ]; then
	# Check for archive directory
	if [ ! -d $NISCC_HOME/archive ]; then
		mkdir -p $NISCC_HOME/archive
	fi
	# Determine next log storage point
	DATE=`date +%Y%m%d`
	SLOT=`ls -1 $NISCC_HOME/archive | grep ${DATE} | wc -l`
	SLOT=`expr $SLOT + 1`
	LOCATION=$NISCC_HOME/archive/${DATE}.${SLOT}
	mkdir -p ${LOCATION}
	# Archive the logs
	mv nisccBuildLog ${LOCATION} 2> /dev/null
	mv nisccLogSummary ${LOCATION}
	mv nisccLog00 ${LOCATION}
	mv nisccLog01 ${LOCATION}
	mv nisccLog02 ${LOCATION}
	mv nisccLog03 ${LOCATION}
	mv nisccLog04 ${LOCATION}
	mv nisccLog05 ${LOCATION}
	mv nisccLog06 ${LOCATION}
	mv nisccLog07 ${LOCATION}
	mv nisccLog08 ${LOCATION}
	mv nisccLog09 ${LOCATION}
	mv nisccLog10 ${LOCATION}
	mv nisccLog11 ${LOCATION}
	mv nisccLog12 ${LOCATION}
	mv niscc_smime/p7m-ed-m-results.txt ${LOCATION}
	mv niscc_smime/p7m-sd-dt-results.txt ${LOCATION}
	mv niscc_smime/p7m-sd-op-results.txt ${LOCATION}
	# Archive any core files produced
	for CORE in `cat $NISCC_HOME/crashLog`
	do
		mv $CORE ${LOCATION}
	done
	mv crashLog ${LOCATION}
	return
  fi

  if [ -d ../mozilla ]; then
	mv -f ../mozilla ../mozilla.old
  	mv nisccBuildLog nisccBuildLog.old
  fi
  mv nisccLogSummary nisccLogSummary.old
  mv crashLog crashLog.old

  rm -f nisccLog00 nisccLog01 nisccLog02 nisccLog03 nisccLog04 nisccLog05 \
nisccLog06 nisccLog07 nisccLog08 nisccLog09 nisccLog10 nisccLog11 nisccLog12
  rm -f niscc_smime/p7m-ed-m-results.txt \
      niscc_smime/p7m-sd-dt-results.txt \
      niscc_smime/p7m-sd-op-results.txt
}

############################## main ##############################
init
niscc_smime
niscc_ssl_init
ssl_setup_dirs_simple
  ssl_simple_client_auth
  ssl_simple_server_auth
  ssl_simple_rootca
ssl_setup_dirs_resigned
  ssl_resigned_client_auth
  ssl_resigned_server_auth
  ssl_resigned_rootca
log_summary
mail_testLog
move_files