Scenario: Let's say a MITM was able to plant a faked, self-signed certificate on my client (Android app), instead of the self-signed certificate of my server.
When now my app tries to connect to the server, using:
URL url = new URL("https://www.hardcoded.unchangeable.uri.toserver"); HttpsURLConnection urlConnection = (HttpsURLConnection)url.openConnection(); urlConnection.setSSLSocketFactory(context.getSocketFactory()); urlConnection.connect(); ...
Is the MITM able to reroute the request to his server?
If not I'm safe, I would just see a handshake exception, wouldn't I?