summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/blinkt/openvpn')
-rw-r--r--src/de/blinkt/openvpn/LaunchVPN.java5
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java7
-rw-r--r--src/de/blinkt/openvpn/OpenVPN.java141
-rw-r--r--src/de/blinkt/openvpn/OpenVPNThread.java2
-rw-r--r--src/de/blinkt/openvpn/OpenVpnManagementThread.java14
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java73
6 files changed, 167 insertions, 75 deletions
diff --git a/src/de/blinkt/openvpn/LaunchVPN.java b/src/de/blinkt/openvpn/LaunchVPN.java
index d74834ca..2e25f7a2 100644
--- a/src/de/blinkt/openvpn/LaunchVPN.java
+++ b/src/de/blinkt/openvpn/LaunchVPN.java
@@ -29,6 +29,8 @@ import android.content.Intent;
import android.net.VpnService;
import android.os.Bundle;
import android.os.Parcelable;
+import android.text.InputType;
+import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
@@ -207,7 +209,8 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
final EditText entry = new EditText(this);
entry.setSingleLine();
- entry.setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
+ entry.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+ entry.setTransformationMethod(new PasswordTransformationMethod());
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("Need " + type);
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index 001dbf1f..65e8c66c 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -23,6 +23,8 @@ import android.widget.TextView;
import de.blinkt.openvpn.OpenVPN.LogListener;
public class LogWindow extends ListActivity {
+ private String[] mBconfig=null;
+
class LogWindowListAdapter implements ListAdapter,LogListener, Callback {
@@ -36,6 +38,7 @@ public class LogWindow extends ListActivity {
private Vector<DataSetObserver> observers=new Vector<DataSetObserver>();
+
public LogWindowListAdapter() {
initLogBuffer();
@@ -159,7 +162,6 @@ public class LogWindow extends ListActivity {
OpenVPN.logMessage(0,"","Log cleared.");
mHandler.sendEmptyMessage(MESSAGE_CLEARLOG);
}
-
}
@@ -185,6 +187,9 @@ public class LogWindow extends ListActivity {
builder.setNegativeButton(android.R.string.no, null);
builder.show();
return true;
+ } else if(item.getItemId()==R.id.info) {
+ if(mBconfig==null)
+ OpenVPN.triggerLogBuilderConfig();
}
return super.onOptionsItemSelected(item);
diff --git a/src/de/blinkt/openvpn/OpenVPN.java b/src/de/blinkt/openvpn/OpenVPN.java
index daa29717..a5f60daf 100644
--- a/src/de/blinkt/openvpn/OpenVPN.java
+++ b/src/de/blinkt/openvpn/OpenVPN.java
@@ -10,77 +10,79 @@ public class OpenVPN {
private static final int MAXLOGENTRIES = 500;
public static native int startOpenVPNThread();
public static native int startOpenVPNThreadArgs(String argv[]);
- private static final String TAG = "OpenVpn";
+ private static final String TAG = "OpenVpn";
+
-
public static LinkedList<String> logbuffer = new LinkedList<String>();
private static int counter=0;
private static Vector<LogListener> logListener=new Vector<OpenVPN.LogListener>();
-
+ private static String[] mBconfig=null;
+
public interface LogListener {
void newLog(String logmessage);
}
- static {
- System.loadLibrary("crypto");
- System.loadLibrary("ssl");
- System.loadLibrary("lzo");
- System.loadLibrary("openvpn");
- }
-
- static void addRoute(String dest,String mask, String gw) {
- Log.i("openvpn" ,"Got Routing information " + dest + " " + mask + " " + gw );
- mOpenVpnService.addRoute(dest,mask);
- }
-
- synchronized static void logMessage(int level,String prefix, String message)
- {
- logbuffer.addLast(prefix + " " + message);
- if(logbuffer.size()>MAXLOGENTRIES)
- logbuffer.removeFirst();
-
- // The garbage collector does not collect the String from native
- // but kills me for logging 100 messages with too many references :(
- // Force GC how and then to kill loose ends
- if(counter++ % 50==0)
- System.gc();
-
- for (LogListener ll : logListener) {
+ static {
+ System.loadLibrary("crypto");
+ System.loadLibrary("ssl");
+ System.loadLibrary("lzo");
+ System.loadLibrary("openvpn");
+ }
+
+ static void addRoute(String dest,String mask, String gw) {
+ Log.i("openvpn" ,"Got Routing information " + dest + " " + mask + " " + gw );
+ mOpenVpnService.addRoute(dest,mask);
+ }
+
+ synchronized static void logMessage(int level,String prefix, String message)
+ {
+ logbuffer.addLast(prefix + " " + message);
+ if(logbuffer.size()>MAXLOGENTRIES)
+ logbuffer.removeFirst();
+
+ // The garbage collector does not collect the String from native
+ // but kills me for logging 100 messages with too many references :(
+ // Force GC how and then to kill loose ends
+ if(counter++ % 50==0) {
+ System.gc();
+ }
+
+ for (LogListener ll : logListener) {
ll.newLog(prefix + " " + message);
}
-
- }
-
- synchronized static void clearLog() {
- logbuffer.clear();
- }
-
- synchronized static void addLogListener(LogListener ll){
- logListener.add(ll);
- }
-
- synchronized static void removeLogListener(LogListener ll) {
- logListener.remove(ll);
- }
-
-
- static void addInterfaceInfo(int mtu, String local, String netmask)
- {
- Log.i("openvpn","Got interface info M" + mtu + " L: " + local + "NM: " + netmask);
- mOpenVpnService.setLocalIP(local,netmask);
- }
-
- static void addDns(String dns) {
- Log.i("openvpn","Got DNS Server: " + dns);
- mOpenVpnService.addDNS(dns);
- }
-
-
- static void addDomain(String domain) {
- Log.i("openvpn","Got DNS Domain: " + domain);
- mOpenVpnService.setDomain(domain);
- }
+
+ }
+
+ synchronized static void clearLog() {
+ logbuffer.clear();
+ }
+
+ synchronized static void addLogListener(LogListener ll){
+ logListener.add(ll);
+ }
+
+ synchronized static void removeLogListener(LogListener ll) {
+ logListener.remove(ll);
+ }
+
+
+ static void addInterfaceInfo(int mtu, String local, String netmask)
+ {
+ Log.i("openvpn","Got interface info M" + mtu + " L: " + local + "NM: " + netmask);
+ mOpenVpnService.setLocalIP(local,netmask);
+ }
+
+ static void addDns(String dns) {
+ Log.i("openvpn","Got DNS Server: " + dns);
+ mOpenVpnService.addDNS(dns);
+ }
+
+
+ static void addDomain(String domain) {
+ Log.i("openvpn","Got DNS Domain: " + domain);
+ mOpenVpnService.setDomain(domain);
+ }
public static void setCallback(OpenVpnService openVpnService) {
@@ -96,19 +98,32 @@ public class OpenVPN {
Log.e("openvpn","Error protecting socket "+ sockfd);
return p;
}
-
+
public static int openTunDevice() {
Log.d(TAG,"Opening tun device");
return mOpenVpnService.openTun();
}
//! Dummy method being called to force loading of JNI Libraries
public static void foo() { }
-
+
synchronized public static String[] getlogbuffer() {
-
+
// The stoned way of java to return an array from a vector
// brought to you by eclipse auto complete
return (String[]) logbuffer.toArray(new String[logbuffer.size()]);
}
+ public static void logBuilderConfig(String[] bconfig) {
+ mBconfig =bconfig;
+ }
+ public static void triggerLogBuilderConfig() {
+ if(mBconfig==null) {
+ logMessage(0, "", "No active interface");
+ } else {
+ for (String item : mBconfig) {
+ logMessage(0, "", item);
+ }
+ }
+
+ }
}
diff --git a/src/de/blinkt/openvpn/OpenVPNThread.java b/src/de/blinkt/openvpn/OpenVPNThread.java
index 124179e5..a5b3e5e4 100644
--- a/src/de/blinkt/openvpn/OpenVPNThread.java
+++ b/src/de/blinkt/openvpn/OpenVPNThread.java
@@ -55,6 +55,8 @@ public class OpenVPNThread implements Runnable {
mService.getHandler().sendEmptyMessage(R.string.disconnected);
+ // Not a good place to do it, but will do
+ OpenVPN.logBuilderConfig(null);
Log.i(TAG, "Exiting");
}
}
diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
index f05f58dc..2421b28c 100644
--- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java
+++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
@@ -105,13 +105,14 @@ private static Vector<OpenVpnManagementThread> active=new Vector<OpenVpnManageme
else if (cmd.equals("PASSWORD")) {
processPWCommand(argument);
} else if (cmd.equals("HOLD")) {
- managmentCommand("hold release\n");
+ managmentCommand("hold release\nlog on\n");
} else if (cmd.equals("PROTECT-FD")) {
protectFD(argument);
}
+ Log.i(TAG, "Got unrecognized command" + command);
+ } else {
+ Log.i(TAG, "Got unrecognized line from managment" + command);
}
- Log.i(TAG, "Got unrecognized command" + command);
-
}
@@ -158,10 +159,13 @@ private static Vector<OpenVpnManagementThread> active=new Vector<OpenVpnManageme
}
- public static void stopOpenVPN() {
+ public static boolean stopOpenVPN() {
+ boolean sendCMD=false;
for (OpenVpnManagementThread mt: active){
mt.managmentCommand("signal SIGINT\n");
- }
+ sendCMD=true;
+ }
+ return sendCMD;
}
}
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java
index 076fe7b5..b4ae411a 100644
--- a/src/de/blinkt/openvpn/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/OpenVpnService.java
@@ -17,8 +17,11 @@
package de.blinkt.openvpn;
import java.io.IOException;
+import java.lang.reflect.Array;
import java.util.Vector;
+import de.blinkt.openvpn.OpenVpnService.CIDRIP;
+
import android.app.PendingIntent;
import android.content.Intent;
import android.net.LocalSocket;
@@ -83,11 +86,30 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
public String toString() {
return String.format("%s/%d",mIp,len);
}
+
+ public boolean normalise(){
+ long ip=0;
+
+ String[] ipt = mIp.split("\\.");
+
+ ip += Long.parseLong(ipt[0])<< 24;
+ ip += Integer.parseInt(ipt[1])<< 16;
+ ip += Integer.parseInt(ipt[2])<< 8;
+ ip += Integer.parseInt(ipt[3]);
+
+ long newip = ip & (0xffffffffl << (32 -len));
+ if (newip != ip){
+ mIp = String.format("%d.%d.%d.%d", (newip & 0xff000000) >> 24,(newip & 0xff0000) >> 16, (newip & 0xff00) >> 8 ,newip & 0xff);
+ return true;
+ } else {
+ return false;
+ }
+ }
}
@Override
public void onRevoke() {
- mSocketManager.managmentCommand("signal SIGINT\n");
+ OpenVpnManagementThread.stopOpenVPN();
mServiceThread=null;
stopSelf();
};
@@ -128,8 +150,12 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
}
// Stop the previous session by interrupting the thread.
- if (mSocketManager != null) {
- mSocketManager.managmentCommand("signal SIGINT\n");
+ if(OpenVpnManagementThread.stopOpenVPN()){
+ // an old was asked to exit, wait 2s
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ }
}
if (mServiceThread!=null) {
@@ -210,13 +236,25 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
if(mDomain!=null)
builder.addSearchDomain(mDomain);
-
+ String bconfig[] = new String[5];
+
+ bconfig[0]= getString(R.string.last_openvpn_tun_config);
+ bconfig[1] = String.format(getString(R.string.local_ip_info,mLocalIP.mIp,mLocalIP.len));
+ bconfig[2] = String.format(getString(R.string.dns_server_info, joinString(mDnslist)));
+ bconfig[3] = String.format(getString(R.string.dns_domain_info, mDomain));
+ bconfig[4] = String.format(getString(R.string.routes_info, joinString(mRoutes)));
+
+
+ OpenVPN.logBuilderConfig(bconfig);
+
mDnslist.clear();
mRoutes.clear();
builder.setSession(mProfile.mName + " - " + mLocalIP);
+
+
// Let the configure Button show the Log
Intent intent = new Intent(getBaseContext(),LogWindow.class);
PendingIntent startLW = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
@@ -233,6 +271,23 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
}
+
+ // Ugly, but java has no such method
+ private <T> String joinString(Vector<T> vec) {
+ String ret = "";
+ if(vec.size() > 0);
+ ret = vec.get(0).toString();
+ for(int i=1;i < vec.size();i++) {
+ ret = ret + ", " + vec.get(i).toString();
+ }
+ return ret;
+ }
+
+
+
+
+
+
public void addDNS(String dns) {
mDnslist.add(dns);
}
@@ -246,7 +301,15 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
public void addRoute(String dest, String mask) {
- mRoutes.add(new CIDRIP(dest, mask));
+ CIDRIP route = new CIDRIP(dest, mask);
+ if(route.len == 32 && !mask.equals("255.255.255.255")) {
+ OpenVPN.logMessage(0, "", String.format(getString(R.string.route_not_cidr,dest,mask)));
+ }
+
+ if(route.normalise())
+ OpenVPN.logMessage(0, "", String.format(getString(R.string.route_not_netip,dest,route.len,route.mIp)));
+
+ mRoutes.add(route);
}