|
21 | 21 | * questions. |
22 | 22 | */ |
23 | 23 |
|
| 24 | +import java.io.FileInputStream; |
| 25 | +import java.io.InputStream; |
| 26 | +import java.security.KeyStore; |
| 27 | +import java.security.cert.X509Certificate; |
24 | 28 | import java.util.Date; |
25 | 29 | import java.util.Locale; |
| 30 | + |
26 | 31 | import jdk.testlibrary.OutputAnalyzer; |
27 | 32 | import jdk.test.lib.util.JarUtils; |
28 | 33 |
|
@@ -61,16 +66,14 @@ private void start() throws Throwable { |
61 | 66 | Utils.createFiles(FIRST_FILE); |
62 | 67 | JarUtils.createJar(UNSIGNED_JARFILE, FIRST_FILE); |
63 | 68 |
|
64 | | - // calculate certificate expiration date |
65 | | - Date expirationDate = new Date(System.currentTimeMillis() + VALIDITY |
66 | | - * 24 * 60 * 60 * 1000L); |
67 | | - |
68 | 69 | // create key pair |
69 | 70 | createAlias(CA_KEY_ALIAS, "-ext", "bc:c"); |
70 | 71 | createAlias(KEY_ALIAS); |
71 | 72 | issueCert(KEY_ALIAS, |
72 | 73 | "-validity", Integer.toString(VALIDITY)); |
73 | 74 |
|
| 75 | + Date expirationDate = getCertExpirationDate(); |
| 76 | + |
74 | 77 | // sign jar file |
75 | 78 | OutputAnalyzer analyzer = jarsigner( |
76 | 79 | "-J-Duser.timezone=" + timezone, |
@@ -114,4 +117,12 @@ private void start() throws Throwable { |
114 | 117 | System.out.println("Test passed"); |
115 | 118 | } |
116 | 119 |
|
| 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 | + } |
117 | 128 | } |
0 commit comments