/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.util.ConfigFactory
 *  com.l7tech.util.ExceptionUtils
 *  com.l7tech.util.ResourceUtils
 */
package com.l7tech.server.transport.http;

import com.l7tech.server.transport.http.SslClientSocketFactory;
import com.l7tech.server.transport.http.a;
import com.l7tech.util.ConfigFactory;
import com.l7tech.util.ExceptionUtils;
import com.l7tech.util.ResourceUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.security.GeneralSecurityException;
import java.util.Comparator;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public abstract class SslClientSocketFactorySupport
extends SSLSocketFactory
implements Comparator {
    private static final String a;
    private static final int b = 600;
    private final SSLContext c = this.buildSSLContext();
    private static final String[] h;

    public final int compare(Object object, Object object2) {
        int n2;
        block7: {
            block6: {
                try {
                    try {
                        try {
                            if (object == null || object2 == null) break block6;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw SslClientSocketFactorySupport.b(illegalStateException);
                        }
                        if (!object.equals(object2)) break block6;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw SslClientSocketFactorySupport.b(illegalStateException);
                    }
                    n2 = 0;
                    break block7;
                }
                catch (IllegalStateException illegalStateException) {
                    throw SslClientSocketFactorySupport.b(illegalStateException);
                }
            }
            n2 = -1;
        }
        return n2;
    }

    @Override
    public final String[] getDefaultCipherSuites() {
        return this.a().getDefaultCipherSuites();
    }

    @Override
    public final String[] getSupportedCipherSuites() {
        return this.a().getSupportedCipherSuites();
    }

    @Override
    public final Socket createSocket() throws IOException {
        Socket socket = this.a().createSocket();
        return this.a(socket, null, null, -1, null, -1);
    }

    @Override
    public final Socket createSocket(Socket socket, String string, int n2, boolean bl2) throws IOException {
        Socket socket2 = this.a().createSocket(socket, string, n2, bl2);
        return this.a(socket2, string, null, n2, null, -1);
    }

    @Override
    public final Socket createSocket(String string, int n2) throws IOException {
        Socket socket = this.a().createSocket(string, n2);
        return this.a(socket, string, null, n2, null, -1);
    }

    @Override
    public final Socket createSocket(String string, int n2, InetAddress inetAddress, int n3) throws IOException {
        Socket socket = this.a().createSocket(string, n2, inetAddress, n3);
        return this.a(socket, string, null, n2, inetAddress, n3);
    }

    @Override
    public final Socket createSocket(InetAddress inetAddress, int n2) throws IOException {
        Socket socket = this.a().createSocket(inetAddress, n2);
        return this.a(socket, null, inetAddress, n2, null, -1);
    }

    @Override
    public final Socket createSocket(InetAddress inetAddress, int n2, InetAddress inetAddress2, int n3) throws IOException {
        Socket socket = this.a().createSocket(inetAddress, n2, inetAddress2, n3);
        return this.a(socket, null, inetAddress, n2, inetAddress2, n3);
    }

    @Override
    public final Socket createSocket(Socket socket, InputStream inputStream, boolean bl2) throws IOException {
        Socket socket2 = this.a().createSocket(socket, inputStream, bl2);
        return this.a(socket2, null, null, -1, null, -1);
    }

    protected abstract X509TrustManager getTrustManager();

    protected KeyManager[] getDefaultKeyManagers() {
        return null;
    }

    protected SSLContext buildSSLContext() {
        SSLContext sSLContext;
        KeyManager[] keyManagerArray = this.getDefaultKeyManagers();
        X509TrustManager x509TrustManager = this.getTrustManager();
        try {
            if (x509TrustManager == null) {
                throw new IllegalStateException(h[3]);
            }
        }
        catch (GeneralSecurityException generalSecurityException) {
            throw SslClientSocketFactorySupport.b(generalSecurityException);
        }
        int n2 = ConfigFactory.getIntProperty((String)a, (int)600);
        try {
            String[] stringArray = h;
            sSLContext = SSLContext.getInstance(stringArray[4]);
            sSLContext.init(keyManagerArray, new TrustManager[]{x509TrustManager}, null);
            sSLContext.getClientSessionContext().setSessionTimeout(n2);
        }
        catch (GeneralSecurityException generalSecurityException) {
            throw new RuntimeException(h[5], generalSecurityException);
        }
        return sSLContext;
    }

    protected Socket notifyCreated(Socket socket, String string, InetAddress inetAddress, int n2, InetAddress inetAddress2, int n3) throws IOException {
        return socket;
    }

    protected final Socket doVerifyHostname(HostnameVerifier hostnameVerifier, SSLSocket sSLSocket, String string, InetAddress inetAddress) throws IOException {
        block8: {
            try {
                try {
                    if (string != null || inetAddress != null) break block8;
                }
                catch (IOException iOException) {
                    throw SslClientSocketFactorySupport.b(iOException);
                }
                return new a(this, sSLSocket, sSLSocket, hostnameVerifier);
            }
            catch (IOException iOException) {
                throw SslClientSocketFactorySupport.b(iOException);
            }
        }
        String string2 = string;
        if (string2 == null) {
            string2 = inetAddress.getHostName();
        }
        try {
            if (!hostnameVerifier.verify(string2, sSLSocket.getSession())) {
                throw new IOException(h[0] + string + h[1]);
            }
        }
        catch (IOException iOException) {
            throw SslClientSocketFactorySupport.b(iOException);
        }
        return sSLSocket;
    }

    protected SslClientSocketFactorySupport() {
    }

    private SSLSocketFactory a() {
        return this.c.getSocketFactory();
    }

    private Socket a(Socket socket, String string, InetAddress inetAddress, int n2, InetAddress inetAddress2, int n3) throws IOException {
        try {
            return this.notifyCreated(socket, string, inetAddress, n2, inetAddress2, n3);
        }
        catch (Exception exception) {
            try {
                ResourceUtils.closeQuietly((Socket)socket);
                if (exception instanceof IOException) {
                    throw (IOException)exception;
                }
            }
            catch (Exception exception2) {
                throw SslClientSocketFactorySupport.b(exception2);
            }
            throw ExceptionUtils.wrap((Throwable)exception);
        }
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[6];
                var3_1 = 0;
                var2_2 = ".mrQ 7c\u000bg!Ao<qFlnQ 4c\u0012ai\u0005c<p\u0012kgLc8v\u0003\"&\u0002A,\u0019HqrIS<q\u0015knKT0o\u0003mtQS<a\tleV)2ptVt\u0014c\bcf@ryo\u0013qu\u0005b<\"\u0015gu\u0005b<d\tpd\u0005f0p\u0015v!Ps<";
                var4_3 = ".mrQ 7c\u000bg!Ao<qFlnQ 4c\u0012ai\u0005c<p\u0012kgLc8v\u0003\"&\u0002A,\u0019HqrIS<q\u0015knKT0o\u0003mtQS<a\tleV)2ptVt\u0014c\bcf@ryo\u0013qu\u0005b<\"\u0015gu\u0005b<d\tpd\u0005f0p\u0015v!Ps<".length();
                var1_4 = 38;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 87;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = SslClientSocketFactorySupport.a(v0, SslClientSocketFactorySupport.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "k\u0017\u000b+|4-\u0010=n|K{1\u00120t2^71\u0006< \u0017{\u001a\b\\:l2Z5,\\\nS\u0017\u001f87\u0012-e#K";
                    var4_3 = "k\u0017\u000b+|4-\u0010=n|K{1\u00120t2^71\u0006< \u0017{\u001a\b\\:l2Z5,\\\nS\u0017\u001f87\u0012-e#K".length();
                    var1_4 = 3;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 14;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = SslClientSocketFactorySupport.a(v0, SslClientSocketFactorySupport.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        SslClientSocketFactorySupport.h = var5;
        SslClientSocketFactorySupport.a = SslClientSocketFactory.class.getName() + SslClientSocketFactorySupport.h[2];
    }

    private static Exception b(Exception exception) {
        return exception;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x55);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 49;
                    case 1 -> 85;
                    case 2 -> 86;
                    case 3 -> 114;
                    case 4 -> 87;
                    case 5 -> 14;
                    default -> 85;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

