Search in sources :

Example 21 with HomeSP

use of com.android.hotspot2.pps.HomeSP in project android_frameworks_base by DirtyUnicorns.

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)

Example 22 with HomeSP

use of com.android.hotspot2.pps.HomeSP 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;
}
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 23 with HomeSP

use of com.android.hotspot2.pps.HomeSP in project android_frameworks_base by DirtyUnicorns.

the class MOManager method buildHomeSPTree.

private static OMANode buildHomeSPTree(HomeSP homeSP, OMAConstructed root, int instanceID) throws IOException {
    OMANode providerSubNode = root.addChild(getInstanceString(instanceID), null, null, null);
    // The HomeSP:
    OMANode homeSpNode = providerSubNode.addChild(TAG_HomeSP, null, null, null);
    if (!homeSP.getSSIDs().isEmpty()) {
        OMAConstructed nwkIDNode = (OMAConstructed) homeSpNode.addChild(TAG_NetworkID, null, null, null);
        int instance = 0;
        for (Map.Entry<String, Long> entry : homeSP.getSSIDs().entrySet()) {
            OMAConstructed inode = (OMAConstructed) nwkIDNode.addChild(getInstanceString(instance++), null, null, null);
            inode.addChild(TAG_SSID, null, entry.getKey(), null);
            if (entry.getValue() != null) {
                inode.addChild(TAG_HESSID, null, String.format("%012x", entry.getValue()), null);
            }
        }
    }
    homeSpNode.addChild(TAG_FriendlyName, null, homeSP.getFriendlyName(), null);
    if (homeSP.getIconURL() != null) {
        homeSpNode.addChild(TAG_IconURL, null, homeSP.getIconURL(), null);
    }
    homeSpNode.addChild(TAG_FQDN, null, homeSP.getFQDN(), null);
    if (!homeSP.getMatchAllOIs().isEmpty() || !homeSP.getMatchAnyOIs().isEmpty()) {
        OMAConstructed homeOIList = (OMAConstructed) homeSpNode.addChild(TAG_HomeOIList, null, null, null);
        int instance = 0;
        for (Long oi : homeSP.getMatchAllOIs()) {
            OMAConstructed inode = (OMAConstructed) homeOIList.addChild(getInstanceString(instance++), null, null, null);
            inode.addChild(TAG_HomeOI, null, String.format("%x", oi), null);
            inode.addChild(TAG_HomeOIRequired, null, "TRUE", null);
        }
        for (Long oi : homeSP.getMatchAnyOIs()) {
            OMAConstructed inode = (OMAConstructed) homeOIList.addChild(getInstanceString(instance++), null, null, null);
            inode.addChild(TAG_HomeOI, null, String.format("%x", oi), null);
            inode.addChild(TAG_HomeOIRequired, null, "FALSE", null);
        }
    }
    if (!homeSP.getOtherHomePartners().isEmpty()) {
        OMAConstructed otherPartners = (OMAConstructed) homeSpNode.addChild(TAG_OtherHomePartners, null, null, null);
        int instance = 0;
        for (String fqdn : homeSP.getOtherHomePartners()) {
            OMAConstructed inode = (OMAConstructed) otherPartners.addChild(getInstanceString(instance++), null, null, null);
            inode.addChild(TAG_FQDN, null, fqdn, null);
        }
    }
    if (!homeSP.getRoamingConsortiums().isEmpty()) {
        homeSpNode.addChild(TAG_RoamingConsortiumOI, null, getRCList(homeSP.getRoamingConsortiums()), null);
    }
    // The Credential:
    OMANode credentialNode = providerSubNode.addChild(TAG_Credential, null, null, null);
    Credential cred = homeSP.getCredential();
    EAPMethod method = cred.getEAPMethod();
    if (cred.getCtime() > 0) {
        credentialNode.addChild(TAG_CreationDate, null, DTFormat.format(new Date(cred.getCtime())), null);
    }
    if (cred.getExpTime() > 0) {
        credentialNode.addChild(TAG_ExpirationDate, null, DTFormat.format(new Date(cred.getExpTime())), null);
    }
    if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_SIM || method.getEAPMethodID() == EAP.EAPMethodID.EAP_AKA || method.getEAPMethodID() == EAP.EAPMethodID.EAP_AKAPrim) {
        OMANode simNode = credentialNode.addChild(TAG_SIM, null, null, null);
        simNode.addChild(TAG_IMSI, null, cred.getImsi().toString(), null);
        simNode.addChild(TAG_EAPType, null, Integer.toString(EAP.mapEAPMethod(method.getEAPMethodID())), null);
    } else if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_TTLS) {
        OMANode unpNode = credentialNode.addChild(TAG_UsernamePassword, null, null, null);
        unpNode.addChild(TAG_Username, null, cred.getUserName(), null);
        unpNode.addChild(TAG_Password, null, Base64.encodeToString(cred.getPassword().getBytes(StandardCharsets.UTF_8), Base64.DEFAULT), null);
        OMANode eapNode = unpNode.addChild(TAG_EAPMethod, null, null, null);
        eapNode.addChild(TAG_EAPType, null, Integer.toString(EAP.mapEAPMethod(method.getEAPMethodID())), null);
        eapNode.addChild(TAG_InnerMethod, null, ((NonEAPInnerAuth) method.getAuthParam()).getOMAtype(), null);
    } else if (method.getEAPMethodID() == EAP.EAPMethodID.EAP_TLS) {
        OMANode certNode = credentialNode.addChild(TAG_DigitalCertificate, null, null, null);
        certNode.addChild(TAG_CertificateType, null, Credential.CertTypeX509, null);
        certNode.addChild(TAG_CertSHA256Fingerprint, null, Utils.toHex(cred.getFingerPrint()), null);
    } else {
        throw new OMAException("Invalid credential on " + homeSP.getFQDN());
    }
    credentialNode.addChild(TAG_Realm, null, cred.getRealm(), null);
    //credentialNode.addChild(TAG_CheckAAAServerCertStatus, null, "TRUE", null);
    return providerSubNode;
}
Also used : Credential(com.android.hotspot2.pps.Credential) HashMap(java.util.HashMap) Map(java.util.Map) ExpandedEAPMethod(com.android.anqp.eap.ExpandedEAPMethod) EAPMethod(com.android.anqp.eap.EAPMethod) Date(java.util.Date) NonEAPInnerAuth(com.android.anqp.eap.NonEAPInnerAuth)

Example 24 with HomeSP

use of com.android.hotspot2.pps.HomeSP in project android_frameworks_base by DirtyUnicorns.

the class MOManager method loadAllSPs.

public List<HomeSP> loadAllSPs() throws IOException {
    if (!mEnabled || !mPpsFile.exists()) {
        return Collections.emptyList();
    }
    try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) {
        MOTree moTree = MOTree.unmarshal(in);
        mSPs.clear();
        if (moTree == null) {
            // Empty file
            return Collections.emptyList();
        }
        List<HomeSP> sps = buildSPs(moTree);
        if (sps != null) {
            for (HomeSP sp : sps) {
                if (mSPs.put(sp.getFQDN(), sp) != null) {
                    throw new OMAException("Multiple SPs for FQDN '" + sp.getFQDN() + "'");
                } else {
                    Log.d(OSUManager.TAG, "retrieved " + sp.getFQDN() + " from PPS");
                }
            }
            return sps;
        } else {
            throw new OMAException("Failed to build HomeSP");
        }
    }
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream)

Example 25 with HomeSP

use of com.android.hotspot2.pps.HomeSP in project android_frameworks_base by DirtyUnicorns.

the class MOManager method addSP.

public HomeSP addSP(MOTree instanceTree, OSUManager osuManager) throws IOException {
    List<HomeSP> spList = buildSPs(instanceTree);
    if (spList.size() != 1) {
        throw new OMAException("Expected exactly one HomeSP, got " + spList.size());
    }
    HomeSP sp = spList.iterator().next();
    String fqdn = sp.getFQDN();
    if (mSPs.put(fqdn, sp) != null) {
        throw new OMAException("SP " + fqdn + " already exists");
    }
    OMAConstructed pps = (OMAConstructed) instanceTree.getRoot().getChild(TAG_PerProviderSubscription);
    try {
        addSP(pps, osuManager);
    } catch (FileNotFoundException fnfe) {
        MOTree tree = new MOTree(instanceTree.getUrn(), instanceTree.getDtdRev(), instanceTree.getRoot());
        writeMO(tree, mPpsFile, osuManager);
    }
    return sp;
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

HomeSP (com.android.hotspot2.pps.HomeSP)50 IOException (java.io.IOException)45 Credential (com.android.hotspot2.pps.Credential)35 WifiConfiguration (android.net.wifi.WifiConfiguration)25 HashMap (java.util.HashMap)16 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)15 X509Certificate (java.security.cert.X509Certificate)15 ArrayList (java.util.ArrayList)12 EAPMethod (com.android.anqp.eap.EAPMethod)10 NonEAPInnerAuth (com.android.anqp.eap.NonEAPInnerAuth)10 MOData (com.android.hotspot2.osu.commands.MOData)10 UpdateInfo (com.android.hotspot2.pps.UpdateInfo)10 BufferedInputStream (java.io.BufferedInputStream)10 FileInputStream (java.io.FileInputStream)10 GeneralSecurityException (java.security.GeneralSecurityException)10 SAXException (org.xml.sax.SAXException)10 List (java.util.List)6 Network (android.net.Network)5 WifiInfo (android.net.wifi.WifiInfo)5 AuthParam (com.android.anqp.eap.AuthParam)5