diff options
author | Tobias Brunner <tobias@strongswan.org> | 2016-04-30 16:11:45 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2016-05-02 18:39:18 +0200 |
commit | eb507a5a0dd13db1042ff05e5ae72c6fe0525170 (patch) | |
tree | 2f62df47b9eb7b58f7e871cba82ddf92f7f8f064 /src | |
parent | e7a12cc862bf41d363bd70b400f9cd2cf7e51e39 (diff) | |
download | strongswan-eb507a5a0dd13db1042ff05e5ae72c6fe0525170.tar.bz2 strongswan-eb507a5a0dd13db1042ff05e5ae72c6fe0525170.tar.xz |
android: Add helper function to TrustedCertificateEntry to get subjectAltNames
Duplicates (e.g. with different types) are filtered. If necessary we
could later perhaps add a prefix.
Diffstat (limited to 'src')
-rw-r--r-- | src/frontends/android/app/src/main/java/org/strongswan/android/security/TrustedCertificateEntry.java | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/security/TrustedCertificateEntry.java b/src/frontends/android/app/src/main/java/org/strongswan/android/security/TrustedCertificateEntry.java index 143741faf..5e9873d1b 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/security/TrustedCertificateEntry.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/security/TrustedCertificateEntry.java @@ -1,6 +1,6 @@ /* - * Copyright (C) 2012 Tobias Brunner - * Hochschule fuer Technik Rapperswil + * Copyright (C) 2012-2016 Tobias Brunner + * HSR 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 @@ -15,10 +15,15 @@ package org.strongswan.android.security; -import java.security.cert.X509Certificate; - import android.net.http.SslCertificate; +import java.security.cert.CertificateParsingException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + public class TrustedCertificateEntry implements Comparable<TrustedCertificateEntry> { private final X509Certificate mCert; @@ -87,6 +92,40 @@ public class TrustedCertificateEntry implements Comparable<TrustedCertificateEnt } /** + * Get a sorted list of all rfc822Name, dnSName and iPAddress subjectAltNames + * + * @return sorted list of selected SANs + */ + public List<String> getSubjectAltNames() + { + List<String> list = new ArrayList<>(); + try + { + Collection<List<?>> sans = mCert.getSubjectAlternativeNames(); + if (sans != null) + { + for (List<?> san : sans) + { + switch ((Integer)san.get(0)) + { + case 1: /* rfc822Name */ + case 2: /* dnSName */ + case 7: /* iPAddress */ + list.add((String)san.get(1)); + break; + } + } + } + Collections.sort(list); + } + catch(CertificateParsingException ex) + { + ex.printStackTrace(); + } + return list; + } + + /** * The alias associated with this certificate. * * @return KeyStore alias of this certificate |