1 #
   2 # Copyright (c) 2007, 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 6543842 6543440 6939248 8009636 8024302
  26 # @summary checking response of timestamp
  27 # @modules java.base/sun.security.pkcs
  28 #          java.base/sun.security.timestamp
  29 #          java.base/sun.security.x509
  30 #          java.base/sun.security.util
  31 #
  32 # @run shell/timeout=600 ts.sh
  33 
  34 # Run for a long time because jarsigner with timestamp needs to create a
  35 # 64-bit random number and it might be extremely slow on a machine with
  36 # not enough entropy pool
  37 
  38 # set platform-dependent variables
  39 OS=`uname -s`
  40 case "$OS" in
  41   Windows_* )
  42     FS="\\"
  43     ;;
  44   * )
  45     FS="/"
  46     ;;
  47 esac
  48 
  49 if [ "${TESTSRC}" = "" ] ; then
  50   TESTSRC="."
  51 fi
  52 if [ "${TESTJAVA}" = "" ] ; then
  53   JAVAC_CMD=`which javac`
  54   TESTJAVA=`dirname $JAVAC_CMD`/..
  55 fi
  56 
  57 JAR="${TESTJAVA}${FS}bin${FS}jar ${TESTTOOLVMOPTS}"
  58 JAVA="${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS}"
  59 JAVAC="${TESTJAVA}${FS}bin${FS}javac ${TESTTOOLVMOPTS} ${TESTJAVACOPTS}"
  60 KT="${TESTJAVA}${FS}bin${FS}keytool ${TESTTOOLVMOPTS} -keystore tsks -storepass changeit -keypass changeit -keyalg rsa -validity 200"
  61 
  62 rm tsks
  63 echo Nothing > A
  64 rm old.jar
  65 $JAR cvf old.jar A
  66 
  67 # ca is CA
  68 # old is signer for code
  69 # ts is signer for timestamp
  70 # tsbad1 has no extendedKeyUsage
  71 # tsbad2's extendedKeyUsage is non-critical
  72 # tsbad3's extendedKeyUsage has no timestamping
  73 
  74 $KT -alias ca -genkeypair -ext bc -dname CN=CA
  75 $KT -alias old -genkeypair -dname CN=old
  76 $KT -alias ts -genkeypair -dname CN=ts
  77 $KT -alias tsbad1 -genkeypair -dname CN=tsbad1
  78 $KT -alias tsbad2 -genkeypair -dname CN=tsbad2
  79 $KT -alias tsbad3 -genkeypair -dname CN=tsbad3
  80 
  81 $KT -alias old -certreq | \
  82         $KT -alias ca -gencert | \
  83         $KT -alias old -importcert
  84 $KT -alias ts -certreq | \
  85         $KT -alias ca -gencert -ext eku:critical=ts | \
  86         $KT -alias ts -importcert
  87 $KT -alias tsbad1 -certreq | \
  88         $KT -alias ca -gencert | \
  89         $KT -alias tsbad1 -importcert
  90 $KT -alias tsbad2 -certreq | \
  91         $KT -alias ca -gencert -ext eku=ts | \
  92         $KT -alias tsbad2 -importcert
  93 $KT -alias tsbad3 -certreq | \
  94         $KT -alias ca -gencert -ext eku:critical=cs | \
  95         $KT -alias tsbad3 -importcert
  96 
  97 EXTRAOPTS="-XaddExports:java.base/sun.security.pkcs=ALL-UNNAMED \
  98  -XaddExports:java.base/sun.security.timestamp=ALL-UNNAMED \
  99  -XaddExports:java.base/sun.security.x509=ALL-UNNAMED \
 100  -XaddExports:java.base/sun.security.util=ALL-UNNAMED"
 101 $JAVAC ${EXTRAOPTS} -d . ${TESTSRC}/TimestampCheck.java
 102 $JAVA ${TESTVMOPTS} ${EXTRAOPTS} "-Dtest.tool.vm.opts=${TESTTOOLVMOPTS}" TimestampCheck
 103