blob: 5501116b9c954f1a0902c9b254de9101e028484b [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001#
2# Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# This code is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 2 only, as
7# published by the Free Software Foundation.
8#
9# This code is distributed in the hope that it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12# version 2 for more details (a copy is included in the LICENSE file that
13# accompanied this code).
14#
15# You should have received a copy of the GNU General Public License version
16# 2 along with this work; if not, write to the Free Software Foundation,
17# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18#
19# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20# CA 95054 USA or visit www.sun.com if you need additional information or
21# have any questions.
22#
23
24# @test
25# @bug 5094028 6219522
26# @summary test new jarsigner -sigalg and -digestalg options
27# @author Sean Mullan
28#
29# @run shell AlgOptions.sh
30#
31
32# set a few environment variables so that the shell-script can run stand-alone
33# in the source directory
34if [ "${TESTSRC}" = "" ] ; then
35 TESTSRC="."
36fi
37if [ "${TESTCLASSES}" = "" ] ; then
38 TESTCLASSES="."
39fi
40if [ "${TESTJAVA}" = "" ] ; then
41 echo "TESTJAVA not set. Test cannot execute."
42 echo "FAILED!!!"
43 exit 1
44fi
45
46# set platform-dependent variables
47OS=`uname -s`
48case "$OS" in
49 SunOS | Linux )
50 NULL=/dev/null
51 PS=":"
52 FS="/"
53 CP="${FS}bin${FS}cp -f"
54 TMP=/tmp
55 ;;
56 Windows_* )
57 NULL=NUL
58 PS=";"
59 FS="\\"
60 CP="cp -f"
61 TMP="c:/temp"
62 ;;
63 * )
64 echo "Unrecognized operating system!"
65 exit 1;
66 ;;
67esac
68
69# copy jar file into writeable location
70${CP} ${TESTSRC}${FS}AlgOptions.jar ${TESTCLASSES}${FS}AlgOptionsTmp.jar
71
72failed=0
73# test missing signature algorithm arg
74${TESTJAVA}${FS}bin${FS}jarsigner \
75 -keystore ${TESTSRC}${FS}JarSigning.keystore \
76 -storepass bbbbbb \
77 -sigalg \
78 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
79RESULT=$?
80if [ $RESULT -eq 0 ]; then
81 echo "test 1 failed"
82 failed=1
83else
84 echo "test 1 passed"
85fi
86
87# test missing digest algorithm arg
88${TESTJAVA}${FS}bin${FS}jarsigner \
89 -keystore ${TESTSRC}${FS}JarSigning.keystore \
90 -storepass bbbbbb \
91 -digestalg \
92 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
93RESULT=$?
94if [ $RESULT -eq 0 ]; then
95 echo "test 2 failed"
96 failed=1
97else
98 echo "test 2 passed"
99fi
100
101# test BOGUS signature algorithm
102${TESTJAVA}${FS}bin${FS}jarsigner \
103 -keystore ${TESTSRC}${FS}JarSigning.keystore \
104 -storepass bbbbbb \
105 -sigalg BOGUS \
106 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
107RESULT=$?
108if [ $RESULT -eq 0 ]; then
109 echo "test 3 failed"
110 failed=1
111else
112 echo "test 3 passed"
113fi
114
115# test BOGUS digest algorithm
116${TESTJAVA}${FS}bin${FS}jarsigner \
117 -keystore ${TESTSRC}${FS}JarSigning.keystore \
118 -storepass bbbbbb \
119 -digestalg BOGUS \
120 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
121RESULT=$?
122if [ $RESULT -eq 0 ]; then
123 echo "test 4 failed"
124 failed=1
125else
126 echo "test 4 passed"
127fi
128
129# test incompatible signature algorithm
130${TESTJAVA}${FS}bin${FS}jarsigner \
131 -keystore ${TESTSRC}${FS}JarSigning.keystore \
132 -storepass bbbbbb \
133 -sigalg SHA1withDSA \
134 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
135RESULT=$?
136if [ $RESULT -eq 0 ]; then
137 echo "test 5 failed"
138 failed=1
139else
140 echo "test 5 passed"
141fi
142
143# test compatible signature algorithm
144${TESTJAVA}${FS}bin${FS}jarsigner \
145 -keystore ${TESTSRC}${FS}JarSigning.keystore \
146 -storepass bbbbbb \
147 -sigalg SHA512withRSA \
148 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
149RESULT=$?
150if [ $RESULT -eq 0 ]; then
151 echo "test 6 passed"
152else
153 echo "test 6 failed"
154 failed=1
155fi
156
157# verify it
158${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar
159RESULT=$?
160if [ $RESULT -eq 0 ]; then
161 echo "test 7 passed"
162else
163 echo "test 7 failed"
164 failed=1
165fi
166
167# test non-default digest algorithm
168${TESTJAVA}${FS}bin${FS}jarsigner \
169 -keystore ${TESTSRC}${FS}JarSigning.keystore \
170 -storepass bbbbbb \
171 -digestalg SHA-256 \
172 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
173RESULT=$?
174if [ $RESULT -eq 0 ]; then
175 echo "test 8 passed"
176else
177 echo "test 8 failed"
178 failed=1
179fi
180
181# verify it
182${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar
183RESULT=$?
184if [ $RESULT -eq 0 ]; then
185 echo "test 9 passed"
186else
187 echo "test 9 failed"
188 failed=1
189fi
190
191# test SHA-512 digest algorithm (creates long lines)
192${TESTJAVA}${FS}bin${FS}jarsigner \
193 -keystore ${TESTSRC}${FS}JarSigning.keystore \
194 -storepass bbbbbb \
195 -digestalg SHA-512 \
196 -sigalg SHA512withRSA \
197 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
198RESULT=$?
199if [ $RESULT -eq 0 ]; then
200 echo "test 10 passed"
201else
202 echo "test 10 failed"
203 failed=1
204fi
205
206# verify it
207${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar
208RESULT=$?
209if [ $RESULT -eq 0 ]; then
210 echo "test 11 passed"
211else
212 echo "test 11 failed"
213 failed=1
214fi
215
216if [ $failed -eq 1 ]; then
217 exit 1
218else
219 exit 0
220fi