1 # 2 # Copyright (c) 2010, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 # or visit www.oracle.com if you need additional information or have any 21 # questions. 22 # 23 24 # @test 25 # @bug 6948803 26 # @summary CertPath validation regression caused by SHA1 replacement root 27 # and MD2 disable feature 28 # @modules java.base/sun.security.validator 29 # 30 31 if [ "${TESTSRC}" = "" ] ; then 32 TESTSRC="." 33 fi 34 if [ "${TESTJAVA}" = "" ] ; then 35 JAVAC_CMD=`which javac` 36 TESTJAVA=`dirname $JAVAC_CMD`/.. 37 COMPILEJAVA="${TESTJAVA}" 38 fi 39 40 # set platform-dependent variables 41 OS=`uname -s` 42 case "$OS" in 43 Windows_* ) 44 FS="\\" 45 ;; 46 * ) 47 FS="/" 48 ;; 49 esac 50 51 KT="$TESTJAVA${FS}bin${FS}keytool ${TESTTOOLVMOPTS} -storepass changeit \ 52 -keypass changeit -keystore certreplace.jks -keyalg rsa" 53 JAVAC=$COMPILEJAVA${FS}bin${FS}javac 54 JAVA=$TESTJAVA${FS}bin${FS}java 55 56 rm -rf certreplace.jks 2> /dev/null 57 58 # 1. Generate 3 aliases in a keystore: ca, int, user 59 60 $KT -genkeypair -alias ca -dname CN=CA -keyalg rsa -sigalg md2withrsa -ext bc 61 $KT -genkeypair -alias int -dname CN=Int -keyalg rsa 62 $KT -genkeypair -alias user -dname CN=User -keyalg rsa 63 64 # 2. Signing: ca -> int -> user 65 66 $KT -certreq -alias int | $KT -gencert -rfc -alias ca -ext bc \ 67 | $KT -import -alias int 68 $KT -certreq -alias user | $KT -gencert -rfc -alias int \ 69 | $KT -import -alias user 70 71 # 3. Create the certchain file 72 73 $KT -export -alias user -rfc > certreplace.certs 74 $KT -export -rfc -alias int >> certreplace.certs 75 $KT -export -rfc -alias ca >> certreplace.certs 76 77 # 4. Upgrade ca from MD2withRSA to SHA256withRSA, remove other aliases and 78 # make this keystore the cacerts file 79 80 $KT -selfcert -alias ca 81 $KT -delete -alias int 82 $KT -delete -alias user 83 84 # 5. Build and run test 85 86 EXTRAOPTS="-XaddExports:java.base/sun.security.validator=ALL-UNNAMED" 87 $JAVAC ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} ${EXTRAOPTS} -d . ${TESTSRC}${FS}CertReplace.java 88 $JAVA ${TESTVMOPTS} ${EXTRAOPTS} CertReplace certreplace.jks certreplace.certs