~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/security/nss/tests/ssl/ecssl.sh

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
#
 
3
# The contents of this file are subject to the Mozilla Public
 
4
# License Version 1.1 (the "License"); you may not use this file
 
5
# except in compliance with the License. You may obtain a copy of
 
6
# the License at http://www.mozilla.org/MPL/
 
7
 
8
# Software distributed under the License is distributed on an "AS
 
9
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
# implied. See the License for the specific language governing
 
11
# rights and limitations under the License.
 
12
 
13
# The Original Code is the Netscape security libraries.
 
14
 
15
# The Initial Developer of the Original Code is Netscape
 
16
# Communications Corporation.  Portions created by Netscape are 
 
17
# Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 
18
# Rights Reserved.
 
19
 
20
# Portions created by Sun Microsystems, Inc. are Copyright (C) 2003
 
21
# Sun Microsystems, Inc. All Rights Reserved.
 
22
#
 
23
# Contributor(s):
 
24
#       Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
 
25
 
26
# Alternatively, the contents of this file may be used under the
 
27
# terms of the GNU General Public License Version 2 or later (the
 
28
# "GPL"), in which case the provisions of the GPL are applicable 
 
29
# instead of those above.  If you wish to allow use of your 
 
30
# version of this file only under the terms of the GPL and not to
 
31
# allow others to use your version of this file under the MPL,
 
32
# indicate your decision by deleting the provisions above and
 
33
# replace them with the notice and other provisions required by
 
34
# the GPL.  If you do not delete the provisions above, a recipient
 
35
# may use your version of this file under either the MPL or the
 
36
# GPL.
 
37
#
 
38
#
 
39
########################################################################
 
40
#
 
41
# mozilla/security/nss/tests/ssl/ssl.sh
 
42
#
 
43
# Script to test NSS SSL
 
44
#
 
45
# needs to work on all Unix and Windows platforms
 
46
#
 
47
# special strings
 
48
# ---------------
 
49
#   FIXME ... known problems, search for this string
 
50
#   NOTE .... unexpected behavior
 
51
#
 
52
########################################################################
 
53
 
 
54
############################## ssl_init ################################
 
55
# local shell function to initialize this script
 
56
########################################################################
 
57
ssl_init()
 
58
{
 
59
  SCRIPTNAME=ssl.sh      # sourced - $0 would point to all.sh
 
60
 
 
61
  if [ -z "${CLEANUP}" ] ; then     # if nobody else is responsible for
 
62
      CLEANUP="${SCRIPTNAME}"       # cleaning this script will do it
 
63
  fi
 
64
  
 
65
  if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then
 
66
      cd ../common
 
67
      . ./init.sh
 
68
  fi
 
69
  if [ ! -r $CERT_LOG_FILE ]; then  # we need certificates here
 
70
      cd ../cert
 
71
      . ./cert.sh
 
72
  fi
 
73
  SCRIPTNAME=ssl.sh
 
74
  echo "$SCRIPTNAME: SSL tests ==============================="
 
75
 
 
76
  grep "SUCCESS: SSL passed" $CERT_LOG_FILE >/dev/null || {
 
77
      html_head "SSL Test failure"
 
78
      Exit 8 "Fatal - SSL of cert.sh needs to pass first"
 
79
  }
 
80
 
 
81
  PORT=${PORT-8443}
 
82
 
 
83
  # Test case files
 
84
  SSLCOV=${QADIR}/ssl/sslcov.txt
 
85
  SSLAUTH=${QADIR}/ssl/sslauth.txt
 
86
  SSLSTRESS=${QADIR}/ssl/sslstress.txt
 
87
  REQUEST_FILE=${QADIR}/ssl/sslreq.txt
 
88
 
 
89
  #temparary files
 
90
  SERVEROUTFILE=${TMP}/tests_server.$$
 
91
  SERVERPID=${TMP}/tests_pid.$$
 
92
 
 
93
  R_SERVERPID=../tests_pid.$$
 
94
 
 
95
  TEMPFILES="$TMPFILES ${SERVEROUTFILE}  ${SERVERPID}"
 
96
 
 
97
  fileout=0 #FIXME, looks like all.sh tried to turn this on but actually didn't
 
98
  #fileout=1
 
99
  #verbose="-v" #FIXME - see where this is usefull
 
100
 
 
101
  USER_NICKNAME=TestUser
 
102
  NORM_EXT=""
 
103
 
 
104
  cd ${CLIENTDIR}
 
105
}
 
106
 
 
107
########################### is_selfserv_alive ##########################
 
108
# local shell function to exit with a fatal error if selfserver is not
 
109
# running
 
110
########################################################################
 
111
is_selfserv_alive()
 
112
{
 
113
  if [ ! -f "${SERVERPID}" ]; then
 
114
      echo "$SCRIPTNAME: Error - selfserv PID file ${SERVERPID} doesn't exist"
 
115
      sleep 5
 
116
      if [ ! -f "${SERVERPID}" ]; then
 
117
          Exit 9 "Fatal - selfserv pid file ${SERVERPID} does not exist"
 
118
      fi
 
119
  fi
 
120
  PID=`cat ${SERVERPID}`
 
121
  #if  [ "${OS_ARCH}" = "Linux" ]; then
 
122
      kill -0 $PID >/dev/null 2>/dev/null || Exit 10 "Fatal - selfserv process not detectable"
 
123
  #else
 
124
      #$PS -e | grep $PID >/dev/null || \
 
125
          #Exit 10 "Fatal - selfserv process not detectable"
 
126
  #fi
 
127
}
 
128
 
 
129
########################### wait_for_selfserv ##########################
 
130
# local shell function to wait until selfserver is running and initialized
 
131
########################################################################
 
132
wait_for_selfserv()
 
133
{
 
134
  echo "tstclnt -p ${PORT} -h ${HOSTADDR} -q "
 
135
  echo "        -d ${P_R_CLIENTDIR} < ${REQUEST_FILE} \\"
 
136
  #echo "tstclnt -q started at `date`"
 
137
  tstclnt -p ${PORT} -h ${HOSTADDR} -q -d ${P_R_CLIENTDIR} < ${REQUEST_FILE}
 
138
  if [ $? -ne 0 ]; then
 
139
      html_failed "<TR><TD> Wait for Server "
 
140
      echo "RETRY: tstclnt -p ${PORT} -h ${HOSTADDR} -q \\"
 
141
      echo "               -d ${P_R_CLIENTDIR} < ${REQUEST_FILE}"
 
142
      tstclnt -p ${PORT} -h ${HOSTADDR} -q -d ${P_R_CLIENTDIR} < ${REQUEST_FILE}
 
143
  elif [ sparam = "-c ABCDEFGHIJKLMNOPQRSTabcdefghijklmnvy" ] ; then # "$1" = "cov" ] ; then
 
144
      html_passed "<TR><TD> Wait for Server"
 
145
  fi
 
146
  is_selfserv_alive
 
147
}
 
148
 
 
149
########################### kill_selfserv ##############################
 
150
# local shell function to kill the selfserver after the tests are done
 
151
########################################################################
 
152
kill_selfserv()
 
153
{
 
154
  ${KILL} `cat ${SERVERPID}`
 
155
  wait `cat ${SERVERPID}`
 
156
  if [ ${fileout} -eq 1 ]; then
 
157
      cat ${SERVEROUTFILE}
 
158
  fi
 
159
  # On Linux selfserv needs up to 30 seconds to fully die and free
 
160
  # the port.  Wait until the port is free. (Bug 129701)
 
161
  if [ "${OS_ARCH}" = "Linux" ]; then
 
162
      until selfserv -b -p ${PORT} 2>/dev/null; do
 
163
          sleep 1
 
164
      done
 
165
  fi
 
166
  rm ${SERVERPID}
 
167
}
 
168
 
 
169
########################### start_selfserv #############################
 
170
# local shell function to start the selfserver with the parameters required 
 
171
# for this test and log information (parameters, start time)
 
172
# also: wait until the server is up and running
 
173
########################################################################
 
174
start_selfserv()
 
175
{
 
176
  if [ -n "$testname" ] ; then
 
177
      echo "$SCRIPTNAME: $testname ----"
 
178
  fi
 
179
  sparam=`echo $sparam | sed -e 's;_; ;g'`
 
180
  echo "selfserv -D -p ${PORT} -d ${P_R_SERVERDIR} -n ${HOSTADDR} \\"
 
181
  echo "         -e ${HOSTADDR}-ec \\"
 
182
  echo "         -w nss ${sparam} -i ${R_SERVERPID} $verbose &"
 
183
  echo "selfserv started at `date`"
 
184
  if [ ${fileout} -eq 1 ]; then
 
185
      selfserv -D -p ${PORT} -d ${P_R_SERVERDIR} -n ${HOSTADDR} \
 
186
               -e ${HOSTADDR}-ec \
 
187
               -w nss ${sparam} -i ${R_SERVERPID} $verbose \
 
188
               > ${SERVEROUTFILE} 2>&1 &
 
189
  else
 
190
      selfserv -D -p ${PORT} -d ${P_R_SERVERDIR} -n ${HOSTADDR} \
 
191
               -e ${HOSTADDR}-ec \
 
192
               -w nss ${sparam} -i ${R_SERVERPID} $verbose &
 
193
  fi
 
194
  wait_for_selfserv
 
195
}
 
196
 
 
197
############################## ssl_cov #################################
 
198
# local shell function to perform SSL Cipher Coverage tests
 
199
########################################################################
 
200
ssl_cov()
 
201
{
 
202
  html_head "SSL Cipher Coverage $NORM_EXT"
 
203
 
 
204
  testname=""
 
205
  sparam="-c ABCDEFGHIJKLMNOPQRSTabcdefghijklmnvyz"
 
206
  start_selfserv # Launch the server
 
207
               
 
208
  p=""
 
209
 
 
210
  while read tls param testname
 
211
  do
 
212
      p=`echo "$testname" | sed -e "s/ .*//"`   #sonmi, only run extended test on SSL3 and TLS
 
213
      
 
214
      if [ "$p" = "SSL2" -a "$NORM_EXT" = "Extended test" ] ; then
 
215
          echo "$SCRIPTNAME: skipping  $testname for $NORM_EXT"
 
216
      elif [ "$tls" != "#" ] ; then
 
217
          echo "$SCRIPTNAME: running $testname ----------------------------"
 
218
          TLS_FLAG=-T
 
219
          if [ $tls = "TLS" ]; then
 
220
              TLS_FLAG=""
 
221
          fi
 
222
 
 
223
          is_selfserv_alive
 
224
          echo "tstclnt -p ${PORT} -h ${HOSTADDR} -c ${param} ${TLS_FLAG} \\"
 
225
          echo "        -f -d ${P_R_CLIENTDIR} < ${REQUEST_FILE}"
 
226
 
 
227
          rm ${TMP}/$HOST.tmp.$$ 2>/dev/null
 
228
          tstclnt -p ${PORT} -h ${HOSTADDR} -c ${param} ${TLS_FLAG} -f \
 
229
                  -d ${P_R_CLIENTDIR} < ${REQUEST_FILE} \
 
230
                  >${TMP}/$HOST.tmp.$$  2>&1
 
231
          ret=$?
 
232
          cat ${TMP}/$HOST.tmp.$$ 
 
233
          rm ${TMP}/$HOST.tmp.$$ 2>/dev/null
 
234
          html_msg $ret 0 "${testname}"
 
235
      fi
 
236
  done < ${SSLCOV}
 
237
 
 
238
  kill_selfserv
 
239
  html "</TABLE><BR>"
 
240
}
 
241
 
 
242
############################## ssl_auth ################################
 
243
# local shell function to perform SSL  Client Authentication tests
 
244
########################################################################
 
245
ssl_auth()
 
246
{
 
247
  html_head "SSL Client Authentication $NORM_EXT"
 
248
 
 
249
  while read value sparam cparam testname
 
250
  do
 
251
      if [ $value != "#" ]; then
 
252
          cparam=`echo $cparam | sed -e 's;_; ;g' -e "s/TestUser/$USER_NICKNAME/g" `
 
253
          start_selfserv
 
254
 
 
255
          echo "tstclnt -p ${PORT} -h ${HOSTADDR} -f -d ${P_R_CLIENTDIR} \\"
 
256
          echo "        ${cparam}  < ${REQUEST_FILE}"
 
257
          rm ${TMP}/$HOST.tmp.$$ 2>/dev/null
 
258
          tstclnt -p ${PORT} -h ${HOSTADDR} -f ${cparam} \
 
259
                  -d ${P_R_CLIENTDIR} < ${REQUEST_FILE} \
 
260
                  >${TMP}/$HOST.tmp.$$  2>&1
 
261
          ret=$?
 
262
          cat ${TMP}/$HOST.tmp.$$ 
 
263
          rm ${TMP}/$HOST.tmp.$$ 2>/dev/null
 
264
 
 
265
          html_msg $ret $value "${testname}" \
 
266
                   "produced a returncode of $ret, expected is $value"
 
267
          kill_selfserv
 
268
      fi
 
269
  done < ${SSLAUTH}
 
270
 
 
271
  html "</TABLE><BR>"
 
272
}
 
273
 
 
274
 
 
275
############################## ssl_stress ##############################
 
276
# local shell function to perform SSL stress test
 
277
########################################################################
 
278
ssl_stress()
 
279
{
 
280
  html_head "SSL Stress Test $NORM_EXT"
 
281
 
 
282
  while read value sparam cparam testname
 
283
  do
 
284
      p=`echo "$testname" | sed -e "s/Stress //" -e "s/ .*//"`   #sonmi, only run extended test on SSL3 and TLS
 
285
      if [ "$p" = "SSL2" -a "$NORM_EXT" = "Extended test" ] ; then
 
286
          echo "$SCRIPTNAME: skipping  $testname for $NORM_EXT"
 
287
      elif [ $value != "#" ]; then
 
288
          cparam=`echo $cparam | sed -e 's;_; ;g'`
 
289
          start_selfserv
 
290
          if [ `uname -n` = "sjsu" ] ; then
 
291
              echo "debugging disapering selfserv... ps -ef | grep selfserv"
 
292
              ps -ef | grep selfserv
 
293
          fi
 
294
 
 
295
          echo "strsclnt -q -p ${PORT} -d ${P_R_CLIENTDIR} -w nss $cparam \\"
 
296
          echo "         $verbose ${HOSTADDR}"
 
297
          echo "strsclnt started at `date`"
 
298
          strsclnt -q -p ${PORT} -d ${P_R_CLIENTDIR} -w nss $cparam \
 
299
                   $verbose ${HOSTADDR}
 
300
          ret=$?
 
301
          echo "strsclnt completed at `date`"
 
302
          html_msg $ret $value "${testname}"
 
303
          if [ `uname -n` = "sjsu" ] ; then
 
304
              echo "debugging disapering selfserv... ps -ef | grep selfserv"
 
305
              ps -ef | grep selfserv
 
306
          fi
 
307
          kill_selfserv
 
308
      fi
 
309
  done < ${SSLSTRESS}
 
310
 
 
311
  html "</TABLE><BR>"
 
312
}
 
313
 
 
314
 
 
315
############################## ssl_cleanup #############################
 
316
# local shell function to finish this script (no exit since it might be
 
317
# sourced)
 
318
########################################################################
 
319
ssl_cleanup()
 
320
{
 
321
  rm $SERVERPID 2>/dev/null
 
322
  cd ${QADIR}
 
323
  . common/cleanup.sh
 
324
}
 
325
 
 
326
################## main #################################################
 
327
 
 
328
#this script may be sourced from the distributed stress test - in this case do nothing...
 
329
 
 
330
if [ -z  "$DO_REM_ST" -a -z  "$DO_DIST_ST" ] ; then
 
331
    ssl_init
 
332
    ssl_cov
 
333
    ssl_auth
 
334
    ssl_stress
 
335
 
 
336
    SERVERDIR=$EXT_SERVERDIR
 
337
    CLIENTDIR=$EXT_CLIENTDIR
 
338
    R_SERVERDIR=$R_EXT_SERVERDIR
 
339
    R_CLIENTDIR=$R_EXT_CLIENTDIR
 
340
    P_R_SERVERDIR=$P_R_EXT_SERVERDIR
 
341
    P_R_CLIENTDIR=$P_R_EXT_CLIENTDIR
 
342
    USER_NICKNAME=ExtendedSSLUser
 
343
    NORM_EXT="Extended test"
 
344
    cd ${CLIENTDIR}
 
345
    ssl_cov
 
346
    ssl_auth
 
347
    ssl_stress
 
348
    ssl_cleanup
 
349
fi