summaryrefslogtreecommitdiff
path: root/src/se/leap
diff options
context:
space:
mode:
Diffstat (limited to 'src/se/leap')
-rw-r--r--src/se/leap/leapclient/ConfigHelper.java14
-rw-r--r--src/se/leap/leapclient/ConfigurationWizard.java78
-rw-r--r--src/se/leap/leapclient/Dashboard.java62
-rw-r--r--src/se/leap/leapclient/ProviderAPI.java90
-rw-r--r--src/se/leap/leapclient/ProviderListContent.java5
5 files changed, 202 insertions, 47 deletions
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java
index 98761b61..0dab26f4 100644
--- a/src/se/leap/leapclient/ConfigHelper.java
+++ b/src/se/leap/leapclient/ConfigHelper.java
@@ -16,7 +16,6 @@ import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
-import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -30,6 +29,7 @@ public class ConfigHelper {
private static KeyStore keystore_trusted;
final static String downloadJsonFilesBundleExtra = "downloadJSONFiles";
+ final static String updateProviderDotJSON = "updateProviderDotJSON";
final static String downloadNewProviderDotJSON = "downloadNewProviderDotJSON";
final public static String logInDialog = "logInDialog";
final public static String newProviderDialog = "logInDialog";
@@ -41,6 +41,7 @@ public class ConfigHelper {
public static String api_version_key = "api_version";
final public static String resultKey = "result";
final static String provider_key = "provider";
+ final static String service_key = "service";
final static String main_cert_key = "main_cert";
final static String cert_key = "cert";
final static String eip_service_key = "eip";
@@ -48,11 +49,15 @@ public class ConfigHelper {
final static String session_id_key = "session_id";
public static final String PREFERENCES_KEY = "LEAPPreferences";
public static final String user_directory = "leap_android";
+ final public static String provider_name = "provider_name";
final public static String provider_main_url = "provider_main_url";
+ final public static String provider_json_url = "provider_json_url";
+ final public static String custom = "custom";
final public static String danger_on = "danger_on";
final public static String api_url_key = "api_uri";
final public static String username_key = "username";
final public static String password_key = "password";
+ final public static String allow_registration_key = "allow_registration";
final public static String eip_service_api_path = "config/eip-service.json";
final public static String NG_1024 =
@@ -70,6 +75,8 @@ public class ConfigHelper {
final public static int LOGOUT_FAILED = 8;
final public static int CORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE = 9;
final public static int INCORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE = 10;
+ final public static int CORRECTLY_UPDATED_PROVIDER_DOT_JSON = 11;
+ final public static int INCORRECTLY_UPDATED_PROVIDER_DOT_JSON = 12;
static String getStringFromSharedPref(String shared_preferences_key) {
String value = "";
@@ -194,7 +201,6 @@ public class ConfigHelper {
// Initialize the keystore with the provided trusted certificates
// Also provide the password of the keystore
if(leap_keystore != null) {
- InputStream android_default_keystore;
//keystore_trusted.load(leap_keystore, "uer92jf".toCharArray());
keystore_trusted.load(null, null);
} else {
@@ -221,7 +227,9 @@ public class ConfigHelper {
public static int getSrpAuthenticationFailed() {
return SRP_AUTHENTICATION_FAILED;
- }static String extractProviderName(String provider_main_url) {
+ }
+
+ static String extractProviderName(String provider_main_url) {
return null;
}
diff --git a/src/se/leap/leapclient/ConfigurationWizard.java b/src/se/leap/leapclient/ConfigurationWizard.java
index a50a8e62..ba17f9bb 100644
--- a/src/se/leap/leapclient/ConfigurationWizard.java
+++ b/src/se/leap/leapclient/ConfigurationWizard.java
@@ -3,6 +3,7 @@ package se.leap.leapclient;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.net.URL;
import java.util.Iterator;
import java.util.Scanner;
@@ -133,29 +134,27 @@ public class ConfigurationWizard extends Activity
}
}
- private void saveProviderJson(ProviderItem current_provider_item) {
- AssetManager assets_manager = getAssets();
- JSONObject provider_json = new JSONObject();
- try {
- String provider_contents = "";
- if(!current_provider_item.custom)
- provider_contents = new Scanner(new InputStreamReader(assets_manager.open(current_provider_item.provider_json_filename))).useDelimiter("\\A").next();
- else
- provider_contents = new Scanner(ConfigHelper.openFileInputStream(current_provider_item.provider_json_filename)).useDelimiter("\\A").next();
- provider_json = new JSONObject(provider_contents);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (JSONException e) {
- ConfigHelper.rescueJSONException(e);
- }
- ConfigHelper.saveSharedPref(ConfigHelper.provider_key, provider_json);
- try {
- ConfigHelper.saveSharedPref(ConfigHelper.danger_on, new JSONObject().put(ConfigHelper.danger_on, current_provider_item.danger_on));
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ private void saveProviderJson(ProviderItem current_provider_item) {
+ JSONObject provider_json = new JSONObject();
+ try {
+ String provider_contents = "";
+ if(!current_provider_item.custom) {
+ //provider_contents = new Scanner(new InputStreamReader(assets_manager.open(current_provider_item.provider_json_filename))).useDelimiter("\\A").next();
+ updateProviderDotJson(current_provider_item.name, current_provider_item.provider_json_url, current_provider_item.danger_on);
+ } else {
+ provider_contents = new Scanner(ConfigHelper.openFileInputStream(current_provider_item.provider_json_filename)).useDelimiter("\\A").next();
+ provider_json = new JSONObject(provider_contents);
+ ConfigHelper.saveSharedPref(ConfigHelper.provider_key, provider_json);
+ try {
+ ConfigHelper.saveSharedPref(ConfigHelper.danger_on, new JSONObject().put(ConfigHelper.danger_on, current_provider_item.danger_on));
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ } catch (JSONException e) {
+ ConfigHelper.rescueJSONException(e);
+ }
}
private void downloadJSONFiles(ProviderItem current_provider_item) throws IOException {
@@ -205,6 +204,23 @@ public class ConfigurationWizard extends Activity
startService(provider_API_command);
}
+
+ public void updateProviderDotJson(String provider_name, String provider_json_url, boolean danger_on) {
+ providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
+ providerAPI_result_receiver.setReceiver(this);
+
+ Intent provider_API_command = new Intent(this, ProviderAPI.class);
+
+ Bundle method_and_parameters = new Bundle();
+ method_and_parameters.putString(ConfigHelper.provider_name, provider_name);
+ method_and_parameters.putString(ConfigHelper.provider_json_url, provider_json_url);
+ method_and_parameters.putBoolean(ConfigHelper.danger_on, danger_on);
+
+ provider_API_command.putExtra(ConfigHelper.updateProviderDotJSON, method_and_parameters);
+ provider_API_command.putExtra("receiver", providerAPI_result_receiver);
+
+ startService(provider_API_command);
+ }
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
@@ -224,5 +240,21 @@ public class ConfigurationWizard extends Activity
setResult(RESULT_CANCELED);
Toast.makeText(getApplicationContext(), "You have not entered a LEAP provider URL", Toast.LENGTH_LONG).show();
}
+ else if(resultCode == ConfigHelper.CORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
+ JSONObject provider_json;
+ try {
+ provider_json = new JSONObject(resultData.getString(ConfigHelper.provider_key));
+ boolean danger_on = resultData.getBoolean(ConfigHelper.danger_on);
+ ConfigHelper.saveSharedPref(ConfigHelper.provider_key, provider_json);
+ ConfigHelper.saveSharedPref(ConfigHelper.danger_on, new JSONObject().put(ConfigHelper.danger_on, danger_on));
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ else if(resultCode == ConfigHelper.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
+ Toast.makeText(getApplicationContext(), "Install a new version of this app.", Toast.LENGTH_LONG).show();
+ }
+
}
}
diff --git a/src/se/leap/leapclient/Dashboard.java b/src/se/leap/leapclient/Dashboard.java
index dbee9c48..c8cbc5a3 100644
--- a/src/se/leap/leapclient/Dashboard.java
+++ b/src/se/leap/leapclient/Dashboard.java
@@ -11,7 +11,6 @@ import se.leap.openvpn.MainActivity;
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
-import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -116,6 +115,25 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
}
@Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ String provider_json_string = ConfigHelper.getStringFromSharedPref(ConfigHelper.provider_key);
+ try {
+ JSONObject provider_json = new JSONObject(provider_json_string);
+ JSONObject service_description = provider_json.getJSONObject(ConfigHelper.service_key);
+ if(service_description.getBoolean(ConfigHelper.allow_registration_key)) {
+ menu.findItem(R.id.login_button).setVisible(true);
+ menu.findItem(R.id.logout_button).setVisible(true);
+ return true;
+ }
+ } catch (JSONException e) {
+ menu.findItem(R.id.login_button).setVisible(false);
+ menu.findItem(R.id.logout_button).setVisible(false);
+ return false;
+ }
+ return false;
+ }
+
+ @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.client_dashboard, menu);
@@ -147,6 +165,9 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);
logInDialog(view);
return true;
+ case R.id.logout_button:
+ logOut();
+ return true;
default:
return super.onOptionsItemSelected(item);
}
@@ -184,6 +205,28 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
startService(provider_API_command);
}
+ public void logOut() {
+ providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
+ providerAPI_result_receiver.setReceiver(this);
+ Intent provider_API_command = new Intent(this, ProviderAPI.class);
+
+ Bundle method_and_parameters = new Bundle();
+
+ JSONObject provider_json;
+ try {
+ provider_json = new JSONObject(preferences.getString(ConfigHelper.provider_key, ""));
+ method_and_parameters.putString(ConfigHelper.api_url_key, provider_json.getString(ConfigHelper.api_url_key) + "/" + provider_json.getString(ConfigHelper.api_version_key));
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ provider_API_command.putExtra(ConfigHelper.logOut, method_and_parameters);
+ provider_API_command.putExtra("receiver", providerAPI_result_receiver);
+
+ startService(provider_API_command);
+ }
+
public void logInDialog(View view) {
FragmentTransaction fragment_transaction = getFragmentManager().beginTransaction();
Fragment previous_log_in_dialog = getFragmentManager().findFragmentByTag(ConfigHelper.logInDialog);
@@ -219,19 +262,22 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
String session_id_string = resultData.getString(ConfigHelper.session_id_key);
setResult(RESULT_OK);
Toast.makeText(getApplicationContext(), "Authentication succeeded", Toast.LENGTH_LONG).show();
- //TODO Download certificate requesting /1/cert with session_id cookie
+
Cookie session_id = new BasicClientCookie(session_id_cookie_key, session_id_string);
downloadAuthedUserCertificate(session_id);
- }
- else if(resultCode == ConfigHelper.SRP_AUTHENTICATION_FAILED) {
+ } else if(resultCode == ConfigHelper.SRP_AUTHENTICATION_FAILED) {
setResult(RESULT_CANCELED);
Toast.makeText(getApplicationContext(), "Authentication failed", Toast.LENGTH_LONG).show();
- }
- else if(resultCode == ConfigHelper.CORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE) {
+ } else if(resultCode == ConfigHelper.LOGOUT_SUCCESSFUL) {
+ setResult(RESULT_OK);
+ Toast.makeText(getApplicationContext(), "Logged out", Toast.LENGTH_LONG).show();
+ } else if(resultCode == ConfigHelper.LOGOUT_FAILED) {
+ setResult(RESULT_CANCELED);
+ Toast.makeText(getApplicationContext(), "Didn't logged out", Toast.LENGTH_LONG).show();
+ } else if(resultCode == ConfigHelper.CORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE) {
setResult(RESULT_CANCELED);
Toast.makeText(getApplicationContext(), "Your own cert has been correctly downloaded", Toast.LENGTH_LONG).show();
- }
- else if(resultCode == ConfigHelper.INCORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE) {
+ } else if(resultCode == ConfigHelper.INCORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE) {
setResult(RESULT_CANCELED);
Toast.makeText(getApplicationContext(), "Your own cert has incorrectly been downloaded", Toast.LENGTH_LONG).show();
}
diff --git a/src/se/leap/leapclient/ProviderAPI.java b/src/se/leap/leapclient/ProviderAPI.java
index bdfd6207..b44c9971 100644
--- a/src/se/leap/leapclient/ProviderAPI.java
+++ b/src/se/leap/leapclient/ProviderAPI.java
@@ -15,7 +15,6 @@ import java.util.List;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.HttpCookie;
-import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
@@ -30,16 +29,12 @@ import javax.net.ssl.TrustManagerFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.cookie.Cookie;
-import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.jboss.security.Util;
@@ -74,6 +69,24 @@ public class ProviderAPI extends IntentService {
else
receiver.send(ConfigHelper.CORRECTLY_DOWNLOADED_JSON_FILES, Bundle.EMPTY);
}
+ else if ((task = task_for.getBundleExtra(ConfigHelper.updateProviderDotJSON)) != null) {
+ JSONObject result = updateProviderDotJSON(task);
+ boolean successful;
+ try {
+ successful = result.getBoolean(ConfigHelper.resultKey);
+ if(successful) {
+ Bundle provider_dot_json_and_danger_on = new Bundle();
+ provider_dot_json_and_danger_on.putBoolean(ConfigHelper.danger_on, result.getBoolean(ConfigHelper.danger_on));
+ provider_dot_json_and_danger_on.putString(ConfigHelper.provider_key, result.getJSONObject(ConfigHelper.provider_key).toString());
+ receiver.send(ConfigHelper.CORRECTLY_UPDATED_PROVIDER_DOT_JSON, provider_dot_json_and_danger_on);
+ } else {
+ receiver.send(ConfigHelper.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON, Bundle.EMPTY);
+ }
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
else if ((task = task_for.getBundleExtra(ConfigHelper.downloadNewProviderDotJSON)) != null) {
if(downloadNewProviderDotJSON(task))
receiver.send(ConfigHelper.CUSTOM_PROVIDER_ADDED, Bundle.EMPTY);
@@ -172,6 +185,9 @@ public class ProviderAPI extends IntentService {
successfulAndsession_id.put(ConfigHelper.session_id_cookie_key, session_idAndM2.getString(ConfigHelper.session_id_cookie_key));
return successfulAndsession_id;
}
+ } else {
+ successfulAndsession_id.put(ConfigHelper.resultKey, false);
+ return successfulAndsession_id;
}
} catch (ClientProtocolException e1) {
// TODO Auto-generated catch block
@@ -236,6 +252,50 @@ public class ProviderAPI extends IntentService {
return session_idAndM2;
}
+ private JSONObject updateProviderDotJSON(Bundle task) {
+ JSONObject result = new JSONObject();
+ boolean custom = task.getBoolean(ConfigHelper.custom);
+ boolean danger_on = task.getBoolean(ConfigHelper.danger_on);
+ String provider_json_url = task.getString(ConfigHelper.provider_json_url);
+ String provider_name = task.getString(ConfigHelper.provider_name);
+
+ JSONObject provider_json = null;
+ try {
+ provider_json = getJSONFromProvider(provider_json_url, danger_on);
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ try {
+ return result.put(ConfigHelper.resultKey, false);
+ } catch (JSONException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+
+ if(provider_json == null) {
+ try {
+ return result.put(ConfigHelper.resultKey, false);
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } else {
+ String filename = provider_name + "_provider.json".replaceFirst("__", "_");
+ ConfigHelper.saveFile(filename, provider_json.toString());
+ //ConfigHelper.saveSharedPref(ConfigHelper.provider_key, provider_json);
+
+ ProviderListContent.addItem(new ProviderItem(provider_name, provider_json_url, filename, custom, danger_on));
+ try {
+ return result.put(ConfigHelper.resultKey, true).put(ConfigHelper.provider_key, provider_json).put(ConfigHelper.danger_on, danger_on);
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ return result;
+ }
+
private boolean downloadNewProviderDotJSON(Bundle task) {
boolean custom = true;
boolean danger_on = task.getBoolean(ConfigHelper.danger_on);
@@ -259,7 +319,7 @@ public class ProviderAPI extends IntentService {
ConfigHelper.saveFile(filename, provider_json.toString());
//ConfigHelper.saveSharedPref(ConfigHelper.provider_key, provider_json);
- ProviderListContent.addItem(new ProviderItem(provider_name, provider_json_url, ConfigHelper.openFileInputStream(filename), custom, danger_on));
+ ProviderListContent.addItem(new ProviderItem(provider_name, provider_json_url, filename, custom, danger_on));
return true;
}
}
@@ -291,10 +351,6 @@ public class ProviderAPI extends IntentService {
}
return json_string;
}
-
- private String guessURL(String provider_main_url) {
- return provider_main_url + "/provider.json";
- }
private String getStringFromProvider(String string_url, boolean danger_on) {
@@ -388,23 +444,33 @@ public class ProviderAPI extends IntentService {
String json_file_content = getStringFromProvider(json_url, danger_on);
return new JSONObject(json_file_content);
}
+
+ private String guessURL(String provider_main_url) {
+ return provider_main_url + "/provider.json";
+ }
private boolean logOut(Bundle task) {
DefaultHttpClient client = LeapHttpClient.getInstance(getApplicationContext());
int session_id_index = 0;
//String delete_url = task.getString(ConfigHelper.srp_server_url_key) + "/sessions/" + client.getCookieStore().getCookies().get(0).getValue();
- String delete_url = task.getString(ConfigHelper.api_url_key) + "/logout" + "?authenticity_token=" + client.getCookieStore().getCookies().get(session_id_index).getValue();
- HttpDelete delete = new HttpDelete(delete_url);
try {
+ String delete_url = task.getString(ConfigHelper.api_url_key) + "/logout" + "?authenticity_token=" + client.getCookieStore().getCookies().get(session_id_index).getValue();
+ HttpDelete delete = new HttpDelete(delete_url);
HttpResponse getResponse = client.execute(delete);
HttpEntity responseEntity = getResponse.getEntity();
responseEntity.consumeContent();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
+ return false;
+ } catch (IndexOutOfBoundsException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
+ return false;
}
return true;
}
diff --git a/src/se/leap/leapclient/ProviderListContent.java b/src/se/leap/leapclient/ProviderListContent.java
index 8cc349c2..d4bb6a9a 100644
--- a/src/se/leap/leapclient/ProviderListContent.java
+++ b/src/se/leap/leapclient/ProviderListContent.java
@@ -78,8 +78,10 @@ public class ProviderListContent {
}
}
- public ProviderItem(String name, String provider_json_url, FileInputStream provider_json, boolean custom, boolean danger_on) {
+ public ProviderItem(String name, String provider_json_url, String provider_json_filename, boolean custom, boolean danger_on) {
+
+ FileInputStream provider_json = ConfigHelper.openFileInputStream(provider_json_filename);
try {
byte[] urls_file_bytes = new byte[provider_json.available()];
provider_json.read(urls_file_bytes);
@@ -88,6 +90,7 @@ public class ProviderListContent {
id = name;
this.name = name;
this.provider_json_url = provider_json_url;
+ this.provider_json_filename = provider_json_filename;
eip_service_json_url = file_contents.getString("api_uri") + "/" + file_contents.getString("api_version") + "/" + ConfigHelper.eip_service_api_path;
cert_json_url = (String) file_contents.get("ca_cert_uri");
this.custom = custom;