/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.keystore.SsgKeyEntry
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.ObjectNotFoundException
 *  com.l7tech.policy.assertion.PrivateKeyable
 *  com.l7tech.security.xml.SignerInfo
 *  com.l7tech.util.ExceptionUtils
 *  org.jetbrains.annotations.NotNull
 *  org.springframework.beans.factory.BeanFactory
 */
package com.l7tech.server.policy.assertion;

import com.l7tech.gateway.common.security.keystore.SsgKeyEntry;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.ObjectNotFoundException;
import com.l7tech.policy.assertion.PrivateKeyable;
import com.l7tech.security.xml.SignerInfo;
import com.l7tech.server.DefaultKey;
import com.l7tech.server.security.keystore.SsgKeyStoreManager;
import com.l7tech.util.ExceptionUtils;
import java.io.IOException;
import java.security.KeyStoreException;
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.X509Certificate;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.BeanFactory;

public class ServerAssertionUtils {
    private static final String[] a;

    @NotNull
    public static SignerInfo getSignerInfo(BeanFactory beanFactory, Object object) throws KeyStoreException {
        SsgKeyEntry ssgKeyEntry;
        try {
            Object object2;
            if (object instanceof PrivateKeyable && !(object2 = (PrivateKeyable)object).isUsesDefaultKeyStore()) {
                Goid goid = object2.getNonDefaultKeystoreId();
                String string = object2.getKeyAlias();
                String[] stringArray = a;
                SsgKeyStoreManager ssgKeyStoreManager = (SsgKeyStoreManager)beanFactory.getBean(stringArray[3], SsgKeyStoreManager.class);
                SsgKeyEntry ssgKeyEntry2 = ssgKeyStoreManager.lookupKeyByKeyAlias(string, goid);
                X509Certificate[] x509CertificateArray = ssgKeyEntry2.getCertificateChain();
                PrivateKey privateKey = ssgKeyEntry2.getPrivateKey();
                return new SignerInfo(privateKey, x509CertificateArray);
            }
            String[] stringArray = a;
            object2 = (DefaultKey)beanFactory.getBean(stringArray[0], DefaultKey.class);
            ssgKeyEntry = object2.getClientSslInfo();
        }
        catch (IOException iOException) {
            String[] stringArray = a;
            throw new KeyStoreException(stringArray[6] + ExceptionUtils.getMessage((Throwable)iOException), iOException);
        }
        catch (ObjectNotFoundException objectNotFoundException) {
            String[] stringArray = a;
            throw new KeyStoreException(stringArray[1] + ExceptionUtils.getMessage((Throwable)objectNotFoundException), objectNotFoundException);
        }
        catch (FindException findException) {
            String[] stringArray = a;
            throw new KeyStoreException(stringArray[5] + ExceptionUtils.getMessage((Throwable)findException), findException);
        }
        catch (UnrecoverableKeyException unrecoverableKeyException) {
            throw new KeyStoreException(a[5] + ExceptionUtils.getMessage((Throwable)unrecoverableKeyException), unrecoverableKeyException);
        }
        if (ssgKeyEntry == null) {
            ServerAssertionUtils.a(0);
        }
        return ssgKeyEntry;
    }

    public static boolean isPreferredSigner(Object object) {
        boolean bl2 = false;
        if (object instanceof PrivateKeyable) {
            boolean bl3;
            PrivateKeyable privateKeyable = (PrivateKeyable)object;
            try {
                bl3 = !privateKeyable.isUsesDefaultKeyStore();
            }
            catch (IllegalStateException illegalStateException) {
                throw ServerAssertionUtils.a(illegalStateException);
            }
            bl2 = bl3;
        }
        return bl2;
    }

    private static /* synthetic */ void a(int n2) {
        String[] stringArray = a;
        throw new IllegalStateException(String.format(stringArray[4], stringArray[2], stringArray[7]));
    }

    private static IllegalStateException a(IllegalStateException illegalStateException) {
        return illegalStateException;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[8];
                var3_1 = 0;
                var2_2 = "\u0012~ZY\u0002P6=~E85zR\u001f\u0003\u001c$\u001fuX\u0018\u0007N+\u0000zH]WW'\u000f;ZW\u0005\u001c-\u0003o^W\u0002R&VvYK\u0004]%\u0013;X]\u0014S0\u0017oUW\u0019\u0006b7\u0015tQ\u0017\u001b\u000b6\u0013xT\u0017\u0004Y0\u0000~N\u0017\u0007S.\u001fxE\u0017\u0016O1\u0013iHQ\u0018Rm%~NN\u0012N\u0003\u0005hYJ\u0003U-\u0018NHQ\u001bO\u0012\u0005h[s\u0012E\u0011\u0002tN]:],\u0017|YJ*6USL9I.\u001a;Q]\u0003T-\u0012;\u0019KY\u00191VvIK\u0003\u001c,\u0019o\u001cJ\u0012H7\u0004u\u001cV\u0002P.95zR\u001f\u0003\u001c0\u0013zX\u0018\u0003T'VpYA\u0004H-\u0004~\u001c^\u0018Nb\u0019nHZ\u0018I,\u0012;Q]\u0004O#\u0011~\u001c\\\u0012_-\u0004zHQ\u0018RxV";
                var4_3 = "\u0012~ZY\u0002P6=~E85zR\u001f\u0003\u001c$\u001fuX\u0018\u0007N+\u0000zH]WW'\u000f;ZW\u0005\u001c-\u0003o^W\u0002R&VvYK\u0004]%\u0013;X]\u0014S0\u0017oUW\u0019\u0006b7\u0015tQ\u0017\u001b\u000b6\u0013xT\u0017\u0004Y0\u0000~N\u0017\u0007S.\u001fxE\u0017\u0016O1\u0013iHQ\u0018Rm%~NN\u0012N\u0003\u0005hYJ\u0003U-\u0018NHQ\u001bO\u0012\u0005h[s\u0012E\u0011\u0002tN]:],\u0017|YJ*6USL9I.\u001a;Q]\u0003T-\u0012;\u0019KY\u00191VvIK\u0003\u001c,\u0019o\u001cJ\u0012H7\u0004u\u001cV\u0002P.95zR\u001f\u0003\u001c0\u0013zX\u0018\u0003T'VpYA\u0004H-\u0004~\u001c^\u0018Nb\u0019nHZ\u0018I,\u0012;Q]\u0004O#\u0011~\u001c\\\u0012_-\u0004zHQ\u0018RxV".length();
                var1_4 = 10;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ServerAssertionUtils.a(v0, ServerAssertionUtils.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "#lD\t\u0015\n&\u0005lN\u000e\u0015B1@fOW\u0012^;\u0012h\nH\u000eXt\u000fx^L\u000e_:\u0004-GK\u0012Y5\u0007h\nJ\u0004I;\u0012l^G\u000eDn@\r\u0007h^}\bM:\u0005\u007fc@\u0007E";
                    var4_3 = "#lD\t\u0015\n&\u0005lN\u000e\u0015B1@fOW\u0012^;\u0012h\nH\u000eXt\u000fx^L\u000e_:\u0004-GK\u0012Y5\u0007h\nJ\u0004I;\u0012l^G\u000eDn@\r\u0007h^}\bM:\u0005\u007fc@\u0007E".length();
                    var1_4 = 57;
                    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++] = ServerAssertionUtils.a(v0, ServerAssertionUtils.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;
            }
        }
        ServerAssertionUtils.a = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x5A);
        }
        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 -> 110;
                    case 1 -> 3;
                    case 2 -> 36;
                    case 3 -> 32;
                    case 4 -> 111;
                    case 5 -> 36;
                    default -> 90;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

