android: Allow selection of local certificates
This commit is contained in:
@@ -78,6 +78,7 @@
|
||||
<string name="no_certificates">Keine Zertifikate</string>
|
||||
<string name="system_tab">System</string>
|
||||
<string name="user_tab">Benutzer</string>
|
||||
<string name="local_tab">Importiert</string>
|
||||
|
||||
<!-- VPN state fragment -->
|
||||
<string name="state_label">Status:</string>
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
<string name="no_certificates">Brak certyfikatów</string>
|
||||
<string name="system_tab">System</string>
|
||||
<string name="user_tab">Użytkownik</string>
|
||||
<string name="local_tab">Imported</string>
|
||||
|
||||
<!-- VPN state fragment -->
|
||||
<string name="state_label">Status:</string>
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
<string name="no_certificates">Нет доступных сертификатов</string>
|
||||
<string name="system_tab">Система</string>
|
||||
<string name="user_tab">Пользователь</string>
|
||||
<string name="local_tab">Imported</string>
|
||||
|
||||
<!-- VPN state fragment -->
|
||||
<string name="state_label">Статус:</string>
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
<string name="no_certificates">Немає сертифікатів</string>
|
||||
<string name="system_tab">Система</string>
|
||||
<string name="user_tab">Користувач</string>
|
||||
<string name="local_tab">Imported</string>
|
||||
|
||||
<!-- VPN state fragment -->
|
||||
<string name="state_label">Статус:</string>
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
<string name="no_certificates">No certificates</string>
|
||||
<string name="system_tab">System</string>
|
||||
<string name="user_tab">User</string>
|
||||
<string name="local_tab">Imported</string>
|
||||
|
||||
<!-- VPN state fragment -->
|
||||
<string name="state_label">Status:</string>
|
||||
|
||||
+13
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Tobias Brunner
|
||||
* Copyright (C) 2012-2014 Tobias Brunner
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
@@ -46,9 +46,10 @@ import android.widget.SearchView.OnQueryTextListener;
|
||||
|
||||
public class TrustedCertificateListFragment extends ListFragment implements LoaderCallbacks<List<TrustedCertificateEntry>>, OnQueryTextListener
|
||||
{
|
||||
public static final String EXTRA_CERTIFICATE_SOURCE = "certificate_source";
|
||||
private OnTrustedCertificateSelectedListener mListener;
|
||||
private TrustedCertificateAdapter mAdapter;
|
||||
private boolean mUser;
|
||||
private TrustedCertificateSource mSource = TrustedCertificateSource.SYSTEM;
|
||||
|
||||
/**
|
||||
* The activity containing this fragment should implement this interface
|
||||
@@ -70,8 +71,11 @@ public class TrustedCertificateListFragment extends ListFragment implements Load
|
||||
|
||||
setListShown(false);
|
||||
|
||||
/* non empty arguments mean we list user certificate */
|
||||
mUser = getArguments() != null;
|
||||
Bundle arguments = getArguments();
|
||||
if (arguments != null)
|
||||
{
|
||||
mSource = (TrustedCertificateSource)arguments.getSerializable(EXTRA_CERTIFICATE_SOURCE);
|
||||
}
|
||||
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
@@ -122,7 +126,7 @@ public class TrustedCertificateListFragment extends ListFragment implements Load
|
||||
@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);
|
||||
return new CertificateListLoader(getActivity(), mSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,22 +162,21 @@ public class TrustedCertificateListFragment extends ListFragment implements Load
|
||||
public static class CertificateListLoader extends AsyncTaskLoader<List<TrustedCertificateEntry>>
|
||||
{
|
||||
private List<TrustedCertificateEntry> mData;
|
||||
private final boolean mUser;
|
||||
private final TrustedCertificateSource mSource;
|
||||
|
||||
public CertificateListLoader(Context context, boolean user)
|
||||
public CertificateListLoader(Context context, TrustedCertificateSource source)
|
||||
{
|
||||
super(context);
|
||||
mUser = user;
|
||||
mSource = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TrustedCertificateEntry> loadInBackground()
|
||||
{
|
||||
TrustedCertificateManager certman = TrustedCertificateManager.getInstance().load();
|
||||
Hashtable<String,X509Certificate> certificates;
|
||||
Hashtable<String,X509Certificate> certificates = certman.getCACertificates(mSource);
|
||||
List<TrustedCertificateEntry> selected;
|
||||
|
||||
certificates = mUser ? certman.getCACertificates(TrustedCertificateSource.USER) : certman.getCACertificates(TrustedCertificateSource.SYSTEM);
|
||||
selected = new ArrayList<TrustedCertificateEntry>();
|
||||
for (Entry<String, X509Certificate> entry : certificates.entrySet())
|
||||
{
|
||||
|
||||
+13
-9
@@ -17,6 +17,7 @@ package org.strongswan.android.ui;
|
||||
|
||||
import org.strongswan.android.R;
|
||||
import org.strongswan.android.data.VpnProfileDataSource;
|
||||
import org.strongswan.android.logic.TrustedCertificateManager.TrustedCertificateSource;
|
||||
import org.strongswan.android.security.TrustedCertificateEntry;
|
||||
|
||||
import android.app.ActionBar;
|
||||
@@ -43,11 +44,15 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert
|
||||
actionBar.addTab(actionBar
|
||||
.newTab()
|
||||
.setText(R.string.system_tab)
|
||||
.setTabListener(new TrustedCertificatesTabListener(this, "system", false)));
|
||||
.setTabListener(new TrustedCertificatesTabListener(this, "system", TrustedCertificateSource.SYSTEM)));
|
||||
actionBar.addTab(actionBar
|
||||
.newTab()
|
||||
.setText(R.string.user_tab)
|
||||
.setTabListener(new TrustedCertificatesTabListener(this, "user", true)));
|
||||
.setTabListener(new TrustedCertificatesTabListener(this, "user", TrustedCertificateSource.USER)));
|
||||
actionBar.addTab(actionBar
|
||||
.newTab()
|
||||
.setText(R.string.local_tab)
|
||||
.setTabListener(new TrustedCertificatesTabListener(this, "local", TrustedCertificateSource.LOCAL)));
|
||||
|
||||
if (savedInstanceState != null)
|
||||
{
|
||||
@@ -87,13 +92,13 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert
|
||||
public static class TrustedCertificatesTabListener implements ActionBar.TabListener
|
||||
{
|
||||
private final String mTag;
|
||||
private final boolean mUser;
|
||||
private final TrustedCertificateSource mSource;
|
||||
private Fragment mFragment;
|
||||
|
||||
public TrustedCertificatesTabListener(Activity activity, String tag, boolean user)
|
||||
public TrustedCertificatesTabListener(Activity activity, String tag, TrustedCertificateSource source)
|
||||
{
|
||||
mTag = tag;
|
||||
mUser = user;
|
||||
mSource = source;
|
||||
/* check to see if we already have a fragment for this tab, probably
|
||||
* from a previously saved state. if so, deactivate it, because the
|
||||
* initial state is that no tab is shown */
|
||||
@@ -112,10 +117,9 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert
|
||||
if (mFragment == null)
|
||||
{
|
||||
mFragment = new TrustedCertificateListFragment();
|
||||
if (mUser)
|
||||
{ /* use non empty arguments to indicate this */
|
||||
mFragment.setArguments(new Bundle());
|
||||
}
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(TrustedCertificateListFragment.EXTRA_CERTIFICATE_SOURCE, mSource);
|
||||
mFragment.setArguments(args);
|
||||
ft.add(android.R.id.content, mFragment, mTag);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user