Okhttp3, Hostname cannot be verified in case SSL certificate is issued for IP address

544 Views Asked by At

Following exception happens when OkHttp tries to connect to a server using IP address:

javax.net.ssl.SSLPeerUnverifiedException: Hostname 195.168.2.68 not verified:
       certificate: sha256/rxO7r+KJOj2iTLR+MPWF7rNV45BYYQKvhlsb4K6yHXE=
       DN: CN=test sandbox,OU=it,O=abc,L=newyork,ST=western,C=us
       subjectAltNames: []

A server has a self-signed SSL Certificate which was generated for server's IP address.

Base Url is : https://195.168.2.68:8092/Mobile/

Whats going wrong here?

1

There are 1 best solutions below

0
On

Hostname 195.168.2.68 not verified

and

I tried with various Values for CN , I used ip also. now cn values is 'test'.

Since 195.168.2.68 does not match test it all works as expected as CommonName is what is mainly being used for matching, so you need either properly issued certificate or you may i.e. delegate test domain to point to 195.168.2.68 and use test instead of IP to make it match CN. But I'd fix the certificate in first place.