author | iignatyev |
Mon, 12 Jun 2017 12:43:26 -0700 | |
changeset 45467 | 99c87a16a8e4 |
parent 45287 | e0bb5f83e17a |
permissions | -rw-r--r-- |
28662 | 1 |
/* |
44109
df1a27b17bc2
8176320: sun/security/tools/jarsigner/TsacertOptionTest.java compilation error, all mach 5 tier 2 platforms broken.
weijun
parents:
41591
diff
changeset
|
2 |
* Copyright (c) 2013, 2017, 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:
44109
diff
changeset
|
25 |
import jdk.test.lib.util.JarUtils; |
28662 | 26 |
|
27 |
/** |
|
28 |
* @test |
|
44109
df1a27b17bc2
8176320: sun/security/tools/jarsigner/TsacertOptionTest.java compilation error, all mach 5 tier 2 platforms broken.
weijun
parents:
41591
diff
changeset
|
29 |
* @bug 8024302 8026037 8176320 |
28662 | 30 |
* @summary The test signs and verifies a jar file with -tsacert option |
40262 | 31 |
* @library /lib/testlibrary warnings |
44109
df1a27b17bc2
8176320: sun/security/tools/jarsigner/TsacertOptionTest.java compilation error, all mach 5 tier 2 platforms broken.
weijun
parents:
41591
diff
changeset
|
32 |
* @library /test/lib |
36966 | 33 |
* @modules java.base/sun.security.pkcs |
30820 | 34 |
* java.base/sun.security.timestamp |
41591
86396e0674ae
8168374: TsacertOptionTest.java fails on all platforms
weijun
parents:
40262
diff
changeset
|
35 |
* java.base/sun.security.tools.keytool |
30820 | 36 |
* java.base/sun.security.util |
37 |
* java.base/sun.security.x509 |
|
38 |
* java.management |
|
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45287
diff
changeset
|
39 |
* @build jdk.test.lib.util.JarUtils |
28662 | 40 |
* @run main TsacertOptionTest |
41 |
*/ |
|
40262 | 42 |
public class TsacertOptionTest extends Test { |
28662 | 43 |
|
44 |
private static final String FILENAME = TsacertOptionTest.class.getName() |
|
45 |
+ ".txt"; |
|
46 |
private static final String SIGNING_KEY_ALIAS = "sign_alias"; |
|
47 |
private static final String TSA_KEY_ALIAS = "ts"; |
|
40262 | 48 |
|
49 |
private static final String PASSWORD = "changeit"; |
|
28662 | 50 |
|
51 |
/** |
|
52 |
* The test signs and verifies a jar file with -tsacert option, |
|
53 |
* and checks that no warning was shown. |
|
54 |
* A certificate that is addressed in -tsacert option contains URL to TSA |
|
55 |
* in Subject Information Access extension. |
|
56 |
*/ |
|
57 |
public static void main(String[] args) throws Throwable { |
|
58 |
TsacertOptionTest test = new TsacertOptionTest(); |
|
59 |
test.start(); |
|
60 |
} |
|
61 |
||
62 |
void start() throws Throwable { |
|
63 |
// create a jar file that contains one file |
|
64 |
Utils.createFiles(FILENAME); |
|
65 |
JarUtils.createJar(UNSIGNED_JARFILE, FILENAME); |
|
66 |
||
67 |
// create key pair for jar signing |
|
40262 | 68 |
keytool( |
28662 | 69 |
"-genkey", |
34382
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
70 |
"-alias", CA_KEY_ALIAS, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
71 |
"-keyalg", KEY_ALG, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
72 |
"-keysize", Integer.toString(KEY_SIZE), |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
73 |
"-keystore", KEYSTORE, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
74 |
"-storepass", PASSWORD, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
75 |
"-keypass", PASSWORD, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
76 |
"-dname", "CN=CA", |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
77 |
"-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0); |
40262 | 78 |
keytool( |
34382
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
79 |
"-genkey", |
28662 | 80 |
"-alias", SIGNING_KEY_ALIAS, |
81 |
"-keyalg", KEY_ALG, |
|
82 |
"-keysize", Integer.toString(KEY_SIZE), |
|
83 |
"-keystore", KEYSTORE, |
|
84 |
"-storepass", PASSWORD, |
|
85 |
"-keypass", PASSWORD, |
|
34382
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
86 |
"-dname", "CN=Test").shouldHaveExitValue(0); |
40262 | 87 |
keytool( |
34382
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
88 |
"-certreq", |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
89 |
"-alias", SIGNING_KEY_ALIAS, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
90 |
"-keystore", KEYSTORE, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
91 |
"-storepass", PASSWORD, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
92 |
"-keypass", PASSWORD, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
93 |
"-file", "certreq").shouldHaveExitValue(0); |
40262 | 94 |
keytool( |
34382
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
95 |
"-gencert", |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
96 |
"-alias", CA_KEY_ALIAS, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
97 |
"-keystore", KEYSTORE, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
98 |
"-storepass", PASSWORD, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
99 |
"-keypass", PASSWORD, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
100 |
"-validity", Integer.toString(VALIDITY), |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
101 |
"-infile", "certreq", |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
102 |
"-outfile", "cert").shouldHaveExitValue(0); |
40262 | 103 |
keytool( |
34382
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
104 |
"-importcert", |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
105 |
"-alias", SIGNING_KEY_ALIAS, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
106 |
"-keystore", KEYSTORE, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
107 |
"-storepass", PASSWORD, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
108 |
"-keypass", PASSWORD, |
5d11306d6969
8130132: jarsigner should emit warning if weak algorithms or keysizes are used
weijun
parents:
31647
diff
changeset
|
109 |
"-file", "cert").shouldHaveExitValue(0); |
28662 | 110 |
|
40252
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
111 |
|
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
112 |
try (TimestampCheck.Handler tsa = TimestampCheck.Handler.init(0, |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
113 |
KEYSTORE)) { |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
114 |
|
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
115 |
// look for free network port for TSA service |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
116 |
int port = tsa.getPort(); |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
117 |
String host = "127.0.0.1"; |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
118 |
String tsaUrl = "http://" + host + ":" + port; |
28662 | 119 |
|
40252
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
120 |
// create key pair for TSA service |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
121 |
// SubjectInfoAccess extension contains URL to TSA service |
40262 | 122 |
keytool( |
40252
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
123 |
"-genkey", |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
124 |
"-v", |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
125 |
"-alias", TSA_KEY_ALIAS, |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
126 |
"-keyalg", KEY_ALG, |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
127 |
"-keysize", Integer.toString(KEY_SIZE), |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
128 |
"-keystore", KEYSTORE, |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
129 |
"-storepass", PASSWORD, |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
130 |
"-keypass", PASSWORD, |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
131 |
"-dname", "CN=TSA", |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
132 |
"-ext", "ExtendedkeyUsage:critical=timeStamping", |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
133 |
"-ext", "SubjectInfoAccess=timeStamping:URI:" + tsaUrl, |
8f320a3f83b8
8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test
weijun
parents:
36966
diff
changeset
|
134 |
"-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0); |
28662 | 135 |
|
136 |
// start TSA |
|
137 |
tsa.start(); |
|
138 |
||
139 |
// sign jar file |
|
140 |
// specify -tsadigestalg option because |
|
141 |
// TSA server uses SHA-1 digest algorithm |
|
40262 | 142 |
OutputAnalyzer analyzer = jarsigner( |
31647
9c848765e848
8130041: TsacertOptionTest.java intermittently fails on Mac
vinnie
parents:
30820
diff
changeset
|
143 |
"-J-Dhttp.proxyHost=", |
9c848765e848
8130041: TsacertOptionTest.java intermittently fails on Mac
vinnie
parents:
30820
diff
changeset
|
144 |
"-J-Dhttp.proxyPort=", |
9c848765e848
8130041: TsacertOptionTest.java intermittently fails on Mac
vinnie
parents:
30820
diff
changeset
|
145 |
"-J-Djava.net.useSystemProxies=", |
28662 | 146 |
"-verbose", |
147 |
"-keystore", KEYSTORE, |
|
148 |
"-storepass", PASSWORD, |
|
149 |
"-keypass", PASSWORD, |
|
150 |
"-signedjar", SIGNED_JARFILE, |
|
151 |
"-tsacert", TSA_KEY_ALIAS, |
|
152 |
"-tsadigestalg", "SHA-1", |
|
153 |
UNSIGNED_JARFILE, |
|
154 |
SIGNING_KEY_ALIAS); |
|
155 |
||
156 |
analyzer.shouldHaveExitValue(0); |
|
157 |
analyzer.stdoutShouldNotContain(WARNING); |
|
158 |
analyzer.shouldContain(JAR_SIGNED); |
|
159 |
||
160 |
// verify signed jar |
|
40262 | 161 |
analyzer = jarsigner( |
28662 | 162 |
"-verbose", |
163 |
"-verify", |
|
164 |
"-keystore", KEYSTORE, |
|
165 |
"-storepass", PASSWORD, |
|
166 |
SIGNED_JARFILE); |
|
167 |
||
168 |
analyzer.shouldHaveExitValue(0); |
|
169 |
analyzer.stdoutShouldNotContain(WARNING); |
|
170 |
analyzer.shouldContain(JAR_VERIFIED); |
|
171 |
} |
|
172 |
||
173 |
System.out.println("Test passed"); |
|
174 |
} |
|
175 |
||
176 |
} |