android: Change how CA certificates from different sources are accessed
This commit is contained in:
+23
-31
@@ -36,6 +36,25 @@ public class TrustedCertificateManager
|
|||||||
private boolean mLoaded;
|
private boolean mLoaded;
|
||||||
private final ArrayList<KeyStore> mKeyStores = new ArrayList<KeyStore>();
|
private final ArrayList<KeyStore> mKeyStores = new ArrayList<KeyStore>();
|
||||||
|
|
||||||
|
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.
|
* Private constructor to prevent instantiation from other classes.
|
||||||
*/
|
*/
|
||||||
@@ -202,44 +221,17 @@ public class TrustedCertificateManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get only the system-wide CA certificates.
|
* Get all certificates from the given source.
|
||||||
|
* @param source type to filter certificates
|
||||||
* @return Hashtable mapping aliases to certificates
|
* @return Hashtable mapping aliases to certificates
|
||||||
*/
|
*/
|
||||||
public Hashtable<String, X509Certificate> getSystemCACertificates()
|
public Hashtable<String, X509Certificate> getCACertificates(TrustedCertificateSource source)
|
||||||
{
|
|
||||||
return getCertificates("system:");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get only the CA certificates installed by the user.
|
|
||||||
* @return Hashtable mapping aliases to certificates
|
|
||||||
*/
|
|
||||||
public Hashtable<String, X509Certificate> getUserCACertificates()
|
|
||||||
{
|
|
||||||
return getCertificates("user:");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get only the local CA certificates installed by the user.
|
|
||||||
* @return Hashtable mapping aliases to certificates
|
|
||||||
*/
|
|
||||||
public Hashtable<String, X509Certificate> getLocalCACertificates()
|
|
||||||
{
|
|
||||||
return getCertificates("local:");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all certificates whose aliases start with the given prefix.
|
|
||||||
* @param prefix prefix to filter certificates
|
|
||||||
* @return Hashtable mapping aliases to certificates
|
|
||||||
*/
|
|
||||||
private Hashtable<String, X509Certificate> getCertificates(String prefix)
|
|
||||||
{
|
{
|
||||||
Hashtable<String, X509Certificate> certs = new Hashtable<String, X509Certificate>();
|
Hashtable<String, X509Certificate> certs = new Hashtable<String, X509Certificate>();
|
||||||
this.mLock.readLock().lock();
|
this.mLock.readLock().lock();
|
||||||
for (String alias : this.mCACerts.keySet())
|
for (String alias : this.mCACerts.keySet())
|
||||||
{
|
{
|
||||||
if (alias.startsWith(prefix))
|
if (alias.startsWith(source.getPrefix()))
|
||||||
{
|
{
|
||||||
certs.put(alias, this.mCACerts.get(alias));
|
certs.put(alias, this.mCACerts.get(alias));
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -24,6 +24,7 @@ import java.util.Map.Entry;
|
|||||||
|
|
||||||
import org.strongswan.android.R;
|
import org.strongswan.android.R;
|
||||||
import org.strongswan.android.logic.TrustedCertificateManager;
|
import org.strongswan.android.logic.TrustedCertificateManager;
|
||||||
|
import org.strongswan.android.logic.TrustedCertificateManager.TrustedCertificateSource;
|
||||||
import org.strongswan.android.security.TrustedCertificateEntry;
|
import org.strongswan.android.security.TrustedCertificateEntry;
|
||||||
import org.strongswan.android.ui.adapter.TrustedCertificateAdapter;
|
import org.strongswan.android.ui.adapter.TrustedCertificateAdapter;
|
||||||
|
|
||||||
@@ -172,7 +173,7 @@ public class TrustedCertificateListFragment extends ListFragment implements Load
|
|||||||
Hashtable<String,X509Certificate> certificates;
|
Hashtable<String,X509Certificate> certificates;
|
||||||
List<TrustedCertificateEntry> selected;
|
List<TrustedCertificateEntry> selected;
|
||||||
|
|
||||||
certificates = mUser ? certman.getUserCACertificates() : certman.getSystemCACertificates();
|
certificates = mUser ? certman.getCACertificates(TrustedCertificateSource.USER) : certman.getCACertificates(TrustedCertificateSource.SYSTEM);
|
||||||
selected = new ArrayList<TrustedCertificateEntry>();
|
selected = new ArrayList<TrustedCertificateEntry>();
|
||||||
for (Entry<String, X509Certificate> entry : certificates.entrySet())
|
for (Entry<String, X509Certificate> entry : certificates.entrySet())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user