Search in sources :

Example 66 with HomeSP

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

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

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

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

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

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)

Example 69 with HomeSP

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

the class ConfigBuilder method buildTLSConfig.

private static WifiConfiguration buildTLSConfig(HomeSP homeSP, List<X509Certificate> clientChain, PrivateKey clientKey) throws IOException, GeneralSecurityException {
    Credential credential = homeSP.getCredential();
    X509Certificate clientCertificate = null;
    if (clientKey == null || clientChain == null) {
        throw new IOException("No key and/or cert passed for EAP-TLS");
    }
    if (credential.getCertType() != Credential.CertType.x509v3) {
        throw new IOException("Invalid certificate type for TLS: " + credential.getCertType());
    }
    byte[] reference = credential.getFingerPrint();
    MessageDigest digester = MessageDigest.getInstance("SHA-256");
    for (X509Certificate certificate : clientChain) {
        digester.reset();
        byte[] fingerprint = digester.digest(certificate.getEncoded());
        if (Arrays.equals(reference, fingerprint)) {
            clientCertificate = certificate;
            break;
        }
    }
    if (clientCertificate == null) {
        throw new IOException("No certificate in chain matches supplied fingerprint");
    }
    String alias = Base64.encodeToString(reference, Base64.DEFAULT);
    WifiConfiguration config = buildBaseConfiguration(homeSP);
    WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
    enterpriseConfig.setClientCertificateAlias(alias);
    enterpriseConfig.setClientKeyEntry(clientKey, clientCertificate);
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) Credential(com.android.hotspot2.pps.Credential) WifiConfiguration(android.net.wifi.WifiConfiguration) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) X509Certificate(java.security.cert.X509Certificate)

Example 70 with HomeSP

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

the class SubscriptionTimer method checkUpdates.

public void checkUpdates() {
    mHandler.removeCallbacks(this);
    long now = System.currentTimeMillis();
    long next = Long.MAX_VALUE;
    Collection<HomeSP> homeSPs = mWifiNetworkAdapter.getLoadedSPs();
    if (homeSPs.isEmpty()) {
        return;
    }
    for (HomeSP homeSP : homeSPs) {
        UpdateAction updateAction = mOutstanding.get(homeSP);
        try {
            if (updateAction == null) {
                updateAction = new UpdateAction(homeSP, now);
                mOutstanding.put(homeSP, updateAction);
            } else if (updateAction.remediate(now)) {
                mOSUManager.remediate(homeSP, false);
                mOutstanding.put(homeSP, new UpdateAction(homeSP, now));
            } else if (updateAction.policyUpdate(now)) {
                mOSUManager.remediate(homeSP, true);
                mOutstanding.put(homeSP, new UpdateAction(homeSP, now));
            }
            next = Math.min(next, updateAction.nextExpiry(now));
        } catch (IOException | SAXException e) {
            Log.d(OSUManager.TAG, "Failed subscription update: " + e.getMessage());
        }
    }
    setAlarm(next);
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

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