jdk/test/sun/security/tools/jarsigner/warnings.sh
changeset 32751 38184f604d96
parent 32750 e90079907456
parent 32712 f61a63b7d1e5
child 32752 43c458023730
child 32827 b00f765af244
equal deleted inserted replaced
32750:e90079907456 32751:38184f604d96
     1 #
       
     2 # Copyright (c) 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 8024302
       
    26 # @bug 8026037
       
    27 # @summary Clarify jar verifications
       
    28 #
       
    29 
       
    30 if [ "${TESTJAVA}" = "" ] ; then
       
    31   JAVAC_CMD=`which javac`
       
    32   TESTJAVA=`dirname $JAVAC_CMD`/..
       
    33 fi
       
    34 
       
    35 # set platform-dependent variables
       
    36 OS=`uname -s`
       
    37 case "$OS" in
       
    38   Windows_* )
       
    39     FS="\\"
       
    40     ;;
       
    41   * )
       
    42     FS="/"
       
    43     ;;
       
    44 esac
       
    45 
       
    46 KS=warnings.jks
       
    47 JFILE=warnings.jar
       
    48 
       
    49 KT="$TESTJAVA${FS}bin${FS}keytool ${TESTTOOLVMOPTS} -storepass changeit -keypass changeit \
       
    50         -keystore $KS"
       
    51 JAR="$TESTJAVA${FS}bin${FS}jar ${TESTTOOLVMOPTS}"
       
    52 JARSIGNER="$TESTJAVA${FS}bin${FS}jarsigner ${TESTTOOLVMOPTS} -keystore $KS -storepass changeit"
       
    53 
       
    54 rm $KS 2> /dev/null
       
    55 
       
    56 LANG=C
       
    57 export LANG
       
    58 
       
    59 echo 12345 > file
       
    60 
       
    61 ERR=""
       
    62 
       
    63 # Normal signer expiring on 2100-01-01
       
    64 $KT -alias s1 -dname CN=s1 -genkey -startdate 2000/01/01 -validity 36525 || ERR="$ERR keytool s1,"
       
    65 # Cert expiring soon, informational warning
       
    66 $KT -alias s2 -dname CN=s2 -genkey -validity 100 || ERR="$ERR keytool s2,"
       
    67 # Cert expired, severe warning
       
    68 $KT -alias s3 -dname CN=s3 -genkey -startdate -200d -validity 100 || ERR="$ERR keytool s3,"
       
    69 
       
    70 # noTimestamp is informatiional warning and includes a date
       
    71 $JAR cvf $JFILE file
       
    72 $JARSIGNER $JFILE s1 > output1 || ERR="$ERR jarsigner s1,"
       
    73 $JARSIGNER -strict $JFILE s1 >> output1 || ERR="$ERR jarsigner s1 strict,"
       
    74 $JARSIGNER -verify $JFILE s1 >> output1 || ERR="$ERR jarsigner s1,"
       
    75 $JARSIGNER -verify -strict $JFILE s1 >> output1 || ERR="$ERR jarsigner s1 strict,"
       
    76 
       
    77 cat output1 | grep Warning || ERR="$ERR s1 warning,"
       
    78 cat output1 | grep Error && ERR="$ERR s1 error,"
       
    79 cat output1 | grep timestamp | grep 2100-01-01 || ERR="$ERR s1 timestamp,"
       
    80 cat output1 | grep "with signer errors" && ERR="$ERR s1 err,"
       
    81 
       
    82 # hasExpiringCert is informatiional warning
       
    83 $JAR cvf $JFILE file
       
    84 $JARSIGNER $JFILE s2 > output2 || ERR="$ERR jarsigner s2,"
       
    85 $JARSIGNER -strict $JFILE s2 >> output2 || ERR="$ERR jarsigner s2 strict,"
       
    86 $JARSIGNER -verify $JFILE s2 >> output2 || ERR="$ERR jarsigner s2,"
       
    87 $JARSIGNER -verify -strict $JFILE s2 >> output2 || ERR="$ERR jarsigner s2 strict,"
       
    88 
       
    89 cat output2 | grep Warning || ERR="$ERR s2 warning,"
       
    90 cat output2 | grep Error && ERR="$ERR s2 error,"
       
    91 cat output2 | grep timestamp || ERR="$ERR s2 timestamp,"
       
    92 cat output2 | grep "will expire" || ERR="$ERR s2 expiring,"
       
    93 cat output2 | grep "with signer errors" && ERR="$ERR s2 err,"
       
    94 
       
    95 # hasExpiredCert is severe warning
       
    96 $JAR cvf $JFILE file
       
    97 $JARSIGNER $JFILE s3 > output3 || ERR="$ERR jarsigner s3,"
       
    98 $JARSIGNER -strict $JFILE s3 > output3s && ERR="$ERR jarsigner s3 strict,"
       
    99 $JARSIGNER -verify $JFILE s3 >> output3 || ERR="$ERR jarsigner s3,"
       
   100 $JARSIGNER -verify -strict $JFILE s3 >> output3s && ERR="$ERR jarsigner s3 strict,"
       
   101 
       
   102 # warning without -strict
       
   103 cat output3 | grep Warning || ERR="$ERR s3 warning,"
       
   104 cat output3 | grep Error && ERR="$ERR s3 error,"
       
   105 cat output3 | grep "with signer errors" && ERR="$ERR s3 err,"
       
   106 
       
   107 # error with -strict
       
   108 cat output3s | grep Warning || ERR="$ERR s3s warning,"
       
   109 cat output3s | grep Error || ERR="$ERR s3s error,"
       
   110 cat output3s | grep "with signer errors" || ERR="$ERR s3 err,"
       
   111 
       
   112 if [ "$ERR" = "" ]; then
       
   113     exit 0
       
   114 else
       
   115     echo "ERR is $ERR"
       
   116     exit 1
       
   117 fi