Skip to content
Permalink
Browse files
8214937: sun/security/tools/jarsigner/warnings/NoTimestampTest.java f…
…ailed due to unexpected expiration date

Backport-of: 017c702
  • Loading branch information
shipilev committed Aug 13, 2021
1 parent 868921f commit 236a4693ca17e3ee1c46b5ec3a0e039f1b423c6a
Showing with 15 additions and 4 deletions.
  1. +15 −4 test/jdk/sun/security/tools/jarsigner/warnings/NoTimestampTest.java
@@ -21,8 +21,13 @@
* questions.
*/

import java.io.FileInputStream;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.Locale;

import jdk.testlibrary.OutputAnalyzer;
import jdk.test.lib.util.JarUtils;

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

// calculate certificate expiration date
Date expirationDate = new Date(System.currentTimeMillis() + VALIDITY
* 24 * 60 * 60 * 1000L);

// create key pair
createAlias(CA_KEY_ALIAS, "-ext", "bc:c");
createAlias(KEY_ALIAS);
issueCert(KEY_ALIAS,
"-validity", Integer.toString(VALIDITY));

Date expirationDate = getCertExpirationDate();

// sign jar file
OutputAnalyzer analyzer = jarsigner(
"-J-Duser.timezone=" + timezone,
@@ -114,4 +117,12 @@ private void start() throws Throwable {
System.out.println("Test passed");
}

private static Date getCertExpirationDate() throws Exception {
KeyStore ks = KeyStore.getInstance("JKS");
try (InputStream in = new FileInputStream(KEYSTORE)) {
ks.load(in, PASSWORD.toCharArray());
}
X509Certificate cert = (X509Certificate) ks.getCertificate(KEY_ALIAS);
return cert.getNotAfter();
}
}

1 comment on commit 236a469

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 236a469 Aug 13, 2021

Please sign in to comment.