Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/AlgOptions.sh
38854 views
#1# Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.2# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3#4# This code is free software; you can redistribute it and/or modify it5# under the terms of the GNU General Public License version 2 only, as6# published by the Free Software Foundation.7#8# This code is distributed in the hope that it will be useful, but WITHOUT9# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11# version 2 for more details (a copy is included in the LICENSE file that12# accompanied this code).13#14# You should have received a copy of the GNU General Public License version15# 2 along with this work; if not, write to the Free Software Foundation,16# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17#18# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19# or visit www.oracle.com if you need additional information or have any20# questions.21#2223# @test24# @bug 5094028 621952225# @summary test new jarsigner -sigalg and -digestalg options26# @author Sean Mullan27#28# @run shell AlgOptions.sh29#3031# set a few environment variables so that the shell-script can run stand-alone32# in the source directory33if [ "${TESTSRC}" = "" ] ; then34TESTSRC="."35fi36if [ "${TESTCLASSES}" = "" ] ; then37TESTCLASSES="."38fi39if [ "${TESTJAVA}" = "" ] ; then40echo "TESTJAVA not set. Test cannot execute."41echo "FAILED!!!"42exit 143fi4445# set platform-dependent variables46OS=`uname -s`47case "$OS" in48SunOS | Linux | Darwin | AIX )49NULL=/dev/null50PS=":"51FS="/"52CP="${FS}bin${FS}cp -f"53;;54CYGWIN* )55NULL=/dev/null56PS=";"57FS="/"58CP="cp -f"59;;60Windows_* )61NULL=NUL62PS=";"63FS="\\"64CP="cp -f"65;;66* )67echo "Unrecognized operating system!"68exit 1;69;;70esac7172# copy jar file into writeable location73${CP} ${TESTSRC}${FS}AlgOptions.jar ${TESTCLASSES}${FS}AlgOptionsTmp.jar7475failed=076# test missing signature algorithm arg77${TESTJAVA}${FS}bin${FS}jarsigner \78-keystore ${TESTSRC}${FS}JarSigning.keystore \79-storepass bbbbbb \80-sigalg \81${TESTCLASSES}${FS}AlgOptionsTmp.jar c82RESULT=$?83if [ $RESULT -eq 0 ]; then84echo "test 1 failed"85failed=186else87echo "test 1 passed"88fi8990# test missing digest algorithm arg91${TESTJAVA}${FS}bin${FS}jarsigner \92-keystore ${TESTSRC}${FS}JarSigning.keystore \93-storepass bbbbbb \94-digestalg \95${TESTCLASSES}${FS}AlgOptionsTmp.jar c96RESULT=$?97if [ $RESULT -eq 0 ]; then98echo "test 2 failed"99failed=1100else101echo "test 2 passed"102fi103104# test BOGUS signature algorithm105${TESTJAVA}${FS}bin${FS}jarsigner \106-keystore ${TESTSRC}${FS}JarSigning.keystore \107-storepass bbbbbb \108-sigalg BOGUS \109${TESTCLASSES}${FS}AlgOptionsTmp.jar c110RESULT=$?111if [ $RESULT -eq 0 ]; then112echo "test 3 failed"113failed=1114else115echo "test 3 passed"116fi117118# test BOGUS digest algorithm119${TESTJAVA}${FS}bin${FS}jarsigner \120-keystore ${TESTSRC}${FS}JarSigning.keystore \121-storepass bbbbbb \122-digestalg BOGUS \123${TESTCLASSES}${FS}AlgOptionsTmp.jar c124RESULT=$?125if [ $RESULT -eq 0 ]; then126echo "test 4 failed"127failed=1128else129echo "test 4 passed"130fi131132# test incompatible signature algorithm133${TESTJAVA}${FS}bin${FS}jarsigner \134-keystore ${TESTSRC}${FS}JarSigning.keystore \135-storepass bbbbbb \136-sigalg SHA1withDSA \137${TESTCLASSES}${FS}AlgOptionsTmp.jar c138RESULT=$?139if [ $RESULT -eq 0 ]; then140echo "test 5 failed"141failed=1142else143echo "test 5 passed"144fi145146# test compatible signature algorithm147${TESTJAVA}${FS}bin${FS}jarsigner \148-keystore ${TESTSRC}${FS}JarSigning.keystore \149-storepass bbbbbb \150-sigalg SHA512withRSA \151${TESTCLASSES}${FS}AlgOptionsTmp.jar c152RESULT=$?153if [ $RESULT -eq 0 ]; then154echo "test 6 passed"155else156echo "test 6 failed"157failed=1158fi159160# verify it161${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar162RESULT=$?163if [ $RESULT -eq 0 ]; then164echo "test 7 passed"165else166echo "test 7 failed"167failed=1168fi169170# test non-default digest algorithm171${TESTJAVA}${FS}bin${FS}jarsigner \172-keystore ${TESTSRC}${FS}JarSigning.keystore \173-storepass bbbbbb \174-digestalg SHA-256 \175${TESTCLASSES}${FS}AlgOptionsTmp.jar c176RESULT=$?177if [ $RESULT -eq 0 ]; then178echo "test 8 passed"179else180echo "test 8 failed"181failed=1182fi183184# verify it185${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar186RESULT=$?187if [ $RESULT -eq 0 ]; then188echo "test 9 passed"189else190echo "test 9 failed"191failed=1192fi193194# test SHA-512 digest algorithm (creates long lines)195${TESTJAVA}${FS}bin${FS}jarsigner \196-keystore ${TESTSRC}${FS}JarSigning.keystore \197-storepass bbbbbb \198-digestalg SHA-512 \199-sigalg SHA512withRSA \200${TESTCLASSES}${FS}AlgOptionsTmp.jar c201RESULT=$?202if [ $RESULT -eq 0 ]; then203echo "test 10 passed"204else205echo "test 10 failed"206failed=1207fi208209# verify it210${TESTJAVA}${FS}bin${FS}jarsigner -verify ${TESTCLASSES}${FS}AlgOptionsTmp.jar211RESULT=$?212if [ $RESULT -eq 0 ]; then213echo "test 11 passed"214else215echo "test 11 failed"216failed=1217fi218219if [ $failed -eq 1 ]; then220exit 1221else222exit 0223fi224225226