From: Tobias Brunner Date: Wed, 11 Jun 2014 12:48:08 +0000 (+0200) Subject: android: Change how CA certificates from different sources are accessed X-Git-Tag: 5.2.1dr1~117^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b2b536b707520f4084cd6ab8ccab41d515aced2;p=thirdparty%2Fstrongswan.git android: Change how CA certificates from different sources are accessed --- diff --git a/src/frontends/android/src/org/strongswan/android/logic/TrustedCertificateManager.java b/src/frontends/android/src/org/strongswan/android/logic/TrustedCertificateManager.java index a5cea4499e..6e0c9f7a7e 100644 --- a/src/frontends/android/src/org/strongswan/android/logic/TrustedCertificateManager.java +++ b/src/frontends/android/src/org/strongswan/android/logic/TrustedCertificateManager.java @@ -36,6 +36,25 @@ public class TrustedCertificateManager private boolean mLoaded; private final ArrayList mKeyStores = new ArrayList(); + public enum TrustedCertificateSource + { + SYSTEM("system:"), + USER("user:"), + LOCAL("local:"); + + private final String mPrefix; + + private TrustedCertificateSource(String prefix) + { + mPrefix = prefix; + } + + private String getPrefix() + { + return mPrefix; + } + } + /** * Private constructor to prevent instantiation from other classes. */ @@ -202,44 +221,17 @@ public class TrustedCertificateManager } /** - * Get only the system-wide CA certificates. - * @return Hashtable mapping aliases to certificates - */ - public Hashtable getSystemCACertificates() - { - return getCertificates("system:"); - } - - /** - * Get only the CA certificates installed by the user. - * @return Hashtable mapping aliases to certificates - */ - public Hashtable getUserCACertificates() - { - return getCertificates("user:"); - } - - /** - * Get only the local CA certificates installed by the user. - * @return Hashtable mapping aliases to certificates - */ - public Hashtable getLocalCACertificates() - { - return getCertificates("local:"); - } - - /** - * Get all certificates whose aliases start with the given prefix. - * @param prefix prefix to filter certificates + * Get all certificates from the given source. + * @param source type to filter certificates * @return Hashtable mapping aliases to certificates */ - private Hashtable getCertificates(String prefix) + public Hashtable getCACertificates(TrustedCertificateSource source) { Hashtable certs = new Hashtable(); this.mLock.readLock().lock(); for (String alias : this.mCACerts.keySet()) { - if (alias.startsWith(prefix)) + if (alias.startsWith(source.getPrefix())) { certs.put(alias, this.mCACerts.get(alias)); } diff --git a/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java index 2f07b96c2d..918393fe65 100644 --- a/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java +++ b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificateListFragment.java @@ -24,6 +24,7 @@ import java.util.Map.Entry; import org.strongswan.android.R; import org.strongswan.android.logic.TrustedCertificateManager; +import org.strongswan.android.logic.TrustedCertificateManager.TrustedCertificateSource; import org.strongswan.android.security.TrustedCertificateEntry; import org.strongswan.android.ui.adapter.TrustedCertificateAdapter; @@ -172,7 +173,7 @@ public class TrustedCertificateListFragment extends ListFragment implements Load Hashtable certificates; List selected; - certificates = mUser ? certman.getUserCACertificates() : certman.getSystemCACertificates(); + certificates = mUser ? certman.getCACertificates(TrustedCertificateSource.USER) : certman.getCACertificates(TrustedCertificateSource.SYSTEM); selected = new ArrayList(); for (Entry entry : certificates.entrySet()) {