Search in sources :

Example 6 with WifiEnterpriseConfig

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

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

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

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

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

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

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

the class WifiNetworkAdapter method connect.

/**
     * Connect to an OSU provisioning network. The connection should not bring down other existing
     * connection and the network should not be made the default network since the connection
     * is solely for sign up and is neither intended for nor likely provides access to any
     * generic resources.
     *
     * @param osuInfo The OSU info object that defines the parameters for the network. An OSU
     *                network is either an open network, or, if the OSU NAI is set, an "OSEN"
     *                network, which is an anonymous EAP-TLS network with special keys.
     * @param info    An opaque string that is passed on to any user notification. The string is used
     *                for the name of the service provider.
     * @return an Integer holding the network-id of the just added network configuration, or null
     * if the network existed prior to this call (was not added by the OSU infrastructure).
     * The value will be used at the end of the OSU flow to delete the network as applicable.
     * @throws IOException Issues:
     *                     1. The network id is not returned. addNetwork cannot be called from here since the method
     *                     runs in the context of the app and doesn't have the appropriate permission.
     *                     2. The connection is not immediately usable if the network was not previously selected
     *                     manually.
     */
public Integer connect(OSUInfo osuInfo, final String info) throws IOException {
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = '"' + osuInfo.getSSID() + '"';
    if (osuInfo.getOSUBssid() != 0) {
        config.BSSID = Utils.macToString(osuInfo.getOSUBssid());
        Log.d(OSUManager.TAG, String.format("Setting BSSID of '%s' to %012x", osuInfo.getSSID(), osuInfo.getOSUBssid()));
    }
    if (osuInfo.getOSUProvider().getOsuNai() == null) {
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
    } else {
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.OSEN);
        config.allowedProtocols.set(WifiConfiguration.Protocol.OSEN);
        config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
        config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GTK_NOT_USED);
        config.enterpriseConfig = new WifiEnterpriseConfig();
        config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.UNAUTH_TLS);
        config.enterpriseConfig.setIdentity(osuInfo.getOSUProvider().getOsuNai());
    // !!! OSEN CA Cert???
    }
    int networkId = wifiManager.addNetwork(config);
    if (wifiManager.enableNetwork(networkId, true)) {
        return networkId;
    } else {
        return null;
    }
/* sequence of addNetwork(), enableNetwork(), saveConfiguration() and reconnect()
        wifiManager.connect(config, new WifiManager.ActionListener() {
            @Override
            public void onSuccess() {
                // Connection event comes from network change intent registered in initialize
            }

            @Override
            public void onFailure(int reason) {
                mOSUManager.notifyUser(OSUOperationStatus.ProvisioningFailure,
                        "Cannot connect to OSU network: " + reason, info);
            }
        });
        return null;

        /*
        try {
            int nwkID = wifiManager.addOrUpdateOSUNetwork(config);
            if (nwkID == WifiConfiguration.INVALID_NETWORK_ID) {
                throw new IOException("Failed to add OSU network");
            }
            wifiManager.enableNetwork(nwkID, false);
            wifiManager.reconnect();
            return nwkID;
        }
        catch (SecurityException se) {
            Log.d("ZXZ", "Blah: " + se, se);
            wifiManager.connect(config, new WifiManager.ActionListener() {
                @Override
                public void onSuccess() {
                    // Connection event comes from network change intent registered in initialize
                }

                @Override
                public void onFailure(int reason) {
                    mOSUManager.notifyUser(OSUOperationStatus.ProvisioningFailure,
                            "Cannot connect to OSU network: " + reason, info);
                }
            });
            return null;
        }
        */
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 10 with WifiEnterpriseConfig

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

the class WifiNetworkAdapter method connect.

/**
     * Connect to an OSU provisioning network. The connection should not bring down other existing
     * connection and the network should not be made the default network since the connection
     * is solely for sign up and is neither intended for nor likely provides access to any
     * generic resources.
     *
     * @param osuInfo The OSU info object that defines the parameters for the network. An OSU
     *                network is either an open network, or, if the OSU NAI is set, an "OSEN"
     *                network, which is an anonymous EAP-TLS network with special keys.
     * @param info    An opaque string that is passed on to any user notification. The string is used
     *                for the name of the service provider.
     * @return an Integer holding the network-id of the just added network configuration, or null
     * if the network existed prior to this call (was not added by the OSU infrastructure).
     * The value will be used at the end of the OSU flow to delete the network as applicable.
     * @throws IOException Issues:
     *                     1. The network id is not returned. addNetwork cannot be called from here since the method
     *                     runs in the context of the app and doesn't have the appropriate permission.
     *                     2. The connection is not immediately usable if the network was not previously selected
     *                     manually.
     */
public Integer connect(OSUInfo osuInfo, final String info) throws IOException {
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = '"' + osuInfo.getSSID() + '"';
    if (osuInfo.getOSUBssid() != 0) {
        config.BSSID = Utils.macToString(osuInfo.getOSUBssid());
        Log.d(OSUManager.TAG, String.format("Setting BSSID of '%s' to %012x", osuInfo.getSSID(), osuInfo.getOSUBssid()));
    }
    if (osuInfo.getOSUProvider().getOsuNai() == null) {
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
    } else {
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.OSEN);
        config.allowedProtocols.set(WifiConfiguration.Protocol.OSEN);
        config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
        config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GTK_NOT_USED);
        config.enterpriseConfig = new WifiEnterpriseConfig();
        config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.UNAUTH_TLS);
        config.enterpriseConfig.setIdentity(osuInfo.getOSUProvider().getOsuNai());
    // !!! OSEN CA Cert???
    }
    int networkId = wifiManager.addNetwork(config);
    if (wifiManager.enableNetwork(networkId, true)) {
        return networkId;
    } else {
        return null;
    }
/* sequence of addNetwork(), enableNetwork(), saveConfiguration() and reconnect()
        wifiManager.connect(config, new WifiManager.ActionListener() {
            @Override
            public void onSuccess() {
                // Connection event comes from network change intent registered in initialize
            }

            @Override
            public void onFailure(int reason) {
                mOSUManager.notifyUser(OSUOperationStatus.ProvisioningFailure,
                        "Cannot connect to OSU network: " + reason, info);
            }
        });
        return null;

        /*
        try {
            int nwkID = wifiManager.addOrUpdateOSUNetwork(config);
            if (nwkID == WifiConfiguration.INVALID_NETWORK_ID) {
                throw new IOException("Failed to add OSU network");
            }
            wifiManager.enableNetwork(nwkID, false);
            wifiManager.reconnect();
            return nwkID;
        }
        catch (SecurityException se) {
            Log.d("ZXZ", "Blah: " + se, se);
            wifiManager.connect(config, new WifiManager.ActionListener() {
                @Override
                public void onSuccess() {
                    // Connection event comes from network change intent registered in initialize
                }

                @Override
                public void onFailure(int reason) {
                    mOSUManager.notifyUser(OSUOperationStatus.ProvisioningFailure,
                            "Cannot connect to OSU network: " + reason, info);
                }
            });
            return null;
        }
        */
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration)

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