PageRenderTime 32ms CodeModel.GetById 14ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/security/nss/tests/smime/smime.sh

http://github.com/zpao/v8monkey
Shell | 292 lines | 181 code | 45 blank | 66 comment | 11 complexity | 56bb61031cd3b84678cb05c674cfaee0 MD5 | raw file
  1#! /bin/sh  
  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-2000
 21# the Initial Developer. 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 terms of
 27# either the GNU General Public License Version 2 or later (the "GPL"), or
 28# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 29# in which case the provisions of the GPL or the LGPL are applicable instead
 30# of those above. If you wish to allow use of your version of this file only
 31# under the terms of either the GPL or the LGPL, and not to allow others to
 32# use your version of this file under the terms of the MPL, indicate your
 33# decision by deleting the provisions above and replace them with the notice
 34# and other provisions required by the GPL or the LGPL. If you do not delete
 35# the provisions above, a recipient may use your version of this file under
 36# the terms of any one of the MPL, the GPL or the LGPL.
 37#
 38# ***** END LICENSE BLOCK *****
 39
 40########################################################################
 41#
 42# mozilla/security/nss/tests/smime/smime.sh
 43#
 44# Script to test NSS smime
 45#
 46# needs to work on all Unix and Windows platforms
 47#
 48# special strings
 49# ---------------
 50#   FIXME ... known problems, search for this string
 51#   NOTE .... unexpected behavior
 52#
 53########################################################################
 54
 55############################## smime_init ##############################
 56# local shell function to initialize this script
 57########################################################################
 58smime_init()
 59{
 60  SCRIPTNAME=smime.sh      # sourced - $0 would point to all.sh
 61
 62  if [ -z "${CLEANUP}" ] ; then     # if nobody else is responsible for
 63      CLEANUP="${SCRIPTNAME}"       # cleaning this script will do it
 64  fi
 65
 66  if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then
 67      cd ../common
 68      . ./init.sh
 69  fi
 70  if [ ! -r $CERT_LOG_FILE ]; then  # we need certificates here
 71      cd ../cert
 72      . ./cert.sh
 73  fi
 74  SCRIPTNAME=smime.sh
 75
 76  if [ -n "$NSS_ENABLE_ECC" ] ; then
 77      html_head "S/MIME Tests with ECC"
 78  else
 79      html_head "S/MIME Tests"
 80  fi
 81
 82  grep "SUCCESS: SMIME passed" $CERT_LOG_FILE >/dev/null || {
 83      Exit 11 "Fatal - S/MIME of cert.sh needs to pass first"
 84  }
 85
 86  SMIMEDIR=${HOSTDIR}/smime
 87  R_SMIMEDIR=../smime
 88  mkdir -p ${SMIMEDIR}
 89  cd ${SMIMEDIR}
 90  cp ${QADIR}/smime/alice.txt ${SMIMEDIR}
 91}
 92
 93smime_sign()
 94{
 95  HASH_CMD="-H ${HASH}"
 96  SIG=sig.${HASH}
 97
 98  echo "$SCRIPTNAME: Signing Detached Message {$HASH} ------------------"
 99  echo "cmsutil -S -T -N Alice ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice.d${SIG}"
100  ${PROFTOOL} ${BINDIR}/cmsutil -S -T -N Alice ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice.d${SIG}
101  html_msg $? 0 "Create Detached Signature Alice (${HASH})" "."
102
103  echo "cmsutil -D -i alice.d${SIG} -c alice.txt -d ${P_R_BOBDIR} "
104  ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice.d${SIG} -c alice.txt -d ${P_R_BOBDIR} 
105  html_msg $? 0 "Verifying Alice's Detached Signature (${HASH})" "."
106
107  echo "$SCRIPTNAME: Signing Attached Message (${HASH}) ------------------"
108  echo "cmsutil -S -N Alice ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice.${SIG}"
109  ${PROFTOOL} ${BINDIR}/cmsutil -S -N Alice ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice.${SIG}
110  html_msg $? 0 "Create Attached Signature Alice (${HASH})" "."
111
112  echo "cmsutil -D -i alice.${SIG} -d ${P_R_BOBDIR} -o alice.data.${HASH}"
113  ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice.${SIG} -d ${P_R_BOBDIR} -o alice.data.${HASH}
114  html_msg $? 0 "Decode Alice's Attached Signature (${HASH})" "."
115
116  echo "diff alice.txt alice.data.${HASH}"
117  diff alice.txt alice.data.${HASH}
118  html_msg $? 0 "Compare Attached Signed Data and Original (${HASH})" "."
119
120# Test ECDSA signing for all hash algorithms.
121  if [ -n "$NSS_ENABLE_ECC" ] ; then
122      echo "$SCRIPTNAME: Signing Detached Message ECDSA w/ {$HASH} ------------------"
123      echo "cmsutil -S -T -N Alice-ec ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice-ec.d${SIG}"
124      ${PROFTOOL} ${BINDIR}/cmsutil -S -T -N Alice-ec ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice-ec.d${SIG}
125      html_msg $? 0 "Create Detached Signature Alice (ECDSA w/ ${HASH})" "."
126
127      echo "cmsutil -D -i alice-ec.d${SIG} -c alice.txt -d ${P_R_BOBDIR} "
128      ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice-ec.d${SIG} -c alice.txt -d ${P_R_BOBDIR} 
129      html_msg $? 0 "Verifying Alice's Detached Signature (ECDSA w/ ${HASH})" "."
130
131      echo "$SCRIPTNAME: Signing Attached Message (ECDSA w/ ${HASH}) ------------------"
132      echo "cmsutil -S -N Alice-ec ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice-ec.${SIG}"
133      ${PROFTOOL} ${BINDIR}/cmsutil -S -N Alice-ec ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice-ec.${SIG}
134      html_msg $? 0 "Create Attached Signature Alice (ECDSA w/ ${HASH})" "."
135
136      echo "cmsutil -D -i alice-ec.${SIG} -d ${P_R_BOBDIR} -o alice-ec.data.${HASH}"
137      ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice-ec.${SIG} -d ${P_R_BOBDIR} -o alice-ec.data.${HASH}
138      html_msg $? 0 "Decode Alice's Attached Signature (ECDSA w/ ${HASH})" "."
139
140      echo "diff alice.txt alice-ec.data.${HASH}"
141      diff alice.txt alice-ec.data.${HASH}
142      html_msg $? 0 "Compare Attached Signed Data and Original (ECDSA w/ ${HASH})" "."
143  fi
144
145}
146
147
148
149smime_p7()
150{
151  echo "$SCRIPTNAME: p7 util Data Tests ------------------------------"
152  echo "p7env -d ${P_R_ALICEDIR} -r Alice -i alice.txt -o alice_p7.env"
153  ${PROFTOOL} ${BINDIR}/p7env -d ${P_R_ALICEDIR} -r Alice -i alice.txt -o alice.env
154  html_msg $? 0 "Creating envelope for user Alice" "."
155
156  echo "p7content -d ${P_R_ALICEDIR} -i alice.env -o alice_p7.data"
157  ${PROFTOOL} ${BINDIR}/p7content -d ${P_R_ALICEDIR} -i alice.env -o alice_p7.data -p nss
158  html_msg $? 0 "Verifying file delivered to user Alice" "."
159
160  sed -e '3,8p' -n alice_p7.data > alice_p7.data.sed
161
162  echo "diff alice.txt alice_p7.data.sed"
163  diff alice.txt alice_p7.data.sed
164  html_msg $? 0 "Compare Decoded Enveloped Data and Original" "."
165
166  echo "p7sign -d ${P_R_ALICEDIR} -k Alice -i alice.txt -o alice.sig -p nss -e"
167  ${PROFTOOL} ${BINDIR}/p7sign -d ${P_R_ALICEDIR} -k Alice -i alice.txt -o alice.sig -p nss -e
168  html_msg $? 0 "Signing file for user Alice" "."
169
170  echo "p7verify -d ${P_R_ALICEDIR} -c alice.txt -s alice.sig"
171  ${PROFTOOL} ${BINDIR}/p7verify -d ${P_R_ALICEDIR} -c alice.txt -s alice.sig
172  html_msg $? 0 "Verifying file delivered to user Alice" "."
173}
174
175############################## smime_main ##############################
176# local shell function to test basic signed and enveloped messages 
177# from 1 --> 2"
178########################################################################
179smime_main()
180{
181
182  HASH=SHA1
183  smime_sign
184  HASH=SHA256
185  smime_sign
186  HASH=SHA384
187  smime_sign
188  HASH=SHA512
189  smime_sign
190
191  echo "$SCRIPTNAME: Enveloped Data Tests ------------------------------"
192  echo "cmsutil -E -r bob@bogus.com -i alice.txt -d ${P_R_ALICEDIR} -p nss \\"
193  echo "        -o alice.env"
194  ${PROFTOOL} ${BINDIR}/cmsutil -E -r bob@bogus.com -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice.env
195  html_msg $? 0 "Create Enveloped Data Alice" "."
196
197  echo "cmsutil -D -i alice.env -d ${P_R_BOBDIR} -p nss -o alice.data1"
198  ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice.env -d ${P_R_BOBDIR} -p nss -o alice.data1
199  html_msg $? 0 "Decode Enveloped Data Alice" "."
200
201  echo "diff alice.txt alice.data1"
202  diff alice.txt alice.data1
203  html_msg $? 0 "Compare Decoded Enveloped Data and Original" "."
204
205  # multiple recip
206  echo "$SCRIPTNAME: Testing multiple recipients ------------------------------"
207  echo "cmsutil -E -i alice.txt -d ${P_R_ALICEDIR} -o alicecc.env \\"
208  echo "        -r bob@bogus.com,dave@bogus.com"
209  ${PROFTOOL} ${BINDIR}/cmsutil -E -i alice.txt -d ${P_R_ALICEDIR} -o alicecc.env \
210          -r bob@bogus.com,dave@bogus.com
211  ret=$?
212  html_msg $ret 0 "Create Multiple Recipients Enveloped Data Alice" "."
213  if [ $ret != 0 ] ; then
214	echo "certutil -L -d ${P_R_ALICEDIR}"
215	${BINDIR}/certutil -L -d ${P_R_ALICEDIR}
216	echo "certutil -L -d ${P_R_ALICEDIR} -n dave@bogus.com"
217	${BINDIR}/certutil -L -d ${P_R_ALICEDIR} -n dave@bogus.com
218  fi
219
220  echo "$SCRIPTNAME: Testing multiple email addrs ------------------------------"
221  echo "cmsutil -E -i alice.txt -d ${P_R_ALICEDIR} -o aliceve.env \\"
222  echo "        -r eve@bogus.net"
223  ${PROFTOOL} ${BINDIR}/cmsutil -E -i alice.txt -d ${P_R_ALICEDIR} -o aliceve.env \
224          -r eve@bogus.net
225  ret=$?
226  html_msg $ret 0 "Encrypt to a Multiple Email cert" "."
227
228  echo "cmsutil -D -i alicecc.env -d ${P_R_BOBDIR} -p nss -o alice.data2"
229  ${PROFTOOL} ${BINDIR}/cmsutil -D -i alicecc.env -d ${P_R_BOBDIR} -p nss -o alice.data2
230  html_msg $? 0 "Decode Multiple Recipients Enveloped Data Alice by Bob" "."
231
232  echo "cmsutil -D -i alicecc.env -d ${P_R_DAVEDIR} -p nss -o alice.data3"
233  ${PROFTOOL} ${BINDIR}/cmsutil -D -i alicecc.env -d ${P_R_DAVEDIR} -p nss -o alice.data3
234  html_msg $? 0 "Decode Multiple Recipients Enveloped Data Alice by Dave" "."
235
236  echo "cmsutil -D -i aliceve.env -d ${P_R_EVEDIR} -p nss -o alice.data4"
237  ${PROFTOOL} ${BINDIR}/cmsutil -D -i aliceve.env -d ${P_R_EVEDIR} -p nss -o alice.data4
238  html_msg $? 0 "Decrypt with a Multiple Email cert" "."
239
240  diff alice.txt alice.data2
241  html_msg $? 0 "Compare Decoded Mult. Recipients Enveloped Data Alice/Bob" "."
242
243  diff alice.txt alice.data3
244  html_msg $? 0 "Compare Decoded Mult. Recipients Enveloped Data Alice/Dave" "."
245
246  diff alice.txt alice.data4
247  html_msg $? 0 "Compare Decoded with Multiple Email cert" "."
248  
249  echo "$SCRIPTNAME: Sending CERTS-ONLY Message ------------------------------"
250  echo "cmsutil -O -r \"Alice,bob@bogus.com,dave@bogus.com\" \\"
251  echo "        -d ${P_R_ALICEDIR} > co.der"
252  ${PROFTOOL} ${BINDIR}/cmsutil -O -r "Alice,bob@bogus.com,dave@bogus.com" -d ${P_R_ALICEDIR} > co.der
253  html_msg $? 0 "Create Certs-Only Alice" "."
254
255  echo "cmsutil -D -i co.der -d ${P_R_BOBDIR}"
256  ${PROFTOOL} ${BINDIR}/cmsutil -D -i co.der -d ${P_R_BOBDIR}
257  html_msg $? 0 "Verify Certs-Only by CA" "."
258
259  echo "$SCRIPTNAME: Encrypted-Data Message ---------------------------------"
260  echo "cmsutil -C -i alice.txt -e alicehello.env -d ${P_R_ALICEDIR} \\"
261  echo "        -r \"bob@bogus.com\" > alice.enc"
262  ${PROFTOOL} ${BINDIR}/cmsutil -C -i alice.txt -e alicehello.env -d ${P_R_ALICEDIR} \
263          -r "bob@bogus.com" > alice.enc
264  html_msg $? 0 "Create Encrypted-Data" "."
265
266  echo "cmsutil -D -i alice.enc -d ${P_R_BOBDIR} -e alicehello.env -p nss \\"
267  echo "        -o alice.data2"
268  ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice.enc -d ${P_R_BOBDIR} -e alicehello.env -p nss -o alice.data2
269  html_msg $? 0 "Decode Encrypted-Data" "."
270
271  diff alice.txt alice.data2
272  html_msg $? 0 "Compare Decoded and Original Data" "."
273}
274  
275############################## smime_cleanup ###########################
276# local shell function to finish this script (no exit since it might be
277# sourced)
278########################################################################
279smime_cleanup()
280{
281  html "</TABLE><BR>"
282  cd ${QADIR}
283  . common/cleanup.sh
284}
285
286################## main #################################################
287
288smime_init
289smime_main
290smime_p7
291smime_cleanup
292