import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.Proxy.Type;
import java.nio.charset.Charset;
import java.util.List;

public class Class436_Sub1 extends Class436 {

   ProxySelector aProxySelector7983 = ProxySelector.getDefault();
   static final String aString7984 = "java.net.useSystemProxies";


   public Socket method7341() throws IOException {
      boolean var1 = Boolean.parseBoolean(System.getProperty("java.net.useSystemProxies"));
      if(!var1) {
         System.setProperty("java.net.useSystemProxies", "true");
      }

      boolean var2 = this.anInt5436 * 342437023 == 443;

      List var3;
      List var4;
      try {
         var3 = this.aProxySelector7983.select(new URI((var2?"https":"http") + "://" + this.aString5437));
         var4 = this.aProxySelector7983.select(new URI((var2?"http":"https") + "://" + this.aString5437));
      } catch (URISyntaxException var14) {
         return this.method7346(-599350594);
      }

      var3.addAll(var4);
      Object[] var5 = var3.toArray();
      IOException_Sub1 var6 = null;
      Object[] var7 = var5;

      for(int var8 = 0; var8 < var7.length; ++var8) {
         Object var9 = var7[var8];
         Proxy var10 = (Proxy)var9;

         try {
            Socket var11 = this.method12807(var10, (short)30832);
            if(var11 != null) {
               return var11;
            }
         } catch (IOException_Sub1 var12) {
            var6 = var12;
         } catch (IOException var13) {
            ;
         }
      }

      if(var6 != null) {
         throw var6;
      } else {
         return this.method7346(-599350594);
      }
   }

   public Socket method7342(byte var1) throws IOException {
      boolean var2 = Boolean.parseBoolean(System.getProperty("java.net.useSystemProxies"));
      if(!var2) {
         System.setProperty("java.net.useSystemProxies", "true");
      }

      boolean var3 = this.anInt5436 * 342437023 == 443;

      List var4;
      List var5;
      try {
         var4 = this.aProxySelector7983.select(new URI((var3?"https":"http") + "://" + this.aString5437));
         var5 = this.aProxySelector7983.select(new URI((var3?"http":"https") + "://" + this.aString5437));
      } catch (URISyntaxException var15) {
         return this.method7346(-599350594);
      }

      var4.addAll(var5);
      Object[] var6 = var4.toArray();
      IOException_Sub1 var7 = null;
      Object[] var8 = var6;

      for(int var9 = 0; var9 < var8.length; ++var9) {
         Object var10 = var8[var9];
         Proxy var11 = (Proxy)var10;

         try {
            Socket var12 = this.method12807(var11, (short)5400);
            if(var12 != null) {
               return var12;
            }
         } catch (IOException_Sub1 var13) {
            var7 = var13;
         } catch (IOException var14) {
            ;
         }
      }

      if(var7 != null) {
         throw var7;
      } else {
         return this.method7346(-599350594);
      }
   }

   Socket method12807(Proxy var1, short var2) throws IOException {
      if(var1.type() == Type.DIRECT) {
         return this.method7346(-599350594);
      } else {
         SocketAddress var3 = var1.address();
         if(!(var3 instanceof InetSocketAddress)) {
            return null;
         } else {
            InetSocketAddress var4 = (InetSocketAddress)var3;
            if(var1.type() == Type.HTTP) {
               String var15 = null;

               try {
                  Class var6 = Class.forName("sun.net.www.protocol.http.AuthenticationInfo");
                  Method var7 = var6.getDeclaredMethod("getProxyAuth", new Class[]{String.class, Integer.TYPE});
                  var7.setAccessible(true);
                  Object var8 = var7.invoke((Object)null, new Object[]{var4.getHostName(), new Integer(var4.getPort())});
                  if(null != var8) {
                     Method var9 = var6.getDeclaredMethod("supportsPreemptiveAuthorization", new Class[0]);
                     var9.setAccessible(true);
                     if(((Boolean)var9.invoke(var8, new Object[0])).booleanValue()) {
                        Method var10 = var6.getDeclaredMethod("getHeaderName", new Class[0]);
                        var10.setAccessible(true);
                        Method var11 = var6.getDeclaredMethod("getHeaderValue", new Class[]{URL.class, String.class});
                        var11.setAccessible(true);
                        String var12 = (String)var10.invoke(var8, new Object[0]);
                        String var13 = (String)var11.invoke(var8, new Object[]{new URL("https://" + this.aString5437 + "/"), "https"});
                        var15 = var12 + ": " + var13;
                     }
                  }
               } catch (Exception var14) {
                  ;
               }

               return this.method12808(var4.getHostName(), var4.getPort(), var15, (byte)-103);
            } else if(var1.type() == Type.SOCKS) {
               Socket var5 = new Socket(var1);
               var5.connect(new InetSocketAddress(this.aString5437, this.anInt5436 * 342437023));
               return var5;
            } else {
               return null;
            }
         }
      }
   }

   public Socket method7350() throws IOException {
      boolean var1 = Boolean.parseBoolean(System.getProperty("java.net.useSystemProxies"));
      if(!var1) {
         System.setProperty("java.net.useSystemProxies", "true");
      }

      boolean var2 = this.anInt5436 * 342437023 == 443;

      List var3;
      List var4;
      try {
         var3 = this.aProxySelector7983.select(new URI((var2?"https":"http") + "://" + this.aString5437));
         var4 = this.aProxySelector7983.select(new URI((var2?"http":"https") + "://" + this.aString5437));
      } catch (URISyntaxException var14) {
         return this.method7346(-599350594);
      }

      var3.addAll(var4);
      Object[] var5 = var3.toArray();
      IOException_Sub1 var6 = null;
      Object[] var7 = var5;

      for(int var8 = 0; var8 < var7.length; ++var8) {
         Object var9 = var7[var8];
         Proxy var10 = (Proxy)var9;

         try {
            Socket var11 = this.method12807(var10, (short)8);
            if(var11 != null) {
               return var11;
            }
         } catch (IOException_Sub1 var12) {
            var6 = var12;
         } catch (IOException var13) {
            ;
         }
      }

      if(var6 != null) {
         throw var6;
      } else {
         return this.method7346(-599350594);
      }
   }

   Socket method12808(String var1, int var2, String var3, byte var4) throws IOException {
      Socket var5 = new Socket(var1, var2);
      var5.setSoTimeout(10000);
      OutputStream var6 = var5.getOutputStream();
      if(var3 == null) {
         var6.write(("CONNECT " + this.aString5437 + ":" + this.anInt5436 * 342437023 + " HTTP/1.0\n\n").getBytes(Charset.forName("ISO-8859-1")));
      } else {
         var6.write(("CONNECT " + this.aString5437 + ":" + this.anInt5436 * 342437023 + " HTTP/1.0\n" + var3 + "\n\n").getBytes(Charset.forName("ISO-8859-1")));
      }

      var6.flush();
      BufferedReader var7 = new BufferedReader(new InputStreamReader(var5.getInputStream()));
      String var8 = var7.readLine();
      if(null != var8) {
         if(var8.startsWith("HTTP/1.0 200") || var8.startsWith("HTTP/1.1 200")) {
            return var5;
         }

         if(var8.startsWith("HTTP/1.0 407") || var8.startsWith("HTTP/1.1 407")) {
            int var9 = 0;
            String var10 = "proxy-authenticate: ";

            for(var8 = var7.readLine(); var8 != null && var9 < 50; ++var9) {
               if(var8.toLowerCase().startsWith(var10)) {
                  var8 = var8.substring(var10.length()).trim();
                  int var11 = var8.indexOf(32);
                  if(var11 != -1) {
                     var8 = var8.substring(0, var11);
                  }

                  throw new IOException_Sub1(var8);
               }

               var8 = var7.readLine();
            }

            throw new IOException_Sub1("");
         }
      }

      var6.close();
      var7.close();
      var5.close();
      return null;
   }

   Socket method12809(Proxy var1) throws IOException {
      if(var1.type() == Type.DIRECT) {
         return this.method7346(-599350594);
      } else {
         SocketAddress var2 = var1.address();
         if(!(var2 instanceof InetSocketAddress)) {
            return null;
         } else {
            InetSocketAddress var3 = (InetSocketAddress)var2;
            if(var1.type() == Type.HTTP) {
               String var14 = null;

               try {
                  Class var5 = Class.forName("sun.net.www.protocol.http.AuthenticationInfo");
                  Method var6 = var5.getDeclaredMethod("getProxyAuth", new Class[]{String.class, Integer.TYPE});
                  var6.setAccessible(true);
                  Object var7 = var6.invoke((Object)null, new Object[]{var3.getHostName(), new Integer(var3.getPort())});
                  if(null != var7) {
                     Method var8 = var5.getDeclaredMethod("supportsPreemptiveAuthorization", new Class[0]);
                     var8.setAccessible(true);
                     if(((Boolean)var8.invoke(var7, new Object[0])).booleanValue()) {
                        Method var9 = var5.getDeclaredMethod("getHeaderName", new Class[0]);
                        var9.setAccessible(true);
                        Method var10 = var5.getDeclaredMethod("getHeaderValue", new Class[]{URL.class, String.class});
                        var10.setAccessible(true);
                        String var11 = (String)var9.invoke(var7, new Object[0]);
                        String var12 = (String)var10.invoke(var7, new Object[]{new URL("https://" + this.aString5437 + "/"), "https"});
                        var14 = var11 + ": " + var12;
                     }
                  }
               } catch (Exception var13) {
                  ;
               }

               return this.method12808(var3.getHostName(), var3.getPort(), var14, (byte)22);
            } else if(var1.type() == Type.SOCKS) {
               Socket var4 = new Socket(var1);
               var4.connect(new InetSocketAddress(this.aString5437, this.anInt5436 * 342437023));
               return var4;
            } else {
               return null;
            }
         }
      }
   }

   Socket method12810(Proxy var1) throws IOException {
      if(var1.type() == Type.DIRECT) {
         return this.method7346(-599350594);
      } else {
         SocketAddress var2 = var1.address();
         if(!(var2 instanceof InetSocketAddress)) {
            return null;
         } else {
            InetSocketAddress var3 = (InetSocketAddress)var2;
            if(var1.type() == Type.HTTP) {
               String var14 = null;

               try {
                  Class var5 = Class.forName("sun.net.www.protocol.http.AuthenticationInfo");
                  Method var6 = var5.getDeclaredMethod("getProxyAuth", new Class[]{String.class, Integer.TYPE});
                  var6.setAccessible(true);
                  Object var7 = var6.invoke((Object)null, new Object[]{var3.getHostName(), new Integer(var3.getPort())});
                  if(null != var7) {
                     Method var8 = var5.getDeclaredMethod("supportsPreemptiveAuthorization", new Class[0]);
                     var8.setAccessible(true);
                     if(((Boolean)var8.invoke(var7, new Object[0])).booleanValue()) {
                        Method var9 = var5.getDeclaredMethod("getHeaderName", new Class[0]);
                        var9.setAccessible(true);
                        Method var10 = var5.getDeclaredMethod("getHeaderValue", new Class[]{URL.class, String.class});
                        var10.setAccessible(true);
                        String var11 = (String)var9.invoke(var7, new Object[0]);
                        String var12 = (String)var10.invoke(var7, new Object[]{new URL("https://" + this.aString5437 + "/"), "https"});
                        var14 = var11 + ": " + var12;
                     }
                  }
               } catch (Exception var13) {
                  ;
               }

               return this.method12808(var3.getHostName(), var3.getPort(), var14, (byte)29);
            } else if(var1.type() == Type.SOCKS) {
               Socket var4 = new Socket(var1);
               var4.connect(new InetSocketAddress(this.aString5437, this.anInt5436 * 342437023));
               return var4;
            } else {
               return null;
            }
         }
      }
   }

   Socket method12811(Proxy var1) throws IOException {
      if(var1.type() == Type.DIRECT) {
         return this.method7346(-599350594);
      } else {
         SocketAddress var2 = var1.address();
         if(!(var2 instanceof InetSocketAddress)) {
            return null;
         } else {
            InetSocketAddress var3 = (InetSocketAddress)var2;
            if(var1.type() == Type.HTTP) {
               String var14 = null;

               try {
                  Class var5 = Class.forName("sun.net.www.protocol.http.AuthenticationInfo");
                  Method var6 = var5.getDeclaredMethod("getProxyAuth", new Class[]{String.class, Integer.TYPE});
                  var6.setAccessible(true);
                  Object var7 = var6.invoke((Object)null, new Object[]{var3.getHostName(), new Integer(var3.getPort())});
                  if(null != var7) {
                     Method var8 = var5.getDeclaredMethod("supportsPreemptiveAuthorization", new Class[0]);
                     var8.setAccessible(true);
                     if(((Boolean)var8.invoke(var7, new Object[0])).booleanValue()) {
                        Method var9 = var5.getDeclaredMethod("getHeaderName", new Class[0]);
                        var9.setAccessible(true);
                        Method var10 = var5.getDeclaredMethod("getHeaderValue", new Class[]{URL.class, String.class});
                        var10.setAccessible(true);
                        String var11 = (String)var9.invoke(var7, new Object[0]);
                        String var12 = (String)var10.invoke(var7, new Object[]{new URL("https://" + this.aString5437 + "/"), "https"});
                        var14 = var11 + ": " + var12;
                     }
                  }
               } catch (Exception var13) {
                  ;
               }

               return this.method12808(var3.getHostName(), var3.getPort(), var14, (byte)-77);
            } else if(var1.type() == Type.SOCKS) {
               Socket var4 = new Socket(var1);
               var4.connect(new InetSocketAddress(this.aString5437, this.anInt5436 * 342437023));
               return var4;
            } else {
               return null;
            }
         }
      }
   }

   Socket method12812(String var1, int var2, String var3) throws IOException {
      Socket var4 = new Socket(var1, var2);
      var4.setSoTimeout(10000);
      OutputStream var5 = var4.getOutputStream();
      if(var3 == null) {
         var5.write(("CONNECT " + this.aString5437 + ":" + this.anInt5436 * 342437023 + " HTTP/1.0\n\n").getBytes(Charset.forName("ISO-8859-1")));
      } else {
         var5.write(("CONNECT " + this.aString5437 + ":" + this.anInt5436 * 342437023 + " HTTP/1.0\n" + var3 + "\n\n").getBytes(Charset.forName("ISO-8859-1")));
      }

      var5.flush();
      BufferedReader var6 = new BufferedReader(new InputStreamReader(var4.getInputStream()));
      String var7 = var6.readLine();
      if(null != var7) {
         if(var7.startsWith("HTTP/1.0 200") || var7.startsWith("HTTP/1.1 200")) {
            return var4;
         }

         if(var7.startsWith("HTTP/1.0 407") || var7.startsWith("HTTP/1.1 407")) {
            int var8 = 0;
            String var9 = "proxy-authenticate: ";

            for(var7 = var6.readLine(); var7 != null && var8 < 50; ++var8) {
               if(var7.toLowerCase().startsWith(var9)) {
                  var7 = var7.substring(var9.length()).trim();
                  int var10 = var7.indexOf(32);
                  if(var10 != -1) {
                     var7 = var7.substring(0, var10);
                  }

                  throw new IOException_Sub1(var7);
               }

               var7 = var6.readLine();
            }

            throw new IOException_Sub1("");
         }
      }

      var5.close();
      var6.close();
      var4.close();
      return null;
   }

   public static void method12813(int var0) {
      Class564 var1 = Class540.aClass564_7317;
      synchronized(var1) {
         Class540.aClass564_7317.method11968((short)-22286);
      }

      var1 = Class540.aClass564_7319;
      synchronized(var1) {
         Class540.aClass564_7319.method11968((short)-12138);
      }
   }

   static String method12814(String var0, byte var1) {
      String var2 = null;
      int var3 = var0.indexOf("--> ");
      if(var3 >= 0) {
         var2 = var0.substring(0, 4 + var3);
         var0 = var0.substring(4 + var3);
      }

      if(var0.startsWith("directlogin ")) {
         int var4 = var0.indexOf(" ", "directlogin ".length());
         if(var4 >= 0) {
            int var5 = var0.length();
            var0 = var0.substring(0, var4) + " ";

            for(int var6 = var4 + 1; var6 < var5; ++var6) {
               var0 = var0 + "*";
            }
         }
      }

      return var2 != null?var2 + var0:var0;
   }
}
