Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable SSL debugging on the Android platform?

Tags:

java

android

ssl

Is there something similar to setting -D javax.net.debug=ssl at the command line for Java desktop applications, but for the Android? I've tried setting it in code via System.setProperty("javax.net.debug", "ssl"); but that didn't work.

If there isn't a way to enable this property, is there at least another way to debug the client side of an SSL connection?

EDIT: Just to clarify, this is referring to raw SSL sockets (SSLSocket and SSLSocketFactory), not the Apache library or any other network library.

like image 211
Ben Baron Avatar asked Oct 31 '10 22:10

Ben Baron


People also ask

How to enable SSL Debug in WebSphere?

SSL Debug Trace for IBM WebSphereIn the WebSphere Application Server (WAS) Admin Console, navigate to Servers > Server Types > WebSphere application servers, then select the server name. Under Server Infrastructure, expand Java and Process Management > Process definition > Java Virtual Machine.

What is SSL in Android?

The Secure Sockets Layer (SSL)—now technically known as Transport Layer Security (TLS)—is a common building block for encrypted communications between clients and servers.


2 Answers

At this point, there just doesn't seem to be a way to do this. But in any case, we're switching to the Netty library soon which has more detailed logging capabilities build in.

So the (not great) solution to this issue is simply not to use SSLSocket, but to use a better network library instead.

like image 151
Ben Baron Avatar answered Sep 22 '22 06:09

Ben Baron


you can write a TrustManager class to handle it. example :

ClientConnectionManager cm = new BasicClientConnectionManager();
cm.getSchemeRegistry().register(createHttpsScheme());
DefaultHttpClient client = new DefaultHttpClient(cm);
String url = "https://your domain/your url";
HttpGet get = new HttpGet(url);
HttpResponse resp = client.execute(get);

etc..

public static Scheme createHttpsScheme() {
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new TrustManager[] {
                new TestTrustManager()
        }, new SecureRandom());

        SSLSocketFactory sf = new SSLSocketFactory(context);
        return new Scheme("https", 443, sf);
}

int TestTrustManager.java you can print the chain like this:

public class TestTrustManager implements X509TrustManager {
    @Override
    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {

       for (int i = 0; i < chain.length; ++i) {
        System.out.println(chain[i]);
       }

       decorated.checkServerTrusted(chain, authType);
  }
}
like image 40
sambatree Avatar answered Sep 21 '22 06:09

sambatree