/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.CertUtils
 *  com.l7tech.gateway.common.audit.Audit
 *  com.l7tech.security.cert.CertVerifier
 *  com.l7tech.security.types.CertificateValidationResult
 */
package com.l7tech.server.security.cert;

import com.l7tech.common.io.CertUtils;
import com.l7tech.gateway.common.audit.Audit;
import com.l7tech.security.cert.CertVerifier;
import com.l7tech.security.types.CertificateValidationResult;
import com.l7tech.server.security.cert.RevocationChecker;
import com.l7tech.server.security.cert.RevocationCheckerFactory;
import java.security.cert.CertPathValidatorException;
import java.security.cert.Certificate;
import java.security.cert.PKIXCertPathChecker;
import java.security.cert.PKIXParameters;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

public class RevocationCheckingPKIXCertPathChecker
extends PKIXCertPathChecker {
    private static final Logger a;
    private final RevocationCheckerFactory b;
    private final Set<TrustAnchor> c;
    private final Audit d;
    private X509Certificate e;
    private final X509Certificate[] f;
    private static final String[] g;

    public RevocationCheckingPKIXCertPathChecker(RevocationCheckerFactory revocationCheckerFactory, PKIXParameters pKIXParameters, Audit audit) {
        this.b = revocationCheckerFactory;
        this.c = pKIXParameters.getTrustAnchors();
        this.d = audit;
        this.f = new X509Certificate[1];
    }

    @Override
    public void check(Certificate certificate, Collection<String> collection) throws CertPathValidatorException {
        TrustAnchor trustAnchor2;
        X509Certificate x509Certificate;
        block20: {
            try {
                if (!(certificate instanceof X509Certificate)) {
                    throw new CertPathValidatorException(g[5]);
                }
            }
            catch (CertPathValidatorException certPathValidatorException) {
                throw RevocationCheckingPKIXCertPathChecker.a(certPathValidatorException);
            }
            x509Certificate = (X509Certificate)certificate;
            try {
                try {
                    if (this.f[0] == null || !CertUtils.certsAreEqual((X509Certificate)x509Certificate, (X509Certificate)this.f[0])) break block20;
                }
                catch (CertPathValidatorException certPathValidatorException) {
                    throw RevocationCheckingPKIXCertPathChecker.a(certPathValidatorException);
                }
                throw new CertPathValidatorException(g[1] + String.valueOf(x509Certificate.getSubjectDN()) + g[3]);
            }
            catch (CertPathValidatorException certPathValidatorException) {
                throw RevocationCheckingPKIXCertPathChecker.a(certPathValidatorException);
            }
        }
        try {
            if (a.isLoggable(Level.FINE)) {
                a.log(Level.FINE, g[4], x509Certificate.getSubjectDN());
            }
        }
        catch (CertPathValidatorException certPathValidatorException) {
            throw RevocationCheckingPKIXCertPathChecker.a(certPathValidatorException);
        }
        X509Certificate x509Certificate2 = this.e;
        if (x509Certificate2 == null) {
            for (TrustAnchor trustAnchor2 : this.c) {
                X509Certificate x509Certificate3 = trustAnchor2.getTrustedCert();
                try {
                    if (!x509Certificate3.getSubjectX500Principal().equals(x509Certificate.getIssuerX500Principal()) || !CertVerifier.isVerified((X509Certificate)x509Certificate, (X509Certificate)x509Certificate3)) continue;
                }
                catch (CertPathValidatorException certPathValidatorException) {
                    throw RevocationCheckingPKIXCertPathChecker.a(certPathValidatorException);
                }
                x509Certificate2 = x509Certificate3;
                break;
            }
            try {
                if (x509Certificate2 == null) {
                    throw new CertPathValidatorException(g[2] + String.valueOf(x509Certificate.getSubjectDN()) + g[0]);
                }
            }
            catch (CertPathValidatorException certPathValidatorException) {
                throw RevocationCheckingPKIXCertPathChecker.a(certPathValidatorException);
            }
        }
        RevocationChecker revocationChecker = this.b.getRevocationChecker(x509Certificate2);
        trustAnchor2 = revocationChecker.getRevocationStatus(x509Certificate, x509Certificate2, this.d, CertificateValidationResult.UNKNOWN);
        try {
            if (!trustAnchor2.equals(CertificateValidationResult.OK)) {
                this.f[0] = x509Certificate;
                throw new CertPathValidatorException(g[8] + String.valueOf(x509Certificate.getSubjectDN()) + g[6]);
            }
        }
        catch (CertPathValidatorException certPathValidatorException) {
            throw RevocationCheckingPKIXCertPathChecker.a(certPathValidatorException);
        }
        this.e = x509Certificate;
    }

    @Override
    public Set<String> getSupportedExtensions() {
        return Collections.emptySet();
    }

    @Override
    public void init(boolean bl2) throws CertPathValidatorException {
        try {
            if (bl2) {
                throw new CertPathValidatorException(g[7]);
            }
        }
        catch (CertPathValidatorException certPathValidatorException) {
            throw RevocationCheckingPKIXCertPathChecker.a(certPathValidatorException);
        }
        this.e = null;
    }

    @Override
    public boolean isForwardCheckingSupported() {
        return false;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[9];
                var3_1 = 0;
                var2_2 = "_\u0003C\r\u0015[Q\u0016@\u0003\f\bR)*F\u001d\f\u0019\u001aD\u0011L\u0005C\u0019\u0013U\u001bHK\u0005\u001b\u0012\\\u001dGK\u0005\u0015\t\u0010\u001bF\u0019\u0017\u0013\u001dY\u001bB\u001f\u0006Z\\\u0019;F\u0019\u0017\u0013\u001dY\u001bB\u001f\u0006Z\u0015_\f\u0003\u001f\u0011\u000f\bD\u001dGKD\u0002_\r4(F\u0019\u0005\u0015\t]\u0011M\fC\b\u001eF\u0017@\n\u0017\u0013\u0014^X@\u0003\u0006\u0019\u0010\u0010\u001eL\u0019C\u0019\u001eB\fJ\r\n\u0019\u001aD\u001d\u0003LD\u0001KM_\u0004E&7M\u0007\u001aZ#\u001eM\u0013RC\u0019\u001eB\fJ\r\n\u0019\u001aD\u001dPK\u0002\b\u001e\u0010\u000bV\u001b\u0013\u0015\tD\u001dGE\u0002_\r";
                var4_3 = "_\u0003C\r\u0015[Q\u0016@\u0003\f\bR)*F\u001d\f\u0019\u001aD\u0011L\u0005C\u0019\u0013U\u001bHK\u0005\u001b\u0012\\\u001dGK\u0005\u0015\t\u0010\u001bF\u0019\u0017\u0013\u001dY\u001bB\u001f\u0006Z\\\u0019;F\u0019\u0017\u0013\u001dY\u001bB\u001f\u0006Z\u0015_\f\u0003\u001f\u0011\u000f\bD\u001dGKD\u0002_\r4(F\u0019\u0005\u0015\t]\u0011M\fC\b\u001eF\u0017@\n\u0017\u0013\u0014^X@\u0003\u0006\u0019\u0010\u0010\u001eL\u0019C\u0019\u001eB\fJ\r\n\u0019\u001aD\u001d\u0003LD\u0001KM_\u0004E&7M\u0007\u001aZ#\u001eM\u0013RC\u0019\u001eB\fJ\r\n\u0019\u001aD\u001dPK\u0002\b\u001e\u0010\u000bV\u001b\u0013\u0015\tD\u001dGE\u0002_\r".length();
                var1_4 = 13;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = RevocationCheckingPKIXCertPathChecker.a(v0, RevocationCheckingPKIXCertPathChecker.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "y\u000b^S\\N\u0013\u001f\u0007DA^W\u001eQ\u0003\fJRHWL\u0011\\TRN\u0003Z\u0000)m\u0001ZK^]\u0003V\u000bB\u0004^T\u0012\\\u000f\fB\\U\u001bZ\u0000\fBRNW\\\u0001^PTZ\u001e\\\u0005XA\u001d\u001b";
                    var4_3 = "y\u000b^S\\N\u0013\u001f\u0007DA^W\u001eQ\u0003\fJRHWL\u0011\\TRN\u0003Z\u0000)m\u0001ZK^]\u0003V\u000bB\u0004^T\u0012\\\u000f\fB\\U\u001bZ\u0000\fBRNW\\\u0001^PTZ\u001e\\\u0005XA\u001d\u001b".length();
                    var1_4 = 30;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 91;
                        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++] = RevocationCheckingPKIXCertPathChecker.a(v0, RevocationCheckingPKIXCertPathChecker.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;
            }
        }
        RevocationCheckingPKIXCertPathChecker.g = var5;
        RevocationCheckingPKIXCertPathChecker.a = Logger.getLogger(RevocationCheckingPKIXCertPathChecker.class.getName());
    }

    private static CertPathValidatorException a(CertPathValidatorException certPathValidatorException) {
        return certPathValidatorException;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x2C);
        }
        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 -> 100;
                    case 1 -> 63;
                    case 2 -> 119;
                    case 3 -> 127;
                    case 4 -> 102;
                    case 5 -> 103;
                    default -> 44;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

