Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/checkusage.sh
38853 views
#1# Copyright (c) 2010, 2017, 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 700416825# @summary jarsigner -verify checks for KeyUsage codesigning ext on all certs26# instead of just signing cert27#28# @run shell checkusage.sh29#3031if [ "${TESTJAVA}" = "" ] ; then32JAVAC_CMD=`which javac`33TESTJAVA=`dirname $JAVAC_CMD`/..34fi3536# set platform-dependent variables37OS=`uname -s`38case "$OS" in39Windows_* )40FS="\\"41;;42* )43FS="/"44;;45esac4647KT="$TESTJAVA${FS}bin${FS}keytool -storepass changeit -keypass changeit -keyalg rsa"48JAR=$TESTJAVA${FS}bin${FS}jar49JARSIGNER="$TESTJAVA${FS}bin${FS}jarsigner"5051rm js.jks trust.jks unrelated.jks 2> /dev/null5253echo x > x54$JAR cvf a.jar x5556################### 3 Keystores #######################5758# Keystore js.jks: including CA and Publisher59# CA contains a non-empty KeyUsage60$KT -keystore js.jks -genkeypair -alias ca -dname CN=CA -ext KU=kCS -ext bc -validity 36561$KT -keystore js.jks -genkeypair -alias pub -dname CN=Publisher6263# Publisher contains the correct KeyUsage64$KT -keystore js.jks -certreq -alias pub | \65$KT -keystore js.jks -gencert -alias ca -ext KU=dig -validity 365 | \66$KT -keystore js.jks -importcert -alias pub6768# Keystore trust.jks: including CA only69$KT -keystore js.jks -exportcert -alias ca | \70$KT -keystore trust.jks -importcert -alias ca -noprompt7172# Keystore unrelated.jks: unrelated73$KT -keystore unrelated.jks -genkeypair -alias nothing -dname CN=Nothing -validity 365747576################### 4 Tests #######################7778# Test 1: Sign should be OK7980$JARSIGNER -keystore js.jks -storepass changeit a.jar pub81RESULT=$?82echo $RESULT83#[ $RESULT = 0 ] || exit 18485# Test 2: Verify should be OK8687$JARSIGNER -keystore trust.jks -strict -verify a.jar88RESULT=$?89echo $RESULT90#[ $RESULT = 0 ] || exit 29192# Test 3: When no keystore is specified, the error is only93# "chain invalid"9495$JARSIGNER -strict -verify a.jar96RESULT=$?97echo $RESULT98#[ $RESULT = 4 ] || exit 399100# Test 4: When unrelated keystore is specified, the error is101# "chain invalid" and "not alias in keystore"102103$JARSIGNER -keystore unrelated.jks -strict -verify a.jar104RESULT=$?105echo $RESULT106#[ $RESULT = 36 ] || exit 4107108exit 0109110111