Skip to content

Provide API to disable SSL validation when using RestClient #32800

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

Closed
hannah23280 opened this issue May 12, 2024 · 4 comments
Closed

Provide API to disable SSL validation when using RestClient #32800

hannah23280 opened this issue May 12, 2024 · 4 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@hannah23280
Copy link

hannah23280 commented May 12, 2024

Scenario:
Using RestClient to send an API call to another application via HTTPS, for the purpose of encrypting payload at transportation layer. I do not want any client or server authentication/validation. To that end I observe the following code works. Just call this method in the @PostConstruct of my spring boot main application. It works

*Note: I understood the importance of having SSL validations, but let's not debate why I want to disable such validations. Cos not every projects out in the wild are interested to care about the SSL validations, especially if 2 microservices are interacting with each other via a dedicated link in an isolated, super secured area

At both client and server side

public Boolean disableSSLValidation() throws Exception {
	final SSLContext sslContext = SSLContext.getInstance("TLS");

	sslContext.init(null, new TrustManager[]{new X509TrustManager() {
		@Override
		public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {}

		@Override
		public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {}

		@Override
		public X509Certificate[] getAcceptedIssuers() {
			return new X509Certificate[0];
		}
	}}, null);

	HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
	HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
		public boolean verify(String hostname, SSLSession session) {
			return true;
		}
	});

}

At server side (disable client authentication)

server:
  port: 443
  ssl:
    enabled: true
    protocol: TLS
    enabled-protocols: TLSv1.2
    bundle: xxx
    key-alias: demo
spring.ssl.bundle.jks.xxx:
    keystore.type: PKCS12
    keystore.location: file:C:/.../cert_dev.p12   <--have no choice but to generate a keystore file, otherwise during bootup, embedded tomcat server will throw error. Even though this file seems to be useless since i am not interested in any SSL validations
    keystore.password: xxxx

My question is: Can spring-mvc provides an API to do what the aforementioned code is doing (disableSSLValidation) instead of developer having to manually implement it?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 12, 2024
@xufeiranfree
Copy link

I want to know too.

@bclozel
Copy link
Member

bclozel commented May 13, 2024

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

In this case, RestTemplate, RestClient and WebClient all are API abstractions on top of existing HTTP client libraries. Such configuration depends on the actual library and we cannot provide a unified model for all.

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 13, 2024
@hannah23280
Copy link
Author

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

In this case, RestTemplate, RestClient and WebClient all are API abstractions on top of existing HTTP client libraries. Such configuration depends on the actual library and we cannot provide a unified model for all.

hi, this post is actually for request for enhancement purpose.
if the above disableSslvalidation works for restclient and web client ,(ignoring resttemplate, since it is currently put into maintenance mode), I wonder why not let the framework implement it for us developer? developer can just simply configure via properties to disable SSL validations (or programmatically call an API), rather than having to implement the boilerplate code

@bclozel
Copy link
Member

bclozel commented May 13, 2024

@hannah23280 we are not going to invest here, since such configuration is very low level and specific to the HTTP client. Again, providing a unified approach for this would be very challenging. There are many variations and subtle HTTP client configuration, so it's unlikely we would design an efficient property model. We are declining this enhancement proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants