diff options
author | james.wei@intel.com <james.wei@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-15 07:46:39 +0000 |
---|---|---|
committer | james.wei@intel.com <james.wei@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-15 07:46:39 +0000 |
commit | c470e1b90271e7347962ea9641b91fe87a7ea034 (patch) | |
tree | d2a1e7f77e30227db46f025995623b2fc0e65285 /net/android | |
parent | c4fc5f3b0f783b7662bfe8c128e3cde7c6352fda (diff) | |
download | chromium_src-c470e1b90271e7347962ea9641b91fe87a7ea034.zip chromium_src-c470e1b90271e7347962ea9641b91fe87a7ea034.tar.gz chromium_src-c470e1b90271e7347962ea9641b91fe87a7ea034.tar.bz2 |
implement HaveOnlyLoopbackAddresses() for android
BUG=132033
TEST=
Review URL: https://chromiumcodereview.appspot.com/10532080
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142354 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/android')
-rw-r--r-- | net/android/java/org/chromium/net/AndroidNetworkLibrary.java | 31 | ||||
-rw-r--r-- | net/android/network_library.cc | 5 | ||||
-rw-r--r-- | net/android/network_library.h | 5 |
3 files changed, 41 insertions, 0 deletions
diff --git a/net/android/java/org/chromium/net/AndroidNetworkLibrary.java b/net/android/java/org/chromium/net/AndroidNetworkLibrary.java index 699a3a4..2de0854 100644 --- a/net/android/java/org/chromium/net/AndroidNetworkLibrary.java +++ b/net/android/java/org/chromium/net/AndroidNetworkLibrary.java @@ -13,6 +13,8 @@ import org.chromium.base.CalledByNative; import org.chromium.base.CalledByNativeUnchecked; import java.io.ByteArrayInputStream; +import java.net.NetworkInterface; +import java.net.SocketException; import java.net.URLConnection; import java.security.KeyStore; import java.security.KeyStoreException; @@ -21,6 +23,7 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.concurrent.atomic.AtomicReference; +import java.util.Enumeration; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; @@ -58,6 +61,34 @@ class AndroidNetworkLibrary { return URLConnection.guessContentTypeFromName("foo." + extension); } + // Returns true if it can determine that only loopback addresses are configured. + // i.e. if only 127.0.0.1 and ::1 are routable. + // Also returns false if it cannot determine this. + @CalledByNative + static public boolean haveOnlyLoopbackAddresses() { + boolean result = true; + try { + Enumeration list = NetworkInterface.getNetworkInterfaces(); + if (list == null) return false; + + while (list.hasMoreElements()) { + NetworkInterface netIf = (NetworkInterface)list.nextElement(); + try { + if (!netIf.isUp() || netIf.isLoopback()) + continue; + result = false; + break; + } catch (SocketException e) { + continue; + } + } + } catch (SocketException e) { + Log.w(TAG, "could not get network interfaces: " + e); + return false; + } + return result; + } + /** * Validate the server's certificate chain is trusted. * @param certChain The ASN.1 DER encoded bytes for certificates. diff --git a/net/android/network_library.cc b/net/android/network_library.cc index 24a065e..57cf551 100644 --- a/net/android/network_library.cc +++ b/net/android/network_library.cc @@ -64,6 +64,11 @@ bool StoreKeyPair(const uint8* public_key, return ret; } +bool HaveOnlyLoopbackAddresses() { + JNIEnv* env = AttachCurrentThread(); + return Java_AndroidNetworkLibrary_haveOnlyLoopbackAddresses(env); +} + bool GetMimeTypeFromExtension(const std::string& extension, std::string* result) { JNIEnv* env = AttachCurrentThread(); diff --git a/net/android/network_library.h b/net/android/network_library.h index 5e2b8ec..a0a1913 100644 --- a/net/android/network_library.h +++ b/net/android/network_library.h @@ -40,6 +40,11 @@ bool StoreKeyPair(const uint8* public_key, const uint8* private_key, size_t private_len); +// Returns true if it can determine that only loopback addresses are configured. +// i.e. if only 127.0.0.1 and ::1 are routable. +// Also returns false if it cannot determine this. +bool HaveOnlyLoopbackAddresses(); + // Get the mime type (if any) that is associated with the file extension. // Returns true if a corresponding mime type exists. bool GetMimeTypeFromExtension(const std::string& extension, |