use of com.android.hotspot2.pps.Credential in project platform_frameworks_base by android.
the class PasspointConfigurationTest method createCredential.
/**
* Utility function for creating a {@link android.net.wifi.hotspot2.pps.Credential}.
*
* @return {@link android.net.wifi.hotspot2.pps.Credential}
*/
private static Credential createCredential() {
Credential cred = new Credential();
cred.setRealm("realm");
cred.setUserCredential(null);
cred.setCertCredential(null);
cred.setSimCredential(new Credential.SimCredential());
cred.getSimCredential().setImsi("1234*");
cred.getSimCredential().setEapType(EAPConstants.EAP_SIM);
cred.setCaCertificate(null);
cred.setClientCertificateChain(null);
cred.setClientPrivateKey(null);
return cred;
}
use of com.android.hotspot2.pps.Credential 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;
}
use of com.android.hotspot2.pps.Credential 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;
}
use of com.android.hotspot2.pps.Credential in project android_frameworks_base by DirtyUnicorns.
the class OSUClient method createHandler.
private HTTPHandler createHandler(Network network, HomeSP homeSP, KeyManager km, int flowType) throws GeneralSecurityException, IOException {
Credential credential = homeSP.getCredential();
Log.d(TAG, "Credential method " + credential.getEAPMethod().getEAPMethodID());
switch(credential.getEAPMethod().getEAPMethodID()) {
case EAP_TTLS:
String user;
byte[] password;
UpdateInfo subscriptionUpdate;
if (flowType == OSUManager.FLOW_POLICY) {
subscriptionUpdate = homeSP.getPolicy() != null ? homeSP.getPolicy().getPolicyUpdate() : null;
} else {
subscriptionUpdate = homeSP.getSubscriptionUpdate();
}
if (subscriptionUpdate != null && subscriptionUpdate.getUsername() != null) {
user = subscriptionUpdate.getUsername();
password = subscriptionUpdate.getPassword() != null ? subscriptionUpdate.getPassword().getBytes(StandardCharsets.UTF_8) : new byte[0];
} else {
user = credential.getUserName();
password = credential.getPassword().getBytes(StandardCharsets.UTF_8);
}
return new HTTPHandler(StandardCharsets.UTF_8, OSUSocketFactory.getSocketFactory(mKeyStore, homeSP, flowType, network, mURL, km, true), user, password);
case EAP_TLS:
return new HTTPHandler(StandardCharsets.UTF_8, OSUSocketFactory.getSocketFactory(mKeyStore, homeSP, flowType, network, mURL, km, true));
default:
throw new IOException("Cannot remediate account with " + credential.getEAPMethod().getEAPMethodID());
}
}
use of com.android.hotspot2.pps.Credential in project android_frameworks_base by DirtyUnicorns.
the class MOManager method modifySP.
public HomeSP modifySP(HomeSP homeSP, Collection<MOData> mods, OSUManager osuManager) throws IOException {
Log.d(OSUManager.TAG, "modifying SP: " + mods);
MOTree moTree;
int ppsMods = 0;
int updateIdentifier = 0;
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) {
moTree = MOTree.unmarshal(in);
// moTree is PPS/?/provider-data
OMAConstructed targetTree = findTargetTree(moTree, homeSP.getFQDN());
if (targetTree == null) {
throw new IOException("Failed to find PPS tree for " + homeSP.getFQDN());
}
OMAConstructed instance = getInstanceNode(targetTree);
for (MOData mod : mods) {
LinkedList<String> tailPath = getTailPath(mod.getBaseURI(), TAG_PerProviderSubscription);
OMAConstructed modRoot = mod.getMOTree().getRoot();
if (tailPath.getFirst().equals(TAG_UpdateIdentifier)) {
updateIdentifier = getInteger(modRoot.getChildren().iterator().next());
OMANode oldUdi = targetTree.getChild(TAG_UpdateIdentifier);
if (getInteger(oldUdi) != updateIdentifier) {
ppsMods++;
}
if (oldUdi != null) {
targetTree.replaceNode(oldUdi, modRoot.getChild(TAG_UpdateIdentifier));
} else {
targetTree.addChild(modRoot.getChild(TAG_UpdateIdentifier));
}
} else {
// Drop the instance
tailPath.removeFirst();
OMANode current = instance.getListValue(tailPath.iterator());
if (current == null) {
throw new IOException("No previous node for " + tailPath + " in " + homeSP.getFQDN());
}
for (OMANode newNode : modRoot.getChildren()) {
// newNode is something like Credential
// current is the same existing node
OMANode old = current.getParent().replaceNode(current, newNode);
ppsMods++;
}
}
}
}
writeMO(moTree, mPpsFile, osuManager);
if (ppsMods == 0) {
// HomeSP not modified.
return null;
}
// Return a new rebuilt HomeSP
List<HomeSP> sps = buildSPs(moTree);
if (sps != null) {
for (HomeSP sp : sps) {
if (sp.getFQDN().equals(homeSP.getFQDN())) {
return sp;
}
}
} else {
throw new OMAException("Failed to build HomeSP");
}
return null;
}
Aggregations