author | weijun |
Fri, 15 Nov 2019 09:06:58 +0800 | |
changeset 59104 | 046e4024e55a |
parent 48760 | 25725c11c296 |
permissions | -rw-r--r-- |
48760
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
1 |
/* |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
4 |
* |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
8 |
* |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
14 |
* |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
18 |
* |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
21 |
* questions. |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
22 |
*/ |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
23 |
|
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
24 |
/* |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
25 |
* @test |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
26 |
* @bug 8196823 |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
27 |
* @summary jarsigner should not create a signed jar if the signing fails |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
28 |
* @library /test/lib |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
29 |
*/ |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
30 |
|
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
31 |
import jdk.test.lib.Asserts; |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
32 |
import jdk.test.lib.SecurityTools; |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
33 |
import jdk.test.lib.util.JarUtils; |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
34 |
|
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
35 |
import java.nio.file.Files; |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
36 |
import java.nio.file.Paths; |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
37 |
|
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
38 |
public class FailedSigning { |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
39 |
|
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
40 |
public static void main(String[] args) throws Exception { |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
41 |
|
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
42 |
SecurityTools.keytool("-keystore", "ks", "-genkeypair", |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
43 |
"-storepass", "changeit", "-keypass", "changeit", |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
44 |
"-keyalg", "RSA", |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
45 |
"-alias", "x", "-dname", "CN=X") |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
46 |
.shouldHaveExitValue(0); |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
47 |
|
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
48 |
JarUtils.createJar("x.jar", "ks"); |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
49 |
|
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
50 |
SecurityTools.jarsigner("-keystore", "ks", "-storepass", "changeit", |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
51 |
"-tsa", "ftp://0.0.0.0", |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
52 |
"x.jar", "x") |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
53 |
.shouldHaveExitValue(1); |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
54 |
|
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
55 |
Asserts.assertFalse(Files.exists(Paths.get("x.jar.sig"))); |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
56 |
|
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
57 |
SecurityTools.jarsigner("-keystore", "ks", "-storepass", "changeit", |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
58 |
"-tsa", "ftp://0.0.0.0", |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
59 |
"-signedjar", "y.jar", "x.jar", "x") |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
60 |
.shouldHaveExitValue(1); |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
61 |
|
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
62 |
Asserts.assertFalse(Files.exists(Paths.get("y.jar"))); |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
63 |
} |
25725c11c296
8196823: jarsigner should not create a signed jar if the signing fails
weijun
parents:
diff
changeset
|
64 |
} |