package com.l7tech.server.policy.assertion.credential.wss;

import com.l7tech.gateway.common.audit.AssertionMessages;
import com.l7tech.message.Message;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.assertion.credential.wss.EncryptedUsernameTokenAssertion;
import com.l7tech.security.token.EncryptedElement;
import com.l7tech.security.token.UsernameToken;
import com.l7tech.security.xml.SecurityTokenResolver;
import com.l7tech.security.xml.processor.ProcessorResult;
import com.l7tech.server.message.AuthenticationContext;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.AbstractMessageTargetableServerAssertion;
import com.l7tech.util.Config;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.springframework.context.ApplicationContext;

public class ServerEncryptedUsernameTokenAssertion extends AbstractMessageTargetableServerAssertion<EncryptedUsernameTokenAssertion> {
   private final EncryptedUsernameTokenAssertion d;
   private final Config e;
   private final SecurityTokenResolver f;
   private final Set<String> g;
   private static final String[] h;

   public ServerEncryptedUsernameTokenAssertion(EncryptedUsernameTokenAssertion var1, ApplicationContext var2) {
      super(var1);
      this.d = var1;
      String[] var3 = h;
      this.e = (Config)var2.getBean(var3[5], Config.class);
      this.f = (SecurityTokenResolver)var2.getBean(var3[6], SecurityTokenResolver.class);
      this.g = var1.getXEncAlgorithmList() == null ? null : new HashSet<>(var1.getXEncAlgorithmList());
   }

   @Override
   public AssertionStatus checkRequest(PolicyEnforcementContext var1) throws IOException, PolicyAssertionException {
      try {
         if (!this.d.getRecipientContext().localRecipient()) {
            this.logAndAudit(AssertionMessages.WSS_BASIC_FOR_ANOTHER_RECIPIENT);
            return AssertionStatus.NONE;
         }
      } catch (IOException var2) {
         throw a(var2);
      }

      return super.checkRequest(var1);
   }

   @Override
   protected AssertionStatus doCheckRequest(PolicyEnforcementContext param1, Message param2, String param3, AuthenticationContext param4) throws IOException, PolicyAssertionException {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 000: aload 2
      // 001: invokevirtual com/l7tech/message/Message.isSoap ()Z
      // 004: ifne 01e
      // 007: aload 0
      // 008: getstatic com/l7tech/gateway/common/audit/AssertionMessages.WSS_BASIC_NOT_SOAP Lcom/l7tech/gateway/common/audit/Messages$M;
      // 00b: bipush 1
      // 00c: anewarray 145
      // 00f: dup
      // 010: bipush 0
      // 011: aload 3
      // 012: aastore
      // 013: invokevirtual com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 016: getstatic com/l7tech/policy/assertion/AssertionStatus.NOT_APPLICABLE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 019: areturn
      // 01a: invokestatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 01d: athrow
      // 01e: aload 0
      // 01f: invokevirtual com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.isRequest ()Z
      // 022: ifeq 056
      // 025: aload 0
      // 026: getfield com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.e Lcom/l7tech/util/Config;
      // 029: getstatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.h [Ljava/lang/String;
      // 02c: bipush 2
      // 02d: aaload
      // 02e: bipush 1
      // 02f: invokeinterface com/l7tech/util/Config.getBooleanProperty (Ljava/lang/String;Z)Z 3
      // 034: ifne 056
      // 037: goto 03e
      // 03a: invokestatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 03d: athrow
      // 03e: aload 2
      // 03f: invokevirtual com/l7tech/message/Message.getSecurityKnob ()Lcom/l7tech/message/SecurityKnob;
      // 042: invokeinterface com/l7tech/message/SecurityKnob.getProcessorResult ()Lcom/l7tech/security/xml/processor/ProcessorResult; 1
      // 047: astore 5
      // 049: aload 2
      // 04a: invokevirtual com/l7tech/message/Message.getSecurityKnob ()Lcom/l7tech/message/SecurityKnob;
      // 04d: bipush 1
      // 04e: invokeinterface com/l7tech/message/SecurityKnob.setNeedsSignatureConfirmations (Z)V 2
      // 053: goto 086
      // 056: aload 2
      // 057: aload 3
      // 058: aload 0
      // 059: getfield com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.f Lcom/l7tech/security/xml/SecurityTokenResolver;
      // 05c: aload 0
      // 05d: invokevirtual com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.getAudit ()Lcom/l7tech/gateway/common/audit/Audit;
      // 060: invokestatic com/l7tech/server/util/WSSecurityProcessorUtils.getWssResults (Lcom/l7tech/message/Message;Ljava/lang/String;Lcom/l7tech/security/xml/SecurityTokenResolver;Lcom/l7tech/gateway/common/audit/Audit;)Lcom/l7tech/security/xml/processor/ProcessorResult;
      // 063: astore 5
      // 065: aload 2
      // 066: getstatic com/l7tech/message/MessageRole.REQUEST Lcom/l7tech/message/MessageRole;
      // 069: invokevirtual com/l7tech/message/Message.getRelated (Lcom/l7tech/message/MessageRole;)Lcom/l7tech/message/Message;
      // 06c: ifnull 086
      // 06f: aload 2
      // 070: getstatic com/l7tech/message/MessageRole.REQUEST Lcom/l7tech/message/MessageRole;
      // 073: invokevirtual com/l7tech/message/Message.getRelated (Lcom/l7tech/message/MessageRole;)Lcom/l7tech/message/Message;
      // 076: invokevirtual com/l7tech/message/Message.getSecurityKnob ()Lcom/l7tech/message/SecurityKnob;
      // 079: bipush 1
      // 07a: invokeinterface com/l7tech/message/SecurityKnob.setNeedsSignatureConfirmations (Z)V 2
      // 07f: goto 086
      // 082: invokestatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 085: athrow
      // 086: goto 09e
      // 089: astore 6
      // 08b: new com/l7tech/util/CausedIOException
      // 08e: dup
      // 08f: getstatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.h [Ljava/lang/String;
      // 092: astore 18
      // 094: aload 18
      // 096: bipush 3
      // 097: aaload
      // 098: aload 6
      // 09a: invokespecial com/l7tech/util/CausedIOException.<init> (Ljava/lang/String;Ljava/lang/Throwable;)V
      // 09d: athrow
      // 09e: aload 5
      // 0a0: ifnonnull 0d7
      // 0a3: aload 0
      // 0a4: getstatic com/l7tech/gateway/common/audit/AssertionMessages.WSS_BASIC_NO_CREDENTIALS Lcom/l7tech/gateway/common/audit/Messages$M;
      // 0a7: bipush 1
      // 0a8: anewarray 145
      // 0ab: dup
      // 0ac: bipush 0
      // 0ad: aload 3
      // 0ae: aastore
      // 0af: invokevirtual com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 0b2: aload 0
      // 0b3: invokevirtual com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.isRequest ()Z
      // 0b6: ifeq 0d3
      // 0b9: goto 0c0
      // 0bc: invokestatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0bf: athrow
      // 0c0: aload 1
      // 0c1: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setAuthenticationMissing ()V 1
      // 0c6: aload 1
      // 0c7: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setRequestPolicyViolated ()V 1
      // 0cc: goto 0d3
      // 0cf: invokestatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0d2: athrow
      // 0d3: getstatic com/l7tech/policy/assertion/AssertionStatus.AUTH_REQUIRED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 0d6: areturn
      // 0d7: aload 5
      // 0d9: invokeinterface com/l7tech/security/xml/processor/ProcessorResult.getXmlSecurityTokens ()[Lcom/l7tech/security/token/XmlSecurityToken; 1
      // 0de: astore 6
      // 0e0: aload 6
      // 0e2: astore 7
      // 0e4: aload 7
      // 0e6: arraylength
      // 0e7: istore 8
      // 0e9: bipush 0
      // 0ea: istore 9
      // 0ec: iload 9
      // 0ee: iload 8
      // 0f0: if_icmpge 1de
      // 0f3: aload 7
      // 0f5: iload 9
      // 0f7: aaload
      // 0f8: astore 10
      // 0fa: aload 10
      // 0fc: instanceof com/l7tech/security/token/UsernameToken
      // 0ff: ifeq 1d8
      // 102: aload 10
      // 104: checkcast com/l7tech/security/token/UsernameToken
      // 107: astore 11
      // 109: aload 0
      // 10a: aload 5
      // 10c: aload 11
      // 10e: invokevirtual com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Lcom/l7tech/security/xml/processor/ProcessorResult;Lcom/l7tech/security/token/UsernameToken;)Z
      // 111: ifne 127
      // 114: aload 0
      // 115: getfield com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.logger Ljava/util/logging/Logger;
      // 118: getstatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.h [Ljava/lang/String;
      // 11b: bipush 0
      // 11c: aaload
      // 11d: invokevirtual java/util/logging/Logger.fine (Ljava/lang/String;)V
      // 120: goto 1d8
      // 123: invokestatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 126: athrow
      // 127: aload 5
      // 129: aload 11
      // 12b: invokeinterface com/l7tech/security/token/UsernameToken.asElement ()Lorg/w3c/dom/Element; 1
      // 130: invokeinterface com/l7tech/security/xml/processor/ProcessorResult.getSigningTokens (Lorg/w3c/dom/Element;)[Lcom/l7tech/security/token/SigningSecurityToken; 2
      // 135: astore 12
      // 137: aload 12
      // 139: ifnull 14a
      // 13c: aload 12
      // 13e: arraylength
      // 13f: bipush 1
      // 140: if_icmpge 15d
      // 143: goto 14a
      // 146: invokestatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 149: athrow
      // 14a: aload 0
      // 14b: getfield com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.logger Ljava/util/logging/Logger;
      // 14e: getstatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.h [Ljava/lang/String;
      // 151: bipush 4
      // 152: aaload
      // 153: invokevirtual java/util/logging/Logger.fine (Ljava/lang/String;)V
      // 156: goto 1d8
      // 159: invokestatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 15c: athrow
      // 15d: aconst_null
      // 15e: astore 13
      // 160: aload 12
      // 162: astore 14
      // 164: aload 14
      // 166: arraylength
      // 167: istore 15
      // 169: bipush 0
      // 16a: istore 16
      // 16c: iload 16
      // 16e: iload 15
      // 170: if_icmpge 1a2
      // 173: aload 14
      // 175: iload 16
      // 177: aaload
      // 178: astore 17
      // 17a: aload 17
      // 17c: instanceof com/l7tech/security/token/EncryptedKey
      // 17f: ifne 195
      // 182: aload 0
      // 183: getfield com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.logger Ljava/util/logging/Logger;
      // 186: getstatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.h [Ljava/lang/String;
      // 189: bipush 1
      // 18a: aaload
      // 18b: invokevirtual java/util/logging/Logger.fine (Ljava/lang/String;)V
      // 18e: goto 19c
      // 191: invokestatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 194: athrow
      // 195: aload 17
      // 197: checkcast com/l7tech/security/token/EncryptedKey
      // 19a: astore 13
      // 19c: iinc 16 1
      // 19f: goto 16c
      // 1a2: aload 13
      // 1a4: ifnonnull 1bb
      // 1a7: aload 0
      // 1a8: getfield com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.logger Ljava/util/logging/Logger;
      // 1ab: getstatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.h [Ljava/lang/String;
      // 1ae: bipush 7
      // 1b0: aaload
      // 1b1: invokevirtual java/util/logging/Logger.fine (Ljava/lang/String;)V
      // 1b4: goto 1d8
      // 1b7: invokestatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 1ba: athrow
      // 1bb: aload 11
      // 1bd: ldc com/l7tech/policy/assertion/credential/wss/WssBasic
      // 1bf: bipush 1
      // 1c0: anewarray 258
      // 1c3: dup
      // 1c4: bipush 0
      // 1c5: aload 13
      // 1c7: aastore
      // 1c8: invokestatic com/l7tech/policy/assertion/credential/LoginCredentials.makeLoginCredentials (Lcom/l7tech/security/token/SecurityToken;Ljava/lang/Class;[Lcom/l7tech/security/token/SecurityToken;)Lcom/l7tech/policy/assertion/credential/LoginCredentials;
      // 1cb: astore 14
      // 1cd: aload 4
      // 1cf: aload 14
      // 1d1: invokevirtual com/l7tech/server/message/AuthenticationContext.addCredentials (Lcom/l7tech/policy/assertion/credential/LoginCredentials;)V
      // 1d4: getstatic com/l7tech/policy/assertion/AssertionStatus.NONE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 1d7: areturn
      // 1d8: iinc 9 1
      // 1db: goto 0ec
      // 1de: aload 0
      // 1df: getstatic com/l7tech/gateway/common/audit/AssertionMessages.WSS_BASIC_CANNOT_FIND_ENC_CREDENTIALS Lcom/l7tech/gateway/common/audit/Messages$M;
      // 1e2: bipush 1
      // 1e3: anewarray 145
      // 1e6: dup
      // 1e7: bipush 0
      // 1e8: aload 3
      // 1e9: aastore
      // 1ea: invokevirtual com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 1ed: aload 0
      // 1ee: invokevirtual com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.isRequest ()Z
      // 1f1: ifeq 201
      // 1f4: aload 1
      // 1f5: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setRequestPolicyViolated ()V 1
      // 1fa: goto 201
      // 1fd: invokestatic com/l7tech/server/policy/assertion/credential/wss/ServerEncryptedUsernameTokenAssertion.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 200: athrow
      // 201: getstatic com/l7tech/policy/assertion/AssertionStatus.AUTH_REQUIRED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 204: areturn
      // try (0 -> 13): 61 org/xml/sax/SAXException
      // try (47 -> 57): 58 org/xml/sax/SAXException
      // try (16 -> 27): 28 org/xml/sax/SAXException
      // try (0 -> 14): 14 java/io/IOException
      // try (16 -> 60): 61 org/xml/sax/SAXException
      // try (72 -> 86): 87 org/xml/sax/SAXException
      // try (74 -> 93): 94 org/xml/sax/SAXException
      // try (121 -> 133): 133 org/xml/sax/SAXException
      // try (140 -> 146): 147 org/xml/sax/SAXException
      // try (142 -> 156): 156 org/xml/sax/SAXException
      // try (174 -> 184): 184 org/xml/sax/SAXException
      // try (191 -> 200): 200 org/xml/sax/SAXException
      // try (219 -> 233): 234 org/xml/sax/SAXException
   }

   private boolean a(ProcessorResult var1, UsernameToken var2) {
      for (EncryptedElement var6 : var1.getElementsThatWereEncrypted()) {
         if (var6.asElement() == var2.asElement() && (this.g == null || this.g.contains(var6.getAlgorithm()))) {
            return true;
         }
      }

      return false;
   }

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

   static {
      String[] var5 = new String[8];
      int var3 = 0;
      String var2 = "VRTL\u0011nKx\u0015oP\u0006uK~X_w\fl@q\u0015NK\u0002s\u0005hTI\u0003\rhQ?EHL\u0013bWsL\u001aF\rdWfENF\u0007AVRTL\u0011nKx\u0015oP\u0006uK~X_w\fl@q\u0015IJ\u0004iLqR\u001aW\fl@q\u0015NK\u0002s\u0005hTI\u0003\rhQ?TT\u0003&iFmLJW\u0006cnzL-hFI\r\u0013uJ|PIP\fu\u000bz[[A\u000fbazS_Q\u0011bAMPKV\u0006tQOGU@\u0006tVv[].MPKV\u0006tQ?Q_@\u000ffWzQ\u001aB\u0010'}Ry\u001aA\u0016s\u0005vF\u001aM\fs\u0005hPVONaJmX_G*VRTL\u0011nKx\u0015oP\u0006uK~X_w\fl@q\u0015NK\u0002s\u0005hTI\u0003\rhQ?FSD\rbA\flPHU\u0006ufp[\\J\u0004";
      int var4 = "VRTL\u0011nKx\u0015oP\u0006uK~X_w\fl@q\u0015NK\u0002s\u0005hTI\u0003\rhQ?EHL\u0013bWsL\u001aF\rdWfENF\u0007AVRTL\u0011nKx\u0015oP\u0006uK~X_w\fl@q\u0015IJ\u0004iLqR\u001aW\fl@q\u0015NK\u0002s\u0005hTI\u0003\rhQ?TT\u0003&iFmLJW\u0006cnzL-hFI\r\u0013uJ|PIP\fu\u000bz[[A\u000fbazS_Q\u0011bAMPKV\u0006tQOGU@\u0006tVv[].MPKV\u0006tQ?Q_@\u000ffWzQ\u001aB\u0010'}Ry\u001aA\u0016s\u0005vF\u001aM\fs\u0005hPVONaJmX_G*VRTL\u0011nKx\u0015oP\u0006uK~X_w\fl@q\u0015NK\u0002s\u0005hTI\u0003\rhQ?FSD\rbA\flPHU\u0006ufp[\\J\u0004"
         .length();
      char var1 = '6';
      int var7 = -1;

      label24:
      while (true) {
         byte var10000 = 98;
         String var10001 = var2.substring(++var7, var7 + var1);
         byte var10002 = -1;

         while (true) {
            String var8 = c(var10000, a(var10001));
            switch (var10002) {
               case 0:
                  var5[var3++] = var8;
                  if ((var7 += var1) >= var4) {
                     h = var5;
                     return;
                  }

                  var1 = var2.charAt(var7);
                  break;
               default:
                  var5[var3++] = var8;
                  if ((var7 += var1) < var4) {
                     var1 = var2.charAt(var7);
                     continue label24;
                  }

                  var2 = "zFO@\u0007xGpwC^\u0010\u007falPCY\u0003tA=@DBZ\u0007x]n\u0003yF\u0010c]hNIa\u001azVg\u0003X]\u0014e\u0013~B_\u0015\u001b~G)PER\u001btW)AU\u0015\u0014\u007f\u0013LMOG\faGlGgP\f";
                  var4 = "zFO@\u0007xGpwC^\u0010\u007falPCY\u0003tA=@DBZ\u0007x]n\u0003yF\u0010c]hNIa\u001azVg\u0003X]\u0014e\u0013~B_\u0015\u001b~G)PER\u001btW)AU\u0015\u0014\u007f\u0013LMOG\faGlGgP\f"
                     .length();
                  var1 = 21;
                  var7 = -1;
            }

            var10000 = 116;
            var10001 = var2.substring(++var7, var7 + var1);
            var10002 = 0;
         }
      }
   }

   private static char[] a(String var0) {
      char[] var10000 = var0.toCharArray();
      if (var10000.length < 2) {
         var10000[0] = (char)(var10000[0] ^ 71);
      }

      return var10000;
   }

   private static String c(int var0, char[] var1) {
      int var10003 = var1.length;
      int var10002 = var0;
      char[] var10001 = var1;
      int var10000 = var10003;

      for (int var2 = 0; var10000 > var2; var2++) {
         var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
            case 0 -> 125;
            case 1 -> 87;
            case 2 -> 88;
            case 3 -> 65;
            case 4 -> 1;
            case 5 -> 101;
            default -> 71;
         });
      }

      return new String(var10001).intern();
   }
}
