1 # |
|
2 # Copyright (c) 2014, 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 8023197 |
|
26 # @summary Pre-configured command line options for keytool and jarsigner |
|
27 # |
|
28 |
|
29 if [ "${TESTJAVA}" = "" ] ; then |
|
30 JAVAC_CMD=`which javac` |
|
31 TESTJAVA=`dirname $JAVAC_CMD`/.. |
|
32 fi |
|
33 |
|
34 TESTTOOLVMOPTS="$TESTTOOLVMOPTS -J-Duser.language=en -J-Duser.country=US" |
|
35 |
|
36 KS=ks |
|
37 KEYTOOL="$TESTJAVA/bin/keytool ${TESTTOOLVMOPTS}" |
|
38 |
|
39 rm $KS 2> /dev/null |
|
40 |
|
41 PASS=changeit |
|
42 export PASS |
|
43 |
|
44 cat <<EOF > kt.conf |
|
45 # A Pre-configured options file |
|
46 keytool.all = -storepass:env PASS -keypass:env PASS -keystore \${user.dir}/$KS -debug |
|
47 keytool.genkey = -keyalg ec -ext bc |
|
48 keytool.delete = -keystore nothing |
|
49 EOF |
|
50 |
|
51 # kt.conf is read |
|
52 $KEYTOOL -conf kt.conf -genkeypair -dname CN=A -alias a || exit 1 |
|
53 $KEYTOOL -conf kt.conf -list -alias a -v > a_certinfo || exit 2 |
|
54 grep "Signature algorithm name" a_certinfo | grep ECDSA || exit 3 |
|
55 grep "BasicConstraints" a_certinfo || exit 4 |
|
56 |
|
57 # kt.conf is read, and dup multi-valued options processed as expected |
|
58 $KEYTOOL -conf kt.conf -genkeypair -dname CN=B -alias b -ext ku=ds \ |
|
59 || exit 11 |
|
60 $KEYTOOL -conf kt.conf -list -alias b -v > b_certinfo || exit 12 |
|
61 grep "BasicConstraints" b_certinfo || exit 14 |
|
62 grep "DigitalSignature" b_certinfo || exit 15 |
|
63 |
|
64 # Single-valued option in command section override all |
|
65 $KEYTOOL -conf kt.conf -delete -alias a && exit 16 |
|
66 |
|
67 # Single-valued option on command line overrides again |
|
68 $KEYTOOL -conf kt.conf -delete -alias b -keystore $KS || exit 17 |
|
69 |
|
70 # Error cases |
|
71 |
|
72 # File does not exist |
|
73 $KEYTOOL -conf no-such-file -help -list && exit 31 |
|
74 |
|
75 # Cannot have both standard name (-genkeypair) and legacy name (-genkey) |
|
76 cat <<EOF > bad.conf |
|
77 keytool.all = -storepass:env PASS -keypass:env PASS -keystore ks |
|
78 keytool.genkeypair = -keyalg rsa |
|
79 keytool.genkey = -keyalg ec |
|
80 EOF |
|
81 |
|
82 $KEYTOOL -conf bad.conf -genkeypair -alias me -dname "cn=me" && exit 32 |
|
83 |
|
84 # Unknown options are rejected by tool |
|
85 cat <<EOF > bad.conf |
|
86 keytool.all=-unknown |
|
87 EOF |
|
88 |
|
89 $KEYTOOL -conf bad.conf -help -list && exit 33 |
|
90 |
|
91 # System property must be present |
|
92 cat <<EOF > bad.conf |
|
93 keytool.all = -keystore \${no.such.prop} |
|
94 EOF |
|
95 |
|
96 $KEYTOOL -conf bad.conf -help -list && exit 34 |
|
97 |
|
98 echo Done |
|
99 exit 0 |
|