author | iignatyev |
Fri, 07 Sep 2018 14:01:52 -0700 | |
changeset 51675 | b487c1e914d0 |
parent 50779 | 7284ce754713 |
child 52999 | 8b585e1b2805 |
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 java.util.Date; |
|
50779
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
25 |
import java.util.Locale; |
51675 | 26 |
import jdk.test.lib.process.OutputAnalyzer; |
45287
e0bb5f83e17a
8180888: move jdk.testlibrary.JarUtils to the top level testlibrary
iignatyev
parents:
40262
diff
changeset
|
27 |
import jdk.test.lib.util.JarUtils; |
28662 | 28 |
|
29 |
/** |
|
30 |
* @test |
|
50779
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
31 |
* @bug 8024302 8026037 8196213 |
28662 | 32 |
* @summary Checks warnings if -tsa and -tsacert options are not specified |
51675 | 33 |
* @library /test/lib ../ |
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45287
diff
changeset
|
34 |
* @build jdk.test.lib.util.JarUtils |
28662 | 35 |
* @run main NoTimestampTest |
36 |
*/ |
|
37 |
public class NoTimestampTest extends Test { |
|
38 |
||
39 |
/** |
|
40 |
* The test signs and verifies a jar file without -tsa and -tsacert options, |
|
41 |
* and checks that proper warnings are shown. |
|
42 |
*/ |
|
43 |
public static void main(String[] args) throws Throwable { |
|
50779
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
44 |
Locale reservedLocale = Locale.getDefault(); |
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
45 |
Locale.setDefault(Locale.US); |
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
46 |
|
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
47 |
try { |
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
48 |
NoTimestampTest test = new NoTimestampTest(); |
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
49 |
test.start(); |
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
50 |
} finally { |
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
51 |
// Restore the reserved locale |
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
52 |
Locale.setDefault(reservedLocale); |
7284ce754713
8196213: sun/security/tools/jarsigner/warnings/NoTimestampTest.java test fails on ar_SA locale.
xiaofeya
parents:
48893
diff
changeset
|
53 |
} |
28662 | 54 |
} |
55 |
||
56 |
private void start() throws Throwable { |
|
57 |
String timezone = System.getProperty("user.timezone"); |
|
58 |
System.out.println(String.format("Timezone = %s", timezone)); |
|
59 |
||
60 |
// create a jar file that contains one class file |
|
61 |
Utils.createFiles(FIRST_FILE); |
|
62 |
JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE); |
|
63 |
||
64 |
// calculate certificate expiration date |
|
65 |
Date expirationDate = new Date(System.currentTimeMillis() + VALIDITY |
|
66 |
* 24 * 60 * 60 * 1000L); |
|
67 |
||
68 |
// create key pair |
|
48893
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
69 |
createAlias(CA_KEY_ALIAS); |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
70 |
createAlias(KEY_ALIAS); |
454518b338b0
8191438: jarsigner should print when a timestamp will expire
weijun
parents:
47216
diff
changeset
|
71 |
issueCert(KEY_ALIAS, |
28662 | 72 |
"-validity", Integer.toString(VALIDITY)); |
73 |
||
74 |
// sign jar file |
|
40262 | 75 |
OutputAnalyzer analyzer = jarsigner( |
28662 | 76 |
"-J-Duser.timezone=" + timezone, |
77 |
"-keystore", KEYSTORE, |
|
78 |
"-storepass", PASSWORD, |
|
79 |
"-keypass", PASSWORD, |
|
80 |
"-signedjar", SIGNED_JARFILE, |
|
81 |
UNSIGNED_JARFILE, |
|
82 |
KEY_ALIAS); |
|
83 |
||
84 |
String warning = String.format(NO_TIMESTAMP_SIGNING_WARN_TEMPLATE, |
|
85 |
expirationDate); |
|
86 |
checkSigning(analyzer, warning); |
|
87 |
||
88 |
// verify signed jar |
|
40262 | 89 |
analyzer = jarsigner( |
28662 | 90 |
"-J-Duser.timezone=" + timezone, |
91 |
"-verify", |
|
92 |
"-keystore", KEYSTORE, |
|
93 |
"-storepass", PASSWORD, |
|
94 |
"-keypass", PASSWORD, |
|
95 |
SIGNED_JARFILE, |
|
96 |
KEY_ALIAS); |
|
97 |
||
98 |
warning = String.format(NO_TIMESTAMP_VERIFYING_WARN_TEMPLATE, expirationDate); |
|
99 |
checkVerifying(analyzer, 0, warning); |
|
100 |
||
101 |
// verify signed jar in strict mode |
|
40262 | 102 |
analyzer = jarsigner( |
28662 | 103 |
"-J-Duser.timezone=" + timezone, |
104 |
"-verify", |
|
105 |
"-strict", |
|
106 |
"-keystore", KEYSTORE, |
|
107 |
"-storepass", PASSWORD, |
|
108 |
"-keypass", PASSWORD, |
|
109 |
SIGNED_JARFILE, |
|
110 |
KEY_ALIAS); |
|
111 |
||
112 |
checkVerifying(analyzer, 0, warning); |
|
113 |
||
114 |
System.out.println("Test passed"); |
|
115 |
} |
|
116 |
||
117 |
} |