summaryrefslogtreecommitdiffstats
path: root/security/nss/tests/dbupgrade/dbupgrade.sh
blob: 0302e614348bab09303bfa25dff345db353bc55c (plain)
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
#!/bin/sh
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

########################################################################
#
# mozilla/security/nss/tests/dbupgrade/dbupgrade.sh
#
# Script to upgrade databases to Shared DB
#
# needs to work on all Unix and Windows platforms
#
# special strings
# ---------------
#   FIXME ... known problems, search for this string
#   NOTE .... unexpected behavior
#
########################################################################

############################ dbupgrade_init ############################
# local shell function to initialize this script
########################################################################
dbupgrade_init()
{
	if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then 
		cd ${QADIR}/common
		. ./init.sh
	fi
	
	if [ ! -r "${CERT_LOG_FILE}" ]; then  # we need certificates here
		cd ${QADIR}/cert 
		. ./cert.sh
	fi

	if [ ! -d ${HOSTDIR}/SDR ]; then  # we also need sdr as well
		cd ${QADIR}/sdr
		. ./sdr.sh
	fi
	
	SCRIPTNAME=dbupgrade.sh
	if [ -z "${CLEANUP}" ] ; then     # if nobody else is responsible for
		CLEANUP="${SCRIPTNAME}"       # cleaning this script will do it
	fi
	
	echo "$SCRIPTNAME: DB upgrade tests ==============================="
}

############################ dbupgrade_main ############################
# local shell function to upgrade certificate databases
########################################################################
dbupgrade_main()
{
	# 'reset' the databases to initial values
	echo "Reset databases to their initial values:"
	cd ${HOSTDIR}
	${BINDIR}/certutil -D -n objsigner -d alicedir 2>&1
	${BINDIR}/certutil -M -n FIPS_PUB_140_Test_Certificate -t "C,C,C" -d fips -f ${FIPSPWFILE} 2>&1
	${BINDIR}/certutil -L -d fips 2>&1
	rm -f smime/alicehello.env
	
	# test upgrade to the new database
	echo "nss" > ${PWFILE}
	html_head "Legacy to shared Library update"
	dirs="alicedir bobdir CA cert_extensions client clientCA dave eccurves eve ext_client ext_server SDR server serverCA ssl_gtests stapling tools/copydir"
	for i in $dirs
	do
		echo $i
		if [ -d $i ]; then
			echo "upgrading db $i"
			${BINDIR}/certutil -G -g 512 -d sql:$i -f ${PWFILE} -z ${NOISE_FILE} 2>&1
			html_msg $? 0 "Upgrading $i"
		else
			echo "skipping db $i"
			html_msg 0 0 "No directory $i"
		fi
	done
	
	if [ -d fips ]; then
		echo "upgrading db fips"
		${BINDIR}/certutil -S -g 1024 -n tmprsa -t "u,u,u" -s "CN=tmprsa, C=US" -x -d sql:fips -f ${FIPSPWFILE} -z ${NOISE_FILE} 2>&1
		html_msg $? 0 "Upgrading fips"
		# remove our temp certificate we created in the fist token
		${BINDIR}/certutil -F -n tmprsa -d sql:fips -f ${FIPSPWFILE} 2>&1
		${BINDIR}/certutil -L -d sql:fips 2>&1
	fi
	
	html "</TABLE><BR>"
}

########################## dbupgrade_cleanup ###########################
# local shell function to finish this script (no exit since it might be
# sourced)
########################################################################
dbupgrade_cleanup()
{
	cd ${QADIR}
	. common/cleanup.sh
}

################################# main #################################

dbupgrade_init
dbupgrade_main
dbupgrade_cleanup