VpnService: require root access

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2017-11-30 21:46:56 +01:00
parent 417e973c8f
commit 9e028ae8d6
3 changed files with 16 additions and 1 deletions
@@ -283,9 +283,14 @@ public class VpnService extends Service
return -0xfff0001;
if (!existsInPath("wg") || !existsInPath("wg-quick"))
return -0xfff0002;
if (!existsInPath("su"))
return -0xfff0003;
Log.i(TAG, "Running wg-quick up for " + config.getName());
final File configFile = new File(getFilesDir(), config.getName() + ".conf");
return rootShell.run(null, "wg-quick up '" + configFile.getPath() + "'");
final int ret = rootShell.run(null, "wg-quick up '" + configFile.getPath() + "'");
if (ret == 13 /* EPERM */)
return -0xfff0003;
return ret;
}
private boolean existsInPath(final String file) {
@@ -304,6 +309,9 @@ public class VpnService extends Service
} else if (ret == -0xfff0002) {
Toast.makeText(getApplicationContext(), getString(R.string.error_missing),
Toast.LENGTH_LONG).show();
} else if (ret == -0xfff0003) {
Toast.makeText(getApplicationContext(), getString(R.string.error_su),
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), getString(R.string.error_up),
Toast.LENGTH_SHORT).show();