summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
Diffstat (limited to 'src/de')
-rw-r--r--src/de/blinkt/openvpn/VpnProfile.java79
-rw-r--r--src/de/blinkt/openvpn/core/DeviceStateReceiver.java235
-rw-r--r--src/de/blinkt/openvpn/core/OpenVPNThread.java23
-rw-r--r--src/de/blinkt/openvpn/core/OpenVpnService.java54
4 files changed, 177 insertions, 214 deletions
diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java
index dcca334c..8b905a84 100644
--- a/src/de/blinkt/openvpn/VpnProfile.java
+++ b/src/de/blinkt/openvpn/VpnProfile.java
@@ -1,51 +1,40 @@
package de.blinkt.openvpn;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.io.StringWriter;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.util.Collection;
-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 org.spongycastle.util.io.pem.PemObject;
-import org.spongycastle.util.io.pem.PemWriter;
-
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.os.Build;
import android.preference.PreferenceManager;
import android.security.KeyChain;
import android.security.KeyChainException;
import android.util.Base64;
-import de.blinkt.openvpn.R;
import de.blinkt.openvpn.core.NativeUtils;
import de.blinkt.openvpn.core.OpenVPN;
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.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.UUID;
+import java.util.Vector;
public class VpnProfile implements Serializable{
// Note that this class cannot be moved to core where it belongs since
@@ -198,12 +187,7 @@ public class VpnProfile implements Serializable{
//cfg += "management-signal\n";
cfg += "management-query-passwords\n";
cfg += "management-hold\n\n";
-
- /* tmp-dir patched out :)
- cfg+="# /tmp does not exist on Android\n";
- cfg+="tmp-dir ";
- cfg+=cacheDir.getAbsolutePath();
- cfg+="\n\n"; */
+ cfg += getVersionEnvString(context);
cfg+="# Log window is better readable this way\n";
cfg+="suppress-timestamps\n";
@@ -440,7 +424,18 @@ public class VpnProfile implements Serializable{
return cfg;
}
- //! Put inline data inline and other data as normal escaped filename
+ private String getVersionEnvString(Context c) {
+ String version="unknown";
+ try {
+ PackageInfo packageinfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
+ version = packageinfo.versionName;
+ } catch (PackageManager.NameNotFoundException e) {
+ }
+ return String.format(Locale.US,"setenv IV_OPENVPN_GUI_VERSION \"%s %s\"\n",c.getPackageName(),version);
+
+ }
+
+ //! Put inline data inline and other data as normal escaped filename
private String insertFileData(String cfgentry, String filedata) {
if(filedata==null) {
// TODO: generate good error
@@ -534,10 +529,6 @@ public class VpnProfile implements Serializable{
args.add("--config");
args.add(cacheDir.getAbsolutePath() + "/" + OVPNCONFIGFILE);
- // Silences script security warning
-
- args.add("script-security");
- args.add("0");
return (String[]) args.toArray(new String[args.size()]);
diff --git a/src/de/blinkt/openvpn/core/DeviceStateReceiver.java b/src/de/blinkt/openvpn/core/DeviceStateReceiver.java
index b27ea00f..f20e3617 100644
--- a/src/de/blinkt/openvpn/core/DeviceStateReceiver.java
+++ b/src/de/blinkt/openvpn/core/DeviceStateReceiver.java
@@ -15,56 +15,56 @@ import de.blinkt.openvpn.core.OpenVPN.ByteCountListener;
import java.util.LinkedList;
public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountListener {
- private int lastNetwork=-1;
- private OpenVPNMangement mManangement;
+ private int lastNetwork=-1;
+ private OpenVPNMangement mManangement;
- // Window time in s
- private final int TRAFFIC_WINDOW = 60;
- // Data traffic limit in bytes
- private final long TRAFFIC_LIMIT = 64 * 1024;
+ // Window time in s
+ private final int TRAFFIC_WINDOW = 60;
+ // Data traffic limit in bytes
+ private final long TRAFFIC_LIMIT = 64 * 1024;
- connectState network= connectState.DISCONNECTED;
- connectState screen = connectState.SHOULDBECONNECTED;
+ connectState network= connectState.DISCONNECTED;
+ connectState screen = connectState.SHOULDBECONNECTED;
- private String lastStateMsg=null;
+ private String lastStateMsg=null;
- enum connectState {
- SHOULDBECONNECTED,
- PENDINGDISCONNECT,
- DISCONNECTED
- }
+ enum connectState {
+ SHOULDBECONNECTED,
+ PENDINGDISCONNECT,
+ DISCONNECTED
+ }
- static class Datapoint {
- private Datapoint(long t, long d)
- {
- timestamp = t;
- data = d;
- }
+ static class Datapoint {
+ private Datapoint(long t, long d)
+ {
+ timestamp = t;
+ data = d;
+ }
- long timestamp;
- long data;
- }
+ long timestamp;
+ long data;
+ }
- LinkedList<Datapoint> trafficdata = new LinkedList<DeviceStateReceiver.Datapoint>();
+ LinkedList<Datapoint> trafficdata = new LinkedList<DeviceStateReceiver.Datapoint>();
- @Override
- public void updateByteCount(long in, long out, long diffin, long diffout) {
- Log.i("OpenVPN", String.format("State: %s %s",network.name(), screen.name()));
+ @Override
+ public void updateByteCount(long in, long out, long diffin, long diffout) {
+ Log.i("OpenVPN", String.format("State: %s %s",network.name(), screen.name()));
- if (screen!=connectState.PENDINGDISCONNECT)
- return;
+ if (screen!=connectState.PENDINGDISCONNECT)
+ return;
- long total = diffin + diffout;
- trafficdata.add(new Datapoint(System.currentTimeMillis(),total));
+ long total = diffin + diffout;
+ trafficdata.add(new Datapoint(System.currentTimeMillis(),total));
- while(trafficdata.getFirst().timestamp <= (System.currentTimeMillis() - TRAFFIC_WINDOW*1000)) {
- trafficdata.removeFirst();
- }
+ while(trafficdata.getFirst().timestamp <= (System.currentTimeMillis() - TRAFFIC_WINDOW*1000)) {
+ trafficdata.removeFirst();
+ }
- long windowtraffic = 0;
- for (Datapoint dp: trafficdata)
- windowtraffic += dp.data;
+ long windowtraffic = 0;
+ for (Datapoint dp: trafficdata)
+ windowtraffic += dp.data;
if(windowtraffic < TRAFFIC_LIMIT) {
screen = connectState.DISCONNECTED;
@@ -73,23 +73,19 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
mManangement.pause();
}
- Log.i("OpenVPN", String.format("State: %s %s total %d last %d time %d",network.name(), screen.name(),windowtraffic/1024,
- total,
- System.currentTimeMillis()/1024));
-
- }
+ }
- public DeviceStateReceiver(OpenVPNMangement magnagement) {
- super();
- mManangement = magnagement;
- }
+ public DeviceStateReceiver(OpenVPNMangement magnagement) {
+ super();
+ mManangement = magnagement;
+ }
- @Override
- public void onReceive(Context context, Intent intent) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if(ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
@@ -97,46 +93,47 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
} else if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
boolean screenoff = prefs.getBoolean("screenoff", false);
- if(screenoff)
+ if(screenoff) {
if(!ProfileManager.getLastConnectedVpn().mPersistTun)
OpenVPN.logError(R.string.screen_nopersistenttun);
- screen = connectState.PENDINGDISCONNECT;
- fillTrafficData();
- if (network == connectState.DISCONNECTED)
- screen = connectState.DISCONNECTED;
+ screen = connectState.PENDINGDISCONNECT;
+ fillTrafficData();
+ if (network == connectState.DISCONNECTED)
+ screen = connectState.DISCONNECTED;
+ }
} else if (Intent.ACTION_SCREEN_ON.equals(intent.getAction())) {
- // Network was disabled because screen off
- if (screen == connectState.DISCONNECTED && network == connectState.SHOULDBECONNECTED) {
- mManangement.resume();
+ // Network was disabled because screen off
+ if (screen == connectState.DISCONNECTED && network == connectState.SHOULDBECONNECTED) {
+ mManangement.resume();
- }
- screen = connectState.SHOULDBECONNECTED;
+ }
+ screen = connectState.SHOULDBECONNECTED;
- }
- }
+ }
+ }
- private void fillTrafficData() {
- trafficdata.add(new Datapoint(System.currentTimeMillis(), TRAFFIC_LIMIT));
- }
+ private void fillTrafficData() {
+ trafficdata.add(new Datapoint(System.currentTimeMillis(), TRAFFIC_LIMIT));
+ }
- public void networkStateChange(Context context) {
- NetworkInfo networkInfo = getCurrentNetworkInfo(context);
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- boolean sendusr1 = prefs.getBoolean("netchangereconnect", true);
+ public void networkStateChange(Context context) {
+ NetworkInfo networkInfo = getCurrentNetworkInfo(context);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ boolean sendusr1 = prefs.getBoolean("netchangereconnect", true);
- String netstatestring;
- if(networkInfo==null) {
- netstatestring = "not connected";
+ String netstatestring;
+ if(networkInfo==null) {
+ netstatestring = "not connected";
} else {
- String subtype = networkInfo.getSubtypeName();
- if(subtype==null)
- subtype = "";
- String extrainfo = networkInfo.getExtraInfo();
- if(extrainfo==null)
- extrainfo="";
+ String subtype = networkInfo.getSubtypeName();
+ if(subtype==null)
+ subtype = "";
+ String extrainfo = networkInfo.getExtraInfo();
+ if(extrainfo==null)
+ extrainfo="";
/*
if(networkInfo.getType()==android.net.ConnectivityManager.TYPE_WIFI) {
@@ -149,53 +146,53 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
- netstatestring = String.format("%2$s %4$s to %1$s %3$s",networkInfo.getTypeName(),
- networkInfo.getDetailedState(),extrainfo,subtype );
- }
+ netstatestring = String.format("%2$s %4$s to %1$s %3$s",networkInfo.getTypeName(),
+ networkInfo.getDetailedState(),extrainfo,subtype );
+ }
- if(networkInfo!=null && networkInfo.getState() == State.CONNECTED) {
- int newnet = networkInfo.getType();
- network = connectState.SHOULDBECONNECTED;
-
- if(sendusr1 && lastNetwork!=newnet) {
- if (screen == connectState.PENDINGDISCONNECT)
- screen = connectState.DISCONNECTED;
-
- if (lastNetwork==-1){
- if (screen == connectState.SHOULDBECONNECTED)
- mManangement.resume();
- }else{
- if (screen == connectState.SHOULDBECONNECTED)
- mManangement.reconnect();
- }
-
-
- lastNetwork = newnet;
- }
- } else if (networkInfo==null) {
- // Not connected, stop openvpn, set last connected network to no network
- lastNetwork=-1;
- if(sendusr1) {
- mManangement.pause();
- network = connectState.DISCONNECTED;
-
- // Set screen state to be disconnected if it want to disconnect
- if (screen == connectState.PENDINGDISCONNECT)
- screen = connectState.DISCONNECTED;
- }
- }
+ if(networkInfo!=null && networkInfo.getState() == State.CONNECTED) {
+ int newnet = networkInfo.getType();
+ network = connectState.SHOULDBECONNECTED;
+
+ if(sendusr1 && lastNetwork!=newnet) {
+ if (screen == connectState.PENDINGDISCONNECT)
+ screen = connectState.DISCONNECTED;
+
+ if (lastNetwork==-1){
+ if (screen == connectState.SHOULDBECONNECTED)
+ mManangement.resume();
+ }else{
+ if (screen == connectState.SHOULDBECONNECTED)
+ mManangement.reconnect();
+ }
+
+
+ lastNetwork = newnet;
+ }
+ } else if (networkInfo==null) {
+ // Not connected, stop openvpn, set last connected network to no network
+ lastNetwork=-1;
+ if(sendusr1) {
+ mManangement.pause();
+ network = connectState.DISCONNECTED;
+
+ // Set screen state to be disconnected if it want to disconnect
+ if (screen == connectState.PENDINGDISCONNECT)
+ screen = connectState.DISCONNECTED;
+ }
+ }
- if(!netstatestring.equals(lastStateMsg))
- OpenVPN.logInfo(R.string.netstatus, netstatestring);
- lastStateMsg=netstatestring;
+ if(!netstatestring.equals(lastStateMsg))
+ OpenVPN.logInfo(R.string.netstatus, netstatestring);
+ lastStateMsg=netstatestring;
- }
+ }
- private NetworkInfo getCurrentNetworkInfo(Context context) {
- ConnectivityManager conn = (ConnectivityManager)
- context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ private NetworkInfo getCurrentNetworkInfo(Context context) {
+ ConnectivityManager conn = (ConnectivityManager)
+ context.getSystemService(Context.CONNECTIVITY_SERVICE);
return conn.getActiveNetworkInfo();
- }
+ }
}
diff --git a/src/de/blinkt/openvpn/core/OpenVPNThread.java b/src/de/blinkt/openvpn/core/OpenVPNThread.java
index 24d65b55..2cfde13d 100644
--- a/src/de/blinkt/openvpn/core/OpenVPNThread.java
+++ b/src/de/blinkt/openvpn/core/OpenVPNThread.java
@@ -1,11 +1,12 @@
package de.blinkt.openvpn.core;
-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 android.util.Log;
+import de.blinkt.openvpn.R;
+import de.blinkt.openvpn.VpnProfile;
+import de.blinkt.openvpn.core.OpenVPN.ConnectionStatus;
+import de.blinkt.openvpn.core.OpenVPN.LogItem;
+
+import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
@@ -13,12 +14,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
-import android.util.Log;
-import de.blinkt.openvpn.R;
-import de.blinkt.openvpn.VpnProfile;
-import de.blinkt.openvpn.core.OpenVPN.ConnectionStatus;
-import de.blinkt.openvpn.core.OpenVPN.LogItem;
-
public class OpenVPNThread implements Runnable {
private static final String DUMP_PATH_STRING = "Dump path: ";
private static final String TAG = "OpenVPN";
@@ -34,7 +29,7 @@ public class OpenVPNThread implements Runnable {
mArgv = argv;
mNativeDir = nativelibdir;
mService = service;
- mProcessEnv = processEnv;
+ mProcessEnv = processEnv;
}
public void stopProcess() {
@@ -86,7 +81,7 @@ public class OpenVPNThread implements Runnable {
}
}
- private void startOpenVPNThreadArgs(String[] argv,Map<String, String> env) {
+ private void startOpenVPNThreadArgs(String[] argv, Map<String, String> env) {
LinkedList<String> argvlist = new LinkedList<String>();
for(String arg:argv)
diff --git a/src/de/blinkt/openvpn/core/OpenVpnService.java b/src/de/blinkt/openvpn/core/OpenVpnService.java
index c3ac0629..6563fa0f 100644
--- a/src/de/blinkt/openvpn/core/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/core/OpenVpnService.java
@@ -1,13 +1,5 @@
package de.blinkt.openvpn.core;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Vector;
-
import android.Manifest.permission;
import android.annotation.TargetApi;
import android.app.Notification;
@@ -17,19 +9,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.net.ConnectivityManager;
-import android.net.LocalServerSocket;
-import android.net.LocalSocket;
-import android.net.LocalSocketAddress;
-import android.net.VpnService;
-import android.os.Binder;
-import android.os.Build;
+import android.net.*;
+import android.os.*;
import android.os.Handler.Callback;
-import android.os.IBinder;
-import android.os.Message;
-import android.os.ParcelFileDescriptor;
import android.preference.PreferenceManager;
import de.blinkt.openvpn.LogWindow;
import de.blinkt.openvpn.R;
@@ -38,6 +20,13 @@ import de.blinkt.openvpn.core.OpenVPN.ByteCountListener;
import de.blinkt.openvpn.core.OpenVPN.ConnectionStatus;
import de.blinkt.openvpn.core.OpenVPN.StateListener;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Vector;
+
public class OpenVpnService extends VpnService implements StateListener, Callback, ByteCountListener {
public static final String START_SERVICE = "de.blinkt.openvpn.START_SERVICE";
public static final String START_SERVICE_STICKY = "de.blinkt.openvpn.START_SERVICE_STICKY";
@@ -46,14 +35,14 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
private Thread mProcessThread=null;
- private Vector<String> mDnslist=new Vector<String>();
+ private final Vector<String> mDnslist=new Vector<String>();
private VpnProfile mProfile;
private String mDomain=null;
- private Vector<CIDRIP> mRoutes=new Vector<CIDRIP>();
- private Vector<String> mRoutesv6=new Vector<String>();
+ private final Vector<CIDRIP> mRoutes=new Vector<CIDRIP>();
+ private final Vector<String> mRoutesv6=new Vector<String>();
private CIDRIP mLocalIP=null;
@@ -331,18 +320,10 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
mManagement = mOpenVPN3;
- } else {
- HashMap<String, String> env = new HashMap<String, String>();
- String version="unknown";
- try {
- PackageInfo packageinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
- version = packageinfo.versionName;
- } catch (NameNotFoundException e) {
- }
- env.put("UV_ICSOPENVPN_VERSION", version);
- env.put("UV_ICSOPENVPN_PKG", getPackageName());
- processThread = new OpenVPNThread(this, argv, env, nativelibdir);
- }
+ } else {
+ HashMap<String, String> env = new HashMap<String, String>();
+ processThread = new OpenVPNThread(this, argv, env, nativelibdir);
+ }
mProcessThread = new Thread(processThread, "OpenVPNProcessThread");
mProcessThread.start();
@@ -458,8 +439,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
builder.setConfigureIntent(getLogPendingIntent());
try {
- ParcelFileDescriptor pfd = builder.establish();
- return pfd;
+ return builder.establish();
} catch (Exception e) {
OpenVPN.logMessage(0, "", getString(R.string.tun_open_error));
OpenVPN.logMessage(0, "", getString(R.string.error) + e.getLocalizedMessage());