package com.l7tech.common.http.prov.apache.components;

import java.io.IOException;
import java.net.Socket;
import java.util.Collections;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SNIHostName;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocket;
import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
import org.apache.hc.client5.http.ssl.HostnameVerificationPolicy;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.io.Closer;
import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
import org.jetbrains.annotations.NotNull;

public class SecureClientTlsStrategy extends DefaultClientTlsStrategy {
   Logger a = Logger.getLogger(SecureClientTlsStrategy.class.getName());
   private static final String b;
   private static final Logger c;
   private static final Pattern d;
   private String e;
   private SSLContext f;
   private final String[] g;
   private final String[] h;
   private final HostnameVerificationPolicy i;
   private final boolean j;
   private static final String[] k;

   public SecureClientTlsStrategy(SSLContext var1, String[] var2, String[] var3, SSLBufferMode var4, HostnameVerifier var5, String var6, boolean var7) {
      super(var1, var2, var3, var4, HostnameVerificationPolicy.CLIENT, var5);
      this.f = var1;
      this.g = var2;
      this.h = var3;
      this.i = HostnameVerificationPolicy.CLIENT;
      this.e = var6;
      this.j = var7;
   }

   protected void initializeSocket(SSLSocket var1) {
      try {
         if (var1 != null) {
            this.a(var1);
            this.b(var1);
         }
      } catch (RuntimeException var2) {
         throw a(var2);
      }
   }

   private void a(SSLSocket var1) {
      String[] var4 = k;
      String[] var2 = a(var4[5]);
      String[] var3 = a(var4[7]);

      try {
         if (var2 != null) {
            var1.setEnabledProtocols(var2);
         }
      } catch (RuntimeException var6) {
         throw a(var6);
      }

      try {
         if (var3 != null) {
            var1.setEnabledCipherSuites(var3);
         }
      } catch (RuntimeException var5) {
         throw a(var5);
      }
   }

   private static String[] a(String param0) {
      // $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:
      // 00: aload 0
      // 01: aconst_null
      // 02: invokestatic com/l7tech/util/ConfigFactory.getProperty (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
      // 05: astore 1
      // 06: aload 1
      // 07: ifnull 19
      // 0a: aload 1
      // 0b: invokevirtual java/lang/String.length ()I
      // 0e: bipush 1
      // 0f: if_icmpge 21
      // 12: goto 19
      // 15: invokestatic com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 18: athrow
      // 19: aconst_null
      // 1a: goto 28
      // 1d: invokestatic com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 20: athrow
      // 21: getstatic com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.d Ljava/util/regex/Pattern;
      // 24: aload 1
      // 25: invokevirtual java/util/regex/Pattern.split (Ljava/lang/CharSequence;)[Ljava/lang/String;
      // 28: areturn
      // try (4 -> 10): 11 java/lang/RuntimeException
      // try (6 -> 15): 15 java/lang/RuntimeException
   }

   private void b(@NotNull SSLSocket var1) {
      try {
         if (var1 == null) {
            a(0);
         }
      } catch (RuntimeException var3) {
         throw a(var3);
      }

      if (this.e != null) {
         SSLParameters var2 = var1.getSSLParameters();
         var2.setServerNames(Collections.singletonList(new SNIHostName(this.e)));
         var1.setSSLParameters(var2);
      }
   }

   public SSLSocket upgrade(Socket var1, String var2, int var3, Object var4, HttpContext var5) throws IOException {
      SSLSocket var6 = (SSLSocket)this.f.getSocketFactory().createSocket(var1, var2, var3, false);
      if (this.j) {
         var6 = (SSLSocket)this.a(var6, k[11], c);
      }

      try {
         this.a(var6, var2, var4);
         return var6;
      } catch (IOException | RuntimeException var8) {
         Closer.closeQuietly(var6);
         throw var8;
      }
   }

   private void a(SSLSocket param1, String param2, Object 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:
      // 00: aload 3
      // 01: instanceof org/apache/hc/client5/http/config/TlsConfig
      // 04: ifeq 12
      // 07: aload 3
      // 08: checkcast org/apache/hc/client5/http/config/TlsConfig
      // 0b: goto 15
      // 0e: invokestatic com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 11: athrow
      // 12: getstatic org/apache/hc/client5/http/config/TlsConfig.DEFAULT Lorg/apache/hc/client5/http/config/TlsConfig;
      // 15: astore 4
      // 17: aload 1
      // 18: invokevirtual javax/net/ssl/SSLSocket.getSSLParameters ()Ljavax/net/ssl/SSLParameters;
      // 1b: astore 5
      // 1d: aload 0
      // 1e: getfield com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.g [Ljava/lang/String;
      // 21: ifnull 34
      // 24: aload 5
      // 26: aload 0
      // 27: getfield com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.g [Ljava/lang/String;
      // 2a: invokevirtual javax/net/ssl/SSLParameters.setProtocols ([Ljava/lang/String;)V
      // 2d: goto 40
      // 30: invokestatic com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 33: athrow
      // 34: aload 5
      // 36: aload 1
      // 37: invokevirtual javax/net/ssl/SSLSocket.getEnabledProtocols ()[Ljava/lang/String;
      // 3a: invokestatic org/apache/hc/core5/http/ssl/TLS.excludeWeak ([Ljava/lang/String;)[Ljava/lang/String;
      // 3d: invokevirtual javax/net/ssl/SSLParameters.setProtocols ([Ljava/lang/String;)V
      // 40: aload 0
      // 41: getfield com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.h [Ljava/lang/String;
      // 44: ifnull 57
      // 47: aload 5
      // 49: aload 0
      // 4a: getfield com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.h [Ljava/lang/String;
      // 4d: invokevirtual javax/net/ssl/SSLParameters.setCipherSuites ([Ljava/lang/String;)V
      // 50: goto 63
      // 53: invokestatic com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 56: athrow
      // 57: aload 5
      // 59: aload 1
      // 5a: invokevirtual javax/net/ssl/SSLSocket.getEnabledCipherSuites ()[Ljava/lang/String;
      // 5d: invokestatic org/apache/hc/core5/http/ssl/TlsCiphers.excludeWeak ([Ljava/lang/String;)[Ljava/lang/String;
      // 60: invokevirtual javax/net/ssl/SSLParameters.setCipherSuites ([Ljava/lang/String;)V
      // 63: aload 0
      // 64: getfield com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.i Lorg/apache/hc/client5/http/ssl/HostnameVerificationPolicy;
      // 67: getstatic org/apache/hc/client5/http/ssl/HostnameVerificationPolicy.BUILTIN Lorg/apache/hc/client5/http/ssl/HostnameVerificationPolicy;
      // 6a: if_acmpeq 7e
      // 6d: aload 0
      // 6e: getfield com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.i Lorg/apache/hc/client5/http/ssl/HostnameVerificationPolicy;
      // 71: getstatic org/apache/hc/client5/http/ssl/HostnameVerificationPolicy.BOTH Lorg/apache/hc/client5/http/ssl/HostnameVerificationPolicy;
      // 74: if_acmpne 90
      // 77: goto 7e
      // 7a: invokestatic com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 7d: athrow
      // 7e: aload 5
      // 80: getstatic org/apache/hc/core5/http/URIScheme.HTTPS Lorg/apache/hc/core5/http/URIScheme;
      // 83: getfield org/apache/hc/core5/http/URIScheme.id Ljava/lang/String;
      // 86: invokevirtual javax/net/ssl/SSLParameters.setEndpointIdentificationAlgorithm (Ljava/lang/String;)V
      // 89: goto 90
      // 8c: invokestatic com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 8f: athrow
      // 90: aload 1
      // 91: aload 5
      // 93: invokevirtual javax/net/ssl/SSLSocket.setSSLParameters (Ljavax/net/ssl/SSLParameters;)V
      // 96: aload 4
      // 98: invokevirtual org/apache/hc/client5/http/config/TlsConfig.getHandshakeTimeout ()Lorg/apache/hc/core5/util/Timeout;
      // 9b: astore 6
      // 9d: aload 6
      // 9f: ifnull b2
      // a2: aload 1
      // a3: aload 6
      // a5: invokevirtual org/apache/hc/core5/util/Timeout.toMillisecondsIntBound ()I
      // a8: invokevirtual javax/net/ssl/SSLSocket.setSoTimeout (I)V
      // ab: goto b2
      // ae: invokestatic com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // b1: athrow
      // b2: aload 0
      // b3: aload 1
      // b4: invokevirtual com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.initializeSocket (Ljavax/net/ssl/SSLSocket;)V
      // b7: aload 0
      // b8: getfield com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.a Ljava/util/logging/Logger;
      // bb: getstatic java/util/logging/Level.FINE Ljava/util/logging/Level;
      // be: getstatic com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.k [Ljava/lang/String;
      // c1: astore 7
      // c3: aload 7
      // c5: bipush 10
      // c7: aaload
      // c8: aload 1
      // c9: invokevirtual javax/net/ssl/SSLSocket.getEnabledProtocols ()[Ljava/lang/String;
      // cc: invokevirtual java/util/logging/Logger.log (Ljava/util/logging/Level;Ljava/lang/String;Ljava/lang/Object;)V
      // cf: aload 0
      // d0: getfield com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.a Ljava/util/logging/Logger;
      // d3: getstatic java/util/logging/Level.FINE Ljava/util/logging/Level;
      // d6: aload 7
      // d8: bipush 2
      // d9: aaload
      // da: aload 1
      // db: invokevirtual javax/net/ssl/SSLSocket.getEnabledCipherSuites ()[Ljava/lang/String;
      // de: invokevirtual java/util/logging/Logger.log (Ljava/util/logging/Level;Ljava/lang/String;Ljava/lang/Object;)V
      // e1: aload 0
      // e2: getfield com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.a Ljava/util/logging/Logger;
      // e5: getstatic java/util/logging/Level.FINE Ljava/util/logging/Level;
      // e8: aload 7
      // ea: bipush 4
      // eb: aaload
      // ec: aload 6
      // ee: invokevirtual java/util/logging/Logger.log (Ljava/util/logging/Level;Ljava/lang/String;Ljava/lang/Object;)V
      // f1: aload 1
      // f2: invokevirtual javax/net/ssl/SSLSocket.startHandshake ()V
      // f5: aload 0
      // f6: aload 2
      // f7: aload 1
      // f8: invokevirtual javax/net/ssl/SSLSocket.getSession ()Ljavax/net/ssl/SSLSession;
      // fb: invokevirtual com/l7tech/common/http/prov/apache/components/SecureClientTlsStrategy.verifySession (Ljava/lang/String;Ljavax/net/ssl/SSLSession;)V
      // fe: return
      // try (0 -> 6): 6 java/io/IOException
      // try (13 -> 21): 21 java/io/IOException
      // try (28 -> 36): 36 java/io/IOException
      // try (43 -> 51): 52 java/io/IOException
      // try (47 -> 58): 59 java/io/IOException
      // try (67 -> 73): 74 java/io/IOException
   }

   private Socket a(Socket var1, String var2, Logger var3) {
      try {
         return var1 instanceof SSLSocket ? new j(this, (SSLSocket)var1, var1, var2, var3) : var1;
      } catch (RuntimeException var4) {
         throw a(var4);
      }
   }

   static {
      String[] var5 = new String[12];
      int var3 = 0;
      String var2 = "\u0016;\b\u0013M%\u001d \u0011MRdG\u001b,\u0014MM6A\b*\u000eML<F\n&\u0012\u0004\u0010;G\n?\u000fMJ!R\u001d*\u0019;!\u001d\u0001R6W^,\u0015\u0013V6A^<\t\nJ6@Do\u0007\u001e\u0007\"<VOb \u0019\u0017-;\u001d\u0011J:]\u0019o\u0014\u0002P7@\u0016.\u0017\u0006\u001e{H\u0003f\u000f\u0016;\b\u0013M}C\f \b\f]<_\r\u0014\u001d \u0012\u0005W4F\f*/\rW\u001eV\n.\u0018\u0002J2\u0012\u0016;\b\u0013M}P\u0017?\u0014\u0006L\u0000F\u0017;\u0019\u0010>?=\u001b\u0016S6]\no\u001a\fLss0 \b-K?_^?\u001d\u0011_>V\n*\u000eC\u0019v@Yo\u0013\u0005\u001ev@Pj\u000fCS&@\no\u0012\fJsQ\u001bo\u0012\u0016R?E\u001d \u0011LRdG\u001b,\u0014L]<^\u0013 \u0012LV'G\u000e`\f\u0011Q%\u001c\u001f?\u001d\u0000V6\u001c\u001d \u0011\u0013Q=V\u0010;\u000fLm6P\u000b=\u0019 R:V\u0010;(\u000fM\u0000G\f.\b\u0006Y*";
      int var4 = "\u0016;\b\u0013M%\u001d \u0011MRdG\u001b,\u0014MM6A\b*\u000eML<F\n&\u0012\u0004\u0010;G\n?\u000fMJ!R\u001d*\u0019;!\u001d\u0001R6W^,\u0015\u0013V6A^<\t\nJ6@Do\u0007\u001e\u0007\"<VOb \u0019\u0017-;\u001d\u0011J:]\u0019o\u0014\u0002P7@\u0016.\u0017\u0006\u001e{H\u0003f\u000f\u0016;\b\u0013M}C\f \b\f]<_\r\u0014\u001d \u0012\u0005W4F\f*/\rW\u001eV\n.\u0018\u0002J2\u0012\u0016;\b\u0013M}P\u0017?\u0014\u0006L\u0000F\u0017;\u0019\u0010>?=\u001b\u0016S6]\no\u001a\fLss0 \b-K?_^?\u001d\u0011_>V\n*\u000eC\u0019v@Yo\u0013\u0005\u001ev@Pj\u000fCS&@\no\u0012\fJsQ\u001bo\u0012\u0016R?E\u001d \u0011LRdG\u001b,\u0014L]<^\u0013 \u0012LV'G\u000e`\f\u0011Q%\u001c\u001f?\u001d\u0000V6\u001c\u001d \u0011\u0013Q=V\u0010;\u000fLm6P\u000b=\u0019 R:V\u0010;(\u000fM\u0000G\f.\b\u0006Y*"
         .length();
      char var1 = 5;
      int var7 = -1;

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

         while (true) {
            String var9 = a(var10000, b(var10001));
            switch (var10002) {
               case 0:
                  var5[var3++] = var9;
                  if ((var7 += var1) >= var4) {
                     k = var5;
                     b = k[0];
                     String[] var8 = k;
                     c = Logger.getLogger(var8[1]);
                     d = Pattern.compile(var8[3]);
                     return;
                  }

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

                  var2 = "d~B^\ri\b\u0001`QS\u0015c\u000fN|P\u0006Aw\u0011\u0005IdWL\u0012";
                  var4 = "d~B^\ri\b\u0001`QS\u0015c\u000fN|P\u0006Aw\u0011\u0005IdWL\u0012".length();
                  var1 = 21;
                  var7 = -1;
            }

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

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

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

      return var10000;
   }

   private static String a(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 -> 98;
            case 1 -> 83;
            case 2 -> 96;
            case 3 -> 127;
            case 4 -> 34;
            case 5 -> 79;
            default -> 47;
         });
      }

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