/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.mime.NoSuchPartException
 *  com.l7tech.gateway.common.audit.AssertionMessages
 *  com.l7tech.gateway.common.audit.Audit
 *  com.l7tech.gateway.common.audit.AuditDetailMessage
 *  com.l7tech.gateway.common.audit.LoggingAudit
 *  com.l7tech.gateway.common.audit.MessageProcessingMessages
 *  com.l7tech.gateway.common.audit.Messages$M
 *  com.l7tech.message.Message
 *  com.l7tech.message.MessageRole
 *  com.l7tech.message.SecurityKnob
 *  com.l7tech.policy.assertion.IdentityTarget
 *  com.l7tech.policy.assertion.credential.LoginCredentials
 *  com.l7tech.security.token.EncryptedKey
 *  com.l7tech.security.token.KerberosSecurityToken
 *  com.l7tech.security.token.KerberosSigningSecurityToken
 *  com.l7tech.security.token.ParsedElement
 *  com.l7tech.security.token.SecurityContextToken
 *  com.l7tech.security.token.SecurityToken
 *  com.l7tech.security.token.SignatureConfirmation$Status
 *  com.l7tech.security.token.SignedElement
 *  com.l7tech.security.token.SigningSecurityToken
 *  com.l7tech.security.token.XmlSecurityToken
 *  com.l7tech.security.xml.KeyInfoDetails
 *  com.l7tech.security.xml.SecurityTokenResolver
 *  com.l7tech.security.xml.decorator.DecorationRequirements
 *  com.l7tech.security.xml.decorator.DecorationRequirements$SecureConversationSession
 *  com.l7tech.security.xml.decorator.WssDecorator$DecorationResult
 *  com.l7tech.security.xml.processor.BadSecurityContextException
 *  com.l7tech.security.xml.processor.ProcessorException
 *  com.l7tech.security.xml.processor.ProcessorResult
 *  com.l7tech.security.xml.processor.ProcessorValidationException
 *  com.l7tech.security.xml.processor.SecurityContext
 *  com.l7tech.security.xml.processor.SecurityContextFinder
 *  com.l7tech.security.xml.processor.WssProcessorErrorHandler
 *  com.l7tech.security.xml.processor.WssProcessorImpl
 *  com.l7tech.util.ArrayUtils
 *  com.l7tech.util.Config
 *  com.l7tech.util.ConfigFactory
 *  com.l7tech.util.ExceptionUtils
 *  com.l7tech.util.Functions
 *  com.l7tech.util.Functions$Unary
 *  com.l7tech.util.InvalidDocumentFormatException
 *  com.l7tech.util.Pair
 *  com.l7tech.util.SoapConstants
 *  com.l7tech.util.TimeUnit
 *  com.l7tech.xml.InvalidDocumentSignatureException
 */
package com.l7tech.server.util;

import com.l7tech.common.mime.NoSuchPartException;
import com.l7tech.gateway.common.audit.AssertionMessages;
import com.l7tech.gateway.common.audit.Audit;
import com.l7tech.gateway.common.audit.AuditDetailMessage;
import com.l7tech.gateway.common.audit.LoggingAudit;
import com.l7tech.gateway.common.audit.MessageProcessingMessages;
import com.l7tech.gateway.common.audit.Messages;
import com.l7tech.message.Message;
import com.l7tech.message.MessageRole;
import com.l7tech.message.SecurityKnob;
import com.l7tech.policy.assertion.IdentityTarget;
import com.l7tech.policy.assertion.credential.LoginCredentials;
import com.l7tech.security.token.EncryptedKey;
import com.l7tech.security.token.KerberosSecurityToken;
import com.l7tech.security.token.KerberosSigningSecurityToken;
import com.l7tech.security.token.ParsedElement;
import com.l7tech.security.token.SecurityContextToken;
import com.l7tech.security.token.SecurityToken;
import com.l7tech.security.token.SignatureConfirmation;
import com.l7tech.security.token.SignedElement;
import com.l7tech.security.token.SigningSecurityToken;
import com.l7tech.security.token.XmlSecurityToken;
import com.l7tech.security.xml.KeyInfoDetails;
import com.l7tech.security.xml.SecurityTokenResolver;
import com.l7tech.security.xml.decorator.DecorationRequirements;
import com.l7tech.security.xml.decorator.WssDecorator;
import com.l7tech.security.xml.processor.BadSecurityContextException;
import com.l7tech.security.xml.processor.ProcessorException;
import com.l7tech.security.xml.processor.ProcessorResult;
import com.l7tech.security.xml.processor.ProcessorValidationException;
import com.l7tech.security.xml.processor.SecurityContext;
import com.l7tech.security.xml.processor.SecurityContextFinder;
import com.l7tech.security.xml.processor.WssProcessorErrorHandler;
import com.l7tech.security.xml.processor.WssProcessorImpl;
import com.l7tech.server.message.AuthenticationContext;
import com.l7tech.server.secureconversation.SecureConversationSession;
import com.l7tech.server.util.b;
import com.l7tech.server.util.u;
import com.l7tech.server.util.v;
import com.l7tech.server.util.w;
import com.l7tech.server.util.y;
import com.l7tech.util.ArrayUtils;
import com.l7tech.util.Config;
import com.l7tech.util.ConfigFactory;
import com.l7tech.util.ExceptionUtils;
import com.l7tech.util.Functions;
import com.l7tech.util.InvalidDocumentFormatException;
import com.l7tech.util.Pair;
import com.l7tech.util.SoapConstants;
import com.l7tech.util.TimeUnit;
import com.l7tech.xml.InvalidDocumentSignatureException;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

public class WSSecurityProcessorUtils {
    private static final Logger a;
    private static final AtomicReference<y> b;
    private static final String[] c;

    public static ProcessorResult getWssResults(Message message, String string, SecurityTokenResolver securityTokenResolver, Audit audit) {
        return WSSecurityProcessorUtils.getWssResults(message, string, securityTokenResolver, null, audit, null);
    }

    /*
     * Loose catch block
     */
    public static ProcessorResult getWssResults(Message message, String string, SecurityTokenResolver securityTokenResolver, SecurityContextFinder securityContextFinder, Audit audit, Functions.Unary<Boolean, Throwable> unary) {
        SecurityKnob securityKnob = (SecurityKnob)message.getKnob(SecurityKnob.class);
        if (securityKnob != null) {
            ProcessorResult processorResult = securityKnob.getProcessorResult();
            try {
                if (null != processorResult) {
                    return processorResult;
                }
            }
            catch (ProcessorValidationException processorValidationException) {
                throw WSSecurityProcessorUtils.a((Exception)((Object)processorValidationException));
            }
        }
        try {
            boolean bl22;
            block23: {
                boolean bl3;
                block22: {
                    boolean bl4 = message.isSoap();
                    if (!bl4) break block22;
                    try {
                        block24: {
                            if (!message.getSoapKnob().isSecurityHeaderPresent()) break block22;
                            break block24;
                            catch (ProcessorValidationException processorValidationException) {
                                throw WSSecurityProcessorUtils.a((Exception)((Object)processorValidationException));
                            }
                        }
                        bl3 = true;
                        break block23;
                    }
                    catch (ProcessorValidationException processorValidationException) {
                        throw WSSecurityProcessorUtils.a((Exception)((Object)processorValidationException));
                    }
                }
                bl3 = bl22 = false;
            }
            if (bl22) {
                SecurityContextFinder securityContextFinder2;
                WssProcessorImpl wssProcessorImpl;
                WssProcessorImpl wssProcessorImpl2 = new WssProcessorImpl(message);
                try {
                    wssProcessorImpl2.setSecurityTokenResolver((SecurityTokenResolver)wssProcessorImpl2.contextual(securityTokenResolver));
                    wssProcessorImpl = wssProcessorImpl2;
                    securityContextFinder2 = securityContextFinder != null ? securityContextFinder : WSSecurityProcessorUtils.a(message);
                }
                catch (ProcessorValidationException processorValidationException) {
                    throw WSSecurityProcessorUtils.a((Exception)((Object)processorValidationException));
                }
                wssProcessorImpl.setSecurityContextFinder(securityContextFinder2);
                y y2 = WSSecurityProcessorUtils.a();
                wssProcessorImpl2.setSignedAttachmentSizeLimit(y2.b);
                wssProcessorImpl2.setRejectOnMustUnderstand(y2.c);
                wssProcessorImpl2.setPermitMultipleTimestampSignatures(y2.d);
                wssProcessorImpl2.setPermitUnknownBinarySecurityTokens(y2.e);
                wssProcessorImpl2.setStrictSignatureConfirmationValidation(y2.f);
                wssProcessorImpl2.setErrorHandler((WssProcessorErrorHandler)new b(audit));
                ProcessorResult processorResult = wssProcessorImpl2.processMessage();
                message.getSecurityKnob().setProcessorResult(processorResult);
                return processorResult;
            }
        }
        catch (ProcessorValidationException processorValidationException) {
            WSSecurityProcessorUtils.a(audit, unary, string, processorValidationException, true);
        }
        catch (InvalidDocumentSignatureException invalidDocumentSignatureException) {
            WSSecurityProcessorUtils.a(audit, unary, string, invalidDocumentSignatureException, true);
        }
        catch (BadSecurityContextException badSecurityContextException) {
            WSSecurityProcessorUtils.a(audit, unary, string, badSecurityContextException, true);
        }
        catch (IOException iOException) {
            WSSecurityProcessorUtils.a(audit, unary, string, iOException, true);
        }
        catch (GeneralSecurityException generalSecurityException) {
            WSSecurityProcessorUtils.a(audit, unary, string, generalSecurityException, true);
        }
        catch (InvalidDocumentFormatException invalidDocumentFormatException) {
            WSSecurityProcessorUtils.a(audit, unary, string, invalidDocumentFormatException, true);
        }
        catch (ProcessorException processorException) {
            WSSecurityProcessorUtils.a(audit, unary, string, processorException, true);
        }
        catch (SAXException sAXException) {
            WSSecurityProcessorUtils.a(audit, unary, string, sAXException, true);
        }
        catch (NoSuchPartException noSuchPartException) {
            WSSecurityProcessorUtils.a(audit, unary, string, noSuchPartException, true);
        }
        catch (Exception exception) {
            WSSecurityProcessorUtils.a(audit, unary, string, exception, false);
        }
        return null;
    }

    private static void a(Audit audit, Functions.Unary<Boolean, Throwable> unary, String string, Throwable throwable, boolean bl2) {
        block7: {
            Throwable throwable2;
            String[] stringArray;
            Messages.M m2;
            Audit audit2;
            block9: {
                block8: {
                    boolean bl3 = false;
                    if (unary != null) {
                        bl3 = (Boolean)unary.call((Object)throwable);
                    }
                    try {
                        try {
                            try {
                                if (bl3 || audit == null) break block7;
                            }
                            catch (IllegalStateException illegalStateException) {
                                throw WSSecurityProcessorUtils.a(illegalStateException);
                            }
                            audit2 = audit;
                            m2 = MessageProcessingMessages.MESSAGE_VAR_BAD_WSS;
                            String[] stringArray2 = new String[2];
                            stringArray2[0] = string;
                            stringArray = stringArray2;
                            stringArray2[1] = ExceptionUtils.getMessage((Throwable)throwable);
                            if (!bl2) break block8;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw WSSecurityProcessorUtils.a(illegalStateException);
                        }
                        throwable2 = ExceptionUtils.getDebugException((Throwable)throwable);
                        break block9;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw WSSecurityProcessorUtils.a(illegalStateException);
                    }
                }
                throwable2 = throwable;
            }
            audit2.logAndAudit((AuditDetailMessage)m2, stringArray, throwable2);
        }
    }

    public static boolean isValidSingleSigner(AuthenticationContext authenticationContext, ProcessorResult processorResult, ParsedElement[] parsedElementArray, boolean bl2, Message message, AuthenticationContext authenticationContext2, Audit audit) {
        boolean bl3;
        List list;
        SignedElement[] signedElementArray = processorResult.getElementsThatWereSigned();
        try {
            list = authenticationContext == null ? null : authenticationContext.getCredentials();
        }
        catch (IllegalStateException illegalStateException) {
            throw WSSecurityProcessorUtils.a(illegalStateException);
        }
        List list2 = list;
        XmlSecurityToken xmlSecurityToken = WSSecurityProcessorUtils.a(authenticationContext, processorResult, bl2, new u(message, list2, authenticationContext2, bl2, audit), audit);
        try {
            bl3 = xmlSecurityToken != null;
        }
        catch (IllegalStateException illegalStateException) {
            throw WSSecurityProcessorUtils.a(illegalStateException);
        }
        boolean bl4 = bl3;
        List list3 = Functions.map(Arrays.asList(signedElementArray), (Functions.Unary)new v());
        for (ParsedElement parsedElement : parsedElementArray) {
            if (list3.contains(parsedElement.asElement())) continue;
            bl4 = false;
            break;
        }
        return bl4;
    }

    private static boolean a(SigningSecurityToken signingSecurityToken, Message message, AuthenticationContext authenticationContext, boolean bl2, Audit audit) {
        block31: {
            Object object;
            String string;
            block28: {
                string = null;
                if (signingSecurityToken instanceof EncryptedKey) {
                    object = (EncryptedKey)signingSecurityToken;
                    string = object.getEncryptedKeySHA1();
                }
                object = null;
                if (signingSecurityToken instanceof SecurityContextToken) {
                    SecurityContextToken securityContextToken = (SecurityContextToken)signingSecurityToken;
                    object = securityContextToken.getContextIdentifier();
                }
                try {
                    try {
                        if (string != null || object != null) break block28;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw WSSecurityProcessorUtils.a(illegalStateException);
                    }
                    return false;
                }
                catch (IllegalStateException illegalStateException) {
                    throw WSSecurityProcessorUtils.a(illegalStateException);
                }
            }
            boolean bl3 = false;
            List list = message.getSecurityKnob().getAllDecorationResults();
            for (WssDecorator.DecorationResult decorationResult : list) {
                block29: {
                    bl3 = true;
                    String string2 = decorationResult.getEncryptedKeySha1();
                    try {
                        try {
                            if (string2 == null || !string2.equals(string)) break block29;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw WSSecurityProcessorUtils.a(illegalStateException);
                        }
                        return true;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw WSSecurityProcessorUtils.a(illegalStateException);
                    }
                }
                String string3 = decorationResult.getWsscSecurityContextId();
                try {
                    try {
                        if (string3 == null || !string3.equals(object)) continue;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw WSSecurityProcessorUtils.a(illegalStateException);
                    }
                    return true;
                }
                catch (IllegalStateException illegalStateException) {
                    throw WSSecurityProcessorUtils.a(illegalStateException);
                }
            }
            if (!bl3) {
                XmlSecurityToken xmlSecurityToken;
                WssDecorator.DecorationResult decorationResult;
                block30: {
                    xmlSecurityToken = WSSecurityProcessorUtils.a(authenticationContext, message.getSecurityKnob().getProcessorResult(), bl2, null, audit);
                    if (xmlSecurityToken instanceof EncryptedKey) {
                        decorationResult = (EncryptedKey)xmlSecurityToken;
                        try {
                            try {
                                if (!decorationResult.isPossessionProved() || !decorationResult.getEncryptedKeySHA1().equals(string)) break block30;
                            }
                            catch (IllegalStateException illegalStateException) {
                                throw WSSecurityProcessorUtils.a(illegalStateException);
                            }
                            return true;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw WSSecurityProcessorUtils.a(illegalStateException);
                        }
                    }
                }
                if (xmlSecurityToken instanceof SecurityContextToken) {
                    decorationResult = (SecurityContextToken)xmlSecurityToken;
                    try {
                        try {
                            try {
                                if (!decorationResult.isPossessionProved() || decorationResult.getContextIdentifier() == null) break block31;
                            }
                            catch (IllegalStateException illegalStateException) {
                                throw WSSecurityProcessorUtils.a(illegalStateException);
                            }
                            if (!decorationResult.getContextIdentifier().equals(object)) break block31;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw WSSecurityProcessorUtils.a(illegalStateException);
                        }
                        return true;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw WSSecurityProcessorUtils.a(illegalStateException);
                    }
                }
            }
        }
        return false;
    }

    private static XmlSecurityToken a(AuthenticationContext authenticationContext, ProcessorResult processorResult, boolean bl2, Functions.Unary<Boolean, SigningSecurityToken> unary, Audit audit) {
        Object[] objectArray;
        List list;
        if (audit == null) {
            audit = new LoggingAudit(a);
        }
        SigningSecurityToken signingSecurityToken = null;
        try {
            list = authenticationContext == null ? null : authenticationContext.getCredentials();
        }
        catch (IllegalStateException illegalStateException) {
            throw WSSecurityProcessorUtils.a(illegalStateException);
        }
        List list2 = list;
        try {
            objectArray = bl2 ? WSSecurityProcessorUtils.getSigningSecurityTokens(list2) : null;
        }
        catch (IllegalStateException illegalStateException) {
            throw WSSecurityProcessorUtils.a(illegalStateException);
        }
        Object[] objectArray2 = objectArray;
        Element element = null;
        if (processorResult != null) {
            SignedElement[] signedElementArray;
            Set<Element> set = WSSecurityProcessorUtils.getSecurityTokenElements(processorResult);
            for (SignedElement signedElement : signedElementArray = processorResult.getElementsThatWereSigned()) {
                block15: {
                    Messages.M m2;
                    Audit audit2;
                    block17: {
                        SigningSecurityToken signingSecurityToken2;
                        block16: {
                            try {
                                if (set.contains(signedElement.asElement())) continue;
                                if (element != null) break block15;
                            }
                            catch (IllegalStateException illegalStateException) {
                                throw WSSecurityProcessorUtils.a(illegalStateException);
                            }
                            signingSecurityToken2 = signedElement.getSigningSecurityToken();
                            try {
                                if (objectArray2 != null && !ArrayUtils.contains((Object[])objectArray2, (Object)signingSecurityToken2)) break block16;
                            }
                            catch (IllegalStateException illegalStateException) {
                                throw WSSecurityProcessorUtils.a(illegalStateException);
                            }
                            element = signedElement.getSignatureElement();
                            signingSecurityToken = signingSecurityToken2;
                            continue;
                        }
                        try {
                            if (unary == null || !((Boolean)unary.call((Object)signingSecurityToken2)).booleanValue()) break block17;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw WSSecurityProcessorUtils.a(illegalStateException);
                        }
                        element = signedElement.getSignatureElement();
                        signingSecurityToken = signingSecurityToken2;
                        continue;
                    }
                    try {
                        audit2 = audit;
                        m2 = objectArray2.length == 0 ? MessageProcessingMessages.WSS_NO_SIGNING_TOKEN : MessageProcessingMessages.WSS_WRONG_SIGNING_TOKEN;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw WSSecurityProcessorUtils.a(illegalStateException);
                    }
                    audit2.logAndAudit((AuditDetailMessage)m2);
                    signingSecurityToken = null;
                    break;
                }
                if (element == signedElement.getSignatureElement()) continue;
                audit.logAndAudit((AuditDetailMessage)MessageProcessingMessages.WSS_DIFFERENT_SIGNATURE);
                signingSecurityToken = null;
                break;
            }
        }
        return signingSecurityToken;
    }

    public static boolean isValidSigningIdentity(AuthenticationContext authenticationContext, IdentityTarget identityTarget, ProcessorResult processorResult, ParsedElement[] parsedElementArray) {
        return WSSecurityProcessorUtils.isValidSigningIdentity(authenticationContext, identityTarget, processorResult.getElementsThatWereSigned(), parsedElementArray);
    }

    public static boolean isValidSigningIdentity(AuthenticationContext authenticationContext, IdentityTarget identityTarget, SignedElement[] signedElementArray, ParsedElement[] parsedElementArray) {
        boolean bl2;
        block13: {
            boolean bl3;
            try {
                bl3 = parsedElementArray.length > 0;
            }
            catch (MultipleTokenException multipleTokenException) {
                throw WSSecurityProcessorUtils.a(multipleTokenException);
            }
            bl2 = bl3;
            try {
                block12: {
                    Object object;
                    Object object2;
                    try {
                        if (authenticationContext == null || new IdentityTarget().equals((Object)new IdentityTarget(identityTarget))) break block12;
                    }
                    catch (MultipleTokenException multipleTokenException) {
                        throw WSSecurityProcessorUtils.a(multipleTokenException);
                    }
                    Element element = null;
                    for (SignedElement signedElement : signedElementArray) {
                        object2 = WSSecurityProcessorUtils.a(signedElement.asElement(), parsedElementArray);
                        object = WSSecurityProcessorUtils.a(authenticationContext, object2, identityTarget);
                        if (object == null) continue;
                        element = object.getSignedElements()[0].getSignatureElement();
                        break;
                    }
                    if (element == null) {
                        bl2 = false;
                        break block13;
                    }
                    for (SignedElement signedElement : parsedElementArray) {
                        SigningSecurityToken signingSecurityToken;
                        if (!(signedElement instanceof SignedElement) || element == (signingSecurityToken = WSSecurityProcessorUtils.a(authenticationContext, (Collection<SigningSecurityToken>)(object = WSSecurityProcessorUtils.a((object2 = signedElement).asElement(), parsedElementArray)), identityTarget)).getSignedElements()[0].getSignatureElement()) continue;
                        bl2 = false;
                        break;
                    }
                    if (!bl2) break block13;
                    for (SignedElement signedElement : signedElementArray) {
                        object2 = WSSecurityProcessorUtils.a(signedElement.asElement(), parsedElementArray);
                        object = WSSecurityProcessorUtils.a(authenticationContext, (Collection<SigningSecurityToken>)object2, identityTarget);
                        try {
                            if (object == null || object.getSignedElements()[0].getSignatureElement() == element) continue;
                        }
                        catch (MultipleTokenException multipleTokenException) {
                            throw WSSecurityProcessorUtils.a(multipleTokenException);
                        }
                        bl2 = false;
                        break block13;
                    }
                    break block13;
                }
                bl2 = false;
            }
            catch (MultipleTokenException multipleTokenException) {
                a.log(Level.WARNING, ExceptionUtils.getMessage((Throwable)multipleTokenException));
                bl2 = false;
            }
        }
        return bl2;
    }

    public static SigningSecurityToken getSigningSecurityTokenByIdentity(AuthenticationContext authenticationContext, ProcessorResult processorResult, IdentityTarget identityTarget) {
        SigningSecurityToken signingSecurityToken = null;
        SignedElement[] signedElementArray = processorResult.getElementsThatWereSigned();
        if (new IdentityTarget().equals((Object)new IdentityTarget(identityTarget))) {
            Set<Element> set = WSSecurityProcessorUtils.getSecurityTokenElements(processorResult);
            for (SignedElement signedElement : signedElementArray) {
                if (set.contains(signedElement.asElement())) continue;
                signingSecurityToken = signedElement.getSigningSecurityToken();
                break;
            }
        } else {
            try {
                for (SignedElement signedElement : signedElementArray) {
                    Set<SigningSecurityToken> set = WSSecurityProcessorUtils.a(signedElement.asElement(), (ParsedElement[])signedElementArray);
                    signingSecurityToken = WSSecurityProcessorUtils.a(authenticationContext, set, identityTarget);
                    try {
                        if (signingSecurityToken == null) continue;
                    }
                    catch (MultipleTokenException multipleTokenException) {
                        throw WSSecurityProcessorUtils.a(multipleTokenException);
                    }
                }
            }
            catch (MultipleTokenException multipleTokenException) {
                a.log(Level.WARNING, ExceptionUtils.getMessage((Throwable)multipleTokenException));
            }
        }
        return signingSecurityToken;
    }

    /*
     * Loose catch block
     */
    public static SignedElement[] filterSignedElementsByIdentity(AuthenticationContext authenticationContext, ProcessorResult processorResult, IdentityTarget identityTarget, boolean bl2, Message message, AuthenticationContext authenticationContext2, Audit audit) {
        ArrayList<Object> arrayList;
        block15: {
            SignedElement[] signedElementArray;
            block14: {
                arrayList = new ArrayList<Object>();
                signedElementArray = processorResult.getElementsThatWereSigned();
                if (!new IdentityTarget().equals((Object)new IdentityTarget(identityTarget))) break block14;
                try {
                    block16: {
                        if (!WSSecurityProcessorUtils.isValidSingleSigner(authenticationContext, processorResult, new ParsedElement[0], bl2, message, authenticationContext2, audit)) break block15;
                        break block16;
                        catch (MultipleTokenException multipleTokenException) {
                            throw WSSecurityProcessorUtils.a(multipleTokenException);
                        }
                    }
                    arrayList.addAll(Arrays.asList(signedElementArray));
                    break block15;
                }
                catch (MultipleTokenException multipleTokenException) {
                    throw WSSecurityProcessorUtils.a(multipleTokenException);
                }
            }
            try {
                ArrayList<SignedElement> arrayList2 = new ArrayList<SignedElement>();
                for (SignedElement signedElement : signedElementArray) {
                    Set<SigningSecurityToken> set = WSSecurityProcessorUtils.a(signedElement.asElement(), (ParsedElement[])signedElementArray);
                    SigningSecurityToken signingSecurityToken = WSSecurityProcessorUtils.a(authenticationContext, set, identityTarget);
                    if (signingSecurityToken == null) continue;
                    try {
                        block17: {
                            if (signingSecurityToken != signedElement.getSigningSecurityToken()) continue;
                            break block17;
                            catch (MultipleTokenException multipleTokenException) {
                                throw WSSecurityProcessorUtils.a(multipleTokenException);
                            }
                        }
                        arrayList2.add(signedElement);
                    }
                    catch (MultipleTokenException multipleTokenException) {
                        throw WSSecurityProcessorUtils.a(multipleTokenException);
                    }
                }
                try {
                    if (WSSecurityProcessorUtils.isValidSigningIdentity(authenticationContext, identityTarget, signedElementArray, arrayList2.toArray(new ParsedElement[arrayList2.size()]))) {
                        arrayList.addAll(arrayList2);
                    }
                }
                catch (MultipleTokenException multipleTokenException) {
                    throw WSSecurityProcessorUtils.a(multipleTokenException);
                }
            }
            catch (MultipleTokenException multipleTokenException) {
                a.log(Level.WARNING, ExceptionUtils.getMessage((Throwable)multipleTokenException));
            }
        }
        return arrayList.toArray(new SignedElement[arrayList.size()]);
    }

    public static SigningSecurityToken[] getSigningSecurityTokens(Collection<LoginCredentials> collection) {
        ArrayList<SigningSecurityToken> arrayList = new ArrayList<SigningSecurityToken>();
        if (collection != null) {
            for (LoginCredentials loginCredentials : collection) {
                for (SecurityToken securityToken : loginCredentials.getSecurityTokens()) {
                    try {
                        try {
                            if (!loginCredentials.isSecurityTokenPresent(securityToken) || !(securityToken instanceof SigningSecurityToken)) continue;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw WSSecurityProcessorUtils.a(illegalStateException);
                        }
                        arrayList.add((SigningSecurityToken)securityToken);
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw WSSecurityProcessorUtils.a(illegalStateException);
                    }
                }
            }
        }
        return arrayList.toArray(new SigningSecurityToken[arrayList.size()]);
    }

    public static Set<Element> getSecurityTokenElements(ProcessorResult processorResult) {
        HashSet<Element> hashSet = new HashSet<Element>();
        XmlSecurityToken[] xmlSecurityTokenArray = processorResult.getXmlSecurityTokens();
        if (xmlSecurityTokenArray != null) {
            for (XmlSecurityToken xmlSecurityToken : xmlSecurityTokenArray) {
                if (!(xmlSecurityToken instanceof SigningSecurityToken)) continue;
                SigningSecurityToken signingSecurityToken = (SigningSecurityToken)xmlSecurityToken;
                hashSet.add(signingSecurityToken.asElement());
            }
        }
        return hashSet;
    }

    public static boolean isSameSignature(SigningSecurityToken ... signingSecurityTokenArray) {
        boolean bl2 = true;
        Element element = null;
        block0: for (SigningSecurityToken signingSecurityToken : signingSecurityTokenArray) {
            SignedElement[] signedElementArray = signingSecurityToken.getSignedElements();
            if (signedElementArray.length == 0) {
                bl2 = false;
                break;
            }
            if (element == null) {
                element = signedElementArray[0].getSignatureElement();
            }
            for (SignedElement signedElement : signedElementArray) {
                if (element == signedElement.getSignatureElement()) continue;
                bl2 = false;
                continue block0;
            }
        }
        return bl2;
    }

    private static Set<SigningSecurityToken> a(Element element, ParsedElement[] parsedElementArray) {
        HashSet<SigningSecurityToken> hashSet = new HashSet<SigningSecurityToken>();
        for (ParsedElement parsedElement : parsedElementArray) {
            if (!(parsedElement instanceof SignedElement)) continue;
            SignedElement signedElement = (SignedElement)parsedElement;
            try {
                if (signedElement.asElement() != element) continue;
                hashSet.add(signedElement.getSigningSecurityToken());
            }
            catch (IllegalStateException illegalStateException) {
                throw WSSecurityProcessorUtils.a(illegalStateException);
            }
        }
        return hashSet;
    }

    /*
     * Exception decompiling
     */
    private static SigningSecurityToken a(AuthenticationContext var0, Collection<SigningSecurityToken> var1_1, IdentityTarget var2_2) throws MultipleTokenException {
        /*
         * 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: Tried to end blocks [3[TRYBLOCK]], but top level block is 11[SWITCH]
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.processEndingBlocks(Op04StructuredStatement.java:435)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:484)
         *     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");
    }

    public static Pair<Boolean, Collection<ParsedElement>> processSignatureConfirmations(SecurityKnob securityKnob, ProcessorResult processorResult, Audit audit) {
        if (!securityKnob.isSignatureConfirmationValidated()) {
            boolean bl2;
            Pair pair;
            Pair pair2;
            securityKnob.setSignatureConfirmationValidated(true);
            Collection collection = null;
            SignatureConfirmation.Status status = processorResult.getSignatureConfirmation().getStatus();
            if (SignatureConfirmation.Status.CONFIRMED == status) {
                collection = processorResult.getSignatureConfirmation().getConfirmationElements().values();
            }
            try {
                if (SignatureConfirmation.Status.INVALID == status) {
                    audit.logAndAudit((AuditDetailMessage)AssertionMessages.REQUIRE_WSS_SIGNATURE_CONFIRMATION_FAILED, new String[]{Arrays.toString(processorResult.getSignatureConfirmation().getErrors().toArray())});
                }
            }
            catch (IllegalStateException illegalStateException) {
                throw WSSecurityProcessorUtils.a(illegalStateException);
            }
            try {
                Pair pair3;
                pair2 = pair3;
                pair = pair3;
                bl2 = SignatureConfirmation.Status.INVALID != status;
            }
            catch (IllegalStateException illegalStateException) {
                throw WSSecurityProcessorUtils.a(illegalStateException);
            }
            pair2((Object)bl2, collection);
            return pair;
        }
        return new Pair((Object)true, null);
    }

    public static void addSignatureConfirmations(Message message, Audit audit) {
        SecurityKnob securityKnob;
        SecurityKnob securityKnob2;
        block39: {
            List list;
            DecorationRequirements decorationRequirements;
            block40: {
                block38: {
                    List list2;
                    Object object;
                    block36: {
                        Set set;
                        HashMap<String, DecorationRequirements> hashMap;
                        block37: {
                            block35: {
                                block34: {
                                    boolean bl2;
                                    block33: {
                                        block32: {
                                            Message message2 = message.getRelated(MessageRole.REQUEST);
                                            try {
                                                if (message2 == null) {
                                                    return;
                                                }
                                            }
                                            catch (IllegalStateException illegalStateException) {
                                                throw WSSecurityProcessorUtils.a(illegalStateException);
                                            }
                                            securityKnob2 = message.getSecurityKnob();
                                            securityKnob = message2.getSecurityKnob();
                                            try {
                                                try {
                                                    if (securityKnob2.getProcessorResult() == null || !securityKnob2.getProcessorResult().isWsse11Seen()) break block32;
                                                }
                                                catch (IllegalStateException illegalStateException) {
                                                    throw WSSecurityProcessorUtils.a(illegalStateException);
                                                }
                                                bl2 = true;
                                                break block33;
                                            }
                                            catch (IllegalStateException illegalStateException) {
                                                throw WSSecurityProcessorUtils.a(illegalStateException);
                                            }
                                        }
                                        bl2 = false;
                                    }
                                    boolean bl3 = bl2;
                                    try {
                                        try {
                                            try {
                                                if (securityKnob.isNeedsSignatureConfirmations() || bl3) break block34;
                                            }
                                            catch (IllegalStateException illegalStateException) {
                                                throw WSSecurityProcessorUtils.a(illegalStateException);
                                            }
                                            if (securityKnob2.hasWss11Decorations()) break block34;
                                        }
                                        catch (IllegalStateException illegalStateException) {
                                            throw WSSecurityProcessorUtils.a(illegalStateException);
                                        }
                                        return;
                                    }
                                    catch (IllegalStateException illegalStateException) {
                                        throw WSSecurityProcessorUtils.a(illegalStateException);
                                    }
                                }
                                hashMap = new HashMap<String, DecorationRequirements>();
                                for (DecorationRequirements object3 : securityKnob2.getDecorationRequirements()) {
                                    hashMap.put(object3.getSecurityHeaderActor(), object3);
                                }
                                set = hashMap.keySet();
                                try {
                                    if (!set.contains(SoapConstants.L7_SOAP_ACTOR)) break block35;
                                    object = (DecorationRequirements)hashMap.get(SoapConstants.L7_SOAP_ACTOR);
                                    break block36;
                                }
                                catch (IllegalStateException illegalStateException) {
                                    throw WSSecurityProcessorUtils.a(illegalStateException);
                                }
                            }
                            try {
                                if (!set.contains(null)) break block37;
                                object = (DecorationRequirements)hashMap.get(null);
                                break block36;
                            }
                            catch (IllegalStateException illegalStateException) {
                                throw WSSecurityProcessorUtils.a(illegalStateException);
                            }
                        }
                        try {
                            object = set.size() == 1 ? hashMap.values().toArray(new DecorationRequirements[1])[0] : null;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw WSSecurityProcessorUtils.a(illegalStateException);
                        }
                    }
                    decorationRequirements = object;
                    ProcessorResult processorResult = securityKnob.getProcessorResult();
                    try {
                        if (processorResult == null) {
                            audit.logAndAudit((AuditDetailMessage)MessageProcessingMessages.MESSAGE_VAR_NO_WSS, new String[]{c[6]});
                        }
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw WSSecurityProcessorUtils.a(illegalStateException);
                    }
                    try {
                        list2 = processorResult == null ? null : processorResult.getValidatedSignatureValues();
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw WSSecurityProcessorUtils.a(illegalStateException);
                    }
                    list = list2;
                    try {
                        if (decorationRequirements != null) break block38;
                        audit.logAndAudit((AuditDetailMessage)MessageProcessingMessages.MESSAGE_NO_SIG_CONFIRMATION);
                        break block39;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw WSSecurityProcessorUtils.a(illegalStateException);
                    }
                }
                try {
                    try {
                        if (list != null && !list.isEmpty()) break block40;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw WSSecurityProcessorUtils.a(illegalStateException);
                    }
                    decorationRequirements.addSignatureConfirmation(null);
                    break block39;
                }
                catch (IllegalStateException illegalStateException) {
                    throw WSSecurityProcessorUtils.a(illegalStateException);
                }
            }
            for (String string : list) {
                decorationRequirements.addSignatureConfirmation(string);
            }
        }
        securityKnob.setNeedsSignatureConfirmations(false);
        securityKnob2.setSignatureConfirmationValidated(true);
    }

    public static boolean setToken(DecorationRequirements decorationRequirements, SigningSecurityToken signingSecurityToken) {
        EncryptedKey encryptedKey;
        boolean bl2 = false;
        if (signingSecurityToken instanceof KerberosSigningSecurityToken) {
            decorationRequirements.setKerberosTicket(((KerberosSecurityToken)signingSecurityToken).getServiceTicket());
            bl2 = true;
        } else if (signingSecurityToken instanceof SecurityContextToken) {
            SecurityContextToken securityContextToken = (SecurityContextToken)signingSecurityToken;
            SecurityContext securityContext = securityContextToken.getSecurityContext();
            if (securityContext instanceof SecureConversationSession) {
                decorationRequirements.setSecureConversationSession((DecorationRequirements.SecureConversationSession)((SecureConversationSession)securityContext));
                bl2 = true;
            }
        } else if (signingSecurityToken instanceof EncryptedKey && (encryptedKey = (EncryptedKey)signingSecurityToken).isUnwrapped()) {
            try {
                decorationRequirements.setEncryptedKey(encryptedKey.getSecretKey());
                decorationRequirements.setEncryptedKeyReferenceInfo(KeyInfoDetails.makeEncryptedKeySha1Ref((String)encryptedKey.getEncryptedKeySHA1()));
                bl2 = true;
            }
            catch (InvalidDocumentFormatException invalidDocumentFormatException) {
                throw new IllegalStateException();
            }
            catch (GeneralSecurityException generalSecurityException) {
                throw new IllegalStateException();
            }
        }
        return bl2;
    }

    private static SecurityContextFinder a(Message message) {
        w w2 = null;
        Message message2 = message.getRelated(MessageRole.REQUEST);
        if (message2 != null) {
            w2 = new w(message2);
        }
        return w2;
    }

    private static y a() {
        y y2;
        block2: {
            y2 = b.get();
            try {
                if (y2 != null && y2.a + TimeUnit.SECONDS.toMillis(30L) >= System.currentTimeMillis()) break block2;
            }
            catch (IllegalStateException illegalStateException) {
                throw WSSecurityProcessorUtils.a(illegalStateException);
            }
            Config config = ConfigFactory.getUncachedConfig();
            String[] stringArray = c;
            y2 = new y(config.getLongProperty(stringArray[0], 0L), config.getBooleanProperty(stringArray[8], true), config.getBooleanProperty(stringArray[5], false), config.getBooleanProperty(stringArray[9], false), config.getBooleanProperty(stringArray[7], true));
            b.set(y2);
        }
        return y2;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[10];
                var3_1 = 0;
                var2_2 = ")v\u0001<!\u0005j(t%&!7`'w%,\u0018\u0005q\u0002`4-&\u0002g7$\rl,<<\u0014e%94'>\u0001g39&' \nm`\u007f/:u\rm%w4!!\u001d)g\u0002g7$\rl,<<\u0014e%94'>\u0001g39&' \nm`\u007f/:u\rm%w4!!\u001d)g.7j3f%\u0016f#|3;:\u0016'!u,'\")|,m)89\u0001])t%;!\u0005d0J)/;\u0005}5k%;\u0007\u0012|1=0\u0017}37j3f%\u0016f#|3;:\u0016'3m2!6\u0010Z)~.)!\u0011{%Z/&3\r{-x4!:\n_!u),4\u0010`/w";
                var4_3 = ")v\u0001<!\u0005j(t%&!7`'w%,\u0018\u0005q\u0002`4-&\u0002g7$\rl,<<\u0014e%94'>\u0001g39&' \nm`\u007f/:u\rm%w4!!\u001d)g\u0002g7$\rl,<<\u0014e%94'>\u0001g39&' \nm`\u007f/:u\rm%w4!!\u001d)g.7j3f%\u0016f#|3;:\u0016'!u,'\")|,m)89\u0001])t%;!\u0005d0J)/;\u0005}5k%;\u0007\u0012|1=0\u0017}37j3f%\u0016f#|3;:\u0016'3m2!6\u0010Z)~.)!\u0011{%Z/&3\r{-x4!:\n_!u),4\u0010`/w".length();
                var1_4 = 26;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = WSSecurityProcessorUtils.a(v0, WSSecurityProcessorUtils.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u000eK\u001c\u0005:<^\u0018G\t8\u001d*@(J\u0019\u0010\u001a*@\u001cJ\u0019.\nW\u000e[\u0018+[\u001eA\u000e\u0006\u0007+\u001a\u001cH\u0011\u001a\u001f\fZ\u0016J\u0012\u0002\u0006\u001b]\u0013E\u000f\f;<W\bV\u0014\u0001\u0011\r[\u0016A\u0013\u0006";
                    var4_3 = "\u000eK\u001c\u0005:<^\u0018G\t8\u001d*@(J\u0019\u0010\u001a*@\u001cJ\u0019.\nW\u000e[\u0018+[\u001eA\u000e\u0006\u0007+\u001a\u001cH\u0011\u001a\u001f\fZ\u0016J\u0012\u0002\u0006\u001b]\u0013E\u000f\f;<W\bV\u0014\u0001\u0011\r[\u0016A\u0013\u0006".length();
                    var1_4 = 24;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 106;
                        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++] = WSSecurityProcessorUtils.a(v0, WSSecurityProcessorUtils.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;
            }
        }
        WSSecurityProcessorUtils.c = var5;
        WSSecurityProcessorUtils.a = Logger.getLogger(WSSecurityProcessorUtils.class.getName());
        WSSecurityProcessorUtils.b = new AtomicReference<V>();
    }

    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] ^ 0x5E);
        }
        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 -> 23;
                    case 1 -> 78;
                    case 2 -> 23;
                    case 3 -> 31;
                    case 4 -> 2;
                    case 5 -> 51;
                    default -> 94;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }

    private static class MultipleTokenException
    extends Exception {
        static final long serialVersionUID = 3447178923432468148L;

        private MultipleTokenException(String string) {
            super(string);
        }
    }
}

