package me.vickychijwani.spectre;

import com.facebook.stetho.Stetho;
import com.facebook.stetho.okhttp.StethoInterceptor;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.okhttp.OkHttpClient;
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;

public class DebugSpectreApplication extends SpectreApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        Stetho.Initializer initializer = Stetho.newInitializerBuilder(this)
                .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                .enableWebKitInspector(RealmInspectorModulesProvider.builder(this)
                        .withMetaTables()
                        .build())
                .build();
        Stetho.initialize(initializer);

        // auto-detect Activity memory leaks!
        LeakCanary.install(this);
    }

    @Override
    protected OkHttpClient getOkHttpClient() {
        OkHttpClient client = super.getOkHttpClient();
        client.networkInterceptors().add(new StethoInterceptor());
        return client;
    }

}

@@ -263,16 +263,212 @@
 vider;%0A%0A
+import java.security.cert.CertificateException;%0A%0Aimport javax.net.ssl.SSLContext;%0Aimport javax.net.ssl.SSLSocketFactory;%0Aimport javax.net.ssl.TrustManager;%0Aimport javax.net.ssl.X509TrustManager;%0A%0A
 public c
@@ -1245,30 +1245,1456 @@
 ));%0A
-        return client;
+%0A        // trust all SSL certs, for TESTING ONLY!%0A        client.setHostnameVerifier((hostname, session) -%3E true);%0A        client.setSslSocketFactory(getUnsafeSslSocketFactory());%0A%0A        return client;%0A    %7D%0A%0A    private SSLSocketFactory getUnsafeSslSocketFactory() %7B%0A        try %7B%0A            // Create a trust manager that does not validate certificate chains%0A            final TrustManager%5B%5D trustAllCerts = new TrustManager%5B%5D %7B new TrustEveryoneManager() %7D;%0A            // Install the all-trusting trust manager%0A            final SSLContext sslContext = SSLContext.getInstance(%22SSL%22);%0A            sslContext.init(null, trustAllCerts, new java.security.SecureRandom());%0A            // Create an ssl socket factory with our all-trusting manager%0A            return sslContext.getSocketFactory();%0A        %7D catch (Exception e) %7B%0A            throw new RuntimeException(e);%0A        %7D%0A    %7D%0A%0A    // private stuff%0A    private static class TrustEveryoneManager implements X509TrustManager %7B%0A        @Override%0A        public void checkClientTrusted(java.security.cert.X509Certificate%5B%5D chain, String authType)%0A                throws CertificateException %7B%7D%0A%0A        @Override%0A        public void checkServerTrusted(java.security.cert.X509Certificate%5B%5D chain, String authType)%0A                throws CertificateException %7B%7D%0A%0A        @Override%0A        public java.security.cert.X509Certificate%5B%5D getAcceptedIssuers() %7B%0A            return null;%0A        %7D
 %0A   

Fix #41: Test with https.