use of android.net.wifi.WifiEnterpriseConfig in project android_frameworks_base by ResurrectionRemix.
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;
}
use of android.net.wifi.WifiEnterpriseConfig in project android_frameworks_base by ResurrectionRemix.
the class ConfigBuilder method buildBaseConfiguration.
private static WifiConfiguration buildBaseConfiguration(HomeSP homeSP) throws IOException {
EAP.EAPMethodID eapMethodID = homeSP.getCredential().getEAPMethod().getEAPMethodID();
WifiConfiguration config = new WifiConfiguration();
config.FQDN = homeSP.getFQDN();
HashSet<Long> roamingConsortiumIds = homeSP.getRoamingConsortiums();
config.roamingConsortiumIds = new long[roamingConsortiumIds.size()];
int i = 0;
for (long id : roamingConsortiumIds) {
config.roamingConsortiumIds[i] = id;
i++;
}
config.providerFriendlyName = homeSP.getFriendlyName();
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
enterpriseConfig.setEapMethod(remapEAPMethod(eapMethodID));
enterpriseConfig.setRealm(homeSP.getCredential().getRealm());
if (homeSP.getUpdateIdentifier() >= 0) {
config.updateIdentifier = Integer.toString(homeSP.getUpdateIdentifier());
}
config.enterpriseConfig = enterpriseConfig;
if (homeSP.getUpdateIdentifier() >= 0) {
config.updateIdentifier = Integer.toString(homeSP.getUpdateIdentifier());
}
return config;
}
use of android.net.wifi.WifiEnterpriseConfig in project android_frameworks_base by ResurrectionRemix.
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;
}
*/
}
use of android.net.wifi.WifiEnterpriseConfig in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class WifiConfigController method showSecurityFields.
private void showSecurityFields() {
if (mAccessPointSecurity == AccessPoint.SECURITY_NONE) {
mView.findViewById(R.id.security_fields).setVisibility(View.GONE);
return;
}
mView.findViewById(R.id.security_fields).setVisibility(View.VISIBLE);
if (mPasswordView == null) {
mPasswordView = (TextView) mView.findViewById(R.id.password);
mPasswordView.addTextChangedListener(this);
mPasswordView.setOnEditorActionListener(this);
mPasswordView.setOnKeyListener(this);
((CheckBox) mView.findViewById(R.id.show_password)).setOnCheckedChangeListener(this);
if (mAccessPoint != null && mAccessPoint.isSaved()) {
mPasswordView.setHint(R.string.wifi_unchanged);
}
}
if (mAccessPointSecurity != AccessPoint.SECURITY_EAP) {
mView.findViewById(R.id.eap).setVisibility(View.GONE);
return;
}
mView.findViewById(R.id.eap).setVisibility(View.VISIBLE);
if (mEapMethodSpinner == null) {
getSIMInfo();
mEapMethodSpinner = (Spinner) mView.findViewById(R.id.method);
mEapMethodSpinner.setOnItemSelectedListener(this);
if (Utils.isWifiOnly(mContext) || !mContext.getResources().getBoolean(com.android.internal.R.bool.config_eap_sim_based_auth_supported)) {
String[] eapMethods = mContext.getResources().getStringArray(R.array.eap_method_without_sim_auth);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, eapMethods);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mEapMethodSpinner.setAdapter(spinnerAdapter);
}
mPhase2Spinner = (Spinner) mView.findViewById(R.id.phase2);
mEapCaCertSpinner = (Spinner) mView.findViewById(R.id.ca_cert);
mEapCaCertSpinner.setOnItemSelectedListener(this);
mEapDomainView = (TextView) mView.findViewById(R.id.domain);
mEapDomainView.addTextChangedListener(this);
mEapUserCertSpinner = (Spinner) mView.findViewById(R.id.user_cert);
mEapUserCertSpinner.setOnItemSelectedListener(this);
mSimCardSpinner = (Spinner) mView.findViewById(R.id.sim_card);
mEapIdentityView = (TextView) mView.findViewById(R.id.identity);
mEapAnonymousView = (TextView) mView.findViewById(R.id.anonymous);
loadCertificates(mEapCaCertSpinner, Credentials.CA_CERTIFICATE, mDoNotValidateEapServerString, false, true);
loadCertificates(mEapUserCertSpinner, Credentials.USER_PRIVATE_KEY, mDoNotProvideEapUserCertString, false, false);
// Modifying an existing network
if (mAccessPoint != null && mAccessPoint.isSaved()) {
WifiEnterpriseConfig enterpriseConfig = mAccessPoint.getConfig().enterpriseConfig;
int eapMethod = enterpriseConfig.getEapMethod();
int phase2Method = enterpriseConfig.getPhase2Method();
mEapMethodSpinner.setSelection(eapMethod);
showEapFieldsByMethod(eapMethod);
switch(eapMethod) {
case Eap.PEAP:
switch(phase2Method) {
case Phase2.NONE:
mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_NONE);
break;
case Phase2.MSCHAPV2:
mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_MSCHAPV2);
break;
case Phase2.GTC:
mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_GTC);
break;
default:
Log.e(TAG, "Invalid phase 2 method " + phase2Method);
break;
}
break;
case Eap.SIM:
case Eap.AKA:
case Eap.AKA_PRIME:
WifiConfiguration config = mAccessPoint.getConfig();
mSimCardSpinner.setSelection(config.SIMNum - 1);
break;
default:
mPhase2Spinner.setSelection(phase2Method);
break;
}
if (!TextUtils.isEmpty(enterpriseConfig.getCaPath())) {
setSelection(mEapCaCertSpinner, mUseSystemCertsString);
} else {
String[] caCerts = enterpriseConfig.getCaCertificateAliases();
if (caCerts == null) {
setSelection(mEapCaCertSpinner, mDoNotValidateEapServerString);
} else if (caCerts.length == 1) {
setSelection(mEapCaCertSpinner, caCerts[0]);
} else {
// Reload the cert spinner with an extra "multiple certificates added" item.
loadCertificates(mEapCaCertSpinner, Credentials.CA_CERTIFICATE, mDoNotValidateEapServerString, true, true);
setSelection(mEapCaCertSpinner, mMultipleCertSetString);
}
}
mEapDomainView.setText(enterpriseConfig.getDomainSuffixMatch());
String userCert = enterpriseConfig.getClientCertificateAlias();
if (TextUtils.isEmpty(userCert)) {
setSelection(mEapUserCertSpinner, mDoNotProvideEapUserCertString);
} else {
setSelection(mEapUserCertSpinner, userCert);
}
mEapIdentityView.setText(enterpriseConfig.getIdentity());
mEapAnonymousView.setText(enterpriseConfig.getAnonymousIdentity());
} else {
showEapFieldsByMethod(mEapMethodSpinner.getSelectedItemPosition());
}
} else {
showEapFieldsByMethod(mEapMethodSpinner.getSelectedItemPosition());
}
}
use of android.net.wifi.WifiEnterpriseConfig in project android_frameworks_base by DirtyUnicorns.
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;
}
Aggregations