将Android连接到WiFi企业网络EAP(PEAP)

将Android连接到WiFi企业网络EAP(PEAP),android,wifi,connect,enterprise,Android,Wifi,Connect,Enterprise,在过去的几天里,我一直在尝试通过编程将我的android设备连接到企业网络,但没有任何成功。我一直在网上关注多个示例,但我发现的大多数示例都是针对EAP(TLS)网络的,我工作的是EAP(PEAP),以下是网络类型 802.1x EAP EAP方法:PEAP 第2阶段身份验证:MSCHAPV2 身份验证总是失败,logcat没有告诉我问题出在哪里,我只知道在执行身份验证时它失败了 这是我当前代码的副本,以及logcat失败时的日志: /******************代码**********

在过去的几天里,我一直在尝试通过编程将我的android设备连接到企业网络,但没有任何成功。我一直在网上关注多个示例,但我发现的大多数示例都是针对EAP(TLS)网络的,我工作的是EAP(PEAP),以下是网络类型

802.1x EAP

EAP方法:PEAP

第2阶段身份验证:MSCHAPV2

身份验证总是失败,logcat没有告诉我问题出在哪里,我只知道在执行身份验证时它失败了

这是我当前代码的副本,以及logcat失败时的日志:

/******************代码******************************/

public class WPAActivity extends LauncherActivity 
{

private static final String TAG = "WPAActivity";

/************* Definitions to find variables ***************************/
private static final String INT_PRIVATE_KEY = "private_key";
private static final String INT_PHASE2 = "phase2";
private static final String INT_PASSWORD = "password";
private static final String INT_IDENTITY = "identity";
private static final String INT_EAP = "eap";
private static final String INT_CLIENT_CERT = "client_cert";
private static final String INT_CA_CERT = "ca_cert";
private static final String INT_ANONYMOUS_IDENTITY = "anonymous_identity";
final String INT_ENTERPRISEFIELD_NAME ="android.net.wifi.WifiConfiguration$EnterpriseField";
/************************************************************************/

/********************************Configuration Strings*********************/
final String ENTERPRISE_EAP = "PEAP";
final String ENTERPRISE_CLIENT_CERT = "";
final String ENTERPRISE_PRIV_KEY = "";
final String ENTERPRISE_PHASE2 = "\"MSCHAPV2\"";
final String ENTERPRISE_ANON_IDENT = "";
final String ENTERPRISE_CA_CERT = "";
final String userName = "\"my Username";
final String passString = "\"my Password\"";

/**************************************************************************/


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{


super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiConfiguration wc = new WifiConfiguration();
    wc.SSID = "\"mySSID\"";
    wc.preSharedKey  = "\"my Password\"";
    wc.hiddenSSID = true;
    wc.status = WifiConfiguration.Status.ENABLED;        

    wc.allowedKeyManagement.clear();
    wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
    wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);


    /*Group Ciphers*/
    wc.allowedGroupCiphers.clear();
    wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
    wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);

    /*Protocols*/
    wc.allowedProtocols.clear();
    wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
    wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);

    Class[] enterpriseFieldArray  = WifiConfiguration.class.getClasses();
    Class<?> enterpriseFieldClass = null;


    for(Class<?> myClass : enterpriseFieldArray)
    {
        if(myClass.getName().equals(INT_ENTERPRISEFIELD_NAME))
        {
        enterpriseFieldClass = myClass;
        break;
        }
    }
    Log.d(TAG, "class chosen " + enterpriseFieldClass.getName() );


    Field anonymousId = null, caCert = null, clientCert = null, 
        eap = null, identity = null, password = null, 
        phase2 = null, privateKey =  null;

    Field[] fields = WifiConfiguration.class.getFields();


    for (Field tempField : fields) 
    {
        if (tempField.getName().trim().equals(INT_ANONYMOUS_IDENTITY))
        {
        anonymousId = tempField;
        Log.d(TAG, "field " + anonymousId.getName() );
        }
        else if (tempField.getName().trim().equals(INT_CA_CERT))
        {
        caCert = tempField;
        }
        else if (tempField.getName().trim().equals(INT_CA_CERT))
        {
        }
        else if (tempField.getName().trim().equals(INT_CLIENT_CERT))
        {
        clientCert = tempField;
        Log.d(TAG, "field " + clientCert.getName() );
        }    
        else if (tempField.getName().trim().equals(INT_EAP))
        {
        eap = tempField;
        Log.d(TAG, "field " + eap.getName() );
        }
        else if (tempField.getName().trim().equals(INT_IDENTITY))
        {
        identity = tempField;
        Log.d(TAG, "field " + identity.getName() );
        }
        else if (tempField.getName().trim().equals(INT_PASSWORD))
        {
        password = tempField;
        Log.d(TAG, "field " + password.getName() );
        }
        else if (tempField.getName().trim().equals(INT_PHASE2))
        {
        phase2 = tempField;
        Log.d(TAG, "field " + phase2.getName() );

        }
        else if (tempField.getName().trim().equals(INT_PRIVATE_KEY))
        {
        privateKey = tempField;
        }
    }


    Method setValue = null;


    for(Method m: enterpriseFieldClass.getMethods())
    {
        if(m.getName().trim().equals("setValue"))
        {
        Log.d(TAG, "method " + m.getName() );
        setValue = m;
        break;
        }
    }

    try
    {
        // EAP
        setValue.invoke(eap.get(wc), ENTERPRISE_EAP);

        // EAP Phase 2
        setValue.invoke(phase2.get(wc), ENTERPRISE_PHASE2);

        // EAP Anonymous Id
        setValue.invoke(anonymousId.get(wc), ENTERPRISE_ANON_IDENT);

        // EAP CA Certificate
        setValue.invoke(caCert.get(wc), ENTERPRISE_CA_CERT);

        // Private Key
        setValue.invoke(privateKey.get(wc), ENTERPRISE_PRIV_KEY);

        // EAP Identity
        setValue.invoke(identity.get(wc), userName);

        // EAP Password
        setValue.invoke(password.get(wc), passString);

        // EAP Client certificate
        setValue.invoke(clientCert.get(wc), ENTERPRISE_CLIENT_CERT);

    }
    catch (Exception e)
    {

    }

    Log.d("WifiPreference", "2");
    int res = wifi.addNetwork(wc);
    Log.d("WifiPreference", "add Network returned " + res );
    boolean b = wifi.enableNetwork(res, true);        
    Log.d("WifiPreference", "enableNetwork returned " + b );
    }
}
02-09 09:23:30.514: I/ActivityManager(2084): Displayed activity com.test.wpa/.WPAActivity: 445 ms (total 445 ms)

02-09 09:23:31.514: I/wpa_supplicant(27633): CTRL-EVENT-SCAN-RESULTS  Ready

02-09 09:23:31.514: I/wpa_supplicant(27633): Trying to associate with 00:1c:0f:82:04:e0 (SSID='*****' freq=2437 MHz)

02-09 09:23:31.514: I/wpa_supplicant(27633): CTRL-EVENT-STATE-CHANGE id=-1 state=3

02-09 09:23:31.649: V/WifiMonitor(2084): Event [Trying to associate with 00:1c:0f:82:04:e0 (SSID='*****' freq=2437 MHz)]

02-09 09:23:31.649: V/WifiMonitor(2084): Event [CTRL-EVENT-STATE-CHANGE id=-1 state=3]

02-09 09:23:31.654: V/WifiStateTracker(2084): Changing supplicant state: SCANNING ==> ASSOCIATING

02-09 09:23:31.654: D/NetworkStateTracker(2084): setDetailed state, old =SCANNING and new state=CONNECTING

02-09 09:23:31.659: D/ConnectivityService(2084): ConnectivityChange for WIFI: CONNECTING/CONNECTING

02-09 09:23:32.621: I/wpa_supplicant(27633): CTRL-EVENT-STATE-CHANGE id=0 state=4

02-09 09:23:32.621: V/WifiMonitor(2084): Event [CTRL-EVENT-STATE-CHANGE id=0 state=4]

02-09 09:23:32.624: I/wpa_supplicant(27633): Associated with 00:1c:0f:82:04:e0

02-09 09:23:32.624: I/wpa_supplicant(27633): CTRL-EVENT-EAP-STARTED EAP authentication started

02-09 09:23:32.629: V/WifiMonitor(2084): Event [Associated with 00:1c:0f:82:04:e0]

**02-09 09:23:32.629: V/WifiMonitor(2084): Event [CTRL-EVENT-EAP-STARTED EAP authentication started]**

02-09 09:23:32.629: V/WifiStateTracker(2084): Changing supplicant state: ASSOCIATING ==> ASSOCIATED

**02-09 09:23:32.629: D/NetworkStateTracker(2084): setDetailed state, old =CONNECTING and new state=CONNECTING**

**02-09 09:23:32.634: I/wpa_supplicant(27633): CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys**

02-09 09:23:32.644: I/wpa_supplicant(27633): CTRL-EVENT-STATE-CHANGE id=0 state=0

**02-09 09:23:32.644: V/WifiMonitor(2084): Event [CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys]**

02-09 09:23:32.644: V/WifiMonitor(2084): Event [CTRL-EVENT-STATE-CHANGE id=0 state=0]

我无法通过编程在网上找到有关EAP(PEAP)身份验证的示例,我尝试过更改WiFi配置,但没有成功。关于如何连接到企业网络EAP(PEAP)有什么想法或有用的站点/示例,或者有人能给我指出正确的方向吗?

最后,我击败了我的CiSCO EAP-FAST企业wifi网络,我们所有的安卓设备现在都能连接到它

为了从Android设备上访问这种网络,我进行了一次漫游,这比你想象的要简单

Google Play商店中有一个Wifi配置编辑器,您可以在设置EAP Wifi连接时使用该编辑器“激活”辅助CISCO协议

它的名字是Wifi配置高级编辑器

  • 首先,您必须手动设置无线网络,尽可能接近“官方”公司wifi参数

  • 保存它

  • 转到WCE并编辑在上一步中创建的网络的参数

  • 您应该激活3或4系列设置,以强制Android设备使用它们作为连接方式(我认为您要访问的主要站点是Enterprise Configuration,但不要忘记检查所有参数,以便在需要时更改它们。
    作为一个建议,即使你有一个WPA2 EAP-FAST密码,在你的设置中尝试LEAP。它对我来说是一个魅力

  • 编辑完配置后,转到主Android wifi控制器,强制连接到此网络

  • 请勿使用Android wifi接口再次编辑网络


我已经在三星Galaxy 1和Galaxy 2、Note移动设备以及联想Thinkpad平板电脑上进行了测试。

感谢您对我们Cypawer的启发

我也试过这个应用

它工作得非常完美


我正试图在我的程序中连接公司的eap wifi

前提条件:

1.让IT人员将设备的mac地址添加到网络配置中

2.我的网络配置:

EAP method:PEAP

Phase2MethodVerify:NULL

CACertificateVerify:NULL

Identity:""

Password:""
首先,我添加了一些登录设置,这样我就知道当我点击wifi提交按钮时发生了什么

它是这样打印的:

* ID: -1 SSID: "SSID" PROVIDER-NAME: null BSSID: null FQDN: null PRIO: 0 HIDDEN: false
 NetworkSelectionStatus NETWORK_SELECTION_ENABLED
 hasEverConnected: false
 KeyMgmt: WPA_EAP IEEE8021X Protocols:
 AuthAlgorithms:
 PairwiseCiphers:
 GroupCiphers:
 PSK: 
Enterprise config:
password <removed>
ca_path NULL
engine 0
proactive_key_caching 1
client_cert NULL
anonymous_identity NULL
ca_cert NULL
identity "name"
domain_suffix_match NULL
key_id NULL
engine_id NULL
IP config:
IP assignment: DHCP
Proxy settings: NONE
 cuid=-1 luid=-1 lcuid=0 userApproved=USER_UNSPECIFIED noInternetAccessExpected=false isCarrierNetwork=false roamingFailureBlackListTimeMilli: 1000
triggeredLow: 0 triggeredBad: 0 triggeredNotHigh: 0
ticksLow: 0 ticksBad: 0 ticksNotHigh: 0
triggeredJoin: 0
    * ID: -1 SSID: "SSID" PROVIDER-NAME: null BSSID: null FQDN: null PRIO: 0 HIDDEN: false
 NetworkSelectionStatus NETWORK_SELECTION_ENABLED
 hasEverConnected: false
 KeyMgmt: WPA_EAP IEEE8021X Protocols:
 AuthAlgorithms:
 PairwiseCiphers:
 GroupCiphers:
 PSK: 
Enterprise config:
anonymous_identity NULL
password <removed>
identity "name"
domain_suffix_match NULL
proactive_key_caching 1
IP config:
IP assignment: UNASSIGNED
Proxy settings: UNASSIGNED
 cuid=-1 luid=-1 lcuid=0 userApproved=USER_UNSPECIFIED noInternetAccessExpected=false isCarrierNetwork=false roamingFailureBlackListTimeMilli: 1000
triggeredLow: 0 triggeredBad: 0 triggeredNotHigh: 0
ticksLow: 0 ticksBad: 0 ticksNotHigh: 0
triggeredJoin: 0
它是这样打印的:

* ID: -1 SSID: "SSID" PROVIDER-NAME: null BSSID: null FQDN: null PRIO: 0 HIDDEN: false
 NetworkSelectionStatus NETWORK_SELECTION_ENABLED
 hasEverConnected: false
 KeyMgmt: WPA_EAP IEEE8021X Protocols:
 AuthAlgorithms:
 PairwiseCiphers:
 GroupCiphers:
 PSK: 
Enterprise config:
password <removed>
ca_path NULL
engine 0
proactive_key_caching 1
client_cert NULL
anonymous_identity NULL
ca_cert NULL
identity "name"
domain_suffix_match NULL
key_id NULL
engine_id NULL
IP config:
IP assignment: DHCP
Proxy settings: NONE
 cuid=-1 luid=-1 lcuid=0 userApproved=USER_UNSPECIFIED noInternetAccessExpected=false isCarrierNetwork=false roamingFailureBlackListTimeMilli: 1000
triggeredLow: 0 triggeredBad: 0 triggeredNotHigh: 0
ticksLow: 0 ticksBad: 0 ticksNotHigh: 0
triggeredJoin: 0
    * ID: -1 SSID: "SSID" PROVIDER-NAME: null BSSID: null FQDN: null PRIO: 0 HIDDEN: false
 NetworkSelectionStatus NETWORK_SELECTION_ENABLED
 hasEverConnected: false
 KeyMgmt: WPA_EAP IEEE8021X Protocols:
 AuthAlgorithms:
 PairwiseCiphers:
 GroupCiphers:
 PSK: 
Enterprise config:
anonymous_identity NULL
password <removed>
identity "name"
domain_suffix_match NULL
proactive_key_caching 1
IP config:
IP assignment: UNASSIGNED
Proxy settings: UNASSIGNED
 cuid=-1 luid=-1 lcuid=0 userApproved=USER_UNSPECIFIED noInternetAccessExpected=false isCarrierNetwork=false roamingFailureBlackListTimeMilli: 1000
triggeredLow: 0 triggeredBad: 0 triggeredNotHigh: 0
ticksLow: 0 ticksBad: 0 ticksNotHigh: 0
triggeredJoin: 0
*ID:-1 SSID:“SSID”提供程序-NAME:null BSSID:null FQDN:null PRIO:0 HIDDEN:false
网络选择状态网络选择已启用
hasEverConnected:错误
密钥管理:WPA_EAP IEEE8021X协议:
授权算法:
成对密码:
分组密码:
PSK:
企业配置:
匿名身份为空
密码
身份“名称”
域\后缀\匹配NULL
主动\u密钥\u缓存1
IP配置:
IP分配:未分配
代理设置:未指定
cuid=-1 luid=-1 lcuid=0 userApproved=USER\u未指定的noInternetAccessExpected=false isCarrierNetwork=false roamingFailureBlackListTimeMilli:1000
triggeredLow:0 triggeredBad:0 triggeredNotHigh:0
滴答声慢:0滴答声白:0滴答声大腿:0
TriggerJoin:0

最后,它可以工作~

我无法理解这一点,所以我决定简单地告诉用户,如果没有找到连接或抛出异常,手动连接,它似乎工作得更好。所以解决方案是使用LEAP?