Rabbit-R1/android (non root)/java/sources/okhttp3/internal/authenticator/JavaNetAuthenticator.java
2024-05-21 17:08:36 -04:00

119 lines
6.5 KiB
Java

package okhttp3.internal.authenticator;
import com.google.common.net.HttpHeaders;
import io.sentry.okhttp.SentryOkHttpEventListener;
import io.sentry.protocol.Request;
import io.sentry.protocol.Response;
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 okhttp3.Address;
import okhttp3.Authenticator;
import okhttp3.Challenge;
import okhttp3.Credentials;
import okhttp3.Dns;
import okhttp3.HttpUrl;
import okhttp3.Route;
/* compiled from: JavaNetAuthenticator.kt */
@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\u0082\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.TYPE, "Lokhttp3/Response;", "connectToInetAddress", "Ljava/net/InetAddress;", "Ljava/net/Proxy;", Request.JsonKeys.URL, "Lokhttp3/HttpUrl;", SentryOkHttpEventListener.DNS_EVENT, "okhttp"}, k = 1, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public final class JavaNetAuthenticator implements Authenticator {
private final Dns defaultDns;
@Metadata(bv = {1, 0, 3}, k = 3, mv = {1, 4, 0})
/* loaded from: classes3.dex */
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;
}
}
/* JADX WARN: Multi-variable type inference failed */
public JavaNetAuthenticator() {
this(null, 1, 0 == true ? 1 : 0);
}
public JavaNetAuthenticator(Dns defaultDns) {
Intrinsics.checkNotNullParameter(defaultDns, "defaultDns");
this.defaultDns = defaultDns;
}
public /* synthetic */ JavaNetAuthenticator(Dns dns, int i, DefaultConstructorMarker defaultConstructorMarker) {
this((i & 1) != 0 ? Dns.SYSTEM : dns);
}
@Override // okhttp3.Authenticator
public okhttp3.Request authenticate(Route route, okhttp3.Response response) throws IOException {
Proxy proxy;
Dns dns;
PasswordAuthentication requestPasswordAuthentication;
Address address;
Intrinsics.checkNotNullParameter(response, "response");
List<Challenge> challenges = response.challenges();
okhttp3.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 challenge : challenges) {
if (StringsKt.equals("Basic", challenge.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) {
throw new NullPointerException("null cannot be cast to non-null type java.net.InetSocketAddress");
}
InetSocketAddress inetSocketAddress = (InetSocketAddress) address2;
String hostName = inetSocketAddress.getHostName();
Intrinsics.checkNotNullExpressionValue(proxy, "proxy");
requestPasswordAuthentication = java.net.Authenticator.requestPasswordAuthentication(hostName, connectToInetAddress(proxy, url, dns), inetSocketAddress.getPort(), url.scheme(), challenge.realm(), challenge.scheme(), url.url(), Authenticator.RequestorType.PROXY);
} else {
String host = url.host();
Intrinsics.checkNotNullExpressionValue(proxy, "proxy");
requestPasswordAuthentication = java.net.Authenticator.requestPasswordAuthentication(host, connectToInetAddress(proxy, url, dns), url.port(), url.scheme(), challenge.realm(), challenge.scheme(), url.url(), Authenticator.RequestorType.SERVER);
}
if (requestPasswordAuthentication != null) {
String str = z ? HttpHeaders.PROXY_AUTHORIZATION : HttpHeaders.AUTHORIZATION;
String userName = requestPasswordAuthentication.getUserName();
Intrinsics.checkNotNullExpressionValue(userName, "auth.userName");
char[] password = requestPasswordAuthentication.getPassword();
Intrinsics.checkNotNullExpressionValue(password, "auth.password");
return request.newBuilder().header(str, Credentials.basic(userName, new String(password), challenge.charset())).build();
}
}
}
return null;
}
private final InetAddress connectToInetAddress(Proxy proxy, HttpUrl httpUrl, Dns dns) throws IOException {
Proxy.Type type = proxy.type();
if (type != null && WhenMappings.$EnumSwitchMapping$0[type.ordinal()] == 1) {
return (InetAddress) CollectionsKt.first((List) dns.lookup(httpUrl.host()));
}
SocketAddress address = proxy.address();
if (address == null) {
throw new NullPointerException("null cannot be cast to non-null type java.net.InetSocketAddress");
}
InetAddress address2 = ((InetSocketAddress) address).getAddress();
Intrinsics.checkNotNullExpressionValue(address2, "(address() as InetSocketAddress).address");
return address2;
}
}