Search in sources :

Example 26 with WifiEnterpriseConfig

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

the class WifiNetworkAdapter method updateNetwork.

public void updateNetwork(HomeSP homeSP, X509Certificate caCert, List<X509Certificate> clientCerts, PrivateKey privateKey) throws IOException, GeneralSecurityException {
    WifiConfiguration config = getWifiConfig(homeSP);
    if (config == null) {
        throw new IOException("Failed to find matching network config");
    }
    Log.d(OSUManager.TAG, "Found matching config " + config.networkId + ", updating");
    WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
    WifiConfiguration newConfig = ConfigBuilder.buildConfig(homeSP, caCert != null ? caCert : enterpriseConfig.getCaCertificate(), clientCerts, privateKey);
    newConfig.networkId = config.networkId;
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    wifiManager.save(newConfig, null);
    wifiManager.saveConfiguration();
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) IOException(java.io.IOException)

Example 27 with WifiEnterpriseConfig

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

the class WifiNetworkAdapter method updateNetwork.

public void updateNetwork(HomeSP homeSP, X509Certificate caCert, List<X509Certificate> clientCerts, PrivateKey privateKey) throws IOException, GeneralSecurityException {
    WifiConfiguration config = getWifiConfig(homeSP);
    if (config == null) {
        throw new IOException("Failed to find matching network config");
    }
    Log.d(OSUManager.TAG, "Found matching config " + config.networkId + ", updating");
    WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
    WifiConfiguration newConfig = ConfigBuilder.buildConfig(homeSP, caCert != null ? caCert : enterpriseConfig.getCaCertificate(), clientCerts, privateKey);
    newConfig.networkId = config.networkId;
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    wifiManager.save(newConfig, null);
    wifiManager.saveConfiguration();
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) IOException(java.io.IOException)

Example 28 with WifiEnterpriseConfig

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

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 29 with WifiEnterpriseConfig

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

the class ConfigBuilder method buildConfig.

public static WifiConfiguration buildConfig(HomeSP homeSP, X509Certificate caCert, List<X509Certificate> clientChain, PrivateKey key) throws IOException, GeneralSecurityException {
    Credential credential = homeSP.getCredential();
    WifiConfiguration config;
    EAP.EAPMethodID eapMethodID = credential.getEAPMethod().getEAPMethodID();
    switch(eapMethodID) {
        case EAP_TTLS:
            if (key != null || clientChain != null) {
                Log.w(TAG, "Client cert and/or key included with EAP-TTLS profile");
            }
            config = buildTTLSConfig(homeSP);
            break;
        case EAP_TLS:
            config = buildTLSConfig(homeSP, clientChain, key);
            break;
        case EAP_AKA:
        case EAP_AKAPrim:
        case EAP_SIM:
            if (key != null || clientChain != null || caCert != null) {
                Log.i(TAG, "Client/CA cert and/or key included with " + eapMethodID + " profile");
            }
            config = buildSIMConfig(homeSP);
            break;
        default:
            throw new IOException("Unsupported EAP Method: " + eapMethodID);
    }
    WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
    enterpriseConfig.setCaCertificate(caCert);
    enterpriseConfig.setAnonymousIdentity("anonymous@" + credential.getRealm());
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) Credential(com.android.hotspot2.pps.Credential) WifiConfiguration(android.net.wifi.WifiConfiguration) EAP(com.android.anqp.eap.EAP) IOException(java.io.IOException)

Example 30 with WifiEnterpriseConfig

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

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