AlgOptions.sh revision 5116:d45bc4307996
1219820Sjeff# 2219820Sjeff# Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. 3219820Sjeff# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4219820Sjeff# 5219820Sjeff# This code is free software; you can redistribute it and/or modify it 6219820Sjeff# under the terms of the GNU General Public License version 2 only, as 7219820Sjeff# published by the Free Software Foundation. 8219820Sjeff# 9219820Sjeff# This code is distributed in the hope that it will be useful, but WITHOUT 10219820Sjeff# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11219820Sjeff# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12219820Sjeff# version 2 for more details (a copy is included in the LICENSE file that 13219820Sjeff# accompanied this code). 14219820Sjeff# 15219820Sjeff# You should have received a copy of the GNU General Public License version 16219820Sjeff# 2 along with this work; if not, write to the Free Software Foundation, 17219820Sjeff# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18219820Sjeff# 19219820Sjeff# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20219820Sjeff# or visit www.oracle.com if you need additional information or have any 21219820Sjeff# questions. 22219820Sjeff# 23219820Sjeff 24219820Sjeff# @test 25219820Sjeff# @bug 5094028 6219522 26219820Sjeff# @summary test new jarsigner -sigalg and -digestalg options 27219820Sjeff# @author Sean Mullan 28219820Sjeff# 29219820Sjeff# @run shell AlgOptions.sh 30219820Sjeff# 31219820Sjeff 32219820Sjeff# set a few environment variables so that the shell-script can run stand-alone 33219820Sjeff# in the source directory 34219820Sjeffif [ "${TESTSRC}" = "" ] ; then 35219820Sjeff TESTSRC="." 36219820Sjefffi 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 | Darwin ) 50 NULL=/dev/null 51 PS=":" 52 FS="/" 53 CP="${FS}bin${FS}cp -f" 54 ;; 55 CYGWIN* ) 56 NULL=/dev/null 57 PS=";" 58 FS="/" 59 CP="cp -f" 60 ;; 61 Windows_* ) 62 NULL=NUL 63 PS=";" 64 FS="\\" 65 CP="cp -f" 66 ;; 67 * ) 68 echo "Unrecognized operating system!" 69 exit 1; 70 ;; 71esac 72 73# copy jar file into writeable location 74${CP} ${TESTSRC}${FS}AlgOptions.jar ${TESTCLASSES}${FS}AlgOptionsTmp.jar 75 76failed=0 77# test missing signature algorithm arg 78${TESTJAVA}${FS}bin${FS}jarsigner \ 79 -keystore ${TESTSRC}${FS}JarSigning.keystore \ 80 -storepass bbbbbb \ 81 -sigalg \ 82 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c 83RESULT=$? 84if [ $RESULT -eq 0 ]; then 85 echo "test 1 failed" 86 failed=1 87else 88 echo "test 1 passed" 89fi 90 91# test missing digest algorithm arg 92${TESTJAVA}${FS}bin${FS}jarsigner \ 93 -keystore ${TESTSRC}${FS}JarSigning.keystore \ 94 -storepass bbbbbb \ 95 -digestalg \ 96 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c 97RESULT=$? 98if [ $RESULT -eq 0 ]; then 99 echo "test 2 failed" 100 failed=1 101else 102 echo "test 2 passed" 103fi 104 105# test BOGUS signature algorithm 106${TESTJAVA}${FS}bin${FS}jarsigner \ 107 -keystore ${TESTSRC}${FS}JarSigning.keystore \ 108 -storepass bbbbbb \ 109 -sigalg BOGUS \ 110 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c 111RESULT=$? 112if [ $RESULT -eq 0 ]; then 113 echo "test 3 failed" 114 failed=1 115else 116 echo "test 3 passed" 117fi 118 119# test BOGUS digest algorithm 120${TESTJAVA}${FS}bin${FS}jarsigner \ 121 -keystore ${TESTSRC}${FS}JarSigning.keystore \ 122 -storepass bbbbbb \ 123 -digestalg BOGUS \ 124 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c 125RESULT=$? 126if [ $RESULT -eq 0 ]; then 127 echo "test 4 failed" 128 failed=1 129else 130 echo "test 4 passed" 131fi 132 133# test incompatible signature algorithm 134${TESTJAVA}${FS}bin${FS}jarsigner \ 135 -keystore ${TESTSRC}${FS}JarSigning.keystore \ 136 -storepass bbbbbb \ 137 -sigalg SHA1withDSA \ 138 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c 139RESULT=$? 140if [ $RESULT -eq 0 ]; then 141 echo "test 5 failed" 142 failed=1 143else 144 echo "test 5 passed" 145fi 146 147# test compatible signature algorithm 148${TESTJAVA}${FS}bin${FS}jarsigner \ 149 -keystore ${TESTSRC}${FS}JarSigning.keystore \ 150 -storepass bbbbbb \ 151 -sigalg SHA512withRSA \ 152 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c 153RESULT=$? 154if [ $RESULT -eq 0 ]; then 155 echo "test 6 passed" 156else 157 echo "test 6 failed" 158 failed=1 159fi 160 161# verify it 162${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar 163RESULT=$? 164if [ $RESULT -eq 0 ]; then 165 echo "test 7 passed" 166else 167 echo "test 7 failed" 168 failed=1 169fi 170 171# test non-default digest algorithm 172${TESTJAVA}${FS}bin${FS}jarsigner \ 173 -keystore ${TESTSRC}${FS}JarSigning.keystore \ 174 -storepass bbbbbb \ 175 -digestalg SHA-256 \ 176 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c 177RESULT=$? 178if [ $RESULT -eq 0 ]; then 179 echo "test 8 passed" 180else 181 echo "test 8 failed" 182 failed=1 183fi 184 185# verify it 186${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar 187RESULT=$? 188if [ $RESULT -eq 0 ]; then 189 echo "test 9 passed" 190else 191 echo "test 9 failed" 192 failed=1 193fi 194 195# test SHA-512 digest algorithm (creates long lines) 196${TESTJAVA}${FS}bin${FS}jarsigner \ 197 -keystore ${TESTSRC}${FS}JarSigning.keystore \ 198 -storepass bbbbbb \ 199 -digestalg SHA-512 \ 200 -sigalg SHA512withRSA \ 201 ${TESTCLASSES}${FS}AlgOptionsTmp.jar c 202RESULT=$? 203if [ $RESULT -eq 0 ]; then 204 echo "test 10 passed" 205else 206 echo "test 10 failed" 207 failed=1 208fi 209 210# verify it 211${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar 212RESULT=$? 213if [ $RESULT -eq 0 ]; then 214 echo "test 11 passed" 215else 216 echo "test 11 failed" 217 failed=1 218fi 219 220if [ $failed -eq 1 ]; then 221 exit 1 222else 223 exit 0 224fi 225