summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-05-20 14:36:00 +0200
committerArne Schwabe <arne@rfc2549.org>2012-05-20 14:36:00 +0200
commite3152fa86cda600c3d993f8ddb43273f95aaa9f0 (patch)
tree6f00e49697c6553c4f319c0133e0ba2bf9500f6a
parentbb987226c843375a93043bbd5f78a94e0edea29d (diff)
- Fix missing about
- Fix vpn list saving to sharedpreferences (closes issue #27) - Version 0.5.5a
-rw-r--r--res/values/strings.xml6
-rw-r--r--res/xml/main_headers.xml21
-rw-r--r--src/de/blinkt/openvpn/ConfigConverter.java16
-rw-r--r--src/de/blinkt/openvpn/OpenVPNThread.java14
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java97
-rw-r--r--src/de/blinkt/openvpn/ProfileManager.java16
-rw-r--r--todo.txt3
7 files changed, 95 insertions, 78 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0f1004a7..b6006103 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -210,7 +210,7 @@
<string name="import_done">Done reading config file.</string>
<string name="nobind_summary">Do not bind to local address and port</string>
<string name="no_bind">No local binding</string>
- <string name="import_experimental">Please not that the config importer is an experimental feature.</string>
+ <string name="import_experimental">Please not that the config importer is an experimental feature. If it does not work for you or you think that things could be done better please drop me a email.</string>
<string name="import_configuration_file">Import configuration file</string>
<string name="faq_security_title">Security considerations</string>
<string name="faq_security">"As openvpn is security sensitive a few notes about security are sensible. All data on the sdcard is inherently unsecure. Every app can read it (for example this program requires no special sd card rights). The data of this application can only be read by the application itself. By using the import option for cacert/cert/key in the file dialog the data is stored in the vpn profile. The vpn profiles are only accessable by this application. (Do not forget to delte the copies on the sdcard afterwards). Even though accessible only by this application the data is stil unecrypted. By rooting the telephone or other exploits it may be possible to retrieve the data. Saved passwords are stored in plain text as well. For pkcs12 files it is highly recommended that you import them into the android keystore."</string>
@@ -220,5 +220,7 @@
<string name="ipv4">IPv4</string>
<string name="ipv6">IPv6</string>
<string name="speed_waiting">Waiting for state messageā€¦</string>
- <string name="generalsettings">General Settings</string>
+ <string name="generalsettings">General Settings</string>
+ <string name="converted_profile">imported profile</string>
+ <string name="converted_profile_i">imported profile %d</string>
</resources>
diff --git a/res/xml/main_headers.xml b/res/xml/main_headers.xml
index 95bc6fe3..030b5488 100644
--- a/res/xml/main_headers.xml
+++ b/res/xml/main_headers.xml
@@ -5,16 +5,21 @@
android:fragment="de.blinkt.openvpn.VPNProfileList"
android:summary="@string/vpn_list_summary"
android:title="@string/vpn_list_title" />
-
- <header
+
+ <!--
+ <header
+
+ android:fragment="de.blinkt.openvpn.GeneralSettings"
+ android:title="@string/generalsettings" />
+ -->
+
+ <header
android:fragment="de.blinkt.openvpn.FaqFragment"
android:summary="@string/faq_summary"
android:title="@string/faq" />
-
-<!-- <header
- android:fragment="de.blinkt.openvpn.GeneralSettings"
- android:title="@string/generalsettings" /> -->
-
-
+ <header
+ android:fragment="de.blinkt.openvpn.AboutFragment"
+ android:summary="@string/about_summary"
+ android:title="@string/about" />
</preference-headers> \ No newline at end of file
diff --git a/src/de/blinkt/openvpn/ConfigConverter.java b/src/de/blinkt/openvpn/ConfigConverter.java
index 952ab968..8aebc664 100644
--- a/src/de/blinkt/openvpn/ConfigConverter.java
+++ b/src/de/blinkt/openvpn/ConfigConverter.java
@@ -41,8 +41,11 @@ public class ConfigConverter extends ListActivity {
log("Importing the config had error, cannot save it");
return true;
}
+
Intent result = new Intent();
ProfileManager vpl = ProfileManager.getInstance(this);
+
+ setUniqueProfileName(vpl);
vpl.addProfile(mResult);
vpl.saveProfile(this, mResult);
vpl.saveProfileList(this);
@@ -56,6 +59,19 @@ public class ConfigConverter extends ListActivity {
}
+
+ private void setUniqueProfileName(ProfileManager vpl) {
+ int i=1;
+ String newname = getString(R.string.converted_profile);
+
+ while(vpl.getProfileByName(newname)!=null) {
+ i++;
+ newname = getString(R.string.converted_profile_i,i);
+ }
+
+ mResult.mName=newname;
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
diff --git a/src/de/blinkt/openvpn/OpenVPNThread.java b/src/de/blinkt/openvpn/OpenVPNThread.java
index dcd5f4ec..503f4c4c 100644
--- a/src/de/blinkt/openvpn/OpenVPNThread.java
+++ b/src/de/blinkt/openvpn/OpenVPNThread.java
@@ -29,19 +29,7 @@ public class OpenVPNThread implements Runnable {
@Override
public void run() {
try {
- Log.i(TAG, "Starting openvpn");
-
- // We try to create the tunnel for several times. The better way
- // is to work with ConnectivityManager, such as trying only when
- // the network is avaiable. Here we just use a counter to keep
- // things simple.
- //for (int attempt = 0; attempt < 10; ++attempt) {
- mService.getHandler().sendEmptyMessage(R.string.connecting);
-
- // Log argv
-
- //OpenVPN.logMessage(0, "argv:" , Arrays.toString(mArgv));
-
+ Log.i(TAG, "Starting openvpn");
startOpenVPNThreadArgs(mArgv);
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java
index e2f7ba12..8aa39d89 100644
--- a/src/de/blinkt/openvpn/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/OpenVpnService.java
@@ -19,19 +19,17 @@ package de.blinkt.openvpn;
import java.io.IOException;
import java.util.Vector;
-
+import android.app.Notification;
+import android.app.NotificationManager;
import android.app.PendingIntent;
+import android.content.Context;
import android.content.Intent;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
import android.net.VpnService;
-import android.os.Handler;
-import android.os.Message;
import android.os.ParcelFileDescriptor;
-import android.widget.Toast;
-public class OpenVpnService extends VpnService implements Handler.Callback {
- Handler mHandler;
+public class OpenVpnService extends VpnService {
private Thread mServiceThread;
private Vector<String> mDnslist=new Vector<String>();
@@ -50,9 +48,10 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
private Thread mSocketManagerThread;
private int mMtu;
private String mLocalIPv6=null;
+ private Notification mNotification=null;
-
-
+ private static final int HELLO_ID = 1;
+
@Override
public void onRevoke() {
OpenVpnManagementThread.stopOpenVPN();
@@ -60,8 +59,36 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
stopSelf();
};
+ private void showNotification() {
+ String ns = Context.NOTIFICATION_SERVICE;
+ NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
+
+
+ int icon = R.drawable.icon;
+ CharSequence tickerText = "Hello";
+ long when = System.currentTimeMillis();
+
+ mNotification = new Notification(icon, tickerText, when);
+
+ Context context = getApplicationContext();
+ CharSequence contentTitle = "My notification";
+ CharSequence contentText = "Hello World!";
+ mNotification.setLatestEventInfo(context, contentTitle, contentText, getLogPendingIntent());
+
+ mNotificationManager.notify(HELLO_ID, mNotification);
+
+ }
+
+ PendingIntent getLogPendingIntent() {
+ // Let the configure Button show the Log
+ Intent intent = new Intent(getBaseContext(),LogWindow.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+ PendingIntent startLW = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
+ intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+ return startLW;
+ }
@@ -97,12 +124,8 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
String profileUUID = intent.getStringExtra(prefix + ".profileUUID");
mProfile = ProfileManager.get(profileUUID);
-
- // The handler is only used to show messages.
- if (mHandler == null) {
- mHandler = new Handler(this);
- }
-
+ //showNotification();
+
// Stop the previous session by interrupting the thread.
if(OpenVpnManagementThread.stopOpenVPN()){
// an old was asked to exit, wait 2s
@@ -132,10 +155,7 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
//checkForRemainingMiniVpns();
}
-
-
// Start a new session by creating a new thread.
-
OpenVPNThread serviceThread = new OpenVPNThread(this, argv,nativelibdir);
mServiceThread = new Thread(serviceThread, "OpenVPNServiceThread");
@@ -164,34 +184,25 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
}
}
- @Override
- public boolean handleMessage(Message message) {
- if (message != null) {
- Toast.makeText(this, message.what, Toast.LENGTH_SHORT).show();
- }
- return true;
- }
-
-
public ParcelFileDescriptor openTun() {
Builder builder = new Builder();
-
+
if(mLocalIP==null && mLocalIPv6==null) {
OpenVPN.logMessage(0, "", getString(R.string.opentun_no_ipaddr));
return null;
}
-
+
if(mLocalIP!=null) {
builder.addAddress(mLocalIP.mIp, mLocalIP.len);
}
-
+
if(mLocalIPv6!=null) {
String[] ipv6parts = mLocalIPv6.split("/");
builder.addAddress(ipv6parts[0],Integer.parseInt(ipv6parts[1]));
}
-
+
for (String dns : mDnslist ) {
builder.addDnsServer(dns);
@@ -216,7 +227,7 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
OpenVPN.logMessage(0, "", getString(R.string.route_rejected) + v6route + " " + ia.getLocalizedMessage());
}
}
-
+
if(mDomain!=null)
builder.addSearchDomain(mDomain);
@@ -245,13 +256,9 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
mRoutesv6.clear();
mLocalIP=null;
mLocalIPv6=null;
-
- // Let the configure Button show the Log
- Intent intent = new Intent(getBaseContext(),LogWindow.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
- PendingIntent startLW = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
- intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
- builder.setConfigureIntent(startLW);
+
+ builder.setConfigureIntent(getLogPendingIntent());
+
try {
ParcelFileDescriptor pfd = builder.establish();
return pfd;
@@ -305,7 +312,7 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
mRoutes.add(route);
}
-
+
public void addRoutev6(String extra) {
mRoutesv6.add(extra);
}
@@ -329,20 +336,8 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
}
}
-
-
-
-
-
-
-
public void setLocalIPv6(String ipv6addr) {
mLocalIPv6 = ipv6addr;
}
-
- public Handler getHandler() {
- return mHandler;
- }
-
}
diff --git a/src/de/blinkt/openvpn/ProfileManager.java b/src/de/blinkt/openvpn/ProfileManager.java
index d34bdbec..eb94505a 100644
--- a/src/de/blinkt/openvpn/ProfileManager.java
+++ b/src/de/blinkt/openvpn/ProfileManager.java
@@ -10,6 +10,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
+import de.blinkt.openvpn.R.string;
+
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
@@ -23,6 +25,7 @@ public class ProfileManager {
private static ProfileManager instance;
private HashMap<String,VpnProfile> profiles=new HashMap<String, VpnProfile>();
+
public static VpnProfile get(String key) {
if(instance==null)
return null;
@@ -65,7 +68,14 @@ public class ProfileManager {
SharedPreferences sharedprefs = context.getSharedPreferences(PREFS_NAME,Activity.MODE_PRIVATE);
Editor editor = sharedprefs.edit();
editor.putStringSet("vpnlist", profiles.keySet());
- editor.commit();
+
+ // For reasing I do not understand at all
+ // Android saves my prefs file only one time
+ // if I remove the debug code below :(
+ int counter = sharedprefs.getInt("counter", 0);
+ editor.putInt("counter", counter+1);
+ editor.apply();
+
}
public void addProfile(VpnProfile profile) {
@@ -99,8 +109,8 @@ public class ProfileManager {
private void loadVPNList(Context context) {
profiles = new HashMap<String, VpnProfile>();
- SharedPreferences settings =context.getSharedPreferences(PREFS_NAME,Activity.MODE_PRIVATE);
- Set<String> vlist = settings.getStringSet("vpnlist", null);
+ SharedPreferences listpref = context.getSharedPreferences(PREFS_NAME,Activity.MODE_PRIVATE);
+ Set<String> vlist = listpref.getStringSet("vpnlist", null);
Exception exp =null;
if(vlist==null){
vlist = new HashSet<String>();
diff --git a/todo.txt b/todo.txt
index 62e6d279..aa7a3d1d 100644
--- a/todo.txt
+++ b/todo.txt
@@ -8,11 +8,12 @@ Ideas:
- implement general settings dialog
- encryption of profiles
- - Speed/Transfered in notification bar (byte counter of managment)
+ - Speed/Transfered in notification bar (byte counter of management)
- Kick openvpn on network state change (Wifi <-> GPRS/EDGE/UMTS)
- map SIGUSR1 to SIGINT
+- add a put this certificate into file obscure option
Missing configuration options: