author | weijun |
Wed, 14 Feb 2018 16:58:49 +0800 | |
changeset 48893 | 454518b338b0 |
parent 47216 | 71c04702a3d5 |
child 51675 | b487c1e914d0 |
permissions | -rw-r--r-- |
28662 | 1 |
/* |
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
28662 | 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 |
import jdk.testlibrary.OutputAnalyzer; |
|
45287
e0bb5f83e17a
8180888: move jdk.testlibrary.JarUtils to the top level testlibrary
iignatyev
parents:
40262
diff
changeset
|
25 |
import jdk.test.lib.util.JarUtils; |
28662 | 26 |
|
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
27 |
import java.nio.file.Files; |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
28 |
import java.nio.file.Paths; |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
29 |
|
28662 | 30 |
/** |
31 |
* @test |
|
32 |
* @bug 8024302 8026037 |
|
33 |
* @summary Test for chainNotValidated warning |
|
45287
e0bb5f83e17a
8180888: move jdk.testlibrary.JarUtils to the top level testlibrary
iignatyev
parents:
40262
diff
changeset
|
34 |
* @library /lib/testlibrary /test/lib ../ |
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45287
diff
changeset
|
35 |
* @build jdk.test.lib.util.JarUtils |
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
36 |
* @run main ChainNotValidatedTest ca2yes |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
37 |
* @run main ChainNotValidatedTest ca2no |
28662 | 38 |
*/ |
39 |
public class ChainNotValidatedTest extends Test { |
|
40 |
||
41 |
public static void main(String[] args) throws Throwable { |
|
42 |
ChainNotValidatedTest test = new ChainNotValidatedTest(); |
|
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
43 |
test.start(args[0].equals("ca2yes")); |
28662 | 44 |
} |
45 |
||
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
46 |
private void start(boolean ca2yes) throws Throwable { |
28662 | 47 |
// create a jar file that contains one class file |
48 |
Utils.createFiles(FIRST_FILE); |
|
49 |
JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE); |
|
50 |
||
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
51 |
// We have 2 @run. Need cleanup. |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
52 |
Files.deleteIfExists(Paths.get(KEYSTORE)); |
28662 | 53 |
|
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
54 |
// Root CA is not checked at all. If the intermediate CA has |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
55 |
// BasicConstraints extension set to true, it will be valid. |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
56 |
// Otherwise, chain validation will fail. |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
57 |
createAlias(CA_KEY_ALIAS); |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
58 |
createAlias(CA2_KEY_ALIAS); |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
59 |
issueCert(CA2_KEY_ALIAS, |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
60 |
"-ext", |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
61 |
"bc=ca:" + ca2yes); |
28662 | 62 |
|
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
63 |
createAlias(KEY_ALIAS); |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
64 |
issueCert(KEY_ALIAS, "-alias", CA2_KEY_ALIAS); |
28662 | 65 |
|
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
66 |
// remove CA2 certificate so it's not trusted |
40262 | 67 |
keytool( |
28662 | 68 |
"-delete", |
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
69 |
"-alias", CA2_KEY_ALIAS, |
28662 | 70 |
"-keystore", KEYSTORE, |
71 |
"-storepass", PASSWORD, |
|
72 |
"-keypass", PASSWORD).shouldHaveExitValue(0); |
|
73 |
||
74 |
// sign jar |
|
40262 | 75 |
OutputAnalyzer analyzer = jarsigner( |
28662 | 76 |
"-keystore", KEYSTORE, |
77 |
"-storepass", PASSWORD, |
|
78 |
"-keypass", PASSWORD, |
|
79 |
"-signedjar", SIGNED_JARFILE, |
|
80 |
UNSIGNED_JARFILE, |
|
81 |
KEY_ALIAS); |
|
82 |
||
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
83 |
if (ca2yes) { |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
84 |
checkSigning(analyzer, "!" + CHAIN_NOT_VALIDATED_SIGNING_WARNING); |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
85 |
} else { |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
86 |
checkSigning(analyzer, CHAIN_NOT_VALIDATED_SIGNING_WARNING); |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
87 |
} |
28662 | 88 |
|
89 |
// verify signed jar |
|
40262 | 90 |
analyzer = jarsigner( |
28662 | 91 |
"-verify", |
92 |
"-verbose", |
|
93 |
"-keystore", KEYSTORE, |
|
94 |
"-storepass", PASSWORD, |
|
95 |
"-keypass", PASSWORD, |
|
96 |
SIGNED_JARFILE); |
|
97 |
||
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
98 |
if (ca2yes) { |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
99 |
checkVerifying(analyzer, 0, "!" + CHAIN_NOT_VALIDATED_VERIFYING_WARNING); |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
100 |
} else { |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
101 |
checkVerifying(analyzer, 0, CHAIN_NOT_VALIDATED_VERIFYING_WARNING); |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
102 |
} |
28662 | 103 |
|
104 |
// verify signed jar in strict mode |
|
40262 | 105 |
analyzer = jarsigner( |
28662 | 106 |
"-verify", |
107 |
"-verbose", |
|
108 |
"-strict", |
|
109 |
"-keystore", KEYSTORE, |
|
110 |
"-storepass", PASSWORD, |
|
111 |
"-keypass", PASSWORD, |
|
112 |
SIGNED_JARFILE); |
|
113 |
||
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
114 |
if (ca2yes) { |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
115 |
checkVerifying(analyzer, 0, |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
116 |
"!" + CHAIN_NOT_VALIDATED_VERIFYING_WARNING); |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
117 |
} else { |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
118 |
checkVerifying(analyzer, CHAIN_NOT_VALIDATED_EXIT_CODE, |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
119 |
CHAIN_NOT_VALIDATED_VERIFYING_WARNING); |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
120 |
} |
28662 | 121 |
|
122 |
System.out.println("Test passed"); |
|
123 |
} |
|
124 |
||
125 |
} |