summaryrefslogtreecommitdiff
path: root/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2015-06-08 19:56:43 +0200
committerParménides GV <parmegv@sdf.org>2015-06-08 20:04:03 +0200
commitb0a0805ab81aaa4e204ecfc77d3a6a7f7ed66b2f (patch)
tree7ebeb40d0c74a8c431b7845e403cb1add5e63be4 /app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java
parent8d39fbdb4980c95268249f21f3c6b8e36b22cf90 (diff)
s/buildtype/flavor, changed riseup's pin
Riseup's EE certificate expired (EE = End-Entity, the commercial certificate signed by the issuer), and we weren't able to fetch provider.json because the pin wasn't valid. This problem needs to be avoided in the future, using HKPK (https://tools.ietf.org/html/rfc7469), which Micah's implementing on Riseup. Switching from build types from flavors enables us to run tests against production apk, not just debug. I didn't detect this pinning problem because tests were run only against the debug apk, which trusted preseeded providers by default (thus bypassing pinning issue).
Diffstat (limited to 'app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java')
-rw-r--r--app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java111
1 files changed, 111 insertions, 0 deletions
diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java
new file mode 100644
index 00000000..08fc5f3d
--- /dev/null
+++ b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java
@@ -0,0 +1,111 @@
+package se.leap.bitmaskclient;
+
+import org.json.*;
+
+import se.leap.bitmaskclient.eip.*;
+import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
+
+import android.app.*;
+import android.content.*;
+import android.os.*;
+import android.view.*;
+import android.widget.*;
+
+public class ProviderDetailFragment extends DialogFragment {
+
+ final public static String TAG = "providerDetailFragment";
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ try {
+
+ LayoutInflater inflater = getActivity().getLayoutInflater();
+ View provider_detail_view = inflater.inflate(R.layout.provider_detail_fragment, null);
+
+ JSONObject provider_json = new JSONObject(getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, getActivity().MODE_PRIVATE).getString(Provider.KEY, ""));
+
+ final TextView domain = (TextView) provider_detail_view.findViewById(R.id.provider_detail_domain);
+ domain.setText(provider_json.getString(Provider.DOMAIN));
+ final TextView name = (TextView) provider_detail_view.findViewById(R.id.provider_detail_name);
+ name.setText(provider_json.getJSONObject(Provider.NAME).getString("en"));
+ final TextView description = (TextView) provider_detail_view.findViewById(R.id.provider_detail_description);
+ description.setText(provider_json.getJSONObject(Provider.DESCRIPTION).getString("en"));
+
+ builder.setView(provider_detail_view);
+ builder.setTitle(R.string.provider_details_fragment_title);
+
+ if (anon_allowed(provider_json)) {
+ builder.setPositiveButton(R.string.use_anonymously_button, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ interface_with_configuration_wizard.use_anonymously();
+ }
+ });
+ }
+
+ if (registration_allowed(provider_json)) {
+ builder.setNegativeButton(R.string.signup_or_login_button, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ interface_with_configuration_wizard.login();
+ }
+ });
+ }
+
+ return builder.create();
+ } catch (JSONException e) {
+ return null;
+ }
+ }
+
+ private boolean anon_allowed(JSONObject provider_json) {
+ try {
+ JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE);
+ return service_description.has(Constants.ALLOWED_ANON) && service_description.getBoolean(Constants.ALLOWED_ANON);
+ } catch (JSONException e) {
+ return false;
+ }
+ }
+
+ private boolean registration_allowed(JSONObject provider_json) {
+ try {
+ JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE);
+ return service_description.has(Provider.ALLOW_REGISTRATION) && service_description.getBoolean(Provider.ALLOW_REGISTRATION);
+ } catch (JSONException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ super.onCancel(dialog);
+ SharedPreferences.Editor editor = getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit();
+ editor.remove(Provider.KEY).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit();
+ interface_with_configuration_wizard.showAllProviders();
+ }
+
+ public static DialogFragment newInstance() {
+ ProviderDetailFragment provider_detail_fragment = new ProviderDetailFragment();
+ return provider_detail_fragment;
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ try {
+ interface_with_configuration_wizard = (ProviderDetailFragmentInterface) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString()
+ + " must implement LogInDialogListener");
+ }
+ }
+
+ public interface ProviderDetailFragmentInterface {
+ public void login();
+
+ public void use_anonymously();
+
+ public void showAllProviders();
+ }
+
+ ProviderDetailFragmentInterface interface_with_configuration_wizard;
+}