/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.ObjectNotFoundException
 *  com.l7tech.objectmodel.PersistentEntity
 */
package com.l7tech.server.security.cert;

import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.ObjectNotFoundException;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.server.security.cert.SslContextInitializer;
import com.l7tech.server.security.keystore.SsgKeyStoreManager;
import java.net.Socket;
import java.security.KeyStoreException;
import java.security.Principal;
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.X509Certificate;
import java.util.logging.Level;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.X509ExtendedKeyManager;
import javax.security.auth.x500.X500Principal;

class ag
extends X509ExtendedKeyManager {
    private final SsgKeyStoreManager a;
    private static final String[] b;

    private ag(SsgKeyStoreManager ssgKeyStoreManager) {
        this.a = ssgKeyStoreManager;
    }

    /*
     * Exception decompiling
     */
    @Override
    public String[] getClientAliases(String var1_1, Principal[] var2_2) {
        /*
         * This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
         * 
         * org.benf.cfr.reader.util.ConfusedCFRException: Started 6 blocks at once
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.getStartingBlocks(Op04StructuredStatement.java:412)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:487)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op03SimpleStatement.createInitialStructuredBlock(Op03SimpleStatement.java:736)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:850)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:278)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:201)
         *     at org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:94)
         *     at org.benf.cfr.reader.entities.Method.analyse(Method.java:531)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:1055)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:942)
         *     at org.benf.cfr.reader.Driver.doJarVersionTypes(Driver.java:257)
         *     at org.benf.cfr.reader.Driver.doJar(Driver.java:139)
         *     at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:76)
         *     at org.benf.cfr.reader.Main.main(Main.java:54)
         */
        throw new IllegalStateException("Decompilation failed");
    }

    private boolean a(Principal[] principalArray, X500Principal x500Principal) {
        boolean bl2 = false;
        if (principalArray == null) {
            bl2 = true;
        } else {
            for (Principal principal : principalArray) {
                if (x500Principal.equals(principal)) {
                    bl2 = true;
                    break;
                }
                if (!SslContextInitializer.a.isLoggable(Level.FINEST)) continue;
                String[] stringArray = b;
                SslContextInitializer.a.log(Level.FINEST, stringArray[14] + principal.getName() + stringArray[12] + x500Principal.getName());
            }
        }
        return bl2;
    }

    @Override
    public String chooseClientAlias(String[] stringArray, Principal[] principalArray, Socket socket) {
        return this.a(stringArray, principalArray);
    }

    @Override
    public String chooseEngineClientAlias(String[] stringArray, Principal[] principalArray, SSLEngine sSLEngine) {
        return this.a(stringArray, principalArray);
    }

    private String a(String[] stringArray, Principal[] principalArray) {
        String string = null;
        if (stringArray != null) {
            for (String string2 : stringArray) {
                String[] stringArray2 = this.getClientAliases(string2, principalArray);
                if (stringArray2 == null || stringArray2.length <= 0 || stringArray2[0] == null) continue;
                string = stringArray2[0];
                break;
            }
        }
        return string;
    }

    @Override
    public X509Certificate[] getCertificateChain(String string) {
        try {
            if (SslContextInitializer.a.isLoggable(Level.FINE)) {
                SslContextInitializer.a.log(Level.FINE, b[15] + string + b[5]);
            }
        }
        catch (ObjectNotFoundException objectNotFoundException) {
            throw ag.a((Exception)((Object)objectNotFoundException));
        }
        try {
            return this.a.lookupKeyByKeyAlias(string, PersistentEntity.DEFAULT_GOID).getCertificateChain();
        }
        catch (ObjectNotFoundException objectNotFoundException) {
            String[] stringArray = b;
            SslContextInitializer.a.log(Level.INFO, stringArray[7] + string + stringArray[17]);
        }
        catch (FindException findException) {
            String[] stringArray = b;
            SslContextInitializer.a.log(Level.WARNING, stringArray[16], findException);
        }
        catch (KeyStoreException keyStoreException) {
            SslContextInitializer.a.log(Level.WARNING, b[1], keyStoreException);
        }
        return null;
    }

    @Override
    public PrivateKey getPrivateKey(String string) {
        try {
            if (SslContextInitializer.a.isLoggable(Level.FINE)) {
                SslContextInitializer.a.log(Level.FINE, b[11] + string + b[6]);
            }
        }
        catch (ObjectNotFoundException objectNotFoundException) {
            throw ag.a((Exception)((Object)objectNotFoundException));
        }
        try {
            return this.a.lookupKeyByKeyAlias(string, PersistentEntity.DEFAULT_GOID).getPrivateKey();
        }
        catch (ObjectNotFoundException objectNotFoundException) {
            String[] stringArray = b;
            SslContextInitializer.a.log(Level.INFO, stringArray[4] + string + stringArray[13]);
        }
        catch (UnrecoverableKeyException unrecoverableKeyException) {
            String[] stringArray = b;
            SslContextInitializer.a.log(Level.WARNING, stringArray[3], unrecoverableKeyException);
        }
        catch (FindException findException) {
            String[] stringArray = b;
            SslContextInitializer.a.log(Level.WARNING, stringArray[2], findException);
        }
        catch (KeyStoreException keyStoreException) {
            SslContextInitializer.a.log(Level.WARNING, b[2], keyStoreException);
        }
        return null;
    }

    @Override
    public String[] getServerAliases(String string, Principal[] principalArray) {
        return this.getClientAliases(string, principalArray);
    }

    @Override
    public String chooseServerAlias(String string, Principal[] principalArray, Socket socket) {
        return this.chooseClientAlias(new String[]{string}, principalArray, socket);
    }

    @Override
    public String chooseEngineServerAlias(String string, Principal[] principalArray, SSLEngine sSLEngine) {
        return this.chooseEngineClientAlias(new String[]{string}, principalArray, sSLEngine);
    }

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[18];
                var3_1 = 0;
                var2_2 = "\u0003\u0005 \u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx;=\u0017\u001a#E1;9\u0011\u000bj@091\u000b@\u001a\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx(*\f\u0018+W=x3\u0000\u0017d\u001a\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx(*\f\u0018+W=x3\u0000\u0017d0\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx(*\f\u0018+W=x3\u0000\u0017j\u000b67,E\b%V6<x\u0003\u00018\u0003941\u0004\u001dj\u0004\u0002\u007fv\u0002\u007fv6\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx;=\u0017\u001a#E1;9\u0011\u000bj@091\u000bNbM7,x\u0003\u0001?M<x>\n\u001cjB419\u0016Nm\u001d\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx;4\f\u000b$Wx94\f\u000f9F+v\u0017\u001f=\u0011\u001a#M?x;\t\u0007/M,x9\t\u0007+P=+x\u001d\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx;4\f\u000b$Wx94\f\u000f9F+v\u001f\u001f=\u0011\u001a#M?x(\u0017\u0007<B,=x\u000e\u000b3\u0003>7*E\u000f&J9+xB\u0003xwE\u0003\u007fqK\u0019\b*\f\u0000)J(94E\n%F+x6\n\u001ajN9,;\rN%\u001f=\u0011\u001a#M?x;\u0000\u001c>J>1;\u0004\u001a/\u0003;09\f\u0000jE7*x\u0004\u0002#B+x\u007f";
                var4_3 = "\u0003\u0005 \u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx;=\u0017\u001a#E1;9\u0011\u000bj@091\u000b@\u001a\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx(*\f\u0018+W=x3\u0000\u0017d\u001a\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx(*\f\u0018+W=x3\u0000\u0017d0\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx(*\f\u0018+W=x3\u0000\u0017j\u000b67,E\b%V6<x\u0003\u00018\u0003941\u0004\u001dj\u0004\u0002\u007fv\u0002\u007fv6\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx;=\u0017\u001a#E1;9\u0011\u000bj@091\u000bNbM7,x\u0003\u0001?M<x>\n\u001cjB419\u0016Nm\u001d\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx;4\f\u000b$Wx94\f\u000f9F+v\u0017\u001f=\u0011\u001a#M?x;\t\u0007/M,x9\t\u0007+P=+x\u001d\u001d*\u0017\u00018\u0003?=,\u0011\u0007$Dx;4\f\u000b$Wx94\f\u000f9F+v\u001f\u001f=\u0011\u001a#M?x(\u0017\u0007<B,=x\u000e\u000b3\u0003>7*E\u000f&J9+xB\u0003xwE\u0003\u007fqK\u0019\b*\f\u0000)J(94E\n%F+x6\n\u001ajN9,;\rN%\u001f=\u0011\u001a#M?x;\u0000\u001c>J>1;\u0004\u001a/\u0003;09\f\u0000jE7*x\u0004\u0002#B+x\u007f".length();
                var1_4 = 2;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ag.a(v0, ag.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u0016!\u001c\n3\b46'\u001a\f/Os06\u001c\u0011(N:02\u001a\u0000aK;2:\u0000K\u0003tz@";
                    var4_3 = "\u0016!\u001c\n3\b46'\u001a\f/Os06\u001c\u0011(N:02\u001a\u0000aK;2:\u0000K\u0003tz@".length();
                    var1_4 = 32;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 45;
                        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++] = ag.a(v0, ag.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;
            }
        }
        ag.b = var5;
    }

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

