AlgOptions.sh 5.2 KB
Newer Older
D
duke 已提交
1
#
2
# Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
19 20 21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
D
duke 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#

# @test
# @bug 5094028 6219522
# @summary test new jarsigner -sigalg and -digestalg options
# @author Sean Mullan
#
# @run shell AlgOptions.sh
#

# set a few environment variables so that the shell-script can run stand-alone
# in the source directory
if [ "${TESTSRC}" = "" ] ; then
  TESTSRC="."
fi
if [ "${TESTCLASSES}" = "" ] ; then
  TESTCLASSES="."
fi
if [ "${TESTJAVA}" = "" ] ; then
  echo "TESTJAVA not set.  Test cannot execute."
  echo "FAILED!!!"
  exit 1
fi

# set platform-dependent variables
OS=`uname -s`
case "$OS" in
  SunOS | Linux )
    NULL=/dev/null
    PS=":"
    FS="/"
    CP="${FS}bin${FS}cp -f"
    ;;
55 56 57 58 59 60
  CYGWIN* )
    NULL=/dev/null
    PS=";"
    FS="/"
    CP="cp -f"
    ;;
D
duke 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
  Windows_* )
    NULL=NUL
    PS=";"
    FS="\\"
    CP="cp -f"
    ;;
  * )
    echo "Unrecognized operating system!"
    exit 1;
    ;;
esac

# copy jar file into writeable location
${CP} ${TESTSRC}${FS}AlgOptions.jar ${TESTCLASSES}${FS}AlgOptionsTmp.jar

failed=0
# test missing signature algorithm arg
${TESTJAVA}${FS}bin${FS}jarsigner \
    -keystore ${TESTSRC}${FS}JarSigning.keystore \
    -storepass bbbbbb \
    -sigalg \
    ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
RESULT=$?
if [ $RESULT -eq 0 ]; then
    echo "test 1 failed"
    failed=1
else 
    echo "test 1 passed"
fi

# test missing digest algorithm arg
${TESTJAVA}${FS}bin${FS}jarsigner \
    -keystore ${TESTSRC}${FS}JarSigning.keystore \
    -storepass bbbbbb \
    -digestalg \
    ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
RESULT=$?
if [ $RESULT -eq 0 ]; then
    echo "test 2 failed"
    failed=1
else 
    echo "test 2 passed"
fi

# test BOGUS signature algorithm 
${TESTJAVA}${FS}bin${FS}jarsigner \
    -keystore ${TESTSRC}${FS}JarSigning.keystore \
    -storepass bbbbbb \
    -sigalg BOGUS \
    ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
RESULT=$?
if [ $RESULT -eq 0 ]; then
    echo "test 3 failed"
    failed=1
else 
    echo "test 3 passed"
fi

# test BOGUS digest algorithm 
${TESTJAVA}${FS}bin${FS}jarsigner \
    -keystore ${TESTSRC}${FS}JarSigning.keystore \
    -storepass bbbbbb \
    -digestalg BOGUS \
    ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
RESULT=$?
if [ $RESULT -eq 0 ]; then
    echo "test 4 failed"
    failed=1
else 
    echo "test 4 passed"
fi

# test incompatible signature algorithm 
${TESTJAVA}${FS}bin${FS}jarsigner \
    -keystore ${TESTSRC}${FS}JarSigning.keystore \
    -storepass bbbbbb \
    -sigalg SHA1withDSA \
    ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
RESULT=$?
if [ $RESULT -eq 0 ]; then
    echo "test 5 failed"
    failed=1
else 
    echo "test 5 passed"
fi

# test compatible signature algorithm 
${TESTJAVA}${FS}bin${FS}jarsigner \
    -keystore ${TESTSRC}${FS}JarSigning.keystore \
    -storepass bbbbbb \
    -sigalg SHA512withRSA \
    ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
RESULT=$?
if [ $RESULT -eq 0 ]; then
    echo "test 6 passed"
else 
    echo "test 6 failed"
    failed=1
fi

# verify it 
${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar
RESULT=$?
if [ $RESULT -eq 0 ]; then
    echo "test 7 passed"
else 
    echo "test 7 failed"
    failed=1
fi

# test non-default digest algorithm 
${TESTJAVA}${FS}bin${FS}jarsigner \
    -keystore ${TESTSRC}${FS}JarSigning.keystore \
    -storepass bbbbbb \
    -digestalg SHA-256 \
    ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
RESULT=$?
if [ $RESULT -eq 0 ]; then
    echo "test 8 passed"
else 
    echo "test 8 failed"
    failed=1
fi

# verify it 
${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar
RESULT=$?
if [ $RESULT -eq 0 ]; then
    echo "test 9 passed"
else 
    echo "test 9 failed"
    failed=1
fi

# test SHA-512 digest algorithm (creates long lines)
${TESTJAVA}${FS}bin${FS}jarsigner \
    -keystore ${TESTSRC}${FS}JarSigning.keystore \
    -storepass bbbbbb \
    -digestalg SHA-512 \
    -sigalg SHA512withRSA \
    ${TESTCLASSES}${FS}AlgOptionsTmp.jar c
RESULT=$?
if [ $RESULT -eq 0 ]; then
    echo "test 10 passed"
else 
    echo "test 10 failed"
    failed=1
fi

# verify it 
${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar
RESULT=$?
if [ $RESULT -eq 0 ]; then
    echo "test 11 passed"
else 
    echo "test 11 failed"
    failed=1
fi

if [ $failed -eq 1 ]; then
    exit 1
else
    exit 0
fi