Skip to content

Commit d667aeb

Browse files
Chia-chi YehAndroid (Google) Code Review
authored andcommitted
Merge "VPN: move VpnDialogs away from system uid." into jb-dev
2 parents 926a5c5 + dadc857 commit d667aeb

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

core/java/com/android/internal/net/VpnConfig.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ public class VpnConfig implements Parcelable {
3434

3535
public static final String SERVICE_INTERFACE = "android.net.VpnService";
3636

37+
public static final String DIALOGS_PACKAGE = "com.android.vpndialogs";
38+
3739
public static final String LEGACY_VPN = "[Legacy VPN]";
3840

3941
public static Intent getIntentForConfirmation() {
4042
Intent intent = new Intent();
41-
intent.setClassName("com.android.vpndialogs", "com.android.vpndialogs.ConfirmDialog");
43+
intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ConfirmDialog");
4244
return intent;
4345
}
4446

4547
public static PendingIntent getIntentForStatusPanel(Context context, VpnConfig config) {
4648
Intent intent = new Intent();
47-
intent.setClassName("com.android.vpndialogs", "com.android.vpndialogs.ManageDialog");
49+
intent.setClassName(DIALOGS_PACKAGE, DIALOGS_PACKAGE + ".ManageDialog");
4850
intent.putExtra("config", config);
4951
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY |
5052
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

packages/VpnDialogs/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.android.vpndialogs"
3-
android:sharedUserId="android.uid.system">
2+
package="com.android.vpndialogs">
43

54
<application android:label="VpnDialogs"
65
android:allowBackup="false" >

services/java/com/android/server/connectivity/Vpn.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,16 @@ public synchronized boolean prepare(String oldPackage, String newPackage) {
106106
return true;
107107
}
108108

109-
// Only system user can revoke a package.
110-
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
111-
throw new SecurityException("Unauthorized Caller");
112-
}
109+
// Check if the caller is authorized.
110+
enforceControlPermission();
113111

114112
// Reset the interface and hide the notification.
115113
if (mInterface != null) {
116114
jniReset(mInterface);
115+
long identity = Binder.clearCallingIdentity();
117116
mCallback.restore();
118117
hideNotification();
118+
Binder.restoreCallingIdentity(identity);
119119
mInterface = null;
120120
}
121121

@@ -291,6 +291,26 @@ public synchronized void interfaceRemoved(String interfaze) {
291291
public void limitReached(String limit, String interfaze) {
292292
}
293293

294+
private void enforceControlPermission() {
295+
// System user is allowed to control VPN.
296+
if (Binder.getCallingUid() == Process.SYSTEM_UID) {
297+
return;
298+
}
299+
300+
try {
301+
// System dialogs are also allowed to control VPN.
302+
PackageManager pm = mContext.getPackageManager();
303+
ApplicationInfo app = pm.getApplicationInfo(VpnConfig.DIALOGS_PACKAGE, 0);
304+
if (Binder.getCallingUid() == app.uid) {
305+
return;
306+
}
307+
} catch (Exception e) {
308+
// ignore
309+
}
310+
311+
throw new SecurityException("Unauthorized Caller");
312+
}
313+
294314
private class Connection implements ServiceConnection {
295315
private IBinder mService;
296316

@@ -368,10 +388,8 @@ public synchronized void startLegacyVpn(VpnConfig config, String[] racoon, Strin
368388
* Return the information of the current ongoing legacy VPN.
369389
*/
370390
public synchronized LegacyVpnInfo getLegacyVpnInfo() {
371-
// Only system user can call this method.
372-
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
373-
throw new SecurityException("Unauthorized Caller");
374-
}
391+
// Check if the caller is authorized.
392+
enforceControlPermission();
375393
return (mLegacyVpnRunner == null) ? null : mLegacyVpnRunner.getInfo();
376394
}
377395

0 commit comments

Comments
 (0)