summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/VpnProfile.java36
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java5
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java145
3 files changed, 104 insertions, 82 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
index 666337b7..7a9c2907 100644
--- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
+++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java
@@ -41,7 +41,6 @@ import java.util.Collection;
import java.util.Locale;
import java.util.UUID;
import java.util.Vector;
-import java.util.concurrent.Future;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
@@ -50,6 +49,7 @@ import javax.crypto.NoSuchPaddingException;
import de.blinkt.openvpn.core.NativeUtils;
import de.blinkt.openvpn.core.OpenVPNService;
+import de.blinkt.openvpn.core.VPNLaunchHelper;
import de.blinkt.openvpn.core.VpnStatus;
import de.blinkt.openvpn.core.X509Utils;
@@ -64,11 +64,8 @@ public class VpnProfile implements Serializable {
public static final String EXTRA_PROFILEUUID = "de.blinkt.openvpn.profileUUID";
public static final String INLINE_TAG = "[[INLINE]]";
public static final String DISPLAYNAME_TAG = "[[NAME]]";
- private static final String MININONPIEVPN = "nopievpn";
- private static final String MINIPIEVPN = "pievpn";
private static final long serialVersionUID = 7085688938959334563L;
- private static final String OVPNCONFIGFILE = "android.conf";
public static final int MAXLOGLEVEL = 4;
public static final int CURRENT_PROFILE_VERSION = 2;
public static final int DEFAULT_MSSFIX_SIZE = 1450;
@@ -160,20 +157,6 @@ public class VpnProfile implements Serializable {
mProfileVersion = CURRENT_PROFILE_VERSION;
}
- public static String getMiniVPNExecutableName()
- {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
- return VpnProfile.MINIPIEVPN;
- else
- return VpnProfile.MININONPIEVPN;
- }
-
- public static String[] replacePieWithNoPie(String[] mArgv)
- {
- mArgv[0] = mArgv[0].replace(MINIPIEVPN, MININONPIEVPN);
- return mArgv;
- }
-
public static String openVpnEscape(String unescaped) {
if (unescaped == null)
return null;
@@ -572,19 +555,6 @@ public class VpnProfile implements Serializable {
return parts[0] + " " + netmask;
}
- private String[] buildOpenvpnArgv(File cacheDir) {
- Vector<String> args = new Vector<String>();
-
- // Add fixed paramenters
- //args.add("/data/data/de.blinkt.openvpn/lib/openvpn");
- args.add(cacheDir.getAbsolutePath() + "/" + getMiniVPNExecutableName());
-
- args.add("--config");
- args.add(cacheDir.getAbsolutePath() + "/" + OVPNCONFIGFILE);
-
-
- return args.toArray(new String[args.size()]);
- }
@@ -599,7 +569,7 @@ public class VpnProfile implements Serializable {
try {
- FileWriter cfg = new FileWriter(context.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE);
+ FileWriter cfg = new FileWriter(VPNLaunchHelper.getConfigFilePath(context));
cfg.write(getConfigFile(context, false));
cfg.flush();
cfg.close();
@@ -614,7 +584,7 @@ public class VpnProfile implements Serializable {
String prefix = context.getPackageName();
Intent intent = new Intent(context, OpenVPNService.class);
- intent.putExtra(prefix + ".ARGV", buildOpenvpnArgv(context.getCacheDir()));
+ intent.putExtra(prefix + ".ARGV", VPNLaunchHelper.buildOpenvpnArgv(context));
intent.putExtra(prefix + ".profileUUID", mUuid.toString());
ApplicationInfo info = context.getApplicationInfo();
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
index e79dbe0c..20d0e327 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
@@ -78,7 +78,8 @@ public class OpenVPNThread implements Runnable {
if( exitvalue != 0) {
VpnStatus.logError("Process exited with exit value " + exitvalue);
if (mBrokenPie) {
- String[] noPieArgv = VpnProfile.replacePieWithNoPie(mArgv);
+ /* This will probably fail since the NoPIE binary is probably not written */
+ String[] noPieArgv = VPNLaunchHelper.replacePieWithNoPie(mArgv);
// We are already noPIE, nothing to gain
if (!noPieArgv.equals(mArgv)) {
@@ -190,7 +191,7 @@ public class OpenVPNThread implements Runnable {
private String genLibraryPath(String[] argv, ProcessBuilder pb) {
// Hack until I find a good way to get the real library path
- String applibpath = argv[0].replace("/cache/" + VpnProfile.getMiniVPNExecutableName() , "/lib");
+ String applibpath = argv[0].replaceFirst("/cache/.*$" , "/lib");
String lbpath = pb.environment().get("LD_LIBRARY_PATH");
if(lbpath==null)
diff --git a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
index 15926506..de903fa5 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
@@ -7,68 +7,114 @@ package de.blinkt.openvpn.core;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
import android.os.Build;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Vector;
import de.blinkt.openvpn.R;
import de.blinkt.openvpn.VpnProfile;
public class VPNLaunchHelper {
- static private boolean writeMiniVPN(Context context) {
- File mvpnout = new File(context.getCacheDir(),VpnProfile.getMiniVPNExecutableName());
- if (mvpnout.exists() && mvpnout.canExecute())
- return true;
-
- IOException e2 = null;
-
- try {
- InputStream mvpn;
-
- try {
- mvpn = context.getAssets().open(VpnProfile.getMiniVPNExecutableName() + "." + Build.CPU_ABI);
- }
- catch (IOException errabi) {
- VpnStatus.logInfo("Failed getting assets for archicture " + Build.CPU_ABI);
- e2=errabi;
- mvpn = context.getAssets().open(VpnProfile.getMiniVPNExecutableName() + "." + Build.CPU_ABI2);
-
- }
-
-
- FileOutputStream fout = new FileOutputStream(mvpnout);
-
- byte buf[]= new byte[4096];
-
- int lenread = mvpn.read(buf);
- while(lenread> 0) {
- fout.write(buf, 0, lenread);
- lenread = mvpn.read(buf);
- }
- fout.close();
-
- if(!mvpnout.setExecutable(true)) {
- VpnStatus.logError("Failed to make OpenVPN executable");
- return false;
- }
-
-
- return true;
- } catch (IOException e) {
- if(e2!=null)
- VpnStatus.logException(e2);
- VpnStatus.logException(e);
-
- return false;
- }
+ private static final String MININONPIEVPN = "nopievpn";
+ private static final String MINIPIEVPN = "pievpn";
+ private static final String OVPNCONFIGFILE = "android.conf";
+
+
+
+ static private String writeMiniVPN(Context context) {
+ String[] abis;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
+ abis =Build.SUPPORTED_ABIS;
+ else
+ abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
+
+ for (String abi: abis) {
+
+ File mvpnout = new File(context.getCacheDir(), getMiniVPNExecutableName() + "." + abi);
+ if ((mvpnout.exists() && mvpnout.canExecute()) || writeMiniVPNBinary(context, abi, mvpnout)) {
+ return mvpnout.getPath();
+ }
+ }
+
+ return null;
}
+
+ private static String getMiniVPNExecutableName()
+ {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
+ return MINIPIEVPN;
+ else
+ return MININONPIEVPN;
+ }
+
+
+ public static String[] replacePieWithNoPie(String[] mArgv)
+ {
+ mArgv[0] = mArgv[0].replace(MINIPIEVPN, MININONPIEVPN);
+ return mArgv;
+ }
+
+
+ public static String[] buildOpenvpnArgv(Context c) {
+ Vector<String> args = new Vector<String>();
+
+ // Add fixed paramenters
+ //args.add("/data/data/de.blinkt.openvpn/lib/openvpn");
+ args.add(writeMiniVPN(c));
+
+ args.add("--config");
+ args.add(c.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE);
+
+
+ return args.toArray(new String[args.size()]);
+ }
+
+ private static boolean writeMiniVPNBinary(Context context, String abi, File mvpnout) {
+ try {
+ InputStream mvpn;
+
+ try {
+ mvpn = context.getAssets().open(getMiniVPNExecutableName() + "." + abi);
+ }
+ catch (IOException errabi) {
+ VpnStatus.logInfo("Failed getting assets for archicture " + abi);
+ return false;
+ }
+
+
+ FileOutputStream fout = new FileOutputStream(mvpnout);
+
+ byte buf[]= new byte[4096];
+
+ int lenread = mvpn.read(buf);
+ while(lenread> 0) {
+ fout.write(buf, 0, lenread);
+ lenread = mvpn.read(buf);
+ }
+ fout.close();
+
+ if(!mvpnout.setExecutable(true)) {
+ VpnStatus.logError("Failed to make OpenVPN executable");
+ return false;
+ }
+
+
+ return true;
+ } catch (IOException e) {
+ VpnStatus.logException(e);
+ return false;
+ }
+
+ }
public static void startOpenVpn(VpnProfile startprofile, Context context) {
- if(!writeMiniVPN(context)) {
+ if(writeMiniVPN(context)==null) {
VpnStatus.logError("Error writing minivpn binary");
return;
}
@@ -80,4 +126,9 @@ public class VPNLaunchHelper {
context.startService(startVPN);
}
+
+ public static String getConfigFilePath(Context context) {
+ return context.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE;
+ }
+
}