mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-05 00:00:45 -04:00
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.
This commit is contained in:
parent
e7a12cc862
commit
eb507a5a0d
@ -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;
|
||||
@ -86,6 +91,40 @@ public class TrustedCertificateEntry implements Comparable<TrustedCertificateEnt
|
||||
return mSubjectSecondary;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user