package io.netty.handler.ssl;

import g.a.a.a.a;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.net.ssl.SNIHostName;
import javax.net.ssl.SNIMatcher;
import javax.net.ssl.SNIServerName;
import javax.net.ssl.SSLParameters;

/* JADX INFO: loaded from: classes.dex */
public final class Java8SslUtils {
    private Java8SslUtils() {
    }

    public static boolean checkSniHostnameMatch(Collection<?> collection, String str) {
        if (collection == null || collection.isEmpty()) {
            return true;
        }
        SNIHostName sNIHostName = new SNIHostName(str);
        Iterator<?> it = collection.iterator();
        while (it.hasNext()) {
            SNIMatcher sNIMatcher = (SNIMatcher) it.next();
            if (sNIMatcher.getType() == 0 && sNIMatcher.matches(sNIHostName)) {
                return true;
            }
        }
        return false;
    }

    public static List<String> getSniHostNames(SSLParameters sSLParameters) {
        List<SNIServerName> serverNames = sSLParameters.getServerNames();
        if (serverNames == null || serverNames.isEmpty()) {
            return Collections.emptyList();
        }
        ArrayList arrayList = new ArrayList(serverNames.size());
        for (SNIServerName sNIServerName : serverNames) {
            if (!(sNIServerName instanceof SNIHostName)) {
                StringBuilder sbF = a.F("Only ");
                sbF.append(SNIHostName.class.getName());
                sbF.append(" instances are supported, but found: ");
                sbF.append(sNIServerName);
                throw new IllegalArgumentException(sbF.toString());
            }
            arrayList.add(((SNIHostName) sNIServerName).getAsciiName());
        }
        return arrayList;
    }

    public static boolean getUseCipherSuitesOrder(SSLParameters sSLParameters) {
        return sSLParameters.getUseCipherSuitesOrder();
    }

    public static void setSNIMatchers(SSLParameters sSLParameters, Collection<?> collection) {
        sSLParameters.setSNIMatchers(collection);
    }

    public static void setSniHostNames(SSLParameters sSLParameters, List<String> list) {
        ArrayList arrayList = new ArrayList(list.size());
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            arrayList.add(new SNIHostName(it.next()));
        }
        sSLParameters.setServerNames(arrayList);
    }

    public static void setUseCipherSuitesOrder(SSLParameters sSLParameters, boolean z2) {
        sSLParameters.setUseCipherSuitesOrder(z2);
    }
}
