Skip to content

Provide API to disable SSL validation when using RestClient #32800

Closed as not planned
@hannah23280

Description

@hannah23280

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions