jdk/test/sun/security/tools/jarsigner/warnings.sh
author martin
Wed, 02 Sep 2015 14:11:50 -0700
changeset 32427 c22b7e41adf3
parent 24116 9f9b4ba34aad
permissions -rw-r--r--
8134984: Text files should end in exactly one newline Summary: automated fixup of newlines at end-of-file via the usual perl one-liner Reviewed-by: chegar, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22315
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
     1
#
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
     2
# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
     3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
     4
#
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
     5
# This code is free software; you can redistribute it and/or modify it
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
     6
# under the terms of the GNU General Public License version 2 only, as
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
     7
# published by the Free Software Foundation.
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
     8
#
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
     9
# This code is distributed in the hope that it will be useful, but WITHOUT
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    12
# version 2 for more details (a copy is included in the LICENSE file that
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    13
# accompanied this code).
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    14
#
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    15
# You should have received a copy of the GNU General Public License version
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    16
# 2 along with this work; if not, write to the Free Software Foundation,
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    17
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    18
#
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    19
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    20
# or visit www.oracle.com if you need additional information or have any
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    21
# questions.
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    22
#
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    23
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    24
# @test
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    25
# @bug 8024302
22322
40151ab78d1a 8026037: [TESTBUG] sun/security/tools/jarsigner/warnings.sh test fails on Solaris
weijun
parents: 22315
diff changeset
    26
# @bug 8026037
22315
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    27
# @summary Clarify jar verifications
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    28
#
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    29
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    30
if [ "${TESTJAVA}" = "" ] ; then
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    31
  JAVAC_CMD=`which javac`
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    32
  TESTJAVA=`dirname $JAVAC_CMD`/..
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    33
fi
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    34
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    35
# set platform-dependent variables
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    36
OS=`uname -s`
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    37
case "$OS" in
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    38
  Windows_* )
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    39
    FS="\\"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    40
    ;;
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    41
  * )
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    42
    FS="/"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    43
    ;;
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    44
esac
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    45
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    46
KS=warnings.jks
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    47
JFILE=warnings.jar
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    48
24116
9f9b4ba34aad 8040321: keytool and jarsigner tests doesn't pass though VM tools to tools
weijun
parents: 22322
diff changeset
    49
KT="$TESTJAVA${FS}bin${FS}keytool ${TESTTOOLVMOPTS} -storepass changeit -keypass changeit \
22315
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    50
        -keystore $KS"
24116
9f9b4ba34aad 8040321: keytool and jarsigner tests doesn't pass though VM tools to tools
weijun
parents: 22322
diff changeset
    51
JAR="$TESTJAVA${FS}bin${FS}jar ${TESTTOOLVMOPTS}"
9f9b4ba34aad 8040321: keytool and jarsigner tests doesn't pass though VM tools to tools
weijun
parents: 22322
diff changeset
    52
JARSIGNER="$TESTJAVA${FS}bin${FS}jarsigner ${TESTTOOLVMOPTS} -keystore $KS -storepass changeit"
22315
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    53
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    54
rm $KS 2> /dev/null
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    55
22322
40151ab78d1a 8026037: [TESTBUG] sun/security/tools/jarsigner/warnings.sh test fails on Solaris
weijun
parents: 22315
diff changeset
    56
LANG=C
40151ab78d1a 8026037: [TESTBUG] sun/security/tools/jarsigner/warnings.sh test fails on Solaris
weijun
parents: 22315
diff changeset
    57
export LANG
22315
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    58
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    59
echo 12345 > file
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    60
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    61
ERR=""
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    62
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    63
# Normal signer expiring on 2100-01-01
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    64
$KT -alias s1 -dname CN=s1 -genkey -startdate 2000/01/01 -validity 36525 || ERR="$ERR keytool s1,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    65
# Cert expiring soon, informational warning
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    66
$KT -alias s2 -dname CN=s2 -genkey -validity 100 || ERR="$ERR keytool s2,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    67
# Cert expired, severe warning
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    68
$KT -alias s3 -dname CN=s3 -genkey -startdate -200d -validity 100 || ERR="$ERR keytool s3,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    69
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    70
# noTimestamp is informatiional warning and includes a date
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    71
$JAR cvf $JFILE file
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    72
$JARSIGNER $JFILE s1 > output1 || ERR="$ERR jarsigner s1,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    73
$JARSIGNER -strict $JFILE s1 >> output1 || ERR="$ERR jarsigner s1 strict,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    74
$JARSIGNER -verify $JFILE s1 >> output1 || ERR="$ERR jarsigner s1,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    75
$JARSIGNER -verify -strict $JFILE s1 >> output1 || ERR="$ERR jarsigner s1 strict,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    76
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    77
cat output1 | grep Warning || ERR="$ERR s1 warning,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    78
cat output1 | grep Error && ERR="$ERR s1 error,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    79
cat output1 | grep timestamp | grep 2100-01-01 || ERR="$ERR s1 timestamp,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    80
cat output1 | grep "with signer errors" && ERR="$ERR s1 err,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    81
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    82
# hasExpiringCert is informatiional warning
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    83
$JAR cvf $JFILE file
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    84
$JARSIGNER $JFILE s2 > output2 || ERR="$ERR jarsigner s2,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    85
$JARSIGNER -strict $JFILE s2 >> output2 || ERR="$ERR jarsigner s2 strict,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    86
$JARSIGNER -verify $JFILE s2 >> output2 || ERR="$ERR jarsigner s2,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    87
$JARSIGNER -verify -strict $JFILE s2 >> output2 || ERR="$ERR jarsigner s2 strict,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    88
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    89
cat output2 | grep Warning || ERR="$ERR s2 warning,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    90
cat output2 | grep Error && ERR="$ERR s2 error,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    91
cat output2 | grep timestamp || ERR="$ERR s2 timestamp,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    92
cat output2 | grep "will expire" || ERR="$ERR s2 expiring,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    93
cat output2 | grep "with signer errors" && ERR="$ERR s2 err,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    94
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    95
# hasExpiredCert is severe warning
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    96
$JAR cvf $JFILE file
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    97
$JARSIGNER $JFILE s3 > output3 || ERR="$ERR jarsigner s3,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    98
$JARSIGNER -strict $JFILE s3 > output3s && ERR="$ERR jarsigner s3 strict,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
    99
$JARSIGNER -verify $JFILE s3 >> output3 || ERR="$ERR jarsigner s3,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   100
$JARSIGNER -verify -strict $JFILE s3 >> output3s && ERR="$ERR jarsigner s3 strict,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   101
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   102
# warning without -strict
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   103
cat output3 | grep Warning || ERR="$ERR s3 warning,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   104
cat output3 | grep Error && ERR="$ERR s3 error,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   105
cat output3 | grep "with signer errors" && ERR="$ERR s3 err,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   106
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   107
# error with -strict
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   108
cat output3s | grep Warning || ERR="$ERR s3s warning,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   109
cat output3s | grep Error || ERR="$ERR s3s error,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   110
cat output3s | grep "with signer errors" || ERR="$ERR s3 err,"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   111
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   112
if [ "$ERR" = "" ]; then
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   113
    exit 0
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   114
else
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   115
    echo "ERR is $ERR"
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   116
    exit 1
529f1cc322fc 8024302: Clarify jar verifications
weijun
parents:
diff changeset
   117
fi