From 2a711c010c721cfa477da6bb6dfed3f508359ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Mon, 16 Jun 2014 14:13:06 +0200 Subject: Succesfully updated. --- .../main/java/de/blinkt/openvpn/VpnProfile.java | 62 +++++++++++++--------- 1 file changed, 38 insertions(+), 24 deletions(-) (limited to 'app/src/main/java/de/blinkt/openvpn/VpnProfile.java') diff --git a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java index 93d0d386..d21a085f 100644 --- a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java +++ b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java @@ -4,8 +4,8 @@ import se.leap.bitmaskclient.R; 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; @@ -20,18 +20,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; @@ -45,6 +43,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 @@ -56,7 +64,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; @@ -146,6 +156,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; @@ -260,22 +278,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+="\n"+preferences.getString(Provider.CA_CERT, "")+"\n\n"; cfg+="\n"+preferences.getString(EIP.PRIVATE_KEY, "")+"\n\n"; cfg+="\n"+preferences.getString(EIP.CERTIFICATE, "")+"\n\n"; + break; case VpnProfile.TYPE_USERPASS_PKCS12: cfg += "auth-user-pass\n"; @@ -551,7 +563,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); @@ -560,14 +572,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())); @@ -736,8 +750,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) { -- cgit v1.2.3