Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8246709: sun/security/tools/jarsigner/TsacertOptionTest.java compilat…
…ion failed after JDK-8244683

Reviewed-by: weijun
  • Loading branch information
John Jiang committed Jun 6, 2020
1 parent 2625942 commit ff8c6d5debd1746bd06b3ea01d10a22128e654e1
@@ -27,6 +27,7 @@
import java.io.InputStream;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.cert.CertificateException;
@@ -46,6 +47,7 @@

import jdk.test.lib.SecurityTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.security.KeyStoreUtils;
import jdk.test.lib.security.timestamp.*;
import jdk.test.lib.util.JarUtils;
import sun.security.pkcs.PKCS7;
@@ -153,8 +155,7 @@ public TsaParam getRespParam(TsaParam reqParam) {
private static class Handler extends TsaHandler {

Handler(String keystore) throws Exception {
super(KeyStore.getInstance(new File(keystore),
PASSWORD.toCharArray()), PASSWORD);
super(KeyStoreUtils.loadKeyStore(keystore, PASSWORD), PASSWORD);
}

public TsaSigner createSigner(HttpExchange exchange)
@@ -170,7 +171,7 @@ public TsaSigner createSigner(HttpExchange exchange)
}

private static TsaServer initServer(String keystore) throws Exception {
return new TsaServer(new Handler(keystore));
return new TsaServer(0, new Handler(keystore));
}

public static void main(String[] args) throws Throwable {
@@ -22,8 +22,14 @@
*/

import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.security.KeyStoreUtils;
import jdk.test.lib.security.timestamp.TsaHandler;
import jdk.test.lib.security.timestamp.TsaServer;
import jdk.test.lib.util.JarUtils;

import java.io.File;
import java.security.KeyStore;

/**
* @test
* @bug 8024302 8026037 8176320
@@ -110,8 +116,7 @@ void start() throws Throwable {
"-file", "cert").shouldHaveExitValue(0);


try (TimestampCheck.Handler tsa = TimestampCheck.Handler.init(0,
KEYSTORE)) {
try (TsaServer tsa = new TsaServer(0)) {

// look for free network port for TSA service
int port = tsa.getPort();
@@ -134,6 +139,9 @@ void start() throws Throwable {
"-ext", "SubjectInfoAccess=timeStamping:URI:" + tsaUrl,
"-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);

tsa.setHandler(new TsaHandler(
KeyStoreUtils.loadKeyStore(KEYSTORE, PASSWORD), PASSWORD));

// start TSA
tsa.start();

@@ -44,6 +44,30 @@ public class TsaServer implements AutoCloseable {

private final HttpServer server;

/**
* Create {@code TSA} server with the given port and {@link TsaHandler}.
*
* @param port the port number
* @param handler a {@link TsaHandler} instance
* @throws IOException the I/O exception
*/
public TsaServer(int port, TsaHandler handler) throws IOException {
server = HttpServer.create(new InetSocketAddress(port), 0);
if (handler != null) {
setHandler(handler);
}
}

/**
* Create {@code TSA} server with the given port, but without {@link TsaHandler}.
*
* @param port the port number
* @throws IOException the I/O exception
*/
public TsaServer(int port) throws IOException {
this(port, null);
}

/**
* Create {@code TSA} server with the given port, key store and the
* associated passphrase if any. A default {@link TsaHandler} is initialized
@@ -56,40 +80,18 @@ public class TsaServer implements AutoCloseable {
*/
public TsaServer(int port, KeyStore keyStore, String passphrase)
throws IOException {
Objects.requireNonNull(keyStore, "Key store cannot be null");

server = HttpServer.create(new InetSocketAddress(port), 0);
server.createContext("/", new TsaHandler(keyStore, passphrase));
}

public TsaServer(KeyStore keyStore, String passphrase) throws IOException {
this(0, keyStore, passphrase);
}

public TsaServer(int port, KeyStore keyStore) throws IOException {
this(port, keyStore, null);
}

public TsaServer(KeyStore keyStore) throws IOException {
this(0, keyStore, null);
this(port, new TsaHandler(keyStore, passphrase));
}

/**
* Create {@code TSA} server with the given port and {@link TsaHandler}.
* Setup a {@link TsaHandler} for this {@code TSA} server.
*
* @param port the port number
* @param handler a {@link TsaHandler} instance
* @throws IOException the I/O exception
* @param handler a {@link TsaHandler}
*/
public TsaServer(int port, TsaHandler handler) throws IOException {
server = HttpServer.create(new InetSocketAddress(port), 0);
public void setHandler(TsaHandler handler) {
server.createContext("/", handler);
}

public TsaServer(TsaHandler handler) throws IOException {
this(0, handler);
}

/**
* Start {@code TSA} server.
*/

0 comments on commit ff8c6d5

Please sign in to comment.