Search in sources :

Example 1 with Policy

use of android.net.wifi.hotspot2.pps.Policy in project platform_frameworks_base by android.

the class PasspointConfigurationTest method createPolicy.

/**
     * Helper function for creating a {@link Policy} for testing.
     *
     * @return {@link Policy}
     */
private static Policy createPolicy() {
    Policy policy = new Policy();
    policy.setMinHomeDownlinkBandwidth(123);
    policy.setMinHomeUplinkBandwidth(345);
    policy.setMinRoamingDownlinkBandwidth(567);
    policy.setMinRoamingUplinkBandwidth(789);
    policy.setMaximumBssLoadValue(12);
    policy.setExcludedSsidList(new String[] { "ssid1", "ssid2" });
    HashMap<Integer, String> requiredProtoPortMap = new HashMap<>();
    requiredProtoPortMap.put(12, "23,342,123");
    requiredProtoPortMap.put(23, "789,372,1235");
    policy.setRequiredProtoPortMap(requiredProtoPortMap);
    List<Policy.RoamingPartner> preferredRoamingPartnerList = new ArrayList<>();
    Policy.RoamingPartner partner1 = new Policy.RoamingPartner();
    partner1.setFqdn("partner1.com");
    partner1.setFqdnExactMatch(true);
    partner1.setPriority(12);
    partner1.setCountries("us,jp");
    Policy.RoamingPartner partner2 = new Policy.RoamingPartner();
    partner2.setFqdn("partner2.com");
    partner2.setFqdnExactMatch(false);
    partner2.setPriority(42);
    partner2.setCountries("ca,fr");
    preferredRoamingPartnerList.add(partner1);
    preferredRoamingPartnerList.add(partner2);
    policy.setPreferredRoamingPartnerList(preferredRoamingPartnerList);
    UpdateParameter policyUpdate = new UpdateParameter();
    policyUpdate.setUpdateIntervalInMinutes(1712);
    policyUpdate.setUpdateMethod(UpdateParameter.UPDATE_METHOD_OMADM);
    policyUpdate.setRestriction(UpdateParameter.UPDATE_RESTRICTION_HOMESP);
    policyUpdate.setServerUri("policy.update.com");
    policyUpdate.setUsername("username");
    policyUpdate.setBase64EncodedPassword(Base64.encodeToString("password".getBytes(), Base64.DEFAULT));
    policyUpdate.setTrustRootCertUrl("trust.cert.com");
    policyUpdate.setTrustRootCertSha256Fingerprint(new byte[CERTIFICATE_FINGERPRINT_BYTES]);
    policy.setPolicyUpdate(policyUpdate);
    return policy;
}
Also used : Policy(android.net.wifi.hotspot2.pps.Policy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UpdateParameter(android.net.wifi.hotspot2.pps.UpdateParameter)

Example 2 with Policy

use of android.net.wifi.hotspot2.pps.Policy in project platform_frameworks_base by android.

the class MOManager method buildHomeSP.

private static HomeSP buildHomeSP(OMANode ppsRoot, int updateIdentifier) throws OMAException {
    OMANode spRoot = ppsRoot.getChild(TAG_HomeSP);
    String fqdn = spRoot.getScalarValue(Arrays.asList(TAG_FQDN).iterator());
    String friendlyName = spRoot.getScalarValue(Arrays.asList(TAG_FriendlyName).iterator());
    String iconURL = spRoot.getScalarValue(Arrays.asList(TAG_IconURL).iterator());
    HashSet<Long> roamingConsortiums = new HashSet<>();
    String oiString = spRoot.getScalarValue(Arrays.asList(TAG_RoamingConsortiumOI).iterator());
    if (oiString != null) {
        for (String oi : oiString.split(",")) {
            roamingConsortiums.add(Long.parseLong(oi.trim(), 16));
        }
    }
    Map<String, Long> ssids = new HashMap<>();
    OMANode ssidListNode = spRoot.getListValue(Arrays.asList(TAG_NetworkID).iterator());
    if (ssidListNode != null) {
        for (OMANode ssidRoot : ssidListNode.getChildren()) {
            OMANode hessidNode = ssidRoot.getChild(TAG_HESSID);
            ssids.put(ssidRoot.getChild(TAG_SSID).getValue(), getMac(hessidNode));
        }
    }
    Set<Long> matchAnyOIs = new HashSet<>();
    List<Long> matchAllOIs = new ArrayList<>();
    OMANode homeOIListNode = spRoot.getListValue(Arrays.asList(TAG_HomeOIList).iterator());
    if (homeOIListNode != null) {
        for (OMANode homeOIRoot : homeOIListNode.getChildren()) {
            String homeOI = homeOIRoot.getChild(TAG_HomeOI).getValue();
            if (Boolean.parseBoolean(homeOIRoot.getChild(TAG_HomeOIRequired).getValue())) {
                matchAllOIs.add(Long.parseLong(homeOI, 16));
            } else {
                matchAnyOIs.add(Long.parseLong(homeOI, 16));
            }
        }
    }
    Set<String> otherHomePartners = new HashSet<>();
    OMANode otherListNode = spRoot.getListValue(Arrays.asList(TAG_OtherHomePartners).iterator());
    if (otherListNode != null) {
        for (OMANode fqdnNode : otherListNode.getChildren()) {
            otherHomePartners.add(fqdnNode.getChild(TAG_FQDN).getValue());
        }
    }
    Credential credential = buildCredential(ppsRoot.getChild(TAG_Credential));
    OMANode policyNode = ppsRoot.getChild(TAG_Policy);
    Policy policy = policyNode != null ? new Policy(policyNode) : null;
    Map<String, String> aaaTrustRoots;
    OMANode aaaRootNode = ppsRoot.getChild(TAG_AAAServerTrustRoot);
    if (aaaRootNode == null) {
        aaaTrustRoots = null;
    } else {
        aaaTrustRoots = new HashMap<>(aaaRootNode.getChildren().size());
        for (OMANode child : aaaRootNode.getChildren()) {
            aaaTrustRoots.put(getString(child, TAG_CertURL), getString(child, TAG_CertSHA256Fingerprint));
        }
    }
    OMANode updateNode = ppsRoot.getChild(TAG_SubscriptionUpdate);
    UpdateInfo subscriptionUpdate = updateNode != null ? new UpdateInfo(updateNode) : null;
    OMANode subNode = ppsRoot.getChild(TAG_SubscriptionParameters);
    SubscriptionParameters subscriptionParameters = subNode != null ? new SubscriptionParameters(subNode) : null;
    return new HomeSP(ssids, fqdn, roamingConsortiums, otherHomePartners, matchAnyOIs, matchAllOIs, friendlyName, iconURL, credential, policy, getInteger(ppsRoot.getChild(TAG_CredentialPriority), 0), aaaTrustRoots, subscriptionUpdate, subscriptionParameters, updateIdentifier);
}
Also used : Policy(com.android.hotspot2.pps.Policy) Credential(com.android.hotspot2.pps.Credential) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HomeSP(com.android.hotspot2.pps.HomeSP) SubscriptionParameters(com.android.hotspot2.pps.SubscriptionParameters) UpdateInfo(com.android.hotspot2.pps.UpdateInfo) HashSet(java.util.HashSet)

Example 3 with Policy

use of android.net.wifi.hotspot2.pps.Policy in project android_frameworks_base by crdroidandroid.

the class MOManager method buildHomeSP.

private static HomeSP buildHomeSP(OMANode ppsRoot, int updateIdentifier) throws OMAException {
    OMANode spRoot = ppsRoot.getChild(TAG_HomeSP);
    String fqdn = spRoot.getScalarValue(Arrays.asList(TAG_FQDN).iterator());
    String friendlyName = spRoot.getScalarValue(Arrays.asList(TAG_FriendlyName).iterator());
    String iconURL = spRoot.getScalarValue(Arrays.asList(TAG_IconURL).iterator());
    HashSet<Long> roamingConsortiums = new HashSet<>();
    String oiString = spRoot.getScalarValue(Arrays.asList(TAG_RoamingConsortiumOI).iterator());
    if (oiString != null) {
        for (String oi : oiString.split(",")) {
            roamingConsortiums.add(Long.parseLong(oi.trim(), 16));
        }
    }
    Map<String, Long> ssids = new HashMap<>();
    OMANode ssidListNode = spRoot.getListValue(Arrays.asList(TAG_NetworkID).iterator());
    if (ssidListNode != null) {
        for (OMANode ssidRoot : ssidListNode.getChildren()) {
            OMANode hessidNode = ssidRoot.getChild(TAG_HESSID);
            ssids.put(ssidRoot.getChild(TAG_SSID).getValue(), getMac(hessidNode));
        }
    }
    Set<Long> matchAnyOIs = new HashSet<>();
    List<Long> matchAllOIs = new ArrayList<>();
    OMANode homeOIListNode = spRoot.getListValue(Arrays.asList(TAG_HomeOIList).iterator());
    if (homeOIListNode != null) {
        for (OMANode homeOIRoot : homeOIListNode.getChildren()) {
            String homeOI = homeOIRoot.getChild(TAG_HomeOI).getValue();
            if (Boolean.parseBoolean(homeOIRoot.getChild(TAG_HomeOIRequired).getValue())) {
                matchAllOIs.add(Long.parseLong(homeOI, 16));
            } else {
                matchAnyOIs.add(Long.parseLong(homeOI, 16));
            }
        }
    }
    Set<String> otherHomePartners = new HashSet<>();
    OMANode otherListNode = spRoot.getListValue(Arrays.asList(TAG_OtherHomePartners).iterator());
    if (otherListNode != null) {
        for (OMANode fqdnNode : otherListNode.getChildren()) {
            otherHomePartners.add(fqdnNode.getChild(TAG_FQDN).getValue());
        }
    }
    Credential credential = buildCredential(ppsRoot.getChild(TAG_Credential));
    OMANode policyNode = ppsRoot.getChild(TAG_Policy);
    Policy policy = policyNode != null ? new Policy(policyNode) : null;
    Map<String, String> aaaTrustRoots;
    OMANode aaaRootNode = ppsRoot.getChild(TAG_AAAServerTrustRoot);
    if (aaaRootNode == null) {
        aaaTrustRoots = null;
    } else {
        aaaTrustRoots = new HashMap<>(aaaRootNode.getChildren().size());
        for (OMANode child : aaaRootNode.getChildren()) {
            aaaTrustRoots.put(getString(child, TAG_CertURL), getString(child, TAG_CertSHA256Fingerprint));
        }
    }
    OMANode updateNode = ppsRoot.getChild(TAG_SubscriptionUpdate);
    UpdateInfo subscriptionUpdate = updateNode != null ? new UpdateInfo(updateNode) : null;
    OMANode subNode = ppsRoot.getChild(TAG_SubscriptionParameters);
    SubscriptionParameters subscriptionParameters = subNode != null ? new SubscriptionParameters(subNode) : null;
    return new HomeSP(ssids, fqdn, roamingConsortiums, otherHomePartners, matchAnyOIs, matchAllOIs, friendlyName, iconURL, credential, policy, getInteger(ppsRoot.getChild(TAG_CredentialPriority), 0), aaaTrustRoots, subscriptionUpdate, subscriptionParameters, updateIdentifier);
}
Also used : Policy(com.android.hotspot2.pps.Policy) Credential(com.android.hotspot2.pps.Credential) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HomeSP(com.android.hotspot2.pps.HomeSP) SubscriptionParameters(com.android.hotspot2.pps.SubscriptionParameters) UpdateInfo(com.android.hotspot2.pps.UpdateInfo) HashSet(java.util.HashSet)

Example 4 with Policy

use of android.net.wifi.hotspot2.pps.Policy 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;
}
Also used : Policy(android.net.wifi.hotspot2.pps.Policy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HomeSp(android.net.wifi.hotspot2.pps.HomeSp) PasspointConfiguration(android.net.wifi.hotspot2.PasspointConfiguration) Credential(android.net.wifi.hotspot2.pps.Credential) UpdateParameter(android.net.wifi.hotspot2.pps.UpdateParameter) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with Policy

use of android.net.wifi.hotspot2.pps.Policy in project platform_frameworks_base by android.

the class PpsMoParser method parseUpdateParameter.

/**
     * Parse update parameters. This contained configurations from either
     * PerProviderSubscription/Policy/PolicyUpdate or PerProviderSubscription/SubscriptionUpdate
     * subtree.
     *
     * @param node PPSNode representing the root of the PerProviderSubscription/Policy/PolicyUpdate
     *             or PerProviderSubscription/SubscriptionUpdate subtree
     * @return {@link UpdateParameter}
     * @throws ParsingException
     */
private static UpdateParameter parseUpdateParameter(PPSNode node) throws ParsingException {
    if (node.isLeaf()) {
        throw new ParsingException("Leaf node not expected for Update Parameters");
    }
    UpdateParameter updateParam = new UpdateParameter();
    for (PPSNode child : node.getChildren()) {
        switch(child.getName()) {
            case NODE_UPDATE_INTERVAL:
                updateParam.setUpdateIntervalInMinutes(parseLong(getPpsNodeValue(child), 10));
                break;
            case NODE_UPDATE_METHOD:
                updateParam.setUpdateMethod(getPpsNodeValue(child));
                break;
            case NODE_RESTRICTION:
                updateParam.setRestriction(getPpsNodeValue(child));
                break;
            case NODE_URI:
                updateParam.setServerUri(getPpsNodeValue(child));
                break;
            case NODE_USERNAME_PASSWORD:
                Pair<String, String> usernamePassword = parseUpdateUserCredential(child);
                updateParam.setUsername(usernamePassword.first);
                updateParam.setBase64EncodedPassword(usernamePassword.second);
                break;
            case NODE_TRUST_ROOT:
                Pair<String, byte[]> trustRoot = parseTrustRoot(child);
                updateParam.setTrustRootCertUrl(trustRoot.first);
                updateParam.setTrustRootCertSha256Fingerprint(trustRoot.second);
                break;
            case NODE_OTHER:
                Log.d(TAG, "Ignore unsupported paramter: " + child.getName());
                break;
            default:
                throw new ParsingException("Unknown node under Update Parameters: " + child.getName());
        }
    }
    return updateParam;
}
Also used : UpdateParameter(android.net.wifi.hotspot2.pps.UpdateParameter)

Aggregations

ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Credential (com.android.hotspot2.pps.Credential)5 HomeSP (com.android.hotspot2.pps.HomeSP)5 Policy (com.android.hotspot2.pps.Policy)5 SubscriptionParameters (com.android.hotspot2.pps.SubscriptionParameters)5 UpdateInfo (com.android.hotspot2.pps.UpdateInfo)5 HashSet (java.util.HashSet)5 UpdateParameter (android.net.wifi.hotspot2.pps.UpdateParameter)3 Policy (android.net.wifi.hotspot2.pps.Policy)2 PasspointConfiguration (android.net.wifi.hotspot2.PasspointConfiguration)1 Credential (android.net.wifi.hotspot2.pps.Credential)1 HomeSp (android.net.wifi.hotspot2.pps.HomeSp)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1