Java 类android.net.wifi.WifiEnterpriseConfig 实例源码

项目:android-testdpc    文件:WifiEapTlsCreateDialogFragment.java   
private boolean saveWifiConfiguration(String ssid, X509Certificate caCert,
        PrivateKey privateKey, X509Certificate userCert, String identity) {
    mWifiConfiguration.SSID = ssid;
    mWifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
    mWifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
    WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
    enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TLS);
    enterpriseConfig.setCaCertificate(caCert);
    enterpriseConfig.setClientKeyEntry(privateKey, userCert);
    if (!TextUtils.isEmpty(identity)) {
        enterpriseConfig.setIdentity(identity);
    }
    mWifiConfiguration.enterpriseConfig = enterpriseConfig;
    return WifiConfigUtil.saveWifiConfiguration(getActivity(), mWifiConfiguration);
}
项目:EnterpriseWifiSafeguard    文件:MainActivity.java   
/**
 * Initiate wifi setup if button has been pressed
 */
public void buttonPressed() {
    Log.d("ews-debug", "Button has pressed");
    // Select eap Mehod
    final int eap;
    String seap = feap.getSelectedItem().toString();
    if (seap.equals("PEAP")) {
        eap = WifiEnterpriseConfig.Eap.PEAP;
    } else if (seap.equals("PWD")) {
        eap = WifiEnterpriseConfig.Eap.PWD;
    } else if (seap.equals("TLS")) {
        eap = WifiEnterpriseConfig.Eap.TLS;
    } else if (seap.equals("TTLS")) {
        eap = WifiEnterpriseConfig.Eap.TTLS;
    } else {
        eap = -1;
    }
    Log.d("ews-debug", seap + eap);
    // Select Phase2 Method
    final String sphase2 = fPhase2.getSelectedItem().toString();
    final int phase2;
    if (sphase2.equals("MSCHAP")) {
        phase2 = WifiEnterpriseConfig.Phase2.MSCHAP;
    } else if (sphase2.equals("MSCHAPV2")) {
        phase2 = WifiEnterpriseConfig.Phase2.MSCHAPV2;
    } else if (sphase2.equals("PAP")) {
        phase2 = WifiEnterpriseConfig.Phase2.PAP;
    } else {
        phase2 = -1;
    }
    Log.d("ews-debug", sphase2 + phase2);
       //create wifi configuration and save it
    final WifiSetup setup = new WifiSetup(this.getApplicationContext());
    boolean error = setup.createConnection("\"" + fssid.getText().toString() + "\"", fuser.getText().toString(),
            fpass.getText().toString(), fanonymous.getText().toString(), fCn.getText().toString(), eap, phase2,
            fcert.getSelectedItem().toString());
    if (error) {
        feedback.setText("Could not Save Network");
    } else {
        feedback.setText("Network setup finished!");
    }
}
项目:EnterpriseWifiSafeguard    文件:WifiConfig.java   
public WifiConfiguration createNewWifiProfile() throws EnterpriseConfigurationException {
    WifiConfiguration profile = new WifiConfiguration();

    // Security Settings for WPA/WPA2
    profile.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
    profile.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
    profile.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
    profile.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
    profile.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
    profile.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
    profile.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
    profile.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);

    // Set SSID
    profile.SSID = this.ssid;
    Log.d("ews-ssid", this.ssid);

    // Enterprise Configuration
    WifiEnterpriseConfig enterprise = new WifiEnterpriseConfig();
    // Set Username
    if (username != null && username.length() > 0) {
        enterprise.setIdentity(this.username);
    } else {
        throw new EnterpriseConfigurationMissingUsernameException();
    }
    // Set Password
    if (password != null && password.length() > 0) {
        enterprise.setPassword(this.password);
    } else {
        throw new EnterpriseConfigurationMissingPasswordException();
    }
    // Set eap method
    enterprise.setEapMethod(this.eap_method);
    // Set Phase2 methos
    enterprise.setPhase2Method(this.phase2_method);
    // Set Anonymous Identity
    enterprise.setAnonymousIdentity(this.anonymous_ident);
    // Set CA_Certificate
    enterprise.setCaCertificate(this.ca_certificate);
    // Set Subject_match
    enterprise.setSubjectMatch(this.subject_match);
    // Add enterprise config to profile
    profile.enterpriseConfig = enterprise;

    Log.d("ews-profile", profile.toString());
    // return the new profile
    return profile;
}
项目:android-proxy    文件:TestUtils.java   
@TargetApi(18)
    private static void setup802xWifiConfig(WifiConfiguration config, String ssid, String password)
    {
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
        config.enterpriseConfig = new WifiEnterpriseConfig();

        int eapMethod = WifiEnterpriseConfig.Eap.PEAP;
        int phase2Method = WifiEnterpriseConfig.Phase2.GTC;

        config.enterpriseConfig.setEapMethod(eapMethod);

        switch (eapMethod)
        {
            case WifiEnterpriseConfig.Eap.PEAP:
                // PEAP supports limited phase2 values
                // Map the index from the PHASE2_PEAP_ADAPTER to the one used
                // by the API which has the full list of PEAP methods.
                switch (phase2Method)
                {
                    case APLReflectionConstants.WIFI_PEAP_PHASE2_NONE:
                        config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.NONE);
                        break;
                    case APLReflectionConstants.WIFI_PEAP_PHASE2_MSCHAPV2:
                        config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.MSCHAPV2);
                        break;
                    case APLReflectionConstants.WIFI_PEAP_PHASE2_GTC:
                        config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.GTC);
                        break;
                    default:
                        Timber.e("Unknown phase2 method" + phase2Method);
                        break;
                }
                break;
            default:
                // The default index from PHASE2_FULL_ADAPTER maps to the API
                config.enterpriseConfig.setPhase2Method(phase2Method);
                break;
        }

        String caCert = "";
//        config.enterpriseConfig.setCaCertificateAlias(caCert);
//        String clientCert = (String) mEapUserCertSpinner.getSelectedItem();
//        if (clientCert.equals(unspecifiedCert)) clientCert = "";
//        config.enterpriseConfig.setClientCertificateAlias(clientCert);
//        config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
//        config.enterpriseConfig.setAnonymousIdentity(mEapAnonymousView.getText().toString());

//         if (mPasswordView.isShown())
//         {
//             // For security reasons, a previous password is not displayed to user.
//             // Update only if it has been changed.
//             if (mPasswordView.length() > 0)
//             {
        config.enterpriseConfig.setPassword(password.toString());
//             }
//         }
//         else
//         {
//             // clear password
//             config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
//         }
    }
项目:TumCampusApp    文件:EduroamManager.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void setupEnterpriseConfigAPI18(WifiConfiguration conf, String lrzId, String networkPass) {
    conf.enterpriseConfig.setIdentity(lrzId + "@eduroam.mwn.de");
    conf.enterpriseConfig.setPassword(networkPass);
    conf.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.PWD);
}
项目:TumCampusApp    文件:EduroamFixCard.java   
private boolean isConfigValid() {
    errors.clear();
    eduroam = EduroamManager.getEduroamConfig(mContext);

    //If it is not configured then the config valid
    if (eduroam == null) {
        return true;
    }

    // Eduroam was configured by other university
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2
            && !isTumEduroam(eduroam.enterpriseConfig.getIdentity())) {
        Utils.log("Eduroam wasn't configured at TUM");
        return true;
    }

    // Check attributes - Android 23+: check newer match for the radius server
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {

        // for all configurations
        // Check that the full quantifier is used (we already know it's a tum config)
        if (!eduroam.enterpriseConfig.getIdentity().contains(atSign)) {
            errors.add(mContext.getString(R.string.wifi_identity_zone));
        }

        int eapMethod = eduroam.enterpriseConfig.getEapMethod();
        int phase2 = eduroam.enterpriseConfig.getPhase2Method();

        if ((eapMethod == WifiEnterpriseConfig.Eap.TTLS
             && (phase2 == WifiEnterpriseConfig.Phase2.MSCHAPV2 || phase2 == WifiEnterpriseConfig.Phase2.PAP)
             || (eapMethod == WifiEnterpriseConfig.Eap.PEAP
                 && phase2 == WifiEnterpriseConfig.Phase2.MSCHAPV2))) {

            checkDNSName();
            checkAnonymousIdentity();

            // note: checking the certificate does not seem possible
        } else {
            // PWD or unknown authentication method (we don't know if that method is safe or not -> ignore)
        }
    }
    return errors.isEmpty();
}