jdk/test/sun/security/tools/keytool/default_options.sh
author weijun
Fri, 13 Jun 2014 08:25:50 +0800
changeset 24873 7553ba5f4eff
parent 24868 89d9bd9eba96
child 25663 9f511964aee6
permissions -rw-r--r--
8046702: default_options.sh test failure on Solaris Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24868
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
     1
#
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
     2
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
     3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
     4
#
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
     5
# This code is free software; you can redistribute it and/or modify it
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
     6
# under the terms of the GNU General Public License version 2 only, as
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
     7
# published by the Free Software Foundation.
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
     8
#
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
     9
# This code is distributed in the hope that it will be useful, but WITHOUT
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    12
# version 2 for more details (a copy is included in the LICENSE file that
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    13
# accompanied this code).
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    14
#
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    15
# You should have received a copy of the GNU General Public License version
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    16
# 2 along with this work; if not, write to the Free Software Foundation,
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    17
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    18
#
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    19
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    20
# or visit www.oracle.com if you need additional information or have any
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    21
# questions.
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    22
#
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    23
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    24
# @test
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    25
# @bug 8023197
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    26
# @summary Pre-configured command line options for keytool and jarsigner
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    27
#
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    28
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    29
if [ "${TESTJAVA}" = "" ] ; then
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    30
  JAVAC_CMD=`which javac`
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    31
  TESTJAVA=`dirname $JAVAC_CMD`/..
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    32
fi
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    33
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    34
KS=ks
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    35
KEYTOOL="$TESTJAVA/bin/keytool ${TESTTOOLVMOPTS}"
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    36
JAR="$TESTJAVA/bin/jar ${TESTTOOLVMOPTS}"
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    37
JARSIGNER="$TESTJAVA/bin/jarsigner ${TESTTOOLVMOPTS}"
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    38
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    39
rm $KS 2> /dev/null
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    40
24873
7553ba5f4eff 8046702: default_options.sh test failure on Solaris
weijun
parents: 24868
diff changeset
    41
PASS=changeit
7553ba5f4eff 8046702: default_options.sh test failure on Solaris
weijun
parents: 24868
diff changeset
    42
export PASS
24868
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    43
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    44
# keytool
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    45
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    46
cat <<EOF > kt.conf
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    47
# A Pre-configured options file
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    48
keytool.all = -storepass:env PASS -keypass:env PASS -keystore \${user.dir}/$KS -debug
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    49
keytool.genkey = -keyalg ec -ext bc
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    50
keytool.delete = -keystore nothing
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    51
EOF
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    52
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    53
# kt.conf is read
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    54
$KEYTOOL -conf kt.conf -genkeypair -dname CN=A -alias a || exit 1
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    55
$KEYTOOL -conf kt.conf -list -alias a -v > a_certinfo || exit 2
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    56
grep "Signature algorithm name" a_certinfo | grep ECDSA || exit 3
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    57
grep "BasicConstraints" a_certinfo || exit 4
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    58
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    59
# kt.conf is read, and dup multi-valued options processed as expected
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    60
$KEYTOOL -conf kt.conf -genkeypair -dname CN=B -alias b -ext ku=ds \
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    61
        || exit 11
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    62
$KEYTOOL -conf kt.conf -list -alias b -v > b_certinfo || exit 12
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    63
grep "BasicConstraints" b_certinfo || exit 14
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    64
grep "DigitalSignature" b_certinfo || exit 15
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    65
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    66
# Single-valued option in command section override all
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    67
$KEYTOOL -conf kt.conf -delete -alias a && exit 16
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    68
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    69
# Single-valued option on command line overrides again
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    70
$KEYTOOL -conf kt.conf -delete -alias b -keystore $KS || exit 17
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    71
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    72
# jarsigner
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    73
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    74
cat <<EOF > js.conf
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    75
jarsigner.all = -keystore \${user.dir}/$KS -storepass:env PASS -debug -strict
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    76
jarsigner.sign = -digestalg SHA1
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    77
jarsigner.verify = -verbose:summary
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    78
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    79
EOF
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    80
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    81
$JAR cvf a.jar ks js.conf kt.conf
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    82
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    83
$JARSIGNER -conf js.conf a.jar a || exit 21
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    84
$JARSIGNER -conf js.conf -verify a.jar > jarsigner.out || exit 22
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    85
grep "and 2 more" jarsigner.out || exit 23
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    86
$JAR xvf a.jar META-INF/MANIFEST.MF
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    87
grep "SHA1-Digest" META-INF/MANIFEST.MF || exit 24
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    88
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    89
# Error cases
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    90
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    91
# File does not exist
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    92
$KEYTOOL -conf no-such-file -help -list && exit 31
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    93
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    94
# Cannot have both standard name (-genkeypair) and legacy name (-genkey)
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    95
cat <<EOF > bad.conf
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    96
keytool.all = -storepass:env PASS -keypass:env PASS -keystore ks
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    97
keytool.genkeypair = -keyalg rsa
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    98
keytool.genkey = -keyalg ec
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
    99
EOF
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   100
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   101
$KEYTOOL -conf bad.conf -genkeypair -alias me -dname "cn=me" && exit 32
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   102
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   103
# Unknown options are rejected by tool
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   104
cat <<EOF > bad.conf
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   105
keytool.all=-unknown
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   106
EOF
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   107
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   108
$KEYTOOL -conf bad.conf -help -list && exit 33
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   109
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   110
# System property must be present
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   111
cat <<EOF > bad.conf
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   112
keytool.all = -keystore \${no.such.prop}
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   113
EOF
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   114
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   115
$KEYTOOL -conf bad.conf -help -list && exit 34
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   116
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   117
echo Done
89d9bd9eba96 8023197: Pre-configured command line options for keytool and jarsigner
weijun
parents:
diff changeset
   118
exit 0