package p447.p448.p449;

import java.net.Authenticator;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import kotlin.TypeCastException;
import kotlin.jvm.internal.DefaultConstructorMarker;
import p402.p403.C6560;
import p402.p403.C6563;
import p402.p411.p413.C6635;
import p402.p420.C6703;
import p447.AbstractC6930;
import p447.C6860;
import p447.C6875;
import p447.C6889;
import p447.C6905;
import p447.C6908;
import p447.C6926;
import p447.C6933;
import p447.C6938;
import p447.InterfaceC6861;
import p447.InterfaceC6891;
import p447.p448.C6943;
import p447.p448.p453.C6985;

/* JADX INFO: renamed from: ސ.ޣ.ށ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C6945 implements InterfaceC6861 {

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final InterfaceC6891 f20199;

    /* JADX WARN: Multi-variable type inference failed */
    public C6945() {
        this(null, 1, 0 == true ? 1 : 0);
    }

    public /* synthetic */ C6945(InterfaceC6891 interfaceC6891, int i, DefaultConstructorMarker defaultConstructorMarker) {
        interfaceC6891 = (i & 1) != 0 ? InterfaceC6891.f19993 : interfaceC6891;
        if (interfaceC6891 != null) {
            this.f20199 = interfaceC6891;
        } else {
            C6635.m9824("defaultDns");
            throw null;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final InetAddress m10179(Proxy proxy, C6908 c6908, InterfaceC6891 interfaceC6891) {
        Proxy.Type type = proxy.type();
        if (type != null && C6944.f20198[type.ordinal()] == 1) {
            return (InetAddress) C6560.m9772((List) interfaceC6891.mo10057(c6908.f20017));
        }
        SocketAddress socketAddressAddress = proxy.address();
        if (socketAddressAddress == null) {
            throw new TypeCastException("null cannot be cast to non-null type java.net.InetSocketAddress");
        }
        InetAddress address = ((InetSocketAddress) socketAddressAddress).getAddress();
        C6635.m9823((Object) address, "(address() as InetSocketAddress).address");
        return address;
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x002a  */
    /* JADX WARN: Removed duplicated region for block: B:14:0x002c  */
    /* JADX WARN: Removed duplicated region for block: B:19:0x0034  */
    /* JADX WARN: Removed duplicated region for block: B:23:0x0040  */
    @Override // p447.InterfaceC6861
    /* JADX INFO: renamed from: ֏ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public C6926 mo2523(C6938 c6938, C6933 c6933) {
        String str;
        List<C6875> listM10259;
        Proxy proxy;
        InterfaceC6891 interfaceC6891;
        PasswordAuthentication passwordAuthenticationRequestPasswordAuthentication;
        Charset charsetForName;
        C6860 c6860;
        if (c6933 == null) {
            C6635.m9824("response");
            throw null;
        }
        C6905 c6905 = c6933.f20151;
        int i = c6933.f20149;
        if (i == 401) {
            str = "WWW-Authenticate";
        } else {
            if (i != 407) {
                listM10259 = C6563.f19343;
                C6926 c6926 = c6933.f20146;
                C6908 c6908 = c6926.f20128;
                boolean z = true;
                boolean z2 = c6933.f20149 != 407;
                if (c6938 != null || (proxy = c6938.f20177) == null) {
                    proxy = Proxy.NO_PROXY;
                }
                for (C6875 c6875 : listM10259) {
                    if (C6703.m9905("Basic", c6875.f19937, z)) {
                        if (c6938 == null || (c6860 = c6938.f20176) == null || (interfaceC6891 = c6860.f19903) == null) {
                            interfaceC6891 = this.f20199;
                        }
                        if (z2) {
                            SocketAddress socketAddressAddress = proxy.address();
                            if (socketAddressAddress == null) {
                                throw new TypeCastException("null cannot be cast to non-null type java.net.InetSocketAddress");
                            }
                            InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddressAddress;
                            String hostName = inetSocketAddress.getHostName();
                            C6635.m9823((Object) proxy, "proxy");
                            try {
                                passwordAuthenticationRequestPasswordAuthentication = Authenticator.requestPasswordAuthentication(hostName, m10179(proxy, c6908, interfaceC6891), inetSocketAddress.getPort(), c6908.f20014, c6875.f19936.get("realm"), c6875.f19937, new URL(c6908.f20022), Authenticator.RequestorType.PROXY);
                            } catch (MalformedURLException e) {
                                throw new RuntimeException(e);
                            }
                        } else {
                            String str2 = c6908.f20017;
                            C6635.m9823((Object) proxy, "proxy");
                            try {
                                passwordAuthenticationRequestPasswordAuthentication = Authenticator.requestPasswordAuthentication(str2, m10179(proxy, c6908, interfaceC6891), c6908.f20018, c6908.f20014, c6875.f19936.get("realm"), c6875.f19937, new URL(c6908.f20022), Authenticator.RequestorType.SERVER);
                            } catch (MalformedURLException e2) {
                                throw new RuntimeException(e2);
                            }
                        }
                        if (passwordAuthenticationRequestPasswordAuthentication != null) {
                            String str3 = z2 ? "Proxy-Authorization" : "Authorization";
                            String userName = passwordAuthenticationRequestPasswordAuthentication.getUserName();
                            C6635.m9823((Object) userName, "auth.userName");
                            char[] password = passwordAuthenticationRequestPasswordAuthentication.getPassword();
                            C6635.m9823((Object) password, "auth.password");
                            String str4 = new String(password);
                            String str5 = c6875.f19936.get("charset");
                            if (str5 != null) {
                                try {
                                    charsetForName = Charset.forName(str5);
                                    C6635.m9823((Object) charsetForName, "Charset.forName(charset)");
                                } catch (Exception unused) {
                                    charsetForName = StandardCharsets.ISO_8859_1;
                                    C6635.m9823((Object) charsetForName, "ISO_8859_1");
                                }
                            } else {
                                charsetForName = StandardCharsets.ISO_8859_1;
                                C6635.m9823((Object) charsetForName, "ISO_8859_1");
                            }
                            String strM10049 = C6889.m10049(userName, str4, charsetForName);
                            new LinkedHashMap();
                            C6908 c69082 = c6926.f20128;
                            String str6 = c6926.f20129;
                            AbstractC6930 abstractC6930 = c6926.f20131;
                            Map linkedHashMap = c6926.f20132.isEmpty() ? new LinkedHashMap() : C6560.m9783(c6926.f20132);
                            C6905.C6906 c6906M10069 = c6926.f20130.m10069();
                            if (strM10049 == null) {
                                C6635.m9824("value");
                                throw null;
                            }
                            c6906M10069.m10075(str3, strM10049);
                            if (c69082 != null) {
                                return new C6926(c69082, str6, c6906M10069.m10073(), abstractC6930, C6943.m10161(linkedHashMap));
                            }
                            throw new IllegalStateException("url == null".toString());
                        }
                    }
                    z = true;
                }
                return null;
            }
            str = "Proxy-Authenticate";
        }
        listM10259 = C6985.m10259(c6905, str);
        C6926 c69262 = c6933.f20146;
        C6908 c69083 = c69262.f20128;
        boolean z3 = true;
        if (c6933.f20149 != 407) {
        }
        if (c6938 != null) {
            proxy = Proxy.NO_PROXY;
        }
        while (r4.hasNext()) {
        }
        return null;
    }
}
