J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | # |
| 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 |
| 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 ) |
| 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 | ;; |
| 67 | esac |
| 68 | |
| 69 | # copy jar file into writeable location |
| 70 | ${CP} ${TESTSRC}${FS}AlgOptions.jar ${TESTCLASSES}${FS}AlgOptionsTmp.jar |
| 71 | |
| 72 | failed=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 |
| 79 | RESULT=$? |
| 80 | if [ $RESULT -eq 0 ]; then |
| 81 | echo "test 1 failed" |
| 82 | failed=1 |
| 83 | else |
| 84 | echo "test 1 passed" |
| 85 | fi |
| 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 |
| 93 | RESULT=$? |
| 94 | if [ $RESULT -eq 0 ]; then |
| 95 | echo "test 2 failed" |
| 96 | failed=1 |
| 97 | else |
| 98 | echo "test 2 passed" |
| 99 | fi |
| 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 |
| 107 | RESULT=$? |
| 108 | if [ $RESULT -eq 0 ]; then |
| 109 | echo "test 3 failed" |
| 110 | failed=1 |
| 111 | else |
| 112 | echo "test 3 passed" |
| 113 | fi |
| 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 |
| 121 | RESULT=$? |
| 122 | if [ $RESULT -eq 0 ]; then |
| 123 | echo "test 4 failed" |
| 124 | failed=1 |
| 125 | else |
| 126 | echo "test 4 passed" |
| 127 | fi |
| 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 |
| 135 | RESULT=$? |
| 136 | if [ $RESULT -eq 0 ]; then |
| 137 | echo "test 5 failed" |
| 138 | failed=1 |
| 139 | else |
| 140 | echo "test 5 passed" |
| 141 | fi |
| 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 |
| 149 | RESULT=$? |
| 150 | if [ $RESULT -eq 0 ]; then |
| 151 | echo "test 6 passed" |
| 152 | else |
| 153 | echo "test 6 failed" |
| 154 | failed=1 |
| 155 | fi |
| 156 | |
| 157 | # verify it |
| 158 | ${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar |
| 159 | RESULT=$? |
| 160 | if [ $RESULT -eq 0 ]; then |
| 161 | echo "test 7 passed" |
| 162 | else |
| 163 | echo "test 7 failed" |
| 164 | failed=1 |
| 165 | fi |
| 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 |
| 173 | RESULT=$? |
| 174 | if [ $RESULT -eq 0 ]; then |
| 175 | echo "test 8 passed" |
| 176 | else |
| 177 | echo "test 8 failed" |
| 178 | failed=1 |
| 179 | fi |
| 180 | |
| 181 | # verify it |
| 182 | ${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar |
| 183 | RESULT=$? |
| 184 | if [ $RESULT -eq 0 ]; then |
| 185 | echo "test 9 passed" |
| 186 | else |
| 187 | echo "test 9 failed" |
| 188 | failed=1 |
| 189 | fi |
| 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 |
| 198 | RESULT=$? |
| 199 | if [ $RESULT -eq 0 ]; then |
| 200 | echo "test 10 passed" |
| 201 | else |
| 202 | echo "test 10 failed" |
| 203 | failed=1 |
| 204 | fi |
| 205 | |
| 206 | # verify it |
| 207 | ${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar |
| 208 | RESULT=$? |
| 209 | if [ $RESULT -eq 0 ]; then |
| 210 | echo "test 11 passed" |
| 211 | else |
| 212 | echo "test 11 failed" |
| 213 | failed=1 |
| 214 | fi |
| 215 | |
| 216 | if [ $failed -eq 1 ]; then |
| 217 | exit 1 |
| 218 | else |
| 219 | exit 0 |
| 220 | fi |