/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.jscape.inet.ftp.FtpException
 *  com.jscape.inet.ftps.FtpsCertificateVerifier
 *  com.l7tech.common.io.CertUtils
 *  com.l7tech.gateway.common.audit.SystemMessages
 *  com.l7tech.util.ExceptionUtils
 */
package com.l7tech.server.transport.ftp;

import com.jscape.inet.ftp.FtpException;
import com.jscape.inet.ftps.FtpsCertificateVerifier;
import com.l7tech.common.io.CertUtils;
import com.l7tech.gateway.common.audit.SystemMessages;
import com.l7tech.server.transport.ftp.FtpClientUtils;
import com.l7tech.util.ExceptionUtils;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.text.MessageFormat;
import java.util.logging.Level;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.X509TrustManager;

class f
implements FtpsCertificateVerifier {
    private final X509TrustManager a;
    private final HostnameVerifier b;
    private final String c;
    private boolean d = false;
    private FtpException e;
    static final boolean f;
    private static final String[] g;

    public f(X509TrustManager x509TrustManager, HostnameVerifier hostnameVerifier, String string) {
        if (!f && x509TrustManager == null) {
            throw new AssertionError();
        }
        if (!f && string == null) {
            throw new AssertionError();
        }
        this.a = x509TrustManager;
        this.b = hostnameVerifier;
        this.c = string;
    }

    public boolean authorized() {
        return this.d;
    }

    /*
     * Unable to fully structure code
     */
    public void verify(SSLSession var1_1) {
        block19: {
            try {
                if (FtpClientUtils.a.isLoggable(Level.FINEST)) {
                    FtpClientUtils.a.finest(com.l7tech.server.transport.ftp.f.g[0] + this.c + com.l7tech.server.transport.ftp.f.g[1]);
                }
            }
            catch (SSLPeerUnverifiedException v0) {
                throw com.l7tech.server.transport.ftp.f.a(v0);
            }
            try {
                var2_2 = var1_1.getPeerCertificates();
            }
            catch (SSLPeerUnverifiedException var3_3) {
                this.e = new FtpException(MessageFormat.format(SystemMessages.FTP_SSL_NO_CERT.getMessage(), new Object[]{this.c, var3_3.getMessage()}));
                return;
            }
            var3_4 = new X509Certificate[var2_2.length];
            var4_5 = 0;
            while (true) {
                block17: {
                    block16: {
                        if (var4_5 >= var2_2.length) break;
                        try {
                            block20: {
                                if (!(var2_2[var4_5] instanceof X509Certificate)) break block16;
                                break block20;
                                catch (SSLPeerUnverifiedException v1) {
                                    throw com.l7tech.server.transport.ftp.f.a(v1);
                                }
                            }
                            var3_4[var4_5] = (X509Certificate)var2_2[var4_5];
                            break block17;
                        }
                        catch (SSLPeerUnverifiedException v2) {
                            throw com.l7tech.server.transport.ftp.f.a(v2);
                        }
                    }
                    this.e = new FtpException(MessageFormat.format(SystemMessages.FTP_SSL_NOT_X509.getMessage(), new Object[]{this.c}));
                    return;
                }
                ++var4_5;
            }
            try {
                block18: {
                    this.a.checkServerTrusted(var3_4, CertUtils.extractAuthType((String)var1_1.getCipherSuite()));
                    if (this.b == null) ** GOTO lbl43
                    try {
                        block21: {
                            if (!this.b.verify(this.c, var1_1)) break block18;
                            break block21;
                            catch (SSLPeerUnverifiedException v3) {
                                throw com.l7tech.server.transport.ftp.f.a(v3);
                            }
                        }
                        this.d = true;
                        this.e = null;
                        break block19;
                    }
                    catch (SSLPeerUnverifiedException v4) {
                        throw com.l7tech.server.transport.ftp.f.a(v4);
                    }
                }
                this.e = new FtpException(MessageFormat.format(SystemMessages.FTP_SSL_UNTRUSTED.getMessage(), new Object[]{this.c, com.l7tech.server.transport.ftp.f.g[2]}));
            }
            catch (CertificateException var4_6) {
                this.e = new FtpException(MessageFormat.format(SystemMessages.FTP_SSL_UNTRUSTED.getMessage(), new Object[]{this.c, ExceptionUtils.getMessage((Throwable)var4_6)}));
            }
        }
    }

    public void throwIfFailed() throws FtpException {
        try {
            if (this.e != null) {
                throw this.e;
            }
        }
        catch (FtpException ftpException) {
            throw com.l7tech.server.transport.ftp.f.a((Exception)((Object)ftpException));
        }
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "OjK\u001bD]*wh\u00194vtcjjK\u0004GVc120/j!n\u0004 |}M\u001bDM x{\\RWW*wh\u0019\u0006PQ0mj]RAA1mf_\u001bAE7|/J\u0006MV&7\u001cQ`J\u0006LE.|/O\u0017PM%plX\u0006KK-9iX\u001bNA'";
        int n3 = "OjK\u001bD]*wh\u00194vtcjjK\u0004GVc120/j!n\u0004 |}M\u001bDM x{\\RWW*wh\u0019\u0006PQ0mj]RAA1mf_\u001bAE7|/J\u0006MV&7\u001cQ`J\u0006LE.|/O\u0017PM%plX\u0006KK-9iX\u001bNA'".length();
        int n4 = 22;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = com.l7tech.server.transport.ftp.f.a(48, com.l7tech.server.transport.ftp.f.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) break;
            n4 = string.charAt(n5);
        }
        g = stringArray;
        f = !FtpClientUtils.class.desiredAssertionStatus();
    }

    private static Exception a(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] ^ 0x73);
        }
        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 -> 41;
                    case 1 -> 63;
                    case 2 -> 9;
                    case 3 -> 66;
                    case 4 -> 18;
                    case 5 -> 20;
                    default -> 115;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

