Search in sources :

Example 21 with WifiEnterpriseConfig

use of android.net.wifi.WifiEnterpriseConfig in project platform_frameworks_base by android.

the class ConfigBuilder method buildTLSConfig.

private static WifiConfiguration buildTLSConfig(HomeSP homeSP, List<X509Certificate> clientChain, PrivateKey clientKey) throws IOException, GeneralSecurityException {
    Credential credential = homeSP.getCredential();
    X509Certificate clientCertificate = null;
    if (clientKey == null || clientChain == null) {
        throw new IOException("No key and/or cert passed for EAP-TLS");
    }
    if (credential.getCertType() != Credential.CertType.x509v3) {
        throw new IOException("Invalid certificate type for TLS: " + credential.getCertType());
    }
    byte[] reference = credential.getFingerPrint();
    MessageDigest digester = MessageDigest.getInstance("SHA-256");
    for (X509Certificate certificate : clientChain) {
        digester.reset();
        byte[] fingerprint = digester.digest(certificate.getEncoded());
        if (Arrays.equals(reference, fingerprint)) {
            clientCertificate = certificate;
            break;
        }
    }
    if (clientCertificate == null) {
        throw new IOException("No certificate in chain matches supplied fingerprint");
    }
    String alias = Base64.encodeToString(reference, Base64.DEFAULT);
    WifiConfiguration config = buildBaseConfiguration(homeSP);
    WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
    enterpriseConfig.setClientCertificateAlias(alias);
    enterpriseConfig.setClientKeyEntry(clientKey, clientCertificate);
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) Credential(com.android.hotspot2.pps.Credential) WifiConfiguration(android.net.wifi.WifiConfiguration) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) X509Certificate(java.security.cert.X509Certificate)

Example 22 with WifiEnterpriseConfig

use of android.net.wifi.WifiEnterpriseConfig in project platform_frameworks_base by android.

the class ConfigBuilder method buildBaseConfiguration.

private static WifiConfiguration buildBaseConfiguration(HomeSP homeSP) throws IOException {
    EAP.EAPMethodID eapMethodID = homeSP.getCredential().getEAPMethod().getEAPMethodID();
    WifiConfiguration config = new WifiConfiguration();
    config.FQDN = homeSP.getFQDN();
    HashSet<Long> roamingConsortiumIds = homeSP.getRoamingConsortiums();
    config.roamingConsortiumIds = new long[roamingConsortiumIds.size()];
    int i = 0;
    for (long id : roamingConsortiumIds) {
        config.roamingConsortiumIds[i] = id;
        i++;
    }
    config.providerFriendlyName = homeSP.getFriendlyName();
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
    WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
    enterpriseConfig.setEapMethod(remapEAPMethod(eapMethodID));
    enterpriseConfig.setRealm(homeSP.getCredential().getRealm());
    if (homeSP.getUpdateIdentifier() >= 0) {
        config.updateIdentifier = Integer.toString(homeSP.getUpdateIdentifier());
    }
    config.enterpriseConfig = enterpriseConfig;
    if (homeSP.getUpdateIdentifier() >= 0) {
        config.updateIdentifier = Integer.toString(homeSP.getUpdateIdentifier());
    }
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) WifiConfiguration(android.net.wifi.WifiConfiguration) EAP(com.android.anqp.eap.EAP)

Example 23 with WifiEnterpriseConfig

use of android.net.wifi.WifiEnterpriseConfig in project android_frameworks_base by AOSPA.

the class ConfigBuilder method buildBaseConfiguration.

private static WifiConfiguration buildBaseConfiguration(HomeSP homeSP) throws IOException {
    EAP.EAPMethodID eapMethodID = homeSP.getCredential().getEAPMethod().getEAPMethodID();
    WifiConfiguration config = new WifiConfiguration();
    config.FQDN = homeSP.getFQDN();
    HashSet<Long> roamingConsortiumIds = homeSP.getRoamingConsortiums();
    config.roamingConsortiumIds = new long[roamingConsortiumIds.size()];
    int i = 0;
    for (long id : roamingConsortiumIds) {
        config.roamingConsortiumIds[i] = id;
        i++;
    }
    config.providerFriendlyName = homeSP.getFriendlyName();
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
    WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
    enterpriseConfig.setEapMethod(remapEAPMethod(eapMethodID));
    enterpriseConfig.setRealm(homeSP.getCredential().getRealm());
    if (homeSP.getUpdateIdentifier() >= 0) {
        config.updateIdentifier = Integer.toString(homeSP.getUpdateIdentifier());
    }
    config.enterpriseConfig = enterpriseConfig;
    if (homeSP.getUpdateIdentifier() >= 0) {
        config.updateIdentifier = Integer.toString(homeSP.getUpdateIdentifier());
    }
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) WifiConfiguration(android.net.wifi.WifiConfiguration) EAP(com.android.anqp.eap.EAP)

Example 24 with WifiEnterpriseConfig

use of android.net.wifi.WifiEnterpriseConfig in project android_frameworks_base by AOSPA.

the class ConfigBuilder method buildTTLSConfig.

// Retain for debugging purposes
/*
    private static void xIterateCerts(KeyStore ks, X509Certificate caCert)
            throws GeneralSecurityException {
        Enumeration<String> aliases = ks.aliases();
        while (aliases.hasMoreElements()) {
            String alias = aliases.nextElement();
            Certificate cert = ks.getCertificate(alias);
            Log.d("HS2J", "Checking " + alias);
            if (cert instanceof X509Certificate) {
                X509Certificate x509Certificate = (X509Certificate) cert;
                boolean sm = x509Certificate.getSubjectX500Principal().equals(
                        caCert.getSubjectX500Principal());
                boolean eq = false;
                if (sm) {
                    eq = Arrays.equals(x509Certificate.getEncoded(), caCert.getEncoded());
                }
                Log.d("HS2J", "Subject: " + x509Certificate.getSubjectX500Principal() +
                        ": " + sm + "/" + eq);
            }
        }
    }
    */
private static WifiConfiguration buildTTLSConfig(HomeSP homeSP) throws IOException {
    Credential credential = homeSP.getCredential();
    if (credential.getUserName() == null || credential.getPassword() == null) {
        throw new IOException("EAP-TTLS provisioned without user name or password");
    }
    EAPMethod eapMethod = credential.getEAPMethod();
    AuthParam authParam = eapMethod.getAuthParam();
    if (authParam == null || authParam.getAuthInfoID() != EAP.AuthInfoID.NonEAPInnerAuthType) {
        throw new IOException("Bad auth parameter for EAP-TTLS: " + authParam);
    }
    WifiConfiguration config = buildBaseConfiguration(homeSP);
    NonEAPInnerAuth ttlsParam = (NonEAPInnerAuth) authParam;
    WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
    enterpriseConfig.setPhase2Method(remapInnerMethod(ttlsParam.getType()));
    enterpriseConfig.setIdentity(credential.getUserName());
    enterpriseConfig.setPassword(credential.getPassword());
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) Credential(com.android.hotspot2.pps.Credential) WifiConfiguration(android.net.wifi.WifiConfiguration) IOException(java.io.IOException) AuthParam(com.android.anqp.eap.AuthParam) EAPMethod(com.android.anqp.eap.EAPMethod) NonEAPInnerAuth(com.android.anqp.eap.NonEAPInnerAuth)

Example 25 with WifiEnterpriseConfig

use of android.net.wifi.WifiEnterpriseConfig in project android_frameworks_base by AOSPA.

the class ConfigBuilder method buildTLSConfig.

private static WifiConfiguration buildTLSConfig(HomeSP homeSP, List<X509Certificate> clientChain, PrivateKey clientKey) throws IOException, GeneralSecurityException {
    Credential credential = homeSP.getCredential();
    X509Certificate clientCertificate = null;
    if (clientKey == null || clientChain == null) {
        throw new IOException("No key and/or cert passed for EAP-TLS");
    }
    if (credential.getCertType() != Credential.CertType.x509v3) {
        throw new IOException("Invalid certificate type for TLS: " + credential.getCertType());
    }
    byte[] reference = credential.getFingerPrint();
    MessageDigest digester = MessageDigest.getInstance("SHA-256");
    for (X509Certificate certificate : clientChain) {
        digester.reset();
        byte[] fingerprint = digester.digest(certificate.getEncoded());
        if (Arrays.equals(reference, fingerprint)) {
            clientCertificate = certificate;
            break;
        }
    }
    if (clientCertificate == null) {
        throw new IOException("No certificate in chain matches supplied fingerprint");
    }
    String alias = Base64.encodeToString(reference, Base64.DEFAULT);
    WifiConfiguration config = buildBaseConfiguration(homeSP);
    WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
    enterpriseConfig.setClientCertificateAlias(alias);
    enterpriseConfig.setClientKeyEntry(clientKey, clientCertificate);
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) Credential(com.android.hotspot2.pps.Credential) WifiConfiguration(android.net.wifi.WifiConfiguration) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) X509Certificate(java.security.cert.X509Certificate)

Aggregations

WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)46 WifiConfiguration (android.net.wifi.WifiConfiguration)39 IOException (java.io.IOException)20 Credential (com.android.hotspot2.pps.Credential)15 AccessPoint (com.android.settingslib.wifi.AccessPoint)15 WifiManager (android.net.wifi.WifiManager)10 EAP (com.android.anqp.eap.EAP)10 CheckBox (android.widget.CheckBox)8 IpConfiguration (android.net.IpConfiguration)7 StaticIpConfiguration (android.net.StaticIpConfiguration)7 ArrayAdapter (android.widget.ArrayAdapter)7 AuthParam (com.android.anqp.eap.AuthParam)5 EAPMethod (com.android.anqp.eap.EAPMethod)5 NonEAPInnerAuth (com.android.anqp.eap.NonEAPInnerAuth)5 MessageDigest (java.security.MessageDigest)5 X509Certificate (java.security.cert.X509Certificate)5 Spinner (android.widget.Spinner)1 Test (org.junit.Test)1