I have create a slef-signed SSL certificate for testing purpose. It works fine when I open https://localhost
from browser and now I am following this guide for adding my own TrustManager
in Android.
When I try to connect to server using IP address
of my machine it throws
javax.net.ssl.SSLPeerUnverifiedException: Hostname 192.168.10.3 not verified:
While I was able to solve it using HostnameVerifier
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
return hostname.trim().equals("192.168.10.3") || hv.verify(hostname, session);
}
};
but still I want to know what am I missing here? Am I still configuring it properly by using custom HostnameVerifier
? Here is the output of my
certificate
I/System.out: ca=C=PK, L=Islamabad, O=Self, OID.1.2.840.113549.1.9.1=#16176D616C6C617564696E71617A6940676D61696C2E636F6D, CN=https://192.168.10.3
I am running openssl
server by using following command
openssl s_server -key rsa.key -cert allaudin.pem -accept 4000 -WWW