Index: modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java =================================================================== --- modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java (revision 418742) +++ modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java (working copy) @@ -320,9 +320,32 @@ } public void connect() throws IOException { + if (connected) { + return; + } super.connect(); - // TODO wrap established Socket into SSLSocket + // TODO make SSL Tunnel in case of using the proxy + setUpTransportIO(wrapConnection(socket)); } + + /** + * Create the secure socket over the connected socket and + * verify remote hostname. + */ + private Socket wrapConnection(Socket socket) throws IOException { + String hostname = url.getHost(); + // create the wrapper over connected socket + sslSocket = (SSLSocket) getSSLSocketFactory().createSocket( + socket, hostname, url.getPort(), true); + sslSocket.setUseClientMode(true); + sslSocket.startHandshake(); + if (!getHostnameVerifier().verify(hostname, + sslSocket.getSession())) { + throw new IOException("Hostname <" + + hostname + "> was not verified."); + } + return sslSocket; + } } }