/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.identity.cert.CertEntryRow
 *  com.l7tech.identity.cert.ClientCertManager
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.security.cert.X509Entity
 *  com.l7tech.security.xml.SecurityTokenResolver
 */
package com.l7tech.server;

import com.l7tech.identity.cert.CertEntryRow;
import com.l7tech.identity.cert.ClientCertManager;
import com.l7tech.objectmodel.FindException;
import com.l7tech.security.cert.X509Entity;
import com.l7tech.security.xml.SecurityTokenResolver;
import com.l7tech.server.SecurityTokenResolverSupport;
import java.math.BigInteger;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.logging.Logger;
import javax.security.auth.x500.X500Principal;

public class UserCertificateResolver
extends SecurityTokenResolverSupport
implements SecurityTokenResolver {
    private final ClientCertManager a;
    private static final Logger b;
    private static final String c;

    public UserCertificateResolver(ClientCertManager clientCertManager) {
        this.a = clientCertManager;
    }

    @Override
    public X509Certificate lookup(String string) {
        try {
            block4: {
                List list = this.a.findByThumbprint(string);
                try {
                    if (list == null || list.size() < 1) break block4;
                }
                catch (FindException findException) {
                    throw UserCertificateResolver.a((Exception)((Object)findException));
                }
                return ((CertEntryRow)list.get(0)).getCertificate();
            }
            return null;
        }
        catch (FindException findException) {
            throw new RuntimeException(findException);
        }
    }

    @Override
    public X509Certificate lookupBySki(String string) {
        try {
            block4: {
                List list = this.a.findBySki(string);
                try {
                    if (list == null || list.size() < 1) break block4;
                }
                catch (FindException findException) {
                    throw UserCertificateResolver.a((Exception)((Object)findException));
                }
                return ((X509Entity)list.get(0)).getCertificate();
            }
            return null;
        }
        catch (FindException findException) {
            throw new RuntimeException(findException);
        }
    }

    @Override
    public X509Certificate lookupByIssuerAndSerial(X500Principal x500Principal, BigInteger bigInteger) {
        try {
            block4: {
                List list = this.a.findByIssuerAndSerial(x500Principal, bigInteger);
                try {
                    if (list == null || list.size() < 1) break block4;
                }
                catch (FindException findException) {
                    throw UserCertificateResolver.a((Exception)((Object)findException));
                }
                return ((X509Entity)list.get(0)).getCertificate();
            }
            return null;
        }
        catch (FindException findException) {
            throw new RuntimeException(findException);
        }
    }

    @Override
    public X509Certificate lookupByKeyName(String string) {
        X500Principal x500Principal;
        try {
            x500Principal = new X500Principal(string);
        }
        catch (IllegalArgumentException illegalArgumentException) {
            b.fine(c);
            return null;
        }
        try {
            block6: {
                List list = this.a.findBySubjectDn(x500Principal);
                try {
                    if (list == null || list.size() < 1) break block6;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw UserCertificateResolver.a(illegalArgumentException);
                }
                return ((X509Entity)list.get(0)).getCertificate();
            }
            return null;
        }
        catch (FindException findException) {
            throw new RuntimeException(findException);
        }
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        c = UserCertificateResolver.a(97, UserCertificateResolver.a("^Y;b%\u0006f\u0015U1\f*\u0004w\u0015]bZ%\u0007jQ\u001c\u001a\u0019t[SGU,O-\u001bbY\u001c1X6\u0002mR\u001co\u0001d\npFI/E*\f#[SbA%\u001f`]"));
        b = Logger.getLogger(UserCertificateResolver.class.getName());
    }

    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] ^ 0x62);
        }
        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 -> 84;
                    case 1 -> 93;
                    case 2 -> 35;
                    case 3 -> 77;
                    case 4 -> 37;
                    case 5 -> 10;
                    default -> 98;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

