Search in sources :

Example 6 with HomeSP

use of com.android.hotspot2.pps.HomeSP in project platform_frameworks_base by android.

the class PpsMoParser method parseHomeSP.

/**
     * Parse configurations under PerProviderSubscription/HomeSP subtree.
     *
     * @param node PPSNode representing the root of the PerProviderSubscription/HomeSP subtree
     * @return HomeSP
     * @throws ParsingException
     */
private static HomeSp parseHomeSP(PPSNode node) throws ParsingException {
    if (node.isLeaf()) {
        throw new ParsingException("Leaf node not expected for HomeSP");
    }
    HomeSp homeSp = new HomeSp();
    for (PPSNode child : node.getChildren()) {
        switch(child.getName()) {
            case NODE_FQDN:
                homeSp.setFqdn(getPpsNodeValue(child));
                break;
            case NODE_FRIENDLY_NAME:
                homeSp.setFriendlyName(getPpsNodeValue(child));
                break;
            case NODE_ROAMING_CONSORTIUM_OI:
                homeSp.setRoamingConsortiumOis(parseRoamingConsortiumOI(getPpsNodeValue(child)));
                break;
            case NODE_ICON_URL:
                homeSp.setIconUrl(getPpsNodeValue(child));
                break;
            case NODE_NETWORK_ID:
                homeSp.setHomeNetworkIds(parseNetworkIds(child));
                break;
            case NODE_HOME_OI_LIST:
                Pair<List<Long>, List<Long>> homeOIs = parseHomeOIList(child);
                homeSp.setMatchAllOis(convertFromLongList(homeOIs.first));
                homeSp.setMatchAnyOis(convertFromLongList(homeOIs.second));
                break;
            case NODE_OTHER_HOME_PARTNERS:
                homeSp.setOtherHomePartners(parseOtherHomePartners(child));
                break;
            default:
                throw new ParsingException("Unknown node under HomeSP: " + child.getName());
        }
    }
    return homeSp;
}
Also used : HomeSp(android.net.wifi.hotspot2.pps.HomeSp) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with HomeSP

use of com.android.hotspot2.pps.HomeSP in project platform_frameworks_base by android.

the class ConfigParserTest method generateConfigurationFromProfile.

/**
     * Generate a {@link PasspointConfiguration} that matches the configuration specified in the
     * XML file {@link #PASSPOINT_INSTALLATION_FILE_WITH_CA_CERT}.
     *
     * @return {@link PasspointConfiguration}
     */
private PasspointConfiguration generateConfigurationFromProfile() {
    PasspointConfiguration config = new PasspointConfiguration();
    // HomeSP configuration.
    HomeSp homeSp = new HomeSp();
    homeSp.setFriendlyName("Century House");
    homeSp.setFqdn("mi6.co.uk");
    homeSp.setRoamingConsortiumOis(new long[] { 0x112233L, 0x445566L });
    config.setHomeSp(homeSp);
    // Credential configuration.
    Credential credential = new Credential();
    credential.setRealm("shaken.stirred.com");
    Credential.UserCredential userCredential = new Credential.UserCredential();
    userCredential.setUsername("james");
    userCredential.setPassword("Ym9uZDAwNw==");
    userCredential.setEapType(21);
    userCredential.setNonEapInnerMethod("MS-CHAP-V2");
    credential.setUserCredential(userCredential);
    Credential.CertificateCredential certCredential = new Credential.CertificateCredential();
    certCredential.setCertType("x509v3");
    byte[] certSha256Fingerprint = new byte[32];
    Arrays.fill(certSha256Fingerprint, (byte) 0x1f);
    certCredential.setCertSha256Fingerprint(certSha256Fingerprint);
    credential.setCertCredential(certCredential);
    Credential.SimCredential simCredential = new Credential.SimCredential();
    simCredential.setImsi("imsi");
    simCredential.setEapType(24);
    credential.setSimCredential(simCredential);
    credential.setCaCertificate(FakeKeys.CA_CERT0);
    config.setCredential(credential);
    return config;
}
Also used : HomeSp(android.net.wifi.hotspot2.pps.HomeSp) Credential(android.net.wifi.hotspot2.pps.Credential)

Example 8 with HomeSP

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

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 9 with HomeSP

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

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)

Example 10 with HomeSP

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

the class ConfigBuilder method buildTTLSConfig.

// Retain for debugging purposes
/*
    private static void xIterateCerts(KeyStore ks, X509Certificate caCert)
            throws GeneralSecurityException {
        Enumeration<String> aliases = ks.aliases();
        while (aliases.hasMoreElements()) {
            String alias = aliases.nextElement();
            Certificate cert = ks.getCertificate(alias);
            Log.d("HS2J", "Checking " + alias);
            if (cert instanceof X509Certificate) {
                X509Certificate x509Certificate = (X509Certificate) cert;
                boolean sm = x509Certificate.getSubjectX500Principal().equals(
                        caCert.getSubjectX500Principal());
                boolean eq = false;
                if (sm) {
                    eq = Arrays.equals(x509Certificate.getEncoded(), caCert.getEncoded());
                }
                Log.d("HS2J", "Subject: " + x509Certificate.getSubjectX500Principal() +
                        ": " + sm + "/" + eq);
            }
        }
    }
    */
private static WifiConfiguration buildTTLSConfig(HomeSP homeSP) throws IOException {
    Credential credential = homeSP.getCredential();
    if (credential.getUserName() == null || credential.getPassword() == null) {
        throw new IOException("EAP-TTLS provisioned without user name or password");
    }
    EAPMethod eapMethod = credential.getEAPMethod();
    AuthParam authParam = eapMethod.getAuthParam();
    if (authParam == null || authParam.getAuthInfoID() != EAP.AuthInfoID.NonEAPInnerAuthType) {
        throw new IOException("Bad auth parameter for EAP-TTLS: " + authParam);
    }
    WifiConfiguration config = buildBaseConfiguration(homeSP);
    NonEAPInnerAuth ttlsParam = (NonEAPInnerAuth) authParam;
    WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
    enterpriseConfig.setPhase2Method(remapInnerMethod(ttlsParam.getType()));
    enterpriseConfig.setIdentity(credential.getUserName());
    enterpriseConfig.setPassword(credential.getPassword());
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) Credential(com.android.hotspot2.pps.Credential) WifiConfiguration(android.net.wifi.WifiConfiguration) IOException(java.io.IOException) AuthParam(com.android.anqp.eap.AuthParam) EAPMethod(com.android.anqp.eap.EAPMethod) NonEAPInnerAuth(com.android.anqp.eap.NonEAPInnerAuth)

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