/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.transport.jms.JmsConnection
 *  com.l7tech.gateway.common.transport.jms.TibcoEmsConstants$TibjmsSSL
 *  com.l7tech.util.ExceptionUtils
 *  com.tibco.tibjms.TibjmsConnectionFactory
 *  javax.jms.ConnectionFactory
 */
package com.l7tech.server.transport.jms.prov;

import com.l7tech.gateway.common.transport.jms.JmsConnection;
import com.l7tech.gateway.common.transport.jms.TibcoEmsConstants;
import com.l7tech.server.transport.jms.ConnectionFactoryCustomizer;
import com.l7tech.server.transport.jms.JmsConfigException;
import com.l7tech.util.ExceptionUtils;
import com.tibco.tibjms.TibjmsConnectionFactory;
import java.security.cert.X509Certificate;
import java.util.Hashtable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jms.ConnectionFactory;
import javax.naming.Context;

public class TibcoConnectionFactoryCustomizer
implements ConnectionFactoryCustomizer {
    private static final Logger a;
    private static final String[] b;

    @Override
    public void configureConnectionFactory(JmsConnection jmsConnection, ConnectionFactory connectionFactory, Context context) throws JmsConfigException {
        block31: {
            try {
                try {
                    if (a.isLoggable(Level.FINE)) {
                        a.log(Level.FINE, b[1]);
                    }
                }
                catch (Exception exception) {
                    throw TibcoConnectionFactoryCustomizer.a(exception);
                }
                Hashtable<?, ?> hashtable = context.getEnvironment();
                if (!(connectionFactory instanceof TibjmsConnectionFactory)) break block31;
                TibjmsConnectionFactory tibjmsConnectionFactory = (TibjmsConnectionFactory)connectionFactory;
                Object v2 = hashtable.get(TibcoEmsConstants.TibjmsSSL.AUTH_ONLY);
                try {
                    if (v2 != null) {
                        tibjmsConnectionFactory.setSSLAuthOnly((Boolean)v2);
                    }
                }
                catch (Exception exception) {
                    throw TibcoConnectionFactoryCustomizer.a(exception);
                }
                v2 = hashtable.get(TibcoEmsConstants.TibjmsSSL.DEBUG_TRACE);
                try {
                    if (v2 != null) {
                        tibjmsConnectionFactory.setSSLDebugTrace((Boolean)v2);
                    }
                }
                catch (Exception exception) {
                    throw TibcoConnectionFactoryCustomizer.a(exception);
                }
                v2 = hashtable.get(TibcoEmsConstants.TibjmsSSL.ENABLE_VERIFY_HOST);
                try {
                    if (v2 != null) {
                        tibjmsConnectionFactory.setSSLEnableVerifyHost((Boolean)v2);
                    }
                }
                catch (Exception exception) {
                    throw TibcoConnectionFactoryCustomizer.a(exception);
                }
                v2 = hashtable.get(TibcoEmsConstants.TibjmsSSL.ENABLE_VERIFY_HOST_NAME);
                try {
                    if (v2 != null) {
                        tibjmsConnectionFactory.setSSLEnableVerifyHostName((Boolean)v2);
                    }
                }
                catch (Exception exception) {
                    throw TibcoConnectionFactoryCustomizer.a(exception);
                }
                v2 = hashtable.get(TibcoEmsConstants.TibjmsSSL.EXPECTED_HOST_NAME);
                try {
                    if (v2 != null) {
                        tibjmsConnectionFactory.setSSLExpectedHostName((String)v2);
                    }
                }
                catch (Exception exception) {
                    throw TibcoConnectionFactoryCustomizer.a(exception);
                }
                v2 = hashtable.get(TibcoEmsConstants.TibjmsSSL.IDENTITY);
                try {
                    if (v2 != null) {
                        tibjmsConnectionFactory.setSSLIdentity((byte[])v2);
                        tibjmsConnectionFactory.setSSLIdentityEncoding(b[0]);
                    }
                }
                catch (Exception exception) {
                    throw TibcoConnectionFactoryCustomizer.a(exception);
                }
                v2 = hashtable.get(TibcoEmsConstants.TibjmsSSL.PASSWORD);
                try {
                    if (v2 != null) {
                        tibjmsConnectionFactory.setSSLPassword((String)v2);
                    }
                }
                catch (Exception exception) {
                    throw TibcoConnectionFactoryCustomizer.a(exception);
                }
                v2 = hashtable.get(TibcoEmsConstants.TibjmsSSL.TRACE);
                try {
                    if (v2 != null) {
                        tibjmsConnectionFactory.setSSLTrace((Boolean)v2);
                    }
                }
                catch (Exception exception) {
                    throw TibcoConnectionFactoryCustomizer.a(exception);
                }
                v2 = hashtable.get(TibcoEmsConstants.TibjmsSSL.TRUSTED_CERTIFICATES);
                if (v2 != null) {
                    List list = (List)v2;
                    for (X509Certificate x509Certificate : list) {
                        String[] stringArray = b;
                        tibjmsConnectionFactory.setSSLTrustedCertificate(x509Certificate.getEncoded(), stringArray[2]);
                    }
                }
            }
            catch (Exception exception) {
                throw new JmsConfigException(b[3] + ExceptionUtils.getMessage((Throwable)exception), exception);
            }
        }
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[4];
                var3_1 = 0;
                var2_2 = "G9t\u007f2<\u001fT\u001dYJjiIe\u001bYK#mSy\u001cROwgSyRQM`zSe\u000b\u0019";
                var4_3 = "G9t\u007f2<\u001fT\u001dYJjiIe\u001bYK#mSy\u001cROwgSyRQM`zSe\u000b\u0019".length();
                var1_4 = 6;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = TibcoConnectionFactoryCustomizer.a(v0, TibcoConnectionFactoryCustomizer.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "J.|'K\u0019\\Zh7Fa\u0005H\\}bWg\u0005I\u0015yxK`\u000eMAsxK.\rOVnxWwK\u0014\u0015";
                    var4_3 = "J.|'K\u0019\\Zh7Fa\u0005H\\}bWg\u0005I\u0015yxK`\u000eMAsxK.\rOVnxWwK\u0014\u0015".length();
                    var1_4 = 3;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 40;
                        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++] = TibcoConnectionFactoryCustomizer.a(v0, TibcoConnectionFactoryCustomizer.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;
            }
        }
        TibcoConnectionFactoryCustomizer.b = var5;
        TibcoConnectionFactoryCustomizer.a = Logger.getLogger(TibcoConnectionFactoryCustomizer.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] ^ 0xD);
        }
        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 -> 38;
                    case 1 -> 67;
                    case 2 -> 6;
                    case 3 -> 29;
                    case 4 -> 50;
                    case 5 -> 63;
                    default -> 13;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

