Repository navigation
Apply disable-ssl-validation to the HTTP/2 client #1462
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
Merged
ryanjbaxter
merged 3 commits into
spring-cloud:main
from
rajeshvasa:gh-1196-http2-disable-ssl-validation
Nov 24, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...java/org/springframework/cloud/openfeign/clientconfig/DisabledValidationTrustManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright 2013-present the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.cloud.openfeign.clientconfig; | ||
|
|
||
| import java.net.Socket; | ||
| import java.security.cert.X509Certificate; | ||
|
|
||
| import javax.net.ssl.SSLEngine; | ||
| import javax.net.ssl.X509ExtendedTrustManager; | ||
|
|
||
| /** | ||
| * Trusts every certificate. Used by {@link HttpClient5FeignConfiguration} for | ||
| * {@code spring.cloud.openfeign.httpclient.disable-ssl-validation} and by | ||
| * {@link Http2ClientFeignConfiguration} for | ||
| * {@code spring.cloud.openfeign.httpclient.http2.disable-ssl-validation}. | ||
| * <p> | ||
| * It extends {@link X509ExtendedTrustManager} because the JDK | ||
| * {@link java.net.http.HttpClient} delegates hostname verification to an extended trust | ||
| * manager, so this also skips hostname verification there, like the Apache HttpClient 5 | ||
| * configuration does with its no-op hostname verifier. | ||
| * | ||
| * @author Rajesh Vasa | ||
| */ | ||
| final class DisabledValidationTrustManager extends X509ExtendedTrustManager { | ||
|
|
||
| @Override | ||
| public void checkClientTrusted(X509Certificate[] chain, String authType) { | ||
| } | ||
|
|
||
| @Override | ||
| public void checkServerTrusted(X509Certificate[] chain, String authType) { | ||
| } | ||
|
|
||
| @Override | ||
| public void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket) { | ||
| } | ||
|
|
||
| @Override | ||
| public void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket) { | ||
| } | ||
|
|
||
| @Override | ||
| public void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine engine) { | ||
| } | ||
|
|
||
| @Override | ||
| public void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine engine) { | ||
| } | ||
|
|
||
| @Override | ||
| public X509Certificate[] getAcceptedIssuers() { | ||
| return new X509Certificate[0]; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
...t/java/org/springframework/cloud/openfeign/FeignHttp2ClientDisableSslValidationTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| /* | ||
| * Copyright 2013-present the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.cloud.openfeign; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.net.InetSocketAddress; | ||
| import java.net.URI; | ||
| import java.net.http.HttpClient; | ||
| import java.net.http.HttpRequest; | ||
| import java.net.http.HttpResponse; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.security.KeyStore; | ||
|
|
||
| import javax.net.ssl.KeyManagerFactory; | ||
| import javax.net.ssl.SSLContext; | ||
| import javax.net.ssl.SSLHandshakeException; | ||
|
|
||
| import com.sun.net.httpserver.HttpsConfigurator; | ||
| import com.sun.net.httpserver.HttpsServer; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
|
|
||
| import org.springframework.boot.WebApplicationType; | ||
| import org.springframework.boot.builder.SpringApplicationBuilder; | ||
| import org.springframework.boot.test.system.CapturedOutput; | ||
| import org.springframework.boot.test.system.OutputCaptureExtension; | ||
| import org.springframework.context.ConfigurableApplicationContext; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
|
||
| /** | ||
| * Tests for {@code spring.cloud.openfeign.httpclient.http2.disable-ssl-validation}. The | ||
| * server uses a self-signed certificate issued for {@code untrusted.invalid}, so both | ||
| * certificate validation and hostname verification fail unless SSL validation is | ||
| * disabled, and a warning is logged when it is. The top-level | ||
| * {@code spring.cloud.openfeign.httpclient.disable-ssl-validation} property does not | ||
| * affect the HTTP/2 client. | ||
| * | ||
| * @author Rajesh Vasa | ||
| */ | ||
| @ExtendWith(OutputCaptureExtension.class) | ||
| class FeignHttp2ClientDisableSslValidationTests { | ||
|
|
||
| private static final String WARNING = "SSL validation is disabled for the HTTP/2 client"; | ||
|
|
||
| private static final char[] KEYSTORE_PASSWORD = "changeit".toCharArray(); | ||
|
|
||
| private static HttpsServer server; | ||
|
|
||
| @BeforeAll | ||
| static void startServer() throws Exception { | ||
| KeyStore keyStore = KeyStore.getInstance("PKCS12"); | ||
| try (InputStream in = FeignHttp2ClientDisableSslValidationTests.class | ||
| .getResourceAsStream("/http2-self-signed.p12")) { | ||
| keyStore.load(in, KEYSTORE_PASSWORD); | ||
| } | ||
| KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); | ||
| keyManagerFactory.init(keyStore, KEYSTORE_PASSWORD); | ||
| SSLContext sslContext = SSLContext.getInstance("TLS"); | ||
| sslContext.init(keyManagerFactory.getKeyManagers(), null, null); | ||
|
|
||
| server = HttpsServer.create(new InetSocketAddress("localhost", 0), 0); | ||
| server.setHttpsConfigurator(new HttpsConfigurator(sslContext)); | ||
| server.createContext("/", exchange -> { | ||
| byte[] body = "ok".getBytes(StandardCharsets.UTF_8); | ||
| exchange.sendResponseHeaders(200, body.length); | ||
| exchange.getResponseBody().write(body); | ||
| exchange.close(); | ||
| }); | ||
| server.start(); | ||
| } | ||
|
|
||
| @AfterAll | ||
| static void stopServer() { | ||
| if (server != null) { | ||
| server.stop(0); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void connectsToSelfSignedServerWhenSslValidationIsDisabled(CapturedOutput output) throws Exception { | ||
| try (ConfigurableApplicationContext context = createContext(true)) { | ||
| HttpResponse<String> response = send(context.getBean(HttpClient.class)); | ||
|
|
||
| assertThat(response.statusCode()).isEqualTo(200); | ||
| assertThat(response.body()).isEqualTo("ok"); | ||
| assertThat(output).containsOnlyOnce(WARNING); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void rejectsSelfSignedServerByDefault(CapturedOutput output) { | ||
| try (ConfigurableApplicationContext context = createContext(false)) { | ||
| HttpClient httpClient = context.getBean(HttpClient.class); | ||
|
|
||
| assertThatExceptionOfType(SSLHandshakeException.class).isThrownBy(() -> send(httpClient)); | ||
| assertThat(output).doesNotContain(WARNING); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void ignoresTopLevelDisableSslValidationProperty(CapturedOutput output) { | ||
| try (ConfigurableApplicationContext context = createContext(false, | ||
| "spring.cloud.openfeign.httpclient.disable-ssl-validation=true")) { | ||
| HttpClient httpClient = context.getBean(HttpClient.class); | ||
|
|
||
| assertThatExceptionOfType(SSLHandshakeException.class).isThrownBy(() -> send(httpClient)); | ||
| assertThat(output).doesNotContain(WARNING); | ||
| } | ||
| } | ||
|
|
||
| private static ConfigurableApplicationContext createContext(boolean disableSslValidation, | ||
| String... extraProperties) { | ||
| return new SpringApplicationBuilder() | ||
| .properties("spring.cloud.openfeign.http2client.enabled=true", | ||
| "spring.cloud.openfeign.httpclient.http2.version=HTTP_1_1", | ||
| "spring.cloud.openfeign.httpclient.http2.disable-ssl-validation=" + disableSslValidation) | ||
| .properties(extraProperties) | ||
| .web(WebApplicationType.NONE) | ||
| .sources(FeignAutoConfiguration.class) | ||
| .run(); | ||
| } | ||
|
|
||
| private static HttpResponse<String> send(HttpClient httpClient) throws Exception { | ||
| URI uri = URI.create("https://localhost:" + server.getAddress().getPort() + "/"); | ||
| return httpClient.send(HttpRequest.newBuilder(uri).GET().build(), HttpResponse.BodyHandlers.ofString()); | ||
| } | ||
|
|
||
| } |
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.