Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpsServer can use TLSv1.3 on JDK16+ #65274

Merged
merged 1 commit into from
Nov 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.sun.net.httpserver.HttpsExchange;
import com.sun.net.httpserver.HttpsParameters;
import com.sun.net.httpserver.HttpsServer;
import org.elasticsearch.bootstrap.JavaVersion;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
Expand Down Expand Up @@ -102,7 +103,7 @@ public static void shutdownHttpServer() {
}

private static SSLContext buildServerSslContext() throws Exception {
final SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
final SSLContext sslContext = SSLContext.getInstance(isHttpsServerBrokenWithTLSv13() ? "TLSv1.2" : "TLS");
final char[] password = "http-password".toCharArray();

final Path cert = PathUtils.get(ReindexRestClientSslTests.class.getResource("http/http.crt").toURI());
Expand All @@ -119,10 +120,12 @@ private static SSLContext buildServerSslContext() throws Exception {
public void testClientFailsWithUntrustedCertificate() throws IOException {
assumeFalse("https://github.com/elastic/elasticsearch/issues/49094", inFipsJvm());
final List<Thread> threads = new ArrayList<>();
final Settings settings = Settings.builder()
.put("path.home", createTempDir())
.put("reindex.ssl.supported_protocols", "TLSv1.2")
.build();
final Settings.Builder builder = Settings.builder()
.put("path.home", createTempDir());
if (isHttpsServerBrokenWithTLSv13()) {
builder.put("reindex.ssl.supported_protocols", "TLSv1.2");
}
final Settings settings = builder.build();
final Environment environment = TestEnvironment.newEnvironment(settings);
final ReindexSslConfig ssl = new ReindexSslConfig(settings, environment, mock(ResourceWatcherService.class));
try (RestClient client = Reindexer.buildRestClient(getRemoteInfo(), ssl, 1L, threads)) {
Expand All @@ -133,11 +136,13 @@ public void testClientFailsWithUntrustedCertificate() throws IOException {
public void testClientSucceedsWithCertificateAuthorities() throws IOException {
final List<Thread> threads = new ArrayList<>();
final Path ca = getDataPath("ca.pem");
final Settings settings = Settings.builder()
final Settings.Builder builder = Settings.builder()
.put("path.home", createTempDir())
.putList("reindex.ssl.certificate_authorities", ca.toString())
.put("reindex.ssl.supported_protocols", "TLSv1.2")
.build();
.putList("reindex.ssl.certificate_authorities", ca.toString());
if (isHttpsServerBrokenWithTLSv13()) {
builder.put("reindex.ssl.supported_protocols", "TLSv1.2");
}
final Settings settings = builder.build();
final Environment environment = TestEnvironment.newEnvironment(settings);
final ReindexSslConfig ssl = new ReindexSslConfig(settings, environment, mock(ResourceWatcherService.class));
try (RestClient client = Reindexer.buildRestClient(getRemoteInfo(), ssl, 1L, threads)) {
Expand All @@ -149,11 +154,13 @@ public void testClientSucceedsWithCertificateAuthorities() throws IOException {
public void testClientSucceedsWithVerificationDisabled() throws IOException {
assumeFalse("Cannot disable verification in FIPS JVM", inFipsJvm());
final List<Thread> threads = new ArrayList<>();
final Settings settings = Settings.builder()
final Settings.Builder builder = Settings.builder()
.put("path.home", createTempDir())
.put("reindex.ssl.verification_mode", "NONE")
.put("reindex.ssl.supported_protocols", "TLSv1.2")
.build();
.put("reindex.ssl.verification_mode", "NONE");
if (isHttpsServerBrokenWithTLSv13()) {
builder.put("reindex.ssl.supported_protocols", "TLSv1.2");
}
final Settings settings = builder.build();
final Environment environment = TestEnvironment.newEnvironment(settings);
final ReindexSslConfig ssl = new ReindexSslConfig(settings, environment, mock(ResourceWatcherService.class));
try (RestClient client = Reindexer.buildRestClient(getRemoteInfo(), ssl, 1L, threads)) {
Expand All @@ -167,14 +174,16 @@ public void testClientPassesClientCertificate() throws IOException {
final Path ca = getDataPath("ca.pem");
final Path cert = getDataPath("client/client.crt");
final Path key = getDataPath("client/client.key");
final Settings settings = Settings.builder()
final Settings.Builder builder = Settings.builder()
.put("path.home", createTempDir())
.putList("reindex.ssl.certificate_authorities", ca.toString())
.put("reindex.ssl.certificate", cert)
.put("reindex.ssl.key", key)
.put("reindex.ssl.key_passphrase", "client-password")
.put("reindex.ssl.supported_protocols", "TLSv1.2")
.build();
.put("reindex.ssl.key_passphrase", "client-password");
if (isHttpsServerBrokenWithTLSv13()) {
builder.put("reindex.ssl.supported_protocols", "TLSv1.2");
}
final Settings settings = builder.build();
AtomicReference<Certificate[]> clientCertificates = new AtomicReference<>();
handler = https -> {
try {
Expand Down Expand Up @@ -216,4 +225,12 @@ public void configure(HttpsParameters params) {
params.setWantClientAuth(true);
}
}

/**
* Checks whether the JVM this test is run under is affected by JDK-8254967, which causes these
* tests to fail if a TLSv1.3 SSLContext is used.
*/
private static boolean isHttpsServerBrokenWithTLSv13() {
return JavaVersion.current().compareTo(JavaVersion.parse("16.0.0")) < 0;
}
}