diff options
Diffstat (limited to 'ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn')
5 files changed, 77 insertions, 48 deletions
diff --git a/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/VpnProfile.java index bdfa51c3..9eed03f1 100644 --- a/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/VpnProfile.java +++ b/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/VpnProfile.java @@ -2,8 +2,8 @@ package de.blinkt.openvpn; import se.leap.bitmaskclient.R; -import se.leap.bitmaskclient.Dashboard; import se.leap.bitmaskclient.EIP; +import se.leap.bitmaskclient.Dashboard; import se.leap.bitmaskclient.Provider; import android.content.Context; @@ -18,18 +18,16 @@ import android.security.KeyChain; import android.security.KeyChainException; import android.util.Base64; -import de.blinkt.openvpn.core.NativeUtils; -import de.blinkt.openvpn.core.VpnStatus; -import de.blinkt.openvpn.core.OpenVpnService; -import de.blinkt.openvpn.core.X509Utils; import org.spongycastle.util.io.pem.PemObject; import org.spongycastle.util.io.pem.PemWriter; -import javax.crypto.BadPaddingException; -import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; -import java.io.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Serializable; +import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.security.InvalidKeyException; @@ -43,6 +41,16 @@ import java.util.Locale; import java.util.UUID; import java.util.Vector; +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; + +import de.blinkt.openvpn.core.NativeUtils; +import de.blinkt.openvpn.core.OpenVpnService; +import de.blinkt.openvpn.core.VpnStatus; +import de.blinkt.openvpn.core.X509Utils; + public class VpnProfile implements Serializable { // Note that this class cannot be moved to core where it belongs since // the profile loading depends on it being here @@ -54,7 +62,9 @@ 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]]"; - public static final String MINIVPN = "miniopenvpn"; + 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; @@ -144,6 +154,14 @@ 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 openVpnEscape(String unescaped) { if (unescaped == null) return null; @@ -258,22 +276,16 @@ public class VpnProfile implements Serializable { cfg += " tcp-client\n"; - android.util.Log.d("vpnprofile", Integer.toString(mAuthenticationType)); switch (mAuthenticationType) { case VpnProfile.TYPE_USERPASS_CERTIFICATES: cfg += "auth-user-pass\n"; - case VpnProfile.TYPE_CERTIFICATES: - // Ca - // cfg += insertFileData("ca", mCaFilename); - - // // Client Cert + Key - // cfg += insertFileData("key", mClientKeyFilename); - // cfg += insertFileData("cert", mClientCertFilename); + case VpnProfile.TYPE_CERTIFICATES: // FIXME This is all we need...The whole switch statement can go... SharedPreferences preferences = context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, context.MODE_PRIVATE); cfg+="<ca>\n"+preferences.getString(Provider.CA_CERT, "")+"\n</ca>\n"; cfg+="<key>\n"+preferences.getString(EIP.PRIVATE_KEY, "")+"\n</key>\n"; cfg+="<cert>\n"+preferences.getString(EIP.CERTIFICATE, "")+"\n</cert>\n"; + break; case VpnProfile.TYPE_USERPASS_PKCS12: cfg += "auth-user-pass\n"; @@ -549,7 +561,7 @@ public class VpnProfile implements Serializable { // Add fixed paramenters //args.add("/data/data/de.blinkt.openvpn/lib/openvpn"); - args.add(cacheDir.getAbsolutePath() + "/" + VpnProfile.MINIVPN); + args.add(cacheDir.getAbsolutePath() + "/" + getMiniVPNExecutableName()); args.add("--config"); args.add(cacheDir.getAbsolutePath() + "/" + OVPNCONFIGFILE); @@ -558,14 +570,16 @@ public class VpnProfile implements Serializable { return args.toArray(new String[args.size()]); } + + public Intent prepareIntent(Context context) { String prefix = context.getPackageName(); Intent intent = new Intent(context, OpenVpnService.class); if (mAuthenticationType == VpnProfile.TYPE_KEYSTORE || mAuthenticationType == VpnProfile.TYPE_USERPASS_KEYSTORE) { - // if (getKeyStoreCertificates(context) == null) - // return null; + if (getKeyStoreCertificates(context) == null) + return null; } intent.putExtra(prefix + ".ARGV", buildOpenvpnArgv(context.getCacheDir())); @@ -734,8 +748,8 @@ public class VpnProfile implements Serializable { //! Return an error if somethign is wrong public int checkProfile(Context context) { if (mAuthenticationType == TYPE_KEYSTORE || mAuthenticationType == TYPE_USERPASS_KEYSTORE) { - // if (mAlias == null) - // return R.string.no_keystore_cert_selected; + if (mAlias == null) + return R.string.no_keystore_cert_selected; } if (!mUsePull || mAuthenticationType == TYPE_STATICKEYS) { diff --git a/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java b/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java index 32e5cabb..4fbbe165 100644 --- a/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java +++ b/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java @@ -33,7 +33,7 @@ public class ConfigParser { public void setDefinition(HashMap<String,Vector<Vector<String>>> args) { options = args; } - + public void parseConfig(Reader reader) throws IOException, ConfigParseError { diff --git a/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java b/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java index 67c24884..0de54ed7 100644 --- a/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java +++ b/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java @@ -1,18 +1,28 @@ package de.blinkt.openvpn.core; import android.util.Log; -import se.leap.bitmaskclient.R; -import de.blinkt.openvpn.VpnProfile; -import de.blinkt.openvpn.core.VpnStatus.ConnectionStatus; -import de.blinkt.openvpn.core.VpnStatus.LogItem; -import java.io.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedList; +import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; +import se.leap.bitmaskclient.R; +import de.blinkt.openvpn.VpnProfile; +import de.blinkt.openvpn.core.VpnStatus.ConnectionStatus; +import de.blinkt.openvpn.core.VpnStatus.LogItem; + public class OpenVPNThread implements Runnable { private static final String DUMP_PATH_STRING = "Dump path: "; private static final String TAG = "OpenVPN"; @@ -158,16 +168,16 @@ 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.MINIVPN , "/lib"); + String applibpath = argv[0].replace("/cache/" + VpnProfile.getMiniVPNExecutableName() , "/lib"); String lbpath = pb.environment().get("LD_LIBRARY_PATH"); if(lbpath==null) lbpath = applibpath; else - lbpath = lbpath + ":" + applibpath; + lbpath = applibpath + ":" + lbpath; if (!applibpath.equals(mNativeDir)) { - lbpath = lbpath + ":" + mNativeDir; + lbpath = mNativeDir + ":" + lbpath; } return lbpath; } diff --git a/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/OpenVpnService.java b/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/OpenVpnService.java index d7bb827e..b5bba5d4 100644 --- a/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/OpenVpnService.java +++ b/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/OpenVpnService.java @@ -79,7 +79,6 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac else return false; } - // From: http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java public static String humanReadableByteCount(long bytes, boolean mbit) { if (mbit) @@ -244,7 +243,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac PendingIntent getLogPendingIntent() { // Let the configure Button show the Log - Intent intent = new Intent(getBaseContext(), LogWindow.class); + Intent intent = new Intent(getBaseContext(), se.leap.bitmaskclient.Dashboard.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); PendingIntent startLW = PendingIntent.getActivity(this, 0, intent, 0); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); @@ -748,12 +747,17 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac public String getTunReopenStatus() { String currentConfiguration = getTunConfigString(); - if (currentConfiguration.equals(mLastTunCfg)) + if (currentConfiguration.equals(mLastTunCfg)) { return "NOACTION"; - else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) - return "OPEN_AFTER_CLOSE"; - else - return "OPEN_BEFORE_CLOSE"; + } else { + String release = Build.VERSION.RELEASE; + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT && !release.startsWith("4.4.3") + && !release.startsWith("4.4.4") && !release.startsWith("4.4.5")) + // There will be probably no 4.4.4 or 4.4.5 version, so don't waste effort to do parsing here + return "OPEN_AFTER_CLOSE"; + else + return "OPEN_BEFORE_CLOSE"; + } } public class LocalBinder extends Binder { diff --git a/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java b/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java index 55fcb0ba..57a94ee7 100644 --- a/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java +++ b/ics-openvpn-stripped/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java @@ -1,19 +1,20 @@ package de.blinkt.openvpn.core; +import android.content.Context; +import android.content.Intent; +import android.os.Build; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import android.content.Context; -import android.content.Intent; -import android.os.Build; import se.leap.bitmaskclient.R; import de.blinkt.openvpn.VpnProfile; public class VPNLaunchHelper { static private boolean writeMiniVPN(Context context) { - File mvpnout = new File(context.getCacheDir(),VpnProfile.MINIVPN); + File mvpnout = new File(context.getCacheDir(),VpnProfile.getMiniVPNExecutableName()); if (mvpnout.exists() && mvpnout.canExecute()) return true; @@ -23,12 +24,12 @@ public class VPNLaunchHelper { InputStream mvpn; try { - mvpn = context.getAssets().open("minivpn." + Build.CPU_ABI); + 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("minivpn." + Build.CPU_ABI2); + mvpn = context.getAssets().open(VpnProfile.getMiniVPNExecutableName() + "." + Build.CPU_ABI2); } @@ -45,7 +46,7 @@ public class VPNLaunchHelper { fout.close(); if(!mvpnout.setExecutable(true)) { - VpnStatus.logError("Failed to set minivpn executable"); + VpnStatus.logError("Failed to make OpenVPN executable"); return false; } |