From e0f762ec657f4d6fba25485cf41e0c57632a97c0 Mon Sep 17 00:00:00 2001 From: Erik Kline Date: Tue, 22 May 2018 21:15:49 +0900 Subject: [PATCH 1/2] Fixup SntpClient to bypass Private DNS NTP may be necessary in order to validate Private DNS certificates, so it should be allowed to bypass Private DNS. Test: as follows - built, flashed, booted - tcpdump for port 53; adb shell am restart queries for the NTP hostname appear in the clear - runtest frameworks-net passes Bug: 64133961 Bug: 80118648 Change-Id: Id9ceb3fcaaffb48cbbd4cd381d48cae991572c9e --- core/java/android/net/Network.java | 44 ++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/core/java/android/net/Network.java b/core/java/android/net/Network.java index 15a0ee5eb2..d75d4391de 100644 --- a/core/java/android/net/Network.java +++ b/core/java/android/net/Network.java @@ -85,6 +85,21 @@ public class Network implements Parcelable { private static final long HANDLE_MAGIC = 0xcafed00dL; private static final int HANDLE_MAGIC_SIZE = 32; + // A boolean to control how getAllByName()/getByName() behaves in the face + // of Private DNS. + // + // When true, these calls will request that DNS resolution bypass any + // Private DNS that might otherwise apply. Use of this feature is restricted + // and permission checks are made by netd (attempts to bypass Private DNS + // without appropriate permission are silently turned into vanilla DNS + // requests). This only affects DNS queries made using this network object. + // + // It it not parceled to receivers because (a) it can be set or cleared at + // anytime and (b) receivers should be explicit about attempts to bypass + // Private DNS so that the intent of the code is easily determined and + // code search audits are possible. + private boolean mPrivateDnsBypass = false; + /** * @hide */ @@ -108,7 +123,7 @@ public class Network implements Parcelable { * @throws UnknownHostException if the address lookup fails. */ public InetAddress[] getAllByName(String host) throws UnknownHostException { - return InetAddress.getAllByNameOnNet(host, netId); + return InetAddress.getAllByNameOnNet(host, getNetIdForResolv()); } /** @@ -122,7 +137,32 @@ public class Network implements Parcelable { * if the address lookup fails. */ public InetAddress getByName(String host) throws UnknownHostException { - return InetAddress.getByNameOnNet(host, netId); + return InetAddress.getByNameOnNet(host, getNetIdForResolv()); + } + + /** + * Specify whether or not Private DNS should be bypassed when attempting + * to use {@link getAllByName()}/{@link getByName()} methods on the given + * instance for hostname resolution. + * + * @hide + */ + public void setPrivateDnsBypass(boolean bypass) { + mPrivateDnsBypass = bypass; + } + + /** + * Returns a netid marked with the Private DNS bypass flag. + * + * This flag must be kept in sync with the NETID_USE_LOCAL_NAMESERVERS flag + * in system/netd/include/NetdClient.h. + * + * @hide + */ + public int getNetIdForResolv() { + return mPrivateDnsBypass + ? (int) (0x80000000L | (long) netId) // Non-portable DNS resolution flag. + : netId; } /** From d937e3a0ee33847a7656745c85582b983a6691f0 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Tue, 22 May 2018 10:01:53 +0900 Subject: [PATCH 2/2] Add configurable captive portal probes The probes allow testing for a configurable status code and location header (regexes). They are disabled by default, so this CL is a no-op unless the probe configurations are pushed. Bug: b/79499239 Test: tests in CL pass, manual: captive portal login works Change-Id: I785723aaed06054b9aa8ebff77803f23d7836db9 --- core/java/android/net/ConnectivityManager.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index c3b8f3959f..c5cb1f5b7c 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -237,6 +237,14 @@ public class ConnectivityManager { */ public static final String EXTRA_CAPTIVE_PORTAL_URL = "android.net.extra.CAPTIVE_PORTAL_URL"; + /** + * Key for passing a {@link android.net.captiveportal.CaptivePortalProbeSpec} to the captive + * portal login activity. + * {@hide} + */ + public static final String EXTRA_CAPTIVE_PORTAL_PROBE_SPEC = + "android.net.extra.CAPTIVE_PORTAL_PROBE_SPEC"; + /** * Key for passing a user agent string to the captive portal login activity. * {@hide}