package com.l7tech.server.policy.assertion;

import com.l7tech.message.HttpServletRequestKnob;
import com.l7tech.message.Message;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.InjectionThreatProtectionAssertion;
import com.l7tech.server.message.PolicyEnforcementContext;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.Map;
import java.util.Map.Entry;

public abstract class ServerInjectionThreatProtectionAssertion<AT extends InjectionThreatProtectionAssertion>
   extends AbstractMessageTargetableServerAssertion<AT> {
   private static final String[] g;

   public ServerInjectionThreatProtectionAssertion(AT var1) {
      super((AT)var1);
   }

   protected AssertionStatus applyThreatProtection(PolicyEnforcementContext param1, Message param2, String param3) throws IOException {
      // $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: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.isPostRouting ()Z 1
      // 006: istore 4
      // 008: aconst_null
      // 009: astore 5
      // 00b: aload 0
      // 00c: invokevirtual com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.isRequest ()Z
      // 00f: ifeq 038
      // 012: iload 4
      // 014: ifeq 02a
      // 017: goto 01e
      // 01a: invokestatic com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 01d: athrow
      // 01e: aload 0
      // 01f: invokevirtual com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.logAndAuditRequestAlreadyRouted ()V
      // 022: getstatic com/l7tech/policy/assertion/AssertionStatus.FAILED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 025: areturn
      // 026: invokestatic com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 029: athrow
      // 02a: aload 2
      // 02b: ldc com/l7tech/message/HttpServletRequestKnob
      // 02d: invokevirtual com/l7tech/message/Message.getKnob (Ljava/lang/Class;)Ljava/lang/Object;
      // 030: checkcast com/l7tech/message/HttpServletRequestKnob
      // 033: astore 5
      // 035: goto 057
      // 038: aload 0
      // 039: invokevirtual com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.isResponse ()Z
      // 03c: ifeq 057
      // 03f: iload 4
      // 041: ifne 057
      // 044: goto 04b
      // 047: invokestatic com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 04a: athrow
      // 04b: aload 0
      // 04c: invokevirtual com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.logAndAuditResponseNotRouted ()V
      // 04f: getstatic com/l7tech/policy/assertion/AssertionStatus.NONE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 052: areturn
      // 053: invokestatic com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 056: athrow
      // 057: getstatic com/l7tech/policy/assertion/AssertionStatus.NONE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 05a: astore 6
      // 05c: aconst_null
      // 05d: aload 5
      // 05f: if_acmpeq 0b9
      // 062: aload 0
      // 063: getfield com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 066: checkcast com/l7tech/policy/assertion/InjectionThreatProtectionAssertion
      // 069: invokevirtual com/l7tech/policy/assertion/InjectionThreatProtectionAssertion.isIncludeUrlPath ()Z
      // 06c: ifeq 091
      // 06f: goto 076
      // 072: invokestatic com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 075: athrow
      // 076: aload 0
      // 077: aload 5
      // 079: invokevirtual com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.scanHttpRequestUrlPath (Lcom/l7tech/message/HttpServletRequestKnob;)Lcom/l7tech/policy/assertion/AssertionStatus;
      // 07c: astore 6
      // 07e: aload 6
      // 080: getstatic com/l7tech/policy/assertion/AssertionStatus.NONE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 083: if_acmpeq 091
      // 086: aload 0
      // 087: invokevirtual com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.logAndAuditAttackRejected ()V
      // 08a: aload 6
      // 08c: areturn
      // 08d: invokestatic com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 090: athrow
      // 091: aload 0
      // 092: getfield com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 095: checkcast com/l7tech/policy/assertion/InjectionThreatProtectionAssertion
      // 098: invokevirtual com/l7tech/policy/assertion/InjectionThreatProtectionAssertion.isIncludeUrlQueryString ()Z
      // 09b: ifeq 0e5
      // 09e: aload 0
      // 09f: aload 5
      // 0a1: invokevirtual com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.scanHttpRequestUrlQueryString (Lcom/l7tech/message/HttpServletRequestKnob;)Lcom/l7tech/policy/assertion/AssertionStatus;
      // 0a4: astore 6
      // 0a6: aload 6
      // 0a8: getstatic com/l7tech/policy/assertion/AssertionStatus.NONE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 0ab: if_acmpeq 0e5
      // 0ae: aload 0
      // 0af: invokevirtual com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.logAndAuditAttackRejected ()V
      // 0b2: aload 6
      // 0b4: areturn
      // 0b5: invokestatic com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0b8: athrow
      // 0b9: aload 0
      // 0ba: getfield com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 0bd: checkcast com/l7tech/policy/assertion/InjectionThreatProtectionAssertion
      // 0c0: invokevirtual com/l7tech/policy/assertion/InjectionThreatProtectionAssertion.isIncludeUrlPath ()Z
      // 0c3: ifne 0da
      // 0c6: aload 0
      // 0c7: getfield com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 0ca: checkcast com/l7tech/policy/assertion/InjectionThreatProtectionAssertion
      // 0cd: invokevirtual com/l7tech/policy/assertion/InjectionThreatProtectionAssertion.isIncludeUrlQueryString ()Z
      // 0d0: ifeq 0e5
      // 0d3: goto 0da
      // 0d6: invokestatic com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0d9: athrow
      // 0da: aload 0
      // 0db: invokevirtual com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.logAndAuditMessageNotHttp ()V
      // 0de: goto 0e5
      // 0e1: invokestatic com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0e4: athrow
      // 0e5: aload 0
      // 0e6: getfield com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 0e9: checkcast com/l7tech/policy/assertion/InjectionThreatProtectionAssertion
      // 0ec: invokevirtual com/l7tech/policy/assertion/InjectionThreatProtectionAssertion.isIncludeBody ()Z
      // 0ef: ifeq 0fa
      // 0f2: aload 0
      // 0f3: aload 2
      // 0f4: aload 3
      // 0f5: invokevirtual com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.scanBody (Lcom/l7tech/message/Message;Ljava/lang/String;)Lcom/l7tech/policy/assertion/AssertionStatus;
      // 0f8: astore 6
      // 0fa: aload 6
      // 0fc: getstatic com/l7tech/policy/assertion/AssertionStatus.NONE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 0ff: if_acmpeq 10d
      // 102: aload 0
      // 103: invokevirtual com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.logAndAuditAttackRejected ()V
      // 106: goto 10d
      // 109: invokestatic com/l7tech/server/policy/assertion/ServerInjectionThreatProtectionAssertion.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 10c: athrow
      // 10d: aload 6
      // 10f: areturn
      // try (5 -> 10): 11 java/io/IOException
      // try (8 -> 17): 17 java/io/IOException
      // try (25 -> 30): 31 java/io/IOException
      // try (28 -> 37): 37 java/io/IOException
      // try (41 -> 49): 50 java/io/IOException
      // try (56 -> 63): 63 java/io/IOException
      // try (74 -> 81): 81 java/io/IOException
      // try (83 -> 93): 94 java/io/IOException
      // try (88 -> 98): 99 java/io/IOException
      // try (111 -> 116): 117 java/io/IOException
   }

   protected AssertionStatus scanHttpRequestUrlPath(HttpServletRequestKnob var1) throws IOException {
      this.logAndAuditScanningUrlPath();
      StringBuilder var2 = new StringBuilder();
      String var3 = var1.getRequestUri();
      String var4 = URLDecoder.decode(var3, g[0]);
      String var5 = this.scan(var4, var2);

      try {
         if (var5 != null) {
            this.logAndAuditAttackDetectedInUrlPath(var2, var3, var5);
            return this.getBadMessageStatus();
         }
      } catch (IOException var6) {
         throw b(var6);
      }

      return AssertionStatus.NONE;
   }

   protected AssertionStatus scanHttpRequestUrlQueryString(HttpServletRequestKnob var1) {
      this.logAndAuditScanningUrlQueryString();
      StringBuilder var2 = new StringBuilder();

      Map var3;
      try {
         var3 = var1.getRawQueryParameterMap();
      } catch (IllegalArgumentException var12) {
         this.logAndAuditCannotParse(g[1], var12.getMessage());
         return this.getBadMessageStatus();
      }

      for (Entry var5 : var3.entrySet()) {
         String var6 = (String)var5.getKey();

         for (String var10 : (String[])var5.getValue()) {
            String var11 = this.scan(var10, var2);

            try {
               if (var11 != null) {
                  this.logAndAuditAttackDetectedInQueryParameter(var2, var6, var11);
                  return this.getBadMessageStatus();
               }
            } catch (IllegalArgumentException var13) {
               throw b(var13);
            }
         }
      }

      return AssertionStatus.NONE;
   }

   protected abstract AssertionStatus scanBody(Message var1, String var2) throws IOException;

   protected abstract String scan(String var1, StringBuilder var2);

   protected abstract void logAndAuditRequestAlreadyRouted();

   protected abstract void logAndAuditResponseNotRouted();

   protected abstract void logAndAuditMessageNotHttp();

   protected abstract void logAndAuditScanningUrlPath();

   protected abstract void logAndAuditAttackDetectedInUrlPath(StringBuilder var1, String var2, String var3);

   protected abstract void logAndAuditScanningUrlQueryString();

   protected abstract void logAndAuditAttackDetectedInQueryParameter(StringBuilder var1, String var2, String var3);

   protected abstract void logAndAuditAttackRejected();

   protected abstract void logAndAuditCannotParse(String var1, String var2);

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

   static {
      String[] var5 = new String[2];
      int var3 = 0;
      String var2 = "L\u0010\n<}\u000bK!=d \u0019\r9\u0011\u001e]";
      int var4 = "L\u0010\n<}\u000bK!=d \u0019\r9\u0011\u001e]".length();
      char var1 = 5;
      int var0 = -1;

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

         var1 = var2.charAt(var0);
      }
   }

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

      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 -> 49;
            case 1 -> 108;
            case 2 -> 100;
            case 3 -> 57;
            case 4 -> 109;
            case 5 -> 66;
            default -> 81;
         });
      }

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