package com.l7tech.server.policy.assertion.xmlsec;

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.xmlsec.WssEncryptElement;
import com.l7tech.server.message.AuthenticationContext;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.xml.xpath.DeferredFailureDomCompiledXpathHolder;
import java.io.IOException;

public class ServerWssEncryptElement extends ServerAddWssEncryption<WssEncryptElement> {
   private final DeferredFailureDomCompiledXpathHolder d = new DeferredFailureDomCompiledXpathHolder(this.assertion.getXpathExpression());
   private static final String[] e;

   public ServerWssEncryptElement(WssEncryptElement var1) throws IOException {
      super(var1);
   }

   @Override
   protected AssertionStatus doCheckRequest(PolicyEnforcementContext var1, Message var2, String var3, AuthenticationContext var4) throws IOException, PolicyAssertionException {
      AddWssEncryptionContext var5;
      try {
         var5 = this.buildEncryptionContext(var1);
      } catch (AddWssEncryptionSupport.MultipleTokensException var7) {
         this.logAndAudit(AssertionMessages.WSS_ENCRYPT_MORE_THAN_ONE_TOKEN);
         return AssertionStatus.BAD_REQUEST;
      }

      try {
         if (!var5.hasEncryptionKey()) {
            this.logAndAudit(AssertionMessages.WSS_ENCRYPT_NO_CERT_OR_SC_TOKEN);
         }
      } catch (AddWssEncryptionSupport.MultipleTokensException var8) {
         throw a(var8);
      }

      return this.a(var2, var3, var5, var1);
   }

   private AssertionStatus a(Message param1, String param2, AddWssEncryptionContext param3, PolicyEnforcementContext 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 1
      // 001: invokevirtual com/l7tech/message/Message.isSoap ()Z
      // 004: ifne 01e
      // 007: aload 0
      // 008: getstatic com/l7tech/gateway/common/audit/AssertionMessages.WSS_ENCRYPT_MESSAGE_NOT_SOAP Lcom/l7tech/gateway/common/audit/Messages$M;
      // 00b: bipush 1
      // 00c: anewarray 123
      // 00f: dup
      // 010: bipush 0
      // 011: aload 2
      // 012: aastore
      // 013: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.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/xmlsec/ServerWssEncryptElement.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 01d: athrow
      // 01e: goto 02d
      // 021: astore 5
      // 023: new com/l7tech/util/CausedIOException
      // 026: dup
      // 027: aload 5
      // 029: invokespecial com/l7tech/util/CausedIOException.<init> (Ljava/lang/Throwable;)V
      // 02c: athrow
      // 02d: aload 1
      // 02e: invokevirtual com/l7tech/message/Message.getXmlKnob ()Lcom/l7tech/message/XmlKnob;
      // 031: invokeinterface com/l7tech/message/XmlKnob.getDocumentReadOnly ()Lorg/w3c/dom/Document; 1
      // 036: astore 5
      // 038: aload 0
      // 039: getfield com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.d Lcom/l7tech/xml/xpath/DeferredFailureDomCompiledXpathHolder;
      // 03c: invokevirtual com/l7tech/xml/xpath/DeferredFailureDomCompiledXpathHolder.getCompiledXpath ()Lcom/l7tech/xml/xpath/DomCompiledXpath;
      // 03f: aload 5
      // 041: new com/l7tech/server/util/xml/PolicyEnforcementContextXpathVariableFinder
      // 044: dup
      // 045: aload 4
      // 047: invokespecial com/l7tech/server/util/xml/PolicyEnforcementContextXpathVariableFinder.<init> (Lcom/l7tech/server/message/PolicyEnforcementContext;)V
      // 04a: invokevirtual com/l7tech/xml/xpath/DomCompiledXpath.rawSelectElements (Lorg/w3c/dom/Document;Lcom/l7tech/xml/xpath/XpathVariableFinder;)Ljava/util/List;
      // 04d: astore 6
      // 04f: goto 07f
      // 052: astore 7
      // 054: aload 0
      // 055: getstatic com/l7tech/gateway/common/audit/AssertionMessages.XPATH_PATTERN_INVALID_MORE_INFO Lcom/l7tech/gateway/common/audit/Messages$M;
      // 058: bipush 1
      // 059: anewarray 123
      // 05c: dup
      // 05d: bipush 0
      // 05e: aload 7
      // 060: invokestatic com/l7tech/util/ExceptionUtils.getMessage (Ljava/lang/Throwable;)Ljava/lang/String;
      // 063: getstatic com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.e [Ljava/lang/String;
      // 066: astore 10
      // 068: aload 10
      // 06a: bipush 0
      // 06b: aaload
      // 06c: swap
      // 06d: invokedynamic makeConcatWithConstants (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; bsm=java/lang/invoke/StringConcatFactory.makeConcatWithConstants (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite; args=[ "\u0001\u0001" ]
      // 072: aastore
      // 073: aload 7
      // 075: invokestatic com/l7tech/util/ExceptionUtils.getDebugException (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 078: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;Ljava/lang/Throwable;)V
      // 07b: getstatic com/l7tech/policy/assertion/AssertionStatus.SERVER_ERROR Lcom/l7tech/policy/assertion/AssertionStatus;
      // 07e: areturn
      // 07f: aload 6
      // 081: ifnull 096
      // 084: aload 6
      // 086: invokeinterface java/util/List.size ()I 1
      // 08b: bipush 1
      // 08c: if_icmpge 0a9
      // 08f: goto 096
      // 092: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 095: athrow
      // 096: aload 0
      // 097: getstatic com/l7tech/gateway/common/audit/AssertionMessages.WSS_ENCRYPT_MESSAGE_NOT_ENCRYPTED Lcom/l7tech/gateway/common/audit/Messages$M;
      // 09a: bipush 1
      // 09b: anewarray 123
      // 09e: dup
      // 09f: bipush 0
      // 0a0: aload 2
      // 0a1: aastore
      // 0a2: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 0a5: getstatic com/l7tech/policy/assertion/AssertionStatus.FALSIFIED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 0a8: areturn
      // 0a9: aload 1
      // 0aa: invokevirtual com/l7tech/message/Message.getSecurityKnob ()Lcom/l7tech/message/SecurityKnob;
      // 0ad: aload 3
      // 0ae: invokevirtual com/l7tech/server/policy/assertion/xmlsec/AddWssEncryptionContext.getRecipientContext ()Lcom/l7tech/policy/assertion/xmlsec/XmlSecurityRecipientContext;
      // 0b1: invokeinterface com/l7tech/message/SecurityKnob.getAlternateDecorationRequirements (Lcom/l7tech/policy/assertion/xmlsec/XmlSecurityRecipientContext;)Lcom/l7tech/security/xml/decorator/DecorationRequirements; 2
      // 0b6: astore 7
      // 0b8: aload 6
      // 0ba: invokeinterface java/util/List.iterator ()Ljava/util/Iterator; 1
      // 0bf: astore 8
      // 0c1: aload 8
      // 0c3: invokeinterface java/util/Iterator.hasNext ()Z 1
      // 0c8: ifeq 0f2
      // 0cb: aload 8
      // 0cd: invokeinterface java/util/Iterator.next ()Ljava/lang/Object; 1
      // 0d2: checkcast org/w3c/dom/Element
      // 0d5: astore 9
      // 0d7: aload 7
      // 0d9: aload 9
      // 0db: new com/l7tech/security/xml/ElementEncryptionConfig
      // 0de: dup
      // 0df: aload 0
      // 0e0: getfield com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 0e3: checkcast com/l7tech/policy/assertion/xmlsec/WssEncryptElement
      // 0e6: invokevirtual com/l7tech/policy/assertion/xmlsec/WssEncryptElement.isEncryptContentsOnly ()Z
      // 0e9: invokespecial com/l7tech/security/xml/ElementEncryptionConfig.<init> (Z)V
      // 0ec: invokevirtual com/l7tech/security/xml/decorator/DecorationRequirements.addElementToEncrypt (Lorg/w3c/dom/Element;Lcom/l7tech/security/xml/ElementEncryptionConfig;)V
      // 0ef: goto 0c1
      // 0f2: aload 7
      // 0f4: aload 0
      // 0f5: getfield com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 0f8: checkcast com/l7tech/policy/assertion/xmlsec/WssEncryptElement
      // 0fb: invokevirtual com/l7tech/policy/assertion/xmlsec/WssEncryptElement.getXEncAlgorithm ()Ljava/lang/String;
      // 0fe: invokevirtual com/l7tech/security/xml/decorator/DecorationRequirements.setEncryptionAlgorithm (Ljava/lang/String;)V
      // 101: aload 7
      // 103: aload 0
      // 104: getfield com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 107: checkcast com/l7tech/policy/assertion/xmlsec/WssEncryptElement
      // 10a: invokevirtual com/l7tech/policy/assertion/xmlsec/WssEncryptElement.getKeyEncryptionAlgorithm ()Ljava/lang/String;
      // 10d: invokevirtual com/l7tech/security/xml/decorator/DecorationRequirements.setKeyEncryptionAlgorithm (Ljava/lang/String;)V
      // 110: aload 0
      // 111: getfield com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 114: checkcast com/l7tech/policy/assertion/xmlsec/WssEncryptElement
      // 117: invokevirtual com/l7tech/policy/assertion/xmlsec/WssEncryptElement.getKeyReference ()Ljava/lang/String;
      // 11a: astore 8
      // 11c: aload 8
      // 11e: ifnull 136
      // 121: getstatic com/l7tech/security/xml/KeyReference.SKI Lcom/l7tech/security/xml/KeyReference;
      // 124: invokevirtual com/l7tech/security/xml/KeyReference.getName ()Ljava/lang/String;
      // 127: aload 8
      // 129: invokevirtual java/lang/String.equals (Ljava/lang/Object;)Z
      // 12c: ifeq 145
      // 12f: goto 136
      // 132: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 135: athrow
      // 136: aload 7
      // 138: getstatic com/l7tech/security/xml/KeyInfoInclusionType.STR_SKI Lcom/l7tech/security/xml/KeyInfoInclusionType;
      // 13b: invokevirtual com/l7tech/security/xml/decorator/DecorationRequirements.setEncryptionKeyInfoInclusionType (Lcom/l7tech/security/xml/KeyInfoInclusionType;)V
      // 13e: goto 19c
      // 141: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 144: athrow
      // 145: getstatic com/l7tech/security/xml/KeyReference.ISSUER_SERIAL Lcom/l7tech/security/xml/KeyReference;
      // 148: invokevirtual com/l7tech/security/xml/KeyReference.getName ()Ljava/lang/String;
      // 14b: aload 8
      // 14d: invokevirtual java/lang/String.equals (Ljava/lang/Object;)Z
      // 150: ifeq 162
      // 153: aload 7
      // 155: getstatic com/l7tech/security/xml/KeyInfoInclusionType.ISSUER_SERIAL Lcom/l7tech/security/xml/KeyInfoInclusionType;
      // 158: invokevirtual com/l7tech/security/xml/decorator/DecorationRequirements.setEncryptionKeyInfoInclusionType (Lcom/l7tech/security/xml/KeyInfoInclusionType;)V
      // 15b: goto 19c
      // 15e: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 161: athrow
      // 162: getstatic com/l7tech/security/xml/KeyReference.BST Lcom/l7tech/security/xml/KeyReference;
      // 165: invokevirtual com/l7tech/security/xml/KeyReference.getName ()Ljava/lang/String;
      // 168: aload 8
      // 16a: invokevirtual java/lang/String.equals (Ljava/lang/Object;)Z
      // 16d: ifeq 17f
      // 170: aload 7
      // 172: getstatic com/l7tech/security/xml/KeyInfoInclusionType.CERT Lcom/l7tech/security/xml/KeyInfoInclusionType;
      // 175: invokevirtual com/l7tech/security/xml/decorator/DecorationRequirements.setEncryptionKeyInfoInclusionType (Lcom/l7tech/security/xml/KeyInfoInclusionType;)V
      // 178: goto 19c
      // 17b: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 17e: athrow
      // 17f: getstatic com/l7tech/security/xml/KeyReference.KEY_NAME Lcom/l7tech/security/xml/KeyReference;
      // 182: invokevirtual com/l7tech/security/xml/KeyReference.getName ()Ljava/lang/String;
      // 185: aload 8
      // 187: invokevirtual java/lang/String.equals (Ljava/lang/Object;)Z
      // 18a: ifeq 19c
      // 18d: aload 7
      // 18f: getstatic com/l7tech/security/xml/KeyInfoInclusionType.KEY_NAME Lcom/l7tech/security/xml/KeyInfoInclusionType;
      // 192: invokevirtual com/l7tech/security/xml/decorator/DecorationRequirements.setEncryptionKeyInfoInclusionType (Lcom/l7tech/security/xml/KeyInfoInclusionType;)V
      // 195: goto 19c
      // 198: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 19b: athrow
      // 19c: aload 0
      // 19d: aload 4
      // 19f: aload 7
      // 1a1: aload 3
      // 1a2: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.applyDecorationRequirements (Lcom/l7tech/server/message/PolicyEnforcementContext;Lcom/l7tech/security/xml/decorator/DecorationRequirements;Lcom/l7tech/server/policy/assertion/xmlsec/AddWssEncryptionContext;)V
      // 1a5: aload 0
      // 1a6: getstatic com/l7tech/gateway/common/audit/AssertionMessages.WSS_ENCRYPT_MESSAGE_ENCRYPTED Lcom/l7tech/gateway/common/audit/Messages$M;
      // 1a9: bipush 2
      // 1aa: anewarray 123
      // 1ad: dup
      // 1ae: bipush 0
      // 1af: aload 2
      // 1b0: aastore
      // 1b1: dup
      // 1b2: bipush 1
      // 1b3: aload 6
      // 1b5: invokeinterface java/util/List.size ()I 1
      // 1ba: invokestatic java/lang/String.valueOf (I)Ljava/lang/String;
      // 1bd: aastore
      // 1be: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 1c1: getstatic com/l7tech/policy/assertion/AssertionStatus.NONE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 1c4: areturn
      // 1c5: astore 6
      // 1c7: getstatic com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.e [Ljava/lang/String;
      // 1ca: bipush 1
      // 1cb: aaload
      // 1cc: astore 7
      // 1ce: aload 0
      // 1cf: getstatic com/l7tech/gateway/common/audit/AssertionMessages.EXCEPTION_SEVERE_WITH_MORE_INFO Lcom/l7tech/gateway/common/audit/Messages$M;
      // 1d2: bipush 1
      // 1d3: anewarray 123
      // 1d6: dup
      // 1d7: bipush 0
      // 1d8: aload 7
      // 1da: aastore
      // 1db: aload 6
      // 1dd: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerWssEncryptElement.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;Ljava/lang/Throwable;)V
      // 1e0: getstatic com/l7tech/policy/assertion/AssertionStatus.SERVER_ERROR Lcom/l7tech/policy/assertion/AssertionStatus;
      // 1e3: areturn
      // try (0 -> 13): 17 org/xml/sax/SAXException
      // try (0 -> 14): 14 com/l7tech/xml/InvalidXpathException
      // try (27 -> 37): 38 com/l7tech/xml/InvalidXpathException
      // try (23 -> 59): 195 org/xml/sax/SAXException
      // try (60 -> 66): 67 org/xml/sax/SAXException
      // try (60 -> 79): 195 org/xml/sax/SAXException
      // try (162 -> 170): 171 org/xml/sax/SAXException
      // try (151 -> 160): 160 org/xml/sax/SAXException
      // try (140 -> 149): 149 org/xml/sax/SAXException
      // try (126 -> 138): 138 org/xml/sax/SAXException
      // try (124 -> 131): 132 org/xml/sax/SAXException
      // try (80 -> 194): 195 org/xml/sax/SAXException
   }

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

   static {
      String[] var5 = new String[2];
      int var3 = 0;
      String var2 = "\u0018LKMI\"p6}FL@v|/r\n\\Spz2&\n7#}DWNv5'y^\u0019@l58qF\u0019Emv5qOWU\"s2sG\u0019Ujp`nOJQm{3y\nMN\"p.\u007fX@Qv";
      int var4 = "\u0018LKMI\"p6}FL@v|/r\n\\Spz2&\n7#}DWNv5'y^\u0019@l58qF\u0019Emv5qOWU\"s2sG\u0019Ujp`nOJQm{3y\nMN\"p.\u007fX@Qv".length();
      char var1 = 24;
      int var0 = -1;

      while (true) {
         String var10002 = c(86, a(var2.substring(++var0, var0 + var1)));
         byte var10001 = -1;
         var5[var3++] = var10002;
         if ((var0 += var1) >= var4) {
            e = var5;
            return;
         }

         var1 = var2.charAt(var0);
      }
   }

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

      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 -> 22;
            case 1 -> 74;
            case 2 -> 124;
            case 3 -> 111;
            case 4 -> 119;
            case 5 -> 84;
            default -> 67;
         });
      }

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