aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-08-14 09:36:56 +0200
committerTobias Brunner <tobias@strongswan.org>2012-08-14 12:01:41 +0200
commitcaf85c872f697235a2908d8c32096626297611a2 (patch)
treed08d497e12dc0bdec59e66e2ffb6aec9b4e6a253 /src
parentdb8bea83119f69fe065fb9d3ee4096c2c91756cf (diff)
downloadstrongswan-caf85c872f697235a2908d8c32096626297611a2.tar.bz2
strongswan-caf85c872f697235a2908d8c32096626297611a2.tar.xz
Added a ListFragment that lists trusted certificates (loaded via a custom Loader)
Diffstat (limited to 'src')
-rw-r--r--src/frontends/android/res/values-de/strings.xml3
-rw-r--r--src/frontends/android/res/values/strings.xml3
-rw-r--r--src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java153
3 files changed, 159 insertions, 0 deletions
diff --git a/src/frontends/android/res/values-de/strings.xml b/src/frontends/android/res/values-de/strings.xml
index bc426e6ea..ce5cb6adb 100644
--- a/src/frontends/android/res/values-de/strings.xml
+++ b/src/frontends/android/res/values-de/strings.xml
@@ -57,6 +57,9 @@
<string name="alert_text_nocertfound_title">Kein CA-Zertifikat ausgewählt</string>
<string name="alert_text_nocertfound">Bitte wählen Sie eines aus oder aktivieren Sie <i>Automatisch wählen</i></string>
+ <!-- Trusted certificate selection -->
+ <string name="no_certificates">Keine Zertifikate</string>
+
<!-- VPN state fragment -->
<string name="state_label">Status:</string>
<string name="profile_label">Profil:</string>
diff --git a/src/frontends/android/res/values/strings.xml b/src/frontends/android/res/values/strings.xml
index 855914015..591bfff5e 100644
--- a/src/frontends/android/res/values/strings.xml
+++ b/src/frontends/android/res/values/strings.xml
@@ -57,6 +57,9 @@
<string name="alert_text_nocertfound_title">No CA certificate selected</string>
<string name="alert_text_nocertfound">Please select one or activate <i>Select automatically</i></string>
+ <!-- Trusted certificate selection -->
+ <string name="no_certificates">No certificates</string>
+
<!-- VPN state fragment -->
<string name="state_label">Status:</string>
<string name="profile_label">Profile:</string>
diff --git a/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java
new file mode 100644
index 000000000..a64a92755
--- /dev/null
+++ b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2012 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * 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. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+package org.strongswan.android.ui;
+
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map.Entry;
+
+import org.strongswan.android.R;
+import org.strongswan.android.data.TrustedCertificateEntry;
+import org.strongswan.android.logic.TrustedCertificateManager;
+import org.strongswan.android.ui.adapter.TrustedCertificateAdapter;
+
+import android.app.ListFragment;
+import android.app.LoaderManager.LoaderCallbacks;
+import android.content.AsyncTaskLoader;
+import android.content.Context;
+import android.content.Loader;
+import android.os.Bundle;
+
+public class TrustedCertificateListFragment extends ListFragment implements LoaderCallbacks<List<TrustedCertificateEntry>>
+{
+ private TrustedCertificateAdapter mAdapter;
+ private boolean mUser;
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState)
+ {
+ super.onActivityCreated(savedInstanceState);
+
+ setEmptyText(getString(R.string.no_certificates));
+
+ mAdapter = new TrustedCertificateAdapter(getActivity());
+ setListAdapter(mAdapter);
+
+ setListShown(false);
+
+ /* non empty arguments mean we list user certificate */
+ mUser = getArguments() != null;
+
+ getLoaderManager().initLoader(0, null, this);
+ }
+
+ @Override
+ public void onDestroy()
+ {
+ super.onDestroy();
+ }
+
+ @Override
+ public Loader<List<TrustedCertificateEntry>> onCreateLoader(int id, Bundle args)
+ { /* we don't need the id as we have only one loader */
+ return new CertificateListLoader(getActivity(), mUser);
+ }
+
+ @Override
+ public void onLoadFinished(Loader<List<TrustedCertificateEntry>> loader, List<TrustedCertificateEntry> data)
+ {
+ mAdapter.setData(data);
+
+ if (isResumed())
+ {
+ setListShown(true);
+ }
+ else
+ {
+ setListShownNoAnimation(true);
+ }
+ }
+
+ @Override
+ public void onLoaderReset(Loader<List<TrustedCertificateEntry>> loader)
+ {
+ mAdapter.setData(null);
+ }
+
+ public static class CertificateListLoader extends AsyncTaskLoader<List<TrustedCertificateEntry>>
+ {
+ private List<TrustedCertificateEntry> mData;
+ private final boolean mUser;
+
+ public CertificateListLoader(Context context, boolean user)
+ {
+ super(context);
+ mUser = user;
+ }
+
+ @Override
+ public List<TrustedCertificateEntry> loadInBackground()
+ {
+ TrustedCertificateManager certman = TrustedCertificateManager.getInstance().load();
+ Hashtable<String,X509Certificate> certificates;
+ List<TrustedCertificateEntry> selected;
+
+ certificates = mUser ? certman.getUserCACertificates() : certman.getSystemCACertificates();
+ selected = new ArrayList<TrustedCertificateEntry>();
+ for (Entry<String, X509Certificate> entry : certificates.entrySet())
+ {
+ selected.add(new TrustedCertificateEntry(entry.getKey(), entry.getValue()));
+ }
+ Collections.sort(selected);
+ return selected;
+ }
+
+ @Override
+ protected void onStartLoading()
+ {
+ if (mData != null)
+ { /* if we have data ready, deliver it directly */
+ deliverResult(mData);
+ return;
+ }
+ forceLoad();
+ }
+
+ @Override
+ public void deliverResult(List<TrustedCertificateEntry> data)
+ {
+ if (isReset())
+ {
+ return;
+ }
+ mData = data;
+ if (isStarted())
+ { /* if it is started we deliver the data directly,
+ * otherwise this is handled in onStartLoading */
+ super.deliverResult(data);
+ }
+ }
+
+ @Override
+ protected void onReset()
+ {
+ mData = null;
+ }
+ }
+}