HTTPS connections in android with firebase performance monitoring

Viewed 989

I have just integrated firebase performance monitoring in my android app.

In our infrastructure, sometimes we need to connect to a local dev machine over https, and I use this piece of code to avoid ssl certificate checking when connecting to a local machine

private SSLSocketFactory getFakeSSLContext() {
        final SSLContext sslContext;

        final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            @Override
            public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                // Not implemented
            }

            @Override
            public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                // Not implemented
            }
        }};

        try {
            sslContext = SSLContext.getInstance("TLS");

            sslContext.init(null, trustAllCerts, new java.security.SecureRandom());

            // Create all-trusting host name verifier
            final HostnameVerifier allHostsValid = (hostname, session) -> true;
            // Install the all-trusting host verifier
            HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

            return sslContext.getSocketFactory();
        } catch (KeyManagementException | NoSuchAlgorithmException e) {
            LogHelper.e("error creating fake ssl context", e);
        }
        return null;
    }

obviously we do not use it in production :)

The problem is that since I introduced firebase perfomance monitoring plugin, this does not work anymore, and I get this error enter image description here

As you can see in the highlighted 2 lines, it looks like it does something inside the HttpsUrlConnection implementation, and I think that is the cause of the problem. I tried to use FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false); on my application's onCreate method but the problem is still there. How can I make untrusted https connection with firebase performance plugin installed?

thank you

0 Answers
Related