0

I have two spring boot applications running on two different ports.Basically two micro-services. In both the applications i have created self SSL certificate and able to send request over HTTPS through browser.

Now, When one micro-service trying to communicate to other micro-service over HTTPS i am getting below exception.

Code Snippet- to connect from one micro service to another

strURL = "http://" + ipAddress + ":" + portNumber + "/" + contextPath;
URL url = new URL(strURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "text/plain");
int responseCode = conn.getResponseCode();
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
while ((output = br.readLine()) != null) {
sb.append(output).append(" ");
}
conn.disconnect();


****javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:328)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:322)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1614)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1052)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:987)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)

Is there any configuration needs to be done for two micro-services to communicate with each other?

  • It would be easier for others to help find a solution if you included some examples of your source-code which describe how you're setting up these connections, and at what point they fail. (See also https://stackoverflow.com/help/how-to-ask) – rwp Apr 03 '18 at 11:04
  • Possible duplicate of [Trusting all certificates using HttpClient over HTTPS](https://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https) – Strelok Apr 03 '18 at 14:18

1 Answers1

0

The above error is caused because of the alternative names missing in your certificates. I believe you are running your application on localhost so

  • Add localhost entry in subject alt name

    OR

  • Run the application on the same 'CN', as defined on your certificates.

Read Here -How to resolve the SSLHandshakeException

Community
  • 1
  • 1
Abhishek Galoda
  • 2,753
  • 24
  • 38