导航菜单

页面标题

页面副标题

bbinstant v6.24.0 - DNSClient.java 源代码

正在查看: bbinstant v6.24.0 应用的 DNSClient.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package de.measite.minidns;

import de.measite.minidns.a;
import de.measite.minidns.b;
import de.measite.minidns.util.CollectionsUtil;
import de.measite.minidns.util.InetAddressUtil;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DNSClient extends de.measite.minidns.a {
    static final List<de.measite.minidns.dnsserverlookup.d> LOOKUP_MECHANISMS = new ArrayList();
    static final Set<Inet4Address> STATIC_IPV4_DNS_SERVERS;
    static final Set<Inet6Address> STATIC_IPV6_DNS_SERVERS;
    private boolean askForDnssec;
    private boolean disableResultFilter;
    private final Set<InetAddress> nonRaServers;

    static class a {
        static final int[] $SwitchMap$de$measite$minidns$AbstractDNSClient$IpVersionSetting;
        static final int[] $SwitchMap$de$measite$minidns$DNSMessage$RESPONSE_CODE;

        static {
            int[] iArr = new int[b.d.values().length];
            $SwitchMap$de$measite$minidns$DNSMessage$RESPONSE_CODE = iArr;
            try {
                iArr[b.d.NO_ERROR.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$de$measite$minidns$DNSMessage$RESPONSE_CODE[b.d.NX_DOMAIN.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            int[] iArr2 = new int[a.b.values().length];
            $SwitchMap$de$measite$minidns$AbstractDNSClient$IpVersionSetting = iArr2;
            try {
                iArr2[a.b.v4v6.ordinal()] = 1;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                $SwitchMap$de$measite$minidns$AbstractDNSClient$IpVersionSetting[a.b.v6v4.ordinal()] = 2;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                $SwitchMap$de$measite$minidns$AbstractDNSClient$IpVersionSetting[a.b.v4only.ordinal()] = 3;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                $SwitchMap$de$measite$minidns$AbstractDNSClient$IpVersionSetting[a.b.v6only.ordinal()] = 4;
            } catch (NoSuchFieldError unused6) {
            }
        }
    }

    static {
        CopyOnWriteArraySet copyOnWriteArraySet = new CopyOnWriteArraySet();
        STATIC_IPV4_DNS_SERVERS = copyOnWriteArraySet;
        STATIC_IPV6_DNS_SERVERS = new CopyOnWriteArraySet();
        addDnsServerLookupMechanism(de.measite.minidns.dnsserverlookup.b.INSTANCE);
        addDnsServerLookupMechanism(de.measite.minidns.dnsserverlookup.c.INSTANCE);
        addDnsServerLookupMechanism(de.measite.minidns.dnsserverlookup.e.INSTANCE);
        try {
            copyOnWriteArraySet.add(InetAddressUtil.ipv4From("8.8.8.8"));
        } catch (IllegalArgumentException e2) {
            de.measite.minidns.a.LOGGER.log(Level.WARNING, "Could not add static IPv4 DNS Server", (Throwable) e2);
        }
        try {
            STATIC_IPV6_DNS_SERVERS.add(InetAddressUtil.ipv6From("[2001:4860:4860::8888]"));
        } catch (IllegalArgumentException e3) {
            de.measite.minidns.a.LOGGER.log(Level.WARNING, "Could not add static IPv6 DNS Server", (Throwable) e3);
        }
    }

    public DNSClient() {
        this.nonRaServers = Collections.newSetFromMap(new ConcurrentHashMap(4));
        this.askForDnssec = false;
        this.disableResultFilter = false;
    }

    public static synchronized void addDnsServerLookupMechanism(de.measite.minidns.dnsserverlookup.d dVar) {
        synchronized (DNSClient.class) {
            if (dVar.isAvailable()) {
                List<de.measite.minidns.dnsserverlookup.d> list = LOOKUP_MECHANISMS;
                list.add(dVar);
                Collections.sort(list);
            } else {
                de.measite.minidns.a.LOGGER.fine("Not adding " + dVar.getName() + " as it is not available.");
            }
        }
    }

    public static synchronized String[] findDNS() {
        String[] strArr;
        synchronized (DNSClient.class) {
            Iterator<de.measite.minidns.dnsserverlookup.d> it = LOOKUP_MECHANISMS.iterator();
            strArr = null;
            while (it.hasNext() && (strArr = it.next().getDnsServerAddresses()) == null) {
            }
        }
        return strArr;
    }

    public static synchronized boolean removeDNSServerLookupMechanism(de.measite.minidns.dnsserverlookup.d dVar) {
        boolean remove;
        synchronized (DNSClient.class) {
            remove = LOOKUP_MECHANISMS.remove(dVar);
        }
        return remove;
    }

    public InetAddress getRandomHarcodedIpv6DnsServer() {
        return (InetAddress) CollectionsUtil.getRandomFrom(STATIC_IPV6_DNS_SERVERS, this.insecureRandom);
    }

    public InetAddress getRandomHardcodedIpv4DnsServer() {
        return (InetAddress) CollectionsUtil.getRandomFrom(STATIC_IPV4_DNS_SERVERS, this.insecureRandom);
    }

    public boolean isAskForDnssec() {
        return this.askForDnssec;
    }

    public boolean isDisableResultFilter() {
        return this.disableResultFilter;
    }

    @Override
    protected b.C0162b newQuestion(b.C0162b c0162b) {
        c0162b.setRecursionDesired(true);
        c0162b.getEdnsBuilder().setUdpPayloadSize(this.dataSource.getUdpPayloadSize()).setDnssecOk(this.askForDnssec);
        return c0162b;
    }

    @Override
    public b query(b.C0162b c0162b) throws IOException {
        InetAddress randomHardcodedIpv4DnsServer;
        InetAddress randomHarcodedIpv6DnsServer;
        b build = newQuestion(c0162b).build();
        DNSCache dNSCache = this.cache;
        b bVar = dNSCache == null ? null : dNSCache.get(build);
        if (bVar != null) {
            return bVar;
        }
        String[] findDNS = findDNS();
        ArrayList<InetAddress> arrayList = new ArrayList(findDNS.length + 2);
        for (String str : findDNS) {
            if (str == null || str.isEmpty()) {
                de.measite.minidns.a.LOGGER.finest("findDns() returned null or empty string as dns server");
            } else {
                arrayList.add(InetAddress.getByName(str));
            }
        }
        int i2 = a.$SwitchMap$de$measite$minidns$AbstractDNSClient$IpVersionSetting[de.measite.minidns.a.ipVersionSetting.ordinal()];
        if (i2 == 1) {
            randomHardcodedIpv4DnsServer = getRandomHardcodedIpv4DnsServer();
            randomHarcodedIpv6DnsServer = getRandomHarcodedIpv6DnsServer();
        } else if (i2 != 2) {
            if (i2 == 3) {
                randomHardcodedIpv4DnsServer = getRandomHardcodedIpv4DnsServer();
            } else if (i2 != 4) {
                randomHardcodedIpv4DnsServer = null;
                randomHarcodedIpv6DnsServer = null;
            } else {
                randomHardcodedIpv4DnsServer = getRandomHarcodedIpv6DnsServer();
            }
            randomHarcodedIpv6DnsServer = null;
        } else {
            randomHardcodedIpv4DnsServer = getRandomHarcodedIpv6DnsServer();
            randomHarcodedIpv6DnsServer = getRandomHardcodedIpv4DnsServer();
        }
        InetAddress[] inetAddressArr = {randomHardcodedIpv4DnsServer, randomHarcodedIpv6DnsServer};
        for (int i3 = 0; i3 < 2; i3++) {
            InetAddress inetAddress = inetAddressArr[i3];
            if (inetAddress != null) {
                arrayList.add(inetAddress);
            }
        }
        ArrayList arrayList2 = new ArrayList(arrayList.size());
        for (InetAddress inetAddress2 : arrayList) {
            if (this.nonRaServers.contains(inetAddress2)) {
                de.measite.minidns.a.LOGGER.finer("Skipping " + inetAddress2 + " because it was marked as \"recursion not available\"");
            } else {
                try {
                    b query = query(build, inetAddress2);
                    if (query != null) {
                        if (query.recursionAvailable) {
                            if (this.disableResultFilter) {
                                return query;
                            }
                            int i4 = a.$SwitchMap$de$measite$minidns$DNSMessage$RESPONSE_CODE[query.responseCode.ordinal()];
                            if (i4 == 1 || i4 == 2) {
                                return query;
                            }
                            String str2 = "Response from " + inetAddress2 + " asked for " + build.getQuestion() + " with error code: " + query.responseCode + '.';
                            Logger logger = de.measite.minidns.a.LOGGER;
                            if (!logger.isLoggable(Level.FINE)) {
                                str2 = str2 + "\n" + query;
                            }
                            logger.warning(str2);
                        } else if (this.nonRaServers.add(inetAddress2)) {
                            de.measite.minidns.a.LOGGER.warning("The DNS server " + inetAddress2 + " returned a response without the \"recursion available\" (RA) flag set. This likely indicates a misconfiguration because the server is not suitable for DNS resolution");
                        }
                    }
                } catch (IOException e2) {
                    arrayList2.add(e2);
                }
            }
        }
        de.measite.minidns.util.c.throwIfRequired(arrayList2);
        return null;
    }

    public void setAskForDnssec(boolean z) {
        this.askForDnssec = z;
    }

    public void setDisableResultFilter(boolean z) {
        this.disableResultFilter = z;
    }

    public DNSClient(DNSCache dNSCache) {
        super(dNSCache);
        this.nonRaServers = Collections.newSetFromMap(new ConcurrentHashMap(4));
        this.askForDnssec = false;
        this.disableResultFilter = false;
    }
}