3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
16 # The Original Code is the Netscape security libraries.
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.
24 # Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
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.
38 # ***** END LICENSE BLOCK *****
40 ########################################################################
42 # mozilla/security/nss/tests/smime/smime.sh
44 # Script to test NSS smime
46 # needs to work on all Unix and Windows platforms
50 # FIXME ... known problems, search for this string
51 # NOTE .... unexpected behavior
53 ########################################################################
55 ############################## smime_init ##############################
56 # local shell function to initialize this script
57 ########################################################################
60 SCRIPTNAME
=smime.sh
# sourced - $0 would point to all.sh
62 if [ -z "${CLEANUP}" ] ; then # if nobody else is responsible for
63 CLEANUP
="${SCRIPTNAME}" # cleaning this script will do it
66 if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then
70 if [ ! -r $CERT_LOG_FILE ]; then # we need certificates here
76 if [ -n "$NSS_ENABLE_ECC" ] ; then
77 html_head
"S/MIME Tests with ECC"
79 html_head
"S/MIME Tests"
82 grep "SUCCESS: SMIME passed" $CERT_LOG_FILE >/dev
/null ||
{
83 Exit
11 "Fatal - S/MIME of cert.sh needs to pass first"
86 SMIMEDIR
=${HOSTDIR}/smime
90 cp ${QADIR}/smime
/alice.txt
${SMIMEDIR}
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 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})" "."
103 echo "cmsutil -D -i alice.d${SIG} -c alice.txt -d ${P_R_BOBDIR} "
104 cmsutil
-D -i alice.d
${SIG} -c alice.txt
-d ${P_R_BOBDIR}
105 html_msg $?
0 "Verifying Alice's Detached Signature (${HASH})" "."
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 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})" "."
112 echo "cmsutil -D -i alice.${SIG} -d ${P_R_BOBDIR} -o alice.data.${HASH}"
113 cmsutil
-D -i alice.
${SIG} -d ${P_R_BOBDIR} -o alice.data.${HASH}
114 html_msg $?
0 "Decode Alice's Attached Signature (${HASH})" "."
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})" "."
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 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})" "."
127 echo "cmsutil -D -i alice-ec.d${SIG} -c alice.txt -d ${P_R_BOBDIR} "
128 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})" "."
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 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})" "."
136 echo "cmsutil -D -i alice-ec.${SIG} -d ${P_R_BOBDIR} -o alice-ec.data.${HASH}"
137 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})" "."
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})" "."
151 echo "$SCRIPTNAME: p7 util Data Tests ------------------------------"
152 echo "p7env -d ${P_R_ALICEDIR} -r Alice -i alice.txt -o alice_p7.env"
153 p7env
-d ${P_R_ALICEDIR} -r Alice
-i alice.txt
-o alice.env
154 html_msg $?
0 "Creating envelope for user Alice" "."
156 echo "p7content -d ${P_R_ALICEDIR} -i alice.env -o alice_p7.data"
157 p7content
-d ${P_R_ALICEDIR} -i alice.env
-o alice_p7.data
-p nss
158 html_msg $?
0 "Verifying file delivered to user Alice" "."
160 sed -e '3,8p' -n alice_p7.data
> alice_p7.data.
sed
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" "."
166 echo "p7sign -d ${P_R_ALICEDIR} -k Alice -i alice.txt -o alice.sig -p nss -e"
167 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" "."
170 echo "p7verify -d ${P_R_ALICEDIR} -c alice.txt -s alice.sig"
171 p7verify
-d ${P_R_ALICEDIR} -c alice.txt
-s alice.sig
172 html_msg $?
0 "Verifying file delivered to user Alice" "."
175 ############################## smime_main ##############################
176 # local shell function to test basic signed and enveloped messages
178 ########################################################################
191 echo "$SCRIPTNAME: Enveloped Data Tests ------------------------------"
192 echo "cmsutil -E -r bob@bogus.com -i alice.txt -d ${P_R_ALICEDIR} -p nss \\"
194 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" "."
197 echo "cmsutil -D -i alice.env -d ${P_R_BOBDIR} -p nss -o alice.data1"
198 cmsutil
-D -i alice.env
-d ${P_R_BOBDIR} -p nss
-o alice.data1
199 html_msg $?
0 "Decode Enveloped Data Alice" "."
201 echo "diff alice.txt alice.data1"
202 diff alice.txt alice.data1
203 html_msg $?
0 "Compare Decoded Enveloped Data and Original" "."
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 cmsutil
-E -i alice.txt
-d ${P_R_ALICEDIR} -o alicecc.env \
210 -r bob@bogus.com
,dave@bogus.com
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 certutil
-L -d ${P_R_ALICEDIR}
216 echo "certutil -L -d ${P_R_ALICEDIR} -n dave@bogus.com"
217 certutil
-L -d ${P_R_ALICEDIR} -n dave@bogus.com
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 cmsutil
-E -i alice.txt
-d ${P_R_ALICEDIR} -o aliceve.env \
226 html_msg
$ret 0 "Encrypt to a Multiple Email cert" "."
228 echo "cmsutil -D -i alicecc.env -d ${P_R_BOBDIR} -p nss -o alice.data2"
229 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" "."
232 echo "cmsutil -D -i alicecc.env -d ${P_R_DAVEDIR} -p nss -o alice.data3"
233 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" "."
236 echo "cmsutil -D -i aliceve.env -d ${P_R_EVEDIR} -p nss -o alice.data4"
237 cmsutil
-D -i aliceve.env
-d ${P_R_EVEDIR} -p nss
-o alice.data4
238 html_msg $?
0 "Decrypt with a Multiple Email cert" "."
240 diff alice.txt alice.data2
241 html_msg $?
0 "Compare Decoded Mult. Recipients Enveloped Data Alice/Bob" "."
243 diff alice.txt alice.data3
244 html_msg $?
0 "Compare Decoded Mult. Recipients Enveloped Data Alice/Dave" "."
246 diff alice.txt alice.data4
247 html_msg $?
0 "Compare Decoded with Multiple Email cert" "."
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 cmsutil
-O -r "Alice,bob@bogus.com,dave@bogus.com" -d ${P_R_ALICEDIR} > co.der
253 html_msg $?
0 "Create Certs-Only Alice" "."
255 echo "cmsutil -D -i co.der -d ${P_R_BOBDIR}"
256 cmsutil
-D -i co.der
-d ${P_R_BOBDIR}
257 html_msg $?
0 "Verify Certs-Only by CA" "."
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 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" "."
266 echo "cmsutil -D -i alice.enc -d ${P_R_BOBDIR} -e alicehello.env -p nss \\"
267 echo " -o alice.data2"
268 cmsutil
-D -i alice.enc
-d ${P_R_BOBDIR} -e alicehello.env
-p nss
-o alice.data2
269 html_msg $?
0 "Decode Encrypted-Data" "."
271 diff alice.txt alice.data2
272 html_msg $?
0 "Compare Decoded and Original Data" "."
275 ############################## smime_cleanup ###########################
276 # local shell function to finish this script (no exit since it might be
278 ########################################################################
286 ################## main #################################################