use of android.net.wifi.hotspot2.PasspointConfiguration in project platform_frameworks_base by android.
the class PpsMoParser method parsePpsNode.
/**
* Parse a PerProviderSubscription node. Below is the format of the XML tree (with
* each XML element represent a node in the tree):
*
* <Node>
* <NodeName>PerProviderSubscription</NodeName>
* <RTProperties>
* ...
* </RTPProperties>
* <Node>
* <NodeName>UpdateIdentifier</NodeName>
* <Value>...</Value>
* </Node>
* <Node>
* ...
* </Node>
* </Node>
*
* @param node XMLNode that contains PerProviderSubscription node.
* @return PasspointConfiguration or null
* @throws ParsingException
*/
private static PasspointConfiguration parsePpsNode(XMLNode node) throws ParsingException {
PasspointConfiguration config = null;
String nodeName = null;
int updateIdentifier = Integer.MIN_VALUE;
for (XMLNode child : node.getChildren()) {
switch(child.getTag()) {
case TAG_NODE_NAME:
if (nodeName != null) {
throw new ParsingException("Duplicate NodeName: " + child.getText());
}
nodeName = child.getText();
if (!TextUtils.equals(nodeName, NODE_PER_PROVIDER_SUBSCRIPTION)) {
throw new ParsingException("Unexpected NodeName: " + nodeName);
}
break;
case TAG_NODE:
// A node can be either an UpdateIdentifier node or a PerProviderSubscription
// instance node. Flatten out the XML tree first by converting it to a PPS
// tree to reduce the complexity of the parsing code.
PPSNode ppsNodeRoot = buildPpsNode(child);
if (TextUtils.equals(ppsNodeRoot.getName(), NODE_UPDATE_IDENTIFIER)) {
if (updateIdentifier != Integer.MIN_VALUE) {
throw new ParsingException("Multiple node for UpdateIdentifier");
}
updateIdentifier = parseInteger(getPpsNodeValue(ppsNodeRoot));
} else {
// Only one PerProviderSubscription instance is expected and allowed.
if (config != null) {
throw new ParsingException("Multiple PPS instance");
}
config = parsePpsInstance(ppsNodeRoot);
}
break;
case TAG_RT_PROPERTIES:
// Parse and verify URN stored in the RT (Run Time) Properties.
String urn = parseUrn(child);
if (!TextUtils.equals(urn, PPS_MO_URN)) {
throw new ParsingException("Unknown URN: " + urn);
}
break;
default:
throw new ParsingException("Unknown tag under PPS node: " + child.getTag());
}
}
if (config != null && updateIdentifier != Integer.MIN_VALUE) {
config.setUpdateIdentifier(updateIdentifier);
}
return config;
}
use of android.net.wifi.hotspot2.PasspointConfiguration in project platform_frameworks_base by android.
the class ConfigParserTest method generateConfigurationFromProfile.
/**
* Generate a {@link PasspointConfiguration} that matches the configuration specified in the
* XML file {@link #PASSPOINT_INSTALLATION_FILE_WITH_CA_CERT}.
*
* @return {@link PasspointConfiguration}
*/
private PasspointConfiguration generateConfigurationFromProfile() {
PasspointConfiguration config = new PasspointConfiguration();
// HomeSP configuration.
HomeSp homeSp = new HomeSp();
homeSp.setFriendlyName("Century House");
homeSp.setFqdn("mi6.co.uk");
homeSp.setRoamingConsortiumOis(new long[] { 0x112233L, 0x445566L });
config.setHomeSp(homeSp);
// Credential configuration.
Credential credential = new Credential();
credential.setRealm("shaken.stirred.com");
Credential.UserCredential userCredential = new Credential.UserCredential();
userCredential.setUsername("james");
userCredential.setPassword("Ym9uZDAwNw==");
userCredential.setEapType(21);
userCredential.setNonEapInnerMethod("MS-CHAP-V2");
credential.setUserCredential(userCredential);
Credential.CertificateCredential certCredential = new Credential.CertificateCredential();
certCredential.setCertType("x509v3");
byte[] certSha256Fingerprint = new byte[32];
Arrays.fill(certSha256Fingerprint, (byte) 0x1f);
certCredential.setCertSha256Fingerprint(certSha256Fingerprint);
credential.setCertCredential(certCredential);
Credential.SimCredential simCredential = new Credential.SimCredential();
simCredential.setImsi("imsi");
simCredential.setEapType(24);
credential.setSimCredential(simCredential);
credential.setCaCertificate(FakeKeys.CA_CERT0);
config.setCredential(credential);
return config;
}
use of android.net.wifi.hotspot2.PasspointConfiguration in project platform_frameworks_base by android.
the class PpsMoParserTest method generateConfigurationFromPPSMOTree.
/**
* Generate a {@link PasspointConfiguration} that matches the configuration specified in the
* XML file {@link #VALID_PPS_MO_XML_FILE}.
*
* @return {@link PasspointConfiguration}
*/
private PasspointConfiguration generateConfigurationFromPPSMOTree() throws Exception {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
byte[] certFingerprint = new byte[32];
Arrays.fill(certFingerprint, (byte) 0x1f);
PasspointConfiguration config = new PasspointConfiguration();
config.setUpdateIdentifier(12);
config.setCredentialPriority(99);
// AAA Server trust root.
Map<String, byte[]> trustRootCertList = new HashMap<>();
trustRootCertList.put("server1.trust.root.com", certFingerprint);
config.setTrustRootCertList(trustRootCertList);
// Subscription update.
UpdateParameter subscriptionUpdate = new UpdateParameter();
subscriptionUpdate.setUpdateIntervalInMinutes(120);
subscriptionUpdate.setUpdateMethod(UpdateParameter.UPDATE_METHOD_SSP);
subscriptionUpdate.setRestriction(UpdateParameter.UPDATE_RESTRICTION_ROAMING_PARTNER);
subscriptionUpdate.setServerUri("subscription.update.com");
subscriptionUpdate.setUsername("subscriptionUser");
subscriptionUpdate.setBase64EncodedPassword("subscriptionPass");
subscriptionUpdate.setTrustRootCertUrl("subscription.update.cert.com");
subscriptionUpdate.setTrustRootCertSha256Fingerprint(certFingerprint);
config.setSubscriptionUpdate(subscriptionUpdate);
// Subscription parameters.
config.setSubscriptionCreationTimeInMs(format.parse("2016-02-01T10:00:00Z").getTime());
config.setSubscriptionExpirationTimeInMs(format.parse("2016-03-01T10:00:00Z").getTime());
config.setSubscriptionType("Gold");
config.setUsageLimitDataLimit(921890);
config.setUsageLimitStartTimeInMs(format.parse("2016-12-01T10:00:00Z").getTime());
config.setUsageLimitTimeLimitInMinutes(120);
config.setUsageLimitUsageTimePeriodInMinutes(99910);
// HomeSP configuration.
HomeSp homeSp = new HomeSp();
homeSp.setFriendlyName("Century House");
homeSp.setFqdn("mi6.co.uk");
homeSp.setRoamingConsortiumOis(new long[] { 0x112233L, 0x445566L });
homeSp.setIconUrl("icon.test.com");
Map<String, Long> homeNetworkIds = new HashMap<>();
homeNetworkIds.put("TestSSID", 0x12345678L);
homeNetworkIds.put("NullHESSID", null);
homeSp.setHomeNetworkIds(homeNetworkIds);
homeSp.setMatchAllOis(new long[] { 0x11223344 });
homeSp.setMatchAnyOis(new long[] { 0x55667788 });
homeSp.setOtherHomePartners(new String[] { "other.fqdn.com" });
config.setHomeSp(homeSp);
// Credential configuration.
Credential credential = new Credential();
credential.setCreationTimeInMs(format.parse("2016-01-01T10:00:00Z").getTime());
credential.setExpirationTimeInMs(format.parse("2016-02-01T10:00:00Z").getTime());
credential.setRealm("shaken.stirred.com");
credential.setCheckAaaServerCertStatus(true);
Credential.UserCredential userCredential = new Credential.UserCredential();
userCredential.setUsername("james");
userCredential.setPassword("Ym9uZDAwNw==");
userCredential.setMachineManaged(true);
userCredential.setSoftTokenApp("TestApp");
userCredential.setAbleToShare(true);
userCredential.setEapType(21);
userCredential.setNonEapInnerMethod("MS-CHAP-V2");
credential.setUserCredential(userCredential);
Credential.CertificateCredential certCredential = new Credential.CertificateCredential();
certCredential.setCertType("x509v3");
certCredential.setCertSha256Fingerprint(certFingerprint);
credential.setCertCredential(certCredential);
Credential.SimCredential simCredential = new Credential.SimCredential();
simCredential.setImsi("imsi");
simCredential.setEapType(24);
credential.setSimCredential(simCredential);
config.setCredential(credential);
// Policy configuration.
Policy policy = new Policy();
List<Policy.RoamingPartner> preferredRoamingPartnerList = new ArrayList<>();
Policy.RoamingPartner partner1 = new Policy.RoamingPartner();
partner1.setFqdn("test1.fqdn.com");
partner1.setFqdnExactMatch(true);
partner1.setPriority(127);
partner1.setCountries("us,fr");
Policy.RoamingPartner partner2 = new Policy.RoamingPartner();
partner2.setFqdn("test2.fqdn.com");
partner2.setFqdnExactMatch(false);
partner2.setPriority(200);
partner2.setCountries("*");
preferredRoamingPartnerList.add(partner1);
preferredRoamingPartnerList.add(partner2);
policy.setPreferredRoamingPartnerList(preferredRoamingPartnerList);
policy.setMinHomeDownlinkBandwidth(23412);
policy.setMinHomeUplinkBandwidth(9823);
policy.setMinRoamingDownlinkBandwidth(9271);
policy.setMinRoamingUplinkBandwidth(2315);
policy.setExcludedSsidList(new String[] { "excludeSSID" });
Map<Integer, String> requiredProtoPortMap = new HashMap<>();
requiredProtoPortMap.put(12, "34,92,234");
policy.setRequiredProtoPortMap(requiredProtoPortMap);
policy.setMaximumBssLoadValue(23);
UpdateParameter policyUpdate = new UpdateParameter();
policyUpdate.setUpdateIntervalInMinutes(120);
policyUpdate.setUpdateMethod(UpdateParameter.UPDATE_METHOD_OMADM);
policyUpdate.setRestriction(UpdateParameter.UPDATE_RESTRICTION_HOMESP);
policyUpdate.setServerUri("policy.update.com");
policyUpdate.setUsername("updateUser");
policyUpdate.setBase64EncodedPassword("updatePass");
policyUpdate.setTrustRootCertUrl("update.cert.com");
policyUpdate.setTrustRootCertSha256Fingerprint(certFingerprint);
policy.setPolicyUpdate(policyUpdate);
config.setPolicy(policy);
return config;
}
use of android.net.wifi.hotspot2.PasspointConfiguration in project platform_frameworks_base by android.
the class PpsMoParserTest method parseValidPPSMOTree.
/**
* Parse and verify all supported fields under PPS MO tree.
*
* @throws Exception
*/
@Test
public void parseValidPPSMOTree() throws Exception {
String ppsMoTree = loadResourceFile(VALID_PPS_MO_XML_FILE);
PasspointConfiguration expectedConfig = generateConfigurationFromPPSMOTree();
PasspointConfiguration actualConfig = PpsMoParser.parseMoText(ppsMoTree);
assertTrue(actualConfig.equals(expectedConfig));
}
use of android.net.wifi.hotspot2.PasspointConfiguration in project platform_frameworks_base by android.
the class PpsMoParser method parseMoText.
/**
* Convert a XML string representation of a PPS MO (PerProviderSubscription
* Management Object) tree to a {@link PasspointConfiguration} object.
*
* @param xmlString XML string representation of a PPS MO tree
* @return {@link PasspointConfiguration} or null
*/
public static PasspointConfiguration parseMoText(String xmlString) {
// Convert the XML string to a XML tree.
XMLParser xmlParser = new XMLParser();
XMLNode root = null;
try {
root = xmlParser.parse(xmlString);
} catch (IOException | SAXException e) {
return null;
}
if (root == null) {
return null;
}
// Verify root node is a "MgmtTree" node.
if (root.getTag() != TAG_MANAGEMENT_TREE) {
Log.e(TAG, "Root is not a MgmtTree");
return null;
}
// Used for detecting duplicate VerDTD element.
String verDtd = null;
PasspointConfiguration config = null;
for (XMLNode child : root.getChildren()) {
switch(child.getTag()) {
case TAG_VER_DTD:
if (verDtd != null) {
Log.e(TAG, "Duplicate VerDTD element");
return null;
}
verDtd = child.getText();
break;
case TAG_NODE:
if (config != null) {
Log.e(TAG, "Unexpected multiple Node element under MgmtTree");
return null;
}
try {
config = parsePpsNode(child);
} catch (ParsingException e) {
Log.e(TAG, e.getMessage());
return null;
}
break;
default:
Log.e(TAG, "Unknown node: " + child.getTag());
return null;
}
}
return config;
}
Aggregations