Search in sources :

Example 46 with HomeSp

use of android.net.wifi.hotspot2.pps.HomeSp in project android_frameworks_base by ResurrectionRemix.

the class OSUManager method remediationComplete.

public void remediationComplete(HomeSP homeSP, Collection<MOData> mods, Map<OSUCertType, List<X509Certificate>> certs, PrivateKey privateKey) throws IOException, GeneralSecurityException {
    HomeSP altSP = mWifiNetworkAdapter.modifySP(homeSP, mods);
    X509Certificate caCert = null;
    List<X509Certificate> clientCerts = null;
    if (certs != null) {
        List<X509Certificate> certList = certs.get(OSUCertType.AAA);
        caCert = certList != null && !certList.isEmpty() ? certList.iterator().next() : null;
        clientCerts = certs.get(OSUCertType.Client);
    }
    if (altSP != null || certs != null) {
        if (altSP == null) {
            // No MO mods, only certs and key
            altSP = homeSP;
        }
        mWifiNetworkAdapter.updateNetwork(altSP, caCert, clientCerts, privateKey);
    }
    notifyUser(OSUOperationStatus.ProvisioningSuccess, null, homeSP.getFriendlyName());
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) X509Certificate(java.security.cert.X509Certificate)

Example 47 with HomeSp

use of android.net.wifi.hotspot2.pps.HomeSp in project android_frameworks_base by ResurrectionRemix.

the class OSUManager method deauth.

public void deauth(long bssid, boolean ess, int delay, String url) throws MalformedURLException {
    Log.d(TAG, String.format("De-auth imminent on %s, delay %ss to '%s'", ess ? "ess" : "bss", delay, url));
    mWifiNetworkAdapter.setHoldoffTime(delay * Constants.MILLIS_IN_A_SEC, ess);
    HomeSP homeSP = mWifiNetworkAdapter.getCurrentSP();
    String spName = homeSP != null ? homeSP.getFriendlyName() : "unknown";
    mAppBridge.showDeauth(spName, ess, delay, url);
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP)

Example 48 with HomeSp

use of android.net.wifi.hotspot2.pps.HomeSp in project android_frameworks_base by ResurrectionRemix.

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 49 with HomeSp

use of android.net.wifi.hotspot2.pps.HomeSp in project android_frameworks_base by ResurrectionRemix.

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;
}
Also used : IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) HomeSP(com.android.hotspot2.pps.HomeSP) MOData(com.android.hotspot2.osu.commands.MOData) BufferedInputStream(java.io.BufferedInputStream)

Example 50 with HomeSp

use of android.net.wifi.hotspot2.pps.HomeSp in project android_frameworks_base by ResurrectionRemix.

the class MOManager method fqdnList.

private static String fqdnList(Collection<HomeSP> sps) {
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (HomeSP sp : sps) {
        if (first) {
            first = false;
        } else {
            sb.append(", ");
        }
        sb.append(sp.getFQDN());
    }
    return sb.toString();
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP)

Aggregations

HomeSP (com.android.hotspot2.pps.HomeSP)50 IOException (java.io.IOException)20 BufferedInputStream (java.io.BufferedInputStream)10 FileInputStream (java.io.FileInputStream)10 X509Certificate (java.security.cert.X509Certificate)10 SAXException (org.xml.sax.SAXException)10 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 Network (android.net.Network)5 WifiConfiguration (android.net.wifi.WifiConfiguration)5 WifiInfo (android.net.wifi.WifiInfo)5 MOData (com.android.hotspot2.osu.commands.MOData)5 Credential (com.android.hotspot2.pps.Credential)5 Policy (com.android.hotspot2.pps.Policy)5 SubscriptionParameters (com.android.hotspot2.pps.SubscriptionParameters)5 UpdateInfo (com.android.hotspot2.pps.UpdateInfo)5 FileNotFoundException (java.io.FileNotFoundException)5 FileOutputStream (java.io.FileOutputStream)5 GeneralSecurityException (java.security.GeneralSecurityException)5 HashSet (java.util.HashSet)5