summaryrefslogtreecommitdiff
path: root/src/se/leap
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-05-14 21:03:07 +0200
committerParménides GV <parmegv@sdf.org>2013-05-14 21:03:07 +0200
commit75edcdb601be69f4c1ee6783cf7f80390a9f094d (patch)
tree452ce21e7a92ff62a63d57260643399c37b560a6 /src/se/leap
parent80a8106afc8956008beb9d1ed9396f1d695d5b7b (diff)
Anon certificate is downloaded if possible.
I download the anon certificate only if allow_anonymous is true, and before launching Dashboard. I store it in SharedPreferences, with "cert" key, as a JSON object.
Diffstat (limited to 'src/se/leap')
-rw-r--r--src/se/leap/leapclient/ConfigHelper.java14
-rw-r--r--src/se/leap/leapclient/ConfigurationWizard.java39
-rw-r--r--src/se/leap/leapclient/Dashboard.java7
-rw-r--r--src/se/leap/leapclient/ProviderAPI.java24
4 files changed, 66 insertions, 18 deletions
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java
index 5d44f004..6a70378f 100644
--- a/src/se/leap/leapclient/ConfigHelper.java
+++ b/src/se/leap/leapclient/ConfigHelper.java
@@ -37,14 +37,18 @@ public class ConfigHelper {
SRP_AUTH = "srpAuth",
LOG_IN = "logIn",
LOG_OUT = "logOut",
- DOWNLOAD_USER_AUTHED_CERTIFICATE = "downloadUserAuthedCertificate",
+ DOWNLOAD_CERTIFICATE = "downloadUserAuthedCertificate",
API_VERSION_KEY = "api_version",
RESULT_KEY = "result",
PROVIDER_KEY = "provider",
SERVICE_KEY = "service",
+ ALLOWED_ANON = "allow_anonymous",
MAIN_CERT_KEY = "main_cert",
CERT_KEY = "cert",
EIP_SERVICE_KEY = "eip",
+ TYPE_OF_CERTIFICATE = "type_of_certificate",
+ ANON_CERTIFICATE = "anon_certificate",
+ AUTHED_CERTIFICATE = "authed_certificate",
SALT_KEY = "salt",
SESSION_ID_COOKIE_KEY = "session_id_cookie_key",
SESSION_ID_KEY = "session_id",
@@ -76,10 +80,12 @@ public class ConfigHelper {
SRP_REGISTRATION_FAILED = 6,
LOGOUT_SUCCESSFUL = 7,
LOGOUT_FAILED = 8,
- CORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE = 9,
- INCORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE = 10,
+ CORRECTLY_DOWNLOADED_CERTIFICATE = 9,
+ INCORRECTLY_DOWNLOADED_CERTIFICATE = 10,
CORRECTLY_UPDATED_PROVIDER_DOT_JSON = 11,
- INCORRECTLY_UPDATED_PROVIDER_DOT_JSON = 12
+ INCORRECTLY_UPDATED_PROVIDER_DOT_JSON = 12,
+ CORRECTLY_DOWNLOADED_ANON_CERTIFICATE = 13,
+ INCORRECTLY_DOWNLOADED_ANON_CERTIFICATE = 14
;
public static void saveSharedPref(String shared_preferences_key, JSONObject content) {
diff --git a/src/se/leap/leapclient/ConfigurationWizard.java b/src/se/leap/leapclient/ConfigurationWizard.java
index 78ac0462..fff155a8 100644
--- a/src/se/leap/leapclient/ConfigurationWizard.java
+++ b/src/se/leap/leapclient/ConfigurationWizard.java
@@ -73,7 +73,6 @@ public class ConfigurationWizard extends Activity
}
else if(resultCode == ConfigHelper.CORRECTLY_DOWNLOADED_JSON_FILES) {
setResult(RESULT_OK);
- finish();
}
else if(resultCode == ConfigHelper.INCORRECTLY_DOWNLOADED_JSON_FILES) {
setResult(RESULT_CANCELED);
@@ -86,6 +85,7 @@ public class ConfigurationWizard extends Activity
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));
+ downloadAnonCert();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -94,6 +94,14 @@ public class ConfigurationWizard extends Activity
else if(resultCode == ConfigHelper.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
Toast.makeText(getApplicationContext(), "Install a new version of this app.", Toast.LENGTH_LONG).show();
}
+ else if(resultCode == ConfigHelper.CORRECTLY_DOWNLOADED_CERTIFICATE) {
+ setResult(RESULT_OK);
+ Toast.makeText(getApplicationContext(), "Your anon cert has been correctly downloaded", Toast.LENGTH_LONG).show();
+ finish();
+ } else if(resultCode == ConfigHelper.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
+ setResult(RESULT_CANCELED);
+ Toast.makeText(getApplicationContext(), "Your anon cert was not downloaded", Toast.LENGTH_LONG).show();
+ }
}
/**
@@ -155,7 +163,9 @@ public class ConfigurationWizard extends Activity
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);
+ ConfigHelper.saveSharedPref(ConfigHelper.ALLOWED_ANON, new JSONObject().put(ConfigHelper.ALLOWED_ANON, provider_json.getJSONObject(ConfigHelper.SERVICE_KEY).getBoolean(ConfigHelper.ALLOWED_ANON)));
ConfigHelper.saveSharedPref(ConfigHelper.DANGER_ON, new JSONObject().put(ConfigHelper.DANGER_ON, current_provider_item.danger_on));
+ downloadAnonCert();
return true;
}
} catch (JSONException e) {
@@ -182,6 +192,33 @@ public class ConfigurationWizard extends Activity
startService(provider_API_command);
}
+ private boolean downloadAnonCert() {
+
+ JSONObject allowed_anon;
+ try {
+ allowed_anon = new JSONObject(ConfigHelper.getStringFromSharedPref(ConfigHelper.ALLOWED_ANON));
+ if(allowed_anon.getBoolean(ConfigHelper.ALLOWED_ANON)) {
+ 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.TYPE_OF_CERTIFICATE, ConfigHelper.ANON_CERTIFICATE);
+
+ provider_API_command.putExtra(ConfigHelper.DOWNLOAD_CERTIFICATE, method_and_parameters);
+ provider_API_command.putExtra("receiver", providerAPI_result_receiver);
+
+ startService(provider_API_command);
+ return true;
+ } else {
+ return false;
+ }
+ } catch (JSONException e) {
+ return false;
+ }
+ }
public void addNewProvider(View view) {
FragmentTransaction fragment_transaction = getFragmentManager().beginTransaction();
Fragment previous_new_provider_dialog = getFragmentManager().findFragmentByTag(ConfigHelper.NEW_PROVIDER_DIALOG);
diff --git a/src/se/leap/leapclient/Dashboard.java b/src/se/leap/leapclient/Dashboard.java
index b937c949..5ffbc19e 100644
--- a/src/se/leap/leapclient/Dashboard.java
+++ b/src/se/leap/leapclient/Dashboard.java
@@ -250,10 +250,11 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
Intent provider_API_command = new Intent(this, ProviderAPI.class);
Bundle method_and_parameters = new Bundle();
+ method_and_parameters.putString(ConfigHelper.TYPE_OF_CERTIFICATE, ConfigHelper.AUTHED_CERTIFICATE);
method_and_parameters.putString(ConfigHelper.SESSION_ID_COOKIE_KEY, session_id.getName());
method_and_parameters.putString(ConfigHelper.SESSION_ID_KEY, session_id.getValue());
- provider_API_command.putExtra(ConfigHelper.DOWNLOAD_USER_AUTHED_CERTIFICATE, method_and_parameters);
+ provider_API_command.putExtra(ConfigHelper.DOWNLOAD_CERTIFICATE, method_and_parameters);
provider_API_command.putExtra("receiver", providerAPI_result_receiver);
startService(provider_API_command);
@@ -278,10 +279,10 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
} 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) {
+ } else if(resultCode == ConfigHelper.CORRECTLY_DOWNLOADED_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_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 00033440..d5e164d6 100644
--- a/src/se/leap/leapclient/ProviderAPI.java
+++ b/src/se/leap/leapclient/ProviderAPI.java
@@ -100,11 +100,11 @@ public class ProviderAPI extends IntentService {
receiver.send(ConfigHelper.LOGOUT_FAILED, Bundle.EMPTY);
}
}
- else if ((task = task_for.getBundleExtra(ConfigHelper.DOWNLOAD_USER_AUTHED_CERTIFICATE)) != null) {
+ else if ((task = task_for.getBundleExtra(ConfigHelper.DOWNLOAD_CERTIFICATE)) != null) {
if(getNewCert(task)) {
- receiver.send(ConfigHelper.CORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE, Bundle.EMPTY);
+ receiver.send(ConfigHelper.CORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
} else {
- receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_AUTHED_USER_CERTIFICATE, Bundle.EMPTY);
+ receiver.send(ConfigHelper.INCORRECTLY_DOWNLOADED_CERTIFICATE, Bundle.EMPTY);
}
}
}
@@ -224,7 +224,9 @@ public class ProviderAPI extends IntentService {
JSONObject provider_json = getJSONFromProvider(provider_json_url, danger_on);
if(provider_json == null) {
result.putBoolean(ConfigHelper.RESULT_KEY, false);
- } else {
+ } else {
+ ConfigHelper.saveSharedPref(ConfigHelper.ALLOWED_ANON, new JSONObject().put(ConfigHelper.ALLOWED_ANON, provider_json.getJSONObject(ConfigHelper.SERVICE_KEY).getBoolean(ConfigHelper.ALLOWED_ANON)));
+
String filename = provider_name + "_provider.json".replaceFirst("__", "_");
ConfigHelper.saveFile(filename, provider_json.toString());
@@ -414,17 +416,20 @@ public class ProviderAPI extends IntentService {
private boolean getNewCert(Bundle task) {
String provider_json_string = ConfigHelper.getStringFromSharedPref(ConfigHelper.PROVIDER_KEY);
- HttpCookie session_id_cookie = new HttpCookie(task.getString(ConfigHelper.SESSION_ID_COOKIE_KEY), task.getString(ConfigHelper.SESSION_ID_KEY));
-
+ String type_of_certificate = task.getString(ConfigHelper.TYPE_OF_CERTIFICATE);
try {
JSONObject provider_json = new JSONObject(provider_json_string);
URL provider_main_url = new URL(provider_json.getString(ConfigHelper.API_URL_KEY).replace("api.", ""));
String new_cert_string_url = provider_main_url.getProtocol() + "://" + provider_main_url.getHost() + "/" + provider_json.getString(ConfigHelper.API_VERSION_KEY) + "/" + ConfigHelper.CERT_KEY;
- CookieManager cookieManager = new CookieManager();
- cookieManager.getCookieStore().add(provider_main_url.toURI(), session_id_cookie);
- CookieHandler.setDefault(cookieManager);
+ if(type_of_certificate.equalsIgnoreCase(ConfigHelper.AUTHED_CERTIFICATE)) {
+ HttpCookie session_id_cookie = new HttpCookie(task.getString(ConfigHelper.SESSION_ID_COOKIE_KEY), task.getString(ConfigHelper.SESSION_ID_KEY));
+ CookieManager cookieManager = new CookieManager();
+ cookieManager.getCookieStore().add(provider_main_url.toURI(), session_id_cookie);
+ CookieHandler.setDefault(cookieManager);
+ }
+
String danger_on_json_string = ConfigHelper.getStringFromSharedPref(ConfigHelper.DANGER_ON);
boolean danger_on = new JSONObject(danger_on_json_string).getBoolean(ConfigHelper.DANGER_ON);
String cert_string = getStringFromProvider(new_cert_string_url, danger_on);
@@ -435,7 +440,6 @@ public class ProviderAPI extends IntentService {
} else {
return false;
}
-
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();