summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--openvpn/src/openvpn/jniglue.c17
-rw-r--r--openvpn/src/openvpn/jniglue.h3
-rw-r--r--openvpn/src/openvpn/route.c9
-rw-r--r--openvpn/src/openvpn/socket.c2
-rw-r--r--openvpn/src/openvpn/tun.c29
-rw-r--r--res/values/strings.xml5
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java26
-rw-r--r--src/de/blinkt/openvpn/OpenVPN.java16
-rw-r--r--src/de/blinkt/openvpn/OpenVpnManagementThread.java46
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java11
10 files changed, 95 insertions, 69 deletions
diff --git a/openvpn/src/openvpn/jniglue.c b/openvpn/src/openvpn/jniglue.c
index d49fe353..e11cabd4 100644
--- a/openvpn/src/openvpn/jniglue.c
+++ b/openvpn/src/openvpn/jniglue.c
@@ -23,14 +23,6 @@ void android_openvpn_exit(int status) {
}
-void testmsg(char* m1, ...) {
- va_list arglist;
- va_start(arglist,m1);
- // vsnprintf(m1, 100, "foo bbaz",arglist);
- __android_log_vprint(ANDROID_LOG_DEBUG, "openvpn",m1, arglist);
- va_end(arglist);
-}
-
// Store env and class, we allow only one instance
// so make these variables global for now
jclass openvpnclass;
@@ -137,15 +129,6 @@ int android_open_tun () {
}
-void android_set_dns(const char* dns) {
- jmethodID aMethodID = (*openvpnjenv)->GetStaticMethodID(openvpnjenv, openvpnclass, "addDns",
- "(Ljava/lang/String;)V");
- jstring jdns = (*openvpnjenv)->NewStringUTF(openvpnjenv,dns);
- (*openvpnjenv)->CallStaticVoidMethod(openvpnjenv,openvpnclass,aMethodID,jdns);
-
-
-}
-
void addRouteInformation(const char* dest, const char* mask, const char* gw) {
jstring jmask = (*openvpnjenv)->NewStringUTF(openvpnjenv, mask);
diff --git a/openvpn/src/openvpn/jniglue.h b/openvpn/src/openvpn/jniglue.h
index ea60a718..236c0323 100644
--- a/openvpn/src/openvpn/jniglue.h
+++ b/openvpn/src/openvpn/jniglue.h
@@ -9,10 +9,7 @@
#ifndef xcopenvpn_jniglue_h
#define xcopenvpn_jniglue_h
-void testmsg(char* m1, ...);
-void addRouteInformation(const char* dest, const char* mask, const char* gw);
void addInterfaceInformation(int mtu,const char* ifconfig_local, const char* ifconfig_remote);
void android_openvpn_log(int level,const char* prefix,const char* prefix_sep,const char* m1);
void android_openvpn_exit(int status);
-void android_set_dns(const char* dns);
#endif
diff --git a/openvpn/src/openvpn/route.c b/openvpn/src/openvpn/route.c
index 6c3ad904..a73bbc4c 100644
--- a/openvpn/src/openvpn/route.c
+++ b/openvpn/src/openvpn/route.c
@@ -1347,7 +1347,14 @@ add_route (struct route *r,
#elif defined (TARGET_ANDROID)
#include "jniglue.h"
- addRouteInformation(network, netmask, gateway);
+ struct user_pass up;
+ struct buffer out = alloc_buf_gc (64, &gc);
+
+ buf_printf (&out, "%s %s", network, netmask);
+
+ strcpy(up.username, buf_bptr(&out));
+ management_query_user_pass(management, &up , "ROUTE", GET_USER_PASS_NEED_OK,(void*) 0);
+
#elif defined (WIN32)
{
diff --git a/openvpn/src/openvpn/socket.c b/openvpn/src/openvpn/socket.c
index 524343b5..756627fe 100644
--- a/openvpn/src/openvpn/socket.c
+++ b/openvpn/src/openvpn/socket.c
@@ -380,7 +380,7 @@ getaddr6 (unsigned int flags,
/*
* Resolve hostname
- */
+ */
while (true)
{
/* try hostname lookup */
diff --git a/openvpn/src/openvpn/tun.c b/openvpn/src/openvpn/tun.c
index 844d596e..66a09ea0 100644
--- a/openvpn/src/openvpn/tun.c
+++ b/openvpn/src/openvpn/tun.c
@@ -46,8 +46,8 @@
#include "manage.h"
#include "route.h"
#include "win32.h"
-
#include "memdbg.h"
+#include <string.h>
#ifdef TARGET_ANDROID
#include "jniglue.h"
@@ -774,7 +774,16 @@ do_ifconfig (struct tuntap *tt,
#endif /*ENABLE_IPROUTE*/
#elif defined(TARGET_ANDROID)
- addInterfaceInformation(tun_mtu,ifconfig_local, ifconfig_remote_netmask);
+
+ struct user_pass up;
+ struct buffer out = alloc_buf_gc (64, &gc);
+
+ buf_printf (&out, "%s %s %d", ifconfig_local, ifconfig_remote_netmask, tun_mtu);
+
+ strcpy(up.username, buf_bptr(&out));
+ management_query_user_pass(management, &up , "IFCONFIG", GET_USER_PASS_NEED_OK,(void*) 0);
+
+
#elif defined(TARGET_SOLARIS)
/* Solaris 2.6 (and 7?) cannot set all parameters in one go...
@@ -1378,20 +1387,24 @@ close_tun_generic (struct tuntap *tt)
void
open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
{
- struct gc_arena gc = gc_new ();
int i;
+ struct user_pass up;
+ struct gc_arena gc = gc_new ();
+
for (i = 0; i < tt->options.dns_len; ++i) {
- android_set_dns(print_in_addr_t(tt->options.dns[i], 0, &gc));
+ strcpy(up.username, print_in_addr_t(tt->options.dns[i], 0, &gc));
+ management_query_user_pass(management, &up , "DNSSERVER", GET_USER_PASS_NEED_OK,(void*) 0);
}
-
-
- if(tt->options.domain)
+ if(tt->options.domain) {
+ strcpy(up.username , tt->options.domain);
management_query_user_pass(management, &up , "DNSDOMAIN", GET_USER_PASS_NEED_OK,(void*) 0);
-
+ }
+
if((tt->fd = android_open_tun())< 0){
msg (M_ERR, "ERROR: Cannot open TUN");
}
+ gc_free (&gc);
}
#else
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b6411a8e..81ca4313 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -159,7 +159,7 @@
<string name="info">info</string>
<string name="show_connection_details">Show connection details</string>
<string name="last_openvpn_tun_config">Last interface configuration from Openvpn:</string>
- <string name="local_ip_info">Local IP: %1$s/%2$d</string>
+ <string name="local_ip_info">Local IP: %1$s/%2$d MTU: %3$d</string>
<string name="dns_server_info">DNS Server: %s</string>
<string name="dns_domain_info">DNS Domain: %s</string>
<string name="routes_info">Routes: %s</string>
@@ -171,5 +171,6 @@
<string name="could_not_write_log">Could not write log contents to file</string>
<string name="send_logfile">Send Logfile</string>
<string name="send">Send</string>
- <string name="ics_openvpn_log_file">ICS Openvpn log file</string>
+ <string name="ics_openvpn_log_file">ICS Openvpn log file</string>
+ <string name="copied_entry">Copied log entry to clip board</string>
</resources>
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index f3809e27..3455e385 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -1,19 +1,17 @@
package de.blinkt.openvpn;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.charset.Charset;
import java.util.Vector;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ListActivity;
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
import android.content.DialogInterface;
-import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
import android.database.DataSetObserver;
-import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
@@ -23,6 +21,8 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
@@ -235,6 +235,20 @@ public class LogWindow extends ListActivity {
super.onCreate(savedInstanceState);
ListView lv = getListView();
+
+ lv.setOnItemLongClickListener(new OnItemLongClickListener() {
+
+ @Override
+ public boolean onItemLongClick(AdapterView<?> parent, View view,
+ int position, long id) {
+ ClipboardManager clipboard = (ClipboardManager)
+ getSystemService(Context.CLIPBOARD_SERVICE);
+ ClipData clip = ClipData.newPlainText("Log Entry",((TextView) view).getText());
+ clipboard.setPrimaryClip(clip);
+ Toast.makeText(getBaseContext(), R.string.copied_entry, Toast.LENGTH_SHORT).show();
+ return true;
+ }
+ });
//lv.setTextFilterEnabled(true);
ladapter = new LogWindowListAdapter();
lv.setAdapter(ladapter);
diff --git a/src/de/blinkt/openvpn/OpenVPN.java b/src/de/blinkt/openvpn/OpenVPN.java
index 8dad6af9..cc827aae 100644
--- a/src/de/blinkt/openvpn/OpenVPN.java
+++ b/src/de/blinkt/openvpn/OpenVPN.java
@@ -67,22 +67,6 @@ public class OpenVPN {
}
- 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) {
diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
index 4162d315..450cd530 100644
--- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java
+++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
@@ -5,9 +5,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.net.DatagramSocket;
import java.util.LinkedList;
-import java.util.List;
import java.util.Vector;
import android.net.LocalSocket;
@@ -146,7 +144,7 @@ public class OpenVpnManagementThread implements Runnable {
} else if (cmd.equals("HOLD")) {
managmentCommand("hold release\n");
} else if (cmd.equals("NEED-OK")) {
- processPWCommand(argument);
+ processNeedCommand(argument);
} else {
Log.i(TAG, "Got unrecognized command" + command);
}
@@ -154,6 +152,37 @@ public class OpenVpnManagementThread implements Runnable {
Log.i(TAG, "Got unrecognized line from managment" + command);
}
}
+
+ private void processNeedCommand(String argument) {
+ int p1 =argument.indexOf('\'');
+ int p2 = argument.indexOf('\'',p1+1);
+
+ String needed = argument.substring(p1+1, p2);
+ String extra = argument.split(":",2)[1];
+
+ if (needed.equals("PROTECTFD")) {
+ FileDescriptor fdtoprotect = mFDList.pollFirst();
+ protectFileDescriptor(fdtoprotect);
+ } else if (needed.equals("DNSSERVER")) {
+ mOpenVPNService.addDNS(extra);
+ }else if (needed.equals("DNSDOMAIN")){
+ mOpenVPNService.setDomain(extra);
+ } else if (needed.equals("ROUTE")) {
+ String[] routeparts = extra.split(" ");
+ mOpenVPNService.addRoute(routeparts[0], routeparts[1]);
+ } else if (needed.equals("IFCONFIG")) {
+ String[] ifconfigparts = extra.split(" ");
+ int mtu = Integer.parseInt(ifconfigparts[0]);
+ mOpenVPNService.setLocalIP(ifconfigparts[0], ifconfigparts[1],mtu);
+
+ } else {
+ Log.e(TAG,"Unkown needok command " + argument);
+ return;
+ }
+
+ String cmd = String.format("needok '%s' %s\n", needed, "ok");
+ managmentCommand(cmd);
+ }
private void processPWCommand(String argument) {
//argument has the form Need 'Private Key' password
@@ -163,7 +192,7 @@ public class OpenVpnManagementThread implements Runnable {
String needed = argument.substring(p1+1, p2);
String pw=null;
- String response="password";
+
if(needed.equals("Private Key")) {
pw = mProfile.getPasswordPrivateKey();
@@ -172,14 +201,9 @@ public class OpenVpnManagementThread implements Runnable {
needed, VpnProfile.openVpnEscape(mProfile.mUsername));
managmentCommand(usercmd);
pw = mProfile.getPasswordAuth();
- } else if (needed.equals("PROTECTFD")) {
- FileDescriptor fdtoprotect = mFDList.pollFirst();
- protectFileDescriptor(fdtoprotect);
- pw = "ok";
- response="needok";
- }
+ }
if(pw!=null) {
- String cmd = String.format("%s '%s' %s\n",response, needed, VpnProfile.openVpnEscape(pw));
+ String cmd = String.format("password '%s' %s\n", needed, VpnProfile.openVpnEscape(pw));
managmentCommand(cmd);
}
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java
index e6e69ab6..5937f48e 100644
--- a/src/de/blinkt/openvpn/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/OpenVpnService.java
@@ -46,6 +46,7 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
private OpenVpnManagementThread mSocketManager;
private Thread mSocketManagerThread;
+ private int mMtu;
@@ -220,6 +221,8 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
for (String dns : mDnslist ) {
builder.addDnsServer(dns);
}
+
+ builder.setMtu(mMtu);
for (CIDRIP route:mRoutes) {
@@ -236,7 +239,7 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
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[1] = String.format(getString(R.string.local_ip_info,mLocalIP.mIp,mLocalIP.len,mMtu));
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)));
@@ -249,8 +252,6 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
builder.setSession(mProfile.mName + " - " + mLocalIP);
-
-
// Let the configure Button show the Log
Intent intent = new Intent(getBaseContext(),LogWindow.class);
@@ -310,8 +311,10 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
}
- public void setLocalIP(String local, String netmask) {
+ public void setLocalIP(String local, String netmask,int mtu) {
mLocalIP = new CIDRIP(local, netmask);
+ mMtu = mtu;
+
if(mLocalIP.len == 32 && !netmask.equals("255.255.255.255")) {
OpenVPN.logMessage(0, "", String.format(getString(R.string.ip_not_cidr, local,netmask)));
}