httpclient ssl certificate on android

后端 未结 3 1945
广开言路
广开言路 2020-12-13 23:38

I have some troubles with ssl using httpclient on android i am trying to access self signed certificate in details i want my app to trust all certificates ( i will use ssl o

3条回答
  •  情深已故
    2020-12-14 00:17

    If you happen to look at the code of DefaultHttpClient, it looks something like this:

       @Override
        protected ClientConnectionManager createClientConnectionManager() {
            SchemeRegistry registry = new SchemeRegistry();
            registry.register(
                    new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
            registry.register(
                    new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    
            ClientConnectionManager connManager = null;     
            HttpParams params = getParams();
            ...
        }
    

    Notice the mapping of https scheme to org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory().

    You can create a custom implementation for org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory interface (http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/protocol/SecureProtocolSocketFactory.html) wherein, you can create java.net.SSLSocket with a custom TrustManager that accepts all certificate.

    You may want to look into JSSE for more details at http://java.sun.com/j2se/1.4.2/docs/guide/security/jsse/JSSERefGuide.html

提交回复
热议问题