Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ff7a0a2 authored by Jan Nordqvist's avatar Jan Nordqvist
Browse files

Multiple fixes and clean up. Remediation working.

Change-Id: Ibb648e2f65acd345470347429330646a05eef167
parent e0248fe4
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package com.android.anqp;
import java.net.ProtocolException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import static com.android.anqp.Constants.BYTE_MASK;
import static com.android.anqp.Constants.SHORT_MASK;
@@ -49,6 +50,20 @@ public class HSIconFileElement extends ANQPElement {
        return mIconData;
    }

    @Override
    public boolean equals(Object thatObject) {
        if (thatObject == this) {
            return true;
        } else if (thatObject.getClass() != HSIconFileElement.class) {
            return false;
        }
        HSIconFileElement that = (HSIconFileElement) thatObject;
        if (getStatusCode() != that.getStatusCode() || getStatusCode() != StatusCode.Success) {
            return false;
        }
        return getType().equals(that.getType()) && Arrays.equals(getIconData(), that.getIconData());
    }

    @Override
    public String toString() {
        return "HSIconFile{" +
+17 −21
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import android.net.CaptivePortal;
import android.net.ConnectivityManager;
import android.net.ICaptivePortal;
import android.net.Network;
import android.net.wifi.PasspointManagementObjectDefinition;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiInfo;
@@ -85,18 +86,20 @@ public class WifiNetworkAdapter {
    }

    private void loadAllSps() {
        Log.d(OSUManager.TAG, "Loading all SPs");
        WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        int count = 0;
        for (WifiConfiguration config : wifiManager.getPrivilegedConfiguredNetworks()) {
            String moTree = config.getMoTree();
            if (moTree != null) {
                try {
                    mPasspointConfigs.put(config.FQDN, new PasspointConfig(config));
                    count++;
                } catch (IOException | SAXException e) {
                    Log.w(OSUManager.TAG, "Failed to parse MO: " + e);
                }
            }
        }
        Log.d(OSUManager.TAG, "Loaded " + count + " SPs");
    }

    public Collection<HomeSP> getLoadedSPs() {
@@ -131,21 +134,19 @@ public class WifiNetworkAdapter {
        mContext.startActivity(intent);
    }

    public HomeSP addSP(MOTree instanceTree) throws IOException, SAXException {
    public int addSP(String xml) throws IOException, SAXException {
        WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        String xml = instanceTree.toXml();
        wifiManager.addPasspointManagementObject(xml);
        return MOManager.buildSP(xml);
        return wifiManager.addPasspointManagementObject(xml);
    }

    public void removeSP(String fqdn) throws IOException {
    public int modifySP(HomeSP homeSP, Collection<MOData> mods) throws IOException {
        WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        List<PasspointManagementObjectDefinition> defMods = new ArrayList<>(mods.size());
        for (MOData mod : mods) {
            defMods.add(new PasspointManagementObjectDefinition(mod.getBaseURI(),
                    mod.getURN(), mod.getMOTree().toXml()));
        }

    public HomeSP modifySP(HomeSP homeSP, Collection<MOData> mods)
            throws IOException {
        WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        return null;
        return wifiManager.modifyPasspointManagementObject(homeSP.getFQDN(), defMods);
    }

    public Network getCurrentNetwork() {
@@ -184,9 +185,9 @@ public class WifiNetworkAdapter {
        return passpointConfig != null ? passpointConfig.getWifiConfiguration() : null;
    }

    public WifiConfiguration getActivePasspointNetwork() {
    public HomeSP getCurrentSP() {
        PasspointConfig passpointConfig = getActivePasspointConfig();
        return passpointConfig != null ? passpointConfig.getWifiConfiguration() : null;
        return passpointConfig != null ? passpointConfig.getHomeSP() : null;
    }

    private PasspointConfig getActivePasspointConfig() {
@@ -203,11 +204,6 @@ public class WifiNetworkAdapter {
        return null;
    }

    public HomeSP getCurrentSP() {
        PasspointConfig passpointConfig = getActivePasspointConfig();
        return passpointConfig != null ? passpointConfig.getHomeSP() : null;
    }

    public void doIconQuery(long bssid, String fileName) {
        WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        Log.d("ZXZ", String.format("Icon query for %012x '%s'", bssid, fileName));
@@ -289,11 +285,11 @@ public class WifiNetworkAdapter {
        WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);

        WifiConfiguration config = new WifiConfiguration();
        config.SSID = '"' + osuInfo.getSSID() + '"';
        config.SSID = '"' + osuInfo.getOsuSsid() + '"';
        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()));
                    osuInfo.getOsuSsid(), osuInfo.getOSUBssid()));
        }

        if (osuInfo.getOSUProvider().getOsuNai() == null) {
+2 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import com.android.hotspot2.asn1.Asn1Object;
import com.android.hotspot2.asn1.Asn1Oid;
import com.android.hotspot2.asn1.OidMappings;
import com.android.hotspot2.osu.HTTPHandler;
import com.android.hotspot2.osu.OSUManager;
import com.android.hotspot2.osu.OSUSocketFactory;
import com.android.hotspot2.osu.commands.GetCertData;
import com.android.hotspot2.pps.HomeSP;
@@ -80,7 +81,7 @@ public class ESTHandler implements AutoCloseable {
    private PrivateKey mClientKey;

    public ESTHandler(GetCertData certData, Network network, OMADMAdapter omadmAdapter,
                      KeyManager km, KeyStore ks, HomeSP homeSP, int flowType)
                      KeyManager km, KeyStore ks, HomeSP homeSP, OSUManager.FlowType flowType)
            throws IOException, GeneralSecurityException {
        mURL = new URL(certData.getServer());
        mUser = certData.getUserName();
+62 −17
Original line number Diff line number Diff line
@@ -220,7 +220,7 @@ public class MOManager {

    public HomeSP addSP(String xml, OSUManager osuManager) throws IOException, SAXException {
        OMAParser omaParser = new OMAParser();
        return addSP(omaParser.parse(xml, OMAConstants.PPS_URN), osuManager);
        return addSP(omaParser.parse(xml, OMAConstants.PPS_URN));
    }

    private static final List<String> FQDNPath = Arrays.asList(TAG_HomeSP, TAG_FQDN);
@@ -231,7 +231,7 @@ public class MOManager {
     * @param homeSP
     * @throws IOException
     */
    public void addSP(HomeSP homeSP, OSUManager osuManager) throws IOException {
    public void addSP(HomeSP homeSP) throws IOException {
        if (!mEnabled) {
            throw new IOException("HS2.0 not enabled on this device");
        }
@@ -245,18 +245,18 @@ public class MOManager {
        OMAConstructed dummyRoot = new OMAConstructed(null, TAG_PerProviderSubscription, null);
        buildHomeSPTree(homeSP, dummyRoot, mSPs.size() + 1);
        try {
            addSP(dummyRoot, osuManager);
            addSP(dummyRoot);
        } catch (FileNotFoundException fnfe) {
            MOTree tree =
                    MOTree.buildMgmtTree(OMAConstants.PPS_URN, OMAConstants.OMAVersion, dummyRoot);
            // No file to load a pre-build MO tree from, create a new one and save it.
            //MOTree tree = new MOTree(OMAConstants.PPS_URN, OMAConstants.OMAVersion, dummyRoot);
            writeMO(tree, mPpsFile, osuManager);
            writeMO(tree, mPpsFile);
        }
        mSPs.put(homeSP.getFQDN(), homeSP);
    }

    public HomeSP addSP(MOTree instanceTree, OSUManager osuManager) throws IOException {
    public HomeSP addSP(MOTree instanceTree) throws IOException {
        List<HomeSP> spList = buildSPs(instanceTree);
        if (spList.size() != 1) {
            throw new OMAException("Expected exactly one HomeSP, got " + spList.size());
@@ -272,11 +272,11 @@ public class MOManager {
                getChild(TAG_PerProviderSubscription);

        try {
            addSP(pps, osuManager);
            addSP(pps);
        } catch (FileNotFoundException fnfe) {
            MOTree tree = new MOTree(instanceTree.getUrn(), instanceTree.getDtdRev(),
                    instanceTree.getRoot());
            writeMO(tree, mPpsFile, osuManager);
            writeMO(tree, mPpsFile);
        }

        return sp;
@@ -289,7 +289,7 @@ public class MOManager {
     * @param mo The new MO
     * @throws IOException
     */
    private void addSP(OMANode mo, OSUManager osuManager) throws IOException {
    private void addSP(OMANode mo) throws IOException {
        MOTree moTree;
        try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) {
            moTree = MOTree.unmarshal(in);
@@ -315,7 +315,7 @@ public class MOManager {
            }
                */
        }
        writeMO(moTree, mPpsFile, osuManager);
        writeMO(moTree, mPpsFile);
    }

    private static OMAConstructed findTargetTree(MOTree moTree, String fqdn) throws OMAException {
@@ -347,7 +347,53 @@ public class MOManager {
        throw new OMAException("Cannot find instance node");
    }

    public HomeSP modifySP(HomeSP homeSP, Collection<MOData> mods, OSUManager osuManager)
    public static HomeSP modifySP(HomeSP homeSP, MOTree moTree, Collection<MOData> mods)
            throws OMAException {

        OMAConstructed ppsTree =
                (OMAConstructed) moTree.getRoot().getChildren().iterator().next();
        OMAConstructed instance = getInstanceNode(ppsTree);

        int ppsMods = 0;
        int updateIdentifier = homeSP.getUpdateIdentifier();
        for (MOData mod : mods) {
            LinkedList<String> tailPath =
                    getTailPath(mod.getBaseURI(), TAG_PerProviderSubscription);
            OMAConstructed modRoot = mod.getMOTree().getRoot();
            // modRoot is the MgmtTree with the actual object as a direct child
            // (e.g. Credential)

            if (tailPath.getFirst().equals(TAG_UpdateIdentifier)) {
                updateIdentifier = getInteger(modRoot.getChildren().iterator().next());
                OMANode oldUdi = ppsTree.getChild(TAG_UpdateIdentifier);
                if (getInteger(oldUdi) != updateIdentifier) {
                    ppsMods++;
                }
                if (oldUdi != null) {
                    ppsTree.replaceNode(oldUdi, modRoot.getChild(TAG_UpdateIdentifier));
                } else {
                    ppsTree.addChild(modRoot.getChild(TAG_UpdateIdentifier));
                }
            } else {
                tailPath.removeFirst();     // Drop the instance
                OMANode current = instance.getListValue(tailPath.iterator());
                if (current == null) {
                    throw new OMAException("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++;
                }
            }
        }

        return ppsMods > 0 ? buildHomeSP(instance, updateIdentifier) : null;
    }

    public HomeSP modifySP(HomeSP homeSP, Collection<MOData> mods)
            throws IOException {

        Log.d(OSUManager.TAG, "modifying SP: " + mods);
@@ -398,7 +444,7 @@ public class MOManager {
                }
            }
        }
        writeMO(moTree, mPpsFile, osuManager);
        writeMO(moTree, mPpsFile);

        if (ppsMods == 0) {
            return null;    // HomeSP not modified.
@@ -419,7 +465,7 @@ public class MOManager {
    }

    private static LinkedList<String> getTailPath(String pathString, String rootName)
            throws IOException {
            throws OMAException {
        String[] path = pathString.split("/");
        int pathIndex;
        for (pathIndex = 0; pathIndex < path.length; pathIndex++) {
@@ -429,7 +475,7 @@ public class MOManager {
            }
        }
        if (pathIndex >= path.length) {
            throw new IOException("Bad node-path: " + pathString);
            throw new OMAException("Bad node-path: " + pathString);
        }
        LinkedList<String> tailPath = new LinkedList<>();
        while (pathIndex < path.length) {
@@ -443,7 +489,7 @@ public class MOManager {
        return mSPs.get(fqdn);
    }

    public void removeSP(String fqdn, OSUManager osuManager) throws IOException {
    public void removeSP(String fqdn) throws IOException {
        if (mSPs.remove(fqdn) == null) {
            Log.d(OSUManager.TAG, "No HS20 profile to delete for " + fqdn);
            return;
@@ -464,8 +510,7 @@ public class MOManager {
                throw new IOException("Failed to remove " + fqdn + " out of MO tree");
            }
        }
        writeMO(moTree, mPpsFile, osuManager);
        osuManager.spDeleted(fqdn);
        writeMO(moTree, mPpsFile);
    }

    public MOTree getMOTree(HomeSP homeSP) throws IOException {
@@ -479,7 +524,7 @@ public class MOManager {
        }
    }

    private static void writeMO(MOTree moTree, File f, OSUManager osuManager) throws IOException {
    private static void writeMO(MOTree moTree, File f) throws IOException {
        try (BufferedOutputStream out =
                     new BufferedOutputStream(new FileOutputStream(f, false))) {
            moTree.marshal(out);
+1 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public class MOTree {
            case OMAConstants.DevInfoURN:
            case OMAConstants.DevDetailURN:
            case OMAConstants.DevDetailXURN:
                realRoot = new OMAConstructed(null, MgmtTreeTag, urn, "xmlns", OMAConstants.SyncML);
                realRoot = new MgmtTreeRoot(OMAConstants.OMAVersion);
                realRoot.addChild(root);
                return new MOTree(urn, rev, realRoot);
            default:
Loading