content: package okhttp3.internal.authenticator;
  
  import java.io.IOException;
  import java.net.Authenticator;
  import java.net.InetAddress;
  import java.net.InetSocketAddress;
  import java.net.PasswordAuthentication;
  import java.net.Proxy;
  import java.net.SocketAddress;
  import java.util.List;
  import kotlin.Metadata;
  import kotlin.collections.CollectionsKt;
  import kotlin.jvm.internal.DefaultConstructorMarker;
  import kotlin.jvm.internal.Intrinsics;
  import kotlin.text.StringsKt;
  import mt.Log1F380D;
  import okhttp3.Address;
  import okhttp3.Authenticator;
  import okhttp3.Challenge;
  import okhttp3.Credentials;
  import okhttp3.Dns;
  import okhttp3.HttpUrl;
  import okhttp3.Request;
  import okhttp3.Response;
  import okhttp3.Route;
  
  @Metadata(bv = {1, 0, 3}, d1 = {"\u00006\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\u0018\u00002\u00020\u0001B\u000f\u0012\b\b\u0002\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u001c\u0010\u0005\u001a\u0004\u0018\u00010\u00062\b\u0010\u0007\u001a\u0004\u0018\u00010\b2\u0006\u0010\t\u001a\u00020\nH\u0016J\u001c\u0010\u000b\u001a\u00020\f*\u00020\r2\u0006\u0010\u000e\u001a\u00020\u000f2\u0006\u0010\u0010\u001a\u00020\u0003H\u0002R\u000e\u0010\u0002\u001a\u00020\u0003X\u0004¢\u0006\u0002\n\u0000¨\u0006\u0011"}, d2 = {"Lokhttp3/internal/authenticator/JavaNetAuthenticator;", "Lokhttp3/Authenticator;", "defaultDns", "Lokhttp3/Dns;", "(Lokhttp3/Dns;)V", "authenticate", "Lokhttp3/Request;", "route", "Lokhttp3/Route;", "response", "Lokhttp3/Response;", "connectToInetAddress", "Ljava/net/InetAddress;", "Ljava/net/Proxy;", "url", "Lokhttp3/HttpUrl;", "dns", "okhttp"}, k = 1, mv = {1, 4, 0})
  /* compiled from: 01C3 */
  public final class JavaNetAuthenticator implements Authenticator {
      private final Dns defaultDns;
  
      @Metadata(bv = {1, 0, 3}, k = 3, mv = {1, 4, 0})
      public final /* synthetic */ class WhenMappings {
          public static final /* synthetic */ int[] $EnumSwitchMapping$0;
  
          static {
              int[] iArr = new int[Proxy.Type.values().length];
              $EnumSwitchMapping$0 = iArr;
              iArr[Proxy.Type.DIRECT.ordinal()] = 1;
          }
      }
  
      public JavaNetAuthenticator() {
          this((Dns) null, 1, (DefaultConstructorMarker) null);
      }
  
      public JavaNetAuthenticator(Dns defaultDns2) {
          Intrinsics.checkNotNullParameter(defaultDns2, "defaultDns");
          this.defaultDns = defaultDns2;
      }
  
      /* JADX INFO: this call moved to the top of the method (can break code semantics) */
      public /* synthetic */ JavaNetAuthenticator(Dns dns, int i, DefaultConstructorMarker defaultConstructorMarker) {
          this((i & 1) != 0 ? Dns.SYSTEM : dns);
      }
  
      private final InetAddress connectToInetAddress(Proxy $this$connectToInetAddress, HttpUrl url, Dns dns) throws IOException {
          Proxy.Type type = $this$connectToInetAddress.type();
          if (type != null) {
              switch (WhenMappings.$EnumSwitchMapping$0[type.ordinal()]) {
                  case 1:
                      return (InetAddress) CollectionsKt.first(dns.lookup(url.host()));
              }
          }
          SocketAddress address = $this$connectToInetAddress.address();
          if (address != null) {
              InetAddress address2 = ((InetSocketAddress) address).getAddress();
              Intrinsics.checkNotNullExpressionValue(address2, "(address() as InetSocketAddress).address");
              return address2;
          }
          throw new NullPointerException("null cannot be cast to non-null type java.net.InetSocketAddress");
      }
  
      public Request authenticate(Route route, Response response) throws IOException {
          Proxy proxy;
          Dns dns;
          PasswordAuthentication passwordAuthentication;
          Address address;
          Intrinsics.checkNotNullParameter(response, "response");
          List<Challenge> challenges = response.challenges();
          Request request = response.request();
          HttpUrl url = request.url();
          boolean z = response.code() == 407;
          if (route == null || (proxy = route.proxy()) == null) {
              proxy = Proxy.NO_PROXY;
          }
          for (Challenge next : challenges) {
              if (StringsKt.equals("Basic", next.scheme(), true)) {
                  if (route == null || (address = route.address()) == null || (dns = address.dns()) == null) {
                      dns = this.defaultDns;
                  }
                  if (z) {
                      SocketAddress address2 = proxy.address();
                      if (address2 != null) {
                          InetSocketAddress inetSocketAddress = (InetSocketAddress) address2;
                          String hostName = inetSocketAddress.getHostName();
                          Intrinsics.checkNotNullExpressionValue(proxy, "proxy");
                          passwordAuthentication = java.net.Authenticator.requestPasswordAuthentication(hostName, connectToInetAddress(proxy, url, dns), inetSocketAddress.getPort(), url.scheme(), next.realm(), next.scheme(), url.url(), Authenticator.RequestorType.PROXY);
                      } else {
                          throw new NullPointerException("null cannot be cast to non-null type java.net.InetSocketAddress");
                      }
                  } else {
                      String host = url.host();
                      Intrinsics.checkNotNullExpressionValue(proxy, "proxy");
                      passwordAuthentication = java.net.Authenticator.requestPasswordAuthentication(host, connectToInetAddress(proxy, url, dns), url.port(), url.scheme(), next.realm(), next.scheme(), url.url(), Authenticator.RequestorType.SERVER);
                  }
                  if (passwordAuthentication != null) {
                      String str = z ? "Proxy-Authorization" : "Authorization";
                      String userName = passwordAuthentication.getUserName();
                      Intrinsics.checkNotNullExpressionValue(userName, "auth.userName");
                      char[] password = passwordAuthentication.getPassword();
                      Intrinsics.checkNotNullExpressionValue(password, "auth.password");
                      String str2 = new String(password);
                      Log1F380D.a((Object) str2);
                      String basic = Credentials.basic(userName, str2, next.charset());
                      Log1F380D.a((Object) basic);
                      return request.newBuilder().header(str, basic).build();
                  }
              }
          }
          return null;
      }
  }
  