1 # 2 # Copyright (c) 2005, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 # or visit www.oracle.com if you need additional information or have any 21 # 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 34 if [ "${TESTSRC}" = "" ] ; then 35 TESTSRC="." 36 fi 37 if [ "${TESTCLASSES}" = "" ] ; then 38 TESTCLASSES="." 39 fi 40 if [ "${TESTJAVA}" = "" ] ; then 41 echo "TESTJAVA not set. Test cannot execute." 42 echo "FAILED!!!" 43 exit 1 44 fi 45 46 # set platform-dependent variables 47 OS=`uname -s` 48 case "$OS" in 49 SunOS | Linux | Darwin | AIX ) 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 ;; 71 esac 72 73 # copy jar file into writeable location 74 ${CP} ${TESTSRC}${FS}AlgOptions.jar ${TESTCLASSES}${FS}AlgOptionsTmp.jar 75 76 failed=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 83 RESULT=$? 84 if [ $RESULT -eq 0 ]; then 85 echo "test 1 failed" 86 failed=1 87 else 88 echo "test 1 passed" 89 fi 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 97 RESULT=$? 98 if [ $RESULT -eq 0 ]; then 99 echo "test 2 failed" 100 failed=1 101 else 102 echo "test 2 passed" 103 fi 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 111 RESULT=$? 112 if [ $RESULT -eq 0 ]; then 113 echo "test 3 failed" 114 failed=1 115 else 116 echo "test 3 passed" 117 fi 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 125 RESULT=$? 126 if [ $RESULT -eq 0 ]; then 127 echo "test 4 failed" 128 failed=1 129 else 130 echo "test 4 passed" 131 fi 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 139 RESULT=$? 140 if [ $RESULT -eq 0 ]; then 141 echo "test 5 failed" 142 failed=1 143 else 144 echo "test 5 passed" 145 fi 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 153 RESULT=$? 154 if [ $RESULT -eq 0 ]; then 155 echo "test 6 passed" 156 else 157 echo "test 6 failed" 158 failed=1 159 fi 160 161 # verify it 162 ${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar 163 RESULT=$? 164 if [ $RESULT -eq 0 ]; then 165 echo "test 7 passed" 166 else 167 echo "test 7 failed" 168 failed=1 169 fi 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 177 RESULT=$? 178 if [ $RESULT -eq 0 ]; then 179 echo "test 8 passed" 180 else 181 echo "test 8 failed" 182 failed=1 183 fi 184 185 # verify it 186 ${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar 187 RESULT=$? 188 if [ $RESULT -eq 0 ]; then 189 echo "test 9 passed" 190 else 191 echo "test 9 failed" 192 failed=1 193 fi 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 202 RESULT=$? 203 if [ $RESULT -eq 0 ]; then 204 echo "test 10 passed" 205 else 206 echo "test 10 failed" 207 failed=1 208 fi 209 210 # verify it 211 ${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar 212 RESULT=$? 213 if [ $RESULT -eq 0 ]; then 214 echo "test 11 passed" 215 else 216 echo "test 11 failed" 217 failed=1 218 fi 219 220 if [ $failed -eq 1 ]; then 221 exit 1 222 else 223 exit 0 224 fi