I tried to work with something I've found on the web. I think I am
quite near. But nothing is printed...

package hyper.hyper;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.log4j.Appender;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Layout;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.spi.LoggingEvent;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

/**
 * Hyper
 */
public class Hyper extends Activity {

        private static Logger logger = Logger.getLogger(Hyper.class);

        private static final String HTTPS = "https://www.commerzbanking.de";;

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                logger.debug("START");

                try {
                        URL url = new URL(HTTPS);
                        HttpsURLConnection.setDefaultHostnameVerifier(new 
MyHostnameVerifier());
                        HttpsURLConnection.setDefaultSSLSocketFactory(new 
MySSLSocketFactory());
                        HttpsURLConnection connection = (HttpsURLConnection) 
url.openConnection();
                        connection.setDoOutput(true);
                        connection.setDoInput(true);

                        BufferedReader br = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
                        StringBuffer sb = new StringBuffer();
                        while (br.ready()) {
                                sb.append(br.readLine());
                        }
                        logger.debug("InputStream: " + sb.toString());
                        
                        logger.debug("END");
                } catch (Exception e) {
                        logger.error(e);
                }
        }

        /**
         * MyHostnameVerifier
         */
        public class MyHostnameVerifier implements HostnameVerifier {

                public boolean verify(String hostname, SSLSession session) {
                        logger.debug("hostname: " + hostname);
                        logger.debug("session.getPeerHost: " + 
session.getPeerHost());
                        return true;
                }
        }

        /**
         * MyTrustManager
         */
        public class MyTrustManager implements X509TrustManager {

                public X509Certificate[] getAcceptedIssuers() {
                        return (null);
                }

                public void checkClientTrusted(X509Certificate[] chain, String 
authType) {
                }

                public void checkServerTrusted(X509Certificate[] chain, String 
authType) {
                }
        }

        /**
         * MySSLSocketFactory
         */
        public class MySSLSocketFactory extends SSLSocketFactory {

                private SSLSocketFactory factory;

                public MySSLSocketFactory() throws KeyManagementException,
                        NoSuchAlgorithmException, KeyStoreException, 
UnrecoverableKeyException {
                        try {
                                SSLContext sc = SSLContext.getInstance("TLS");
                                sc.init(null, new TrustManager[] { new 
MyTrustManager() }, null);
                                factory = sc.getSocketFactory();
                        } catch (Exception ex) {
                        }
                }

                @Override
                public Socket createSocket(Socket arg0, String arg1, int arg2, 
boolean arg3)
                        throws IOException {
                        return factory.createSocket(arg0, arg1, arg2, arg3);
                }

                @Override
                public String[] getDefaultCipherSuites() {
                        return factory.getDefaultCipherSuites();
                }

                @Override
                public String[] getSupportedCipherSuites() {
                        return factory.getSupportedCipherSuites();
                }

                @Override
                public Socket createSocket(String arg0, int arg1) throws 
IOException,
                        UnknownHostException {
                        return factory.createSocket(arg0, arg1);
                }

                @Override
                public Socket createSocket(InetAddress arg0, int arg1) throws 
IOException {
                        return factory.createSocket(arg0, arg1);
                }

                @Override
                public Socket createSocket(String arg0, int arg1, InetAddress 
arg2, int arg3)
                        throws IOException, UnknownHostException {
                        return factory.createSocket(arg0, arg1, arg2, arg3);
                }

                @Override
                public Socket createSocket(InetAddress arg0, int arg1, 
InetAddress
arg2, int arg3)
                        throws IOException {
                        return factory.createSocket(arg0, arg1, arg2, arg3);
                }
        }

}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to