/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.CertUtils
 *  com.l7tech.gateway.common.audit.AssertionMessages
 *  com.l7tech.gateway.common.audit.AuditDetailMessage
 *  com.l7tech.gateway.common.audit.MessageProcessingMessages
 *  com.l7tech.kerberos.KerberosGSSAPReqTicket
 *  com.l7tech.kerberos.KerberosUtils
 *  com.l7tech.message.Message
 *  com.l7tech.message.MessageRole
 *  com.l7tech.policy.assertion.Assertion
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.IdentityTarget
 *  com.l7tech.policy.assertion.PolicyAssertionException
 *  com.l7tech.policy.assertion.xmlsec.SecurityHeaderAddressableSupport
 *  com.l7tech.policy.assertion.xmlsec.WssReplayProtection
 *  com.l7tech.policy.variable.Syntax
 *  com.l7tech.security.token.EncryptedKey
 *  com.l7tech.security.token.KerberosSigningSecurityToken
 *  com.l7tech.security.token.ParsedElement
 *  com.l7tech.security.token.SecurityContextToken
 *  com.l7tech.security.token.SignedElement
 *  com.l7tech.security.token.SigningSecurityToken
 *  com.l7tech.security.token.X509SigningSecurityToken
 *  com.l7tech.security.xml.SecurityTokenResolver
 *  com.l7tech.security.xml.processor.ProcessorResult
 *  com.l7tech.security.xml.processor.ProcessorResultUtil
 *  com.l7tech.security.xml.processor.WssTimestamp
 *  com.l7tech.security.xml.processor.WssTimestampDate
 *  com.l7tech.util.Charsets
 *  com.l7tech.util.Config
 *  com.l7tech.util.ConfigFactory
 *  com.l7tech.util.DomUtils
 *  com.l7tech.util.ExceptionUtils
 *  com.l7tech.util.HexUtils
 *  com.l7tech.util.Pair
 *  com.l7tech.util.SoapConstants
 *  com.l7tech.util.TimeSource
 *  org.springframework.beans.factory.BeanFactory
 */
package com.l7tech.server.policy.assertion.xmlsec;

import com.l7tech.common.io.CertUtils;
import com.l7tech.gateway.common.audit.AssertionMessages;
import com.l7tech.gateway.common.audit.AuditDetailMessage;
import com.l7tech.gateway.common.audit.MessageProcessingMessages;
import com.l7tech.kerberos.KerberosGSSAPReqTicket;
import com.l7tech.kerberos.KerberosUtils;
import com.l7tech.message.Message;
import com.l7tech.message.MessageRole;
import com.l7tech.policy.assertion.Assertion;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.IdentityTarget;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.assertion.xmlsec.SecurityHeaderAddressableSupport;
import com.l7tech.policy.assertion.xmlsec.WssReplayProtection;
import com.l7tech.policy.variable.Syntax;
import com.l7tech.security.token.EncryptedKey;
import com.l7tech.security.token.KerberosSigningSecurityToken;
import com.l7tech.security.token.ParsedElement;
import com.l7tech.security.token.SecurityContextToken;
import com.l7tech.security.token.SignedElement;
import com.l7tech.security.token.SigningSecurityToken;
import com.l7tech.security.token.X509SigningSecurityToken;
import com.l7tech.security.xml.SecurityTokenResolver;
import com.l7tech.security.xml.processor.ProcessorResult;
import com.l7tech.security.xml.processor.ProcessorResultUtil;
import com.l7tech.security.xml.processor.WssTimestamp;
import com.l7tech.security.xml.processor.WssTimestampDate;
import com.l7tech.server.extension.provider.sharedstate.SharedStateProviderLowMemoryException;
import com.l7tech.server.message.AuthenticationContext;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.AbstractMessageTargetableServerAssertion;
import com.l7tech.server.policy.assertion.AssertionStatusException;
import com.l7tech.server.policy.assertion.xmlsec.w;
import com.l7tech.server.policy.variable.ExpandVariables;
import com.l7tech.server.util.MessageId;
import com.l7tech.server.util.MessageIdManager;
import com.l7tech.server.util.WSSecurityProcessorUtils;
import com.l7tech.util.Charsets;
import com.l7tech.util.Config;
import com.l7tech.util.ConfigFactory;
import com.l7tech.util.DomUtils;
import com.l7tech.util.ExceptionUtils;
import com.l7tech.util.HexUtils;
import com.l7tech.util.Pair;
import com.l7tech.util.SoapConstants;
import com.l7tech.util.TimeSource;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.factory.BeanFactory;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

public class ServerWssReplayProtection
extends AbstractMessageTargetableServerAssertion<WssReplayProtection> {
    private static final long d = 60000L;
    private static final long e = 2592000000L;
    private static final long f = 300000L;
    private static final long g = 600000L;
    private static final String h;
    private static final int i;
    private static final int j;
    private static final String k;
    private static final Charset l;
    private final MessageIdManager m;
    private final Config n;
    private final SecurityTokenResolver o;
    private final TimeSource p;
    private static final Logger q;
    private static final String[] s;

    public ServerWssReplayProtection(WssReplayProtection wssReplayProtection, BeanFactory beanFactory) {
        super(wssReplayProtection);
        String[] stringArray = s;
        this.m = (MessageIdManager)beanFactory.getBean(stringArray[11], MessageIdManager.class);
        this.n = (Config)beanFactory.getBean(stringArray[2], Config.class);
        this.o = (SecurityTokenResolver)beanFactory.getBean(stringArray[12], SecurityTokenResolver.class);
        this.p = this.getTimeSource();
    }

    @Override
    public AssertionStatus checkRequest(PolicyEnforcementContext policyEnforcementContext) throws IOException, PolicyAssertionException {
        try {
            if (!SecurityHeaderAddressableSupport.isLocalRecipient((Assertion)this.assertion)) {
                this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUESTWSS_NOT_FOR_US);
                return AssertionStatus.NONE;
            }
        }
        catch (IOException iOException) {
            throw ServerWssReplayProtection.a(iOException);
        }
        return super.checkRequest(policyEnforcementContext);
    }

    @Override
    protected AssertionStatus doCheckRequest(PolicyEnforcementContext policyEnforcementContext, Message message, String string, AuthenticationContext authenticationContext) throws IOException {
        Pair<String, Long> pair;
        try {
            pair = ((WssReplayProtection)this.assertion).isCustomProtection() ? this.a(policyEnforcementContext, string) : this.a(policyEnforcementContext, message, string, authenticationContext);
        }
        catch (AssertionStatusException assertionStatusException) {
            return assertionStatusException.getAssertionStatus();
        }
        MessageId messageId = new MessageId((String)pair.left, (Long)pair.right);
        try {
            this.m.assertMessageIdIsUnique(messageId);
            this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_PROTECTION_SUCCEEDED, (String)pair.left, string);
        }
        catch (MessageIdManager.DuplicateMessageIdException duplicateMessageIdException) {
            this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_REPLAY, (String)pair.left, string);
            return this.getBadMessageStatus();
        }
        catch (MessageIdManager.MessageIdCheckException messageIdCheckException) {
            try {
                if (messageIdCheckException.getCause() instanceof SharedStateProviderLowMemoryException) {
                    q.log(Level.WARNING, s[1] + ExceptionUtils.getMessage((Throwable)messageIdCheckException));
                    policyEnforcementContext.setVariable(WssReplayProtection.VARIABLE_REASON_CODE, AssertionStatus.INSUFFICIENT_STORAGE.getNumeric());
                    return AssertionStatus.FAILED;
                }
            }
            catch (AssertionStatusException assertionStatusException) {
                throw ServerWssReplayProtection.a(assertionStatusException);
            }
            this.logAndAudit((AuditDetailMessage)AssertionMessages.EXCEPTION_WARNING_WITH_MORE_INFO, new String[]{s[3] + ExceptionUtils.getMessage((Throwable)messageIdCheckException)}, messageIdCheckException);
            return AssertionStatus.FAILED;
        }
        return AssertionStatus.NONE;
    }

    protected TimeSource getTimeSource() {
        return new TimeSource();
    }

    /*
     * Loose catch block
     */
    private Pair<String, Long> a(PolicyEnforcementContext policyEnforcementContext, Message message, String string, AuthenticationContext authenticationContext) throws IOException {
        Object object;
        long l2;
        block71: {
            String string2;
            WssTimestamp wssTimestamp;
            WssTimestamp wssTimestamp2;
            block62: {
                Object object2;
                block64: {
                    block63: {
                        long l3;
                        block60: {
                            block61: {
                                AuthenticationContext authenticationContext2;
                                w w2;
                                boolean bl2;
                                IdentityTarget identityTarget;
                                ProcessorResult processorResult;
                                AuthenticationContext authenticationContext3;
                                w w3;
                                ProcessorResult processorResult2;
                                block57: {
                                    l3 = this.p.currentTimeMillis();
                                    try {
                                        block58: {
                                            block65: {
                                                block56: {
                                                    try {
                                                        if (!message.isSoap()) {
                                                            this.logAndAudit((AuditDetailMessage)MessageProcessingMessages.MESSAGE_VAR_NOT_SOAP, string);
                                                            throw new AssertionStatusException(AssertionStatus.NOT_APPLICABLE);
                                                        }
                                                    }
                                                    catch (SAXException sAXException) {
                                                        throw ServerWssReplayProtection.a(sAXException);
                                                    }
                                                    object2 = new boolean[]{false};
                                                    try {
                                                        if (!this.isRequest() || this.n.getBooleanProperty(s[10], true)) break block56;
                                                    }
                                                    catch (SAXException sAXException) {
                                                        throw ServerWssReplayProtection.a(sAXException);
                                                    }
                                                    processorResult2 = message.getSecurityKnob().getProcessorResult();
                                                    break block65;
                                                }
                                                w3 = new w(this, (boolean[])object2);
                                                processorResult2 = WSSecurityProcessorUtils.getWssResults(message, string, this.o, null, this.getAudit(), w3);
                                            }
                                            if (processorResult2 != null) break block57;
                                            try {
                                                block66: {
                                                    if (!this.isRequest()) break block58;
                                                    break block66;
                                                    catch (SAXException sAXException) {
                                                        throw ServerWssReplayProtection.a(sAXException);
                                                    }
                                                }
                                                policyEnforcementContext.setRequestPolicyViolated();
                                                policyEnforcementContext.setAuthenticationMissing();
                                            }
                                            catch (SAXException sAXException) {
                                                throw ServerWssReplayProtection.a(sAXException);
                                            }
                                        }
                                        try {
                                            if (object2[0]) {
                                                throw new AssertionStatusException(this.getBadMessageStatus());
                                            }
                                        }
                                        catch (SAXException sAXException) {
                                            throw ServerWssReplayProtection.a(sAXException);
                                        }
                                        this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_NO_WSS_LEVEL_SECURITY, string);
                                        throw new AssertionStatusException(AssertionStatus.NOT_APPLICABLE);
                                    }
                                    catch (SAXException sAXException) {
                                        throw new IOException(ExceptionUtils.getMessage((Throwable)sAXException), sAXException);
                                    }
                                }
                                object2 = null;
                                w3 = message.getRelated(MessageRole.REQUEST);
                                try {
                                    authenticationContext3 = authenticationContext;
                                    processorResult = processorResult2;
                                    identityTarget = ((WssReplayProtection)this.assertion).getIdentityTarget();
                                    bl2 = false;
                                    w2 = w3;
                                    authenticationContext2 = w3 == null ? null : policyEnforcementContext.getAuthenticationContext((Message)w3);
                                }
                                catch (SAXException sAXException) {
                                    throw ServerWssReplayProtection.a(sAXException);
                                }
                                for (SignedElement signedElement : wssTimestamp2 = WSSecurityProcessorUtils.filterSignedElementsByIdentity(authenticationContext3, processorResult, identityTarget, bl2, (Message)w2, authenticationContext2, this.getAudit())) {
                                    Element element;
                                    block59: {
                                        block67: {
                                            element = signedElement.asElement();
                                            if (!DomUtils.elementInNamespace((Element)element, (String[])SoapConstants.WSA_NAMESPACE_ARRAY)) continue;
                                            if (!SoapConstants.MESSAGEID_EL_NAME.equals(element.getLocalName())) continue;
                                            break block67;
                                            catch (SAXException sAXException) {
                                                throw ServerWssReplayProtection.a(sAXException);
                                            }
                                        }
                                        try {
                                            block68: {
                                                if (object2 == null) break block59;
                                                break block68;
                                                catch (SAXException sAXException) {
                                                    throw ServerWssReplayProtection.a(sAXException);
                                                }
                                            }
                                            this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_MULTIPLE_MESSAGE_IDS, string);
                                            throw new AssertionStatusException(this.getBadMessageStatus());
                                        }
                                        catch (SAXException sAXException) {
                                            throw ServerWssReplayProtection.a(sAXException);
                                        }
                                    }
                                    object2 = DomUtils.getTextValue((Element)element);
                                    this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_GOT_SIGNED_MESSAGE_ID, new String[]{string, object2});
                                }
                                try {
                                    if (object2 == null) {
                                        this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_NO_SIGNED_MESSAGE_ID, string);
                                    }
                                }
                                catch (SAXException sAXException) {
                                    throw ServerWssReplayProtection.a(sAXException);
                                }
                                wssTimestamp = processorResult2.getTimestamp();
                                if (wssTimestamp != null) break block60;
                                try {
                                    block69: {
                                        if (!this.isRequest()) break block61;
                                        break block69;
                                        catch (SAXException sAXException) {
                                            throw ServerWssReplayProtection.a(sAXException);
                                        }
                                    }
                                    policyEnforcementContext.setRequestPolicyViolated();
                                }
                                catch (SAXException sAXException) {
                                    throw ServerWssReplayProtection.a(sAXException);
                                }
                            }
                            this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_NO_TIMESTAMP, string);
                            throw new AssertionStatusException(this.getBadMessageStatus());
                        }
                        try {
                            if (ProcessorResultUtil.getParsedElementsForNode((Node)wssTimestamp.asElement(), (ParsedElement[])wssTimestamp2).isEmpty()) {
                                this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_TIMESTAMP_NOT_SIGNED, string);
                                throw new AssertionStatusException(this.getBadMessageStatus());
                            }
                        }
                        catch (SAXException sAXException) {
                            throw ServerWssReplayProtection.a(sAXException);
                        }
                        WssTimestampDate wssTimestampDate = wssTimestamp.getCreated();
                        try {
                            if (wssTimestampDate == null) {
                                this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_TIMESTAMP_NO_CREATED_ELEMENT, string);
                                throw new AssertionStatusException(this.getBadMessageStatus());
                            }
                        }
                        catch (SAXException sAXException) {
                            throw ServerWssReplayProtection.a(sAXException);
                        }
                        string2 = wssTimestampDate.asIsoString().trim();
                        long l4 = wssTimestampDate.asTime();
                        if (wssTimestamp.getExpires() != null) {
                            l2 = wssTimestamp.getExpires().asTime();
                        } else {
                            this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_TIMESTAMP_NO_EXPIRES_ELEMENT, string, String.valueOf(600000L));
                            l2 = l4 + 600000L;
                        }
                        try {
                            if (l2 <= l3 - 60000L) {
                                this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_STALE_TIMESTAMP, string);
                                throw new AssertionStatusException(this.getBadMessageStatus());
                            }
                        }
                        catch (SAXException sAXException) {
                            throw ServerWssReplayProtection.a(sAXException);
                        }
                        try {
                            if (l4 > l3) {
                                this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_CLOCK_SKEW, string, String.valueOf(l4));
                            }
                        }
                        catch (SAXException sAXException) {
                            throw ServerWssReplayProtection.a(sAXException);
                        }
                        try {
                            if (l4 <= l3 - 2592000000L) {
                                this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_CREATED_TOO_OLD, string);
                                throw new AssertionStatusException(this.getBadMessageStatus());
                            }
                        }
                        catch (SAXException sAXException) {
                            throw ServerWssReplayProtection.a(sAXException);
                        }
                        if (object2 == null) break block62;
                        try {
                            block70: {
                                if (((String)object2).length() <= j) break block63;
                                break block70;
                                catch (SAXException sAXException) {
                                    throw ServerWssReplayProtection.a(sAXException);
                                }
                            }
                            this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_MESSAGE_ID_TOO_LARGE, Integer.toString(((String)object2).length()));
                            throw new AssertionStatusException(this.getBadMessageStatus());
                        }
                        catch (SAXException sAXException) {
                            throw ServerWssReplayProtection.a(sAXException);
                        }
                    }
                    if (((String)object2).length() <= i) break block64;
                    object = s[9] + this.a((String)object2);
                    break block71;
                }
                object = this.c((String)object2);
                break block71;
            }
            try {
                String string3 = this.a(wssTimestamp.asElement(), (SignedElement[])wssTimestamp2, string2, string);
                try {
                    if (string3 == null) {
                        throw new AssertionStatusException(this.getBadMessageStatus());
                    }
                }
                catch (SAXException sAXException) {
                    throw ServerWssReplayProtection.a(sAXException);
                }
                object = string3;
            }
            catch (MultipleSenderIdException multipleSenderIdException) {
                this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_MULTIPLE_SENDER_IDS, string);
                throw new AssertionStatusException(this.getBadMessageStatus());
            }
        }
        return new Pair(object, (Object)(l2 + 300000L));
    }

    private Pair<String, Long> a(PolicyEnforcementContext policyEnforcementContext, String string) {
        long l2;
        String string2;
        long l3 = this.p.currentTimeMillis();
        try {
            String string3;
            String string4 = ((WssReplayProtection)this.assertion).getCustomIdentifierVariable();
            ArrayList<String> arrayList = new ArrayList<String>();
            try {
                if (string4 != null) {
                    arrayList.add(string4);
                }
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw ServerWssReplayProtection.a(illegalArgumentException);
            }
            try {
                if (((WssReplayProtection)this.assertion).getCustomScope() != null) {
                    arrayList.addAll(Arrays.asList(Syntax.getReferencedNames((String)((WssReplayProtection)this.assertion).getCustomScope())));
                }
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw ServerWssReplayProtection.a(illegalArgumentException);
            }
            Map<String, Object> map = policyEnforcementContext.getVariableMap(arrayList.toArray(new String[arrayList.size()]), this.getAudit());
            try {
                string3 = ((WssReplayProtection)this.assertion).getCustomScope() == null ? "" : ExpandVariables.process(((WssReplayProtection)this.assertion).getCustomScope(), map, this.getAudit(), true);
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw ServerWssReplayProtection.a(illegalArgumentException);
            }
            String string5 = string3;
            String string6 = ExpandVariables.process(Syntax.SYNTAX_PREFIX + string4 + "}", map, this.getAudit(), true);
            try {
                if (string6.isEmpty()) {
                    this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_CUSTOM_VAR_EMPTY, string);
                    throw new AssertionStatusException(AssertionStatus.FALSIFIED);
                }
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw ServerWssReplayProtection.a(illegalArgumentException);
            }
            this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_USING_SCOPE_AND_ID, string, string5, string6);
            string2 = MessageFormat.format(s[0], this.a(string5), this.a(string6));
            l2 = l3 + (long)((WssReplayProtection)this.assertion).getCustomExpiryTime();
        }
        catch (IllegalArgumentException illegalArgumentException) {
            this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_CUSTOM_VAR_ERROR, new String[]{string, ExceptionUtils.getMessage((Throwable)illegalArgumentException)}, ExceptionUtils.getDebugException((Throwable)illegalArgumentException));
            throw new AssertionStatusException(AssertionStatus.FAILED);
        }
        return new Pair((Object)string2, (Object)l2);
    }

    /*
     * Loose catch block
     */
    private String a(Element element, SignedElement[] signedElementArray, String string, String string2) throws MultipleSenderIdException, UnsupportedEncodingException {
        String string3 = null;
        for (SignedElement signedElement : signedElementArray) {
            SigningSecurityToken signingSecurityToken;
            block28: {
                Object object;
                Object object2;
                block29: {
                    block26: {
                        String[] stringArray;
                        block27: {
                            block24: {
                                block25: {
                                    block22: {
                                        block23: {
                                            try {
                                                if (!element.isSameNode(signedElement.asElement())) {
                                                    continue;
                                                }
                                            }
                                            catch (CertificateEncodingException certificateEncodingException) {
                                                throw ServerWssReplayProtection.a(certificateEncodingException);
                                            }
                                            signingSecurityToken = signedElement.getSigningSecurityToken();
                                            if (!(signingSecurityToken instanceof X509SigningSecurityToken)) break block22;
                                            try {
                                                block30: {
                                                    if (string3 == null) break block23;
                                                    break block30;
                                                    catch (CertificateEncodingException certificateEncodingException) {
                                                        throw ServerWssReplayProtection.a(certificateEncodingException);
                                                    }
                                                }
                                                throw new MultipleSenderIdException();
                                            }
                                            catch (CertificateEncodingException certificateEncodingException) {
                                                throw ServerWssReplayProtection.a(certificateEncodingException);
                                            }
                                        }
                                        object2 = ((X509SigningSecurityToken)signingSecurityToken).getMessageSigningCertificate();
                                        this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_TIMESTAMP_SIGNED_WITH_CERT, string2);
                                        try {
                                            object = HexUtils.getSha1Digest((byte[][])new byte[][]{string.getBytes(l), ((X509Certificate)object2).getSubjectDN().toString().getBytes(l), ((X509Certificate)object2).getIssuerDN().toString().getBytes(l), this.a((X509Certificate)object2).getBytes(l)});
                                            string3 = HexUtils.hexDump((byte[])object);
                                            continue;
                                        }
                                        catch (CertificateEncodingException certificateEncodingException) {
                                            this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_NO_SKI, string2, ((X509Certificate)object2).getSubjectDN().getName());
                                            return null;
                                        }
                                    }
                                    try {
                                        try {
                                            if (!(signingSecurityToken instanceof SecurityContextToken)) break block24;
                                            if (string3 == null) break block25;
                                        }
                                        catch (CertificateEncodingException certificateEncodingException) {
                                            throw ServerWssReplayProtection.a(certificateEncodingException);
                                        }
                                        throw new MultipleSenderIdException();
                                    }
                                    catch (CertificateEncodingException certificateEncodingException) {
                                        throw ServerWssReplayProtection.a(certificateEncodingException);
                                    }
                                }
                                this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_TIMESTAMP_SIGNED_WITH_SC_KEY, string2);
                                object2 = ((SecurityContextToken)signingSecurityToken).getContextIdentifier();
                                object = new StringBuilder();
                                ((StringBuilder)object).append(string);
                                ((StringBuilder)object).append(";");
                                stringArray = s;
                                ((StringBuilder)object).append(stringArray[13]);
                                ((StringBuilder)object).append(this.c((String)object2));
                                string3 = ((StringBuilder)object).toString();
                                continue;
                            }
                            try {
                                try {
                                    if (!(signingSecurityToken instanceof EncryptedKey)) break block26;
                                    if (string3 == null) break block27;
                                }
                                catch (CertificateEncodingException certificateEncodingException) {
                                    throw ServerWssReplayProtection.a(certificateEncodingException);
                                }
                                throw new MultipleSenderIdException();
                            }
                            catch (CertificateEncodingException certificateEncodingException) {
                                throw ServerWssReplayProtection.a(certificateEncodingException);
                            }
                        }
                        this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_TIMESTAMP_SIGNED_WITH_ENC_KEY, string2);
                        object2 = ((EncryptedKey)signingSecurityToken).getEncryptedKeySHA1();
                        object = new StringBuilder();
                        ((StringBuilder)object).append(string);
                        ((StringBuilder)object).append(";");
                        stringArray = s;
                        ((StringBuilder)object).append(stringArray[7]);
                        ((StringBuilder)object).append(this.b((String)object2));
                        string3 = ((StringBuilder)object).toString();
                        continue;
                    }
                    try {
                        try {
                            if (!(signingSecurityToken instanceof KerberosSigningSecurityToken)) break block28;
                            if (string3 == null) break block29;
                        }
                        catch (CertificateEncodingException certificateEncodingException) {
                            throw ServerWssReplayProtection.a(certificateEncodingException);
                        }
                        throw new MultipleSenderIdException();
                    }
                    catch (CertificateEncodingException certificateEncodingException) {
                        throw ServerWssReplayProtection.a(certificateEncodingException);
                    }
                }
                this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_TIMESTAMP_SIGNED_WITH_KERBEROS, string2);
                object2 = KerberosUtils.getBase64Sha1((KerberosGSSAPReqTicket)((KerberosSigningSecurityToken)signingSecurityToken).getTicket());
                object = new StringBuilder();
                ((StringBuilder)object).append(string);
                ((StringBuilder)object).append(";");
                ((StringBuilder)object).append(s[8]);
                ((StringBuilder)object).append(this.b((String)object2));
                string3 = ((StringBuilder)object).toString();
                continue;
            }
            this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUEST_WSS_REPLAY_UNSUPPORTED_TOKEN_TYPE, string2, signingSecurityToken.getClass().getName());
            return null;
        }
        return string3;
    }

    private String a(String string) {
        return this.b(HexUtils.encodeBase64((byte[])HexUtils.getSha512Digest((byte[])HexUtils.encodeUtf8((String)string)), (boolean)true));
    }

    private String b(String string) {
        return string.replace('/', '-').replace('+', '_');
    }

    private String c(String string) {
        return this.b(HexUtils.encodeBase64((byte[])HexUtils.encodeUtf8((String)string)));
    }

    private String a(X509Certificate x509Certificate) throws CertificateEncodingException {
        String string;
        byte[] byArray = CertUtils.getSKIBytesFromCert((X509Certificate)x509Certificate);
        try {
            string = byArray == null ? "" : HexUtils.hexDump((byte[])byArray);
        }
        catch (CertificateEncodingException certificateEncodingException) {
            throw ServerWssReplayProtection.a(certificateEncodingException);
        }
        return string;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[15];
                var3_1 = 0;
                var2_2 = "\u0013\"?Vu?m\u0015#9_u/{\t'3\b4le\\,gO\"5?7@*88\u0015#7F*|h\u00148 [+9jF;9Eo1}\u000b8$Ku|\f\u00152$D*.[\t90[(\u001c#%$]=|{\u000e25Y&2\u007fF19@o.}\u0016;7Kof8\u0010\u0013\"?Vu+k\u0007m2[(9k\u0012m\u0019\u0013\"?Vu?m\u0015#9_u/{\t'3\b4le\\,gO'\u00058;\u001c#kl\u00034>\u001c<9j\u00102$\u001c\"9k\u001561W\u0006\u0018P\u0007$>f'.}\u000e8:V\u0011#95@6,l\u00033\u001dW6\u000fP'fk\u0014-2$P*.w\u0015!cs\u001f\u000e]7\u0004\u001es~a\u0010\u0013\"?Vu+k\u0007m2[(9k\u0012m-\u0011$%\u001c?.w\u00052%A .6\u000397P#9\\\u000313@=9|42'G*/l6%9Q*/k\u000f91\u0010\u000b2%A.;}/3\u001bS!=\u007f\u0003%\u0015\u001525G=5l\u001f\u00039Y*2J\u0003$9^99j";
                var4_3 = "\u0013\"?Vu?m\u0015#9_u/{\t'3\b4le\\,gO\"5?7@*88\u0015#7F*|h\u00148 [+9jF;9Eo1}\u000b8$Ku|\f\u00152$D*.[\t90[(\u001c#%$]=|{\u000e25Y&2\u007fF19@o.}\u0016;7Kof8\u0010\u0013\"?Vu+k\u0007m2[(9k\u0012m\u0019\u0013\"?Vu?m\u0015#9_u/{\t'3\b4le\\,gO'\u00058;\u001c#kl\u00034>\u001c<9j\u00102$\u001c\"9k\u001561W\u0006\u0018P\u0007$>f'.}\u000e8:V\u0011#95@6,l\u00033\u001dW6\u000fP'fk\u0014-2$P*.w\u0015!cs\u001f\u000e]7\u0004\u001es~a\u0010\u0013\"?Vu+k\u0007m2[(9k\u0012m-\u0011$%\u001c?.w\u00052%A .6\u000397P#9\\\u000313@=9|42'G*/l6%9Q*/k\u000f91\u0010\u000b2%A.;}/3\u001bS!=\u007f\u0003%\u0015\u001525G=5l\u001f\u00039Y*2J\u0003$9^99j".length();
                var1_4 = 25;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ServerWssReplayProtection.c(v0, ServerWssReplayProtection.d(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "tsd\u0000gr7nR*$Dyz]b*-Bu\u007f]}x+Qse]cx*Twp\u0016GY\u0014Fn[\u0016`z-O";
                    var4_3 = "tsd\u0000gr7nR*$Dyz]b*-Bu\u007f]}x+Qse]cx*Twp\u0016GY\u0014Fn[\u0016`z-O".length();
                    var1_4 = 10;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 15;
                        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++] = ServerWssReplayProtection.c(v0, ServerWssReplayProtection.d(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;
            }
        }
        ServerWssReplayProtection.s = var5;
        ServerWssReplayProtection.h = ServerWssReplayProtection.s[4];
        ServerWssReplayProtection.k = ServerWssReplayProtection.s[5];
        var0_6 = ServerWssReplayProtection.s;
        ServerWssReplayProtection.i = ConfigFactory.getIntProperty((String)var0_6[6], (int)150);
        ServerWssReplayProtection.j = ConfigFactory.getIntProperty((String)var0_6[14], (int)8192);
        ServerWssReplayProtection.l = Charsets.UTF8;
        ServerWssReplayProtection.q = Logger.getLogger(ServerWssReplayProtection.class.getName());
    }

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

    private static char[] d(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x56);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String c(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 -> 40;
                    case 1 -> 25;
                    case 2 -> 24;
                    case 3 -> 124;
                    case 4 -> 1;
                    case 5 -> 18;
                    default -> 86;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }

    private static final class MultipleSenderIdException
    extends Exception {
        static final long serialVersionUID = 7968442618719748504L;

        private MultipleSenderIdException() {
        }
    }
}

