Skip to content

Commit 236a469

Browse files
committed
8214937: sun/security/tools/jarsigner/warnings/NoTimestampTest.java failed due to unexpected expiration date
Backport-of: 017c702
1 parent 868921f commit 236a469

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

test/jdk/sun/security/tools/jarsigner/warnings/NoTimestampTest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@
2121
* questions.
2222
*/
2323

24+
import java.io.FileInputStream;
25+
import java.io.InputStream;
26+
import java.security.KeyStore;
27+
import java.security.cert.X509Certificate;
2428
import java.util.Date;
2529
import java.util.Locale;
30+
2631
import jdk.testlibrary.OutputAnalyzer;
2732
import jdk.test.lib.util.JarUtils;
2833

@@ -61,16 +66,14 @@ private void start() throws Throwable {
6166
Utils.createFiles(FIRST_FILE);
6267
JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE);
6368

64-
// calculate certificate expiration date
65-
Date expirationDate = new Date(System.currentTimeMillis() + VALIDITY
66-
* 24 * 60 * 60 * 1000L);
67-
6869
// create key pair
6970
createAlias(CA_KEY_ALIAS, "-ext", "bc:c");
7071
createAlias(KEY_ALIAS);
7172
issueCert(KEY_ALIAS,
7273
"-validity", Integer.toString(VALIDITY));
7374

75+
Date expirationDate = getCertExpirationDate();
76+
7477
// sign jar file
7578
OutputAnalyzer analyzer = jarsigner(
7679
"-J-Duser.timezone=" + timezone,
@@ -114,4 +117,12 @@ private void start() throws Throwable {
114117
System.out.println("Test passed");
115118
}
116119

120+
private static Date getCertExpirationDate() throws Exception {
121+
KeyStore ks = KeyStore.getInstance("JKS");
122+
try (InputStream in = new FileInputStream(KEYSTORE)) {
123+
ks.load(in, PASSWORD.toCharArray());
124+
}
125+
X509Certificate cert = (X509Certificate) ks.getCertificate(KEY_ALIAS);
126+
return cert.getNotAfter();
127+
}
117128
}

0 commit comments

Comments
 (0)