Android的连接到无线网络的企业EAP(PEAP) [英] Connect Android to WiFi Enterprise network EAP(PEAP)

查看:4080
本文介绍了Android的连接到无线网络的企业EAP(PEAP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想我的Andr​​oid设备连接到企业网络编程,在过去几天,没有任何成功的,我一直在关注多个示例在线,但大多数的人,我觉得是EAP(TLS)网络和之一,我的工作是EAP(PEAP),这里是网络的类型。

I have been trying to connect my android device to an enterprise network programatically over the past few days without any success, I have been following multiple examples online, but most of the ones I find are for EAP(TLS) networks and the one where I work is EAP(PEAP), here is the type of network.

802.1X EAP

802.1x EAP

EAP方法:PEAP

EAP method: PEAP

第二阶段认证:MSCHAPV2

Phase 2 Authentication: MSCHAPV2

验证总是失败和的logcat并不表示我是哪里的问题我只知道当执行验证失败。

the authentication always fails and logcat doesn't indicate me where the problem is I just know it fails when the authentication is being performed.

下面是我目前的code副本,并从那里的logcat失败的日志:

Here is a copy of my current code and the logs from logcat where it fails:

/ * 的**的 * 的**的 * 的* code * 的**的 * 的**的 * 的**的 * 的**的 * 的*** /

/******** CODE ****************/

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 );
}
}

和这些指示,其中连接尝试失败的日志

and these are the logs indicating where the connection attempt fails

/ * 的**的 * 的**的 * 的**的 * 的* 这是日志 * 的**的 * 的**的 * 的** /

/***********And here are the logs*********/

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)身份验证编程,我试图改变没有成功的无线网络配置。如何连接到企业网络的EAP(PEAP),或可有人点我在正确的方向?任何意见或有帮助的网站/例子

I couldn’t find examples online about EAP (PEAP) authentication programmatically, I have tried changing the WiFi configuration with no success. Any Ideas or helpful sites/examples on how to connect to a Enterprise network EAP (PEAP), or can someone point me in the right direction?

推荐答案

最后,我已经打败了我的思科EAP-FAST公司的WIFI网络,和我们所有的Andr​​oid设备现在能够连接到它。

Finally, I've defeated my CiSCO EAP-FAST corporate wifi network, and all our Android devices are now able to connect to it.

在步行约我为了获得这种网络从Android设备进行最简单的是比你的想象。

The walk-around I've performed in order to gain access to this kind of networks from an Android device are easiest than you can imagine.

有一个无线配置编辑器在谷歌Play商店,你可以用它来激活二次CISCO的协议,当你在设置的EAP WiFi连接。

There's a Wifi Config Editor in the Google Play Store you can use to "activate" the secondary CISCO Protocols when you are setting up a EAP wifi connection.

它的名字是无线配置高级编辑器。

Its name is Wifi Config Advanced Editor.

  • 首先,你必须设置你的无线网络中手动接近你可以到你的官方的企业无线网络的参数。

  • First, you have to setup your wireless network manually as close as you can to your "official" corporate wifi parameters.

保存它。

转至WCE和编辑已在previous步骤中创建的网络的参数。

Go to the WCE and edit the parameters of the network you have created in the previous step.

有3个或4个系列的设置,你应该激活,以迫使Android设备使用它们作为一种连接(在主网站,我认为您要访问的是企业配置,但不要忘了,如果需要检查所有参数进行更改。
作为一个建议,即使你有一个WPA2 EAP-FAST密码,尝试飞跃您的设置。它的工作对我来说是一个魅力。

There are 3 or 4 series of settings you should activate in order to force the Android device to use them as a way to connect (the main site I think you want to visit is Enterprise Configuration, but don't forget to check all the parameters to change them if needed.
As a suggestion, even if you have a WPA2 EAP-FAST Cipher, try LEAP in your setup. It worked for me as a charm.

当您完成编辑配置,进入主Android的无线控制器和力连接到该网络。

When you finished to edit the config, go to the main Android wifi controller, and force to connect to this network.

不要了Android WiFi接口再次编辑网络。

Do not Edit the network again with the Android wifi interface.

我已经对三星Galaxy 1和2进行了测试,注意移动设备,并在联想ThinkPad平板电脑。

I have tested it on Samsung Galaxy 1 and 2, Note mobile devices, and on a Lenovo Thinkpad Tablet.

这篇关于Android的连接到无线网络的企业EAP(PEAP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆