Path: blob/master/test/jdk/sun/security/validator/certreplace.sh
41149 views
#1# Copyright (c) 2010, 2013, 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 694880325# @summary CertPath validation regression caused by SHA1 replacement root26# and MD2 disable feature27# @modules java.base/sun.security.validator28#2930if [ "${TESTSRC}" = "" ] ; then31TESTSRC="."32fi33if [ "${TESTJAVA}" = "" ] ; then34JAVAC_CMD=`which javac`35TESTJAVA=`dirname $JAVAC_CMD`/..36COMPILEJAVA="${TESTJAVA}"37fi3839# set platform-dependent variables40OS=`uname -s`41case "$OS" in42Windows_* )43FS="\\"44;;45* )46FS="/"47;;48esac4950KT="$TESTJAVA${FS}bin${FS}keytool ${TESTTOOLVMOPTS} -storepass changeit \51-keypass changeit -keystore certreplace.jks -keyalg rsa"52JAVAC=$COMPILEJAVA${FS}bin${FS}javac53JAVA=$TESTJAVA${FS}bin${FS}java5455rm -rf certreplace.jks 2> /dev/null5657# 1. Generate 3 aliases in a keystore: ca, int, user5859$KT -genkeypair -alias ca -dname CN=CA -keyalg rsa -sigalg md2withrsa -ext bc60$KT -genkeypair -alias int -dname CN=Int -keyalg rsa61$KT -genkeypair -alias user -dname CN=User -keyalg rsa6263# 2. Signing: ca -> int -> user6465$KT -certreq -alias int | $KT -gencert -rfc -alias ca -ext bc \66| $KT -import -alias int67$KT -certreq -alias user | $KT -gencert -rfc -alias int \68| $KT -import -alias user6970# 3. Create the certchain file7172$KT -export -alias user -rfc > certreplace.certs73$KT -export -rfc -alias int >> certreplace.certs74$KT -export -rfc -alias ca >> certreplace.certs7576# 4. Upgrade ca from MD2withRSA to SHA256withRSA, remove other aliases and77# make this keystore the cacerts file7879$KT -selfcert -alias ca80$KT -delete -alias int81$KT -delete -alias user8283# 5. Build and run test8485EXTRAOPTS="--add-exports java.base/sun.security.validator=ALL-UNNAMED"86$JAVAC ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} ${EXTRAOPTS} -d . ${TESTSRC}${FS}CertReplace.java87$JAVA ${TESTVMOPTS} ${EXTRAOPTS} CertReplace certreplace.jks certreplace.certs888990