diff --git a/test/jdk/com/sun/net/httpserver/ClearTextServerSSL.java b/test/jdk/com/sun/net/httpserver/ClearTextServerSSL.java index 75e4f3fcf45..896f02b178d 100644 --- a/test/jdk/com/sun/net/httpserver/ClearTextServerSSL.java +++ b/test/jdk/com/sun/net/httpserver/ClearTextServerSSL.java @@ -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); diff --git a/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTest.java b/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTest.java index 2dc6963a63e..8965a942153 100644 --- a/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTest.java +++ b/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTest.java @@ -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"); diff --git a/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTestClient.java b/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTestClient.java index 3f436ef6d02..57790da171f 100644 --- a/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTestClient.java +++ b/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTestClient.java @@ -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()); } } diff --git a/test/jdk/java/net/URLPermission/URLTest.java b/test/jdk/java/net/URLPermission/URLTest.java index 907ba6072ec..9d1b4e840e6 100644 --- a/test/jdk/java/net/URLPermission/URLTest.java +++ b/test/jdk/java/net/URLPermission/URLTest.java @@ -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(); diff --git a/test/jdk/javax/net/ssl/HttpsURLConnection/DummyCacheResponse.java b/test/jdk/javax/net/ssl/HttpsURLConnection/DummyCacheResponse.java index f18dca8b0f7..e0d9a3cdc01 100644 --- a/test/jdk/javax/net/ssl/HttpsURLConnection/DummyCacheResponse.java +++ b/test/jdk/javax/net/ssl/HttpsURLConnection/DummyCacheResponse.java @@ -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> 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(); diff --git a/test/jdk/javax/net/ssl/HttpsURLConnection/Equals.java b/test/jdk/javax/net/ssl/HttpsURLConnection/Equals.java index 35913edd2bf..1e43547c59d 100644 --- a/test/jdk/javax/net/ssl/HttpsURLConnection/Equals.java +++ b/test/jdk/javax/net/ssl/HttpsURLConnection/Equals.java @@ -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(); diff --git a/test/jdk/javax/net/ssl/HttpsURLConnection/HttpsSession.java b/test/jdk/javax/net/ssl/HttpsURLConnection/HttpsSession.java index e17ff6c95b2..7b6ac18c4c9 100644 --- a/test/jdk/javax/net/ssl/HttpsURLConnection/HttpsSession.java +++ b/test/jdk/javax/net/ssl/HttpsURLConnection/HttpsSession.java @@ -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(); diff --git a/test/jdk/javax/net/ssl/HttpsURLConnection/SubjectAltNameIP.java b/test/jdk/javax/net/ssl/HttpsURLConnection/SubjectAltNameIP.java index cbd2089e7bd..de747922d7b 100644 --- a/test/jdk/javax/net/ssl/HttpsURLConnection/SubjectAltNameIP.java +++ b/test/jdk/javax/net/ssl/HttpsURLConnection/SubjectAltNameIP.java @@ -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(); diff --git a/test/jdk/sun/net/www/protocol/http/RedirectOnPost.java b/test/jdk/sun/net/www/protocol/http/RedirectOnPost.java index 1f88c851f63..69da47651b7 100644 --- a/test/jdk/sun/net/www/protocol/http/RedirectOnPost.java +++ b/test/jdk/sun/net/www/protocol/http/RedirectOnPost.java @@ -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); diff --git a/test/jdk/sun/security/krb5/auto/HttpsCB.java b/test/jdk/sun/security/krb5/auto/HttpsCB.java index 1f9f0de33ac..278e72592be 100644 --- a/test/jdk/sun/security/krb5/auto/HttpsCB.java +++ b/test/jdk/sun/security/krb5/auto/HttpsCB.java @@ -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(); diff --git a/test/langtools/jdk/javadoc/doclet/testLinkOption/TestRedirectLinks.java b/test/langtools/jdk/javadoc/doclet/testLinkOption/TestRedirectLinks.java index 2a415141229..a4fd5e3f68e 100644 --- a/test/langtools/jdk/javadoc/doclet/testLinkOption/TestRedirectLinks.java +++ b/test/langtools/jdk/javadoc/doclet/testLinkOption/TestRedirectLinks.java @@ -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") diff --git a/test/lib/jdk/test/lib/net/SimpleSSLContext.java b/test/lib/jdk/test/lib/net/SimpleSSLContext.java index 3e0d362cc23..ae2b479c271 100644 --- a/test/lib/jdk/test/lib/net/SimpleSSLContext.java +++ b/test/lib/jdk/test/lib/net/SimpleSSLContext.java @@ -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; - } - }