From 01a959d60a2c5f04ab240513a853d7845b3a309e Mon Sep 17 00:00:00 2001 From: Alex Klyubin Date: Wed, 18 Mar 2015 10:05:45 -0700 Subject: [PATCH] Add app-level usesCleartextTraffic manifest attribute. The attribute declares whether the app intends to use cleartext network traffic (e.g., HTTP, WebSockets, XMPP, SMTP, IMAP -- without TLS or STARTTLS). The default value is true. If set to false, the app declares that it does not intend to use cleartext network traffic. In this case the app requests the platform, tooling, and third-party libraries to prevent it from using cleartext traffic. The danger of cleartext network traffic is that its confidentiality, authenticity, and integrity are not guaranteed. This feature is designed to help apps which care about security of data exchanged over the network. These apps can accidentally regress/downgrade to using cleartext network communications. This typically happens when the server the app communicates with all of a sudden tells it to use cleartext communications (e.g, HTTP URL instead of an HTTPS URL) or when one of the components of the app gets updated and regresses to cleartext communications without the developer noticing. In general, the prevention measures are on best effort basis. It's impossible to automatically prevent all instances of cleartext traffic. For example, an app bent on bypassing restrictions could perform low-level network I/O with unusual TCP packet fragmentation, or could use a custom application-level protocol. The expectation is that most apps use libraries for network communications and these libraries over time will start to honor this flag, thus increasing the protections offered by it. Bug: 19215516 Change-Id: I8700d51ddbc5d528faa4b6a5fa5bc9551ad02d13 --- .../android/content/pm/ApplicationInfo.java | 12 ++++++++++++ core/java/android/content/pm/PackageParser.java | 6 ++++++ core/res/res/values/attrs_manifest.xml | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java index e1a2aa96c36c2..05c19db1fd483 100644 --- a/core/java/android/content/pm/ApplicationInfo.java +++ b/core/java/android/content/pm/ApplicationInfo.java @@ -333,6 +333,18 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { */ public static final int FLAG_FULL_BACKUP_ONLY = 1<<26; + /** + * Value for {@link #flags}: {@code true} if the application may use cleartext network traffic + * (e.g., HTTP rather than HTTPS; WebSockets rather than WebSockets Secure; XMPP, IMAP, STMP + * without STARTTLS or TLS). If {@code false}, the app declares that it does not intend to use + * cleartext network traffic, in which case platform components (e.g., HTTP stacks, + * {@code WebView}, {@code MediaPlayer}) will refuse app's requests to use cleartext traffic. + * Third-party libraries are encouraged to honor this flag as well. + * + * @hide + */ + public static final int FLAG_USES_CLEARTEXT_TRAFFIC = 1<<27; + /** * Value for {@link #flags}: true if code from this application will need to be * loaded into other applications' processes. On devices that support multiple diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index 4d9445df250ac..4952ba1989c84 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -2549,6 +2549,12 @@ public class PackageParser { ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP; } + if (sa.getBoolean( + com.android.internal.R.styleable.AndroidManifestApplication_usesCleartextTraffic, + true)) { + ai.flags |= ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC; + } + if (sa.getBoolean( com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl, false /* default is no RTL support*/)) { diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml index 0c3fb9a41fa29..ea592cf5d065a 100644 --- a/core/res/res/values/attrs_manifest.xml +++ b/core/res/res/values/attrs_manifest.xml @@ -389,6 +389,15 @@ with the same {@link android.R.attr#taskAffinity} as it has. --> + + + + +