We are using Play 2.5 + Scala and need to use SSL to connect to remote client using https.
The issue is the certificate that we got from client has CN something like api.*.*.*.net
but the actual URL we are trying to hit contains an IP Address :
https://123.234.34.56/service/resource/operation...
Since the common name in the certificate and the hostname(ipAddress) in the URL do not match , we are seeing the below error.
SSLHandshakeException: No subject alternative names present
So I tried to implement HostnameVerifier as shown below in Scala but this code is not being picked up by Play or Netty
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
{
public boolean verify(String hostname, SSLSession session)
{
// custom logic here to match hostname and IpAddress
return true;
}
});
I have no idea why Play/Netty is not picking it up during runtime, but we are hitting the remote client using Play WS :
import play.api.libs.ws.WS
WS.url(url).get()...
I am also thinking of trying the solution mentioned here : Netty SSL hostname verification support
but not sure if I need to implement a ChannelFactory as per the above link as shown here http://netty.io/3.10/xref/org/jboss/netty/example/securechat/SecureChatClientPipelineFactory.html
Also I have seen somewhere else in SO posts that :
If the host name in the certificate doesn't resolve to the address, the server is mis-configured. Nevertheless, you should be able to alter your local DNS resolution to point that name to this IP address in your /etc/hosts file (if under Linux, or its Windows equivalent
I have no idea how to achieve this programatically in Java/Scala
Any help would be much appreciated !
Thanks
Suresh