summaryrefslogtreecommitdiff
path: root/src/se/leap/openvpn
diff options
context:
space:
mode:
Diffstat (limited to 'src/se/leap/openvpn')
-rw-r--r--src/se/leap/openvpn/AboutFragment.java60
-rw-r--r--src/se/leap/openvpn/ConfigParser.java6
-rw-r--r--src/se/leap/openvpn/LICENSE.txt24
-rw-r--r--src/se/leap/openvpn/LaunchVPN.java24
-rw-r--r--src/se/leap/openvpn/OpenVPN.java6
-rw-r--r--src/se/leap/openvpn/OpenVpnService.java68
-rw-r--r--src/se/leap/openvpn/VpnProfile.java21
7 files changed, 93 insertions, 116 deletions
diff --git a/src/se/leap/openvpn/AboutFragment.java b/src/se/leap/openvpn/AboutFragment.java
deleted file mode 100644
index 3563528b..00000000
--- a/src/se/leap/openvpn/AboutFragment.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package se.leap.openvpn;
-
-import android.app.Fragment;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.os.Bundle;
-import android.text.Html;
-import android.text.Spanned;
-import android.text.method.LinkMovementMethod;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
-import se.leap.leapclient.R;
-
-public class AboutFragment extends Fragment {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View v= inflater.inflate(R.layout.about, container, false);
- TextView ver = (TextView) v.findViewById(R.id.version);
-
- String version;
- String name="Openvpn";
- try {
- PackageInfo packageinfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
- version = packageinfo.versionName;
- name = getString(R.string.app);
- } catch (NameNotFoundException e) {
- version = "error fetching version";
- }
-
-
- ver.setText(getString(R.string.version_info,name,version));
-
- TextView paypal = (TextView) v.findViewById(R.id.donatestring);
-
- String donatetext = getActivity().getString(R.string.donatewithpaypal);
- Spanned htmltext = Html.fromHtml(donatetext);
- paypal.setText(htmltext);
- paypal.setMovementMethod(LinkMovementMethod.getInstance());
-
- TextView translation = (TextView) v.findViewById(R.id.translation);
-
- // Don't print a text for myself
- if ( getString(R.string.translationby).contains("Arne Schwabe"))
- translation.setText("");
- else
- translation.setText(R.string.translationby);
- return v;
- }
-
-}
diff --git a/src/se/leap/openvpn/ConfigParser.java b/src/se/leap/openvpn/ConfigParser.java
index f57bbae9..3d369fa6 100644
--- a/src/se/leap/openvpn/ConfigParser.java
+++ b/src/se/leap/openvpn/ConfigParser.java
@@ -47,6 +47,9 @@ public class ConfigParser {
options.get(optionname).add(args);
}
}
+ public void setDefinition(HashMap<String,Vector<Vector<String>>> args) {
+ options = args;
+ }
private void checkinlinefile(Vector<String> args, BufferedReader br) throws IOException, ConfigParseError {
String arg0 = args.get(0);
@@ -247,7 +250,8 @@ public class ConfigParser {
// Pull, client, tls-client
np.clearDefaults();
- if(options.containsKey("client") || options.containsKey("pull")) {
+ // XXX we are always client
+ if(/*options.containsKey("client") || options.containsKey("pull")*/ true) {
np.mUsePull=true;
options.remove("pull");
options.remove("client");
diff --git a/src/se/leap/openvpn/LICENSE.txt b/src/se/leap/openvpn/LICENSE.txt
new file mode 100644
index 00000000..d897edea
--- /dev/null
+++ b/src/se/leap/openvpn/LICENSE.txt
@@ -0,0 +1,24 @@
+License for OpenVPN for Android. Please note that the thirdparty libraries/executables may have other license (OpenVPN, lzo, OpenSSL, Google Breakpad)
+
+Copyright (c) 2012-2013, Arne Schwabe
+ All rights reserved.
+
+If you need a non GPLv2 license of the source please contact me.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+In addition, as a special exception, the copyright holders give
+permission to link the code of portions of this program with the
+OpenSSL library.
diff --git a/src/se/leap/openvpn/LaunchVPN.java b/src/se/leap/openvpn/LaunchVPN.java
index 3df2aacb..1df6be96 100644
--- a/src/se/leap/openvpn/LaunchVPN.java
+++ b/src/se/leap/openvpn/LaunchVPN.java
@@ -19,6 +19,9 @@ package se.leap.openvpn;
import java.io.IOException;
import java.util.Collection;
import java.util.Vector;
+
+import se.leap.leapclient.ConfigHelper;
+import se.leap.leapclient.EIP;
import se.leap.leapclient.R;
import android.app.Activity;
@@ -32,6 +35,7 @@ import android.content.SharedPreferences;
import android.net.VpnService;
import android.os.Bundle;
import android.os.Parcelable;
+import android.os.ResultReceiver;
import android.preference.PreferenceManager;
import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
@@ -74,8 +78,10 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
public static final String EXTRA_NAME = "se.leap.openvpn.shortcutProfileName";
public static final String EXTRA_HIDELOG = "se.leap.openvpn.showNoLogWindow";;
- private static final int START_VPN_PROFILE= 70;
+ public static final int START_VPN_PROFILE= 70;
+ // Dashboard, maybe more, want to know!
+ private ResultReceiver mReceiver;
private ProfileManager mPM;
private VpnProfile mSelectedProfile;
@@ -99,6 +105,9 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
final Intent intent = getIntent();
final String action = intent.getAction();
+ // If something wants feedback, they sent us a Receiver
+ mReceiver = intent.getParcelableExtra(ConfigHelper.RECEIVER_TAG);
+
// If the intent is a request to create a shortcut, we'll do that and exit
@@ -266,14 +275,18 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
askForPW(needpw);
} else {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
- boolean showlogwindow = prefs.getBoolean("showlogwindow", true);
+ boolean showlogwindow = prefs.getBoolean("showlogwindow", false);
if(!mhideLog && showlogwindow)
showLogWindow();
new startOpenVpnThread().start();
}
} else if (resultCode == Activity.RESULT_CANCELED) {
- // User does not want us to start, so we just vanish
+ // User does not want us to start, so we just vanish (well, now we tell our receiver, then vanish)
+ Bundle resultData = new Bundle();
+ // For now, nothing else is calling, so this "request" string is good enough
+ resultData.putString(ConfigHelper.REQUEST_TAG, EIP.ACTION_START_EIP);
+ mReceiver.send(RESULT_CANCELED, resultData);
finish();
}
}
@@ -357,6 +370,11 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
@Override
public void run() {
VPNLaunchHelper.startOpenVpn(mSelectedProfile, getBaseContext());
+ // Tell whom-it-may-concern that we started VPN
+ Bundle resultData = new Bundle();
+ // For now, nothing else is calling, so this "request" string is good enough
+ resultData.putString(ConfigHelper.REQUEST_TAG, EIP.ACTION_START_EIP);
+ mReceiver.send(RESULT_OK, resultData);
finish();
}
diff --git a/src/se/leap/openvpn/OpenVPN.java b/src/se/leap/openvpn/OpenVPN.java
index 152cf2d8..3ffc47cb 100644
--- a/src/se/leap/openvpn/OpenVPN.java
+++ b/src/se/leap/openvpn/OpenVPN.java
@@ -204,10 +204,10 @@ public class OpenVPN {
mLaststate= state;
mLaststatemsg = msg;
mLastStateresid = resid;
- }
- for (StateListener sl : stateListener) {
- sl.updateState(state,msg,resid);
+ for (StateListener sl : stateListener) {
+ sl.updateState(state,msg,resid);
+ }
}
}
diff --git a/src/se/leap/openvpn/OpenVpnService.java b/src/se/leap/openvpn/OpenVpnService.java
index c745ee3b..3ac80497 100644
--- a/src/se/leap/openvpn/OpenVpnService.java
+++ b/src/se/leap/openvpn/OpenVpnService.java
@@ -1,25 +1,11 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
package se.leap.openvpn;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Vector;
+
+import se.leap.leapclient.Dashboard;
import se.leap.leapclient.R;
import android.annotation.TargetApi;
@@ -35,7 +21,6 @@ import android.net.LocalSocket;
import android.net.LocalSocketAddress;
import android.net.VpnService;
import android.os.Binder;
-import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Build;
import android.os.IBinder;
@@ -45,6 +30,7 @@ import se.leap.openvpn.OpenVPN.StateListener;
public class OpenVpnService extends VpnService implements StateListener, Callback {
public static final String START_SERVICE = "se.leap.openvpn.START_SERVICE";
+ public static final String RETRIEVE_SERVICE = "se.leap.openvpn.RETRIEVE_SERVICE";
private Thread mProcessThread=null;
@@ -65,6 +51,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
private int mMtu;
private String mLocalIPv6=null;
private NetworkSateReceiver mNetworkStateReceiver;
+ private NotificationManager mNotificationManager;
private boolean mDisplayBytecount=false;
@@ -89,7 +76,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
@Override
public IBinder onBind(Intent intent) {
String action = intent.getAction();
- if( action !=null && action.equals(START_SERVICE))
+ if( action !=null && (action.equals(START_SERVICE) || action.equals(RETRIEVE_SERVICE)) )
return mBinder;
else
return super.onBind(intent);
@@ -116,9 +103,9 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
}
}
- private void showNotification(String msg, String tickerText, boolean lowpriority, long when) {
+ private void showNotification(String msg, String tickerText, boolean lowpriority, long when, boolean persistant) {
String ns = Context.NOTIFICATION_SERVICE;
- NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
+ mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ic_stat_vpn;
@@ -127,7 +114,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
nbuilder.setContentTitle(getString(R.string.notifcation_title,mProfile.mName));
nbuilder.setContentText(msg);
nbuilder.setOnlyAlertOnce(true);
- nbuilder.setOngoing(true);
+ nbuilder.setOngoing(persistant);
nbuilder.setContentIntent(getLogPendingIntent());
nbuilder.setSmallIcon(icon);
if(when !=0)
@@ -144,7 +131,6 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
mNotificationManager.notify(OPENVPN_STATUS, notification);
- startForeground(OPENVPN_STATUS, notification);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@@ -173,10 +159,10 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
}
PendingIntent getLogPendingIntent() {
- // Let the configure Button show the Log
- Intent intent = new Intent(getBaseContext(),LogWindow.class);
+ // Let the configure Button show the Dashboard
+ Intent intent = new Intent(Dashboard.getAppContext(),Dashboard.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
- PendingIntent startLW = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
+ PendingIntent startLW = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
return startLW;
@@ -223,7 +209,8 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- if(intent != null && intent.getAction() !=null &&intent.getAction().equals(START_SERVICE))
+ if( intent != null && intent.getAction() !=null &&
+ (intent.getAction().equals(START_SERVICE) || intent.getAction().equals(RETRIEVE_SERVICE)) )
return START_NOT_STICKY;
@@ -235,7 +222,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
mProfile = ProfileManager.get(profileUUID);
- showNotification("Starting VPN " + mProfile.mName,"Starting VPN " + mProfile.mName, false,0);
+ //showNotification("Starting VPN " + mProfile.mName,"Starting VPN " + mProfile.mName, false,0);
OpenVPN.addStateListener(this);
@@ -466,6 +453,13 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
mLocalIPv6 = ipv6addr;
}
+ public boolean isRunning() {
+ if (mStarting == true || mProcessThread != null)
+ return true;
+ else
+ return false;
+ }
+
@Override
public void updateState(String state,String logmessage, int resid) {
// If the process is not running, ignore any state,
@@ -473,26 +467,16 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
if(mProcessThread==null)
return;
- // Display byte count only after being connected
-
- if("BYTECOUNT".equals(state)) {
- if(mDisplayBytecount) {
- showNotification(logmessage,null,true,mConnecttime);
- }
- } else {
- if("CONNECTED".equals(state)) {
- mDisplayBytecount = true;
- mConnecttime = System.currentTimeMillis();
- } else {
- mDisplayBytecount = false;
- }
+ if("CONNECTED".equals(state)) {
+ mNotificationManager.cancel(OPENVPN_STATUS);
+ } else if(!"BYTECOUNT".equals(state)) {
// Other notifications are shown,
// This also mean we are no longer connected, ignore bytecount messages until next
// CONNECTED
String ticker = getString(resid);
- showNotification(getString(resid) +" " + logmessage,ticker,false,0);
-
+ boolean persist = ("NOPROCESS".equals(state)) ? false : true;
+ showNotification(getString(resid) +" " + logmessage,ticker,false,0,persist);
}
}
diff --git a/src/se/leap/openvpn/VpnProfile.java b/src/se/leap/openvpn/VpnProfile.java
index 38ee3c83..2262f565 100644
--- a/src/se/leap/openvpn/VpnProfile.java
+++ b/src/se/leap/openvpn/VpnProfile.java
@@ -20,6 +20,8 @@ import java.util.Vector;
import org.spongycastle.util.io.pem.PemObject;
import org.spongycastle.util.io.pem.PemWriter;
+
+import se.leap.leapclient.ConfigHelper;
import se.leap.leapclient.R;
import android.content.Context;
@@ -62,7 +64,7 @@ public class VpnProfile implements Serializable{
// Public attributes, since I got mad with getter/setter
// set members to default values
private UUID mUuid;
- public int mAuthenticationType = TYPE_KEYSTORE ;
+ public int mAuthenticationType = TYPE_CERTIFICATES ;
public String mName;
public String mAlias;
public String mClientCertFilename;
@@ -236,13 +238,18 @@ public class VpnProfile implements Serializable{
case VpnProfile.TYPE_USERPASS_CERTIFICATES:
cfg+="auth-user-pass\n";
case VpnProfile.TYPE_CERTIFICATES:
- // Ca
+ /*// Ca
cfg+=insertFileData("ca",mCaFilename);
// Client Cert + Key
cfg+=insertFileData("key",mClientKeyFilename);
cfg+=insertFileData("cert",mClientCertFilename);
-
+*/
+ // FIXME This is all we need...The whole switch statement can go...
+ cfg+="<ca>\n"+ConfigHelper.getStringFromSharedPref(ConfigHelper.MAIN_CERT_KEY)+"\n</ca>\n";
+ cfg+="<key>\n"+ConfigHelper.getStringFromSharedPref(ConfigHelper.KEY_KEY)+"\n</key>\n";
+ cfg+="<cert>\n"+ConfigHelper.getStringFromSharedPref(ConfigHelper.CERT_KEY)+"\n</cert>\n";
+
break;
case VpnProfile.TYPE_USERPASS_PKCS12:
cfg+="auth-user-pass\n";
@@ -492,8 +499,8 @@ public class VpnProfile implements Serializable{
Intent intent = new Intent(context,OpenVpnService.class);
if(mAuthenticationType == VpnProfile.TYPE_KEYSTORE || mAuthenticationType == VpnProfile.TYPE_USERPASS_KEYSTORE) {
- if(!saveCertificates(context))
- return null;
+ /*if(!saveCertificates(context))
+ return null;*/
}
intent.putExtra(prefix + ".ARGV" , buildOpenvpnArgv(context.getCacheDir()));
@@ -597,10 +604,10 @@ 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(mAuthenticationType==TYPE_KEYSTORE || mAuthenticationType==TYPE_USERPASS_KEYSTORE) {
if(mAlias==null)
return R.string.no_keystore_cert_selected;
- }
+ }*/
if(!mUsePull) {
if(mIPv4Address == null || cidrToIPAndNetmask(mIPv4Address) == null)