Search in sources :

Example 16 with HomeSp

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

the class OSUManager method wnmRemediate.

// !!! Consistently check passpoint match.
// !!! Convert to a one-thread thread-pool
public void wnmRemediate(long bssid, String url, PasspointMatch match) throws IOException, SAXException {
    WifiConfiguration config = mWifiNetworkAdapter.getActiveWifiConfig();
    HomeSP homeSP = MOManager.buildSP(config.getMoTree());
    if (homeSP == null) {
        throw new IOException("Remediation request for unidentified Passpoint network " + config.networkId);
    }
    Network network = mWifiNetworkAdapter.getCurrentNetwork();
    if (network == null) {
        throw new IOException("Failed to determine current network");
    }
    WifiInfo wifiInfo = mWifiNetworkAdapter.getConnectionInfo();
    if (wifiInfo == null || Utils.parseMac(wifiInfo.getBSSID()) != bssid) {
        throw new IOException("Mismatching BSSID");
    }
    Log.d(TAG, "WNM Remediation on " + network.netId + " FQDN " + homeSP.getFQDN());
    doRemediate(url, network, homeSP, false);
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) WifiConfiguration(android.net.wifi.WifiConfiguration) Network(android.net.Network) IOException(java.io.IOException) WifiInfo(android.net.wifi.WifiInfo)

Example 17 with HomeSp

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

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)

Example 18 with HomeSp

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

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

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

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

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

the class OSUManager method provisioningComplete.

public void provisioningComplete(OSUInfo osuInfo, MOData moData, Map<OSUCertType, List<X509Certificate>> certs, PrivateKey privateKey, Network osuNetwork) {
    synchronized (mWifiNetworkAdapter) {
        mProvisioningThread = null;
    }
    try {
        Log.d("ZXZ", "MOTree.toXML: " + moData.getMOTree().toXml());
        HomeSP homeSP = mWifiNetworkAdapter.addSP(moData.getMOTree());
        Integer spNwk = mWifiNetworkAdapter.addNetwork(homeSP, certs, privateKey, osuNetwork);
        if (spNwk == null) {
            notifyUser(OSUOperationStatus.ProvisioningFailure, "Failed to save network configuration", osuInfo.getName(LOCALE));
            mWifiNetworkAdapter.removeSP(homeSP.getFQDN());
        } else {
            Set<X509Certificate> rootCerts = OSUSocketFactory.getRootCerts(mKeyStore);
            X509Certificate remCert = getCert(certs, OSUCertType.Remediation);
            X509Certificate polCert = getCert(certs, OSUCertType.Policy);
            if (privateKey != null) {
                X509Certificate cltCert = getCert(certs, OSUCertType.Client);
                mKeyStore.setKeyEntry(CERT_CLT_KEY_ALIAS + homeSP, privateKey.getEncoded(), new X509Certificate[] { cltCert });
                mKeyStore.setCertificateEntry(CERT_CLT_CERT_ALIAS, cltCert);
            }
            boolean usingShared = false;
            int newCerts = 0;
            if (remCert != null) {
                if (!rootCerts.contains(remCert)) {
                    if (remCert.equals(polCert)) {
                        mKeyStore.setCertificateEntry(CERT_SHARED_ALIAS + homeSP.getFQDN(), remCert);
                        usingShared = true;
                        newCerts++;
                    } else {
                        mKeyStore.setCertificateEntry(CERT_REM_ALIAS + homeSP.getFQDN(), remCert);
                        newCerts++;
                    }
                }
            }
            if (!usingShared && polCert != null) {
                if (!rootCerts.contains(polCert)) {
                    mKeyStore.setCertificateEntry(CERT_POLICY_ALIAS + homeSP.getFQDN(), remCert);
                    newCerts++;
                }
            }
            if (newCerts > 0) {
                try (FileOutputStream out = new FileOutputStream(KEYSTORE_FILE)) {
                    mKeyStore.store(out, null);
                }
            }
            notifyUser(OSUOperationStatus.ProvisioningSuccess, null, osuInfo.getName(LOCALE));
            Log.d(TAG, "Provisioning complete.");
        }
    } catch (IOException | GeneralSecurityException | SAXException e) {
        Log.e(TAG, "Failed to provision: " + e, e);
        notifyUser(OSUOperationStatus.ProvisioningFailure, e.toString(), osuInfo.getName(LOCALE));
    }
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileOutputStream(java.io.FileOutputStream) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate) SAXException(org.xml.sax.SAXException)

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