mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 03:58:21 +00:00
8373538: Migrate all tests to null-safe "SimpleSSLContext" methods
Reviewed-by: djelinski, jpai
This commit is contained in:
parent
da14813a5b
commit
3541bc8635
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -79,7 +79,7 @@ public class ClearTextServerSSL {
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
var sslContext = new SimpleSSLContext().get();
|
||||
var sslContext = SimpleSSLContext.findSSLContext();
|
||||
var handler = new TestHandler();
|
||||
var server = HttpServer.create(new InetSocketAddress(LOOPBACK_ADDR, 0), 0);
|
||||
server.createContext(path(""), handler);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -142,16 +142,12 @@ public class HTTPTest {
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
SSLContext.setDefault(new SimpleSSLContext().get());
|
||||
} catch (IOException ex) {
|
||||
throw new ExceptionInInitializerError(ex);
|
||||
}
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
SSLContext.setDefault(SimpleSSLContext.findSSLContext());
|
||||
}
|
||||
|
||||
static final Logger logger = Logger.getLogger ("com.sun.net.httpserver");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -112,7 +112,7 @@ public class HTTPTestClient extends HTTPTest {
|
||||
// anything here. Otherwise it could look like:
|
||||
// HttpsURLConnection httpsConn = (HttpsURLConnection)conn;
|
||||
// httpsConn.setSSLSocketFactory(
|
||||
// new SimpleSSLContext().get().getSocketFactory());
|
||||
// SimpleSSLContext.findSSLContext().getSocketFactory());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -223,7 +223,7 @@ public class URLTest {
|
||||
static HttpsServer httpsServer;
|
||||
static HttpContext c, cs;
|
||||
static ExecutorService e, es;
|
||||
static SSLContext ctx;
|
||||
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
|
||||
static int httpPort;
|
||||
static int httpsPort;
|
||||
static String httpAuth;
|
||||
@ -243,8 +243,6 @@ public class URLTest {
|
||||
es = Executors.newCachedThreadPool();
|
||||
httpServer.setExecutor(e);
|
||||
httpsServer.setExecutor(es);
|
||||
|
||||
ctx = new SimpleSSLContext().get();
|
||||
httpsServer.setHttpsConfigurator(new HttpsConfigurator (ctx));
|
||||
|
||||
httpServer.start();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -43,7 +43,7 @@ import jdk.test.lib.net.SimpleSSLContext;
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
public class DummyCacheResponse extends SecureCacheResponse {
|
||||
static SSLContext sslContext;
|
||||
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
|
||||
private final SSLSession cachedSession;
|
||||
private final Map<String, List<String>> rqstHeaders;
|
||||
|
||||
@ -61,7 +61,6 @@ public class DummyCacheResponse extends SecureCacheResponse {
|
||||
executor = Executors.newCachedThreadPool();
|
||||
httpsServer.setExecutor(executor);
|
||||
|
||||
sslContext = new SimpleSSLContext().get();
|
||||
httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
|
||||
httpsServer.start();
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -49,7 +49,7 @@ public class Equals {
|
||||
*/
|
||||
private static final boolean debug = false;
|
||||
|
||||
static SSLContext ctx;
|
||||
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (debug) {
|
||||
@ -65,7 +65,6 @@ public class Equals {
|
||||
HttpContext c2 = s2.createContext("/test1", h);
|
||||
executor = Executors.newCachedThreadPool();
|
||||
s2.setExecutor(executor);
|
||||
ctx = new SimpleSSLContext().get();
|
||||
s2.setHttpsConfigurator(new HttpsConfigurator(ctx));
|
||||
s2.start();
|
||||
int httpsport = s2.getAddress().getPort();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -41,7 +41,7 @@ import jdk.test.lib.net.SimpleSSLContext;
|
||||
|
||||
public class HttpsSession {
|
||||
|
||||
static SSLContext sslContext;
|
||||
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
HttpsServer httpsServer = null;
|
||||
@ -53,8 +53,6 @@ public class HttpsSession {
|
||||
|
||||
executor = Executors.newCachedThreadPool();
|
||||
httpsServer.setExecutor(executor);
|
||||
|
||||
sslContext = new SimpleSSLContext().get();
|
||||
httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
|
||||
httpsServer.start();
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -101,7 +101,7 @@ public class SubjectAltNameIP {
|
||||
*/
|
||||
void doServerSide() throws Exception {
|
||||
SSLServerSocketFactory sslssf =
|
||||
new SimpleSSLContext().get().getServerSocketFactory();
|
||||
SimpleSSLContext.findSSLContext().getServerSocketFactory();
|
||||
SSLServerSocket sslServerSocket =
|
||||
(SSLServerSocket) sslssf.createServerSocket(
|
||||
serverPort, 0,
|
||||
@ -139,7 +139,7 @@ public class SubjectAltNameIP {
|
||||
throw new RuntimeException("Server failed to start.", serverException);
|
||||
}
|
||||
|
||||
SSLSocketFactory sf = new SimpleSSLContext().get().getSocketFactory();
|
||||
SSLSocketFactory sf = SimpleSSLContext.findSSLContext().getSocketFactory();
|
||||
URI uri = new URI("https://" + hostName + ":" + serverPort + "/index.html");
|
||||
HttpsURLConnection conn = (HttpsURLConnection)uri.toURL().openConnection();
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -46,7 +46,7 @@ public class RedirectOnPost {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ExecutorService e= Executors.newFixedThreadPool(5);
|
||||
SSLContext ctx = new SimpleSSLContext().get();
|
||||
SSLContext ctx = SimpleSSLContext.findSSLContext();
|
||||
HttpServer httpServer = getHttpServer(e);
|
||||
HttpsServer httpsServer = getHttpsServer(e, ctx);
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -214,7 +214,7 @@ public class HttpsCB {
|
||||
MyHttpHandler h = new MyHttpHandler();
|
||||
HttpsServer server = HttpsServer.create(new InetSocketAddress(0), 0);
|
||||
server.setHttpsConfigurator(
|
||||
new HttpsConfigurator(new SimpleSSLContext().get()));
|
||||
new HttpsConfigurator(SimpleSSLContext.findSSLContext()));
|
||||
server.createContext("/", h).setAuthenticator(
|
||||
new MyServerAuthenticator(scheme, principal, ktab));
|
||||
server.start();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -221,10 +221,7 @@ public class TestRedirectLinks extends JavadocTester {
|
||||
out.println("Starting old server (" + oldServer.getClass().getSimpleName() + ") on " + oldURL);
|
||||
oldServer.start();
|
||||
|
||||
SSLContext sslContext = new SimpleSSLContext().get();
|
||||
if (sslContext == null) {
|
||||
throw new AssertionError("Could not create a SSLContext");
|
||||
}
|
||||
SSLContext sslContext = SimpleSSLContext.findSSLContext();
|
||||
newServer = HttpsServer.create(new InetSocketAddress(loopback, 0), 0);
|
||||
String newURL = URIBuilder.newBuilder()
|
||||
.scheme("https")
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,12 +23,16 @@
|
||||
|
||||
package jdk.test.lib.net;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.security.*;
|
||||
import javax.net.ssl.*;
|
||||
import java.security.KeyStore;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.StringTokenizer;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
/**
|
||||
* Utility for creating a simple usable {@link SSLContext} for testing purposes.
|
||||
@ -39,17 +43,7 @@ public final class SimpleSSLContext {
|
||||
|
||||
private static final String DEFAULT_KEY_STORE_FILE_REL_PATH = "jdk/test/lib/net/testkeys";
|
||||
|
||||
private final SSLContext ssl;
|
||||
|
||||
// Made `public` for backward compatibility
|
||||
public SimpleSSLContext() throws IOException {
|
||||
this.ssl = findSSLContext(DEFAULT_KEY_STORE_FILE_REL_PATH, DEFAULT_PROTOCOL);
|
||||
}
|
||||
|
||||
// Kept for backward compatibility
|
||||
public SimpleSSLContext(String keyStoreFileRelPath) throws IOException {
|
||||
this.ssl = findSSLContext(Objects.requireNonNull(keyStoreFileRelPath), DEFAULT_PROTOCOL);
|
||||
}
|
||||
private SimpleSSLContext() {}
|
||||
|
||||
/**
|
||||
* {@return a new {@link SSLContext} instance by searching for a key store
|
||||
@ -136,20 +130,4 @@ public final class SimpleSSLContext {
|
||||
}
|
||||
}
|
||||
|
||||
// Kept for backward compatibility
|
||||
public static SSLContext getContext(String protocol) throws IOException {
|
||||
try {
|
||||
return protocol == null || protocol.isEmpty()
|
||||
? findSSLContext()
|
||||
: findSSLContext(protocol);
|
||||
} catch (RuntimeException re) {
|
||||
throw new IOException(re);
|
||||
}
|
||||
}
|
||||
|
||||
// Kept for backward compatibility
|
||||
public SSLContext get() {
|
||||
return ssl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user