summaryrefslogtreecommitdiff
path: root/src/se
diff options
context:
space:
mode:
Diffstat (limited to 'src/se')
-rw-r--r--src/se/leap/leapclient/ConfigHelper.java1
-rw-r--r--src/se/leap/leapclient/Dashboard.java44
-rw-r--r--src/se/leap/leapclient/EIP.java58
-rw-r--r--src/se/leap/leapclient/Provider.java1
-rw-r--r--src/se/leap/leapclient/ProviderAPI.java14
-rw-r--r--src/se/leap/openvpn/LaunchVPN.java4
-rw-r--r--src/se/leap/openvpn/VpnProfile.java21
7 files changed, 114 insertions, 29 deletions
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java
index dd20112c..1c2a482a 100644
--- a/src/se/leap/leapclient/ConfigHelper.java
+++ b/src/se/leap/leapclient/ConfigHelper.java
@@ -53,6 +53,7 @@ public class ConfigHelper {
ALLOWED_ANON = "allow_anonymous",
MAIN_CERT_KEY = "main_cert",
CERT_KEY = "cert",
+ KEY_KEY = "key",
EIP_SERVICE_KEY = "eip",
TYPE_OF_CERTIFICATE = "type_of_certificate",
ANON_CERTIFICATE = "anon_certificate",
diff --git a/src/se/leap/leapclient/Dashboard.java b/src/se/leap/leapclient/Dashboard.java
index 19c635a3..31719d90 100644
--- a/src/se/leap/leapclient/Dashboard.java
+++ b/src/se/leap/leapclient/Dashboard.java
@@ -6,7 +6,6 @@ import org.json.JSONException;
import org.json.JSONObject;
import se.leap.leapclient.ProviderAPIResultReceiver.Receiver;
-import se.leap.leapclient.R;
import se.leap.openvpn.AboutFragment;
import se.leap.openvpn.MainActivity;
import android.app.Activity;
@@ -26,6 +25,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.CompoundButton;
+import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
@@ -100,26 +100,32 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
private void buildDashboard() {
// Get our provider
- provider = Provider.getInstance();
- provider.init( this );
-
- // Set provider name in textview
- providerNameTV = (TextView) findViewById(R.id.providerName);
- providerNameTV.setText(provider.getName());
- providerNameTV.setTextSize(28); // TODO maybe to some calculating, or a marquee?
-
- // TODO Inflate layout fragments for provider's services
- if ( provider.hasEIP() )
- serviceItemEIP();
+ provider = Provider.getInstance();
+ provider.init( this );
+
+ // Set provider name in textview
+ providerNameTV = (TextView) findViewById(R.id.providerName);
+ providerNameTV.setText(provider.getName());
+ providerNameTV.setTextSize(28); // TODO maybe to some calculating, or a marquee?
+
+ if ( provider.hasEIP() /*&& provider.getEIP() != null*/){
+ // FIXME let's schedule this, so we're not doing it when we load the app
+ startService( new Intent(EIP.ACTION_UPDATE_EIP_SERVICE) );
+ serviceItemEIP();
+ }
}
private void serviceItemEIP() {
- // FIXME Provider service (eip/openvpn)
((ViewStub) findViewById(R.id.eipOverviewStub)).inflate();
// Set our EIP type title
eipTypeTV = (TextView) findViewById(R.id.eipType);
eipTypeTV.setText(provider.getEIPType());
+ // Show our EIP detail
+ View eipDetail = ((RelativeLayout) findViewById(R.id.eipDetail));
+ View eipSettings = findViewById(R.id.eipSettings);
+ eipSettings.setVisibility(View.GONE); // FIXME too!
+ eipDetail.setVisibility(View.VISIBLE);
// TODO Bind our switch to run our EIP
// What happens when our VPN stops running? does it call the listener?
@@ -127,12 +133,14 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
eipSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if ( isChecked ){
- //TODO startVPN();
- } else {
- //TODO stopVPN();
+ Intent vpnIntent;
+ if (isChecked){
+ vpnIntent = new Intent(EIP.ACTION_START_EIP);
+ } else {
+ vpnIntent = new Intent(EIP.ACTION_STOP_EIP);
+ }
+ startService(vpnIntent);
}
- }
});
//TODO write our info into the view fragment that will expand with details and a settings button
diff --git a/src/se/leap/leapclient/EIP.java b/src/se/leap/leapclient/EIP.java
index f86dd083..21cbdfd5 100644
--- a/src/se/leap/leapclient/EIP.java
+++ b/src/se/leap/leapclient/EIP.java
@@ -3,6 +3,7 @@ package se.leap.leapclient;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.NoSuchElementException;
import java.util.Vector;
import org.json.JSONArray;
@@ -11,6 +12,8 @@ import org.json.JSONObject;
import se.leap.openvpn.ConfigParser;
import se.leap.openvpn.ConfigParser.ConfigParseError;
+import se.leap.openvpn.LaunchVPN;
+import se.leap.openvpn.OpenVpnManagementThread;
import se.leap.openvpn.ProfileManager;
import se.leap.openvpn.VpnProfile;
import android.app.IntentService;
@@ -24,6 +27,8 @@ import android.util.Log;
*/
public final class EIP extends IntentService {
+ public final static String ACTION_START_EIP = "se.leap.leapclient.START_EIP";
+ public final static String ACTION_STOP_EIP = "se.leap.leapclient.STOP_EIP";
public final static String ACTION_UPDATE_EIP_SERVICE = "se.leap.leapclient.UPDATE_EIP_SERVICE";
private static Context context;
@@ -31,6 +36,8 @@ public final class EIP extends IntentService {
// Represents our Provider's eip-service.json
private static JSONObject eipDefinition = null;
+ // Our active gateway
+ private static OVPNGateway activeGateway = null;
public EIP(){
super("LEAPEIP");
@@ -58,6 +65,26 @@ public final class EIP extends IntentService {
if ( action == ACTION_UPDATE_EIP_SERVICE )
this.updateEIPService();
+ else if ( action == ACTION_START_EIP )
+ this.startEIP();
+ else if ( action == ACTION_STOP_EIP )
+ this.stopEIP();
+ }
+
+ private void startEIP() {
+ if (activeGateway==null)
+ activeGateway = selectGateway();
+
+ Intent intent = new Intent(this,LaunchVPN.class);
+ intent.setAction(Intent.ACTION_MAIN);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(LaunchVPN.EXTRA_KEY, activeGateway.mVpnProfile.getUUID().toString() );
+ intent.putExtra(LaunchVPN.EXTRA_NAME, activeGateway.mVpnProfile.getName() );
+ startActivity(intent);
+ }
+
+ private void stopEIP() {
+ OpenVpnManagementThread.stopOpenVPN();
}
private void updateEIPService() {
@@ -71,6 +98,11 @@ public final class EIP extends IntentService {
updateGateways();
}
+ private OVPNGateway selectGateway() {
+ // TODO Logic, yay!
+ return new OVPNGateway("first");
+ }
+
private void updateGateways(){
JSONArray gatewaysDefined = null;
@@ -122,6 +154,32 @@ public final class EIP extends IntentService {
private HashMap<String,Vector<Vector<String>>> options = new HashMap<String, Vector<Vector<String>>>();
+ // Constructor to load a gateway by name
+ private OVPNGateway(String name){
+ ProfileManager vpl = ProfileManager.getInstance(context);
+
+ try {
+
+ // FIXME ha, this got funny..it will get smart once i'm further...
+ if ( name == "first" ) {
+ name = vpl.getProfiles().iterator().next().mName;
+ }
+
+ mVpnProfile = vpl.getProfileByName(name);
+
+ } catch (NoSuchElementException e) {
+
+ // The gateway we were looking for is not in ProfileList!
+ updateEIPService();
+
+ // TODO prompt user to fix config error
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
// Constructor to create a gateway by definition
protected OVPNGateway(JSONObject gw){
// TODO We're going to build 1 profile per gateway, but eventually several
diff --git a/src/se/leap/leapclient/Provider.java b/src/se/leap/leapclient/Provider.java
index 50bd2925..4a09bf7a 100644
--- a/src/se/leap/leapclient/Provider.java
+++ b/src/se/leap/leapclient/Provider.java
@@ -124,6 +124,7 @@ public final class Provider implements Serializable {
}
for (int i=0;i<API_EIP_TYPES.length;i++){
try {
+ // Walk the EIP types array looking for matches in provider's service definitions
if ( Arrays.asList(API_EIP_TYPES).contains( services.getString(i) ) )
return true;
} catch (JSONException e) {
diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java
index 00d7d820..72cc9b62 100644
--- a/src/se/leap/leapclient/ProviderAPI.java
+++ b/src/se/leap/leapclient/ProviderAPI.java
@@ -584,8 +584,18 @@ public class ProviderAPI extends IntentService {
boolean danger_on = ConfigHelper.getBoolFromSharedPref(ConfigHelper.DANGER_ON);
String cert_string = getStringFromProvider(new_cert_string_url, danger_on);
- if(!cert_string.isEmpty()) {
- ConfigHelper.saveSharedPref(ConfigHelper.CERT_KEY, cert_string);
+ if(!cert_string.isEmpty()) {
+ // API returns concatenated cert & key. Split them for OpenVPN options
+ String certificate = null, key = null;
+ String[] certAndKey = cert_string.split("(?<=-\n)");
+ for (int i=0; i < certAndKey.length-1; i++){
+ if ( certAndKey[i].contains("KEY") )
+ key = certAndKey[i++] + certAndKey[i];
+ else if ( certAndKey[i].contains("CERTIFICATE") )
+ certificate = certAndKey[i++] + certAndKey[i];
+ }
+ ConfigHelper.saveSharedPref(ConfigHelper.CERT_KEY, certificate);
+ ConfigHelper.saveSharedPref(ConfigHelper.KEY_KEY, key);
return true;
} else {
return false;
diff --git a/src/se/leap/openvpn/LaunchVPN.java b/src/se/leap/openvpn/LaunchVPN.java
index 3df2aacb..2dcaf176 100644
--- a/src/se/leap/openvpn/LaunchVPN.java
+++ b/src/se/leap/openvpn/LaunchVPN.java
@@ -74,7 +74,7 @@ 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;
private ProfileManager mPM;
@@ -266,7 +266,7 @@ 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();
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)