Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c390cba authored by Mario Danic's avatar Mario Danic
Browse files

Add support for IPv6



Signed-off-by: default avatarMario Danic <mario@lovelyhq.com>
parent fca8d44c
Loading
Loading
Loading
Loading
+111 −99
Original line number Diff line number Diff line
@@ -24,7 +24,17 @@

package com.owncloud.android.lib.common.network;

import com.owncloud.android.lib.common.utils.Log_OC;

import org.apache.commons.httpclient.ConnectTimeoutException;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;

import java.io.IOException;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
@@ -41,15 +51,6 @@ import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;

import org.apache.commons.httpclient.ConnectTimeoutException;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;

import com.owncloud.android.lib.common.utils.Log_OC;



/**
 * AdvancedSSLProtocolSocketFactory allows to create SSL {@link Socket}s with
@@ -66,10 +67,6 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory {
    private AdvancedX509TrustManager mTrustManager = null;
    private X509HostnameVerifier mHostnameVerifier = null;

    public SSLContext getSslContext() {
        return mSslContext;
    }
    
    /**
     * Constructor for AdvancedSSLProtocolSocketFactory.
     */
@@ -89,6 +86,10 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory {
        mHostnameVerifier = hostnameVerifier;
    }

    public SSLContext getSslContext() {
        return mSslContext;
    }

    /**
     * @see ProtocolSocketFactory#createSocket(java.lang.String, int, java.net.InetAddress, int)
     */
@@ -151,9 +152,7 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory {
     * @param clientHost the local host name/IP to bind the socket to
     * @param clientPort the port on the local machine
     * @param params     {@link HttpConnectionParams Http connection parameters}
     * 
     * @return Socket a new socket
     * 
     * @throws IOException          if an I/O error occurs while creating the socket
     * @throws UnknownHostException if the IP address of the host cannot be
     *                              determined
@@ -177,7 +176,19 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory {
        Socket socket = socketfactory.createSocket();
        enableSecureProtocols(socket);
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);

        InetAddress address = InetAddress.getByName(host);
        if (address instanceof Inet6Address) {
            InetAddress[] inetAddressArray = InetAddress.getAllByName(host);
            for (InetAddress inetAddress : inetAddressArray) {
                if (inetAddress instanceof Inet4Address) {
                    address = inetAddress;
                    break;
                }
            }
        }

        SocketAddress remoteaddr = new InetSocketAddress(address, port);
        socket.setSoTimeout(params.getSoTimeout() * 5);
        socket.bind(localaddr);
        ServerNameIndicator.setServerNameIndication(host, (SSLSocket) socket);
@@ -236,6 +247,7 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory {
     *
     * Then, the host name is compared with the content of the server certificate using the current host name verifier,
     * if any.
     *
     * @param socket
     */
    private void verifyPeerIdentity(String host, int port, Socket socket) throws IOException {