Smartphone Connection Problem resolve dns

Document ID : KB000102811
Last Modified Date : 25/06/2018
Show Technical Document Details
Introduction:
While developing an Android test app that uses the Mobile SDK. When the app is launched in the emulator, the Mobile SDK works fine because we can modify the emulator's hosts file adding the API GW domain name (we do that because the API GW is installed in the dev environment on the company's intranet where we don't have a DNS that can resolve the API GW domain name). 
When the app is launched in a phone, we have the following error: 

API Request Url: https://10.10.10.10:8443/connect/client/initialize 
API Request Method: POST 
Unable to post to register_device: Hostname 10.10.10.10 not verified: 
certificate: sha1/MMJ610v359r/3qXRqHG+LHezQAM= 
DN: 1.2.840.113549.1.9.1=#0c0e706970706f40706970706f2e6974,CN=camobile.gateway.local,O=CA Technolegies inc.,ST=USA,C=USA
subjectAltNames: [CAMobile.gateway.local, 10.22.238.196, api.camobile.gateway.com, api.camobile.gateway.local] 

Using a phone, we cannot modify the hosts file so the Mobile SDK connects to the API GW using the IP address, causing the above error.
Adding the API GW IP address in the subjectAltNames field of the certificate, but the Mobile SDK seems to ignore that. 
Instructions:
You can ignore the Hostname Verification during development, here is how to ignore Hostname Verification using the SDK: 

MAS.setConnectionListener(new MASConnectionListener() {
    @Override
    public void onObtained(HttpURLConnection connection) {
        ((HttpsURLConnection) connection).setHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        });
    }

    @Override
    public void onConnected(HttpURLConnection connection) {

    }
});

Note: This could cause insecure network traffic due to trusting SSL/TLS server certificates for wrong hostnames, it is highly recommended to enable this for development purpose only but not production.