diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2016-11-17 05:19:02 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-11-17 05:19:02 +0000 |
commit | 4365d22b77f31af7567fc12a90786c63cdc5c484 (patch) | |
tree | 58269ec5c8f27b8cab824fd484965212bca1b367 | |
parent | 25fff067f6e3e8fc822889817bd904b52c49e25c (diff) | |
parent | b378283f8783e0e20e70a3cbbcdcb3e07b434493 (diff) |
Merge "hotspot2: remove OMADM and PPS code"
24 files changed, 24 insertions, 4410 deletions
diff --git a/service/java/com/android/server/wifi/anqp/NAIRealmData.java b/service/java/com/android/server/wifi/anqp/NAIRealmData.java index 36323f73f..68f6e52b3 100644 --- a/service/java/com/android/server/wifi/anqp/NAIRealmData.java +++ b/service/java/com/android/server/wifi/anqp/NAIRealmData.java @@ -2,9 +2,8 @@ package com.android.server.wifi.anqp; import com.android.server.wifi.anqp.eap.EAPMethod; import com.android.server.wifi.hotspot2.AuthMatch; +import com.android.server.wifi.hotspot2.DomainMatcher; import com.android.server.wifi.hotspot2.Utils; -import com.android.server.wifi.hotspot2.pps.Credential; -import com.android.server.wifi.hotspot2.pps.DomainMatcher; import java.net.ProtocolException; import java.nio.ByteBuffer; @@ -58,7 +57,9 @@ public class NAIRealmData { return Collections.unmodifiableList(mEAPMethods); } - public int match(List<String> credLabels, Credential credential) { + // TODO(b/32714185): revisit this when integrating the new Passpoint implementation and add + // unit tests for this. + public int match(List<String> credLabels, EAPMethod credMethod) { int realmMatch = AuthMatch.None; if (!mRealms.isEmpty()) { for (String realm : mRealms) { @@ -79,7 +80,7 @@ public class NAIRealmData { int best = AuthMatch.None; for (EAPMethod eapMethod : mEAPMethods) { - int match = eapMethod.match(credential) | realmMatch; + int match = eapMethod.match(credMethod) | realmMatch; if (match > best) { best = match; if (best == AuthMatch.Exact) { diff --git a/service/java/com/android/server/wifi/anqp/NAIRealmElement.java b/service/java/com/android/server/wifi/anqp/NAIRealmElement.java index c21dbee6a..f145828ab 100644 --- a/service/java/com/android/server/wifi/anqp/NAIRealmElement.java +++ b/service/java/com/android/server/wifi/anqp/NAIRealmElement.java @@ -1,10 +1,9 @@ package com.android.server.wifi.anqp; import com.android.server.wifi.SIMAccessor; +import com.android.server.wifi.anqp.eap.EAPMethod; import com.android.server.wifi.hotspot2.AuthMatch; import com.android.server.wifi.hotspot2.Utils; -import com.android.server.wifi.hotspot2.pps.Credential; -import com.android.server.wifi.hotspot2.pps.HomeSP; import java.net.ProtocolException; import java.nio.ByteBuffer; @@ -46,14 +45,16 @@ public class NAIRealmElement extends ANQPElement { return Collections.unmodifiableList(mRealmData); } - public int match(Credential credential) { + // TODO(b/32714185): revisit this when integrating the new Passpoint implementation and add + // unit tests for this. + public int match(String realm, EAPMethod credMethod) { if (mRealmData.isEmpty()) return AuthMatch.Indeterminate; - List<String> credLabels = Utils.splitDomain(credential.getRealm()); + List<String> credLabels = Utils.splitDomain(realm); int best = AuthMatch.None; for (NAIRealmData realmData : mRealmData) { - int match = realmData.match(credLabels, credential); + int match = realmData.match(credLabels, credMethod); if (match > best) { best = match; if (best == AuthMatch.Exact) { diff --git a/service/java/com/android/server/wifi/anqp/eap/EAPMethod.java b/service/java/com/android/server/wifi/anqp/eap/EAPMethod.java index 97c53a41e..5961830b2 100644 --- a/service/java/com/android/server/wifi/anqp/eap/EAPMethod.java +++ b/service/java/com/android/server/wifi/anqp/eap/EAPMethod.java @@ -110,9 +110,9 @@ public class EAPMethod { return mEAPMethodID; } - public int match(com.android.server.wifi.hotspot2.pps.Credential credential) { - - EAPMethod credMethod = credential.getEAPMethod(); + // TODO(b/32714185): revisit this when integrating the new Passpoint implementation and add + // unit tests for this. + public int match(EAPMethod credMethod) { if (mEAPMethodID != credMethod.getEAPMethodID()) { return AuthMatch.None; } diff --git a/service/java/com/android/server/wifi/hotspot2/pps/DomainMatcher.java b/service/java/com/android/server/wifi/hotspot2/DomainMatcher.java index 3f6e22a8d..3f93101ba 100644 --- a/service/java/com/android/server/wifi/hotspot2/pps/DomainMatcher.java +++ b/service/java/com/android/server/wifi/hotspot2/DomainMatcher.java @@ -1,6 +1,4 @@ -package com.android.server.wifi.hotspot2.pps; - -import android.util.Log; +package com.android.server.wifi.hotspot2; import com.android.server.wifi.hotspot2.Utils; @@ -9,7 +7,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.ListIterator; import java.util.Map; public class DomainMatcher { diff --git a/service/java/com/android/server/wifi/hotspot2/OMADMAdapter.java b/service/java/com/android/server/wifi/hotspot2/OMADMAdapter.java deleted file mode 100644 index 9e1a582c9..000000000 --- a/service/java/com/android/server/wifi/hotspot2/OMADMAdapter.java +++ /dev/null @@ -1,593 +0,0 @@ -package com.android.server.wifi.hotspot2; - -import android.content.Context; -import android.content.SharedPreferences; -import android.net.wifi.WifiManager; -import android.os.SystemProperties; -import android.telephony.TelephonyManager; -import android.text.TextUtils; -import android.util.Log; - -import com.android.server.wifi.anqp.eap.EAP; -import com.android.server.wifi.hotspot2.omadm.MOTree; -import com.android.server.wifi.hotspot2.omadm.OMAConstants; -import com.android.server.wifi.hotspot2.omadm.OMAConstructed; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; - -import static com.android.server.wifi.anqp.eap.NonEAPInnerAuth.NonEAPType; -import static com.android.server.wifi.anqp.eap.NonEAPInnerAuth.mapInnerType; - -public class OMADMAdapter { - private final Context mContext; - private final String mImei; - private final String mImsi; - private final String mDevID; - private final List<PathAccessor> mDevInfo; - private final List<PathAccessor> mDevDetail; - - private static final int IMEI_Length = 14; - - private static final String[] ExtWiFiPath = {"DevDetail", "Ext", "org.wi-fi", "Wi-Fi"}; - - private static final Map<String, String> RTProps = new HashMap<>(); - - private MOTree mDevInfoTree; - private MOTree mDevDetailTree; - - private static OMADMAdapter sInstance; - - static { - RTProps.put(ExtWiFiPath[2], "urn:wfa:mo-ext:hotspot2dot0-devdetail-ext:1.0"); - } - - private static abstract class PathAccessor { - private final String[] mPath; - private final int mHashCode; - - protected PathAccessor(Object ... path) { - int length = 0; - for (Object o : path) { - if (o.getClass() == String[].class) { - length += ((String[]) o).length; - } - else { - length++; - } - } - mPath = new String[length]; - int n = 0; - for (Object o : path) { - if (o.getClass() == String[].class) { - for (String element : (String[]) o) { - mPath[n++] = element; - } - } - else if (o.getClass() == Integer.class) { - mPath[n++] = "x" + o.toString(); - } - else { - mPath[n++] = o.toString(); - } - } - mHashCode = Arrays.hashCode(mPath); - } - - @Override - public int hashCode() { - return mHashCode; - } - - @Override - public boolean equals(Object thatObject) { - return thatObject == this || (thatObject instanceof ConstPathAccessor && - Arrays.equals(mPath, ((PathAccessor) thatObject).mPath)); - } - - private String[] getPath() { - return mPath; - } - - protected abstract Object getValue(); - } - - private static class ConstPathAccessor<T> extends PathAccessor { - private final T mValue; - - protected ConstPathAccessor(T value, Object ... path) { - super(path); - mValue = value; - } - - protected Object getValue() { - return mValue; - } - } - - public static OMADMAdapter getInstance(Context context) { - synchronized (OMADMAdapter.class) { - if (sInstance == null) { - sInstance = new OMADMAdapter(context); - } - return sInstance; - } - } - - private OMADMAdapter(Context context) { - mContext = context; - - TelephonyManager tm = (TelephonyManager) context - .getSystemService(Context.TELEPHONY_SERVICE); - String simOperator = tm.getSimOperator(); - mImsi = tm.getSubscriberId(); - mImei = tm.getImei(); - String strDevId; - - /* Use MEID for sprint */ - if ("310120".equals(simOperator) || (mImsi != null && mImsi.startsWith("310120"))) { - /* MEID is 14 digits. If IMEI is returned as DevId, MEID can be extracted by taking - * first 14 characters. This is not always true but should be the case for sprint */ - strDevId = tm.getDeviceId().toUpperCase(Locale.US); - if (strDevId != null && strDevId.length() >= IMEI_Length) { - strDevId = strDevId.substring(0, IMEI_Length); - } else { - Log.w(Utils.hs2LogTag(getClass()), - "MEID cannot be extracted from DeviceId " + strDevId); - } - } else { - if (isPhoneTypeLTE()) { - strDevId = mImei; - } else { - strDevId = tm.getDeviceId(); - } - if (strDevId == null) { - strDevId = "unknown"; - } - strDevId = strDevId.toUpperCase(Locale.US); - - if (!isPhoneTypeLTE()) { - strDevId = strDevId.substring(0, IMEI_Length); - } - } - mDevID = strDevId; - - mDevInfo = new ArrayList<>(); - mDevInfo.add(new ConstPathAccessor<>(strDevId, "DevInfo", "DevID")); - mDevInfo.add(new ConstPathAccessor<>(getProperty(context, "Man", "ro.product.manufacturer", "unknown"), "DevInfo", "Man")); - mDevInfo.add(new ConstPathAccessor<>(getProperty(context, "Mod", "ro.product.model", "generic"), "DevInfo", "Mod")); - mDevInfo.add(new ConstPathAccessor<>(getLocale(context), "DevInfo", "Lang")); - mDevInfo.add(new ConstPathAccessor<>("1.2", "DevInfo", "DmV")); - - mDevDetail = new ArrayList<>(); - mDevDetail.add(new ConstPathAccessor<>(getDeviceType(), "DevDetail", "DevType")); - mDevDetail.add(new ConstPathAccessor<>(SystemProperties.get("ro.product.brand"), "DevDetail", "OEM")); - mDevDetail.add(new ConstPathAccessor<>(getVersion(context, false), "DevDetail", "FwV")); - mDevDetail.add(new ConstPathAccessor<>(getVersion(context, true), "DevDetail", "SwV")); - mDevDetail.add(new ConstPathAccessor<>(getHwV(), "DevDetail", "HwV")); - mDevDetail.add(new ConstPathAccessor<>("TRUE", "DevDetail", "LrgObj")); - - mDevDetail.add(new ConstPathAccessor<>(32, "DevDetail", "URI", "MaxDepth")); - mDevDetail.add(new ConstPathAccessor<>(2048, "DevDetail", "URI", "MaxTotLen")); - mDevDetail.add(new ConstPathAccessor<>(64, "DevDetail", "URI", "MaxSegLen")); - - AtomicInteger index = new AtomicInteger(1); - mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_TTLS, ExtWiFiPath, "EAPMethodList", index, "EAPType")); - mDevDetail.add(new ConstPathAccessor<>(mapInnerType(NonEAPType.MSCHAPv2), ExtWiFiPath, "EAPMethodList", index, "InnerMethod")); - - index.incrementAndGet(); - mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_TTLS, ExtWiFiPath, "EAPMethodList", index, "EAPType")); - mDevDetail.add(new ConstPathAccessor<>(mapInnerType(NonEAPType.PAP), ExtWiFiPath, "EAPMethodList", index, "InnerMethod")); - - index.incrementAndGet(); - mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_TTLS, ExtWiFiPath, "EAPMethodList", index, "EAPType")); - mDevDetail.add(new ConstPathAccessor<>(mapInnerType(NonEAPType.MSCHAP), ExtWiFiPath, "EAPMethodList", index, "InnerMethod")); - - index.incrementAndGet(); - mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_TLS, ExtWiFiPath, "EAPMethodList", index, "EAPType")); - index.incrementAndGet(); - mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_AKA, ExtWiFiPath, "EAPMethodList", index, "EAPType")); - index.incrementAndGet(); - mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_AKAPrim, ExtWiFiPath, "EAPMethodList", index, "EAPType")); - index.incrementAndGet(); - mDevDetail.add(new ConstPathAccessor<>(EAP.EAP_SIM, ExtWiFiPath, "EAPMethodList", index, "EAPType")); - - mDevDetail.add(new ConstPathAccessor<>("FALSE", ExtWiFiPath, "ManufacturingCertificate")); - mDevDetail.add(new ConstPathAccessor<>(mImsi, ExtWiFiPath, "IMSI")); - mDevDetail.add(new ConstPathAccessor<>(mImei, ExtWiFiPath, "IMEI_MEID")); - mDevDetail.add(new PathAccessor(ExtWiFiPath, "Wi-FiMACAddress") { - @Override - protected String getValue() { - return getMAC(); - } - }); - } - - private static void buildNode(PathAccessor pathAccessor, int depth, OMAConstructed parent) - throws IOException { - String[] path = pathAccessor.getPath(); - String name = path[depth]; - if (depth < path.length - 1) { - OMAConstructed node = (OMAConstructed) parent.getChild(name); - if (node == null) { - node = (OMAConstructed) parent.addChild(name, RTProps.get(name), - null, null); - } - buildNode(pathAccessor, depth + 1, node); - } - else if (pathAccessor.getValue() != null) { - parent.addChild(name, null, pathAccessor.getValue().toString(), null); - } - } - - public String getMAC() { - WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); - return wifiManager != null ? - String.format("%012x", - Utils.parseMac(wifiManager.getConnectionInfo().getMacAddress())) : - null; - } - - public String getImei() { - return mImei; - } - - public byte[] getMeid() { - return Arrays.copyOf(mImei.getBytes(StandardCharsets.ISO_8859_1), IMEI_Length); - } - - public String getDevID() { - return mDevID; - } - - public MOTree getMO(String urn) { - try { - switch (urn) { - case OMAConstants.DevInfoURN: - if (mDevInfoTree == null) { - OMAConstructed root = new OMAConstructed(null, "DevInfo", urn); - for (PathAccessor pathAccessor : mDevInfo) { - buildNode(pathAccessor, 1, root); - } - mDevInfoTree = MOTree.buildMgmtTree(OMAConstants.DevInfoURN, - OMAConstants.OMAVersion, root); - } - return mDevInfoTree; - case OMAConstants.DevDetailURN: - if (mDevDetailTree == null) { - OMAConstructed root = new OMAConstructed(null, "DevDetail", urn); - for (PathAccessor pathAccessor : mDevDetail) { - buildNode(pathAccessor, 1, root); - } - mDevDetailTree = MOTree.buildMgmtTree(OMAConstants.DevDetailURN, - OMAConstants.OMAVersion, root); - } - return mDevDetailTree; - default: - throw new IllegalArgumentException(urn); - } - } - catch (IOException ioe) { - Log.e(Utils.hs2LogTag(getClass()), "Caught exception building OMA Tree: " + ioe, ioe); - return null; - } - - /* - switch (urn) { - case DevInfoURN: return DevInfo; - case DevDetailURN: return DevDetail; - default: throw new IllegalArgumentException(urn); - } - */ - } - - // TODO: For now, assume the device supports LTE. - private static boolean isPhoneTypeLTE() { - return true; - } - - private static String getHwV() { - try { - return SystemProperties.get("ro.hardware", "Unknown") - + "." + SystemProperties.get("ro.revision", "Unknown"); - } catch (RuntimeException e) { - return "Unknown"; - } - } - - private static String getDeviceType() { - String devicetype = SystemProperties.get("ro.build.characteristics"); - if ((((TextUtils.isEmpty(devicetype)) || (!devicetype.equals("tablet"))))) { - devicetype = "phone"; - } - return devicetype; - } - - private static String getVersion(Context context, boolean swv) { - String version; - try { - if (!isSprint(context) && swv) { - return "Android " + SystemProperties.get("ro.build.version.release"); - } else { - version = SystemProperties.get("ro.build.version.full"); - if (null == version || version.equals("")) { - return SystemProperties.get("ro.build.id", null) + "~" - + SystemProperties.get("ro.build.config.version", null) + "~" - + SystemProperties.get("gsm.version.baseband", null) + "~" - + SystemProperties.get("ro.gsm.flexversion", null); - } - } - } catch (RuntimeException e) { - return "Unknown"; - } - return version; - } - - private static boolean isSprint(Context context) { - TelephonyManager tm = (TelephonyManager) context - .getSystemService(Context.TELEPHONY_SERVICE); - String simOperator = tm.getSimOperator(); - String imsi = tm.getSubscriberId(); - /* Use MEID for sprint */ - if ("310120".equals(simOperator) || (imsi != null && imsi.startsWith("310120"))) { - return true; - } else { - return false; - } - } - - private static String getLocale(Context context) { - String strLang = readValueFromFile(context, "Lang"); - if (strLang == null) { - strLang = Locale.getDefault().toString(); - } - return strLang; - } - - private static String getProperty(Context context, String key, String propKey, String dflt) { - String strMan = readValueFromFile(context, key); - if (strMan == null) { - strMan = SystemProperties.get(propKey, dflt); - } - return strMan; - } - - private static String readValueFromFile(Context context, String propName) { - String ret = null; - // use preference instead of the system property - SharedPreferences prefs = context.getSharedPreferences("dmconfig", 0); - if (prefs.contains(propName)) { - ret = prefs.getString(propName, ""); - if (ret.length() == 0) { - ret = null; - } - } - return ret; - } - - private static final String DevDetail = - "<MgmtTree>" + - "<VerDTD>1.2</VerDTD>" + - "<Node>" + - "<NodeName>DevDetail</NodeName>" + - "<RTProperties>" + - "<Type>" + - "<DDFName>urn:oma:mo:oma-dm-devdetail:1.0</DDFName>" + - "</Type>" + - "</RTProperties>" + - "<Node>" + - "<NodeName>Ext</NodeName>" + - "<Node>" + - "<NodeName>org.wi-fi</NodeName>" + - "<RTProperties>" + - "<Type>" + - "<DDFName>" + - "urn:wfa:mo-ext:hotspot2dot0-devdetail-ext :1.0" + - "</DDFName>" + - "</Type>" + - "</RTProperties>" + - "<Node>" + - "<NodeName>Wi-Fi</NodeName>" + - "<Node>" + - "<NodeName>EAPMethodList</NodeName>" + - "<Node>" + - "<NodeName>Method01</NodeName>" + - "<!-- EAP-TTLS/MS-CHAPv2 -->" + - "<Node>" + - "<NodeName>EAPType</NodeName>" + - "<Value>21</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>InnerMethod</NodeName>" + - "<Value>MS-CHAP-V2</Value>" + - "</Node>" + - "</Node>" + - "<Node>" + - "<NodeName>Method02</NodeName>" + - "<!-- EAP-TLS -->" + - "<Node>" + - "<NodeName>EAPType</NodeName>" + - "<Value>13</Value>" + - "</Node>" + - "</Node>" + - "<Node>" + - "<NodeName>Method03</NodeName>" + - "<!-- EAP-SIM -->" + - "<Node>" + - "<NodeName>EAPType</NodeName>" + - "<Value>18</Value>" + - "</Node>" + - "</Node>" + - "<Node>" + - "<NodeName>Method04</NodeName>" + - "<!-- EAP-AKA -->" + - "<Node>" + - "<NodeName>EAPType</NodeName>" + - "<Value>23</Value>" + - "</Node>" + - "</Node>" + - "<Node>" + - "<NodeName>Method05</NodeName>" + - "<!-- EAP-AKA' -->" + - "<Node>" + - "<NodeName>EAPType</NodeName>" + - "<Value>50</Value>" + - "</Node>" + - "</Node>" + - "<Node>" + - "<NodeName>Method06</NodeName>" + - "<!-- Supported method (EAP-TTLS/PAP) not mandated by Hotspot2.0-->" + - "<Node>" + - "<NodeName>EAPType</NodeName>" + - "<Value>21</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>InnerMethod</NodeName>" + - "<Value>PAP</Value>" + - "</Node>" + - "</Node>" + - "<Node>" + - "<NodeName>Method07</NodeName>" + - "<!-- Supported method (PEAP/EAP-GTC) not mandated by Hotspot 2.0-->" + - "<Node>" + - "<NodeName>EAPType</NodeName>" + - "<Value>25</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>InnerEAPType</NodeName>" + - "<Value>6</Value>" + - "</Node>" + - "</Node>" + - "</Node>" + - "<Node>" + - "<NodeName>SPCertificate</NodeName>" + - "<Node>" + - "<NodeName>Cert01</NodeName>" + - "<Node>" + - "<NodeName>CertificateIssuerName</NodeName>" + - "<Value>CN=RuckusCA</Value>" + - "</Node>" + - "</Node>" + - "</Node>" + - "<Node>" + - "<NodeName>ManufacturingCertificate</NodeName>" + - "<Value>FALSE</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>Wi-FiMACAddress</NodeName>" + - "<Value>001d2e112233</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>ClientTriggerRedirectURI</NodeName>" + - "<Value>http://127.0.0.1:12345/index.htm</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>Ops</NodeName>" + - "<Node>" + - "<NodeName>launchBrowserToURI</NodeName>" + - "<Value></Value>" + - "</Node>" + - "<Node>" + - "<NodeName>negotiateClientCertTLS</NodeName>" + - "<Value></Value>" + - "</Node>" + - "<Node>" + - "<NodeName>getCertificate</NodeName>" + - "<Value></Value>" + - "</Node>" + - "</Node>" + - "</Node>" + - "<!-- End of Wi-Fi node -->" + - "</Node>" + - "<!-- End of org.wi-fi node -->" + - "</Node>" + - "<!-- End of Ext node -->" + - "<Node>" + - "<NodeName>URI</NodeName>" + - "<Node>" + - "<NodeName>MaxDepth</NodeName>" + - "<Value>32</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>MaxTotLen</NodeName>" + - "<Value>2048</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>MaxSegLen</NodeName>" + - "<Value>64</Value>" + - "</Node>" + - "</Node>" + - "<Node>" + - "<NodeName>DevType</NodeName>" + - "<Value>Smartphone</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>OEM</NodeName>" + - "<Value>ACME</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>FwV</NodeName>" + - "<Value>1.2.100.5</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>SwV</NodeName>" + - "<Value>9.11.130</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>HwV</NodeName>" + - "<Value>1.0</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>LrgObj</NodeName>" + - "<Value>TRUE</Value>" + - "</Node>" + - "</Node>" + - "</MgmtTree>"; - - - private static final String DevInfo = - "<MgmtTree>" + - "<VerDTD>1.2</VerDTD>" + - "<Node>" + - "<NodeName>DevInfo</NodeName>" + - "<RTProperties>" + - "<Type>" + - "<DDFName>urn:oma:mo:oma-dm-devinfo:1.0" + - "</DDFName>" + - "</Type>" + - "</RTProperties>" + - "</Node>" + - "<Node>" + - "<NodeName>DevID</NodeName>" + - "<Path>DevInfo</Path>" + - "<Value>urn:acme:00-11-22-33-44-55</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>Man</NodeName>" + - "<Path>DevInfo</Path>" + - "<Value>ACME</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>Mod</NodeName>" + - "<Path>DevInfo</Path>" + - "<Value>HS2.0-01</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>DmV</NodeName>" + - "<Path>DevInfo</Path>" + - "<Value>1.2</Value>" + - "</Node>" + - "<Node>" + - "<NodeName>Lang</NodeName>" + - "<Path>DevInfo</Path>" + - "<Value>en-US</Value>" + - "</Node>" + - "</MgmtTree>"; -} diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointMatchInfo.java b/service/java/com/android/server/wifi/hotspot2/PasspointMatchInfo.java index deb60ed82..ec9e68b64 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointMatchInfo.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointMatchInfo.java @@ -2,23 +2,23 @@ package com.android.server.wifi.hotspot2; import com.android.server.wifi.ScanDetail; import com.android.server.wifi.anqp.ANQPElement; +import com.android.server.wifi.anqp.Constants.ANQPElementType; import com.android.server.wifi.anqp.HSConnectionCapabilityElement; import com.android.server.wifi.anqp.HSWanMetricsElement; import com.android.server.wifi.anqp.IPAddressTypeAvailabilityElement; -import com.android.server.wifi.hotspot2.pps.HomeSP; +import com.android.server.wifi.anqp.IPAddressTypeAvailabilityElement.IPv4Availability; +import com.android.server.wifi.anqp.IPAddressTypeAvailabilityElement.IPv6Availability; import java.util.EnumMap; import java.util.HashMap; import java.util.Map; -import static com.android.server.wifi.anqp.Constants.ANQPElementType; -import static com.android.server.wifi.anqp.IPAddressTypeAvailabilityElement.IPv4Availability; -import static com.android.server.wifi.anqp.IPAddressTypeAvailabilityElement.IPv6Availability; - +/** + * TODO(b/32714185): update using the new HomeSP object. + */ public class PasspointMatchInfo implements Comparable<PasspointMatchInfo> { private final PasspointMatch mPasspointMatch; private final ScanDetail mScanDetail; - private final HomeSP mHomeSP; private final int mScore; private static final Map<IPv4Availability, Integer> sIP4Scores = @@ -87,10 +87,9 @@ public class PasspointMatchInfo implements Comparable<PasspointMatchInfo> { public PasspointMatchInfo(PasspointMatch passpointMatch, - ScanDetail scanDetail, HomeSP homeSP) { + ScanDetail scanDetail) { mPasspointMatch = passpointMatch; mScanDetail = scanDetail; - mHomeSP = homeSP; int score; if (passpointMatch == PasspointMatch.HomeProvider) { @@ -165,16 +164,11 @@ public class PasspointMatchInfo implements Comparable<PasspointMatchInfo> { } public ScanDetail getScanDetail() { - return mScanDetail; + return mScanDetail; } public NetworkDetail getNetworkDetail() { - return mScanDetail.getNetworkDetail(); - } - - - public HomeSP getHomeSP() { - return mHomeSP; + return mScanDetail.getNetworkDetail(); } public int getScore() { @@ -223,7 +217,6 @@ public class PasspointMatchInfo implements Comparable<PasspointMatchInfo> { PasspointMatchInfo that = (PasspointMatchInfo)thatObject; return getNetworkDetail().equals(that.getNetworkDetail()) && - getHomeSP().equals(that.getHomeSP()) && getPasspointMatch().equals(that.getPasspointMatch()); } @@ -231,7 +224,6 @@ public class PasspointMatchInfo implements Comparable<PasspointMatchInfo> { public int hashCode() { int result = mPasspointMatch != null ? mPasspointMatch.hashCode() : 0; result = 31 * result + getNetworkDetail().hashCode(); - result = 31 * result + (mHomeSP != null ? mHomeSP.hashCode() : 0); return result; } @@ -240,7 +232,6 @@ public class PasspointMatchInfo implements Comparable<PasspointMatchInfo> { return "PasspointMatchInfo{" + ", mPasspointMatch=" + mPasspointMatch + ", mNetworkInfo=" + getNetworkDetail().getSSID() + - ", mHomeSP=" + mHomeSP.getFQDN() + '}'; } } diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/MOTree.java b/service/java/com/android/server/wifi/hotspot2/omadm/MOTree.java deleted file mode 100644 index 63541eec8..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/MOTree.java +++ /dev/null @@ -1,273 +0,0 @@ -package com.android.server.wifi.hotspot2.omadm; - -import org.xml.sax.SAXException; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.charset.StandardCharsets; -import java.util.*; - -public class MOTree { - public static final String MgmtTreeTag = "MgmtTree"; - - public static final String NodeTag = "Node"; - public static final String NodeNameTag = "NodeName"; - public static final String PathTag = "Path"; - public static final String ValueTag = "Value"; - public static final String RTPropTag = "RTProperties"; - public static final String TypeTag = "Type"; - public static final String DDFNameTag = "DDFName"; - - private final String mUrn; - private final String mDtdRev; - private final OMAConstructed mRoot; - - public MOTree(XMLNode node, String urn) throws IOException, SAXException { - Iterator<XMLNode> children = node.getChildren().iterator(); - - String dtdRev = null; - - while (children.hasNext()) { - XMLNode child = children.next(); - if (child.getTag().equals(OMAConstants.SyncMLVersionTag)) { - dtdRev = child.getText(); - children.remove(); - break; - } - } - - mUrn = urn; - mDtdRev = dtdRev; - - mRoot = new ManagementTreeRoot(node, dtdRev); - - for (XMLNode child : node.getChildren()) { - buildNode(mRoot, child); - } - } - - public MOTree(String urn, String rev, OMAConstructed root) { - mUrn = urn; - mDtdRev = rev; - mRoot = root; - } - - /** - * Build a Passpoint OMA-DM Management Object tree object. - * @param urn The URN for the tree. - * @param rev The DTD revision for the tree. - * @param root The OMA-DM tree root, in all practical cases the PerProviderSubscription - * node. - * @return an MOTree object - */ - public static MOTree buildMgmtTree(String urn, String rev, OMAConstructed root) { - OMAConstructed realRoot; - switch (urn) { - case OMAConstants.PPS_URN: - case OMAConstants.DevInfoURN: - case OMAConstants.DevDetailURN: - case OMAConstants.DevDetailXURN: - realRoot = new ManagementTreeRoot(OMAConstants.OMAVersion); - realRoot.addChild(root); - return new MOTree(urn, rev, realRoot); - default: - return new MOTree(urn, rev, root); - } - } - - public static boolean hasMgmtTreeTag(String text) { - for (int n = 0; n < text.length(); n++) { - char ch = text.charAt(n); - if (ch > ' ') { - return text.regionMatches(true, n, '<' + MgmtTreeTag + '>', - 0, MgmtTreeTag.length() + 2); - } - } - return false; - } - - private static class NodeData { - private final String mName; - private String mPath; - private String mValue; - - private NodeData(String name) { - mName = name; - } - - private void setPath(String path) { - mPath = path; - } - - private void setValue(String value) { - mValue = value; - } - - public String getName() { - return mName; - } - - public String getPath() { - return mPath; - } - - public String getValue() { - return mValue; - } - } - - private static void buildNode(OMANode parent, XMLNode node) throws IOException { - if (!node.getTag().equals(NodeTag)) - throw new IOException("Node is a '" + node.getTag() + "' instead of a 'Node'"); - - Map<String, XMLNode> checkMap = new HashMap<>(3); - String context = null; - List<NodeData> values = new ArrayList<>(); - List<XMLNode> children = new ArrayList<>(); - - NodeData curValue = null; - - for (XMLNode child : node.getChildren()) { - XMLNode old = checkMap.put(child.getTag(), child); - - switch (child.getTag()) { - case NodeNameTag: - if (curValue != null) - throw new IOException(NodeNameTag + " not expected"); - curValue = new NodeData(child.getText()); - - break; - case PathTag: - if (curValue == null || curValue.getPath() != null) - throw new IOException(PathTag + " not expected"); - curValue.setPath(child.getText()); - - break; - case ValueTag: - if (!children.isEmpty()) - throw new IOException(ValueTag + " in constructed node"); - if (curValue == null || curValue.getValue() != null) - throw new IOException(ValueTag + " not expected"); - curValue.setValue(child.getText()); - values.add(curValue); - curValue = null; - - break; - case RTPropTag: - if (old != null) - throw new IOException("Duplicate " + RTPropTag); - XMLNode typeNode = getNextNode(child, TypeTag); - XMLNode ddfName = getNextNode(typeNode, DDFNameTag); - context = ddfName.getText(); - if (context == null) - throw new IOException("No text in " + DDFNameTag); - - break; - case NodeTag: - if (!values.isEmpty()) - throw new IOException("Scalar node " + node.getText() + " has Node child"); - children.add(child); - - break; - } - } - - if (values.isEmpty()) { - if (curValue == null) - throw new IOException("Missing name"); - - OMANode subNode = parent.addChild(curValue.getName(), - context, null, curValue.getPath()); - - for (XMLNode child : children) { - buildNode(subNode, child); - } - } else { - if (!children.isEmpty()) - throw new IOException("Got both sub nodes and value(s)"); - - for (NodeData nodeData : values) { - parent.addChild(nodeData.getName(), context, - nodeData.getValue(), nodeData.getPath()); - } - } - } - - private static XMLNode getNextNode(XMLNode node, String tag) throws IOException { - if (node == null) - throw new IOException("No node for " + tag); - if (node.getChildren().size() != 1) - throw new IOException("Expected " + node.getTag() + " to have exactly one child"); - XMLNode child = node.getChildren().iterator().next(); - if (!child.getTag().equals(tag)) - throw new IOException("Expected " + node.getTag() + " to have child '" + tag + - "' instead of '" + child.getTag() + "'"); - return child; - } - - public String getUrn() { - return mUrn; - } - - public String getDtdRev() { - return mDtdRev; - } - - public OMAConstructed getRoot() { - return mRoot; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("MO Tree v").append(mDtdRev).append(", urn ").append(mUrn).append(")\n"); - sb.append(mRoot); - - return sb.toString(); - } - - public void marshal(OutputStream out) throws IOException { - out.write("tree ".getBytes(StandardCharsets.UTF_8)); - OMAConstants.serializeString(mDtdRev, out); - out.write(String.format("(%s)\n", mUrn).getBytes(StandardCharsets.UTF_8)); - mRoot.marshal(out, 0); - } - - public static MOTree unmarshal(InputStream in) throws IOException { - boolean strip = true; - StringBuilder tree = new StringBuilder(); - for (; ; ) { - int octet = in.read(); - if (octet < 0) { - throw new FileNotFoundException(); - } else if (octet > ' ') { - tree.append((char) octet); - strip = false; - } else if (!strip) { - break; - } - } - if (!tree.toString().equals("tree")) { - throw new IOException("Not a tree: " + tree); - } - - String version = OMAConstants.deserializeString(in); - int next = in.read(); - if (next != '(') { - throw new IOException("Expected URN in tree definition"); - } - String urn = OMAConstants.readURN(in); - - OMAConstructed root = OMANode.unmarshal(in); - - return new MOTree(urn, version, root); - } - - public String toXml() { - StringBuilder sb = new StringBuilder(); - mRoot.toXml(sb); - return sb.toString(); - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/ManagementTreeRoot.java b/service/java/com/android/server/wifi/hotspot2/omadm/ManagementTreeRoot.java deleted file mode 100644 index 83a8dc834..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/ManagementTreeRoot.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.wifi.hotspot2.omadm; - -import java.util.Map; - -/** - * A specialized OMAConstructed OMA-DM node used as the MgmtTree root node in Passpoint - * management trees. - */ -public class ManagementTreeRoot extends OMAConstructed { - private final String mDtdRev; - - public ManagementTreeRoot(XMLNode node, String dtdRev) { - super(null, MOTree.MgmtTreeTag, null, new MultiValueMap<OMANode>(), - node.getTextualAttributes()); - mDtdRev = dtdRev; - } - - public ManagementTreeRoot(String dtdRev) { - super(null, MOTree.MgmtTreeTag, null, "xmlns", OMAConstants.SyncML); - mDtdRev = dtdRev; - } - - @Override - public void toXml(StringBuilder sb) { - sb.append('<').append(MOTree.MgmtTreeTag); - if (getAttributes() != null && !getAttributes().isEmpty()) { - for (Map.Entry<String, String> avp : getAttributes().entrySet()) { - sb.append(' ').append(avp.getKey()).append("=\"") - .append(escape(avp.getValue())).append('"'); - } - } - sb.append(">\n"); - - sb.append('<').append(OMAConstants.SyncMLVersionTag) - .append('>').append(mDtdRev) - .append("</").append(OMAConstants.SyncMLVersionTag).append(">\n"); - for (OMANode child : getChildren()) { - child.toXml(sb); - } - sb.append("</").append(MOTree.MgmtTreeTag).append(">\n"); - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/MultiValueMap.java b/service/java/com/android/server/wifi/hotspot2/omadm/MultiValueMap.java deleted file mode 100644 index 21e283126..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/MultiValueMap.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.android.server.wifi.hotspot2.omadm; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -public class MultiValueMap<T> { - private final Map<String, ArrayList<T>> mMap = new LinkedHashMap<>(); - - public void put(String key, T value) { - key = key.toLowerCase(); - ArrayList<T> values = mMap.get(key); - if (values == null) { - values = new ArrayList<>(); - mMap.put(key, values); - } - values.add(value); - } - - public T get(String key) { - key = key.toLowerCase(); - List<T> values = mMap.get(key); - if (values == null) { - return null; - } - else if (values.size() == 1) { - return values.get(0); - } - else { - throw new IllegalArgumentException("Cannot do get on multi-value"); - } - } - - public T replace(String key, T oldValue, T newValue) { - key = key.toLowerCase(); - List<T> values = mMap.get(key); - if (values == null) { - return null; - } - - for (int n = 0; n < values.size(); n++) { - T value = values.get(n); - if (value == oldValue) { - values.set(n, newValue); - return value; - } - } - return null; - } - - public T remove(String key, T value) { - key = key.toLowerCase(); - List<T> values = mMap.get(key); - if (values == null) { - return null; - } - - T result = null; - Iterator<T> valueIterator = values.iterator(); - while (valueIterator.hasNext()) { - if (valueIterator.next() == value) { - valueIterator.remove(); - result = value; - break; - } - } - if (values.isEmpty()) { - mMap.remove(key); - } - return result; - } - - public T remove(T value) { - T result = null; - Iterator<Map.Entry<String, ArrayList<T>>> iterator = mMap.entrySet().iterator(); - while (iterator.hasNext()) { - ArrayList<T> values = iterator.next().getValue(); - Iterator<T> valueIterator = values.iterator(); - while (valueIterator.hasNext()) { - if (valueIterator.next() == value) { - valueIterator.remove(); - result = value; - break; - } - } - if (result != null) { - if (values.isEmpty()) { - iterator.remove(); - } - break; - } - } - return result; - } - - public Collection<T> values() { - List<T> allValues = new ArrayList<>(mMap.size()); - for (List<T> values : mMap.values()) { - for (T value : values) { - allValues.add(value); - } - } - return allValues; - } - - public T getSingletonValue() { - if (mMap.size() != 1) { - throw new IllegalArgumentException("Map is not a single entry map"); - } - List<T> values = mMap.values().iterator().next(); - if (values.size() != 1) { - throw new IllegalArgumentException("Map is not a single entry map"); - } - return values.iterator().next(); - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/NodeAttribute.java b/service/java/com/android/server/wifi/hotspot2/omadm/NodeAttribute.java deleted file mode 100644 index 87ded86da..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/NodeAttribute.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.android.server.wifi.hotspot2.omadm; - -public class NodeAttribute { - private final String mName; - private final String mType; - private final String mValue; - - public NodeAttribute(String name, String type, String value) { - mName = name; - mType = type; - mValue = value; - } - - public String getName() { - return mName; - } - - public String getValue() { - return mValue; - } - - public String getType() { - return mType; - } - - @Override - public boolean equals(Object thatObject) { - if (this == thatObject) { - return true; - } - if (thatObject == null || getClass() != thatObject.getClass()) { - return false; - } - - NodeAttribute that = (NodeAttribute) thatObject; - return mName.equals(that.mName) && mType.equals(that.mType) && mValue.equals(that.mValue); - } - - @Override - public String toString() { - return String.format("%s (%s) = '%s'", mName, mType, mValue); - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/OMAConstants.java b/service/java/com/android/server/wifi/hotspot2/omadm/OMAConstants.java deleted file mode 100644 index 6d00edd97..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/OMAConstants.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.android.server.wifi.hotspot2.omadm; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.charset.StandardCharsets; - -public class OMAConstants { - private OMAConstants() { - } - - public static final String MOVersion = "1.0"; - public static final String PPS_URN = "urn:wfa:mo:hotspot2dot0-perprovidersubscription:1.0"; - public static final String DevInfoURN = "urn:oma:mo:oma-dm-devinfo:1.0"; - public static final String DevDetailURN = "urn:oma:mo:oma-dm-devdetail:1.0"; - public static final String DevDetailXURN = "urn:wfa:mo-ext:hotspot2dot0-devdetail-ext:1.0"; - - public static final String[] SupportedMO_URNs = { - PPS_URN, DevInfoURN, DevDetailURN, DevDetailXURN - }; - - public static final String SppMOAttribute = "spp:moURN"; - public static final String TAG_PostDevData = "spp:sppPostDevData"; - public static final String TAG_SupportedVersions = "spp:supportedSPPVersions"; - public static final String TAG_SupportedMOs = "spp:supportedMOList"; - public static final String TAG_UpdateResponse = "spp:sppUpdateResponse"; - public static final String TAG_MOContainer = "spp:moContainer"; - public static final String TAG_Version = "spp:sppVersion"; - - public static final String TAG_SessionID = "spp:sessionID"; - public static final String TAG_Status = "spp:sppStatus"; - public static final String TAG_Error = "spp:sppError"; - - public static final String SyncMLVersionTag = "VerDTD"; - public static final String OMAVersion = "1.2"; - public static final String SyncML = "syncml:dmddf1.2"; - - private static final byte[] INDENT = new byte[1024]; - - public static void serializeString(String s, OutputStream out) throws IOException { - byte[] octets = s.getBytes(StandardCharsets.UTF_8); - byte[] prefix = String.format("%x:", octets.length).getBytes(StandardCharsets.UTF_8); - out.write(prefix); - out.write(octets); - } - - public static void indent(int level, OutputStream out) throws IOException { - out.write(INDENT, 0, level); - } - - public static String deserializeString(InputStream in) throws IOException { - StringBuilder prefix = new StringBuilder(); - for (; ; ) { - byte b = (byte) in.read(); - if (b == '.') - return null; - else if (b == ':') - break; - else if (b > ' ') - prefix.append((char) b); - } - int length = Integer.parseInt(prefix.toString(), 16); - byte[] octets = new byte[length]; - int offset = 0; - while (offset < octets.length) { - int amount = in.read(octets, offset, octets.length - offset); - if (amount <= 0) - throw new EOFException(); - offset += amount; - } - return new String(octets, StandardCharsets.UTF_8); - } - - public static String readURN(InputStream in) throws IOException { - StringBuilder urn = new StringBuilder(); - - for (; ; ) { - byte b = (byte) in.read(); - if (b == ')') - break; - urn.append((char) b); - } - return urn.toString(); - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/OMAConstructed.java b/service/java/com/android/server/wifi/hotspot2/omadm/OMAConstructed.java deleted file mode 100644 index c0e4c66dd..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/OMAConstructed.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.android.server.wifi.hotspot2.omadm; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.Map; - -public class OMAConstructed extends OMANode { - private final MultiValueMap<OMANode> mChildren; - - public OMAConstructed(OMAConstructed parent, String name, String context, String ... avps) { - this(parent, name, context, new MultiValueMap<OMANode>(), buildAttributes(avps)); - } - - protected OMAConstructed(OMAConstructed parent, String name, String context, - MultiValueMap<OMANode> children, Map<String, String> avps) { - super(parent, name, context, avps); - mChildren = children; - } - - @Override - public OMANode addChild(String name, String context, String value, String pathString) - throws IOException { - if (pathString == null) { - OMANode child = value != null ? - new OMAScalar(this, name, context, value) : - new OMAConstructed(this, name, context); - mChildren.put(name, child); - return child; - } else { - OMANode target = this; - while (target.getParent() != null) - target = target.getParent(); - - for (String element : pathString.split("/")) { - target = target.getChild(element); - if (target == null) - throw new IOException("No child node '" + element + "' in " + getPathString()); - else if (target.isLeaf()) - throw new IOException("Cannot add child to leaf node: " + getPathString()); - } - return target.addChild(name, context, value, null); - } - } - - @Override - public OMAConstructed reparent(OMAConstructed parent) { - return new OMAConstructed(parent, getName(), getContext(), mChildren, getAttributes()); - } - - public void addChild(OMANode child) { - mChildren.put(child.getName(), child.reparent(this)); - } - - public String getScalarValue(Iterator<String> path) throws OMAException { - if (!path.hasNext()) { - throw new OMAException("Path too short for " + getPathString()); - } - String tag = path.next(); - OMANode child = mChildren.get(tag); - if (child != null) { - return child.getScalarValue(path); - } else { - return null; - } - } - - @Override - public OMANode getListValue(Iterator<String> path) throws OMAException { - if (!path.hasNext()) { - return null; - } - String tag = path.next(); - OMANode child; - if (tag.equals("?")) { - child = mChildren.getSingletonValue(); - } - else { - child = mChildren.get(tag); - } - - if (child == null) { - return null; - } - else if (path.hasNext()) { - return child.getListValue(path); - } else { - return child; - } - } - - @Override - public boolean isLeaf() { - return false; - } - - @Override - public Collection<OMANode> getChildren() { - return Collections.unmodifiableCollection(mChildren.values()); - } - - public OMANode getChild(String name) { - return mChildren.get(name); - } - - public OMANode replaceNode(OMANode oldNode, OMANode newNode) { - return mChildren.replace(oldNode.getName(), oldNode, newNode); - } - - public OMANode removeNode(String key, OMANode node) { - if (key.equals("?")) { - return mChildren.remove(node); - } - else { - return mChildren.remove(key, node); - } - } - - @Override - public String getValue() { - throw new UnsupportedOperationException(); - } - - @Override - public void toString(StringBuilder sb, int level) { - sb.append(getPathString()); - if (getContext() != null) { - sb.append(" (").append(getContext()).append(')'); - } - sb.append('\n'); - - for (OMANode node : mChildren.values()) { - node.toString(sb, level + 1); - } - } - - @Override - public void marshal(OutputStream out, int level) throws IOException { - OMAConstants.indent(level, out); - OMAConstants.serializeString(getName(), out); - if (getContext() != null) { - out.write(String.format("(%s)", getContext()).getBytes(StandardCharsets.UTF_8)); - } - out.write(new byte[] { '+', '\n' }); - - for (OMANode child : mChildren.values()) { - child.marshal(out, level + 1); - } - OMAConstants.indent(level, out); - out.write(".\n".getBytes(StandardCharsets.UTF_8)); - } - - @Override - public void fillPayload(StringBuilder sb) { - if (getContext() != null) { - sb.append('<').append(MOTree.RTPropTag).append(">\n"); - sb.append('<').append(MOTree.TypeTag).append(">\n"); - sb.append('<').append(MOTree.DDFNameTag).append(">"); - sb.append(getContext()); - sb.append("</").append(MOTree.DDFNameTag).append(">\n"); - sb.append("</").append(MOTree.TypeTag).append(">\n"); - sb.append("</").append(MOTree.RTPropTag).append(">\n"); - } - - for (OMANode child : getChildren()) { - child.toXml(sb); - } - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/OMAException.java b/service/java/com/android/server/wifi/hotspot2/omadm/OMAException.java deleted file mode 100644 index 5f8cd112c..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/OMAException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.android.server.wifi.hotspot2.omadm; - -import java.io.IOException; - -public class OMAException extends IOException { - public OMAException(String message) { - super(message); - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/OMANode.java b/service/java/com/android/server/wifi/hotspot2/omadm/OMANode.java deleted file mode 100644 index fbb607561..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/OMANode.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.android.server.wifi.hotspot2.omadm; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -public abstract class OMANode { - private final OMAConstructed mParent; - private final String mName; - private final String mContext; - private final Map<String, String> mAttributes; - - private static final Map<Character, String> sEscapes = new HashMap<>(); - - static { - sEscapes.put('"', """); - sEscapes.put('\'', "'"); - sEscapes.put('<', "<"); - sEscapes.put('>', ">"); - sEscapes.put('&', "&"); - } - - protected OMANode(OMAConstructed parent, String name, String context, Map<String, String> avps) { - mParent = parent; - mName = name; - mContext = context; - mAttributes = avps; - } - - protected static Map<String, String> buildAttributes(String[] avps) { - if (avps == null) { - return null; - } - Map<String, String> attributes = new HashMap<>(); - for (int n = 0; n < avps.length; n += 2) { - attributes.put(avps[n], avps[n+1]); - } - return attributes; - } - - protected Map<String, String> getAttributes() { - return mAttributes; - } - - public OMAConstructed getParent() { - return mParent; - } - - public String getName() { - return mName; - } - - public String getContext() { - return mContext; - } - - public List<String> getPath() { - LinkedList<String> path = new LinkedList<>(); - for (OMANode node = this; node != null; node = node.getParent()) { - path.addFirst(node.getName()); - } - return path; - } - - public String getPathString() { - StringBuilder sb = new StringBuilder(); - for (String element : getPath()) { - sb.append('/').append(element); - } - return sb.toString(); - } - - /** - * Perform escaping of special XML characters - * @param s the raw string - * @return a "XML clean" representation - */ - public static String escape(String s) { - StringBuilder sb = new StringBuilder(s.length()); - for (int n = 0; n < s.length(); n++) { - char ch = s.charAt(n); - String escape = sEscapes.get(ch); - if (escape != null) { - sb.append(escape); - } else { - sb.append(ch); - } - } - return sb.toString(); - } - - public abstract OMANode reparent(OMAConstructed parent); - - public abstract String getScalarValue(Iterator<String> path) throws OMAException; - - public abstract OMANode getListValue(Iterator<String> path) throws OMAException; - - public abstract boolean isLeaf(); - - public abstract Collection<OMANode> getChildren(); - - public abstract OMANode getChild(String name) throws OMAException; - - public abstract String getValue(); - - public abstract OMANode addChild(String name, String context, String value, String path) - throws IOException; - - public abstract void marshal(OutputStream out, int level) throws IOException; - - public abstract void toString(StringBuilder sb, int level); - - public abstract void fillPayload(StringBuilder sb); - - public void toXml(StringBuilder sb) { - sb.append('<').append(MOTree.NodeTag); - if (mAttributes != null && !mAttributes.isEmpty()) { - for (Map.Entry<String, String> avp : mAttributes.entrySet()) { - sb.append(' ').append(avp.getKey()).append("=\"") - .append(escape(avp.getValue())).append('"'); - } - } - sb.append(">\n"); - - sb.append('<').append(MOTree.NodeNameTag).append('>'); - sb.append(getName()); - sb.append("</").append(MOTree.NodeNameTag).append(">\n"); - - fillPayload(sb); - - sb.append("</").append(MOTree.NodeTag).append(">\n"); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - toString(sb, 0); - return sb.toString(); - } - - public static OMAConstructed unmarshal(InputStream in) throws IOException { - OMANode node = buildNode(in, null); - if (node == null || node.isLeaf()) { - throw new IOException("Bad OMA tree"); - } - unmarshal(in, (OMAConstructed) node); - return (OMAConstructed) node; - } - - private static void unmarshal(InputStream in, OMAConstructed parent) throws IOException { - for (; ; ) { - OMANode node = buildNode(in, parent); - if (node == null) { - return; - } - else if (!node.isLeaf()) { - unmarshal(in, (OMAConstructed) node); - } - } - } - - private static OMANode buildNode(InputStream in, OMAConstructed parent) throws IOException { - String name = OMAConstants.deserializeString(in); - if (name == null) { - return null; - } - - String urn = null; - int next = in.read(); - if (next == '(') { - urn = OMAConstants.readURN(in); - next = in.read(); - } - - if (next == '=') { - String value = OMAConstants.deserializeString(in); - return parent.addChild(name, urn, value, null); - } else if (next == '+') { - if (parent != null) { - return parent.addChild(name, urn, null, null); - } else { - return new OMAConstructed(null, name, urn); - } - } - else { - throw new IOException("Parse error: expected = or + after node name"); - } - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java b/service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java deleted file mode 100644 index cbcd81d16..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.android.server.wifi.hotspot2.omadm; - -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -import java.io.IOException; -import java.io.StringReader; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -/** - * Parses an OMA-DM XML tree. - * OMA-DM = Open Mobile Association Device Management - */ -public class OMAParser extends DefaultHandler { - private XMLNode mRoot; - private XMLNode mCurrent; - - public OMAParser() { - mRoot = null; - mCurrent = null; - } - - public MOTree parse(String text, String urn) throws IOException, SAXException { - try { - SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); - parser.parse(new InputSource(new StringReader(text)), this); - return new MOTree(mRoot, urn); - } catch (ParserConfigurationException pce) { - throw new SAXException(pce); - } - } - - public XMLNode getRoot() { - return mRoot; - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) - throws SAXException { - XMLNode parent = mCurrent; - - mCurrent = new XMLNode(mCurrent, qName, attributes); - - if (mRoot == null) - mRoot = mCurrent; - else - parent.addChild(mCurrent); - } - - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - if (!qName.equals(mCurrent.getTag())) - throw new SAXException("End tag '" + qName + "' doesn't match current node: " + - mCurrent); - - try { - mCurrent.close(); - } catch (IOException ioe) { - throw new SAXException("Failed to close element", ioe); - } - - mCurrent = mCurrent.getParent(); - } - - @Override - public void characters(char[] ch, int start, int length) throws SAXException { - mCurrent.addText(ch, start, length); - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/OMAScalar.java b/service/java/com/android/server/wifi/hotspot2/omadm/OMAScalar.java deleted file mode 100644 index 86740ac1c..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/OMAScalar.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.android.server.wifi.hotspot2.omadm; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -public class OMAScalar extends OMANode { - private final String mValue; - - public OMAScalar(OMAConstructed parent, String name, String context, String value, - String ... avps) { - this(parent, name, context, value, buildAttributes(avps)); - } - - public OMAScalar(OMAConstructed parent, String name, String context, String value, - Map<String, String> avps) { - super(parent, name, context, avps); - mValue = value; - } - - @Override - public OMAScalar reparent(OMAConstructed parent) { - return new OMAScalar(parent, getName(), getContext(), mValue, getAttributes()); - } - - public String getScalarValue(Iterator<String> path) throws OMAException { - return mValue; - } - - @Override - public OMANode getListValue(Iterator<String> path) throws OMAException { - throw new OMAException("Scalar encountered in list path: " + getPathString()); - } - - @Override - public boolean isLeaf() { - return true; - } - - @Override - public Collection<OMANode> getChildren() { - throw new UnsupportedOperationException(); - } - - @Override - public String getValue() { - return mValue; - } - - @Override - public OMANode getChild(String name) throws OMAException { - throw new OMAException("'" + getName() + "' is a scalar node"); - } - - @Override - public OMANode addChild(String name, String context, String value, String path) - throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void toString(StringBuilder sb, int level) { - sb.append(getPathString()).append('=').append(mValue); - if (getContext() != null) { - sb.append(" (").append(getContext()).append(')'); - } - sb.append('\n'); - } - - @Override - public void marshal(OutputStream out, int level) throws IOException { - OMAConstants.indent(level, out); - OMAConstants.serializeString(getName(), out); - out.write((byte) '='); - OMAConstants.serializeString(getValue(), out); - out.write((byte) '\n'); - } - - @Override - public void fillPayload(StringBuilder sb) { - sb.append('<').append(MOTree.ValueTag).append('>'); - sb.append(escape(mValue)); - sb.append("</").append(MOTree.ValueTag).append(">\n"); - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/PasspointManagementObjectManager.java b/service/java/com/android/server/wifi/hotspot2/omadm/PasspointManagementObjectManager.java deleted file mode 100644 index a28ca8471..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/PasspointManagementObjectManager.java +++ /dev/null @@ -1,956 +0,0 @@ -package com.android.server.wifi.hotspot2.omadm; - -import android.net.wifi.PasspointManagementObjectDefinition; -import android.text.TextUtils; -import android.util.Base64; -import android.util.Log; - -import com.android.server.wifi.IMSIParameter; -import com.android.server.wifi.anqp.eap.EAP; -import com.android.server.wifi.anqp.eap.EAPMethod; -import com.android.server.wifi.anqp.eap.ExpandedEAPMethod; -import com.android.server.wifi.anqp.eap.InnerAuthEAP; -import com.android.server.wifi.anqp.eap.NonEAPInnerAuth; -import com.android.server.wifi.hotspot2.Utils; -import com.android.server.wifi.hotspot2.pps.Credential; -import com.android.server.wifi.hotspot2.pps.HomeSP; -import com.android.server.wifi.hotspot2.pps.Policy; -import com.android.server.wifi.hotspot2.pps.SubscriptionParameters; -import com.android.server.wifi.hotspot2.pps.UpdateInfo; - -import org.xml.sax.SAXException; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TimeZone; - -/** - * Handles provisioning of PerProviderSubscription data. - */ -public class PasspointManagementObjectManager { - - public static final String TAG_AAAServerTrustRoot = "AAAServerTrustRoot"; - public static final String TAG_AbleToShare = "AbleToShare"; - public static final String TAG_CertificateType = "CertificateType"; - public static final String TAG_CertSHA256Fingerprint = "CertSHA256Fingerprint"; - public static final String TAG_CertURL = "CertURL"; - public static final String TAG_CheckAAAServerCertStatus = "CheckAAAServerCertStatus"; - public static final String TAG_Country = "Country"; - public static final String TAG_CreationDate = "CreationDate"; - public static final String TAG_Credential = "Credential"; - public static final String TAG_CredentialPriority = "CredentialPriority"; - public static final String TAG_DataLimit = "DataLimit"; - public static final String TAG_DigitalCertificate = "DigitalCertificate"; - public static final String TAG_DLBandwidth = "DLBandwidth"; - public static final String TAG_EAPMethod = "EAPMethod"; - public static final String TAG_EAPType = "EAPType"; - public static final String TAG_ExpirationDate = "ExpirationDate"; - public static final String TAG_Extension = "Extension"; - public static final String TAG_FQDN = "FQDN"; - public static final String TAG_FQDN_Match = "FQDN_Match"; - public static final String TAG_FriendlyName = "FriendlyName"; - public static final String TAG_HESSID = "HESSID"; - public static final String TAG_HomeOI = "HomeOI"; - public static final String TAG_HomeOIList = "HomeOIList"; - public static final String TAG_HomeOIRequired = "HomeOIRequired"; - public static final String TAG_HomeSP = "HomeSP"; - public static final String TAG_IconURL = "IconURL"; - public static final String TAG_IMSI = "IMSI"; - public static final String TAG_InnerEAPType = "InnerEAPType"; - public static final String TAG_InnerMethod = "InnerMethod"; - public static final String TAG_InnerVendorID = "InnerVendorID"; - public static final String TAG_InnerVendorType = "InnerVendorType"; - public static final String TAG_IPProtocol = "IPProtocol"; - public static final String TAG_MachineManaged = "MachineManaged"; - public static final String TAG_MaximumBSSLoadValue = "MaximumBSSLoadValue"; - public static final String TAG_MinBackhaulThreshold = "MinBackhaulThreshold"; - public static final String TAG_NetworkID = "NetworkID"; - public static final String TAG_NetworkType = "NetworkType"; - public static final String TAG_Other = "Other"; - public static final String TAG_OtherHomePartners = "OtherHomePartners"; - public static final String TAG_Password = "Password"; - public static final String TAG_PerProviderSubscription = "PerProviderSubscription"; - public static final String TAG_Policy = "Policy"; - public static final String TAG_PolicyUpdate = "PolicyUpdate"; - public static final String TAG_PortNumber = "PortNumber"; - public static final String TAG_PreferredRoamingPartnerList = "PreferredRoamingPartnerList"; - public static final String TAG_Priority = "Priority"; - public static final String TAG_Realm = "Realm"; - public static final String TAG_RequiredProtoPortTuple = "RequiredProtoPortTuple"; - public static final String TAG_Restriction = "Restriction"; - public static final String TAG_RoamingConsortiumOI = "RoamingConsortiumOI"; - public static final String TAG_SIM = "SIM"; - public static final String TAG_SoftTokenApp = "SoftTokenApp"; - public static final String TAG_SPExclusionList = "SPExclusionList"; - public static final String TAG_SSID = "SSID"; - public static final String TAG_StartDate = "StartDate"; - public static final String TAG_SubscriptionParameters = "SubscriptionParameters"; - public static final String TAG_SubscriptionUpdate = "SubscriptionUpdate"; - public static final String TAG_TimeLimit = "TimeLimit"; - public static final String TAG_TrustRoot = "TrustRoot"; - public static final String TAG_TypeOfSubscription = "TypeOfSubscription"; - public static final String TAG_ULBandwidth = "ULBandwidth"; - public static final String TAG_UpdateIdentifier = "UpdateIdentifier"; - public static final String TAG_UpdateInterval = "UpdateInterval"; - public static final String TAG_UpdateMethod = "UpdateMethod"; - public static final String TAG_URI = "URI"; - public static final String TAG_UsageLimits = "UsageLimits"; - public static final String TAG_UsageTimePeriod = "UsageTimePeriod"; - public static final String TAG_Username = "Username"; - public static final String TAG_UsernamePassword = "UsernamePassword"; - public static final String TAG_VendorId = "VendorId"; - public static final String TAG_VendorType = "VendorType"; - - public static final long IntervalFactor = 60000L; // All MO intervals are in minutes - - private static final DateFormat DTFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - - private static final Map<String, Map<String, Object>> sSelectionMap; - - static { - DTFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - - sSelectionMap = new HashMap<>(); - - setSelections(TAG_FQDN_Match, - "exactmatch", Boolean.FALSE, - "includesubdomains", Boolean.TRUE); - setSelections(TAG_UpdateMethod, - "oma-dm-clientinitiated", Boolean.FALSE, - "spp-clientinitiated", Boolean.TRUE); - setSelections(TAG_Restriction, - "homesp", UpdateInfo.UpdateRestriction.HomeSP, - "roamingpartner", UpdateInfo.UpdateRestriction.RoamingPartner, - "unrestricted", UpdateInfo.UpdateRestriction.Unrestricted); - } - - private static void setSelections(String key, Object... pairs) { - Map<String, Object> kvp = new HashMap<>(); - sSelectionMap.put(key, kvp); - for (int n = 0; n < pairs.length; n += 2) { - kvp.put(pairs[n].toString(), pairs[n + 1]); - } - } - - private final File mPpsFile; - private final boolean mEnabled; - private final Map<String, HomeSP> mSPs; - - public PasspointManagementObjectManager(File ppsFile, boolean hs2enabled) { - mPpsFile = ppsFile; - mEnabled = hs2enabled; - mSPs = new HashMap<>(); - } - - public boolean isEnabled() { - return mEnabled; - } - - public boolean isConfigured() { - return mEnabled && !mSPs.isEmpty(); - } - - public Map<String, HomeSP> getLoadedSPs() { - return Collections.unmodifiableMap(mSPs); - } - - public List<HomeSP> loadAllSPs() throws IOException { - - if (!mEnabled || !mPpsFile.exists()) { - return Collections.emptyList(); - } - - try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) { - mSPs.clear(); - MOTree moTree; - try { - moTree = MOTree.unmarshal(in); - } catch (FileNotFoundException fnfe) { - return Collections.emptyList(); // Empty file - } - - 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(Utils.hs2LogTag(getClass()), - "retrieved " + sp.getFQDN() + " from PPS"); - } - } - return sps; - - } else { - throw new OMAException("Failed to build HomeSP"); - } - } - } - - public static HomeSP buildSP(String xml) throws IOException, SAXException { - OMAParser omaParser = new OMAParser(); - MOTree tree = omaParser.parse(xml, OMAConstants.PPS_URN); - List<HomeSP> spList = buildSPs(tree); - if (spList.size() != 1) { - throw new OMAException("Expected exactly one HomeSP, got " + spList.size()); - } - return spList.iterator().next(); - } - - public HomeSP addSP(String xml) throws IOException, SAXException { - OMAParser omaParser = new OMAParser(); - return addSP(omaParser.parse(xml, OMAConstants.PPS_URN)); - } - - private static final List<String> FQDNPath = Arrays.asList(TAG_HomeSP, TAG_FQDN); - - /** - * R1 *only* addSP method. - * - * @param homeSP - * @throws IOException - */ - public void addSP(HomeSP homeSP) throws IOException { - if (!mEnabled) { - throw new IOException("HS2.0 not enabled on this device"); - } - if (mSPs.containsKey(homeSP.getFQDN())) { - Log.d(Utils.hs2LogTag(getClass()), "HS20 profile for " - + homeSP.getFQDN() + " already exists"); - return; - } - Log.d(Utils.hs2LogTag(getClass()), "Adding new HS20 profile for " + homeSP.getFQDN()); - - OMAConstructed dummyRoot = new OMAConstructed(null, TAG_PerProviderSubscription, null); - buildHomeSPTree(homeSP, dummyRoot, mSPs.size() + 1); - try { - addSP(dummyRoot); - } catch (FileNotFoundException fnfe) { - MOTree tree = MOTree.buildMgmtTree(OMAConstants.PPS_URN, - OMAConstants.OMAVersion, dummyRoot); - writeMO(tree, mPpsFile); - } - mSPs.put(homeSP.getFQDN(), homeSP); - } - - 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()); - } - - 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); - } catch (FileNotFoundException fnfe) { - MOTree tree = new MOTree(instanceTree.getUrn(), instanceTree.getDtdRev(), - instanceTree.getRoot()); - writeMO(tree, mPpsFile); - } - - return sp; - } - - /** - * Add an SP sub-tree. mo must be PPS with an immediate instance child (e.g. Cred01) and an - * optional UpdateIdentifier, - * - * @param mo The new MO - * @throws IOException - */ - private void addSP(OMANode mo) throws IOException { - MOTree moTree; - try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) { - moTree = MOTree.unmarshal(in); - moTree.getRoot().addChild(mo); - } - writeMO(moTree, mPpsFile); - } - - private static OMAConstructed findTargetTree(MOTree moTree, String fqdn) throws OMAException { - OMANode pps = moTree.getRoot(); - for (OMANode node : pps.getChildren()) { - OMANode instance = null; - if (node.getName().equals(TAG_PerProviderSubscription)) { - instance = getInstanceNode((OMAConstructed) node); - } else if (!node.isLeaf()) { - instance = node; - } - if (instance != null) { - String nodeFqdn = getString(instance.getListValue(FQDNPath.iterator())); - if (fqdn.equalsIgnoreCase(nodeFqdn)) { - return (OMAConstructed) node; - // targetTree is rooted at the PPS - } - } - } - return null; - } - - private static OMAConstructed getInstanceNode(OMAConstructed root) throws OMAException { - for (OMANode child : root.getChildren()) { - if (!child.isLeaf()) { - return (OMAConstructed) child; - } - } - throw new OMAException("Cannot find instance node"); - } - - public int modifySP(String fqdn, Collection<PasspointManagementObjectDefinition> mods) - throws IOException, SAXException { - - Log.d(Utils.hs2LogTag(getClass()), "modifying SP: " + mods); - MOTree moTree; - int ppsMods = 0; - int updateIdentifier; - try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) { - moTree = MOTree.unmarshal(in); - // moTree is PPS/?/provider-data - - OMAConstructed targetTree = findTargetTree(moTree, fqdn); - if (targetTree == null) { - throw new IOException("Failed to find PPS tree for " + fqdn); - } - OMAConstructed instance = getInstanceNode(targetTree); - - for (PasspointManagementObjectDefinition mod : mods) { - LinkedList<String> tailPath = getTailPath(mod.getBaseUri(), - TAG_PerProviderSubscription); - OMAConstructed modRoot = buildMoTree(mod).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 = 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 { - tailPath.removeFirst(); // Drop the instance - OMANode current = instance.getListValue(tailPath.iterator()); - if (current == null) { - throw new IOException("No previous node for " + tailPath + " in " + fqdn); - } - for (OMANode newNode : modRoot.getChildren()) { - // newNode is something like Credential - // current is the same existing node - current.getParent().replaceNode(current, newNode); - ppsMods++; - } - } - } - } - writeMO(moTree, mPpsFile); - - return ppsMods; - } - - private static MOTree buildMoTree(PasspointManagementObjectDefinition - managementObjectDefinition) - throws IOException, SAXException { - - OMAParser omaParser = new OMAParser(); - return omaParser.parse(managementObjectDefinition.getMoTree(), OMAConstants.PPS_URN); - } - - private static LinkedList<String> getTailPath(String pathString, String rootName) - throws IOException { - String[] path = pathString.split("/"); - int pathIndex; - for (pathIndex = 0; pathIndex < path.length; pathIndex++) { - if (path[pathIndex].equalsIgnoreCase(rootName)) { - pathIndex++; - break; - } - } - if (pathIndex >= path.length) { - throw new IOException("Bad node-path: " + pathString); - } - LinkedList<String> tailPath = new LinkedList<>(); - while (pathIndex < path.length) { - tailPath.add(path[pathIndex]); - pathIndex++; - } - return tailPath; - } - - public HomeSP getHomeSP(String fqdn) { - return mSPs.get(fqdn); - } - - public void removeSP(String fqdn) throws IOException { - if (mSPs.remove(fqdn) == null) { - Log.d(Utils.hs2LogTag(getClass()), "No HS20 profile to delete for " + fqdn); - return; - } - - Log.d(Utils.hs2LogTag(getClass()), "Deleting HS20 profile for " + fqdn); - - MOTree moTree; - try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) { - moTree = MOTree.unmarshal(in); - OMAConstructed tbd = findTargetTree(moTree, fqdn); - if (tbd == null) { - throw new IOException("Node " + fqdn + " doesn't exist in MO tree"); - } - OMAConstructed pps = moTree.getRoot(); - OMANode removed = pps.removeNode("?", tbd); - if (removed == null) { - throw new IOException("Failed to remove " + fqdn + " out of MO tree"); - } - } - writeMO(moTree, mPpsFile); - } - - public String getMOTree(String fqdn) throws IOException { - if (fqdn == null) { - return null; - } - try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(mPpsFile))) { - MOTree moTree = MOTree.unmarshal(in); - OMAConstructed target = findTargetTree(moTree, fqdn); - if (target == null) { - return null; - } - return MOTree.buildMgmtTree(OMAConstants.PPS_URN, - OMAConstants.OMAVersion, target).toXml(); - } catch (FileNotFoundException fnfe) { - return null; - } - } - - private static void writeMO(MOTree moTree, File f) throws IOException { - try (BufferedOutputStream out = - new BufferedOutputStream(new FileOutputStream(f, false))) { - moTree.marshal(out); - out.flush(); - } - } - - 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); - IMSIParameter imsi = cred.getImsi(); - simNode.addChild(TAG_IMSI, null, imsi != null ? imsi.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); - - // !!! Note: This node defines CRL checking through OSCP, I suspect we won't be able - // to do that so it is commented out: - //credentialNode.addChild(TAG_CheckAAAServerCertStatus, null, "TRUE", null); - return providerSubNode; - } - - private static String getInstanceString(int instance) { - return "r1i" + instance; - } - - private static String getRCList(Collection<Long> rcs) { - StringBuilder builder = new StringBuilder(); - boolean first = true; - for (Long roamingConsortium : rcs) { - if (first) { - first = false; - } else { - builder.append(','); - } - builder.append(String.format("%x", roamingConsortium)); - } - return builder.toString(); - } - - private static List<HomeSP> buildSPs(MOTree moTree) throws OMAException { - OMAConstructed spList; - List<HomeSP> homeSPs = new ArrayList<>(); - if (moTree.getRoot().getName().equals(TAG_PerProviderSubscription)) { - // The old PPS file was rooted at PPS instead of MgmtTree to conserve space - spList = moTree.getRoot(); - - if (spList == null) { - return homeSPs; - } - - for (OMANode node : spList.getChildren()) { - if (!node.isLeaf()) { - homeSPs.add(buildHomeSP(node, 0)); - } - } - } else { - for (OMANode ppsRoot : moTree.getRoot().getChildren()) { - if (ppsRoot.getName().equals(TAG_PerProviderSubscription)) { - Integer updateIdentifier = null; - OMANode instance = null; - for (OMANode child : ppsRoot.getChildren()) { - if (child.getName().equals(TAG_UpdateIdentifier)) { - updateIdentifier = getInteger(child); - } else if (!child.isLeaf()) { - instance = child; - } - } - if (instance == null) { - throw new OMAException("PPS node missing instance node"); - } - homeSPs.add(buildHomeSP(instance, - updateIdentifier != null ? updateIdentifier : 0)); - } - } - } - - return homeSPs; - } - - 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); - } - - private static Credential buildCredential(OMANode credNode) throws OMAException { - long ctime = getTime(credNode.getChild(TAG_CreationDate)); - long expTime = getTime(credNode.getChild(TAG_ExpirationDate)); - String realm = getString(credNode.getChild(TAG_Realm)); - boolean checkAAACert = getBoolean(credNode.getChild(TAG_CheckAAAServerCertStatus)); - - OMANode unNode = credNode.getChild(TAG_UsernamePassword); - OMANode certNode = credNode.getChild(TAG_DigitalCertificate); - OMANode simNode = credNode.getChild(TAG_SIM); - - int alternatives = 0; - alternatives += unNode != null ? 1 : 0; - alternatives += certNode != null ? 1 : 0; - alternatives += simNode != null ? 1 : 0; - if (alternatives != 1) { - throw new OMAException("Expected exactly one credential type, got " + alternatives); - } - - if (unNode != null) { - String userName = getString(unNode.getChild(TAG_Username)); - String password = getString(unNode.getChild(TAG_Password)); - boolean machineManaged = getBoolean(unNode.getChild(TAG_MachineManaged)); - String softTokenApp = getString(unNode.getChild(TAG_SoftTokenApp)); - boolean ableToShare = getBoolean(unNode.getChild(TAG_AbleToShare)); - - OMANode eapMethodNode = unNode.getChild(TAG_EAPMethod); - int eapID = getInteger(eapMethodNode.getChild(TAG_EAPType)); - - EAP.EAPMethodID eapMethodID = EAP.mapEAPMethod(eapID); - if (eapMethodID == null) { - throw new OMAException("Unknown EAP method: " + eapID); - } - - Long vid = getOptionalInteger(eapMethodNode.getChild(TAG_VendorId)); - Long vtype = getOptionalInteger(eapMethodNode.getChild(TAG_VendorType)); - Long innerEAPType = getOptionalInteger(eapMethodNode.getChild(TAG_InnerEAPType)); - EAP.EAPMethodID innerEAPMethod = null; - if (innerEAPType != null) { - innerEAPMethod = EAP.mapEAPMethod(innerEAPType.intValue()); - if (innerEAPMethod == null) { - throw new OMAException("Bad inner EAP method: " + innerEAPType); - } - } - - Long innerVid = getOptionalInteger(eapMethodNode.getChild(TAG_InnerVendorID)); - Long innerVtype = getOptionalInteger(eapMethodNode.getChild(TAG_InnerVendorType)); - String innerNonEAPMethod = getString(eapMethodNode.getChild(TAG_InnerMethod)); - - EAPMethod eapMethod; - if (innerEAPMethod != null) { - eapMethod = new EAPMethod(eapMethodID, new InnerAuthEAP(innerEAPMethod)); - } else if (vid != null) { - eapMethod = new EAPMethod(eapMethodID, - new ExpandedEAPMethod(EAP.AuthInfoID.ExpandedEAPMethod, - vid.intValue(), vtype)); - } else if (innerVid != null) { - eapMethod = - new EAPMethod(eapMethodID, new ExpandedEAPMethod(EAP.AuthInfoID - .ExpandedInnerEAPMethod, innerVid.intValue(), innerVtype)); - } else if (innerNonEAPMethod != null) { - eapMethod = new EAPMethod(eapMethodID, new NonEAPInnerAuth(innerNonEAPMethod)); - } else { - throw new OMAException("Incomplete set of EAP parameters"); - } - - return new Credential(ctime, expTime, realm, checkAAACert, eapMethod, userName, - password, machineManaged, softTokenApp, ableToShare); - } - if (certNode != null) { - try { - String certTypeString = getString(certNode.getChild(TAG_CertificateType)); - byte[] fingerPrint = getOctets(certNode.getChild(TAG_CertSHA256Fingerprint)); - - EAPMethod eapMethod = new EAPMethod(EAP.EAPMethodID.EAP_TLS, null); - - return new Credential(ctime, expTime, realm, checkAAACert, eapMethod, - Credential.mapCertType(certTypeString), fingerPrint); - } catch (NumberFormatException nfe) { - throw new OMAException("Bad hex string: " + nfe.toString()); - } - } - if (simNode != null) { - try { - IMSIParameter imsi = null; - if (!TextUtils.isEmpty(getString(simNode.getChild(TAG_IMSI)))) { - imsi = new IMSIParameter(getString(simNode.getChild(TAG_IMSI))); - } - - EAPMethod eapMethod = - new EAPMethod(EAP.mapEAPMethod(getInteger(simNode.getChild(TAG_EAPType))), - null); - - return new Credential(ctime, expTime, realm, checkAAACert, eapMethod, imsi); - } catch (IOException ioe) { - throw new OMAException("Failed to parse IMSI: " + ioe); - } - } - throw new OMAException("Missing credential parameters"); - } - - public static OMANode getChild(OMANode node, String key) throws OMAException { - OMANode child = node.getChild(key); - if (child == null) { - throw new OMAException("No such node: " + key); - } - return child; - } - - public static String getString(OMANode node, String key) throws OMAException { - OMANode child = node.getChild(key); - if (child == null) { - throw new OMAException("Missing value for " + key); - } else if (!child.isLeaf()) { - throw new OMAException(key + " is not a leaf node"); - } - return child.getValue(); - } - - public static long getLong(OMANode node, String key, Long dflt) throws OMAException { - OMANode child = node.getChild(key); - if (child == null) { - if (dflt != null) { - return dflt; - } else { - throw new OMAException("Missing value for " + key); - } - } else { - if (!child.isLeaf()) { - throw new OMAException(key + " is not a leaf node"); - } - String value = child.getValue(); - try { - long result = Long.parseLong(value); - if (result < 0) { - throw new OMAException("Negative value for " + key); - } - return result; - } catch (NumberFormatException nfe) { - throw new OMAException("Value for " + key + " is non-numeric: " + value); - } - } - } - - public static <T> T getSelection(OMANode node, String key) throws OMAException { - OMANode child = node.getChild(key); - if (child == null) { - throw new OMAException("Missing value for " + key); - } else if (!child.isLeaf()) { - throw new OMAException(key + " is not a leaf node"); - } - return getSelection(key, child.getValue()); - } - - public static <T> T getSelection(String key, String value) throws OMAException { - if (value == null) { - throw new OMAException("No value for " + key); - } - Map<String, Object> kvp = sSelectionMap.get(key); - T result = (T) kvp.get(value.toLowerCase()); - if (result == null) { - throw new OMAException("Invalid value '" + value + "' for " + key); - } - return result; - } - - private static boolean getBoolean(OMANode boolNode) { - return boolNode != null && Boolean.parseBoolean(boolNode.getValue()); - } - - public static String getString(OMANode stringNode) { - return stringNode != null ? stringNode.getValue() : null; - } - - private static int getInteger(OMANode intNode, int dflt) throws OMAException { - if (intNode == null) { - return dflt; - } - return getInteger(intNode); - } - - private static int getInteger(OMANode intNode) throws OMAException { - if (intNode == null) { - throw new OMAException("Missing integer value"); - } - try { - return Integer.parseInt(intNode.getValue()); - } catch (NumberFormatException nfe) { - throw new OMAException("Invalid integer: " + intNode.getValue()); - } - } - - private static Long getMac(OMANode macNode) throws OMAException { - if (macNode == null) { - return null; - } - try { - return Long.parseLong(macNode.getValue(), 16); - } catch (NumberFormatException nfe) { - throw new OMAException("Invalid MAC: " + macNode.getValue()); - } - } - - private static Long getOptionalInteger(OMANode intNode) throws OMAException { - if (intNode == null) { - return null; - } - try { - return Long.parseLong(intNode.getValue()); - } catch (NumberFormatException nfe) { - throw new OMAException("Invalid integer: " + intNode.getValue()); - } - } - - public static long getTime(OMANode timeNode) throws OMAException { - if (timeNode == null) { - return Utils.UNSET_TIME; - } - String timeText = timeNode.getValue(); - try { - Date date = DTFormat.parse(timeText); - return date.getTime(); - } catch (ParseException pe) { - throw new OMAException("Badly formatted time: " + timeText); - } - } - - private static byte[] getOctets(OMANode octetNode) throws OMAException { - if (octetNode == null) { - throw new OMAException("Missing byte value"); - } - return Utils.hexToBytes(octetNode.getValue()); - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/XMLNode.java b/service/java/com/android/server/wifi/hotspot2/omadm/XMLNode.java deleted file mode 100644 index 76b7076df..000000000 --- a/service/java/com/android/server/wifi/hotspot2/omadm/XMLNode.java +++ /dev/null @@ -1,287 +0,0 @@ -package com.android.server.wifi.hotspot2.omadm; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class XMLNode { - private final String mTag; - private final Map<String, NodeAttribute> mAttributes; - private final List<XMLNode> mChildren; - private final XMLNode mParent; - private MOTree mMO; - private StringBuilder mTextBuilder; - private String mText; - - private static final String XML_SPECIAL_CHARS = "\"'<>&"; - private static final Set<Character> XML_SPECIAL = new HashSet<>(); - private static final String CDATA_OPEN = "<![CDATA["; - private static final String CDATA_CLOSE = "]]>"; - - static { - for (int n = 0; n < XML_SPECIAL_CHARS.length(); n++) { - XML_SPECIAL.add(XML_SPECIAL_CHARS.charAt(n)); - } - } - - public XMLNode(XMLNode parent, String tag, Attributes attributes) throws SAXException { - mTag = tag; - - mAttributes = new HashMap<>(); - - if (attributes.getLength() > 0) { - for (int n = 0; n < attributes.getLength(); n++) - mAttributes.put(attributes.getQName(n), new NodeAttribute(attributes.getQName(n), - attributes.getType(n), attributes.getValue(n))); - } - - mParent = parent; - mChildren = new ArrayList<>(); - - mTextBuilder = new StringBuilder(); - } - - public XMLNode(XMLNode parent, String tag, Map<String, String> attributes) { - mTag = tag; - - mAttributes = new HashMap<>(attributes == null ? 0 : attributes.size()); - - if (attributes != null) { - for (Map.Entry<String, String> entry : attributes.entrySet()) { - mAttributes.put(entry.getKey(), new NodeAttribute(entry.getKey(), "", entry.getValue())); - } - } - - mParent = parent; - mChildren = new ArrayList<>(); - - mTextBuilder = new StringBuilder(); - } - - @Override - public boolean equals(Object thatObject) { - if (thatObject == this) { - return true; - } else if (thatObject.getClass() != XMLNode.class) { - return false; - } - - XMLNode that = (XMLNode) thatObject; - if (!getTag().equals(that.getTag()) - || mAttributes.size() != that.mAttributes.size() - || mChildren.size() != that.mChildren.size()) { - return false; - } - - for (Map.Entry<String, NodeAttribute> entry : mAttributes.entrySet()) { - if (!entry.getValue().equals(that.mAttributes.get(entry.getKey()))) { - return false; - } - } - - List<XMLNode> cloneOfThat = new ArrayList<>(that.mChildren); - for (XMLNode child : mChildren) { - Iterator<XMLNode> thatChildren = cloneOfThat.iterator(); - boolean found = false; - while (thatChildren.hasNext()) { - XMLNode thatChild = thatChildren.next(); - if (child.equals(thatChild)) { - found = true; - thatChildren.remove(); - break; - } - } - if (!found) { - return false; - } - } - return true; - } - - public void setText(String text) { - mText = text; - mTextBuilder = null; - } - - public void addText(char[] chs, int start, int length) { - String s = new String(chs, start, length); - String trimmed = s.trim(); - if (trimmed.isEmpty()) - return; - - if (s.charAt(0) != trimmed.charAt(0)) - mTextBuilder.append(' '); - mTextBuilder.append(trimmed); - if (s.charAt(s.length() - 1) != trimmed.charAt(trimmed.length() - 1)) - mTextBuilder.append(' '); - } - - public void addChild(XMLNode child) { - mChildren.add(child); - } - - public void close() throws IOException, SAXException { - String text = mTextBuilder.toString().trim(); - StringBuilder filtered = new StringBuilder(text.length()); - for (int n = 0; n < text.length(); n++) { - char ch = text.charAt(n); - if (ch >= ' ') - filtered.append(ch); - } - - mText = filtered.toString(); - mTextBuilder = null; - - if (MOTree.hasMgmtTreeTag(mText)) { - try { - NodeAttribute urn = mAttributes.get(OMAConstants.SppMOAttribute); - OMAParser omaParser = new OMAParser(); - mMO = omaParser.parse(mText, urn != null ? urn.getValue() : null); - } - catch (SAXException | IOException e) { - mMO = null; - } - } - } - - public String getTag() { - return mTag; - } - - public String getNameSpace() throws OMAException { - String[] nsn = mTag.split(":"); - if (nsn.length != 2) { - throw new OMAException("Non-namespaced tag: '" + mTag + "'"); - } - return nsn[0]; - } - - public String getStrippedTag() throws OMAException { - String[] nsn = mTag.split(":"); - if (nsn.length != 2) { - throw new OMAException("Non-namespaced tag: '" + mTag + "'"); - } - return nsn[1].toLowerCase(); - } - - public XMLNode getSoleChild() throws OMAException{ - if (mChildren.size() != 1) { - throw new OMAException("Expected exactly one child to " + mTag); - } - return mChildren.get(0); - } - - public XMLNode getParent() { - return mParent; - } - - public String getText() { - return mText; - } - - public Map<String, NodeAttribute> getAttributes() { - return Collections.unmodifiableMap(mAttributes); - } - - /** - * Get the attributes of this node as a map of attribute name to attribute value. - * @return The attribute mapping. - */ - public Map<String, String> getTextualAttributes() { - Map<String, String> map = new HashMap<>(mAttributes.size()); - for (Map.Entry<String, NodeAttribute> entry : mAttributes.entrySet()) { - map.put(entry.getKey(), entry.getValue().getValue()); - } - return map; - } - - public String getAttributeValue(String name) { - NodeAttribute nodeAttribute = mAttributes.get(name); - return nodeAttribute != null ? nodeAttribute.getValue() : null; - } - - public List<XMLNode> getChildren() { - return mChildren; - } - - public MOTree getMOTree() { - return mMO; - } - - private void toString(char[] indent, StringBuilder sb) { - Arrays.fill(indent, ' '); - - sb.append(indent).append('<').append(mTag); - for (Map.Entry<String, NodeAttribute> entry : mAttributes.entrySet()) { - sb.append(' ').append(entry.getKey()).append("='").append(entry.getValue().getValue()).append('\''); - } - - if (mText != null && !mText.isEmpty()) { - sb.append('>').append(escapeCdata(mText)).append("</").append(mTag).append(">\n"); - } - else if (mChildren.isEmpty()) { - sb.append("/>\n"); - } - else { - sb.append(">\n"); - char[] subIndent = Arrays.copyOf(indent, indent.length + 2); - for (XMLNode child : mChildren) { - child.toString(subIndent, sb); - } - sb.append(indent).append("</").append(mTag).append(">\n"); - } - } - - private static String escapeCdata(String text) { - if (!escapable(text)) { - return text; - } - - // Any appearance of ]]> in the text must be split into "]]" | "]]>" | <![CDATA[ | ">" - // i.e. "split the sequence by putting a close CDATA and a new open CDATA before the '>' - StringBuilder sb = new StringBuilder(); - sb.append(CDATA_OPEN); - int start = 0; - for (;;) { - int etoken = text.indexOf(CDATA_CLOSE); - if (etoken >= 0) { - sb.append(text.substring(start, etoken + 2)).append(CDATA_CLOSE).append(CDATA_OPEN); - start = etoken + 2; - } - else { - if (start < text.length() - 1) { - sb.append(text.substring(start)); - } - break; - } - } - sb.append(CDATA_CLOSE); - return sb.toString(); - } - - private static boolean escapable(String s) { - for (int n = 0; n < s.length(); n++) { - if (XML_SPECIAL.contains(s.charAt(n))) { - return true; - } - } - return false; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - toString(new char[0], sb); - return sb.toString(); - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/pps/Credential.java b/service/java/com/android/server/wifi/hotspot2/pps/Credential.java deleted file mode 100644 index 4a0602155..000000000 --- a/service/java/com/android/server/wifi/hotspot2/pps/Credential.java +++ /dev/null @@ -1,357 +0,0 @@ -package com.android.server.wifi.hotspot2.pps; - -import android.net.wifi.WifiEnterpriseConfig; -import android.security.Credentials; -import android.security.KeyStore; -import android.text.TextUtils; -import android.util.Base64; -import android.util.Log; - -import com.android.server.wifi.IMSIParameter; -import com.android.server.wifi.anqp.eap.EAP; -import com.android.server.wifi.anqp.eap.EAPMethod; -import com.android.server.wifi.anqp.eap.NonEAPInnerAuth; -import com.android.server.wifi.hotspot2.Utils; -import com.android.server.wifi.hotspot2.omadm.OMAException; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.security.GeneralSecurityException; -import java.security.MessageDigest; -import java.util.Arrays; - -public class Credential { - public enum CertType {IEEE, x509v3} - - public static final String CertTypeX509 = "x509v3"; - public static final String CertTypeIEEE = "802.1ar"; - - private final long mCtime; - private final long mExpTime; - private final String mRealm; - private final boolean mCheckAAACert; - - private final String mUserName; - private final String mPassword; - private final boolean mDisregardPassword; - private final boolean mMachineManaged; - private final String mSTokenApp; - private final boolean mShare; - private final EAPMethod mEAPMethod; - - private final CertType mCertType; - private final byte[] mFingerPrint; - - private final IMSIParameter mImsi; - - public Credential(long ctime, long expTime, String realm, boolean checkAAACert, - EAPMethod eapMethod, String userName, String password, - boolean machineManaged, String stApp, boolean share) { - mCtime = ctime; - mExpTime = expTime; - mRealm = realm; - mCheckAAACert = checkAAACert; - mEAPMethod = eapMethod; - mUserName = userName; - - if (!TextUtils.isEmpty(password)) { - byte[] pwOctets = Base64.decode(password, Base64.DEFAULT); - mPassword = new String(pwOctets, StandardCharsets.UTF_8); - } else { - mPassword = null; - } - mDisregardPassword = false; - - mMachineManaged = machineManaged; - mSTokenApp = stApp; - mShare = share; - - mCertType = null; - mFingerPrint = null; - - mImsi = null; - } - - public Credential(long ctime, long expTime, String realm, boolean checkAAACert, - EAPMethod eapMethod, Credential.CertType certType, byte[] fingerPrint) { - mCtime = ctime; - mExpTime = expTime; - mRealm = realm; - mCheckAAACert = checkAAACert; - mEAPMethod = eapMethod; - mCertType = certType; - mFingerPrint = fingerPrint; - - mUserName = null; - mPassword = null; - mDisregardPassword = false; - mMachineManaged = false; - mSTokenApp = null; - mShare = false; - - mImsi = null; - } - - public Credential(long ctime, long expTime, String realm, boolean checkAAACert, - EAPMethod eapMethod, IMSIParameter imsi) { - mCtime = ctime; - mExpTime = expTime; - mRealm = realm; - mCheckAAACert = checkAAACert; - mEAPMethod = eapMethod; - mImsi = imsi; - - mCertType = null; - mFingerPrint = null; - - mUserName = null; - mPassword = null; - mDisregardPassword = false; - mMachineManaged = false; - mSTokenApp = null; - mShare = false; - } - - public Credential(Credential other, String password) { - mCtime = other.mCtime; - mExpTime = other.mExpTime; - mRealm = other.mRealm; - mCheckAAACert = other.mCheckAAACert; - mUserName = other.mUserName; - mPassword = password; - mDisregardPassword = other.mDisregardPassword; - mMachineManaged = other.mMachineManaged; - mSTokenApp = other.mSTokenApp; - mShare = other.mShare; - mEAPMethod = other.mEAPMethod; - mCertType = other.mCertType; - mFingerPrint = other.mFingerPrint; - mImsi = other.mImsi; - } - - public Credential(WifiEnterpriseConfig enterpriseConfig, KeyStore keyStore, boolean update) - throws IOException { - mCtime = Utils.UNSET_TIME; - mExpTime = Utils.UNSET_TIME; - mRealm = enterpriseConfig.getRealm(); - mCheckAAACert = false; - mEAPMethod = mapEapMethod(enterpriseConfig.getEapMethod(), - enterpriseConfig.getPhase2Method()); - mCertType = mEAPMethod.getEAPMethodID() == EAP.EAPMethodID.EAP_TLS ? CertType.x509v3 : null; - byte[] fingerPrint; - - if (enterpriseConfig.getClientCertificate() != null) { - // !!! Not sure this will be true in any practical instances: - try { - MessageDigest digester = MessageDigest.getInstance("SHA-256"); - fingerPrint = digester.digest(enterpriseConfig.getClientCertificate().getEncoded()); - } catch (GeneralSecurityException gse) { - Log.e(Utils.hs2LogTag(getClass()), - "Failed to generate certificate fingerprint: " + gse); - fingerPrint = null; - } - } else if (enterpriseConfig.getClientCertificateAlias() != null) { - String alias = enterpriseConfig.getClientCertificateAlias(); - byte[] octets = keyStore.get(Credentials.USER_CERTIFICATE + alias); - if (octets != null) { - try { - MessageDigest digester = MessageDigest.getInstance("SHA-256"); - fingerPrint = digester.digest(octets); - } catch (GeneralSecurityException gse) { - Log.e(Utils.hs2LogTag(getClass()), "Failed to construct digest: " + gse); - fingerPrint = null; - } - } else // !!! The current alias is *not* derived from the fingerprint... - { - try { - fingerPrint = Base64.decode(enterpriseConfig.getClientCertificateAlias(), - Base64.DEFAULT); - } catch (IllegalArgumentException ie) { - Log.e(Utils.hs2LogTag(getClass()), "Bad base 64 alias"); - fingerPrint = null; - } - } - } else { - fingerPrint = null; - } - mFingerPrint = fingerPrint; - String imsi = enterpriseConfig.getPlmn(); - mImsi = imsi == null || imsi.length() == 0 ? null : new IMSIParameter(imsi); - mUserName = enterpriseConfig.getIdentity(); - mPassword = enterpriseConfig.getPassword(); - mDisregardPassword = update && mPassword.length() < 2; - mMachineManaged = false; - mSTokenApp = null; - mShare = false; - } - - public static CertType mapCertType(String certType) throws OMAException { - if (certType.equalsIgnoreCase(CertTypeX509)) { - return CertType.x509v3; - } else if (certType.equalsIgnoreCase(CertTypeIEEE)) { - return CertType.IEEE; - } else { - throw new OMAException("Invalid cert type: '" + certType + "'"); - } - } - - private static EAPMethod mapEapMethod(int eapMethod, int phase2Method) throws IOException { - switch (eapMethod) { - case WifiEnterpriseConfig.Eap.TLS: - return new EAPMethod(EAP.EAPMethodID.EAP_TLS, null); - case WifiEnterpriseConfig.Eap.TTLS: - /* keep this table in sync with WifiEnterpriseConfig.Phase2 enum */ - NonEAPInnerAuth inner; - switch (phase2Method) { - case WifiEnterpriseConfig.Phase2.PAP: - inner = new NonEAPInnerAuth(NonEAPInnerAuth.NonEAPType.PAP); - break; - case WifiEnterpriseConfig.Phase2.MSCHAP: - inner = new NonEAPInnerAuth(NonEAPInnerAuth.NonEAPType.MSCHAP); - break; - case WifiEnterpriseConfig.Phase2.MSCHAPV2: - inner = new NonEAPInnerAuth(NonEAPInnerAuth.NonEAPType.MSCHAPv2); - break; - default: - throw new IOException("TTLS phase2 method " + - phase2Method + " not valid for Passpoint"); - } - return new EAPMethod(EAP.EAPMethodID.EAP_TTLS, inner); - case WifiEnterpriseConfig.Eap.SIM: - return new EAPMethod(EAP.EAPMethodID.EAP_SIM, null); - case WifiEnterpriseConfig.Eap.AKA: - return new EAPMethod(EAP.EAPMethodID.EAP_AKA, null); - case WifiEnterpriseConfig.Eap.AKA_PRIME: - return new EAPMethod(EAP.EAPMethodID.EAP_AKAPrim, null); - default: - String methodName; - if (eapMethod >= 0 && eapMethod < WifiEnterpriseConfig.Eap.strings.length) { - methodName = WifiEnterpriseConfig.Eap.strings[eapMethod]; - } else { - methodName = Integer.toString(eapMethod); - } - throw new IOException("EAP method id " + methodName + " is not valid for Passpoint"); - } - } - - public EAPMethod getEAPMethod() { - return mEAPMethod; - } - - public String getRealm() { - return mRealm; - } - - public IMSIParameter getImsi() { - return mImsi; - } - - public String getUserName() { - return mUserName; - } - - public String getPassword() { - return mPassword; - } - - public boolean hasDisregardPassword() { - return mDisregardPassword; - } - - public CertType getCertType() { - return mCertType; - } - - public byte[] getFingerPrint() { - return mFingerPrint; - } - - public long getCtime() { - return mCtime; - } - - public long getExpTime() { - return mExpTime; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Credential that = (Credential) o; - - if (mCheckAAACert != that.mCheckAAACert) return false; - if (mCtime != that.mCtime) return false; - if (mExpTime != that.mExpTime) return false; - if (mMachineManaged != that.mMachineManaged) return false; - if (mShare != that.mShare) return false; - if (mCertType != that.mCertType) return false; - if (!mEAPMethod.equals(that.mEAPMethod)) return false; - if (!Arrays.equals(mFingerPrint, that.mFingerPrint)) return false; - if (!safeEquals(mImsi, that.mImsi)) { - return false; - } - - if (!mDisregardPassword && !safeEquals(mPassword, that.mPassword)) { - return false; - } - - if (!mRealm.equals(that.mRealm)) return false; - if (!safeEquals(mSTokenApp, that.mSTokenApp)) { - return false; - } - if (!safeEquals(mUserName, that.mUserName)) { - return false; - } - - return true; - } - - private static boolean safeEquals(Object s1, Object s2) { - if (s1 == null) { - return s2 == null; - } - else { - return s2 != null && s1.equals(s2); - } - } - - @Override - public int hashCode() { - int result = (int) (mCtime ^ (mCtime >>> 32)); - result = 31 * result + (int) (mExpTime ^ (mExpTime >>> 32)); - result = 31 * result + mRealm.hashCode(); - result = 31 * result + (mCheckAAACert ? 1 : 0); - result = 31 * result + (mUserName != null ? mUserName.hashCode() : 0); - result = 31 * result + (mPassword != null ? mPassword.hashCode() : 0); - result = 31 * result + (mMachineManaged ? 1 : 0); - result = 31 * result + (mSTokenApp != null ? mSTokenApp.hashCode() : 0); - result = 31 * result + (mShare ? 1 : 0); - result = 31 * result + mEAPMethod.hashCode(); - result = 31 * result + (mCertType != null ? mCertType.hashCode() : 0); - result = 31 * result + (mFingerPrint != null ? Arrays.hashCode(mFingerPrint) : 0); - result = 31 * result + (mImsi != null ? mImsi.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "Credential{" + - "mCtime=" + Utils.toUTCString(mCtime) + - ", mExpTime=" + Utils.toUTCString(mExpTime) + - ", mRealm='" + mRealm + '\'' + - ", mCheckAAACert=" + mCheckAAACert + - ", mUserName='" + mUserName + '\'' + - ", mPassword='" + mPassword + '\'' + - ", mDisregardPassword=" + mDisregardPassword + - ", mMachineManaged=" + mMachineManaged + - ", mSTokenApp='" + mSTokenApp + '\'' + - ", mShare=" + mShare + - ", mEAPMethod=" + mEAPMethod + - ", mCertType=" + mCertType + - ", mFingerPrint=" + Utils.toHexString(mFingerPrint) + - ", mImsi='" + mImsi + '\'' + - '}'; - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/pps/HomeSP.java b/service/java/com/android/server/wifi/hotspot2/pps/HomeSP.java deleted file mode 100644 index 160a0566d..000000000 --- a/service/java/com/android/server/wifi/hotspot2/pps/HomeSP.java +++ /dev/null @@ -1,374 +0,0 @@ -package com.android.server.wifi.hotspot2.pps; - -import android.util.Log; - -import com.android.server.wifi.SIMAccessor; -import com.android.server.wifi.anqp.ANQPElement; -import com.android.server.wifi.anqp.CellularNetwork; -import com.android.server.wifi.anqp.Constants; -import com.android.server.wifi.anqp.DomainNameElement; -import com.android.server.wifi.anqp.NAIRealmElement; -import com.android.server.wifi.anqp.RoamingConsortiumElement; -import com.android.server.wifi.anqp.ThreeGPPNetworkElement; -import com.android.server.wifi.hotspot2.AuthMatch; -import com.android.server.wifi.hotspot2.NetworkDetail; -import com.android.server.wifi.hotspot2.PasspointMatch; -import com.android.server.wifi.hotspot2.Utils; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static com.android.server.wifi.anqp.Constants.ANQPElementType; - -/** - * This object describes the Home SP sub tree in the "PerProviderSubscription MO" described in - * the Hotspot 2.0 specification, section 9.1. - * As a convenience, the object also refers to the other sub-parts of the full - * PerProviderSubscription tree. - */ -public class HomeSP { - private final Map<String, Long> mSSIDs; // SSID, HESSID, [0,N] - private final String mFQDN; - private final DomainMatcher mDomainMatcher; - private final Set<String> mOtherHomePartners; - private final HashSet<Long> mRoamingConsortiums; // [0,N] - private final Set<Long> mMatchAnyOIs; // [0,N] - private final List<Long> mMatchAllOIs; // [0,N] - - private final Credential mCredential; - - // Informational: - private final String mFriendlyName; // [1] - private final String mIconURL; // [0,1] - - private final Policy mPolicy; - private final int mCredentialPriority; - private final Map<String, String> mAAATrustRoots; - private final UpdateInfo mSubscriptionUpdate; - private final SubscriptionParameters mSubscriptionParameters; - private final int mUpdateIdentifier; - - @Deprecated - public HomeSP(Map<String, Long> ssidMap, - /*@NotNull*/ String fqdn, - /*@NotNull*/ HashSet<Long> roamingConsortiums, - /*@NotNull*/ Set<String> otherHomePartners, - /*@NotNull*/ Set<Long> matchAnyOIs, - /*@NotNull*/ List<Long> matchAllOIs, - String friendlyName, - String iconURL, - Credential credential) { - - mSSIDs = ssidMap; - List<List<String>> otherPartners = new ArrayList<>(otherHomePartners.size()); - for (String otherPartner : otherHomePartners) { - otherPartners.add(Utils.splitDomain(otherPartner)); - } - mOtherHomePartners = otherHomePartners; - mFQDN = fqdn; - mDomainMatcher = new DomainMatcher(Utils.splitDomain(fqdn), otherPartners); - mRoamingConsortiums = roamingConsortiums; - mMatchAnyOIs = matchAnyOIs; - mMatchAllOIs = matchAllOIs; - mFriendlyName = friendlyName; - mIconURL = iconURL; - mCredential = credential; - - mPolicy = null; - mCredentialPriority = -1; - mAAATrustRoots = null; - mSubscriptionUpdate = null; - mSubscriptionParameters = null; - mUpdateIdentifier = -1; - } - - public HomeSP(Map<String, Long> ssidMap, - /*@NotNull*/ String fqdn, - /*@NotNull*/ HashSet<Long> roamingConsortiums, - /*@NotNull*/ Set<String> otherHomePartners, - /*@NotNull*/ Set<Long> matchAnyOIs, - /*@NotNull*/ List<Long> matchAllOIs, - String friendlyName, - String iconURL, - Credential credential, - - Policy policy, - int credentialPriority, - Map<String, String> AAATrustRoots, - UpdateInfo subscriptionUpdate, - SubscriptionParameters subscriptionParameters, - int updateIdentifier) { - - mSSIDs = ssidMap; - List<List<String>> otherPartners = new ArrayList<>(otherHomePartners.size()); - for (String otherPartner : otherHomePartners) { - otherPartners.add(Utils.splitDomain(otherPartner)); - } - mOtherHomePartners = otherHomePartners; - mFQDN = fqdn; - mDomainMatcher = new DomainMatcher(Utils.splitDomain(fqdn), otherPartners); - mRoamingConsortiums = roamingConsortiums; - mMatchAnyOIs = matchAnyOIs; - mMatchAllOIs = matchAllOIs; - mFriendlyName = friendlyName; - mIconURL = iconURL; - mCredential = credential; - - mPolicy = policy; - mCredentialPriority = credentialPriority; - mAAATrustRoots = AAATrustRoots; - mSubscriptionUpdate = subscriptionUpdate; - mSubscriptionParameters = subscriptionParameters; - mUpdateIdentifier = updateIdentifier; - } - - public int getUpdateIdentifier() { - return mUpdateIdentifier; - } - - public UpdateInfo getSubscriptionUpdate() { - return mSubscriptionUpdate; - } - - public Policy getPolicy() { - return mPolicy; - } - - public PasspointMatch match(NetworkDetail networkDetail, - Map<ANQPElementType, ANQPElement> anqpElementMap, - SIMAccessor simAccessor) { - - List<String> imsis = simAccessor.getMatchingImsis(mCredential.getImsi()); - - PasspointMatch spMatch = matchSP(networkDetail, anqpElementMap, imsis); - - if (spMatch == PasspointMatch.Incomplete || spMatch == PasspointMatch.Declined) { - return spMatch; - } - - if (imsiMatch(imsis, (ThreeGPPNetworkElement) - anqpElementMap.get(ANQPElementType.ANQP3GPPNetwork)) != null) { - // PLMN match, promote sp match to roaming if necessary. - return spMatch == PasspointMatch.None ? PasspointMatch.RoamingProvider : spMatch; - } - - NAIRealmElement naiRealmElement = - (NAIRealmElement) anqpElementMap.get(ANQPElementType.ANQPNAIRealm); - - int authMatch = naiRealmElement != null ? - naiRealmElement.match(mCredential) : - AuthMatch.Indeterminate; - - Log.d(Utils.hs2LogTag(getClass()), networkDetail.toKeyString() + " match on " + mFQDN + - ": " + spMatch + ", auth " + AuthMatch.toString(authMatch)); - - if (authMatch == AuthMatch.None) { - // Distinct auth mismatch, demote authentication. - return PasspointMatch.None; - } - else if ((authMatch & AuthMatch.Realm) == 0) { - // No realm match, return sp match as is. - return spMatch; - } - else { - // Realm match, promote sp match to roaming if necessary. - return spMatch == PasspointMatch.None ? PasspointMatch.RoamingProvider : spMatch; - } - } - - public PasspointMatch matchSP(NetworkDetail networkDetail, - Map<ANQPElementType, ANQPElement> anqpElementMap, - List<String> imsis) { - - if (mSSIDs.containsKey(networkDetail.getSSID())) { - Long hessid = mSSIDs.get(networkDetail.getSSID()); - if (hessid == null || networkDetail.getHESSID() == hessid) { - Log.d(Utils.hs2LogTag(getClass()), "match SSID"); - return PasspointMatch.HomeProvider; - } - } - - Set<Long> anOIs = new HashSet<>(); - - if (networkDetail.getRoamingConsortiums() != null) { - for (long oi : networkDetail.getRoamingConsortiums()) { - anOIs.add(oi); - } - } - - boolean validANQP = anqpElementMap != null && - Constants.hasBaseANQPElements(anqpElementMap.keySet()); - - RoamingConsortiumElement rcElement = validANQP ? - (RoamingConsortiumElement) anqpElementMap.get(ANQPElementType.ANQPRoamingConsortium) - : null; - if (rcElement != null) { - anOIs.addAll(rcElement.getOIs()); - } - - // It may seem reasonable to check for home provider match prior to checking for roaming - // relationship, but it is possible to avoid an ANQP query if it turns out that the - // "match all" rule fails based only on beacon info only. - boolean roamingMatch = false; - - if (!mMatchAllOIs.isEmpty()) { - boolean matchesAll = true; - - for (long spOI : mMatchAllOIs) { - if (!anOIs.contains(spOI)) { - matchesAll = false; - break; - } - } - if (matchesAll) { - roamingMatch = true; - } - else { - if (validANQP || networkDetail.getAnqpOICount() == 0) { - return PasspointMatch.Declined; - } - else { - return PasspointMatch.Incomplete; - } - } - } - - if (!roamingMatch && - (!Collections.disjoint(mMatchAnyOIs, anOIs) || - !Collections.disjoint(mRoamingConsortiums, anOIs))) { - roamingMatch = true; - } - - if (!validANQP) { - return PasspointMatch.Incomplete; - } - - DomainNameElement domainNameElement = - (DomainNameElement) anqpElementMap.get(ANQPElementType.ANQPDomName); - - if (domainNameElement != null) { - for (String domain : domainNameElement.getDomains()) { - List<String> anLabels = Utils.splitDomain(domain); - DomainMatcher.Match match = mDomainMatcher.isSubDomain(anLabels); - if (match != DomainMatcher.Match.None) { - return PasspointMatch.HomeProvider; - } - - if (imsiMatch(imsis, anLabels) != null) { - return PasspointMatch.HomeProvider; - } - } - } - - return roamingMatch ? PasspointMatch.RoamingProvider : PasspointMatch.None; - } - - private String imsiMatch(List<String> imsis, ThreeGPPNetworkElement plmnElement) { - if (imsis == null || plmnElement == null || plmnElement.getPlmns().isEmpty()) { - return null; - } - for (CellularNetwork network : plmnElement.getPlmns()) { - for (String mccMnc : network) { - String imsi = imsiMatch(imsis, mccMnc); - if (imsi != null) { - return imsi; - } - } - } - return null; - } - - private String imsiMatch(List<String> imsis, List<String> fqdn) { - if (imsis == null) { - return null; - } - String mccMnc = Utils.getMccMnc(fqdn); - return mccMnc != null ? imsiMatch(imsis, mccMnc) : null; - } - - private String imsiMatch(List<String> imsis, String mccMnc) { - if (mCredential.getImsi().matchesMccMnc(mccMnc)) { - for (String imsi : imsis) { - if (imsi.startsWith(mccMnc)) { - return imsi; - } - } - } - return null; - } - - public String getFQDN() { return mFQDN; } - public String getFriendlyName() { return mFriendlyName; } - public HashSet<Long> getRoamingConsortiums() { return mRoamingConsortiums; } - public Credential getCredential() { return mCredential; } - - public Map<String, Long> getSSIDs() { - return mSSIDs; - } - - public Collection<String> getOtherHomePartners() { - return mOtherHomePartners; - } - - public Set<Long> getMatchAnyOIs() { - return mMatchAnyOIs; - } - - public List<Long> getMatchAllOIs() { - return mMatchAllOIs; - } - - public String getIconURL() { - return mIconURL; - } - - public boolean deepEquals(HomeSP other) { - return mFQDN.equals(other.mFQDN) && - mSSIDs.equals(other.mSSIDs) && - mOtherHomePartners.equals(other.mOtherHomePartners) && - mRoamingConsortiums.equals(other.mRoamingConsortiums) && - mMatchAnyOIs.equals(other.mMatchAnyOIs) && - mMatchAllOIs.equals(other.mMatchAllOIs) && - mFriendlyName.equals(other.mFriendlyName) && - Utils.compare(mIconURL, other.mIconURL) == 0 && - mCredential.equals(other.mCredential); - } - - @Override - public boolean equals(Object thatObject) { - if (this == thatObject) { - return true; - } else if (thatObject == null || getClass() != thatObject.getClass()) { - return false; - } - - HomeSP that = (HomeSP) thatObject; - return mFQDN.equals(that.mFQDN); - } - - @Override - public int hashCode() { - return mFQDN.hashCode(); - } - - @Override - public String toString() { - return "HomeSP{" + - "SSIDs=" + mSSIDs + - ", FQDN='" + mFQDN + '\'' + - ", DomainMatcher=" + mDomainMatcher + - ", RoamingConsortiums={" + Utils.roamingConsortiumsToString(mRoamingConsortiums) + - '}' + - ", MatchAnyOIs={" + Utils.roamingConsortiumsToString(mMatchAnyOIs) + '}' + - ", MatchAllOIs={" + Utils.roamingConsortiumsToString(mMatchAllOIs) + '}' + - ", Credential=" + mCredential + - ", FriendlyName='" + mFriendlyName + '\'' + - ", IconURL='" + mIconURL + '\'' + - '}'; - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/pps/Policy.java b/service/java/com/android/server/wifi/hotspot2/pps/Policy.java deleted file mode 100644 index 186afd167..000000000 --- a/service/java/com/android/server/wifi/hotspot2/pps/Policy.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.android.server.wifi.hotspot2.pps; - -import com.android.server.wifi.hotspot2.Utils; -import com.android.server.wifi.hotspot2.omadm.OMAException; -import com.android.server.wifi.hotspot2.omadm.OMANode; -import com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_Country; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_DLBandwidth; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_FQDN_Match; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_IPProtocol; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_MaximumBSSLoadValue; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_MinBackhaulThreshold; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_NetworkType; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_PolicyUpdate; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_PortNumber; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_PreferredRoamingPartnerList; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_Priority; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_RequiredProtoPortTuple; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_SPExclusionList; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_SSID; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_ULBandwidth; - -public class Policy { - private final List<PreferredRoamingPartner> mPreferredRoamingPartners; - private final List<MinBackhaul> mMinBackhaulThresholds; - private final UpdateInfo mPolicyUpdate; - private final List<String> mSPExclusionList; - private final Map<Integer, List<Integer>> mRequiredProtos; - private final int mMaxBSSLoad; - - public Policy(OMANode node) throws OMAException { - - OMANode rpNode = node.getChild(TAG_PreferredRoamingPartnerList); - if (rpNode == null) { - mPreferredRoamingPartners = null; - } - else { - mPreferredRoamingPartners = new ArrayList<>(rpNode.getChildren().size()); - for (OMANode instance : rpNode.getChildren()) { - if (instance.isLeaf()) { - throw new OMAException("Not expecting leaf node in " + - TAG_PreferredRoamingPartnerList); - } - mPreferredRoamingPartners.add(new PreferredRoamingPartner(instance)); - } - } - - OMANode bhtNode = node.getChild(TAG_MinBackhaulThreshold); - if (bhtNode == null) { - mMinBackhaulThresholds = null; - } - else { - mMinBackhaulThresholds = new ArrayList<>(bhtNode.getChildren().size()); - for (OMANode instance : bhtNode.getChildren()) { - if (instance.isLeaf()) { - throw new OMAException("Not expecting leaf node in " + - TAG_MinBackhaulThreshold); - } - mMinBackhaulThresholds.add(new MinBackhaul(instance)); - } - } - - mPolicyUpdate = new UpdateInfo(node.getChild(TAG_PolicyUpdate)); - - OMANode sxNode = node.getChild(TAG_SPExclusionList); - if (sxNode == null) { - mSPExclusionList = null; - } - else { - mSPExclusionList = new ArrayList<>(sxNode.getChildren().size()); - for (OMANode instance : sxNode.getChildren()) { - if (instance.isLeaf()) { - throw new OMAException("Not expecting leaf node in " + TAG_SPExclusionList); - } - mSPExclusionList - .add(PasspointManagementObjectManager.getString(instance, TAG_SSID)); - } - } - - OMANode rptNode = node.getChild(TAG_RequiredProtoPortTuple); - if (rptNode == null) { - mRequiredProtos = null; - } - else { - mRequiredProtos = new HashMap<>(rptNode.getChildren().size()); - for (OMANode instance : rptNode.getChildren()) { - if (instance.isLeaf()) { - throw new OMAException("Not expecting leaf node in " + - TAG_RequiredProtoPortTuple); - } - int protocol = - (int) PasspointManagementObjectManager - .getLong(instance, TAG_IPProtocol, null); - String[] portSegments = - PasspointManagementObjectManager - .getString(instance, TAG_PortNumber).split(","); - List<Integer> ports = new ArrayList<>(portSegments.length); - for (String portSegment : portSegments) { - try { - ports.add(Integer.parseInt(portSegment)); - } - catch (NumberFormatException nfe) { - throw new OMAException("Port is not a number: " + portSegment); - } - } - mRequiredProtos.put(protocol, ports); - } - } - - mMaxBSSLoad = (int) PasspointManagementObjectManager.getLong(node, - TAG_MaximumBSSLoadValue, Long.MAX_VALUE); - } - - public List<PreferredRoamingPartner> getPreferredRoamingPartners() { - return mPreferredRoamingPartners; - } - - public List<MinBackhaul> getMinBackhaulThresholds() { - return mMinBackhaulThresholds; - } - - public UpdateInfo getPolicyUpdate() { - return mPolicyUpdate; - } - - public List<String> getSPExclusionList() { - return mSPExclusionList; - } - - public Map<Integer, List<Integer>> getRequiredProtos() { - return mRequiredProtos; - } - - public int getMaxBSSLoad() { - return mMaxBSSLoad; - } - - private static class PreferredRoamingPartner { - private final List<String> mDomain; - private final Boolean mIncludeSubDomains; - private final int mPriority; - private final String mCountry; - - private PreferredRoamingPartner(OMANode node) - throws OMAException { - - String[] segments = - PasspointManagementObjectManager.getString(node, TAG_FQDN_Match).split(","); - if (segments.length != 2) { - throw new OMAException("Bad FQDN match string: " + TAG_FQDN_Match); - } - mDomain = Utils.splitDomain(segments[0]); - mIncludeSubDomains = - PasspointManagementObjectManager.getSelection(TAG_FQDN_Match, segments[1]); - mPriority = (int) PasspointManagementObjectManager.getLong(node, TAG_Priority, null); - mCountry = PasspointManagementObjectManager.getString(node, TAG_Country); - } - - @Override - public String toString() { - return "PreferredRoamingPartner{" + - "domain=" + mDomain + - ", includeSubDomains=" + mIncludeSubDomains + - ", priority=" + mPriority + - ", country='" + mCountry + '\'' + - '}'; - } - } - - private static class MinBackhaul { - private final Boolean mHome; - private final long mDL; - private final long mUL; - - private MinBackhaul(OMANode node) throws OMAException { - mHome = PasspointManagementObjectManager.getSelection(node, TAG_NetworkType); - mDL = PasspointManagementObjectManager.getLong(node, TAG_DLBandwidth, Long.MAX_VALUE); - mUL = PasspointManagementObjectManager.getLong(node, TAG_ULBandwidth, Long.MAX_VALUE); - } - - @Override - public String toString() { - return "MinBackhaul{" + - "home=" + mHome + - ", DL=" + mDL + - ", UL=" + mUL + - '}'; - } - } - - @Override - public String toString() { - return "Policy{" + - "preferredRoamingPartners=" + mPreferredRoamingPartners + - ", minBackhaulThresholds=" + mMinBackhaulThresholds + - ", policyUpdate=" + mPolicyUpdate + - ", SPExclusionList=" + mSPExclusionList + - ", requiredProtos=" + mRequiredProtos + - ", maxBSSLoad=" + mMaxBSSLoad + - '}'; - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/pps/SubscriptionParameters.java b/service/java/com/android/server/wifi/hotspot2/pps/SubscriptionParameters.java deleted file mode 100644 index 2e44d5d75..000000000 --- a/service/java/com/android/server/wifi/hotspot2/pps/SubscriptionParameters.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.android.server.wifi.hotspot2.pps; - -import com.android.server.wifi.hotspot2.Utils; -import com.android.server.wifi.hotspot2.omadm.OMAException; -import com.android.server.wifi.hotspot2.omadm.OMANode; -import com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager; - -import java.util.ArrayList; -import java.util.List; - -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_CreationDate; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_DataLimit; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_ExpirationDate; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_StartDate; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_TimeLimit; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_TypeOfSubscription; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_UsageLimits; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_UsageTimePeriod; - -public class SubscriptionParameters { - private final long mCDate; - private final long mXDate; - private final String mType; - private final List<Limit> mLimits; - - public SubscriptionParameters(OMANode node) throws OMAException { - mCDate = PasspointManagementObjectManager.getTime(node.getChild(TAG_CreationDate)); - mXDate = PasspointManagementObjectManager.getTime(node.getChild(TAG_ExpirationDate)); - mType = PasspointManagementObjectManager.getString(node.getChild(TAG_TypeOfSubscription)); - - OMANode ulNode = node.getChild(TAG_UsageLimits); - if (ulNode == null) { - mLimits = null; - } - else { - mLimits = new ArrayList<>(ulNode.getChildren().size()); - for (OMANode instance : ulNode.getChildren()) { - if (instance.isLeaf()) { - throw new OMAException("Not expecting leaf node in " + - TAG_UsageLimits); - } - mLimits.add(new Limit(instance)); - } - } - - } - - private static class Limit { - private final long mDataLimit; - private final long mStartDate; - private final long mTimeLimit; - private final long mUsageTimePeriod; - - private Limit(OMANode node) throws OMAException { - mDataLimit = PasspointManagementObjectManager - .getLong(node, TAG_DataLimit, Long.MAX_VALUE); - mStartDate = PasspointManagementObjectManager - .getTime(node.getChild(TAG_StartDate)); - mTimeLimit = PasspointManagementObjectManager - .getLong(node, TAG_TimeLimit, Long.MAX_VALUE) - * PasspointManagementObjectManager.IntervalFactor; - mUsageTimePeriod = PasspointManagementObjectManager - .getLong(node, TAG_UsageTimePeriod, null); - } - - @Override - public String toString() { - return "Limit{" + - "dataLimit=" + mDataLimit + - ", startDate=" + Utils.toUTCString(mStartDate) + - ", timeLimit=" + mTimeLimit + - ", usageTimePeriod=" + mUsageTimePeriod + - '}'; - } - } - - @Override - public String toString() { - return "SubscriptionParameters{" + - "cDate=" + Utils.toUTCString(mCDate) + - ", xDate=" + Utils.toUTCString(mXDate) + - ", type='" + mType + '\'' + - ", limits=" + mLimits + - '}'; - } -} diff --git a/service/java/com/android/server/wifi/hotspot2/pps/UpdateInfo.java b/service/java/com/android/server/wifi/hotspot2/pps/UpdateInfo.java deleted file mode 100644 index 99861dddc..000000000 --- a/service/java/com/android/server/wifi/hotspot2/pps/UpdateInfo.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.android.server.wifi.hotspot2.pps; - -import android.util.Base64; - -import com.android.server.wifi.hotspot2.Utils; -import com.android.server.wifi.hotspot2.omadm.OMAException; -import com.android.server.wifi.hotspot2.omadm.OMANode; -import com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager; - -import java.nio.charset.StandardCharsets; - -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_CertSHA256Fingerprint; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_CertURL; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_Password; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_Restriction; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_TrustRoot; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_URI; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_UpdateInterval; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_UpdateMethod; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_Username; -import static com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager.TAG_UsernamePassword; - -public class UpdateInfo { - public enum UpdateRestriction {HomeSP, RoamingPartner, Unrestricted} - - private final long mInterval; - private final boolean mSPPClientInitiated; - private final UpdateRestriction mUpdateRestriction; - private final String mURI; - private final String mUsername; - private final String mPassword; - private final String mCertURL; - private final String mCertFP; - - public UpdateInfo(OMANode policyUpdate) throws OMAException { - mInterval = PasspointManagementObjectManager.getLong(policyUpdate, TAG_UpdateInterval, null) - * PasspointManagementObjectManager.IntervalFactor; - mSPPClientInitiated = PasspointManagementObjectManager.getSelection(policyUpdate, - TAG_UpdateMethod); - mUpdateRestriction = - PasspointManagementObjectManager.getSelection(policyUpdate, TAG_Restriction); - mURI = PasspointManagementObjectManager.getString(policyUpdate, TAG_URI); - - OMANode unp = policyUpdate.getChild(TAG_UsernamePassword); - if (unp != null) { - mUsername = PasspointManagementObjectManager.getString(unp.getChild(TAG_Username)); - String pw = PasspointManagementObjectManager.getString(unp.getChild(TAG_Password)); - mPassword = new String(Base64.decode(pw.getBytes(StandardCharsets.US_ASCII), - Base64.DEFAULT), StandardCharsets.UTF_8); - } - else { - mUsername = null; - mPassword = null; - } - - OMANode trustRoot = PasspointManagementObjectManager.getChild(policyUpdate, TAG_TrustRoot); - mCertURL = PasspointManagementObjectManager.getString(trustRoot, TAG_CertURL); - mCertFP = PasspointManagementObjectManager.getString(trustRoot, TAG_CertSHA256Fingerprint); - } - - public long getInterval() { - return mInterval; - } - - public boolean isSPPClientInitiated() { - return mSPPClientInitiated; - } - - public UpdateRestriction getUpdateRestriction() { - return mUpdateRestriction; - } - - public String getURI() { - return mURI; - } - - public String getUsername() { - return mUsername; - } - - public String getPassword() { - return mPassword; - } - - public String getCertURL() { - return mCertURL; - } - - public String getCertFP() { - return mCertFP; - } - - @Override - public String toString() { - return "UpdateInfo{" + - "interval=" + Utils.toHMS(mInterval) + - ", SPPClientInitiated=" + mSPPClientInitiated + - ", updateRestriction=" + mUpdateRestriction + - ", URI='" + mURI + '\'' + - ", username='" + mUsername + '\'' + - ", password=" + mPassword + - ", certURL='" + mCertURL + '\'' + - ", certFP='" + mCertFP + '\'' + - '}'; - } -} diff --git a/tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java b/tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java deleted file mode 100644 index c76bf91a3..000000000 --- a/tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.wifi; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -import android.net.wifi.PasspointManagementObjectDefinition; -import android.net.wifi.WifiEnterpriseConfig; -import android.security.KeyStore; -import android.test.suitebuilder.annotation.SmallTest; - -import com.android.server.wifi.hotspot2.omadm.MOTree; -import com.android.server.wifi.hotspot2.omadm.OMAParser; -import com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager; -import com.android.server.wifi.hotspot2.omadm.XMLNode; -import com.android.server.wifi.hotspot2.pps.Credential; -import com.android.server.wifi.hotspot2.pps.HomeSP; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.xml.sax.SAXException; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Unit tests for {@link com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager}. - */ -@SmallTest -public class PasspointManagementObjectManagerTest { - - private static final String TAG = "PasspointManagementObjectManagerTest"; - - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - - private File createFileFromResource(String configFile) throws Exception { - InputStream in = getClass().getClassLoader().getResourceAsStream(configFile); - File file = tempFolder.newFile(configFile.split("/")[1]); - - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - FileOutputStream out = new FileOutputStream(file); - - String line; - - while ((line = reader.readLine()) != null) { - out.write(line.getBytes(StandardCharsets.UTF_8)); - } - - out.flush(); - out.close(); - return file; - } - - private void addMoFromWifiConfig(PasspointManagementObjectManager moMgr) throws Exception { - HashMap<String, Long> ssidMap = new HashMap<>(); - String fqdn = "tunisia.org"; - HashSet<Long> roamingConsortiums = new HashSet<Long>(); - HashSet<String> otherHomePartners = new HashSet<String>(); - Set<Long> matchAnyOIs = new HashSet<Long>(); - List<Long> matchAllOIs = new ArrayList<Long>(); - String friendlyName = "Tunisian Passpoint Provider"; - String iconUrl = "http://www.tunisia.org/icons/base_icon.png"; - - WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig(); - enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TTLS); - enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.PAP); - enterpriseConfig.setIdentity("testIdentity1"); - enterpriseConfig.setPassword("AnDrO1D"); - - KeyStore keyStore = mock(KeyStore.class); - Credential credential = new Credential(enterpriseConfig, keyStore, false); - - HomeSP newHomeSP = new HomeSP(Collections.<String, Long>emptyMap(), fqdn, - roamingConsortiums, Collections.<String>emptySet(), - Collections.<Long>emptySet(), Collections.<Long>emptyList(), - friendlyName, null, credential); - - moMgr.addSP(newHomeSP); - } - - private void addMoFromXml(PasspointManagementObjectManager moMgr) throws Exception { - InputStream in = getClass().getClassLoader().getResourceAsStream(R2_TTLS_XML_FILE); - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - StringBuilder builder = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - builder.append(line).append("\n"); - } - - String xml = builder.toString(); - moMgr.addSP(xml); - } - - private static final String R1_CONFIG_FILE = "assets/r1.PerProviderSubscription.conf"; - private static final String R2_CONFIG_FILE = "assets/r2.PerProviderSubscription.conf"; - private static final String R2_TTLS_XML_FILE = "assets/r2-ttls-tree.xml"; - private static final String RUCKUS_CONFIG_FILE = "assets/ruckus.PerProviderSubscription.conf"; - - /** ensure that loading R1 configs works */ - @Test - public void loadR1Configs() throws Exception { - File file = createFileFromResource(R1_CONFIG_FILE); - PasspointManagementObjectManager moMgr = new PasspointManagementObjectManager(file, true); - List<HomeSP> homeSPs = moMgr.loadAllSPs(); - assertEquals(2, homeSPs.size()); - - /* TODO: Verify more attributes */ - HomeSP homeSP = moMgr.getHomeSP("twcwifi.com"); - assertNotNull(homeSP); - assertEquals("TWC-WiFi", homeSP.getFriendlyName()); - assertEquals("tushar4", homeSP.getCredential().getUserName()); - - homeSP = moMgr.getHomeSP("wi-fi.org"); - assertNotNull(homeSP); - assertEquals("Wi-Fi Alliance", homeSP.getFriendlyName()); - assertEquals("sta006", homeSP.getCredential().getUserName()); - } - - /** ensure that loading R2 configs works */ - @Test - public void loadR2Configs() throws Exception { - File file = createFileFromResource(R2_CONFIG_FILE); - PasspointManagementObjectManager moMgr = new PasspointManagementObjectManager(file, true); - List<HomeSP> homeSPs = moMgr.loadAllSPs(); - assertEquals(2, homeSPs.size()); - - /* TODO: Verify more attributes */ - HomeSP homeSP = moMgr.getHomeSP("twcwifi.com"); - assertNotNull(homeSP); - assertEquals("TWC-WiFi", homeSP.getFriendlyName()); - assertEquals("tushar4", homeSP.getCredential().getUserName()); - - homeSP = moMgr.getHomeSP("wi-fi.org"); - assertNotNull(homeSP); - assertEquals("Wi-Fi Alliance", homeSP.getFriendlyName()); - assertEquals("sta015", homeSP.getCredential().getUserName()); - } - - /** verify adding a new service provider works */ - @Test - public void addSP() throws Exception { - File file = tempFolder.newFile("PerProviderSubscription.conf"); - PasspointManagementObjectManager moMgr = new PasspointManagementObjectManager(file, true); - List<HomeSP> homeSPs = moMgr.loadAllSPs(); - assertEquals(0, homeSPs.size()); - - addMoFromWifiConfig(moMgr); - addMoFromXml(moMgr); - - PasspointManagementObjectManager moMgr2 = new PasspointManagementObjectManager(file, true); - homeSPs = moMgr2.loadAllSPs(); - assertEquals(2, homeSPs.size()); - - /* TODO: Verify more attributes */ - HomeSP homeSP = moMgr2.getHomeSP("rk-ttls.org"); - assertNotNull(homeSP); - assertEquals("RK TTLS", homeSP.getFriendlyName()); - assertEquals("sta020", homeSP.getCredential().getUserName()); - - homeSP = moMgr.getHomeSP("tunisia.org"); - assertNotNull(homeSP); - assertEquals("Tunisian Passpoint Provider", homeSP.getFriendlyName()); - assertEquals("testIdentity1", homeSP.getCredential().getUserName()); - } - - /** verify that xml serialization/deserialization works */ - public void checkXml() throws Exception { - InputStream in = getClass().getClassLoader().getResourceAsStream(R2_TTLS_XML_FILE); - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - StringBuilder builder = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - builder.append(line).append("\n"); - } - - String xmlIn = builder.toString(); - - try { - // Parse the file content: - OMAParser parser = new OMAParser(); - MOTree moTree = parser.parse(xmlIn, ""); - XMLNode rootIn = parser.getRoot(); - - // Serialize it back out: - String xmlOut = moTree.toXml(); - parser = new OMAParser(); - // And parse it again: - parser.parse(xmlOut, ""); - XMLNode rootOut = parser.getRoot(); - - // Compare the two roots: - assertTrue("Checking serialized XML", rootIn.equals(rootOut)); - } catch (SAXException se) { - throw new IOException(se); - } - } - - /** verify modifying an existing service provider works */ - @Test - public void modifySP() throws Exception { - File file = createFileFromResource(R2_CONFIG_FILE); - PasspointManagementObjectManager moMgr = new PasspointManagementObjectManager(file, true); - List<HomeSP> homeSPs = moMgr.loadAllSPs(); - assertEquals(2, homeSPs.size()); - - /* verify that wi-fi.org has update identifier of 1 */ - HomeSP homeSP = moMgr.getHomeSP("wi-fi.org"); - assertNotNull(homeSP); - assertEquals("Wi-Fi Alliance", homeSP.getFriendlyName()); - assertEquals("sta015", homeSP.getCredential().getUserName()); - assertEquals(1, homeSP.getUpdateIdentifier()); - - /* PasspointManagementObjectDefinition to change update identifier */ - String urn = "wfa:mo:hotspot2dot0-perprovidersubscription:1.0"; - String baseUri = "./Wi-Fi/wi-fi.org/PerProviderSubscription/UpdateIdentifier"; - String xmlTree = - "<MgmtTree>\n" - + " <VerDTD>1.2</VerDTD>\n" - + " <Node>\n" - + " <NodeName>UpdateIdentifier</NodeName>\n" - + " <Value>9</Value>\n" - + " </Node>\n" - + "</MgmtTree>"; - - PasspointManagementObjectDefinition moDef = - new PasspointManagementObjectDefinition(baseUri, urn, xmlTree); - List<PasspointManagementObjectDefinition> moDefs = - new ArrayList<PasspointManagementObjectDefinition>(); - moDefs.add(moDef); - moMgr.modifySP("wi-fi.org", moDefs); - - /* reload all the SPs again */ - moMgr.loadAllSPs(); - - homeSP = moMgr.getHomeSP("wi-fi.org"); - assertEquals("Wi-Fi Alliance", homeSP.getFriendlyName()); - assertEquals("sta015", homeSP.getCredential().getUserName()); - assertEquals(9, homeSP.getUpdateIdentifier()); - } - - /** verify removing an existing service provider works */ - @Test - public void removeSP() throws Exception { - File file = createFileFromResource(R2_CONFIG_FILE); - PasspointManagementObjectManager moMgr = new PasspointManagementObjectManager(file, true); - List<HomeSP> homeSPs = moMgr.loadAllSPs(); - assertEquals(2, homeSPs.size()); - - moMgr.removeSP("wi-fi.org"); - - homeSPs = moMgr.loadAllSPs(); - assertEquals(null, moMgr.getHomeSP("wi-fi.org")); - } -} - - - - - - - - - |